From ce685fa47bd05998e3e9eba63d288dda7754fb0a Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Fri, 21 May 2021 15:34:39 +0800 Subject: [PATCH] [Injection] Stop using the component icon as a fallback option Settings displays the component icon as a fallback option if the metadata doesn't contain icon and icon_uri. Some injections that don't need an icon have set a transpatrnt color to skip the fallback option. However, the new Settings requires that an item without an icon should align with the border. The transparent icon makes the item unaligned. Therefore, we remove the hidden fallback option, and also filter out the transparent color icon for backward compatibility. Bug: 186801104 Test: robotest Change-Id: I9221bba896e4785901ad617aa8ee58e6028ecc72 --- .../src/com/android/settingslib/drawer/Tile.java | 13 ++----------- .../instrumentation/MetricsFeatureProvider.java | 2 +- .../settingslib/drawer/ActivityTileTest.java | 7 +++---- 3 files changed, 6 insertions(+), 16 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 52d2b3c919d9d..8f3e4bd87aa7a 100644 --- a/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/Tile.java +++ b/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/Tile.java @@ -19,7 +19,6 @@ package com.android.settingslib.drawer; import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_ORDER; 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; @@ -301,16 +300,8 @@ public abstract class Tile implements Parcelable { } int iconResId = mMetaData.getInt(META_DATA_PREFERENCE_ICON); - // Set the icon - if (iconResId == 0) { - // Only fallback to componentInfo.icon if metadata does not contain ICON_URI. - // ICON_URI should be loaded in app UI when need the icon object. Handling IPC at this - // level is too complex because we don't have a strong threading contract for this class - if (!mMetaData.containsKey(META_DATA_PREFERENCE_ICON_URI)) { - iconResId = getComponentIcon(componentInfo); - } - } - if (iconResId != 0) { + // Set the icon. Skip the transparent color for backward compatibility since Android S. + if (iconResId != 0 && iconResId != android.R.color.transparent) { final Icon icon = Icon.createWithResource(componentInfo.packageName, iconResId); if (isIconTintable(context)) { final TypedArray a = context.obtainStyledAttributes(new int[]{ diff --git a/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/MetricsFeatureProvider.java b/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/MetricsFeatureProvider.java index bd0b9e93b09da..6cb60d1aaf0e9 100644 --- a/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/MetricsFeatureProvider.java +++ b/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/MetricsFeatureProvider.java @@ -98,7 +98,7 @@ public class MetricsFeatureProvider { /** * Logs a simple action without page id or attribution */ - public void action(Context context, int category, Pair... taggedData) { + public void action(Context context, int category, Pair... taggedData) { for (LogWriter writer : mLoggerWriters) { writer.action(context, category, taggedData); } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/ActivityTileTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/ActivityTileTest.java index 4f8ecf8f8823b..aa6b0bf33b695 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/ActivityTileTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/ActivityTileTest.java @@ -105,11 +105,10 @@ public class ActivityTileTest { } @Test - public void getIcon_noIconMetadata_returnActivityIcon() { - mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON, 0); + public void getIcon_transparentColorInMetadata_returnNull() { + mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON, android.R.color.transparent); - assertThat(mTile.getIcon(RuntimeEnvironment.application).getResId()) - .isEqualTo(mActivityInfo.icon); + assertThat(mTile.getIcon(RuntimeEnvironment.application)).isNull(); } @Test