Make BT icon colorful

Add new method to get rainbow bt icon and also refactor
AdaptiveHomepageIcon:
1. Rename
2. Add ConstantState

Bug: 126425211
Test: RunSettingsRoboTests

Change-Id: Idb8aaf253d0d9e2ab33d8852f093e6689ebadde4
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index 7074481..e78bac6 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -1317,6 +1317,230 @@
         priority="4"
         summary="Using hardcoded color"
         explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    <color name="bt_color_icon_1">#48a50e0e</color> <!-- 72% Material Red 900 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="144"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_icon_2&quot;>#480d652d&lt;/color> &lt;!-- 72% Material Green 900 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="145"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_icon_3&quot;>#48e37400&lt;/color> &lt;!-- 72% Material Yellow 900 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="146"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_icon_4&quot;>#48b06000&lt;/color> &lt;!-- 72% Material Orange 900 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="147"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_icon_5&quot;>#489c166b&lt;/color> &lt;!-- 72% Material Pink 900 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="148"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_icon_6&quot;>#48681da8&lt;/color> &lt;!-- 72% Material Purple 900 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="149"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_icon_7&quot;>#48007b83&lt;/color> &lt;!-- 72% Material Cyan 900 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="150"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_bg_1&quot;>#fad2cf&lt;/color> &lt;!-- Material Red 100 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="152"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_bg_2&quot;>#ceead6&lt;/color> &lt;!-- Material Green 100 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="153"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_bg_3&quot;>#feefc3&lt;/color> &lt;!-- Material Yellow 100 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="154"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_bg_4&quot;>#fedfc8&lt;/color> &lt;!-- Material Orange 100 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="155"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_bg_5&quot;>#fdcfe8&lt;/color> &lt;!-- Material Pink 100 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="156"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_bg_6&quot;>#e9d2fd&lt;/color> &lt;!-- Material Purple 100 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="157"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+        errorLine1="    &lt;color name=&quot;bt_color_bg_7&quot;>#cbf0f8&lt;/color> &lt;!-- Material Cyan 100 -->"
+        errorLine2="    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+        <location
+            file="res/values/colors.xml"
+            line="158"
+            column="5"/>
+    </issue>
+
+    <issue
+        id="HardCodedColor"
+        severity="Error"
+        message="Avoid using hardcoded color"
+        category="Correctness"
+        priority="4"
+        summary="Using hardcoded color"
+        explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
         errorLine1="                android:background=&quot;@color/lock_pattern_background&quot; />"
         errorLine2="                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
         <location
@@ -2537,7 +2761,7 @@
         errorLine2="                                   ~~~~~~~~~~~~~~~~~~~">
         <location
             file="res/values/strings.xml"
-            line="6026"
+            line="6020"
             column="36"/>
     </issue>
 
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 7e0ba10..521d709 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1378,4 +1378,25 @@
          <item>@string/wifi_calling_mode_cellular_preferred_summary</item>
     </string-array>
 
+    <!-- Bluetooth icon foreground colors -->
+    <integer-array name="bt_icon_fg_colors">
+        <item>@color/bt_color_icon_1</item>
+        <item>@color/bt_color_icon_2</item>
+        <item>@color/bt_color_icon_3</item>
+        <item>@color/bt_color_icon_4</item>
+        <item>@color/bt_color_icon_5</item>
+        <item>@color/bt_color_icon_6</item>
+        <item>@color/bt_color_icon_7</item>
+    </integer-array>
+
+    <!-- Bluetooth icon background colors -->
+    <integer-array name="bt_icon_bg_colors">
+        <item>@color/bt_color_bg_1</item>
+        <item>@color/bt_color_bg_2</item>
+        <item>@color/bt_color_bg_3</item>
+        <item>@color/bt_color_bg_4</item>
+        <item>@color/bt_color_bg_5</item>
+        <item>@color/bt_color_bg_6</item>
+        <item>@color/bt_color_bg_7</item>
+    </integer-array>
 </resources>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 0afd288..2cebd28 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -140,4 +140,20 @@
     <color name="qr_focused_corner_line_color">#ff1a73e8</color>
     <color name="qr_background_color">#b3ffffff</color> <!-- 70% white transparency -->
     <!-- End of QR code scanner colors -->
+
+    <color name="bt_color_icon_1">#48a50e0e</color> <!-- 72% Material Red 900 -->
+    <color name="bt_color_icon_2">#480d652d</color> <!-- 72% Material Green 900 -->
+    <color name="bt_color_icon_3">#48e37400</color> <!-- 72% Material Yellow 900 -->
+    <color name="bt_color_icon_4">#48b06000</color> <!-- 72% Material Orange 900 -->
+    <color name="bt_color_icon_5">#489c166b</color> <!-- 72% Material Pink 900 -->
+    <color name="bt_color_icon_6">#48681da8</color> <!-- 72% Material Purple 900 -->
+    <color name="bt_color_icon_7">#48007b83</color> <!-- 72% Material Cyan 900 -->
+
+    <color name="bt_color_bg_1">#fad2cf</color> <!-- Material Red 100 -->
+    <color name="bt_color_bg_2">#ceead6</color> <!-- Material Green 100 -->
+    <color name="bt_color_bg_3">#feefc3</color> <!-- Material Yellow 100 -->
+    <color name="bt_color_bg_4">#fedfc8</color> <!-- Material Orange 100 -->
+    <color name="bt_color_bg_5">#fdcfe8</color> <!-- Material Pink 100 -->
+    <color name="bt_color_bg_6">#e9d2fd</color> <!-- Material Purple 100 -->
+    <color name="bt_color_bg_7">#cbf0f8</color> <!-- Material Cyan 100 -->
 </resources>
\ No newline at end of file
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
index fd805b8..3860352 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsHeaderController.java
@@ -26,7 +26,6 @@
 
 import com.android.settings.R;
 import com.android.settings.widget.EntityHeaderController;
-import com.android.settingslib.bluetooth.BluetoothUtils;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
 import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -66,10 +65,8 @@
     }
 
     protected void setHeaderProperties() {
-        final Pair<Drawable, String> pair = BluetoothUtils
-                .getBtClassDrawableWithDescription(mContext, mCachedDevice,
-                        mContext.getResources().getFraction(R.fraction.bt_battery_scale_fraction, 1,
-                                1));
+        final Pair<Drawable, String> pair = Utils.getBtRainbowDrawableWithDescription(mContext,
+                mCachedDevice);
         String summaryText = mCachedDevice.getConnectionSummary();
         // If both the hearing aids are connected, two device status should be shown.
         // If Second Summary is unavailable, to set it to null.
diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
index d4c0ed0..8d727eb 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
@@ -38,7 +38,6 @@
 import com.android.settings.R;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.widget.GearPreference;
-import com.android.settingslib.bluetooth.BluetoothUtils;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
 
@@ -130,8 +129,8 @@
         // Null check is done at the framework
         setSummary(mCachedDevice.getConnectionSummary());
 
-        final Pair<Drawable, String> pair = BluetoothUtils
-                .getBtClassDrawableWithDescription(getContext(), mCachedDevice);
+        final Pair<Drawable, String> pair = Utils
+                .getBtRainbowDrawableWithDescription(getContext(), mCachedDevice);
         if (pair.first != null) {
             setIcon(pair.first);
             contentDescription = pair.second;
@@ -246,5 +245,4 @@
                     R.string.bluetooth_pairing_error_message);
         }
     }
-
 }
diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java
index ff4a98f..e02ddc4 100755
--- a/src/com/android/settings/bluetooth/Utils.java
+++ b/src/com/android/settings/bluetooth/Utils.java
@@ -21,8 +21,12 @@
 import android.bluetooth.BluetoothProfile;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.res.Resources;
+import android.graphics.PorterDuff;
+import android.graphics.drawable.Drawable;
 import android.provider.Settings;
 import android.util.Log;
+import android.util.Pair;
 import android.widget.Toast;
 
 import androidx.annotation.VisibleForTesting;
@@ -30,8 +34,10 @@
 
 import com.android.settings.R;
 import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.widget.AdaptiveIcon;
 import com.android.settingslib.bluetooth.BluetoothUtils;
 import com.android.settingslib.bluetooth.BluetoothUtils.ErrorListener;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
 import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
 
@@ -179,4 +185,25 @@
             return META_INT_ERROR;
         }
     }
+
+    /**
+     * Get colorful bluetooth icon with description
+     */
+    public static Pair<Drawable, String> getBtRainbowDrawableWithDescription(Context context,
+            CachedBluetoothDevice cachedDevice) {
+        final Pair<Drawable, String> pair = BluetoothUtils.getBtClassDrawableWithDescription(
+                context, cachedDevice);
+        final Resources resources = context.getResources();
+        final int[] iconFgColors = resources.getIntArray(R.array.bt_icon_fg_colors);
+        final int[] iconBgColors = resources.getIntArray(R.array.bt_icon_bg_colors);
+
+        // get color index based on mac address
+        final int index =  Math.abs(cachedDevice.getAddress().hashCode()) % iconBgColors.length;
+        pair.first.setColorFilter(iconFgColors[index], PorterDuff.Mode.SRC_ATOP);
+        final Drawable adaptiveIcon = new AdaptiveIcon(context, pair.first);
+        ((AdaptiveIcon) adaptiveIcon).setBackgroundColor(iconBgColors[index]);
+
+        return new Pair<>(adaptiveIcon, pair.second);
+    }
+
 }
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index 6348b91..744cbd2 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -46,7 +46,7 @@
 import com.android.settings.SettingsActivity;
 import com.android.settings.dashboard.profileselector.ProfileSelectDialog;
 import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.widget.AdaptiveHomepageIcon;
+import com.android.settings.widget.AdaptiveIcon;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
 import com.android.settingslib.drawer.DashboardCategory;
 import com.android.settingslib.drawer.Tile;
@@ -197,8 +197,8 @@
             Drawable iconDrawable = tileIcon.loadDrawable(preference.getContext());
             if (forceRoundedIcon
                     && !TextUtils.equals(mContext.getPackageName(), tile.getPackageName())) {
-                iconDrawable = new AdaptiveHomepageIcon(mContext, iconDrawable);
-                ((AdaptiveHomepageIcon) iconDrawable).setBackgroundColor(mContext, tile);
+                iconDrawable = new AdaptiveIcon(mContext, iconDrawable);
+                ((AdaptiveIcon) iconDrawable).setBackgroundColor(mContext, tile);
             }
             preference.setIcon(iconDrawable);
         } else if (tile.getMetaData() != null
diff --git a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
index 99fe219..5c1fbdd 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java
@@ -46,7 +46,6 @@
 import com.android.settings.slices.CustomSliceable;
 import com.android.settings.slices.SliceBroadcastReceiver;
 import com.android.settings.slices.SliceBuilderUtils;
-import com.android.settingslib.bluetooth.BluetoothUtils;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
 
@@ -211,8 +210,9 @@
 
     @VisibleForTesting
     IconCompat getBluetoothDeviceIcon(CachedBluetoothDevice device) {
-        final Pair<Drawable, String> pair = BluetoothUtils
-                .getBtClassDrawableWithDescription(mContext, device);
+        final Pair<Drawable, String> pair =
+                com.android.settings.bluetooth.Utils.getBtRainbowDrawableWithDescription(mContext,
+                        device);
         final Drawable drawable = pair.first;
 
         // Use default bluetooth icon if can't get icon.
diff --git a/src/com/android/settings/widget/AdaptiveHomepageIcon.java b/src/com/android/settings/widget/AdaptiveIcon.java
similarity index 76%
rename from src/com/android/settings/widget/AdaptiveHomepageIcon.java
rename to src/com/android/settings/widget/AdaptiveIcon.java
index bc7aaa7..04b33ae 100644
--- a/src/com/android/settings/widget/AdaptiveHomepageIcon.java
+++ b/src/com/android/settings/widget/AdaptiveIcon.java
@@ -35,14 +35,15 @@
 import com.android.settings.homepage.AdaptiveIconShapeDrawable;
 import com.android.settingslib.drawer.Tile;
 
-public class AdaptiveHomepageIcon extends LayerDrawable {
+public class AdaptiveIcon extends LayerDrawable {
 
     private static final String TAG = "AdaptiveHomepageIcon";
 
     @VisibleForTesting(otherwise = NONE)
     int mBackgroundColor = -1;
+    private AdaptiveConstantState mAdaptiveConstantState;
 
-    public AdaptiveHomepageIcon(Context context, Drawable foreground) {
+    public AdaptiveIcon(Context context, Drawable foreground) {
         super(new Drawable[]{
                 new AdaptiveIconShapeDrawable(context.getResources()),
                 foreground
@@ -50,6 +51,7 @@
         final int insetPx = context.getResources()
                 .getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset);
         setLayerInset(1 /* index */, insetPx, insetPx, insetPx, insetPx);
+        mAdaptiveConstantState = new AdaptiveConstantState(context, foreground);
     }
 
     public void setBackgroundColor(Context context, Tile tile) {
@@ -85,5 +87,36 @@
         mBackgroundColor = color;
         getDrawable(0).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
         Log.d(TAG, "Setting background color " + mBackgroundColor);
+        mAdaptiveConstantState.color = color;
+    }
+
+    @Override
+    public ConstantState getConstantState() {
+        return mAdaptiveConstantState;
+    }
+
+    @VisibleForTesting
+    static class AdaptiveConstantState extends ConstantState {
+        Context context;
+        Drawable drawable;
+        int color;
+
+        public AdaptiveConstantState(Context context, Drawable drawable) {
+            this.context = context;
+            this.drawable = drawable;
+        }
+
+        @Override
+        public Drawable newDrawable() {
+            final AdaptiveIcon icon = new AdaptiveIcon(context, drawable);
+            icon.setBackgroundColor(color);
+
+            return icon;
+        }
+
+        @Override
+        public int getChangingConfigurations() {
+            return 0;
+        }
     }
 }
diff --git a/tests/robotests/src/com/android/settings/widget/AdaptiveHomepageIconTest.java b/tests/robotests/src/com/android/settings/widget/AdaptiveIconTest.java
similarity index 80%
rename from tests/robotests/src/com/android/settings/widget/AdaptiveHomepageIconTest.java
rename to tests/robotests/src/com/android/settings/widget/AdaptiveIconTest.java
index 05a9cfb..1be3332 100644
--- a/tests/robotests/src/com/android/settings/widget/AdaptiveHomepageIconTest.java
+++ b/tests/robotests/src/com/android/settings/widget/AdaptiveIconTest.java
@@ -48,7 +48,7 @@
 import org.robolectric.RuntimeEnvironment;
 
 @RunWith(RobolectricTestRunner.class)
-public class AdaptiveHomepageIconTest {
+public class AdaptiveIconTest {
 
     private Context mContext;
     private ActivityInfo mActivityInfo;
@@ -64,8 +64,8 @@
 
     @Test
     public void createIcon_shouldSetBackgroundAndInset() {
-        final AdaptiveHomepageIcon icon =
-                new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
+        final AdaptiveIcon icon =
+                new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK));
 
         assertThat(icon.getNumberOfLayers()).isEqualTo(2);
         assertThat(icon.getDrawable(0)).isInstanceOf(AdaptiveIconShapeDrawable.class);
@@ -73,8 +73,8 @@
 
     @Test
     public void setBackgroundColor_shouldUpdateColorFilter() {
-        final AdaptiveHomepageIcon icon =
-                spy(new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK)));
+        final AdaptiveIcon icon =
+                spy(new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK)));
         final ShapeDrawable background = mock(ShapeDrawable.class);
         when(icon.getDrawable(0)).thenReturn(background);
 
@@ -89,8 +89,8 @@
         mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB, 0xff0000);
         doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings_accent))
                 .when(tile).getIcon(mContext);
-        final AdaptiveHomepageIcon icon =
-                new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
+        final AdaptiveIcon icon =
+                new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK));
 
         icon.setBackgroundColor(mContext, tile);
         assertThat(icon.mBackgroundColor).isEqualTo(0xff0000);
@@ -101,8 +101,8 @@
         final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
         doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings_accent))
             .when(tile).getIcon(mContext);
-        final AdaptiveHomepageIcon icon =
-            new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
+        final AdaptiveIcon icon =
+            new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK));
 
         icon.setBackgroundColor(mContext, tile);
 
@@ -118,11 +118,24 @@
         doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings_accent))
                 .when(tile).getIcon(mContext);
 
-        final AdaptiveHomepageIcon icon =
-                new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
+        final AdaptiveIcon icon =
+                new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK));
         icon.setBackgroundColor(mContext, tile);
 
         assertThat(icon.mBackgroundColor)
                 .isEqualTo(mContext.getColor(R.color.material_blue_500));
     }
+
+    @Test
+    public void getConstantState_returnCorrectState() {
+        final AdaptiveIcon icon =
+                new AdaptiveIcon(mContext, new ColorDrawable(Color.BLACK));
+        icon.setBackgroundColor(Color.YELLOW);
+
+        final AdaptiveIcon.AdaptiveConstantState state =
+                (AdaptiveIcon.AdaptiveConstantState) icon.getConstantState();
+
+        assertThat(state.color).isEqualTo(Color.YELLOW);
+        assertThat(state.context).isEqualTo(mContext);
+    }
 }