Răsfoiți Sursa

Version server is checked every time the root folder is refreshed, and both version and versionstring are in the server are saved locally

David A. Velasco 11 ani în urmă
părinte
comite
7a4ac19993

+ 1 - 1
owncloud-android-library

@@ -1 +1 @@
-Subproject commit 1f6f9bcf84837a72ef2a7a79b5af7bee6677facd
+Subproject commit c3f438220061a302c7f6fd6c32da039efaeb541e

+ 9 - 15
src/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -36,7 +36,6 @@ import android.support.v4.app.Fragment;
 import android.text.Editable;
 import android.text.InputType;
 import android.text.TextWatcher;
-import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.View;
@@ -95,6 +94,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     private static final String KEY_AUTH_MESSAGE_TEXT = "AUTH_MESSAGE_TEXT";
     private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT";
     private static final String KEY_OC_VERSION = "OC_VERSION";
+    private static final String KEY_OC_VERSION_STRING = "OC_VERSION_STRING";
     private static final String KEY_ACCOUNT = "ACCOUNT";
     private static final String KEY_SERVER_VALID = "SERVER_VALID";
     private static final String KEY_SERVER_CHECKED = "SERVER_CHECKED";
@@ -124,7 +124,6 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     
     private String mHostBaseUrl;
     private OwnCloudVersion mDiscoveredVersion;
-    private boolean mIsSharedSupported;
 
     private String mAuthMessageText;
     private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon;
@@ -235,20 +234,19 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             mServerIsChecked = false;
             mIsSslConn = false;
             mAuthStatusText = mAuthStatusIcon = 0;
-            mIsSharedSupported = false;
 
             /// retrieve extras from intent
             mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT);
             if (mAccount != null) {
                 String ocVersion = mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION);
+                String ocVersionString = mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION_STRING);
                 if (ocVersion != null) {
-                    mDiscoveredVersion = new OwnCloudVersion(ocVersion);
+                    mDiscoveredVersion = new OwnCloudVersion(ocVersion, ocVersionString);
                 }
                 mHostBaseUrl = normalizeUrl(mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL));
                 mHostUrlInput.setText(mHostBaseUrl);
                 String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));
                 mUsernameInput.setText(userName);
-                mIsSharedSupported = Boolean.getBoolean(mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API));
                 
             }
             initAuthorizationMethod();  // checks intent and setup.xml to determine mCurrentAuthorizationMethod
@@ -276,9 +274,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             
             /// server data
             String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);
-            mIsSharedSupported = savedInstanceState.getBoolean(KEY_IS_SHARED_SUPPORTED, false);
+            String ocVersionString = savedInstanceState.getString(KEY_OC_VERSION_STRING);
             if (ocVersion != null) {
-                mDiscoveredVersion = new OwnCloudVersion(ocVersion);
+                mDiscoveredVersion = new OwnCloudVersion(ocVersion, ocVersionString);
             }
             mHostBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);
 
@@ -453,10 +451,10 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 
         /// server data
         if (mDiscoveredVersion != null) {
-            outState.putString(KEY_OC_VERSION, mDiscoveredVersion.toString());
+            outState.putString(KEY_OC_VERSION, mDiscoveredVersion.getVersion());
+            outState.putString(KEY_OC_VERSION_STRING, mDiscoveredVersion.getVersionString());
         }
         outState.putString(KEY_HOST_URL_TEXT, mHostBaseUrl);
-        outState.putBoolean(KEY_IS_SHARED_SUPPORTED, mIsSharedSupported);
 
         /// account data, if updating
         if (mAccount != null) {
@@ -591,7 +589,6 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         
         mServerIsValid = false;
         mServerIsChecked = false;
-        mIsSharedSupported = false;
         mOkButton.setEnabled(false);
         mDiscoveredVersion = null;
         hideRefreshButton();
@@ -906,9 +903,6 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             /// allow or not the user try to access the server
             mOkButton.setEnabled(mServerIsValid);
             
-            /// retrieve if is supported the Share API
-            mIsSharedSupported = operation.isSharedSupported();
-
         }   // else nothing ; only the last check operation is considered; 
         // multiple can be triggered if the user amends a URL before a previous check can be triggered
     }
@@ -1299,9 +1293,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
             }
             /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA
-            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION,    mDiscoveredVersion.toString());
+            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION,         mDiscoveredVersion.getVersion());
+            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION_STRING,  mDiscoveredVersion.getVersionString());
             mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL,   mHostBaseUrl);
-            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API, Boolean.toString(mIsSharedSupported));
             if (isSaml) {
                 mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); 
             } else if (isOAuth) {

+ 5 - 1
src/com/owncloud/android/files/FileOperationsHelper.java

@@ -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;
     }

+ 4 - 1
src/com/owncloud/android/files/services/FileUploader.java

@@ -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;

+ 19 - 4
src/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -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;

+ 14 - 4
src/com/owncloud/android/operations/UpdateOCVersionOperation.java

@@ -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;
+    }
+
 }

+ 4 - 5
src/com/owncloud/android/syncadapter/FileSyncAdapter.java

@@ -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()