Use adaptive icon shapes for settings homeepage

- Add AdaptiveIconShapeDrawable for the homepage icon backgrounds
- Rename RoundedHomepageIcon -> AdaptiveHomepageIcon to reflect that the
adaptive icon shape is used

Bug: 123829919
Test: mp settings; manually viewing homepage icons
Change-Id: I9fddfbf57461b300200f30f716d861878bbbcc38
diff --git a/res/drawable/ic_homepage_about.xml b/res/drawable/ic_homepage_about.xml
index d47a740..07dbb34 100644
--- a/res/drawable/ic_homepage_about.xml
+++ b/res/drawable/ic_homepage_about.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_about_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_about_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_accessibility.xml b/res/drawable/ic_homepage_accessibility.xml
index 07c9ef2..39f241b 100644
--- a/res/drawable/ic_homepage_accessibility.xml
+++ b/res/drawable/ic_homepage_accessibility.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_accessibility_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_accessibility_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_accounts.xml b/res/drawable/ic_homepage_accounts.xml
index ee33505..17408ed 100644
--- a/res/drawable/ic_homepage_accounts.xml
+++ b/res/drawable/ic_homepage_accounts.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_accounts_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_accounts_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_apps.xml b/res/drawable/ic_homepage_apps.xml
index 3d18d09..2a6789c 100644
--- a/res/drawable/ic_homepage_apps.xml
+++ b/res/drawable/ic_homepage_apps.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_app_and_notification_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_app_and_notification_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_battery.xml b/res/drawable/ic_homepage_battery.xml
index abafdcb..87bb5be 100644
--- a/res/drawable/ic_homepage_battery.xml
+++ b/res/drawable/ic_homepage_battery.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_battery_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_battery_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_connected_device.xml b/res/drawable/ic_homepage_connected_device.xml
index 483427c..f3ce186 100644
--- a/res/drawable/ic_homepage_connected_device.xml
+++ b/res/drawable/ic_homepage_connected_device.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_connected_device_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_connected_device_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_display.xml b/res/drawable/ic_homepage_display.xml
index 893a583..fba7149 100644
--- a/res/drawable/ic_homepage_display.xml
+++ b/res/drawable/ic_homepage_display.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_display_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_display_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_generic_background.xml b/res/drawable/ic_homepage_generic_background.xml
deleted file mode 100644
index 37273a0..0000000
--- a/res/drawable/ic_homepage_generic_background.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2018 The Android Open Source Project
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-  -->
-<shape xmlns:android="http://schemas.android.com/apk/res/android"
-       android:shape="oval">
-    <solid
-        android:color="@color/homepage_generic_icon_background" />
-    <size
-        android:width="@dimen/dashboard_tile_image_size"
-        android:height="@dimen/dashboard_tile_image_size" />
-</shape>
\ No newline at end of file
diff --git a/res/drawable/ic_homepage_location.xml b/res/drawable/ic_homepage_location.xml
index 413801b..c5d6e89 100644
--- a/res/drawable/ic_homepage_location.xml
+++ b/res/drawable/ic_homepage_location.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_location_background"/>
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size"/>
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_location_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_network.xml b/res/drawable/ic_homepage_network.xml
index 5ed023a..1457ab9 100644
--- a/res/drawable/ic_homepage_network.xml
+++ b/res/drawable/ic_homepage_network.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_network_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_network_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_privacy.xml b/res/drawable/ic_homepage_privacy.xml
index eec3c94..a102905 100644
--- a/res/drawable/ic_homepage_privacy.xml
+++ b/res/drawable/ic_homepage_privacy.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_privacy_background"/>
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size"/>
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_privacy_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_security.xml b/res/drawable/ic_homepage_security.xml
index 5a6ed97..0b6a1fd 100644
--- a/res/drawable/ic_homepage_security.xml
+++ b/res/drawable/ic_homepage_security.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_security_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_security_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_sound.xml b/res/drawable/ic_homepage_sound.xml
index a7369ad..21995c5 100644
--- a/res/drawable/ic_homepage_sound.xml
+++ b/res/drawable/ic_homepage_sound.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_sound_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_sound_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_storage.xml b/res/drawable/ic_homepage_storage.xml
index 604cf51..5e5c3ab 100644
--- a/res/drawable/ic_homepage_storage.xml
+++ b/res/drawable/ic_homepage_storage.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_storage_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_storage_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_support.xml b/res/drawable/ic_homepage_support.xml
index 0936304..906dd6c 100644
--- a/res/drawable/ic_homepage_support.xml
+++ b/res/drawable/ic_homepage_support.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_support_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_support_background" />
     </item>
 
     <item
diff --git a/res/drawable/ic_homepage_system_dashboard.xml b/res/drawable/ic_homepage_system_dashboard.xml
index 60f0476..5e9f372 100644
--- a/res/drawable/ic_homepage_system_dashboard.xml
+++ b/res/drawable/ic_homepage_system_dashboard.xml
@@ -18,13 +18,10 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item>
-        <shape android:shape="oval">
-            <solid
-                android:color="@color/homepage_system_background" />
-            <size
-                android:width="@dimen/dashboard_tile_image_size"
-                android:height="@dimen/dashboard_tile_image_size" />
-        </shape>
+        <com.android.settings.homepage.AdaptiveIconShapeDrawable
+            android:width="@dimen/dashboard_tile_image_size"
+            android:height="@dimen/dashboard_tile_image_size"
+            android:color="@color/homepage_system_background" />
     </item>
 
     <item
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index 69e86cd..6348b91 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.RoundedHomepageIcon;
+import com.android.settings.widget.AdaptiveHomepageIcon;
 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 RoundedHomepageIcon(mContext, iconDrawable);
-                ((RoundedHomepageIcon) iconDrawable).setBackgroundColor(mContext, tile);
+                iconDrawable = new AdaptiveHomepageIcon(mContext, iconDrawable);
+                ((AdaptiveHomepageIcon) iconDrawable).setBackgroundColor(mContext, tile);
             }
             preference.setIcon(iconDrawable);
         } else if (tile.getMetaData() != null
diff --git a/src/com/android/settings/homepage/AdaptiveIconShapeDrawable.java b/src/com/android/settings/homepage/AdaptiveIconShapeDrawable.java
new file mode 100644
index 0000000..62b768a
--- /dev/null
+++ b/src/com/android/settings/homepage/AdaptiveIconShapeDrawable.java
@@ -0,0 +1,43 @@
+package com.android.settings.homepage;
+
+import android.content.res.Resources;
+import android.content.res.Resources.Theme;
+import android.graphics.Path;
+import android.graphics.drawable.AdaptiveIconDrawable;
+import android.graphics.drawable.ShapeDrawable;
+import android.graphics.drawable.shapes.PathShape;
+import android.util.AttributeSet;
+import android.util.PathParser;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
+
+/**
+ * Draws a filled {@link ShapeDrawable} using the path from {@link AdaptiveIconDrawable}.
+ */
+public class AdaptiveIconShapeDrawable extends ShapeDrawable {
+    public AdaptiveIconShapeDrawable() {
+        super();
+    }
+
+    public AdaptiveIconShapeDrawable(Resources resources) {
+        super();
+        init(resources);
+    }
+
+    @Override
+    public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
+            throws XmlPullParserException, IOException {
+        super.inflate(r, parser, attrs, theme);
+        init(r);
+    }
+
+    private void init(Resources resources) {
+        final float pathSize = AdaptiveIconDrawable.MASK_SIZE;
+        final Path path = new Path(PathParser.createPathFromPathData(
+                resources.getString(com.android.internal.R.string.config_icon_mask)));
+        setShape(new PathShape(path, pathSize, pathSize));
+    }
+}
diff --git a/src/com/android/settings/widget/RoundedHomepageIcon.java b/src/com/android/settings/widget/AdaptiveHomepageIcon.java
similarity index 90%
rename from src/com/android/settings/widget/RoundedHomepageIcon.java
rename to src/com/android/settings/widget/AdaptiveHomepageIcon.java
index f7927e7..bec5d8d 100644
--- a/src/com/android/settings/widget/RoundedHomepageIcon.java
+++ b/src/com/android/settings/widget/AdaptiveHomepageIcon.java
@@ -32,18 +32,19 @@
 import androidx.annotation.VisibleForTesting;
 
 import com.android.settings.R;
+import com.android.settings.homepage.AdaptiveIconShapeDrawable;
 import com.android.settingslib.drawer.Tile;
 
-public class RoundedHomepageIcon extends LayerDrawable {
+public class AdaptiveHomepageIcon extends LayerDrawable {
 
-    private static final String TAG = "RoundedHomepageIcon";
+    private static final String TAG = "AdaptiveHomepageIcon";
 
     @VisibleForTesting(otherwise = NONE)
     int mBackgroundColor = -1;
 
-    public RoundedHomepageIcon(Context context, Drawable foreground) {
+    public AdaptiveHomepageIcon(Context context, Drawable foreground) {
         super(new Drawable[]{
-                context.getDrawable(R.drawable.ic_homepage_generic_background),
+                new AdaptiveIconShapeDrawable(context.getResources()),
                 foreground
         });
         final int insetPx = context.getResources()
diff --git a/tests/robotests/src/com/android/settings/widget/RoundedHomepageIconTest.java b/tests/robotests/src/com/android/settings/widget/AdaptiveHomepageIconTest.java
similarity index 83%
rename from tests/robotests/src/com/android/settings/widget/RoundedHomepageIconTest.java
rename to tests/robotests/src/com/android/settings/widget/AdaptiveHomepageIconTest.java
index 21ba907..32690a3 100644
--- a/tests/robotests/src/com/android/settings/widget/RoundedHomepageIconTest.java
+++ b/tests/robotests/src/com/android/settings/widget/AdaptiveHomepageIconTest.java
@@ -37,9 +37,9 @@
 import android.os.Bundle;
 
 import com.android.settings.R;
+import com.android.settings.homepage.AdaptiveIconShapeDrawable;
 import com.android.settingslib.drawer.CategoryKey;
 import com.android.settingslib.drawer.Tile;
-import com.android.settingslib.testutils.DrawableTestHelper;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -48,7 +48,7 @@
 import org.robolectric.RuntimeEnvironment;
 
 @RunWith(RobolectricTestRunner.class)
-public class RoundedHomepageIconTest {
+public class AdaptiveHomepageIconTest {
 
     private Context mContext;
     private ActivityInfo mActivityInfo;
@@ -64,18 +64,17 @@
 
     @Test
     public void createIcon_shouldSetBackgroundAndInset() {
-        final RoundedHomepageIcon icon =
-                new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
+        final AdaptiveHomepageIcon icon =
+                new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
 
         assertThat(icon.getNumberOfLayers()).isEqualTo(2);
-        DrawableTestHelper.assertDrawableResId(icon.getDrawable(0),
-                R.drawable.ic_homepage_generic_background);
+        assertThat(icon.getDrawable(0)).isInstanceOf(AdaptiveIconShapeDrawable.class);
     }
 
     @Test
     public void setBackgroundColor_shouldUpdateColorFilter() {
-        final RoundedHomepageIcon icon =
-                spy(new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK)));
+        final AdaptiveHomepageIcon icon =
+                spy(new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK)));
         final ShapeDrawable background = mock(ShapeDrawable.class);
         when(icon.getDrawable(0)).thenReturn(background);
 
@@ -90,8 +89,8 @@
         mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB, 0xff0000);
         doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings))
                 .when(tile).getIcon(mContext);
-        final RoundedHomepageIcon icon =
-                new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
+        final AdaptiveHomepageIcon icon =
+                new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
 
         icon.setBackgroundColor(mContext, tile);
         assertThat(icon.mBackgroundColor).isEqualTo(0xff0000);
@@ -105,8 +104,8 @@
         doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings))
                 .when(tile).getIcon(mContext);
 
-        final RoundedHomepageIcon icon =
-                new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
+        final AdaptiveHomepageIcon icon =
+                new AdaptiveHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
         icon.setBackgroundColor(mContext, tile);
 
         assertThat(icon.mBackgroundColor)