From 9f0065b61120ff3814a28395b57f79d499079bb4 Mon Sep 17 00:00:00 2001 From: Ajay Nadathur Date: Tue, 13 Feb 2018 15:02:56 -0800 Subject: Add method to retrieve color from partner apk bug: 73077257 Test: Manually tested and verified Change-Id: Ia90998780913966d3953011591d9f46e088ef963 --- .../main/src/com/android/setupwizardlib/util/Partner.java | 10 ++++++++++ .../src/com/android/setupwizardlib/util/PartnerTest.java | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/library/main/src/com/android/setupwizardlib/util/Partner.java b/library/main/src/com/android/setupwizardlib/util/Partner.java index 67f5546..3a603ee 100644 --- a/library/main/src/com/android/setupwizardlib/util/Partner.java +++ b/library/main/src/com/android/setupwizardlib/util/Partner.java @@ -27,6 +27,7 @@ import android.graphics.drawable.Drawable; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.support.annotation.AnyRes; +import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.StringRes; import android.support.annotation.VisibleForTesting; @@ -75,6 +76,15 @@ public class Partner { return entry.resources.getString(entry.id); } + /** + * Convenience method to get color from partner overlay, or if not available, the color from + * the original context. + */ + public static int getColor(Context context, @ColorRes int id) { + final ResourceEntry resourceEntry = getResourceEntry(context, id); + return resourceEntry.resources.getColor(resourceEntry.id); + } + /** * Convenience method to get a CharSequence from partner overlay, or if not available, the text * from the original context. diff --git a/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java b/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java index 683e40b..f8e71be 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java @@ -131,6 +131,20 @@ public class PartnerTest { assertTrue("Partner value should come from overlay", entry.isOverlay); } + @Test + public void getColor_shouldReturnPartnerValueIfPresent() { + final int expectedPartnerColor = 1111; + doReturn(12345).when(mPartnerResources) + .getIdentifier(eq("suw_color_accent_dark"), eq("color"), anyString()); + doReturn(expectedPartnerColor).when(mPartnerResources).getColor(eq(12345)); + mPackageManager.addResolveInfoForIntent( + new Intent(ACTION_PARTNER_CUSTOMIZATION), + Arrays.asList(createResolveInfo("test.partner.package", true, true))); + final int foundColor = Partner.getColor(mContext, R.color.suw_color_accent_dark); + assertEquals("Partner color should be overlayed to: " + expectedPartnerColor, + expectedPartnerColor, foundColor); + } + @Test public void testLoadDefaultValue() { mPackageManager.addResolveInfoForIntent( -- cgit v1.2.3