diff options
author | Tobias Kaminsky <tobiasKaminsky@users.noreply.github.com> | 2017-09-11 10:07:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-11 10:07:54 +0300 |
commit | 7afa1966a52eecc28294139adc2724e25c1bb9de (patch) | |
tree | 8b29f16ce7b416d18688009b033ebf1811b4c168 | |
parent | 620d18d7a8482275d59d52d5908cb40df5237e2b (diff) | |
parent | 3cbcd28406e1127a87a6d055e3869f3b5749929d (diff) |
Merge pull request #1505 from nextcloud/improve-authenticationrc-2.0.0-06
Fix for authentication/favorite/etc
9 files changed, 49 insertions, 142 deletions
diff --git a/build.gradle b/build.gradle index 527aac2327..0c2782d4ef 100644 --- a/build.gradle +++ b/build.gradle @@ -184,7 +184,7 @@ dependencies { /// dependencies for app building implementation name: 'touch-image-view' implementation 'com.android.support:multidex:1.0.2' - implementation 'com.github.nextcloud:android-library:1.0.28' + compile 'com.github.nextcloud:android-library:1.0.30' implementation "com.android.support:support-v4:${supportLibraryVersion}" implementation "com.android.support:design:${supportLibraryVersion}" implementation 'com.jakewharton:disklrucache:2.0.2' diff --git a/scripts/lint/lint-results.txt b/scripts/lint/lint-results.txt index e67c4cbda4..00f8637331 100644 --- a/scripts/lint/lint-results.txt +++ b/scripts/lint/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - <span class="mdl-layout-title">Lint Report: 1 error and 513 warnings</span> + <span class="mdl-layout-title">Lint Report: 1 error and 512 warnings</span> diff --git a/src/main/java/com/owncloud/android/authentication/AccountUtils.java b/src/main/java/com/owncloud/android/authentication/AccountUtils.java index 2dd094be02..b307c4604a 100644 --- a/src/main/java/com/owncloud/android/authentication/AccountUtils.java +++ b/src/main/java/com/owncloud/android/authentication/AccountUtils.java @@ -24,22 +24,16 @@ import android.accounts.Account; import android.accounts.AccountManager;
import android.content.Context;
import android.content.SharedPreferences;
-import android.net.Uri;
import android.preference.PreferenceManager;
import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.FileDataStorageManager;
-import com.owncloud.android.lib.common.OwnCloudAccount;
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
-import com.owncloud.android.lib.common.UserInfo;
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
-import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation;
import com.owncloud.android.operations.GetCapabilitiesOperarion;
import com.owncloud.android.ui.activity.ManageAccountsActivity;
@@ -228,126 +222,7 @@ public class AccountUtils { return null;
}
-
- /**
- * Update the accounts in AccountManager to meet the current version of accounts expected by the app, if needed.
- *
- * Introduced to handle a change in the structure of stored account names needed to allow different OC servers
- * in the same domain, but not in the same path.
- *
- * @param context Used to access the AccountManager.
- */
- public static void updateAccountVersion(Context context) {
- Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(context);
- AccountManager accountMgr = AccountManager.get(context);
-
- if ( currentAccount != null ) {
- String currentAccountVersion = accountMgr.getUserData(currentAccount, Constants.KEY_OC_ACCOUNT_VERSION);
-
- if (!String.valueOf(ACCOUNT_VERSION_WITH_PROPER_ID).equalsIgnoreCase(currentAccountVersion)) {
- Log_OC.i(TAG, "Upgrading accounts to account version #" + ACCOUNT_VERSION_WITH_PROPER_ID);
- Account[] ocAccounts = accountMgr.getAccountsByType(MainApp.getAccountType());
- String serverUrl;
- String username;
- String newAccountName;
- String password;
- Account newAccount;
- for (Account account : ocAccounts) {
- // build new account name
- serverUrl = accountMgr.getUserData(account, Constants.KEY_OC_BASE_URL);
-
- // update user name
- try {
- OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
- OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton()
- .getClientFor(ocAccount, context);
-
- GetRemoteUserInfoOperation remoteUserNameOperation = new GetRemoteUserInfoOperation();
- RemoteOperationResult result = remoteUserNameOperation.execute(client);
-
- if (result.isSuccess()) {
- UserInfo userInfo = (UserInfo) result.getData().get(0);
- username = userInfo.id;
- } else {
- // skip account, try it next time
- Log_OC.e(TAG, "Error while getting username for account: " + account.name);
- continue;
- }
- } catch (Exception e) {
- Log_OC.e(TAG, "Error while getting username: " + e.getMessage());
- continue;
- }
-
- newAccountName = com.owncloud.android.lib.common.accounts.AccountUtils.
- buildAccountName(Uri.parse(serverUrl), username);
-
- // migrate to a new account, if needed
- if (!newAccountName.equals(account.name)) {
- Log_OC.d(TAG, "Upgrading " + account.name + " to " + newAccountName);
-
- // create the new account
- newAccount = new Account(newAccountName, MainApp.getAccountType());
- password = accountMgr.getPassword(account);
- accountMgr.addAccountExplicitly(newAccount, (password != null) ? password : "", null);
-
- // copy base URL
- accountMgr.setUserData(newAccount, Constants.KEY_OC_BASE_URL, serverUrl);
-
- // copy server version
- accountMgr.setUserData(
- newAccount,
- Constants.KEY_OC_VERSION,
- accountMgr.getUserData(account, Constants.KEY_OC_VERSION)
- );
-
- // copy cookies
- accountMgr.setUserData(
- newAccount,
- Constants.KEY_COOKIES,
- accountMgr.getUserData(account, Constants.KEY_COOKIES)
- );
-
- // copy type of authentication
- final String isSamlStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO);
- if (Boolean.parseBoolean(isSamlStr)) {
- accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");
- }
-
- final String isOauthStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2);
- if (Boolean.parseBoolean(isOauthStr)) {
- accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE");
- }
- /* TODO - study if it's possible to run this method in a background thread to copy the authToken
- if (isOAuth || isSaml) {
- accountMgr.setAuthToken(newAccount, mAuthTokenType, mAuthToken);
- }
- */
-
- // don't forget the account saved in preferences as the current one
- if (currentAccount.name.equals(account.name)) {
- AccountUtils.setCurrentOwnCloudAccount(context, newAccountName);
- }
-
- // remove the old account
- accountMgr.removeAccount(account, null, null);
- // will assume it succeeds, not a big deal otherwise
-
- } else {
- // servers which base URL is in the root of their domain need no change
- Log_OC.d(TAG, account.name + " needs no upgrade ");
- newAccount = account;
- }
-
- // at least, upgrade account version
- Log_OC.d(TAG, "Setting version " + ACCOUNT_VERSION_WITH_PROPER_ID + " to " + newAccountName);
- accountMgr.setUserData(newAccount,
- Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(ACCOUNT_VERSION_WITH_PROPER_ID));
- }
- }
- }
- }
-
-
+
public static String trimWebdavSuffix(String url) {
while(url.endsWith("/")) {
url = url.substring(0, url.length() - 1);
diff --git a/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index 4d93f24c58..7fb6da6910 100644 --- a/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -1914,6 +1914,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (isOAuth) {
username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();
}
+
String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.
buildAccountName(uri, username);
Account newAccount = new Account(accountName, MainApp.getAccountType());
@@ -1979,12 +1980,17 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mAccountMgr.setUserData(
mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl
);
+
if (authResult.getData() != null) {
try {
UserInfo userInfo = (UserInfo) authResult.getData().get(0);
mAccountMgr.setUserData(
mAccount, Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName()
);
+
+ mAccountMgr.setUserData(
+ mAccount, Constants.KEY_USER_ID, userInfo.getId()
+ );
} catch (ClassCastException c) {
Log_OC.w(TAG, "Couldn't get display name for " + username);
}
diff --git a/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java b/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java index 9bdcd75ace..da933ca336 100644 --- a/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java +++ b/src/main/java/com/owncloud/android/operations/GetUserProfileOperation.java @@ -65,6 +65,12 @@ public class GetUserProfileOperation extends SyncOperation { AccountUtils.Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName() ); + + accountManager.setUserData( + storedAccount, + AccountUtils.Constants.KEY_USER_ID, + userInfo.getId() + ); } return result; } diff --git a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 4042fb0eb0..e5b49d0445 100644 --- a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -39,6 +39,7 @@ import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.text.Html; +import android.text.TextUtils; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -932,8 +933,18 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU // set user space information Thread t = new Thread(new Runnable() { public void run() { + AccountManager mAccountMgr = AccountManager.get(MainApp.getAppContext()); + + String userId = mAccountMgr.getUserData(AccountUtils.getCurrentOwnCloudAccount(DrawerActivity.this), + com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID); + + RemoteOperation getQuotaInfoOperation; + if (TextUtils.isEmpty(userId)) { + getQuotaInfoOperation = new GetRemoteUserInfoOperation(); + } else { + getQuotaInfoOperation = new GetRemoteUserInfoOperation(userId); + } - RemoteOperation getQuotaInfoOperation = new GetRemoteUserInfoOperation(); RemoteOperationResult result = getQuotaInfoOperation.execute( AccountUtils.getCurrentOwnCloudAccount(DrawerActivity.this), DrawerActivity.this); @@ -941,6 +952,15 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU final UserInfo userInfo = (UserInfo) result.getData().get(0); final Quota quota = userInfo.getQuota(); + // Since we always call this method, might as well put it here + if (userInfo.getId() != null) { + mAccountMgr.setUserData( + AccountUtils.getCurrentOwnCloudAccount(DrawerActivity.this), + com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID, + userInfo.getId() + ); + } + if (quota != null) { final long used = quota.getUsed(); final long total = quota.getTotal(); diff --git a/src/main/java/com/owncloud/android/ui/activity/FileActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileActivity.java index 2eb942d5ce..63d3ad96f8 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileActivity.java @@ -38,7 +38,6 @@ import android.widget.Toast; import com.owncloud.android.MainApp; import com.owncloud.android.R; -import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; @@ -156,15 +155,6 @@ public abstract class FileActivity extends DrawerActivity false); } - Thread t = new Thread(new Runnable() { - @Override - public void run() { - // best place, before any access to AccountManager or database - AccountUtils.updateAccountVersion(getApplicationContext()); - } - }); - t.start(); - setAccount(account, savedInstanceState != null); mOperationsServiceConnection = new OperationsServiceConnection(); diff --git a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java index 6c3532f672..2855c16ec9 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -22,6 +22,7 @@ package com.owncloud.android.ui.fragment; import android.accounts.Account; +import android.accounts.AccountManager; import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.app.Activity; @@ -40,6 +41,7 @@ import android.support.design.widget.BottomNavigationView; import android.support.design.widget.Snackbar; import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; +import android.text.TextUtils; import android.util.SparseBooleanArray; import android.view.ActionMode; import android.view.LayoutInflater; @@ -1415,6 +1417,8 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext()); OwnCloudAccount ocAccount = null; + AccountManager mAccountMgr = AccountManager.get(getActivity()); + try { ocAccount = new OwnCloudAccount( currentAccount, @@ -1424,8 +1428,15 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton(). getClientFor(ocAccount, MainApp.getAppContext()); + String userId = mAccountMgr.getUserData(currentAccount, + com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID); + + if (TextUtils.isEmpty(userId)) { + userId = mClient.getCredentials().getUsername(); + } + ToggleFavoriteOperation toggleFavoriteOperation = new ToggleFavoriteOperation(event.shouldFavorite, - event.remotePath); + event.remotePath, userId); RemoteOperationResult remoteOperationResult = toggleFavoriteOperation.execute(mClient); if (remoteOperationResult.isSuccess()) { diff --git a/src/main/res/values/styles.xml b/src/main/res/values/styles.xml index 2cade42050..5e8af5bb78 100644 --- a/src/main/res/values/styles.xml +++ b/src/main/res/values/styles.xml @@ -256,5 +256,4 @@ </style> <style name="NextcloudTextAppearanceSmall" parent="style/TextAppearance.AppCompat.Small"> </style> - <style name="Test" parent=""/> -</resources>
\ No newline at end of file +</resources> |