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

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

Merge "[pm] small refactor to hide PackageManagerService.getPackageSetting"

parents a00147cf 77719392
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -845,7 +845,7 @@ public abstract class PackageManagerInternal implements PackageSettingsSnapshotP

    /**
     * Perform the given action for each installed package for a user.
     * Note that packages lock will be held while performin the actions.
     * Note that packages lock will be held while performing the actions.
     */
    public abstract void forEachInstalledPackage(
            @NonNull Consumer<AndroidPackage> actionLocked, @UserIdInt int userId);
+12 −7
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.InstantAppInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PermissionInfo;
import android.content.pm.SigningDetails;
import android.graphics.Bitmap;
@@ -123,6 +124,7 @@ class InstantAppRegistry implements Watchable, Snappable {
    private final PackageManagerService mService;
    private final PermissionManagerServiceInternal mPermissionManager;
    private final CookiePersistence mCookiePersistence;
    private final PackageManagerInternal mPmInternal;

    /** State for uninstalled instant apps */
    @Watched
@@ -191,9 +193,11 @@ class InstantAppRegistry implements Watchable, Snappable {
    }

    public InstantAppRegistry(PackageManagerService service,
            PermissionManagerServiceInternal permissionManager) {
            PermissionManagerServiceInternal permissionManager,
            PackageManagerInternal pmInternal) {
        mService = service;
        mPermissionManager = permissionManager;
        mPmInternal = pmInternal;
        mCookiePersistence = new CookiePersistence(BackgroundThread.getHandler().getLooper());

        mUninstalledInstantApps = new WatchedSparseArray<List<UninstalledInstantAppState>>();
@@ -214,6 +218,7 @@ class InstantAppRegistry implements Watchable, Snappable {
    private InstantAppRegistry(InstantAppRegistry r) {
        mService = r.mService;
        mPermissionManager = r.mPermissionManager;
        mPmInternal = r.mPmInternal;
        mCookiePersistence = null;

        mUninstalledInstantApps = new WatchedSparseArray<List<UninstalledInstantAppState>>(
@@ -366,7 +371,7 @@ class InstantAppRegistry implements Watchable, Snappable {

    @GuardedBy("mService.mLock")
    public void onPackageInstalledLPw(@NonNull AndroidPackage pkg, @NonNull int[] userIds) {
        PackageSetting ps = mService.getPackageSetting(pkg.getPackageName());
        PackageSetting ps = mPmInternal.getPackageSetting(pkg.getPackageName());
        if (ps == null) {
            return;
        }
@@ -784,7 +789,7 @@ class InstantAppRegistry implements Watchable, Snappable {
            final int packageCount = mService.mPackages.size();
            for (int i = 0; i < packageCount; i++) {
                final AndroidPackage pkg = mService.mPackages.valueAt(i);
                final PackageSetting ps = mService.getPackageSetting(pkg.getPackageName());
                final PackageSetting ps = mPmInternal.getPackageSetting(pkg.getPackageName());
                if (ps == null) {
                    continue;
                }
@@ -824,13 +829,13 @@ class InstantAppRegistry implements Watchable, Snappable {
                    } else if (rhsPkg == null) {
                        return 1;
                    } else {
                        final PackageSetting lhsPs = mService.getPackageSetting(
                        final PackageSetting lhsPs = mPmInternal.getPackageSetting(
                                lhsPkg.getPackageName());
                        if (lhsPs == null) {
                            return 0;
                        }

                        final PackageSetting rhsPs = mService.getPackageSetting(
                        final PackageSetting rhsPs = mPmInternal.getPackageSetting(
                                rhsPkg.getPackageName());
                        if (rhsPs == null) {
                            return 0;
@@ -918,7 +923,7 @@ class InstantAppRegistry implements Watchable, Snappable {
        final int packageCount = mService.mPackages.size();
        for (int i = 0; i < packageCount; i++) {
            final AndroidPackage pkg = mService.mPackages.valueAt(i);
            final PackageSetting ps = mService.getPackageSetting(pkg.getPackageName());
            final PackageSetting ps = mPmInternal.getPackageSetting(pkg.getPackageName());
            if (ps == null || !ps.getInstantApp(userId)) {
                continue;
            }
@@ -940,7 +945,7 @@ class InstantAppRegistry implements Watchable, Snappable {
    InstantAppInfo createInstantAppInfoForPackage(
            @NonNull AndroidPackage pkg, @UserIdInt int userId,
            boolean addApplicationInfo) {
        PackageSetting ps = mService.getPackageSetting(pkg.getPackageName());
        PackageSetting ps = mPmInternal.getPackageSetting(pkg.getPackageName());
        if (ps == null) {
            return null;
        }
+7 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.IOtaDexopt;
import android.content.pm.PackageManagerInternal;
import android.os.Environment;
import android.os.RemoteException;
import android.os.ResultReceiver;
@@ -33,6 +34,7 @@ import android.util.Log;
import android.util.Slog;

import com.android.internal.logging.MetricsLogger;
import com.android.server.LocalServices;
import com.android.server.pm.Installer.InstallerException;
import com.android.server.pm.dex.DexoptOptions;
import com.android.server.pm.parsing.pkg.AndroidPackage;
@@ -41,7 +43,6 @@ import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import java.io.File;
import java.io.FileDescriptor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -371,8 +372,10 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
            return;
        }

        // Look into all packages.
        Collection<AndroidPackage> pkgs = mPackageManagerService.getPackages();
        // Make a copy of all packages and look into each package.
        final PackageManagerInternal pmInt = LocalServices.getService(PackageManagerInternal.class);
        final ArrayList<AndroidPackage> pkgs = new ArrayList<>();
        pmInt.forEachPackage(pkgs::add);
        int packagePaths = 0;
        int pathsSuccessful = 0;
        for (AndroidPackage pkg : pkgs) {
@@ -398,7 +401,7 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
                continue;
            }

            PackageSetting pkgSetting = mPackageManagerService.getPackageSetting(pkg.getPackageName());
            PackageSetting pkgSetting = pmInt.getPackageSetting(pkg.getPackageName());
            final String[] instructionSets = getAppDexInstructionSets(
                    AndroidPackageUtils.getPrimaryCpuAbi(pkg, pkgSetting),
                    AndroidPackageUtils.getSecondaryCpuAbi(pkg, pkgSetting));
+2 −2
Original line number Diff line number Diff line
@@ -2212,7 +2212,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    @Override
    public void transfer(String packageName) {
        Preconditions.checkArgument(!TextUtils.isEmpty(packageName));

        ApplicationInfo newOwnerAppInfo = mPm.getApplicationInfo(packageName, 0, userId);
        if (newOwnerAppInfo == null) {
            throw new ParcelableException(new PackageManager.NameNotFoundException(packageName));
@@ -2779,7 +2778,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    }

    private long getApksSize(String packageName) {
        final PackageSetting ps = mPm.getPackageSetting(packageName);
        final PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
        final PackageSetting ps = pmi.getPackageSetting(packageName);
        if (ps == null) {
            return 0;
        }
+3 −12
Original line number Diff line number Diff line
@@ -7184,7 +7184,7 @@ public class PackageManagerService extends IPackageManager.Stub
            }
        }
        mInstantAppRegistry = new InstantAppRegistry(this, mPermissionManager);
        mInstantAppRegistry = new InstantAppRegistry(this, mPermissionManager, mPmInternal);
        mDirsToScanAsSystem = new ArrayList<>();
        mDirsToScanAsSystem.addAll(injector.getSystemPartitions());
@@ -28439,7 +28439,8 @@ public class PackageManagerService extends IPackageManager.Stub
    }
    @Nullable
    public PackageSetting getPackageSetting(String packageName) {
    @VisibleForTesting(visibility = Visibility.PRIVATE)
    PackageSetting getPackageSetting(String packageName) {
        return mComputer.getPackageSetting(packageName);
    }
@@ -28477,16 +28478,6 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    /**
     * Return a <b>copy</b> of the collection of packages known to the package manager.
     * @return A copy of the values of mPackages.
     */
    Collection<AndroidPackage> getPackages() {
        synchronized (mLock) {
            return new ArrayList<>(mPackages.values());
        }
    }
    /**
     * Logs process start information (including base APK hash) to the security log.
     * @hide