diff --git a/packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java b/packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java index f3658c38ca357..6ccba92e2e5f9 100644 --- a/packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/drawer/CategoryManager.java @@ -50,19 +50,25 @@ public class CategoryManager { private final Map mCategoryByKeyMap; private List 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) { @@ -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); } diff --git a/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java b/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java index d12e8c09b8c04..6c5a09d23c618 100644 --- a/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java @@ -144,6 +144,19 @@ public class TileUtils { */ public static List getCategories(Context context, Map, 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 getCategories(Context context, + Map, Tile> cache, boolean categoryDefinedInManifest, + String extraAction) { final long startTime = System.currentTimeMillis(); boolean setup = Global.getInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0) != 0; @@ -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); + } } } 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 86b210ac4aef8..c6c6aad22cf0f 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 @@ -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; @@ -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; @@ -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; @@ -59,6 +63,8 @@ public class TileUtilsTest { private PackageManager mPackageManager; @Mock private Resources mResources; + @Mock + private UserManager mUserManager; @Before public void setUp() throws NameNotFoundException { @@ -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, Tile> cache = new ArrayMap<>(); + List 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 userHandleList = new ArrayList<>(); + userHandleList.add(UserHandle.CURRENT); + when(mUserManager.getUserProfiles()).thenReturn(userHandleList); + + when(mPackageManager.queryIntentActivitiesAsUser(argThat(new ArgumentMatcher() { + public boolean matches(Object event) { + return testAction.equals(((Intent) event).getAction()); + } + }), anyInt(), anyInt())).thenReturn(info); + + List 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);