From c75174b3ee02053bc9e76d5f4bccc0961bedfe8b Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Thu, 19 Jul 2018 14:07:58 -0700 Subject: [PATCH] Clean up Tile related classes in settingslib. - Deleted a bunch of things nobody uses Bug: 77600770 Test: rebuild Change-Id: I432b5caea2588477eae3d44f6b58c4f72cfed227 --- .../settingslib/drawer/CategoryManager.java | 2 +- .../android/settingslib/drawer/TileUtils.java | 67 ++----------------- .../settingslib/drawer/TileUtilsTest.java | 21 +++--- 3 files changed, 15 insertions(+), 75 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java b/packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java index d9605367dc561..2bec1d740af21 100644 --- a/packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java @@ -125,7 +125,7 @@ public class CategoryManager { } mCategoryByKeyMap.clear(); mCategories = TileUtils.getCategories(context, mTileByComponentCache, - false /* categoryDefinedInManifest */, mExtraAction, settingPkg); + mExtraAction, settingPkg); for (DashboardCategory category : mCategories) { mCategoryByKeyMap.put(category.key, category); } diff --git a/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java b/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java index 96ed0cdb8ab52..76f24bca8d837 100644 --- a/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java @@ -35,7 +35,6 @@ import android.text.TextUtils; import android.util.Log; import android.util.Pair; -import androidx.annotation.VisibleForTesting; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -197,37 +196,13 @@ public class TileUtils { */ public static final String META_DATA_KEY_PROFILE = "com.android.settings.profile"; - /** - * Build a list of DashboardCategory. Each category must be defined in manifest. - * eg: .Settings$DeviceSettings - * @deprecated - */ - @Deprecated - public static List getCategories(Context context, - Map, Tile> cache) { - return getCategories(context, cache, true /*categoryDefinedInManifest*/); - } - /** * Build a list of DashboardCategory. - * @param categoryDefinedInManifest If true, an dummy activity must exists in manifest to - * represent this category (eg: .Settings$DeviceSettings) - */ - public static List getCategories(Context context, - Map, Tile> cache, boolean categoryDefinedInManifest) { - return getCategories(context, cache, categoryDefinedInManifest, null, SETTING_PKG); - } - - /** - * Build a list of DashboardCategory. - * @param categoryDefinedInManifest If true, an dummy activity must exists in manifest to - * represent this category (eg: .Settings$DeviceSettings) * @param extraAction additional intent filter action to be usetileutild to build the dashboard * categories */ public static List getCategories(Context context, - Map, Tile> cache, boolean categoryDefinedInManifest, - String extraAction, String settingPkg) { + Map, Tile> cache, String extraAction, String settingPkg) { final long startTime = System.currentTimeMillis(); boolean setup = Global.getInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0) != 0; @@ -247,14 +222,12 @@ public class TileUtils { if (setup) { getTilesForAction(context, user, EXTRA_SETTINGS_ACTION, cache, null, tiles, false, settingPkg); - if (!categoryDefinedInManifest) { getTilesForAction(context, user, IA_SETTINGS_ACTION, cache, null, tiles, false, settingPkg); if (extraAction != null) { getTilesForAction(context, user, extraAction, cache, null, tiles, false, settingPkg); } - } } } @@ -262,7 +235,9 @@ public class TileUtils { for (Tile tile : tiles) { DashboardCategory category = categoryMap.get(tile.category); if (category == null) { - category = createCategory(context, tile.category, categoryDefinedInManifest); + category = new DashboardCategory(); + category.key = tile.category; + if (category == null) { Log.w(LOG_TAG, "Couldn't find category " + tile.category); continue; @@ -281,40 +256,6 @@ public class TileUtils { return categories; } - /** - * Create a new DashboardCategory from key. - * - * @param context Context to query intent - * @param categoryKey The category key - * @param categoryDefinedInManifest If true, an dummy activity must exists in manifest to - * represent this category (eg: .Settings$DeviceSettings) - */ - private static DashboardCategory createCategory(Context context, String categoryKey, - boolean categoryDefinedInManifest) { - DashboardCategory category = new DashboardCategory(); - category.key = categoryKey; - if (!categoryDefinedInManifest) { - return category; - } - PackageManager pm = context.getPackageManager(); - List results = pm.queryIntentActivities(new Intent(categoryKey), 0); - if (results.size() == 0) { - return null; - } - for (ResolveInfo resolved : results) { - if (!resolved.system) { - // Do not allow any app to add to settings, only system ones. - continue; - } - category.title = resolved.activityInfo.loadLabel(pm); - category.priority = SETTING_PKG.equals( - resolved.activityInfo.applicationInfo.packageName) ? resolved.priority : 0; - if (DEBUG) Log.d(LOG_TAG, "Adding category " + category.title); - } - - return category; - } - private static void getTilesForAction(Context context, UserHandle user, String action, Map, Tile> addedCache, String defaultCategory, ArrayList outTiles, boolean requireSettings, diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java index 6e66805795b0f..9df43185fd1f9 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java @@ -17,6 +17,7 @@ package com.android.settingslib.drawer; import static com.google.common.truth.Truth.assertThat; + import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; @@ -51,13 +52,14 @@ import android.util.ArrayMap; import android.util.Pair; import android.widget.RemoteViews; +import com.android.settingslib.SettingsLibRobolectricTestRunner; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; @@ -66,7 +68,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -@RunWith(RobolectricTestRunner.class) +@RunWith(SettingsLibRobolectricTestRunner.class) @Config(shadows = TileUtilsTest.TileUtilsShadowRemoteViews.class) public class TileUtilsTest { @@ -176,13 +178,12 @@ public class TileUtilsTest { .thenReturn(info); List categoryList = TileUtils.getCategories( - mContext, cache, false /* categoryDefinedInManifest */, testAction, - TileUtils.SETTING_PKG); + mContext, cache, testAction, TileUtils.SETTING_PKG); assertThat(categoryList.get(0).getTile(0).category).isEqualTo(testCategory); } @Test - public void getCategories_withPackageName() throws Exception { + public void getCategories_withPackageName() { ArgumentCaptor intentCaptor = ArgumentCaptor.forClass(Intent.class); Map, Tile> cache = new ArrayMap<>(); Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1); @@ -192,9 +193,7 @@ public class TileUtilsTest { userHandleList.add(new UserHandle(ActivityManager.getCurrentUser())); when(mUserManager.getUserProfiles()).thenReturn(userHandleList); - TileUtils.getCategories( - mContext, cache, false /* categoryDefinedInManifest */, null /* action */, - TileUtils.SETTING_PKG); + TileUtils.getCategories(mContext, cache, null /* action */, TileUtils.SETTING_PKG); verify(mPackageManager, atLeastOnce()).queryIntentActivitiesAsUser( intentCaptor.capture(), anyInt(), anyInt()); @@ -203,7 +202,7 @@ public class TileUtilsTest { } @Test - public void getTilesForIntent_shouldReadMetadataTitleAsString() throws RemoteException { + public void getTilesForIntent_shouldReadMetadataTitleAsString() { Intent intent = new Intent(); Map, Tile> addedCache = new ArrayMap<>(); List outTiles = new ArrayList<>(); @@ -224,7 +223,7 @@ public class TileUtilsTest { } @Test - public void getTilesForIntent_shouldReadMetadataTitleFromResource() throws RemoteException { + public void getTilesForIntent_shouldReadMetadataTitleFromResource() { Intent intent = new Intent(); Map, Tile> addedCache = new ArrayMap<>(); List outTiles = new ArrayList<>(); @@ -339,7 +338,7 @@ public class TileUtilsTest { } @Test - public void getTilesForIntent_shouldProcessUriContentForSystemApp() throws RemoteException { + public void getTilesForIntent_shouldProcessUriContentForSystemApp() { Intent intent = new Intent(); Map, Tile> addedCache = new ArrayMap<>(); List outTiles = new ArrayList<>();