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

Commit eb66d782 authored by Yanting Yang's avatar Yanting Yang Committed by Automerger Merge Worker
Browse files

Merge "Update mainline module utils function of AppUtils" into rvc-dev am: 2db44245

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11824582

Change-Id: I78b16a6cd8f2f8cb6b0ba8540e700eef323250d6
parents 95a9a1c4 2db44245
Loading
Loading
Loading
Loading
+18 −3
Original line number Original line Diff line number Diff line
@@ -22,10 +22,12 @@ import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
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.hardware.usb.IUsbManager;
import android.hardware.usb.IUsbManager;
import android.net.Uri;
import android.net.Uri;
import android.os.Environment;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserHandle;
@@ -146,10 +148,23 @@ public class AppUtils {
    /**
    /**
     * Returns a boolean indicating whether a given package is a mainline module.
     * Returns a boolean indicating whether a given package is a mainline module.
     */
     */
    public static boolean isMainlineModule(Context context, String packageName) {
    public static boolean isMainlineModule(PackageManager pm, String packageName) {
        final PackageManager pm = context.getPackageManager();
        // Check if the package is listed among the system modules.
        try {
        try {
            return pm.getModuleInfo(packageName, 0 /* flags */) != null;
            pm.getModuleInfo(packageName, 0 /* flags */);
            return true;
        } catch (PackageManager.NameNotFoundException e) {
            //pass
        }

        try {
            final PackageInfo pkg = pm.getPackageInfo(packageName, 0 /* flags */);
            // Check if the package is contained in an APEX. There is no public API to properly
            // check whether a given APK package comes from an APEX registered as module.
            // Therefore we conservatively assume that any package scanned from an /apex path is
            // a system package.
            return pkg.applicationInfo.sourceDir.startsWith(
                    Environment.getApexDirectory().getAbsolutePath());
        } catch (PackageManager.NameNotFoundException e) {
        } catch (PackageManager.NameNotFoundException e) {
            return false;
            return false;
        }
        }