[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
This commit is contained in:
Jason Chiu
2021-05-21 15:34:39 +08:00
parent b04a005c3f
commit ce685fa47b
3 changed files with 6 additions and 16 deletions

View File

@@ -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[]{

View File

@@ -98,7 +98,7 @@ public class MetricsFeatureProvider {
/**
* Logs a simple action without page id or attribution
*/
public void action(Context context, int category, Pair<Integer, Object>... taggedData) {
public void action(Context context, int category, Pair<Integer, Object>... taggedData) {
for (LogWriter writer : mLoggerWriters) {
writer.action(context, category, taggedData);
}

View File

@@ -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