From: David A. Velasco Date: Tue, 10 Feb 2015 09:29:51 +0000 (+0100) Subject: App updated to OwnCloudAccount with deferred load of credentials X-Git-Tag: oc-android-1.7.1_signed^2~42^2~4^2^2~2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/b5d70ad8e793f27324aeb3af6597dd51a3a051ee App updated to OwnCloudAccount with deferred load of credentials --- diff --git a/owncloud-android-library b/owncloud-android-library index 2f178c9c..f5fe254c 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 2f178c9c34e3dab507c46e718705913ed44db3c5 +Subproject commit f5fe254c0929a0e225ad3806082e0e1a8cfb8803 diff --git a/res/values/strings.xml b/res/values/strings.xml index 296a8e0e..1ad9d8d3 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -193,6 +193,7 @@ Your server is not returning a correct user id, please contact an administrator Cannot authenticate against this server + Account does not exist in the device yet Keep file up to date Rename diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 03f65854..0c735401 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -70,6 +70,7 @@ import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientList import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.accounts.AccountTypeUtils; +import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; import com.owncloud.android.lib.common.network.CertificateCombinedException; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; @@ -1000,8 +1001,15 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity showAuthStatus(); Log_OC.d(TAG, result.getLogMessage()); } else { - updateAccountAuthentication(); - success = true; + try { + updateAccountAuthentication(); + success = true; + + } catch (AccountNotFoundException e) { + Log_OC.e(TAG, "Account " + mAccount + " was removed!", e); + Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show(); + finish(); + } } } @@ -1367,8 +1375,15 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity success = createAccount(); } else { - updateAccountAuthentication(); - success = true; + try { + updateAccountAuthentication(); + success = true; + + } catch (AccountNotFoundException e) { + Log_OC.e(TAG, "Account " + mAccount + " was removed!", e); + Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show(); + finish(); + } } if (success) { @@ -1417,16 +1432,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * Kills the session kept by OwnCloudClientManager so that a new one will created with * the new credentials when needed. */ - private void updateAccountAuthentication() { - - try { - OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor( - new OwnCloudAccount(mAccount, this) // TODO avoid this creation may block the main thread - ); - } catch (Exception e) { - e.printStackTrace(); - } + private void updateAccountAuthentication() throws AccountNotFoundException { + OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor( + new OwnCloudAccount(mAccount, this) + ); Bundle response = new Bundle(); response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name); diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index ef9de9ea..18b87cae 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1110,40 +1110,34 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { (synchResult.isException() && synchResult.getException() instanceof AuthenticatorException))) { - OwnCloudClient client = null; + try { - OwnCloudAccount ocAccount = + OwnCloudClient client; + OwnCloudAccount ocAccount = new OwnCloudAccount(getAccount(), context); client = (OwnCloudClientManagerFactory.getDefaultSingleton(). removeClientFor(ocAccount)); - // TODO get rid of these exceptions - } catch (AccountNotFoundException e) { - e.printStackTrace(); - } catch (AuthenticatorException e) { - e.printStackTrace(); - } catch (OperationCanceledException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - if (client != null) { - OwnCloudCredentials cred = client.getCredentials(); - if (cred != null) { - AccountManager am = AccountManager.get(context); - if (cred.authTokenExpires()) { - am.invalidateAuthToken( - getAccount().type, - cred.getAuthToken() - ); - } else { - am.clearPassword(getAccount()); + + if (client != null) { + OwnCloudCredentials cred = client.getCredentials(); + if (cred != null) { + AccountManager am = AccountManager.get(context); + if (cred.authTokenExpires()) { + am.invalidateAuthToken( + getAccount().type, + cred.getAuthToken() + ); + } else { + am.clearPassword(getAccount()); + } } } + requestCredentialsUpdate(); + + } catch (AccountNotFoundException e) { + Log_OC.e(TAG, "Account " + getAccount() + " was removed!", e); } - - requestCredentialsUpdate(); - + } } removeStickyBroadcast(intent); diff --git a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java index e4b1886c..1c295377 100644 --- a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java +++ b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java @@ -489,40 +489,33 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C (synchResult.isException() && synchResult.getException() instanceof AuthenticatorException))) { - OwnCloudClient client = null; try { - OwnCloudAccount ocAccount = + OwnCloudClient client; + OwnCloudAccount ocAccount = new OwnCloudAccount(getAccount(), context); client = (OwnCloudClientManagerFactory.getDefaultSingleton(). removeClientFor(ocAccount)); - // TODO get rid of these exceptions - } catch (AccountNotFoundException e) { - e.printStackTrace(); - } catch (AuthenticatorException e) { - e.printStackTrace(); - } catch (OperationCanceledException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - if (client != null) { - OwnCloudCredentials cred = client.getCredentials(); - if (cred != null) { - AccountManager am = AccountManager.get(context); - if (cred.authTokenExpires()) { - am.invalidateAuthToken( - getAccount().type, - cred.getAuthToken() - ); - } else { - am.clearPassword(getAccount()); + + if (client != null) { + OwnCloudCredentials cred = client.getCredentials(); + if (cred != null) { + AccountManager am = AccountManager.get(context); + if (cred.authTokenExpires()) { + am.invalidateAuthToken( + getAccount().type, + cred.getAuthToken() + ); + } else { + am.clearPassword(getAccount()); + } } } + requestCredentialsUpdate(); + + } catch (AccountNotFoundException e) { + Log_OC.e(TAG, "Account " + getAccount() + " was removed!", e); } - - requestCredentialsUpdate(); - + } } removeStickyBroadcast(intent);