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

Commit f69bd226 authored by Gregory Montoir's avatar Gregory Montoir Committed by Android (Google) Code Review
Browse files

Merge "Add PackageInstaller to SettingsLib.Utils.isEssentialPackage" into main

parents c1f77cb8 cadcf5c4
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
import android.content.pm.UserInfo;
import android.content.res.ColorStateList;
@@ -32,6 +33,7 @@ import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.TetheringManager;
import android.net.Uri;
import android.net.vcn.VcnUtils;
import android.net.wifi.WifiInfo;
import android.os.BatteryManager;
@@ -79,11 +81,14 @@ public class Utils {
    @VisibleForTesting
    static final String STORAGE_MANAGER_ENABLED_PROPERTY = "ro.storage_manager.enabled";

    private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";

    private static Signature[] sSystemSignature;
    private static String sPermissionControllerPackageName;
    private static String sServicesSystemSharedLibPackageName;
    private static String sSharedSystemSharedLibPackageName;
    private static String sDefaultWebViewPackageName;
    private static String sPackageInstallerPackageName;

    static final int[] WIFI_PIE = {
        com.android.internal.R.drawable.ic_wifi_signal_0,
@@ -496,9 +501,29 @@ public class Utils {
                || packageName.equals(sSharedSystemSharedLibPackageName)
                || packageName.equals(PrintManager.PRINT_SPOOLER_PACKAGE_NAME)
                || packageName.equals(getDefaultWebViewPackageName(pm))
                || packageName.equals(getPackageInstallerPackageName(pm))
                || isDeviceProvisioningPackage(resources, packageName);
    }

    /** Return the package name of the installer */
    private static String getPackageInstallerPackageName(PackageManager pm) {
        if (sPackageInstallerPackageName != null) {
            return sPackageInstallerPackageName;
        }
        final Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setDataAndType(Uri.parse("content://com.example/foo.apk"), PACKAGE_MIME_TYPE);
        final List<ResolveInfo> matches =
                pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
        if (matches.size() == 1) {
            final ResolveInfo resolveInfo = matches.get(0);
            if (resolveInfo.activityInfo.applicationInfo.isPrivilegedApp()) {
                sPackageInstallerPackageName = resolveInfo.getComponentInfo().packageName;
            }
        }
        return sPackageInstallerPackageName;
    }

    /**
     * Returns {@code true} if the supplied package is the device provisioning app. Otherwise,
     * returns {@code false}.