Loading packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java +18 −1 Original line number Diff line number Diff line Loading @@ -135,8 +135,16 @@ public class TileUtils { * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the title that should be displayed for the preference. */ @Deprecated public static final String META_DATA_PREFERENCE_TITLE = "com.android.settings.title"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the title that should be displayed for the preference. */ public static final String META_DATA_PREFERENCE_TITLE_RES_ID = "com.android.settings.title.resid"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the summary text that should be displayed for the preference. Loading Loading @@ -364,7 +372,16 @@ public class TileUtils { if (metaData.containsKey(META_DATA_PREFERENCE_ICON)) { icon = metaData.getInt(META_DATA_PREFERENCE_ICON); } if (metaData.containsKey(META_DATA_PREFERENCE_TITLE)) { int resId = 0; if (metaData.containsKey(META_DATA_PREFERENCE_TITLE_RES_ID)) { resId = metaData.getInt(META_DATA_PREFERENCE_TITLE_RES_ID); if (resId != 0) { title = res.getString(resId); } } // Fallback to legacy title extraction if we couldn't get the title through // res id. if ((resId == 0) && metaData.containsKey(META_DATA_PREFERENCE_TITLE)) { if (metaData.get(META_DATA_PREFERENCE_TITLE) instanceof Integer) { title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE)); } else { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java +59 −1 Original line number Diff line number Diff line Loading @@ -230,6 +230,51 @@ public class TileUtilsTest { .isEqualTo(TileUtils.SETTING_PKG); } @Test public void getTilesForIntent_shouldReadMetadataTitleAsString() throws RemoteException { Intent intent = new Intent(); 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, "my title", 0); info.add(resolveInfo); when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt())) .thenReturn(info); TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache, null /* defaultCategory */, outTiles, false /* usePriority */, false /* checkCategory */); assertThat(outTiles.size()).isEqualTo(1); assertThat(outTiles.get(0).title).isEqualTo("my title"); } @Test public void getTilesForIntent_shouldReadMetadataTitleFromResource() throws RemoteException { Intent intent = new Intent(); 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); info.add(resolveInfo); when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt())) .thenReturn(info); when(mResources.getString(eq(123))) .thenReturn("my localized title"); TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache, null /* defaultCategory */, outTiles, false /* usePriority */, false /* checkCategory */); assertThat(outTiles.size()).isEqualTo(1); assertThat(outTiles.get(0).title).isEqualTo("my localized title"); } @Test public void getTilesForIntent_shouldNotProcessInvalidUriContentSystemApp() throws RemoteException { Loading Loading @@ -299,6 +344,12 @@ 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); } private static ResolveInfo newInfo(boolean systemApp, String category, String keyHint, String iconUri, String summaryUri, String title, int titleResId) { ResolveInfo info = new ResolveInfo(); info.system = systemApp; info.activityInfo = new ActivityInfo(); Loading @@ -317,6 +368,13 @@ public class TileUtilsTest { if (summaryUri != null) { info.activityInfo.metaData.putString("com.android.settings.summary_uri", summaryUri); } if (title != null) { info.activityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_TITLE, title); } if (titleResId != 0) { info.activityInfo.metaData.putInt( TileUtils.META_DATA_PREFERENCE_TITLE_RES_ID, titleResId); } info.activityInfo.applicationInfo = new ApplicationInfo(); if (systemApp) { info.activityInfo.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM; Loading Loading
packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java +18 −1 Original line number Diff line number Diff line Loading @@ -135,8 +135,16 @@ public class TileUtils { * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the title that should be displayed for the preference. */ @Deprecated public static final String META_DATA_PREFERENCE_TITLE = "com.android.settings.title"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the title that should be displayed for the preference. */ public static final String META_DATA_PREFERENCE_TITLE_RES_ID = "com.android.settings.title.resid"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml * to specify the summary text that should be displayed for the preference. Loading Loading @@ -364,7 +372,16 @@ public class TileUtils { if (metaData.containsKey(META_DATA_PREFERENCE_ICON)) { icon = metaData.getInt(META_DATA_PREFERENCE_ICON); } if (metaData.containsKey(META_DATA_PREFERENCE_TITLE)) { int resId = 0; if (metaData.containsKey(META_DATA_PREFERENCE_TITLE_RES_ID)) { resId = metaData.getInt(META_DATA_PREFERENCE_TITLE_RES_ID); if (resId != 0) { title = res.getString(resId); } } // Fallback to legacy title extraction if we couldn't get the title through // res id. if ((resId == 0) && metaData.containsKey(META_DATA_PREFERENCE_TITLE)) { if (metaData.get(META_DATA_PREFERENCE_TITLE) instanceof Integer) { title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE)); } else { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java +59 −1 Original line number Diff line number Diff line Loading @@ -230,6 +230,51 @@ public class TileUtilsTest { .isEqualTo(TileUtils.SETTING_PKG); } @Test public void getTilesForIntent_shouldReadMetadataTitleAsString() throws RemoteException { Intent intent = new Intent(); 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, "my title", 0); info.add(resolveInfo); when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt())) .thenReturn(info); TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache, null /* defaultCategory */, outTiles, false /* usePriority */, false /* checkCategory */); assertThat(outTiles.size()).isEqualTo(1); assertThat(outTiles.get(0).title).isEqualTo("my title"); } @Test public void getTilesForIntent_shouldReadMetadataTitleFromResource() throws RemoteException { Intent intent = new Intent(); 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); info.add(resolveInfo); when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt())) .thenReturn(info); when(mResources.getString(eq(123))) .thenReturn("my localized title"); TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache, null /* defaultCategory */, outTiles, false /* usePriority */, false /* checkCategory */); assertThat(outTiles.size()).isEqualTo(1); assertThat(outTiles.get(0).title).isEqualTo("my localized title"); } @Test public void getTilesForIntent_shouldNotProcessInvalidUriContentSystemApp() throws RemoteException { Loading Loading @@ -299,6 +344,12 @@ 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); } private static ResolveInfo newInfo(boolean systemApp, String category, String keyHint, String iconUri, String summaryUri, String title, int titleResId) { ResolveInfo info = new ResolveInfo(); info.system = systemApp; info.activityInfo = new ActivityInfo(); Loading @@ -317,6 +368,13 @@ public class TileUtilsTest { if (summaryUri != null) { info.activityInfo.metaData.putString("com.android.settings.summary_uri", summaryUri); } if (title != null) { info.activityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_TITLE, title); } if (titleResId != 0) { info.activityInfo.metaData.putInt( TileUtils.META_DATA_PREFERENCE_TITLE_RES_ID, titleResId); } info.activityInfo.applicationInfo = new ApplicationInfo(); if (systemApp) { info.activityInfo.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM; Loading