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

Commit a46b7b3f authored by Daniel Colascione's avatar Daniel Colascione
Browse files

Cache package and permission information

We use the package settings class as a central point for invalidating
on package information changes; for permission changes, we invalidate
from inside the individual permission data objects.

Bug: 140788621
Test: boots, package tests (pending)
Change-Id: Iec14d4ec872124e7ef4612c72d94c89a7319ace0
parent a6149521
Loading
Loading
Loading
Loading
+5 −10
Original line number Original line Diff line number Diff line
@@ -2215,16 +2215,11 @@ public final class ActivityThread extends ClientTransactionHandler {
    public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo,
    public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo,
            int flags, int userId) {
            int flags, int userId) {
        final boolean differentUser = (UserHandle.myUserId() != userId);
        final boolean differentUser = (UserHandle.myUserId() != userId);
        ApplicationInfo ai;
        ApplicationInfo ai = PackageManager.getApplicationInfoAsUserCached(
        try {
                packageName,
            ai = getPackageManager().getApplicationInfo(packageName,
                PackageManager.GET_SHARED_LIBRARY_FILES
                PackageManager.GET_SHARED_LIBRARY_FILES
                | PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                | PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                (userId < 0) ? UserHandle.myUserId() : userId);
                (userId < 0) ? UserHandle.myUserId() : userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }

        synchronized (mResourcesManager) {
        synchronized (mResourcesManager) {
            WeakReference<LoadedApk> ref;
            WeakReference<LoadedApk> ref;
            if (differentUser) {
            if (differentUser) {
+18 −27
Original line number Original line Diff line number Diff line
@@ -84,6 +84,7 @@ import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeInfo;
import android.permission.IOnPermissionsChangeListener;
import android.permission.IOnPermissionsChangeListener;
import android.permission.IPermissionManager;
import android.permission.IPermissionManager;
import android.permission.PermissionManager;
import android.provider.Settings;
import android.provider.Settings;
import android.system.ErrnoException;
import android.system.ErrnoException;
import android.system.Os;
import android.system.Os;
@@ -191,17 +192,16 @@ public class ApplicationPackageManager extends PackageManager {
    @Override
    @Override
    public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
    public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
            throws NameNotFoundException {
            throws NameNotFoundException {
        try {
        PackageInfo pi =
            PackageInfo pi = mPM.getPackageInfo(packageName,
                getPackageInfoAsUserCached(
                    updateFlagsForPackage(flags, userId), userId);
                        packageName,
            if (pi != null) {
                        updateFlagsForPackage(flags, userId),
                return pi;
                        userId);
            }
        if (pi == null) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
            throw new NameNotFoundException(packageName);
            throw new NameNotFoundException(packageName);
        }
        }
        return pi;
    }


    @Override
    @Override
    public String[] currentToCanonicalPackageNames(String[] names) {
    public String[] currentToCanonicalPackageNames(String[] names) {
@@ -410,21 +410,15 @@ public class ApplicationPackageManager extends PackageManager {
    @Override
    @Override
    public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
    public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
            throws NameNotFoundException {
            throws NameNotFoundException {
        try {
        ApplicationInfo ai = getApplicationInfoAsUserCached(
            ApplicationInfo ai = mPM.getApplicationInfo(packageName,
                        packageName,
                    updateFlagsForApplication(flags, userId), userId);
                        updateFlagsForApplication(flags, userId),
            if (ai != null) {
                        userId);
                // This is a temporary hack. Callers must use
        if (ai == null) {
                // createPackageContext(packageName).getApplicationInfo() to
                // get the right paths.
                return maybeAdjustApplicationInfo(ai);
            }
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }

            throw new NameNotFoundException(packageName);
            throw new NameNotFoundException(packageName);
        }
        }
        return maybeAdjustApplicationInfo(ai);
    }


    private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
    private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
        // If we're dealing with a multi-arch application that has both
        // If we're dealing with a multi-arch application that has both
@@ -680,11 +674,8 @@ public class ApplicationPackageManager extends PackageManager {


    @Override
    @Override
    public int checkPermission(String permName, String pkgName) {
    public int checkPermission(String permName, String pkgName) {
        try {
        return PermissionManager
            return mPermissionManager.checkPermission(permName, pkgName, getUserId());
                .checkPackageNamePermission(permName, pkgName);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    }


    @Override
    @Override
+2 −21
Original line number Original line Diff line number Diff line
@@ -73,6 +73,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.os.storage.StorageManager;
import android.permission.IPermissionManager;
import android.permission.IPermissionManager;
import android.permission.PermissionManager;
import android.system.ErrnoException;
import android.system.ErrnoException;
import android.system.Os;
import android.system.Os;
import android.system.OsConstants;
import android.system.OsConstants;
@@ -1941,27 +1942,7 @@ class ContextImpl extends Context {
        if (permission == null) {
        if (permission == null) {
            throw new IllegalArgumentException("permission is null");
            throw new IllegalArgumentException("permission is null");
        }
        }

        return PermissionManager.checkPermission(permission, pid, uid);
        final IActivityManager am = ActivityManager.getService();
        if (am == null) {
            // Well this is super awkward; we somehow don't have an active
            // ActivityManager instance. If we're testing a root or system
            // UID, then they totally have whatever permission this is.
            final int appId = UserHandle.getAppId(uid);
            if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
                Slog.w(TAG, "Missing ActivityManager; assuming " + uid + " holds " + permission);
                return PERMISSION_GRANTED;
            }
            Slog.w(TAG, "Missing ActivityManager; assuming " + uid + " does not hold "
                    + permission);
            return PackageManager.PERMISSION_DENIED;
        }

        try {
            return am.checkPermission(permission, pid, uid);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    }


    /** @hide */
    /** @hide */
+5 −11
Original line number Original line Diff line number Diff line
@@ -1001,17 +1001,11 @@ public final class LoadedApk {
     */
     */
    private void initializeJavaContextClassLoader() {
    private void initializeJavaContextClassLoader() {
        IPackageManager pm = ActivityThread.getPackageManager();
        IPackageManager pm = ActivityThread.getPackageManager();
        android.content.pm.PackageInfo pi;
        android.content.pm.PackageInfo pi =
        try {
                PackageManager.getPackageInfoAsUserCached(
            pi = pm.getPackageInfo(mPackageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                        mPackageName,
                        PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                        UserHandle.myUserId());
                        UserHandle.myUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        if (pi == null) {
            throw new IllegalStateException("Unable to get package info for "
                    + mPackageName + "; is package not installed?");
        }
        /*
        /*
         * Two possible indications that this package could be
         * Two possible indications that this package could be
         * sharing its virtual machine with other packages:
         * sharing its virtual machine with other packages:
+1 −1
Original line number Original line Diff line number Diff line
@@ -445,7 +445,7 @@ public abstract class PropertyInvalidatedCache<Query, Result> {
        SystemProperties.set(name, newValueString);
        SystemProperties.set(name, newValueString);
    }
    }


    private Result maybeCheckConsistency(Query query, Result proposedResult) {
    protected Result maybeCheckConsistency(Query query, Result proposedResult) {
        if (VERIFY) {
        if (VERIFY) {
            Result resultToCompare = recompute(query);
            Result resultToCompare = recompute(query);
            boolean nonceChanged = (getCurrentNonce() != mLastSeenNonce);
            boolean nonceChanged = (getCurrentNonce() != mLastSeenNonce);
Loading