Clean up Tile related classes in settingslib.
- Deleted a bunch of things nobody uses Bug: 77600770 Test: rebuild Change-Id: I432b5caea2588477eae3d44f6b58c4f72cfed227
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<DashboardCategory> getCategories(Context context,
|
||||
Map<Pair<String, String>, 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<DashboardCategory> getCategories(Context context,
|
||||
Map<Pair<String, String>, 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<DashboardCategory> getCategories(Context context,
|
||||
Map<Pair<String, String>, Tile> cache, boolean categoryDefinedInManifest,
|
||||
String extraAction, String settingPkg) {
|
||||
Map<Pair<String, String>, 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<ResolveInfo> 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<Pair<String, String>, Tile> addedCache,
|
||||
String defaultCategory, ArrayList<Tile> outTiles, boolean requireSettings,
|
||||
|
||||
@@ -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<DashboardCategory> 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<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
Map<Pair<String, String>, 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<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
|
||||
List<Tile> 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<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
|
||||
List<Tile> 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<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
|
||||
List<Tile> outTiles = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user