Version server is checked every time the root folder is refreshed, and both version...
authorDavid A. Velasco <dvelasco@solidgear.es>
Wed, 19 Feb 2014 11:28:24 +0000 (12:28 +0100)
committerDavid A. Velasco <dvelasco@solidgear.es>
Wed, 19 Feb 2014 11:28:24 +0000 (12:28 +0100)
owncloud-android-library
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/files/FileOperationsHelper.java
src/com/owncloud/android/files/services/FileUploader.java
src/com/owncloud/android/operations/SynchronizeFolderOperation.java
src/com/owncloud/android/operations/UpdateOCVersionOperation.java
src/com/owncloud/android/syncadapter/FileSyncAdapter.java

index 1f6f9bc..c3f4382 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 1f6f9bcf84837a72ef2a7a79b5af7bee6677facd
+Subproject commit c3f438220061a302c7f6fd6c32da039efaeb541e
index 3a817d6..61e31b4 100644 (file)
@@ -36,7 +36,6 @@ import android.support.v4.app.Fragment;
 import android.text.Editable;\r
 import android.text.InputType;\r
 import android.text.TextWatcher;\r
-import android.util.Log;\r
 import android.view.KeyEvent;\r
 import android.view.MotionEvent;\r
 import android.view.View;\r
@@ -95,6 +94,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     private static final String KEY_AUTH_MESSAGE_TEXT = "AUTH_MESSAGE_TEXT";\r
     private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT";\r
     private static final String KEY_OC_VERSION = "OC_VERSION";\r
+    private static final String KEY_OC_VERSION_STRING = "OC_VERSION_STRING";\r
     private static final String KEY_ACCOUNT = "ACCOUNT";\r
     private static final String KEY_SERVER_VALID = "SERVER_VALID";\r
     private static final String KEY_SERVER_CHECKED = "SERVER_CHECKED";\r
@@ -124,7 +124,6 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     \r
     private String mHostBaseUrl;\r
     private OwnCloudVersion mDiscoveredVersion;\r
-    private boolean mIsSharedSupported;\r
 \r
     private String mAuthMessageText;\r
     private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon;\r
@@ -235,20 +234,19 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             mServerIsChecked = false;\r
             mIsSslConn = false;\r
             mAuthStatusText = mAuthStatusIcon = 0;\r
-            mIsSharedSupported = false;\r
 \r
             /// retrieve extras from intent\r
             mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT);\r
             if (mAccount != null) {\r
                 String ocVersion = mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION);\r
+                String ocVersionString = mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION_STRING);\r
                 if (ocVersion != null) {\r
-                    mDiscoveredVersion = new OwnCloudVersion(ocVersion);\r
+                    mDiscoveredVersion = new OwnCloudVersion(ocVersion, ocVersionString);\r
                 }\r
                 mHostBaseUrl = normalizeUrl(mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL));\r
                 mHostUrlInput.setText(mHostBaseUrl);\r
                 String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
                 mUsernameInput.setText(userName);\r
-                mIsSharedSupported = Boolean.getBoolean(mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API));\r
                 \r
             }\r
             initAuthorizationMethod();  // checks intent and setup.xml to determine mCurrentAuthorizationMethod\r
@@ -276,9 +274,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             \r
             /// server data\r
             String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);\r
-            mIsSharedSupported = savedInstanceState.getBoolean(KEY_IS_SHARED_SUPPORTED, false);\r
+            String ocVersionString = savedInstanceState.getString(KEY_OC_VERSION_STRING);\r
             if (ocVersion != null) {\r
-                mDiscoveredVersion = new OwnCloudVersion(ocVersion);\r
+                mDiscoveredVersion = new OwnCloudVersion(ocVersion, ocVersionString);\r
             }\r
             mHostBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);\r
 \r
@@ -453,10 +451,10 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
         /// server data\r
         if (mDiscoveredVersion != null) {\r
-            outState.putString(KEY_OC_VERSION, mDiscoveredVersion.toString());\r
+            outState.putString(KEY_OC_VERSION, mDiscoveredVersion.getVersion());\r
+            outState.putString(KEY_OC_VERSION_STRING, mDiscoveredVersion.getVersionString());\r
         }\r
         outState.putString(KEY_HOST_URL_TEXT, mHostBaseUrl);\r
-        outState.putBoolean(KEY_IS_SHARED_SUPPORTED, mIsSharedSupported);\r
 \r
         /// account data, if updating\r
         if (mAccount != null) {\r
@@ -591,7 +589,6 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         \r
         mServerIsValid = false;\r
         mServerIsChecked = false;\r
-        mIsSharedSupported = false;\r
         mOkButton.setEnabled(false);\r
         mDiscoveredVersion = null;\r
         hideRefreshButton();\r
@@ -906,9 +903,6 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             /// allow or not the user try to access the server\r
             mOkButton.setEnabled(mServerIsValid);\r
             \r
-            /// retrieve if is supported the Share API\r
-            mIsSharedSupported = operation.isSharedSupported();\r
-\r
         }   // else nothing ; only the last check operation is considered; \r
         // multiple can be triggered if the user amends a URL before a previous check can be triggered\r
     }\r
@@ -1299,9 +1293,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);\r
             }\r
             /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA\r
-            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION,    mDiscoveredVersion.toString());\r
+            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION,         mDiscoveredVersion.getVersion());\r
+            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION_STRING,  mDiscoveredVersion.getVersionString());\r
             mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL,   mHostBaseUrl);\r
-            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API, Boolean.toString(mIsSharedSupported));\r
             if (isSaml) {\r
                 mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); \r
             } else if (isOAuth) {\r
index 4b37a3b..61fde2d 100644 (file)
@@ -30,6 +30,7 @@ import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.accounts.OwnCloudAccount;
 import com.owncloud.android.lib.network.webdav.WebdavUtils;
+import com.owncloud.android.lib.utils.OwnCloudVersion;
 import com.owncloud.android.services.OperationsService;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.dialog.ActivityChooserDialog;
@@ -135,7 +136,10 @@ public class FileOperationsHelper {
     public boolean isSharedSupported(FileActivity callerActivity) {
         if (callerActivity.getAccount() != null) {
             AccountManager accountManager = AccountManager.get(callerActivity);
-            return Boolean.parseBoolean(accountManager.getUserData(callerActivity.getAccount(), OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API));
+            String version = accountManager.getUserData(callerActivity.getAccount(), OwnCloudAccount.Constants.KEY_OC_VERSION);
+            String versionString = accountManager.getUserData(callerActivity.getAccount(), OwnCloudAccount.Constants.KEY_OC_VERSION_STRING);
+            return (new OwnCloudVersion(version, versionString)).isSharedSupported();
+            //return Boolean.parseBoolean(accountManager.getUserData(callerActivity.getAccount(), OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API));
         }
         return false;
     }
index e9a4637..0cffa28 100644 (file)
@@ -253,7 +253,10 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
             }
         }
 
-        OwnCloudVersion ocv = new OwnCloudVersion(AccountManager.get(this).getUserData(account, OwnCloudAccount.Constants.KEY_OC_VERSION));
+        AccountManager aMgr = AccountManager.get(this);
+        String version = aMgr.getUserData(account, OwnCloudAccount.Constants.KEY_OC_VERSION);
+        String versionString = aMgr.getUserData(account, OwnCloudAccount.Constants.KEY_OC_VERSION_STRING);
+        OwnCloudVersion ocv = new OwnCloudVersion(version, versionString);
         boolean chunked = FileUploader.chunkedUploadIsSupported(ocv);
         AbstractList<String> requestedUploads = new Vector<String>();
         String uploadKey = null;
index 11ce41e..97641c6 100644 (file)
@@ -46,6 +46,7 @@ import com.owncloud.android.lib.operations.remote.GetSharesForFileRemoteOperatio
 import com.owncloud.android.lib.operations.remote.ReadRemoteFileOperation;
 import com.owncloud.android.lib.operations.remote.ReadRemoteFolderOperation;
 import com.owncloud.android.lib.operations.common.RemoteFile;
+import com.owncloud.android.lib.utils.FileUtils;
 import com.owncloud.android.syncadapter.FileSyncAdapter;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.Log_OC;
@@ -101,7 +102,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
     private boolean mSyncFullAccount;
 
     /** 'True' means that Share resources bound to the files into the folder should be refreshed also */
-    private boolean mRefreshShares;
+    private boolean mIsShareSupported;
     
     /** 'True' means that the remote folder changed from last synchronization and should be fetched */
     private boolean mRemoteFolderChanged;
@@ -122,14 +123,14 @@ public class SynchronizeFolderOperation extends RemoteOperation {
     public SynchronizeFolderOperation(  OCFile folder, 
                                         long currentSyncTime, 
                                         boolean syncFullAccount,
-                                        boolean refreshShares,
+                                        boolean isShareSupported,
                                         FileDataStorageManager dataStorageManager, 
                                         Account account, 
                                         Context context ) {
         mLocalFolder = folder;
         mCurrentSyncTime = currentSyncTime;
         mSyncFullAccount = syncFullAccount;
-        mRefreshShares = refreshShares;
+        mIsShareSupported = isShareSupported;
         mStorageManager = dataStorageManager;
         mAccount = account;
         mContext = context;
@@ -171,6 +172,10 @@ public class SynchronizeFolderOperation extends RemoteOperation {
         mConflictsFound = 0;
         mForgottenLocalFiles.clear();
         
+        if (FileUtils.PATH_SEPARATOR.equals(mLocalFolder.getRemotePath()) && !mSyncFullAccount) {
+            updateOCVersion(client);
+        }
+        
         result = checkForChanges(client);
         
         if (result.isSuccess()) {
@@ -185,7 +190,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
             sendLocalBroadcast(EVENT_SINGLE_FOLDER_CONTENTS_SYNCED, mLocalFolder.getRemotePath(), result);
         }
         
-        if (result.isSuccess() && mRefreshShares) {
+        if (result.isSuccess() && mIsShareSupported) {
             RemoteOperationResult shareResult = refreshSharesForFolder(client);
             if (shareResult.getCode() != ResultCode.FILE_NOT_FOUND) {
                 result = shareResult;
@@ -200,6 +205,16 @@ public class SynchronizeFolderOperation extends RemoteOperation {
         
     }
 
+
+    private void updateOCVersion(OwnCloudClient client) {
+        UpdateOCVersionOperation update = new UpdateOCVersionOperation(mAccount, mContext);
+        RemoteOperationResult result = update.execute(client);
+        if (result.isSuccess()) {
+            mIsShareSupported = update.getOCVersion().isSharedSupported();
+        }
+    }
+
+    
     private RemoteOperationResult checkForChanges(OwnCloudClient client) {
         mRemoteFolderChanged = false;
         RemoteOperationResult result = null;
index a047f11..7fb123a 100644 (file)
@@ -47,11 +47,13 @@ public class UpdateOCVersionOperation extends RemoteOperation {
 
     private Account mAccount;
     private Context mContext;
+    private OwnCloudVersion mOwnCloudVersion;
     
     
     public UpdateOCVersionOperation(Account account, Context context) {
         mAccount = account;
         mContext = context;
+        mOwnCloudVersion = null;
     }
     
     
@@ -74,10 +76,13 @@ public class UpdateOCVersionOperation extends RemoteOperation {
                 if (response != null) {
                     JSONObject json = new JSONObject(response);
                     if (json != null && json.getString("version") != null) {
-                        OwnCloudVersion ocver = new OwnCloudVersion(json.getString("version"));
-                        if (ocver.isVersionValid()) {
-                            accountMngr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION, ocver.toString());
-                            Log_OC.d(TAG, "Got new OC version " + ocver.toString());
+                        String version = json.getString("version");
+                        String versionstring = json.getString("versionstring");
+                        mOwnCloudVersion = new OwnCloudVersion(version, versionstring);
+                        if (mOwnCloudVersion.isVersionValid()) {
+                            accountMngr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION, mOwnCloudVersion.getVersion());
+                            accountMngr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION_STRING, mOwnCloudVersion.getVersionString());
+                            Log_OC.d(TAG, "Got new OC version " + mOwnCloudVersion.toString());
                             result = new RemoteOperationResult(ResultCode.OK);
                             
                         } else {
@@ -107,4 +112,9 @@ public class UpdateOCVersionOperation extends RemoteOperation {
         return result;
     }
 
+
+    public OwnCloudVersion getOCVersion() {
+        return mOwnCloudVersion;
+    }
+
 }
index 6b2ea73..87177c4 100644 (file)
@@ -110,7 +110,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
     private SyncResult mSyncResult;
 
     /** 'True' means that the server supports the share API */
-    private boolean mIsSharedSupported;
+    private boolean mIsShareSupported;
     
     
     /**
@@ -156,9 +156,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         this.setContentProviderClient(providerClient);
         this.setStorageManager(new FileDataStorageManager(account, providerClient));
         
-        AccountManager accountManager = getAccountManager();
-        mIsSharedSupported = Boolean.parseBoolean(accountManager.getUserData(account, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API));
-
         try {
             this.initClientForCurrentAccount();
         } catch (IOException e) {
@@ -235,6 +232,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         RemoteOperationResult result = update.execute(getClient());
         if (!result.isSuccess()) {
             mLastFailedResult = result; 
+        } else {
+            mIsShareSupported = update.getOCVersion().isSharedSupported();
         }
     }
     
@@ -269,7 +268,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         SynchronizeFolderOperation synchFolderOp = new SynchronizeFolderOperation(  folder, 
                                                                                     mCurrentSyncTime, 
                                                                                     true,
-                                                                                    mIsSharedSupported,
+                                                                                    mIsShareSupported,
                                                                                     getStorageManager(), 
                                                                                     getAccount(), 
                                                                                     getContext()