Merge "Skip loading tiles from non-current user if primary profile only" into rvc-d1-dev am: 550d625622
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12316857 Change-Id: Ia357cca1e7d7af18daca43da420e3acfbe8c5198
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user