Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6741d4db authored by Christopher Tate's avatar Christopher Tate Committed by Android (Google) Code Review
Browse files

Merge "Use META_HOME_ALTERNATE for home app uninstall target" into klp-dev

parents 43d8d440 1ea54975
Loading
Loading
Loading
Loading
+37 −6
Original line number Original line Diff line number Diff line
@@ -18,12 +18,14 @@ package com.android.settings;


import java.util.ArrayList;
import java.util.ArrayList;


import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ResolveInfo;
import android.graphics.ColorFilter;
import android.graphics.ColorFilter;
@@ -94,7 +96,7 @@ public class HomeSettings extends SettingsPreferenceFragment {


    void uninstallApp(HomeAppPreference pref) {
    void uninstallApp(HomeAppPreference pref) {
        // Uninstallation is done by asking the OS to do it
        // Uninstallation is done by asking the OS to do it
       Uri packageURI = Uri.parse("package:" + pref.activityName.getPackageName());
       Uri packageURI = Uri.parse("package:" + pref.uninstallTarget);
       Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
       Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
       uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false);
       uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false);
       int requestCode = REQUESTING_UNINSTALL + (pref.isChecked ? 1 : 0);
       int requestCode = REQUESTING_UNINSTALL + (pref.isChecked ? 1 : 0);
@@ -144,9 +146,8 @@ public class HomeSettings extends SettingsPreferenceFragment {
            try {
            try {
                Drawable icon = info.loadIcon(mPm);
                Drawable icon = info.loadIcon(mPm);
                CharSequence name = info.loadLabel(mPm);
                CharSequence name = info.loadLabel(mPm);
                boolean isSystem = (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
                HomeAppPreference pref = new HomeAppPreference(context, activityName, prefIndex,
                HomeAppPreference pref = new HomeAppPreference(context, activityName, prefIndex,
                        icon, name, this, isSystem);
                        icon, name, this, info);
                mPrefs.add(pref);
                mPrefs.add(pref);
                mPrefGroup.addPreference(pref);
                mPrefGroup.addPreference(pref);
                pref.setEnabled(true);
                pref.setEnabled(true);
@@ -186,14 +187,16 @@ public class HomeSettings extends SettingsPreferenceFragment {
    class HomeAppPreference extends Preference {
    class HomeAppPreference extends Preference {
        ComponentName activityName;
        ComponentName activityName;
        int index;
        int index;
        boolean isSystem;
        HomeSettings fragment;
        HomeSettings fragment;
        final ColorFilter grayscaleFilter;
        final ColorFilter grayscaleFilter;
        boolean isChecked;
        boolean isChecked;


        boolean isSystem;
        String uninstallTarget;

        public HomeAppPreference(Context context, ComponentName activity,
        public HomeAppPreference(Context context, ComponentName activity,
                int i, Drawable icon, CharSequence title,
                int i, Drawable icon, CharSequence title,
                HomeSettings parent, boolean sys) {
                HomeSettings parent, ActivityInfo info) {
            super(context);
            super(context);
            setLayoutResource(R.layout.preference_home_app);
            setLayoutResource(R.layout.preference_home_app);
            setIcon(icon);
            setIcon(icon);
@@ -201,13 +204,41 @@ public class HomeSettings extends SettingsPreferenceFragment {
            activityName = activity;
            activityName = activity;
            fragment = parent;
            fragment = parent;
            index = i;
            index = i;
            isSystem = sys;


            ColorMatrix colorMatrix = new ColorMatrix();
            ColorMatrix colorMatrix = new ColorMatrix();
            colorMatrix.setSaturation(0f);
            colorMatrix.setSaturation(0f);
            float[] matrix = colorMatrix.getArray();
            float[] matrix = colorMatrix.getArray();
            matrix[18] = 0.5f;
            matrix[18] = 0.5f;
            grayscaleFilter = new ColorMatrixColorFilter(colorMatrix);
            grayscaleFilter = new ColorMatrixColorFilter(colorMatrix);

            determineTargets(info);
        }

        // Check whether this activity is bundled on the system, with awareness
        // of the META_HOME_ALTERNATE mechanism.
        private void determineTargets(ActivityInfo info) {
            final Bundle meta = info.metaData;
            if (meta != null) {
                final String altHomePackage = meta.getString(ActivityManager.META_HOME_ALTERNATE);
                if (altHomePackage != null) {
                    try {
                        final int match = mPm.checkSignatures(info.packageName, altHomePackage);
                        if (match >= PackageManager.SIGNATURE_MATCH) {
                            PackageInfo altInfo = mPm.getPackageInfo(altHomePackage, 0);
                            final int altFlags = altInfo.applicationInfo.flags;
                            isSystem = (altFlags & ApplicationInfo.FLAG_SYSTEM) != 0;
                            uninstallTarget = altInfo.packageName;
                            return;
                        }
                    } catch (Exception e) {
                        // e.g. named alternate package not found during lookup
                        Log.w(TAG, "Unable to compare/resolve alternate", e);
                    }
                }
            }
            // No suitable metadata redirect, so use the package's own info
            isSystem = (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
            uninstallTarget = info.packageName;
        }
        }


        @Override
        @Override