From 46703b099516c383a6882815bcf9cd4df0ec538d Mon Sep 17 00:00:00 2001 From: Brian Carlstrom Date: Wed, 6 Apr 2011 15:41:29 -0700 Subject: [PATCH] Tolerate missing AccountManager resource, not just missing resource name In addition to the primary change in the subject, also some minor cleanup of javadoc, typos, CloseGuard warning, etc found while working on a new AbstractAccountAuthenticator. Change-Id: I73f3408773a43a0021a15f8d051fd3dbbdf898a5 --- .../AccountAuthenticatorActivity.java | 2 +- .../java/android/accounts/AccountManager.java | 3 ++- .../accounts/AccountManagerService.java | 12 ++++++++---- .../accounts/ChooseAccountActivity.java | 8 +++++++- .../GrantCredentialsPermissionActivity.java | 17 +++++++++++++++-- .../com/android/internal/os/ZygoteInit.java | 3 +++ core/jni/AndroidRuntime.cpp | 2 +- keystore/java/android/security/KeyStore.java | 19 ++++++------------- 8 files changed, 43 insertions(+), 23 deletions(-) diff --git a/core/java/android/accounts/AccountAuthenticatorActivity.java b/core/java/android/accounts/AccountAuthenticatorActivity.java index 5cce6da6d0ca6..6a55ddfd78619 100644 --- a/core/java/android/accounts/AccountAuthenticatorActivity.java +++ b/core/java/android/accounts/AccountAuthenticatorActivity.java @@ -26,7 +26,7 @@ import android.os.Bundle; * to handle the request then it can have the activity extend AccountAuthenticatorActivity. * The AbstractAccountAuthenticator passes in the response to the intent using the following: *
- *      intent.putExtra(Constants.ACCOUNT_AUTHENTICATOR_RESPONSE_KEY, response);
+ *      intent.putExtra({@link AccountManager#KEY_ACCOUNT_AUTHENTICATOR_RESPONSE}, response);
  * 
* The activity then sets the result that is to be handed to the response via * {@link #setAccountAuthenticatorResult(android.os.Bundle)}. diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java index 5bdc79d054b11..2156425f8e51d 100644 --- a/core/java/android/accounts/AccountManager.java +++ b/core/java/android/accounts/AccountManager.java @@ -179,6 +179,7 @@ public class AccountManager { public static final String KEY_PASSWORD = "password"; public static final String KEY_ACCOUNTS = "accounts"; + public static final String KEY_ACCOUNT_AUTHENTICATOR_RESPONSE = "accountAuthenticatorResponse"; public static final String KEY_ACCOUNT_MANAGER_RESPONSE = "accountManagerResponse"; public static final String KEY_AUTHENTICATOR_TYPES = "authenticator_types"; @@ -1269,7 +1270,7 @@ public class AccountManager { /** Handles the responses from the AccountManager */ private class Response extends IAccountManagerResponse.Stub { public void onResult(Bundle bundle) { - Intent intent = bundle.getParcelable("intent"); + Intent intent = bundle.getParcelable(KEY_INTENT); if (intent != null && mActivity != null) { // since the user provided an Activity we will silently start intents // that we see diff --git a/core/java/android/accounts/AccountManagerService.java b/core/java/android/accounts/AccountManagerService.java index 93983a6d55a93..20d5b96933a2a 100644 --- a/core/java/android/accounts/AccountManagerService.java +++ b/core/java/android/accounts/AccountManagerService.java @@ -37,6 +37,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.RegisteredServicesCache; import android.content.pm.RegisteredServicesCacheListener; +import android.content.res.Resources; import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; @@ -73,8 +74,7 @@ import java.util.concurrent.atomic.AtomicReference; * accounts on the device. Some of these calls are implemented with the help of the corresponding * {@link IAccountAuthenticator} services. This service is not accessed by users directly, * instead one uses an instance of {@link AccountManager}, which can be accessed as follows: - * AccountManager accountManager = - * (AccountManager)context.getSystemService(Context.ACCOUNT_SERVICE) + * AccountManager accountManager = AccountManager.get(context); * @hide */ public class AccountManagerService @@ -1064,14 +1064,18 @@ public class AccountManagerService } catch (PackageManager.NameNotFoundException e) { throw new IllegalArgumentException("unknown account type: " + accountType); } - return authContext.getString(serviceInfo.type.labelId); + try { + return authContext.getString(serviceInfo.type.labelId); + } catch (Resources.NotFoundException e) { + throw new IllegalArgumentException("unknown account type: " + accountType); + } } private Intent newGrantCredentialsPermissionIntent(Account account, int uid, AccountAuthenticatorResponse response, String authTokenType, String authTokenLabel) { Intent intent = new Intent(mContext, GrantCredentialsPermissionActivity.class); - // See FLAT_ACTIVITY_NEW_TASK docs for limitations and benefits of the flag. + // See FLAG_ACTIVITY_NEW_TASK docs for limitations and benefits of the flag. // Since it was set in Eclair+ we can't change it without breaking apps using // the intent from a non-Activity context. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/core/java/android/accounts/ChooseAccountActivity.java b/core/java/android/accounts/ChooseAccountActivity.java index 293df782e2958..bfbae24dda917 100644 --- a/core/java/android/accounts/ChooseAccountActivity.java +++ b/core/java/android/accounts/ChooseAccountActivity.java @@ -18,6 +18,7 @@ package android.accounts; import android.app.Activity; import android.content.Context; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Parcelable; @@ -103,7 +104,12 @@ public class ChooseAccountActivity extends Activity { } catch (PackageManager.NameNotFoundException e) { // Nothing we can do much here, just log if (Log.isLoggable(TAG, Log.WARN)) { - Log.w(TAG, "No icon for account type " + accountType); + Log.w(TAG, "No icon name for account type " + accountType); + } + } catch (Resources.NotFoundException e) { + // Nothing we can do much here, just log + if (Log.isLoggable(TAG, Log.WARN)) { + Log.w(TAG, "No icon resource for account type " + accountType); } } } diff --git a/core/java/android/accounts/GrantCredentialsPermissionActivity.java b/core/java/android/accounts/GrantCredentialsPermissionActivity.java index 89eee6d4d36a9..0ee683cb7ee58 100644 --- a/core/java/android/accounts/GrantCredentialsPermissionActivity.java +++ b/core/java/android/accounts/GrantCredentialsPermissionActivity.java @@ -58,6 +58,12 @@ public class GrantCredentialsPermissionActivity extends Activity implements View mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Bundle extras = getIntent().getExtras(); + if (extras == null) { + // we were somehow started with bad parameters. abort the activity. + setResult(Activity.RESULT_CANCELED); + finish(); + return; + } // Grant 'account'/'type' to mUID mAccount = extras.getParcelable(EXTRAS_ACCOUNT); @@ -73,8 +79,15 @@ public class GrantCredentialsPermissionActivity extends Activity implements View return; } - final String accountTypeLabel = accountManagerService.getAccountLabel(mAccount.type); - + String accountTypeLabel; + try { + accountTypeLabel = accountManagerService.getAccountLabel(mAccount.type); + } catch (IllegalArgumentException e) { + // label or resource was missing. abort the activity. + setResult(Activity.RESULT_CANCELED); + finish(); + return; + } final TextView authTokenTypeView = (TextView) findViewById(R.id.authtoken_type); authTokenTypeView.setVisibility(View.GONE); diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 9b71a8b8b3547..a3d13ac412b47 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -32,6 +32,8 @@ import android.util.Log; import dalvik.system.VMRuntime; import dalvik.system.Zygote; +import libcore.io.IoUtils; + import java.io.BufferedReader; import java.io.FileDescriptor; import java.io.IOException; @@ -305,6 +307,7 @@ public class ZygoteInit { } catch (IOException e) { Log.e(TAG, "Error reading " + PRELOADED_CLASSES + ".", e); } finally { + IoUtils.closeQuietly(is); // Restore default. runtime.setTargetHeapUtilization(defaultUtilization); diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index 2a11c87fc24c8..f29d83e493cd7 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -907,7 +907,7 @@ void AndroidRuntime::start(const char* className, const bool startSystemServer) blockSigpipe(); /* - * 'startSystemServer == true' means runtime is obslete and not run from + * 'startSystemServer == true' means runtime is obsolete and not run from * init.rc anymore, so we print out the boot start event here. */ if (startSystemServer) { diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java index 4614b530e9959..7183688bd356c 100644 --- a/keystore/java/android/security/KeyStore.java +++ b/keystore/java/android/security/KeyStore.java @@ -23,10 +23,13 @@ import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.Charsets; import java.util.ArrayList; /** - * {@hide} + * @hide This should not be made public in its present form because it + * assumes that private and secret key bytes are available and would + * preclude the use of hardware crypto. */ public class KeyStore { public static final int NO_ERROR = 1; @@ -211,20 +214,10 @@ public class KeyStore { } private static byte[] getBytes(String string) { - try { - return string.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - // will never happen - throw new RuntimeException(e); - } + return string.getBytes(Charsets.UTF_8); } private static String toString(byte[] bytes) { - try { - return new String(bytes, "UTF-8"); - } catch (UnsupportedEncodingException e) { - // will never happen - throw new RuntimeException(e); - } + return new String(bytes, Charsets.UTF_8); } }