From 5245f945af4b95ec9cb3b4beb3b4dab0ef22f3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Klas=C3=A9n?= Date: Tue, 9 Nov 2010 11:52:06 +0100 Subject: Fixed system-crash when displaying account-list. Catch exception thrown when icon/label is not set in account authenticator. Change-Id: Ie133a84c802e6d72f8a1ffd9202bcce48e60ba17 --- .../android/settings/AccountPreferenceBase.java | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/com/android/settings/AccountPreferenceBase.java b/src/com/android/settings/AccountPreferenceBase.java index 520b9d7..c1b3c41 100644 --- a/src/com/android/settings/AccountPreferenceBase.java +++ b/src/com/android/settings/AccountPreferenceBase.java @@ -31,6 +31,7 @@ import android.content.Context; import android.content.SyncAdapterType; import android.content.SyncStatusObserver; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; @@ -132,12 +133,16 @@ class AccountPreferenceBase extends PreferenceActivity implements OnAccountsUpda protected Drawable getDrawableForType(final String accountType) { Drawable icon = null; if (mTypeToAuthDescription.containsKey(accountType)) { + AuthenticatorDescription desc = null; try { - AuthenticatorDescription desc = (AuthenticatorDescription) - mTypeToAuthDescription.get(accountType); - Context authContext = createPackageContext(desc.packageName, 0); - icon = authContext.getResources().getDrawable(desc.iconId); + desc = (AuthenticatorDescription)mTypeToAuthDescription.get(accountType); + if (desc != null) { + Context authContext = createPackageContext(desc.packageName, 0); + icon = authContext.getResources().getDrawable(desc.iconId); + } } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, "failed createPackageContext for account type " + accountType); + } catch (Resources.NotFoundException e) { // TODO: place holder icon for missing account icons? Log.w(TAG, "No icon for account type " + accountType); } @@ -153,14 +158,18 @@ class AccountPreferenceBase extends PreferenceActivity implements OnAccountsUpda protected CharSequence getLabelForType(final String accountType) { CharSequence label = null; if (mTypeToAuthDescription.containsKey(accountType)) { - try { - AuthenticatorDescription desc = (AuthenticatorDescription) - mTypeToAuthDescription.get(accountType); - Context authContext = createPackageContext(desc.packageName, 0); - label = authContext.getResources().getText(desc.labelId); - } catch (PackageManager.NameNotFoundException e) { - Log.w(TAG, "No label for account type " + ", type " + accountType); - } + AuthenticatorDescription desc = null; + try { + desc = (AuthenticatorDescription)mTypeToAuthDescription.get(accountType); + if (desc != null) { + Context authContext = createPackageContext(desc.packageName, 0); + label = authContext.getResources().getText(desc.labelId); + } + } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, "failed createPackageContext for account type " + accountType); + } catch (Resources.NotFoundException e) { + Log.w(TAG, "No label for account type " + accountType); + } } return label; } -- cgit v1.2.3