Loading packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java +9 −3 Original line number Diff line number Diff line Loading @@ -50,19 +50,25 @@ public class CategoryManager { private final Map<String, DashboardCategory> mCategoryByKeyMap; private List<DashboardCategory> mCategories; private String mExtraAction; public static CategoryManager get(Context context) { return get(context, null); } public static CategoryManager get(Context context, String action) { if (sInstance == null) { sInstance = new CategoryManager(context); sInstance = new CategoryManager(context, action); } return sInstance; } CategoryManager(Context context) { CategoryManager(Context context, String action) { mTileByComponentCache = new ArrayMap<>(); mCategoryByKeyMap = new ArrayMap<>(); mInterestingConfigChanges = new InterestingConfigChanges(); mInterestingConfigChanges.applyNewConfig(context.getResources()); mExtraAction = action; } public synchronized DashboardCategory getTilesByCategory(Context context, String categoryKey) { Loading Loading @@ -111,7 +117,7 @@ public class CategoryManager { } mCategoryByKeyMap.clear(); mCategories = TileUtils.getCategories(context, mTileByComponentCache, false /* categoryDefinedInManifest */); false /* categoryDefinedInManifest */, mExtraAction); for (DashboardCategory category : mCategories) { mCategoryByKeyMap.put(category.key, category); } Loading packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java +16 −0 Original line number Diff line number Diff line Loading @@ -144,6 +144,19 @@ public class TileUtils { */ public static List<DashboardCategory> getCategories(Context context, Map<Pair<String, String>, Tile> cache, boolean categoryDefinedInManifest) { return getCategories(context, cache, categoryDefinedInManifest, null); } /** * 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 used to build the dashboard * categories */ public static List<DashboardCategory> getCategories(Context context, Map<Pair<String, String>, Tile> cache, boolean categoryDefinedInManifest, String extraAction) { final long startTime = System.currentTimeMillis(); boolean setup = Global.getInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0) != 0; Loading @@ -162,6 +175,9 @@ public class TileUtils { if (setup) { getTilesForAction(context, user, EXTRA_SETTINGS_ACTION, cache, null, tiles, false); getTilesForAction(context, user, IA_SETTINGS_ACTION, cache, null, tiles, false); if (extraAction != null) { getTilesForAction(context, user, extraAction, cache, null, tiles, false); } } } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings.Global; import android.util.ArrayMap; import android.util.Pair; Loading @@ -34,6 +36,7 @@ import com.android.settingslib.TestConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; Loading @@ -46,6 +49,7 @@ import java.util.Map; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; Loading @@ -59,6 +63,8 @@ public class TileUtilsTest { private PackageManager mPackageManager; @Mock private Resources mResources; @Mock private UserManager mUserManager; @Before public void setUp() throws NameNotFoundException { Loading Loading @@ -127,6 +133,30 @@ public class TileUtilsTest { assertThat(outTiles.isEmpty()).isTrue(); } @Test public void getCategories_shouldHandleExtraIntentAction() { final String testCategory = "category1"; final String testAction = "action1"; Map<Pair<String, String>, Tile> cache = new ArrayMap<>(); List<ResolveInfo> info = new ArrayList<>(); info.add(newInfo(true, testCategory)); Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1); when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager); List<UserHandle> userHandleList = new ArrayList<>(); userHandleList.add(UserHandle.CURRENT); when(mUserManager.getUserProfiles()).thenReturn(userHandleList); when(mPackageManager.queryIntentActivitiesAsUser(argThat(new ArgumentMatcher<Intent>() { public boolean matches(Object event) { return testAction.equals(((Intent) event).getAction()); } }), anyInt(), anyInt())).thenReturn(info); List<DashboardCategory> categoryList = TileUtils.getCategories( mContext, cache, false /* categoryDefinedInManifest */, testAction); assertThat(categoryList.get(0).tiles.get(0).category).isEqualTo(testCategory); } private ResolveInfo newInfo(boolean systemApp, String category) { return newInfo(systemApp, category, null); Loading Loading
packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java +9 −3 Original line number Diff line number Diff line Loading @@ -50,19 +50,25 @@ public class CategoryManager { private final Map<String, DashboardCategory> mCategoryByKeyMap; private List<DashboardCategory> mCategories; private String mExtraAction; public static CategoryManager get(Context context) { return get(context, null); } public static CategoryManager get(Context context, String action) { if (sInstance == null) { sInstance = new CategoryManager(context); sInstance = new CategoryManager(context, action); } return sInstance; } CategoryManager(Context context) { CategoryManager(Context context, String action) { mTileByComponentCache = new ArrayMap<>(); mCategoryByKeyMap = new ArrayMap<>(); mInterestingConfigChanges = new InterestingConfigChanges(); mInterestingConfigChanges.applyNewConfig(context.getResources()); mExtraAction = action; } public synchronized DashboardCategory getTilesByCategory(Context context, String categoryKey) { Loading Loading @@ -111,7 +117,7 @@ public class CategoryManager { } mCategoryByKeyMap.clear(); mCategories = TileUtils.getCategories(context, mTileByComponentCache, false /* categoryDefinedInManifest */); false /* categoryDefinedInManifest */, mExtraAction); for (DashboardCategory category : mCategories) { mCategoryByKeyMap.put(category.key, category); } Loading
packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java +16 −0 Original line number Diff line number Diff line Loading @@ -144,6 +144,19 @@ public class TileUtils { */ public static List<DashboardCategory> getCategories(Context context, Map<Pair<String, String>, Tile> cache, boolean categoryDefinedInManifest) { return getCategories(context, cache, categoryDefinedInManifest, null); } /** * 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 used to build the dashboard * categories */ public static List<DashboardCategory> getCategories(Context context, Map<Pair<String, String>, Tile> cache, boolean categoryDefinedInManifest, String extraAction) { final long startTime = System.currentTimeMillis(); boolean setup = Global.getInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0) != 0; Loading @@ -162,6 +175,9 @@ public class TileUtils { if (setup) { getTilesForAction(context, user, EXTRA_SETTINGS_ACTION, cache, null, tiles, false); getTilesForAction(context, user, IA_SETTINGS_ACTION, cache, null, tiles, false); if (extraAction != null) { getTilesForAction(context, user, extraAction, cache, null, tiles, false); } } } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings.Global; import android.util.ArrayMap; import android.util.Pair; Loading @@ -34,6 +36,7 @@ import com.android.settingslib.TestConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; Loading @@ -46,6 +49,7 @@ import java.util.Map; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; Loading @@ -59,6 +63,8 @@ public class TileUtilsTest { private PackageManager mPackageManager; @Mock private Resources mResources; @Mock private UserManager mUserManager; @Before public void setUp() throws NameNotFoundException { Loading Loading @@ -127,6 +133,30 @@ public class TileUtilsTest { assertThat(outTiles.isEmpty()).isTrue(); } @Test public void getCategories_shouldHandleExtraIntentAction() { final String testCategory = "category1"; final String testAction = "action1"; Map<Pair<String, String>, Tile> cache = new ArrayMap<>(); List<ResolveInfo> info = new ArrayList<>(); info.add(newInfo(true, testCategory)); Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1); when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager); List<UserHandle> userHandleList = new ArrayList<>(); userHandleList.add(UserHandle.CURRENT); when(mUserManager.getUserProfiles()).thenReturn(userHandleList); when(mPackageManager.queryIntentActivitiesAsUser(argThat(new ArgumentMatcher<Intent>() { public boolean matches(Object event) { return testAction.equals(((Intent) event).getAction()); } }), anyInt(), anyInt())).thenReturn(info); List<DashboardCategory> categoryList = TileUtils.getCategories( mContext, cache, false /* categoryDefinedInManifest */, testAction); assertThat(categoryList.get(0).tiles.get(0).category).isEqualTo(testCategory); } private ResolveInfo newInfo(boolean systemApp, String category) { return newInfo(systemApp, category, null); Loading