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

Commit 02cee29c authored by Patrick Baumann's avatar Patrick Baumann
Browse files

Marks Settings.mPackages as VisibleForTesting

mPackages was accessed directly throughout the pm package. This change
removes those from non-test code and marks the field @VisibleForTesting
to account for the tests still accessing it directly.

Bug: 169360984
Test: atest PackageManagerServiceBootTest
Change-Id: I85be9daabd01f49f86b2cc0d5f9e2bc3d090f52b
parent f010d5de
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -347,7 +347,7 @@ public class AppsFilter {
        }
        final StateProvider stateProvider = command -> {
            synchronized (injector.getLock()) {
                command.currentState(injector.getSettings().mPackages,
                command.currentState(injector.getSettings().getPackagesLocked(),
                        injector.getUserManagerInternal().getUserInfos());
            }
        };
+3 −3
Original line number Diff line number Diff line
@@ -128,12 +128,12 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
        synchronized (mPackageManagerService.mLock) {
            // Important: the packages we need to run with ab-ota compiler-reason.
            important = PackageManagerServiceUtils.getPackagesForDexopt(
                    mPackageManagerService.mSettings.mPackages.values(), mPackageManagerService,
                    DEBUG_DEXOPT);
                    mPackageManagerService.mSettings.getPackagesLocked().values(),
                    mPackageManagerService, DEBUG_DEXOPT);
            // Remove Platform Package from A/B OTA b/160735835.
            important.removeIf(isPlatformPackage);
            // Others: we should optimize this with the (first-)boot compiler-reason.
            others = new ArrayList<>(mPackageManagerService.mSettings.mPackages.values());
            others = new ArrayList<>(mPackageManagerService.mSettings.getPackagesLocked().values());
            others.removeAll(important);
            others.removeIf(PackageManagerServiceUtils.REMOVE_IF_NULL_PKG);
            others.removeIf(isPlatformPackage);
+11 −11
Original line number Diff line number Diff line
@@ -17692,12 +17692,12 @@ public class PackageManagerService extends IPackageManager.Stub
            final SparseArray<int[]> newBroadcastAllowList;
            final String codePath;
            synchronized (mLock) {
                final PackageSetting ps = mSettings.mPackages.get(mPackageName);
                final PackageSetting ps = mSettings.getPackageLPr(mPackageName);
                if (ps == null) {
                    return;
                }
                newBroadcastAllowList = mAppsFilter.getVisibilityAllowList(
                        ps, mInstalledUserIds, mSettings.mPackages);
                        ps, mInstalledUserIds, mSettings.getPackagesLocked());
                codePath = ps.getPathString();
            }
            Bundle extras = new Bundle();
@@ -17715,12 +17715,12 @@ public class PackageManagerService extends IPackageManager.Stub
        public void onPackageUnstartable(int reason) {
            final SparseArray<int[]> newBroadcastAllowList;
            synchronized (mLock) {
                final PackageSetting ps = mSettings.mPackages.get(mPackageName);
                final PackageSetting ps = mSettings.getPackageLPr(mPackageName);
                if (ps == null) {
                    return;
                }
                newBroadcastAllowList = mAppsFilter.getVisibilityAllowList(
                        ps, mInstalledUserIds, mSettings.mPackages);
                        ps, mInstalledUserIds, mSettings.getPackagesLocked());
            }
            Bundle extras = new Bundle();
            extras.putInt(Intent.EXTRA_UID, mUid);
@@ -17737,12 +17737,12 @@ public class PackageManagerService extends IPackageManager.Stub
        public void onPackageStartable() {
            final SparseArray<int[]> newBroadcastAllowList;
            synchronized (mLock) {
                final PackageSetting ps = mSettings.mPackages.get(mPackageName);
                final PackageSetting ps = mSettings.getPackageLPr(mPackageName);
                if (ps == null) {
                    return;
                }
                newBroadcastAllowList = mAppsFilter.getVisibilityAllowList(
                        ps, mInstalledUserIds, mSettings.mPackages);
                        ps, mInstalledUserIds, mSettings.getPackagesLocked());
            }
            Bundle extras = new Bundle();
            extras.putInt(Intent.EXTRA_UID, mUid);
@@ -17768,7 +17768,7 @@ public class PackageManagerService extends IPackageManager.Stub
        public void onPackageLoadingProgressChanged(float progress) {
            final PackageSetting ps;
            synchronized (mLock) {
                ps = mSettings.mPackages.get(mPackageName);
                ps = mSettings.getPackageLPr(mPackageName);
            }
            if (ps == null) {
                return;
@@ -17791,7 +17791,7 @@ public class PackageManagerService extends IPackageManager.Stub
        public void onHealthStatus(int storageId, int status) throws RemoteException {
            final PackageSetting ps;
            synchronized (mLock) {
                ps = mSettings.mPackages.get(mPackageName);
                ps = mSettings.getPackageLPr(mPackageName);
            }
            if (ps == null) {
                return;
@@ -17804,7 +17804,7 @@ public class PackageManagerService extends IPackageManager.Stub
            int userId) {
        final PackageSetting ps;
        synchronized (mLock) {
            ps = mSettings.mPackages.get(packageName);
            ps = mSettings.getPackageLPr(packageName);
            if (ps == null) {
                Slog.w(TAG, "Failed to get package setting. Package " + packageName
                        + " is not installed");
@@ -24612,7 +24612,7 @@ public class PackageManagerService extends IPackageManager.Stub
            // which was uninstalled while keeping its data.
            AndroidPackage dataOwnerPkg = mPackages.get(packageName);
            if (dataOwnerPkg  == null) {
                PackageSetting ps = mSettings.mPackages.get(packageName);
                PackageSetting ps = mSettings.getPackageLPr(packageName);
                if (ps != null) {
                    dataOwnerPkg = ps.pkg;
                }
@@ -26059,7 +26059,7 @@ public class PackageManagerService extends IPackageManager.Stub
        public void notifyPackageCrashOrAnr(@NonNull String packageName) {
            final PackageSetting ps;
            synchronized (mLock) {
                ps = mSettings.mPackages.get(packageName);
                ps = mSettings.getPackageLPr(packageName);
                if (ps == null) {
                    Slog.w(TAG, "Failed notifyPackageCrash. Package " + packageName
                            + " is not installed");
+1 −0
Original line number Diff line number Diff line
@@ -295,6 +295,7 @@ public final class Settings {
    private final File mKernelMappingFilename;

    /** Map from package name to settings */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    final ArrayMap<String, PackageSetting> mPackages = new ArrayMap<>();

    /**