diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java index 056efc779e2..de86bd5b692 100644 --- a/src/com/android/settings/dashboard/DashboardFragment.java +++ b/src/com/android/settings/dashboard/DashboardFragment.java @@ -299,15 +299,15 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment if (mSummaryLoader != null) { mSummaryLoader.release(); } - final Activity activity = getActivity(); - mSummaryLoader = new SummaryLoader(activity, getCategoryKey()); + final Context context = getContext(); + mSummaryLoader = new SummaryLoader(getActivity(), getCategoryKey()); mSummaryLoader.setSummaryConsumer(this); - final TypedArray a = activity.obtainStyledAttributes(new int[] { + final TypedArray a = context.obtainStyledAttributes(new int[] { mDashboardFeatureProvider.isEnabled() ? android.R.attr.colorControlNormal : android.R.attr.colorAccent}); - final int tintColor = a.getColor(0, activity.getColor(android.R.color.white)); + final int tintColor = a.getColor(0, context.getColor(android.R.color.white)); a.recycle(); - final String pkgName = activity.getPackageName(); + final String pkgName = context.getPackageName(); // Install dashboard tiles. for (Tile tile : tiles) { final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile); @@ -318,7 +318,8 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment if (!displayTile(tile)) { continue; } - if (!pkgName.equals(tile.intent.getComponent().getPackageName())) { + if (pkgName != null && tile.intent != null + && !pkgName.equals(tile.intent.getComponent().getPackageName())) { // If this drawable is coming from outside Settings, tint it to match the color. tile.icon.setTint(tintColor); } @@ -326,12 +327,12 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment // Have the key already, will rebind. final Preference preference = mProgressiveDisclosureMixin.findPreference( screen, key); - mDashboardFeatureProvider.bindPreferenceToTile(activity, preference, tile, key, + mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), preference, tile, key, mPlaceholderPreferenceController.getOrder()); } else { // Don't have this key, add it. final Preference pref = new Preference(getPrefContext()); - mDashboardFeatureProvider.bindPreferenceToTile(activity, pref, tile, key, + mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), pref, tile, key, mPlaceholderPreferenceController.getOrder()); mProgressiveDisclosureMixin.addPreference(screen, pref); mDashboardTilePrefKeys.add(key); diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java index f4772020bff..d479e0ab4bd 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java @@ -79,6 +79,7 @@ public class DashboardFragmentTest { when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(anyString())) .thenReturn(mDashboardCategory); mTestFragment.onAttach(ShadowApplication.getInstance().getApplicationContext()); + when(mContext.getPackageName()).thenReturn("TestPackage"); } @Test