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

Commit c3db3399 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "System/root/shell need to explicitly ask for static libs to get them" into oc-dev

parents bb921877 9e77977f
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ public abstract class PackageManager {
            MATCH_DISABLED_COMPONENTS,
            MATCH_DISABLED_UNTIL_USED_COMPONENTS,
            MATCH_INSTANT,
            MATCH_STATIC_SHARED_LIBRARIES,
            GET_DISABLED_UNTIL_USED_COMPONENTS,
            GET_UNINSTALLED_PACKAGES,
    })
@@ -177,6 +178,7 @@ public abstract class PackageManager {
            MATCH_SYSTEM_ONLY,
            MATCH_UNINSTALLED_PACKAGES,
            MATCH_INSTANT,
            MATCH_STATIC_SHARED_LIBRARIES,
            GET_DISABLED_COMPONENTS,
            GET_DISABLED_UNTIL_USED_COMPONENTS,
            GET_UNINSTALLED_PACKAGES,
@@ -474,6 +476,16 @@ public abstract class PackageManager {
     */
    public static final int MATCH_EXPLICITLY_VISIBLE_ONLY = 0x02000000;

    /**
     * Internal {@link PackageInfo} flag: include static shared libraries.
     * Apps that depend on static shared libs can always access the version
     * of the lib they depend on. System/shell/root can access all shared
     * libs regardless of dependency but need to explicitly ask for them
     * via this flag.
     * @hide
     */
    public static final int MATCH_STATIC_SHARED_LIBRARIES = 0x04000000;

    /**
     * Internal flag used to indicate that a system component has done their
     * homework and verified that they correctly handle packages and components
+22 −18
Original line number Diff line number Diff line
@@ -3615,7 +3615,7 @@ public class PackageManagerService extends IPackageManager.Stub
            if (matchFactoryOnly) {
                final PackageSetting ps = mSettings.getDisabledSystemPkgLPr(packageName);
                if (ps != null) {
                    if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId)) {
                    if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId, flags)) {
                        return null;
                    }
                    return generatePackageInfo(ps, flags, userId);
@@ -3630,14 +3630,14 @@ public class PackageManagerService extends IPackageManager.Stub
                Log.v(TAG, "getPackageInfo " + packageName + ": " + p);
            if (p != null) {
                if (filterSharedLibPackageLPr((PackageSetting) p.mExtras,
                        Binder.getCallingUid(), userId)) {
                        Binder.getCallingUid(), userId, flags)) {
                    return null;
                }
                return generatePackageInfo((PackageSetting)p.mExtras, flags, userId);
            }
            if (!matchFactoryOnly && (flags & MATCH_KNOWN_PACKAGES) != 0) {
                final PackageSetting ps = mSettings.mPackages.get(packageName);
                if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId)) {
                if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId, flags)) {
                    return null;
                }
                return generatePackageInfo(ps, flags, userId);
@@ -3646,14 +3646,18 @@ public class PackageManagerService extends IPackageManager.Stub
        return null;
    }
    private boolean filterSharedLibPackageLPr(@Nullable PackageSetting ps, int uid, int userId) {
    private boolean filterSharedLibPackageLPr(@Nullable PackageSetting ps, int uid, int userId,
            int flags) {
        // Callers can access only the libs they depend on, otherwise they need to explicitly
        // ask for the shared libraries given the caller is allowed to access all static libs.
        if ((flags & PackageManager.MATCH_STATIC_SHARED_LIBRARIES) != 0) {
            // System/shell/root get to see all static libs
            final int appId = UserHandle.getAppId(uid);
            if (appId == Process.SYSTEM_UID || appId == Process.SHELL_UID
                    || appId == Process.ROOT_UID) {
                return false;
            }
        }
        // No package means no static lib as it is always on internal storage
        if (ps == null || ps.pkg == null || !ps.pkg.applicationInfo.isStaticSharedLibrary()) {
@@ -3847,7 +3851,7 @@ public class PackageManagerService extends IPackageManager.Stub
        if (!sUserManager.exists(userId)) return null;
        PackageSetting ps = mSettings.mPackages.get(packageName);
        if (ps != null) {
            if (filterSharedLibPackageLPr(ps, uid, userId)) {
            if (filterSharedLibPackageLPr(ps, uid, userId, flags)) {
                return null;
            }
            if (ps.pkg == null) {
@@ -3888,7 +3892,7 @@ public class PackageManagerService extends IPackageManager.Stub
            if (p != null) {
                PackageSetting ps = mSettings.mPackages.get(packageName);
                if (ps == null) return null;
                if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId)) {
                if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId, flags)) {
                    return null;
                }
                // Note: isEnabledLP() does not apply here - always return info
@@ -4349,7 +4353,6 @@ public class PackageManagerService extends IPackageManager.Stub
                    }
                    final long identity = Binder.clearCallingIdentity();
                    try {
                        // TODO: We will change version code to long, so in the new API it is long
                        PackageInfo packageInfo = getPackageInfoVersioned(
                                libInfo.getDeclaringPackage(), flags, userId);
                        if (packageInfo == null) {
@@ -4492,7 +4495,8 @@ public class PackageManagerService extends IPackageManager.Stub
                    }
                    PackageSetting ps = mSettings.getPackageLPr(libEntry.apk);
                    if (ps != null && !filterSharedLibPackageLPr(ps, Binder.getCallingUid(),
                            UserHandle.getUserId(Binder.getCallingUid()))) {
                            UserHandle.getUserId(Binder.getCallingUid()),
                            PackageManager.MATCH_STATIC_SHARED_LIBRARIES)) {
                        if (libs == null) {
                            libs = new ArraySet<>();
                        }
@@ -7547,7 +7551,7 @@ public class PackageManagerService extends IPackageManager.Stub
            if (listUninstalled) {
                list = new ArrayList<>(mSettings.mPackages.size());
                for (PackageSetting ps : mSettings.mPackages.values()) {
                    if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId)) {
                    if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId, flags)) {
                        continue;
                    }
                    final PackageInfo pi = generatePackageInfo(ps, flags, userId);
@@ -7559,7 +7563,7 @@ public class PackageManagerService extends IPackageManager.Stub
                list = new ArrayList<>(mPackages.size());
                for (PackageParser.Package p : mPackages.values()) {
                    if (filterSharedLibPackageLPr((PackageSetting) p.mExtras,
                            Binder.getCallingUid(), userId)) {
                            Binder.getCallingUid(), userId, flags)) {
                        continue;
                    }
                    final PackageInfo pi = generatePackageInfo((PackageSetting)
@@ -7664,7 +7668,7 @@ public class PackageManagerService extends IPackageManager.Stub
                        effectiveFlags |= PackageManager.MATCH_ANY_USER;
                    }
                    if (ps.pkg != null) {
                        if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId)) {
                        if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId, flags)) {
                            continue;
                        }
                        ai = PackageParser.generateApplicationInfo(ps.pkg, effectiveFlags,
@@ -7688,7 +7692,7 @@ public class PackageManagerService extends IPackageManager.Stub
                for (PackageParser.Package p : mPackages.values()) {
                    if (p.mExtras != null) {
                        PackageSetting ps = (PackageSetting) p.mExtras;
                        if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId)) {
                        if (filterSharedLibPackageLPr(ps, Binder.getCallingUid(), userId, flags)) {
                            continue;
                        }
                        ApplicationInfo ai = PackageParser.generateApplicationInfo(p, flags,