From 08875fe1e5c40146b3137c2c92f44df6c5d336f1 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 4 Aug 2017 11:54:34 +0200 Subject: [PATCH 1/2] update user name with correct id found by user ocs call --- .../android/authentication/AccountUtils.java | 45 ++++++++++++++----- .../android/ui/activity/FileActivity.java | 11 +++-- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/owncloud/android/authentication/AccountUtils.java b/src/main/java/com/owncloud/android/authentication/AccountUtils.java index 0ae1db823d..2dd094be02 100644 --- a/src/main/java/com/owncloud/android/authentication/AccountUtils.java +++ b/src/main/java/com/owncloud/android/authentication/AccountUtils.java @@ -30,13 +30,18 @@ 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.ui.activity.ManageAccountsActivity; +import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation; import com.owncloud.android.operations.GetCapabilitiesOperarion; +import com.owncloud.android.ui.activity.ManageAccountsActivity; import java.util.Locale; @@ -51,6 +56,7 @@ public class AccountUtils { public static final String STATUS_PATH = "/status.php"; public static final int ACCOUNT_VERSION = 1; + public static final int ACCOUNT_VERSION_WITH_PROPER_ID = 2; /** * Can be used to get the currently selected ownCloud {@link Account} in the @@ -238,8 +244,8 @@ public class AccountUtils { if ( currentAccount != null ) { String currentAccountVersion = accountMgr.getUserData(currentAccount, Constants.KEY_OC_ACCOUNT_VERSION); - if (currentAccountVersion == null) { - Log_OC.i(TAG, "Upgrading accounts to account version #" + 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; @@ -249,8 +255,29 @@ public class AccountUtils { for (Account account : ocAccounts) { // build new account name serverUrl = accountMgr.getUserData(account, Constants.KEY_OC_BASE_URL); - username = com.owncloud.android.lib.common.accounts.AccountUtils. - getUsernameForAccount(account); + + // 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); @@ -312,11 +339,9 @@ public class AccountUtils { } // at least, upgrade account version - Log_OC.d(TAG, "Setting version " + ACCOUNT_VERSION + " to " + newAccountName); - accountMgr.setUserData( - newAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(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)); } } } 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 7d181d7772..6c11ccc1ac 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileActivity.java @@ -40,7 +40,6 @@ 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.ArbitraryDataProvider; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; @@ -157,8 +156,14 @@ public abstract class FileActivity extends DrawerActivity false); } - AccountUtils.updateAccountVersion(this); // best place, before any access to AccountManager - // or database + 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); From 2e5fc5668d635100d8722e823078733cb31edebc Mon Sep 17 00:00:00 2001 From: nextcloud-android-bot <> Date: Fri, 4 Aug 2017 10:28:43 +0000 Subject: [PATCH 2/2] Drone: update Lint results to reflect reduced error/warning count [skip ci] --- scripts/lint/lint-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint/lint-results.txt b/scripts/lint/lint-results.txt index 545c1e1378..616755235c 100644 --- a/scripts/lint/lint-results.txt +++ b/scripts/lint/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 32 errors and 678 warnings + Lint Report: 32 errors and 676 warnings