Remove IconShapeOverride

Bug: 120736782
Change-Id: Iee44f10ff2b9ec447ae74d9ad6a0aa3668c401d6
diff --git a/quickstep/src/com/android/quickstep/LauncherSearchIndexablesProvider.java b/quickstep/src/com/android/quickstep/LauncherSearchIndexablesProvider.java
index f5e1f6e..5d6fbe2 100644
--- a/quickstep/src/com/android/quickstep/LauncherSearchIndexablesProvider.java
+++ b/quickstep/src/com/android/quickstep/LauncherSearchIndexablesProvider.java
@@ -29,7 +29,6 @@
 import android.util.Xml;
 
 import com.android.launcher3.R;
-import com.android.launcher3.graphics.IconShapeOverride;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -88,8 +87,6 @@
             } catch (IOException |XmlPullParserException e) {
                 throw new RuntimeException(e);
             }
-        } else if (!IconShapeOverride.isSupported(getContext())) {
-            cursor.addRow(new String[] {IconShapeOverride.KEY_PREFERENCE});
         }
         return cursor;
     }
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3f01278..b1eff24 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -205,23 +205,23 @@
     <!-- Text description of the setting that allows the automatic placement of launcher shortcuts for applications and games installed on the device [CHAR LIMIT=NONE] -->
     <string name="auto_add_shortcuts_description">For new apps</string>
 
-    <!-- Developer setting to change the shape of icons on home screen. [CHAR LIMIT=50] -->
-    <string name="icon_shape_override_label">Change icon shape</string>
-    <!-- Subtext explaining that the icons will only be affected on the home screen. This text follows the actual icon action: Change icon shape, on Home screen [CHAR LIMIT=100] -->
-    <string name="icon_shape_override_label_location">on Home screen</string>
-    <!-- Option to not change the icon shape on home screen and use the system default setting instead. [CHAR LIMIT=50] -->
-    <string name="icon_shape_system_default">Use system default</string>
-    <!-- Option to change the shape of the home screen icons to a square. [CHAR LIMIT=50] -->
-    <string name="icon_shape_square">Square</string>
-    <!-- Option to change the shape of the home screen icons to a squircle. This represents the name of the shape somewhere between a circle and a square. [CHAR LIMIT=50] -->
-    <string name="icon_shape_squircle">Squircle</string>
-    <!-- Option to change the shape of the home screen icons to a circle. [CHAR LIMIT=50] -->
-    <string name="icon_shape_circle">Circle</string>
-    <!-- Option to change the shape of the home screen icons to a teardrop. This represents the name of the shape similar to a circle with with the bottom right corner pushed out like a square [CHAR LIMIT=50] -->
-    <string name="icon_shape_teardrop">Teardrop</string>
+    <!-- Developer setting to change the shape of icons on home screen. -->
+    <string name="icon_shape_override_label" translatable="false">Change icon shape</string>
+    <!-- Subtext explaining that the icons will only be affected on the home screen. This text follows the actual icon action: Change icon shape, on Home screen -->
+    <string name="icon_shape_override_label_location" translatable="false">on Home screen</string>
+    <!-- Option to not change the icon shape on home screen and use the system default setting instead.  -->
+    <string name="icon_shape_system_default" translatable="false">Use system default</string>
+    <!-- Option to change the shape of the home screen icons to a square. -->
+    <string name="icon_shape_square" translatable="false">Square</string>
+    <!-- Option to change the shape of the home screen icons to a squircle. This represents the name of the shape somewhere between a circle and a square. -->
+    <string name="icon_shape_squircle" translatable="false">Squircle</string>
+    <!-- Option to change the shape of the home screen icons to a circle. -->
+    <string name="icon_shape_circle" translatable="false">Circle</string>
+    <!-- Option to change the shape of the home screen icons to a teardrop. This represents the name of the shape similar to a circle with with the bottom right corner pushed out like a square -->
+    <string name="icon_shape_teardrop" translatable="false">Teardrop</string>
 
-    <!-- Message shown in the progress dialog when the icon shape override is being applied [CHAR LIMIT=100]-->
-    <string name="icon_shape_override_progress">Applying icon shape changes</string>
+    <!-- Message shown in the progress dialog when the icon shape override is being applied -->
+    <string name="icon_shape_override_progress" translatable="false">Applying icon shape changes</string>
 
     <!-- Label on an icon that references an uninstalled package, for which we have no information about when it might be installed. [CHAR_LIMIT=15] -->
     <string name="package_state_unknown">Unknown</string>
diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml
index be3cb0e..7e72208 100644
--- a/res/xml/launcher_preferences.xml
+++ b/res/xml/launcher_preferences.xml
@@ -44,15 +44,6 @@
         android:defaultValue="@bool/allow_rotation"
         android:persistent="true" />
 
-    <ListPreference
-        android:key="pref_override_icon_shape"
-        android:title="@string/icon_shape_override_label"
-        android:summary="%s"
-        android:entries="@array/icon_shape_override_paths_names"
-        android:entryValues="@array/icon_shape_override_paths_values"
-        android:defaultValue=""
-        android:persistent="false" />
-
     <androidx.preference.PreferenceScreen
         android:key="pref_developer_options"
         android:persistent="false"
diff --git a/src/com/android/launcher3/MainProcessInitializer.java b/src/com/android/launcher3/MainProcessInitializer.java
index a253893..9692d73 100644
--- a/src/com/android/launcher3/MainProcessInitializer.java
+++ b/src/com/android/launcher3/MainProcessInitializer.java
@@ -20,7 +20,6 @@
 
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.folder.FolderShape;
-import com.android.launcher3.graphics.IconShapeOverride;
 import com.android.launcher3.logging.FileLog;
 import com.android.launcher3.util.ResourceBasedOverride;
 
@@ -38,7 +37,6 @@
     protected void init(Context context) {
         FileLog.setDir(context.getApplicationContext().getFilesDir());
         FeatureFlags.initialize(context);
-        IconShapeOverride.apply(context);
         SessionCommitReceiver.applyDefaultUserPrefs(context);
         FolderShape.init();
     }
diff --git a/src/com/android/launcher3/graphics/IconShapeOverride.java b/src/com/android/launcher3/graphics/IconShapeOverride.java
deleted file mode 100644
index b636c6d..0000000
--- a/src/com/android/launcher3/graphics/IconShapeOverride.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-package com.android.launcher3.graphics;
-
-import static com.android.launcher3.Utilities.getDevicePrefs;
-
-import android.annotation.TargetApi;
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.content.Intent;
-import android.content.res.Resources;
-import android.os.Build;
-import android.os.SystemClock;
-import android.provider.Settings;
-import android.text.TextUtils;
-import android.util.Log;
-
-import com.android.launcher3.LauncherAppState;
-import com.android.launcher3.LauncherModel;
-import com.android.launcher3.R;
-import com.android.launcher3.Utilities;
-import com.android.launcher3.util.LooperExecutor;
-
-import java.lang.reflect.Field;
-
-import androidx.annotation.NonNull;
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-import androidx.preference.Preference.OnPreferenceChangeListener;
-
-/**
- * Utility class to override shape of {@link android.graphics.drawable.AdaptiveIconDrawable}.
- */
-@TargetApi(Build.VERSION_CODES.O)
-public class IconShapeOverride {
-
-    private static final String TAG = "IconShapeOverride";
-
-    public static final String KEY_PREFERENCE = "pref_override_icon_shape";
-
-    // Time to wait before killing the process this ensures that the progress bar is visible for
-    // sufficient time so that there is no flicker.
-    private static final long PROCESS_KILL_DELAY_MS = 1000;
-
-    private static final int RESTART_REQUEST_CODE = 42; // the answer to everything
-
-    public static boolean isSupported(Context context) {
-        if (!Utilities.ATLEAST_OREO) {
-            return false;
-        }
-        // Only supported when developer settings is enabled
-        if (Settings.Global.getInt(context.getContentResolver(),
-                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 1) {
-            return false;
-        }
-
-        try {
-            if (getSystemResField().get(null) != Resources.getSystem()) {
-                // Our assumption that mSystem is the system resource is not true.
-                return false;
-            }
-        } catch (Exception e) {
-            // Ignore, not supported
-            return false;
-        }
-
-        return getConfigResId() != 0;
-    }
-
-    public static void apply(Context context) {
-        if (!Utilities.ATLEAST_OREO) {
-            return;
-        }
-        String path = getAppliedValue(context);
-        if (TextUtils.isEmpty(path)) {
-            return;
-        }
-        if (!isSupported(context)) {
-            return;
-        }
-
-        // magic
-        try {
-            Resources override =
-                    new ResourcesOverride(Resources.getSystem(), getConfigResId(), path);
-            getSystemResField().set(null, override);
-        } catch (Exception e) {
-            Log.e(TAG, "Unable to override icon shape", e);
-            // revert value.
-            getDevicePrefs(context).edit().remove(KEY_PREFERENCE).apply();
-        }
-    }
-
-    private static Field getSystemResField() throws Exception {
-        Field staticField = Resources.class.getDeclaredField("mSystem");
-        staticField.setAccessible(true);
-        return staticField;
-    }
-
-    private static int getConfigResId() {
-        return Resources.getSystem().getIdentifier("config_icon_mask", "string", "android");
-    }
-
-    private static String getAppliedValue(Context context) {
-        return getDevicePrefs(context).getString(KEY_PREFERENCE, "");
-    }
-
-    public static void handlePreferenceUi(ListPreference preference) {
-        Context context = preference.getContext();
-        preference.setValue(getAppliedValue(context));
-        preference.setOnPreferenceChangeListener(new PreferenceChangeHandler(context));
-    }
-
-    private static class ResourcesOverride extends Resources {
-
-        private final int mOverrideId;
-        private final String mOverrideValue;
-
-        @SuppressWarnings("deprecation")
-        public ResourcesOverride(Resources parent, int overrideId, String overrideValue) {
-            super(parent.getAssets(), parent.getDisplayMetrics(), parent.getConfiguration());
-            mOverrideId = overrideId;
-            mOverrideValue = overrideValue;
-        }
-
-        @NonNull
-        @Override
-        public String getString(int id) throws NotFoundException {
-            if (id == mOverrideId) {
-                return mOverrideValue;
-            }
-            return super.getString(id);
-        }
-    }
-
-    private static class PreferenceChangeHandler implements OnPreferenceChangeListener {
-
-        private final Context mContext;
-
-        private PreferenceChangeHandler(Context context) {
-            mContext = context;
-        }
-
-        @Override
-        public boolean onPreferenceChange(Preference preference, Object o) {
-            String newValue = (String) o;
-            if (!getAppliedValue(mContext).equals(newValue)) {
-                // Value has changed
-                ProgressDialog.show(mContext,
-                        null /* title */,
-                        mContext.getString(R.string.icon_shape_override_progress),
-                        true /* indeterminate */,
-                        false /* cancelable */);
-                new LooperExecutor(LauncherModel.getWorkerLooper()).execute(
-                        new OverrideApplyHandler(mContext, newValue));
-            }
-            return false;
-        }
-    }
-
-    private static class OverrideApplyHandler implements Runnable {
-
-        private final Context mContext;
-        private final String mValue;
-
-        private OverrideApplyHandler(Context context, String value) {
-            mContext = context;
-            mValue = value;
-        }
-
-        @Override
-        public void run() {
-            // Synchronously write the preference.
-            getDevicePrefs(mContext).edit().putString(KEY_PREFERENCE, mValue).commit();
-            // Clear the icon cache.
-            LauncherAppState.getInstance(mContext).getIconCache().clear();
-
-            // Wait for it
-            try {
-                Thread.sleep(PROCESS_KILL_DELAY_MS);
-            } catch (Exception e) {
-                Log.e(TAG, "Error waiting", e);
-            }
-
-            // Schedule an alarm before we kill ourself.
-            Intent homeIntent = new Intent(Intent.ACTION_MAIN)
-                    .addCategory(Intent.CATEGORY_HOME)
-                    .setPackage(mContext.getPackageName())
-                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            PendingIntent pi = PendingIntent.getActivity(mContext, RESTART_REQUEST_CODE,
-                    homeIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
-            mContext.getSystemService(AlarmManager.class).setExact(
-                    AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 50, pi);
-
-            // Kill process
-            android.os.Process.killProcess(android.os.Process.myPid());
-        }
-    }
-}
diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java
index 77682e5..6e7188f 100644
--- a/src/com/android/launcher3/settings/SettingsActivity.java
+++ b/src/com/android/launcher3/settings/SettingsActivity.java
@@ -32,11 +32,9 @@
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.config.FeatureFlags;
-import com.android.launcher3.graphics.IconShapeOverride;
 import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
 import com.android.launcher3.util.SecureSettingsObserver;
 
-import androidx.preference.ListPreference;
 import androidx.preference.Preference;
 import androidx.preference.PreferenceFragment;
 import androidx.preference.PreferenceFragment.OnPreferenceStartFragmentCallback;
@@ -185,13 +183,6 @@
                 case ADD_ICON_PREFERENCE_KEY:
                     return Utilities.ATLEAST_OREO;
 
-                case IconShapeOverride.KEY_PREFERENCE:
-                    if (!IconShapeOverride.isSupported(getActivity())) {
-                        return false;
-                    }
-                    IconShapeOverride.handlePreferenceUi((ListPreference) preference);
-                    return true;
-
                 case ALLOW_ROTATION_PREFERENCE_KEY:
                     if (getResources().getBoolean(R.bool.allow_rotation)) {
                         // Launcher supports rotation by default. No need to show this setting.