summaryrefslogtreecommitdiffstats
path: root/core/java/android/accounts
diff options
context:
space:
mode:
authorFred Quintana <fredq@google.com>2011-06-23 16:37:58 -0700
committerFred Quintana <fredq@google.com>2011-06-23 17:03:44 -0700
commit5d1a0c3933253d66a9c230ea1da051a7626937d4 (patch)
tree2b8d170b0904178f5f4aa621f96217f629dc9c48 /core/java/android/accounts
parent58b868417755805ebdfe4feb65664ad98c00bf35 (diff)
downloadframeworks_base-5d1a0c3933253d66a9c230ea1da051a7626937d4.zip
frameworks_base-5d1a0c3933253d66a9c230ea1da051a7626937d4.tar.gz
frameworks_base-5d1a0c3933253d66a9c230ea1da051a7626937d4.tar.bz2
Make the AbstractAccountAuthenticator return an error to the AccountManagerService
if it detects a RuntimeException. Bug: 4726899 Change-Id: I5c478464cd0d426722257b2c5c75f964cd839ea6
Diffstat (limited to 'core/java/android/accounts')
-rw-r--r--core/java/android/accounts/AbstractAccountAuthenticator.java118
1 files changed, 45 insertions, 73 deletions
diff --git a/core/java/android/accounts/AbstractAccountAuthenticator.java b/core/java/android/accounts/AbstractAccountAuthenticator.java
index c0c4c17..7183267 100644
--- a/core/java/android/accounts/AbstractAccountAuthenticator.java
+++ b/core/java/android/accounts/AbstractAccountAuthenticator.java
@@ -24,7 +24,6 @@ import android.content.pm.PackageManager;
import android.content.Context;
import android.content.Intent;
import android.Manifest;
-import android.text.TextUtils;
import android.util.Log;
import java.util.Arrays;
@@ -136,17 +135,8 @@ public abstract class AbstractAccountAuthenticator {
if (result != null) {
response.onResult(result);
}
- } catch (NetworkErrorException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "addAccount", e);
- }
- response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
- } catch (UnsupportedOperationException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "addAccount", e);
- }
- response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
- "addAccount not supported");
+ } catch (Exception e) {
+ handleException(response, "addAccount", accountType, e);
}
}
@@ -167,17 +157,8 @@ public abstract class AbstractAccountAuthenticator {
if (result != null) {
response.onResult(result);
}
- } catch (NetworkErrorException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "confirmCredentials", e);
- }
- response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
- } catch (UnsupportedOperationException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "confirmCredentials", e);
- }
- response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
- "confirmCredentials not supported");
+ } catch (Exception e) {
+ handleException(response, "confirmCredentials", account.toString(), e);
}
}
@@ -197,21 +178,9 @@ public abstract class AbstractAccountAuthenticator {
Log.v(TAG, "getAuthTokenLabel: result "
+ AccountManager.sanitizeResult(result));
}
- if (result != null) {
- response.onResult(result);
- }
- } catch (IllegalArgumentException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "getAuthTokenLabel", e);
- }
- response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
- "unknown authTokenType");
- } catch (UnsupportedOperationException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "getAuthTokenLabel", e);
- }
- response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
- "getAuthTokenTypeLabel not supported");
+ response.onResult(result);
+ } catch (Exception e) {
+ handleException(response, "getAuthTokenLabel", authTokenType, e);
}
}
@@ -234,17 +203,9 @@ public abstract class AbstractAccountAuthenticator {
if (result != null) {
response.onResult(result);
}
- } catch (UnsupportedOperationException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "getAuthToken", e);
- }
- response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
- "getAuthToken not supported");
- } catch (NetworkErrorException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "getAuthToken", e);
- }
- response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
+ } catch (Exception e) {
+ handleException(response, "getAuthToken",
+ account.toString() + "," + authTokenType, e);
}
}
@@ -267,17 +228,9 @@ public abstract class AbstractAccountAuthenticator {
if (result != null) {
response.onResult(result);
}
- } catch (NetworkErrorException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "updateCredentials", e);
- }
- response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
- } catch (UnsupportedOperationException e) {
- if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "updateCredentials", e);
- }
- response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
- "updateCredentials not supported");
+ } catch (Exception e) {
+ handleException(response, "updateCredentials",
+ account.toString() + "," + authTokenType, e);
}
}
@@ -290,9 +243,8 @@ public abstract class AbstractAccountAuthenticator {
if (result != null) {
response.onResult(result);
}
- } catch (UnsupportedOperationException e) {
- response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
- "editProperties not supported");
+ } catch (Exception e) {
+ handleException(response, "editProperties", accountType, e);
}
}
@@ -305,11 +257,8 @@ public abstract class AbstractAccountAuthenticator {
if (result != null) {
response.onResult(result);
}
- } catch (UnsupportedOperationException e) {
- response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
- "hasFeatures not supported");
- } catch (NetworkErrorException e) {
- response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
+ } catch (Exception e) {
+ handleException(response, "hasFeatures", account.toString(), e);
}
}
@@ -322,12 +271,35 @@ public abstract class AbstractAccountAuthenticator {
if (result != null) {
response.onResult(result);
}
- } catch (UnsupportedOperationException e) {
- response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
- "getAccountRemovalAllowed not supported");
- } catch (NetworkErrorException e) {
- response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
+ } catch (Exception e) {
+ handleException(response, "getAccountRemovalAllowed", account.toString(), e);
+ }
+ }
+ }
+
+ private void handleException(IAccountAuthenticatorResponse response, String method,
+ String data, Exception e) throws RemoteException {
+ if (e instanceof NetworkErrorException) {
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, method + "(" + data + ")", e);
+ }
+ response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
+ } else if (e instanceof UnsupportedOperationException) {
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, method + "(" + data + ")", e);
+ }
+ response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
+ method + " not supported");
+ } else if (e instanceof IllegalArgumentException) {
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, method + "(" + data + ")", e);
}
+ response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
+ method + " not supported");
+ } else {
+ Log.w(TAG, method + "(" + data + ")", e);
+ response.onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION,
+ method + " failed");
}
}