Catch error when we fail to get slice icon.
Change-Id: Ia8bdf1ef8a090d2f939abf27b2308eafde7d8928 Fixes: 120588243 Test: robotests
This commit is contained in:
@@ -449,6 +449,12 @@ public class SliceBuilderUtils {
|
||||
if (iconResource == 0) {
|
||||
iconResource = R.drawable.ic_settings;
|
||||
}
|
||||
return IconCompat.createWithResource(context, iconResource);
|
||||
try {
|
||||
return IconCompat.createWithResource(context, iconResource);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Falling back to settings icon because there is an error getting slice icon "
|
||||
+ data.getUri(), e);
|
||||
return IconCompat.createWithResource(context, R.drawable.ic_settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -505,6 +505,19 @@ public class SliceBuilderUtilsTest {
|
||||
assertThat(actualIconResource).isEqualTo(settingsIcon);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSafeIcon_invalidResource_shouldFallbackToSettingsIcon() {
|
||||
final int settingsIcon = R.drawable.ic_settings;
|
||||
final int badIcon = 0x12345678;
|
||||
final SliceData data = getDummyData(TOGGLE_CONTROLLER, SliceData.SliceType.SWITCH,
|
||||
badIcon);
|
||||
|
||||
final IconCompat actualIcon = SliceBuilderUtils.getSafeIcon(mContext, data);
|
||||
|
||||
final int actualIconResource = actualIcon.toIcon().getResId();
|
||||
assertThat(actualIconResource).isEqualTo(settingsIcon);
|
||||
}
|
||||
|
||||
private SliceData getDummyData() {
|
||||
return getDummyData(TOGGLE_CONTROLLER, SUMMARY, SliceData.SliceType.SWITCH, SCREEN_TITLE,
|
||||
ICON, IS_DYNAMIC_SUMMARY_ALLOWED);
|
||||
|
Reference in New Issue
Block a user