From 0e96107ddc225f745fd11adbb335a490912ff467 Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Wed, 31 Jan 2018 16:55:10 -0800 Subject: [PATCH] Check icon tintable flag of the Suggestion. - instead of checking the icon resource package, check the icon tintable flag to see if we should tint the suggestion icon. Bug: 72330968 Test: make RunSettingsRoboTests Change-Id: I4767df05bebf815774dbd8e528c7ac0f5b902d44 --- .../suggestions/SuggestionAdapter.java | 2 +- .../suggestions/SuggestionAdapterTest.java | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java b/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java index 070e758e111..9bcf2a2fbcb 100644 --- a/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java +++ b/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java @@ -116,7 +116,7 @@ public class SuggestionAdapter extends RecyclerView.Adapter mConfig.setCardLayout(holder, suggestionCount, position); final Icon icon = suggestion.getIcon(); final Drawable drawable = mCache.getIcon(icon); - if (drawable != null && TextUtils.equals(icon.getResPackage(), mContext.getPackageName())) { + if ((suggestion.getFlags() & Suggestion.FLAG_ICON_TINTABLE) != 0) { drawable.setTint(Utils.getColorAccent(mContext)); } holder.icon.setImageDrawable(drawable); diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java index ebf3dc70fcd..825aee9fb9b 100644 --- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java @@ -215,11 +215,9 @@ public class SuggestionAdapterTest { } @Test - public void onBindViewHolder_differentPackage_shouldNotTintIcon() - throws PendingIntent.CanceledException { + public void onBindViewHolder_iconNotTintable_shouldNotTintIcon() + throws PendingIntent.CanceledException { final Icon icon = mock(Icon.class); - when(icon.getResPackage()).thenReturn("pkg1"); - when(mActivity.getPackageName()).thenReturn("pkg2"); final Suggestion suggestion = new Suggestion.Builder("pkg1") .setPendingIntent(mock(PendingIntent.class)) .setIcon(icon) @@ -243,15 +241,14 @@ public class SuggestionAdapterTest { } @Test - public void onBindViewHolder_samePackage_shouldTintIcon() - throws PendingIntent.CanceledException { + public void onBindViewHolder_iconTintable_shouldTintIcon() + throws PendingIntent.CanceledException { final Icon icon = mock(Icon.class); - final String packageName = "pkg1"; - when(icon.getResPackage()).thenReturn(packageName); - when(mActivity.getPackageName()).thenReturn(packageName); - final Suggestion suggestion = new Suggestion.Builder(packageName) + final int FLAG_ICON_TINTABLE = 1 << 1; + final Suggestion suggestion = new Suggestion.Builder("pkg1") .setPendingIntent(mock(PendingIntent.class)) .setIcon(icon) + .setFlags(FLAG_ICON_TINTABLE) .build(); final List suggestions = new ArrayList<>(); suggestions.add(suggestion);