summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYanting Yang <yantingyang@google.com>2020-08-05 22:43:48 +0800
committerYanting Yang <yantingyang@google.com>2020-08-07 17:40:16 +0800
commit4393c7a5622c9472848099f0da6306d7e999597e (patch)
tree60174475e48518a51b181b96c32d5ff4ae021610
parentb82ba472f7d96f564432c53fd40241744582b915 (diff)
downloadbase-4393c7a5622c9472848099f0da6306d7e999597e.tar.gz
Skip loading tiles from non-current user if primary profile only
Symptom: Disabling an injected activity or provider can't remove the tile entirely. The tile is still shown if the device has a work profile. Root cause: Settings loads tiles from all injected components of all users via PackageManager. When an injected app disables its component of current user to remove tiles, the component for the work profile user is still enabled. Therefore the tiles are still loaded. Solution: Skip loading tiles from non-current user if the injected component is tagged "primary_profile_only". Bug: 161885575 Test: make RunSettingsLibRoboTests Change-Id: I00338204ddccfcbcf84a3eed34e6b8f8d5829d56
-rw-r--r--packages/SettingsLib/Tile/src/com/android/settingslib/drawer/Tile.java8
-rw-r--r--packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java10
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java45
3 files changed, 52 insertions, 11 deletions
diff --git a/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/Tile.java b/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/Tile.java
index 1e4c7cac4404..52d2b3c919d9 100644
--- a/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/Tile.java
+++ b/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/Tile.java
@@ -376,8 +376,12 @@ public abstract class Tile implements Parcelable {
* Check whether tile only has primary profile.
*/
public boolean isPrimaryProfileOnly() {
- String profile = mMetaData != null
- ? mMetaData.getString(META_DATA_KEY_PROFILE) : PROFILE_ALL;
+ return isPrimaryProfileOnly(mMetaData);
+ }
+
+ static boolean isPrimaryProfileOnly(Bundle metaData) {
+ String profile = metaData != null
+ ? metaData.getString(META_DATA_KEY_PROFILE) : PROFILE_ALL;
profile = (profile != null ? profile : PROFILE_ALL);
return TextUtils.equals(profile, PROFILE_PRIMARY);
}
diff --git a/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java b/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java
index ace50f30663d..49f6bd8c3334 100644
--- a/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java
+++ b/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java
@@ -339,6 +339,16 @@ public class TileUtils {
private static void loadTile(UserHandle user, Map<Pair<String, String>, Tile> addedCache,
String defaultCategory, List<Tile> outTiles, Intent intent, Bundle metaData,
ComponentInfo componentInfo) {
+ // Skip loading tile if the component is tagged primary_profile_only but not running on
+ // the current user.
+ if (user.getIdentifier() != ActivityManager.getCurrentUser()
+ && Tile.isPrimaryProfileOnly(componentInfo.metaData)) {
+ Log.w(LOG_TAG, "Found " + componentInfo.name + " for intent "
+ + intent + " is primary profile only, skip loading tile for uid "
+ + user.getIdentifier());
+ return;
+ }
+
String categoryKey = defaultCategory;
// Load category
if ((metaData == null || !metaData.containsKey(EXTRA_CATEGORY_KEY))
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 9b4b97e7f55d..176905305506 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,11 +17,14 @@
package com.android.settingslib.drawer;
import static com.android.settingslib.drawer.TileUtils.IA_SETTINGS_ACTION;
+import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_URI;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY_URI;
+import static com.android.settingslib.drawer.TileUtils.PROFILE_ALL;
+import static com.android.settingslib.drawer.TileUtils.PROFILE_PRIMARY;
import static com.google.common.truth.Truth.assertThat;
@@ -189,7 +192,7 @@ public class TileUtilsTest {
List<Tile> outTiles = new ArrayList<>();
List<ResolveInfo> info = new ArrayList<>();
ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
- URI_GET_SUMMARY, "my title", 0);
+ URI_GET_SUMMARY, "my title", 0, PROFILE_ALL);
info.add(resolveInfo);
when(mPackageManager.queryIntentActivitiesAsUser(any(Intent.class), anyInt(), anyInt()))
@@ -211,7 +214,7 @@ public class TileUtilsTest {
List<Tile> outTiles = new ArrayList<>();
List<ResolveInfo> info = new ArrayList<>();
ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
- URI_GET_SUMMARY, null, 123);
+ URI_GET_SUMMARY, null, 123, PROFILE_ALL);
info.add(resolveInfo);
when(mPackageManager.queryIntentActivitiesAsUser(any(Intent.class), anyInt(), anyInt()))
@@ -235,7 +238,7 @@ public class TileUtilsTest {
List<Tile> outTiles = new ArrayList<>();
List<ResolveInfo> info = new ArrayList<>();
ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
- URI_GET_SUMMARY, null, 123);
+ URI_GET_SUMMARY, null, 123, PROFILE_ALL);
resolveInfo.activityInfo.packageName = "com.android.settings";
resolveInfo.activityInfo.applicationInfo.packageName = "com.android.settings";
info.add(resolveInfo);
@@ -258,7 +261,7 @@ public class TileUtilsTest {
final List<Tile> outTiles = new ArrayList<>();
final List<ResolveInfo> info = new ArrayList<>();
final ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
- URI_GET_SUMMARY, null, 123);
+ URI_GET_SUMMARY, null, 123, PROFILE_ALL);
resolveInfo.activityInfo.packageName = "com.android.settings";
resolveInfo.activityInfo.applicationInfo.packageName = "com.android.settings";
info.add(resolveInfo);
@@ -290,7 +293,7 @@ public class TileUtilsTest {
List<Tile> outTiles = new ArrayList<>();
List<ResolveInfo> info = new ArrayList<>();
ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
- URI_GET_SUMMARY, null, 123);
+ URI_GET_SUMMARY, null, 123, PROFILE_ALL);
resolveInfo.activityInfo.metaData
.putBoolean(TileUtils.META_DATA_PREFERENCE_ICON_TINTABLE, true);
info.add(resolveInfo);
@@ -327,6 +330,26 @@ public class TileUtilsTest {
assertThat(outTiles).hasSize(2);
}
+ @Test
+ public void loadTilesForAction_isPrimaryProfileOnly_shouldSkipNonPrimaryUserTiles() {
+ Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
+ List<Tile> outTiles = new ArrayList<>();
+ List<ResolveInfo> info = new ArrayList<>();
+ ResolveInfo resolveInfo = newInfo(true, null /* category */, null, URI_GET_ICON,
+ URI_GET_SUMMARY, null, 123, PROFILE_PRIMARY);
+ info.add(resolveInfo);
+
+ when(mPackageManager.queryIntentActivitiesAsUser(any(Intent.class), anyInt(), anyInt()))
+ .thenReturn(info);
+ when(mPackageManager.queryIntentContentProvidersAsUser(any(Intent.class), anyInt(),
+ anyInt())).thenReturn(info);
+
+ TileUtils.loadTilesForAction(mContext, new UserHandle(10), IA_SETTINGS_ACTION,
+ addedCache, null /* defaultCategory */, outTiles, false /* requiresSettings */);
+
+ assertThat(outTiles).isEmpty();
+ }
+
public static ResolveInfo newInfo(boolean systemApp, String category) {
return newInfo(systemApp, category, null);
}
@@ -337,14 +360,14 @@ public class TileUtilsTest {
private static ResolveInfo newInfo(boolean systemApp, String category, String keyHint,
String iconUri, String summaryUri) {
- return newInfo(systemApp, category, keyHint, iconUri, summaryUri, null, 0);
+ return newInfo(systemApp, category, keyHint, iconUri, summaryUri, null, 0, PROFILE_ALL);
}
private static ResolveInfo newInfo(boolean systemApp, String category, String keyHint,
- String iconUri, String summaryUri, String title, int titleResId) {
+ String iconUri, String summaryUri, String title, int titleResId, String profile) {
final Bundle metaData = newMetaData(category, keyHint, iconUri, summaryUri, title,
- titleResId);
+ titleResId, profile);
final ResolveInfo info = new ResolveInfo();
info.system = systemApp;
@@ -358,6 +381,7 @@ public class TileUtilsTest {
info.providerInfo.packageName = "abc";
info.providerInfo.name = "456";
info.providerInfo.authority = "auth";
+ info.providerInfo.metaData = metaData;
ShadowTileUtils.setMetaData(metaData);
info.providerInfo.applicationInfo = new ApplicationInfo();
@@ -369,7 +393,7 @@ public class TileUtilsTest {
}
private static Bundle newMetaData(String category, String keyHint, String iconUri,
- String summaryUri, String title, int titleResId) {
+ String summaryUri, String title, int titleResId, String profile) {
final Bundle metaData = new Bundle();
metaData.putString("com.android.settings.category", category);
metaData.putInt(META_DATA_PREFERENCE_ICON, 314159);
@@ -388,6 +412,9 @@ public class TileUtilsTest {
} else if (title != null) {
metaData.putString(TileUtils.META_DATA_PREFERENCE_TITLE, title);
}
+ if (profile != null) {
+ metaData.putString(META_DATA_KEY_PROFILE, profile);
+ }
return metaData;
}