From: David A. Velasco Date: Wed, 19 Feb 2014 11:28:24 +0000 (+0100) Subject: Version server is checked every time the root folder is refreshed, and both version... X-Git-Tag: oc-android-1.5.5~35^2~5 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/7a4ac199930a37c73b76e76003a86a8978b65f0b?ds=inline;hp=-c Version server is checked every time the root folder is refreshed, and both version and versionstring are in the server are saved locally --- 7a4ac199930a37c73b76e76003a86a8978b65f0b diff --git a/owncloud-android-library b/owncloud-android-library index 1f6f9bcf..c3f43822 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 1f6f9bcf84837a72ef2a7a79b5af7bee6677facd +Subproject commit c3f438220061a302c7f6fd6c32da039efaeb541e diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 3a817d67..61e31b44 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/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) { diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 4b37a3ba..61fde2db 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/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; } diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index e9a4637a..0cffa28d 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/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 requestedUploads = new Vector(); String uploadKey = null; diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 11ce41e5..97641c62 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/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; diff --git a/src/com/owncloud/android/operations/UpdateOCVersionOperation.java b/src/com/owncloud/android/operations/UpdateOCVersionOperation.java index a047f110..7fb123af 100644 --- a/src/com/owncloud/android/operations/UpdateOCVersionOperation.java +++ b/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; + } + } diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index 6b2ea73e..87177c43 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java +++ b/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()