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

Commit 7c3d904f authored by Winson Chiu's avatar Winson Chiu Committed by Winson
Browse files

Remove AndroidPackage#isSystem

Follow up to previous change I2a915e55f609992729e082815d78fd2d73cb79fd
moving the partition methods from AndroidPackage into PackageState.

This moves the remaining usages of isSystem so that all of the
partition methods have now been migrated.

A few usages of AndroidPackageUtils methods exist for cases where
an AndroidPackageHidden cast is necessary to read the field
directly from the AndroidPackage object. This is usually because of
the install flow, which doesn't guarantee a PackageSetting until
late in the process.

API-Coverage-Bug: 262593427

Test: presubmit

Change-Id: Iff6b800de68fee92e29eb7a0410a5232386f8c19
parent d4c21606
Loading
Loading
Loading
Loading
+11 −8
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.server.pm.PackageManagerServiceUtils.logCriticalInfo;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.pm.UserInfo;
import android.os.CreateAppDataArgs;
import android.os.CreateAppDataArgs;
@@ -47,6 +48,7 @@ import com.android.server.SystemServerInitThreadPool;
import com.android.server.pm.dex.ArtManagerService;
import com.android.server.pm.dex.ArtManagerService;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.PackageState;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.SELinuxUtil;
import com.android.server.pm.pkg.SELinuxUtil;


@@ -179,13 +181,13 @@ public class AppDataHelper {
    }
    }


    private void prepareAppDataAndMigrate(@NonNull Installer.Batch batch,
    private void prepareAppDataAndMigrate(@NonNull Installer.Batch batch,
            @NonNull AndroidPackage pkg, int userId, @StorageManager.StorageFlags int flags,
            @NonNull PackageState packageState, @NonNull AndroidPackage pkg, @UserIdInt int userId,
            boolean maybeMigrateAppData) {
            @StorageManager.StorageFlags int flags, boolean maybeMigrateAppData) {
        prepareAppData(batch, pkg, Process.INVALID_UID, userId, flags).thenRun(() -> {
        prepareAppData(batch, pkg, Process.INVALID_UID, userId, flags).thenRun(() -> {
            // Note: this code block is executed with the Installer lock
            // Note: this code block is executed with the Installer lock
            // already held, since it's invoked as a side-effect of
            // already held, since it's invoked as a side-effect of
            // executeBatchLI()
            // executeBatchLI()
            if (maybeMigrateAppData && maybeMigrateAppDataLIF(pkg, userId)) {
            if (maybeMigrateAppData && maybeMigrateAppDataLIF(packageState, pkg, userId)) {
                // We may have just shuffled around app data directories, so
                // We may have just shuffled around app data directories, so
                // prepare them one more time
                // prepare them one more time
                final Installer.Batch batchInner = new Installer.Batch();
                final Installer.Batch batchInner = new Installer.Batch();
@@ -320,8 +322,9 @@ public class AppDataHelper {
     * CE/DE data to match the {@code defaultToDeviceProtectedStorage} flag
     * CE/DE data to match the {@code defaultToDeviceProtectedStorage} flag
     * requested by the app.
     * requested by the app.
     */
     */
    private boolean maybeMigrateAppDataLIF(AndroidPackage pkg, int userId) {
    private boolean maybeMigrateAppDataLIF(@NonNull PackageState packageState,
        if (pkg.isSystem() && !StorageManager.isFileEncrypted()
            @NonNull AndroidPackage pkg, @UserIdInt int userId) {
        if (packageState.isSystem() && !StorageManager.isFileEncrypted()
                && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) {
                && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) {
            final int storageTarget = pkg.isDefaultToDeviceProtectedStorage()
            final int storageTarget = pkg.isDefaultToDeviceProtectedStorage()
                    ? StorageManager.FLAG_STORAGE_DE : StorageManager.FLAG_STORAGE_CE;
                    ? StorageManager.FLAG_STORAGE_DE : StorageManager.FLAG_STORAGE_CE;
@@ -454,7 +457,7 @@ public class AppDataHelper {
            }
            }


            if (ps.getUserStateOrDefault(userId).isInstalled()) {
            if (ps.getUserStateOrDefault(userId).isInstalled()) {
                prepareAppDataAndMigrate(batch, ps.getPkg(), userId, flags, migrateAppData);
                prepareAppDataAndMigrate(batch, ps, ps.getPkg(), userId, flags, migrateAppData);
                preparedCount++;
                preparedCount++;
            }
            }
        }
        }
@@ -529,8 +532,8 @@ public class AppDataHelper {
                        && packageStateInternal.getUserStateOrDefault(
                        && packageStateInternal.getUserStateOrDefault(
                                UserHandle.USER_SYSTEM).isInstalled()) {
                                UserHandle.USER_SYSTEM).isInstalled()) {
                    AndroidPackage pkg = packageStateInternal.getPkg();
                    AndroidPackage pkg = packageStateInternal.getPkg();
                    prepareAppDataAndMigrate(batch, pkg, UserHandle.USER_SYSTEM, storageFlags,
                    prepareAppDataAndMigrate(batch, packageStateInternal, pkg,
                            true /* maybeMigrateAppData */);
                            UserHandle.USER_SYSTEM, storageFlags, true /* maybeMigrateAppData */);
                    count++;
                    count++;
                }
                }
            }
            }
+1 −1
Original line number Original line Diff line number Diff line
@@ -593,7 +593,7 @@ public interface Computer extends PackageDataSnapshot {
    CharSequence getHarmfulAppWarning(@NonNull String packageName, @UserIdInt int userId);
    CharSequence getHarmfulAppWarning(@NonNull String packageName, @UserIdInt int userId);


    /**
    /**
     * Only keep package names that refer to {@link AndroidPackage#isSystem system} packages.
     * Only keep package names that refer to {@link PackageState#isSystem system} packages.
     *
     *
     * @param pkgNames The packages to filter
     * @param pkgNames The packages to filter
     *
     *
+14 −10
Original line number Original line Diff line number Diff line
@@ -130,6 +130,7 @@ import com.android.server.pm.parsing.PackageInfoUtils;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.permission.PermissionManagerServiceInternal;
import com.android.server.pm.permission.PermissionManagerServiceInternal;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.PackageState;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.PackageStateUtils;
import com.android.server.pm.pkg.PackageStateUtils;
import com.android.server.pm.pkg.PackageUserStateInternal;
import com.android.server.pm.pkg.PackageUserStateInternal;
@@ -223,7 +224,7 @@ public class ComputerEngine implements Computer {
            }
            }


            return PackageUserStateUtils.isMatch(pkgState.getUserStateOrDefault(userId),
            return PackageUserStateUtils.isMatch(pkgState.getUserStateOrDefault(userId),
                    pkg.isSystem(), pkg.isEnabled(), component, flags);
                    pkgState.isSystem(), pkg.isEnabled(), component, flags);
        }
        }


        @Nullable
        @Nullable
@@ -1571,7 +1572,8 @@ public class ComputerEngine implements Computer {
        }
        }


        AndroidPackage p = mPackages.get(packageName);
        AndroidPackage p = mPackages.get(packageName);
        if (matchFactoryOnly && p != null && !p.isSystem()) {
        var packageState = mSettings.getPackage(packageName);
        if (matchFactoryOnly && p != null && !packageState.isSystem()) {
            return null;
            return null;
        }
        }
        if (DEBUG_PACKAGE_INFO) {
        if (DEBUG_PACKAGE_INFO) {
@@ -1689,7 +1691,7 @@ public class ComputerEngine implements Computer {
            for (AndroidPackage p : mPackages.values()) {
            for (AndroidPackage p : mPackages.values()) {
                PackageStateInternal ps = getPackageStateInternal(p.getPackageName());
                PackageStateInternal ps = getPackageStateInternal(p.getPackageName());
                if (listFactory) {
                if (listFactory) {
                    if (!p.isSystem()) {
                    if (!ps.isSystem()) {
                        continue;
                        continue;
                    }
                    }
                    PackageStateInternal psDisabled =
                    PackageStateInternal psDisabled =
@@ -2566,8 +2568,9 @@ public class ComputerEngine implements Computer {
    public int getPackageUidInternal(String packageName,
    public int getPackageUidInternal(String packageName,
            @PackageManager.PackageInfoFlagsBits long flags, int userId, int callingUid) {
            @PackageManager.PackageInfoFlagsBits long flags, int userId, int callingUid) {
        // reader
        // reader
        var packageState = mSettings.getPackage(packageName);
        final AndroidPackage p = mPackages.get(packageName);
        final AndroidPackage p = mPackages.get(packageName);
        if (p != null && AndroidPackageUtils.isMatchForSystemOnly(p, flags)) {
        if (p != null && AndroidPackageUtils.isMatchForSystemOnly(packageState, flags)) {
            final PackageStateInternal ps = getPackageStateInternal(p.getPackageName(), callingUid);
            final PackageStateInternal ps = getPackageStateInternal(p.getPackageName(), callingUid);
            if (ps != null && ps.getUserStateOrDefault(userId).isInstalled()
            if (ps != null && ps.getUserStateOrDefault(userId).isInstalled()
                    && !shouldFilterApplication(ps, callingUid, userId)) {
                    && !shouldFilterApplication(ps, callingUid, userId)) {
@@ -3616,7 +3619,7 @@ public class ComputerEngine implements Computer {
            return null;
            return null;
        }
        }
        if (ps.getPkg() != null
        if (ps.getPkg() != null
                && AndroidPackageUtils.isMatchForSystemOnly(ps.getPkg(), flags)) {
                && AndroidPackageUtils.isMatchForSystemOnly(ps, flags)) {
            if (ps.getUserStateOrDefault(userId).isInstalled()
            if (ps.getUserStateOrDefault(userId).isInstalled()
                    && !shouldFilterApplication(ps, callingUid, userId)) {
                    && !shouldFilterApplication(ps, callingUid, userId)) {
                return mPermissionManager.getGidsForUid(UserHandle.getUid(userId,
                return mPermissionManager.getGidsForUid(UserHandle.getUid(userId,
@@ -5416,6 +5419,7 @@ public class ComputerEngine implements Computer {
        final int userId = UserHandle.getCallingUserId();
        final int userId = UserHandle.getCallingUserId();
        for (int index = 0; index < numPackages; index++) {
        for (int index = 0; index < numPackages; index++) {
            final AndroidPackage p = mPackages.valueAt(index);
            final AndroidPackage p = mPackages.valueAt(index);
            var packageState = mSettings.getPackage(p.getPackageName());


            final boolean matchesUnaware = ((flags & MATCH_DIRECT_BOOT_UNAWARE) != 0)
            final boolean matchesUnaware = ((flags & MATCH_DIRECT_BOOT_UNAWARE) != 0)
                    && !p.isDirectBootAware();
                    && !p.isDirectBootAware();
@@ -5423,7 +5427,7 @@ public class ComputerEngine implements Computer {
                    && p.isDirectBootAware();
                    && p.isDirectBootAware();


            if (p.isPersistent()
            if (p.isPersistent()
                    && (!safeMode || p.isSystem())
                    && (!safeMode || packageState.isSystem())
                    && (matchesUnaware || matchesAware)) {
                    && (matchesUnaware || matchesAware)) {
                PackageStateInternal ps = mSettings.getPackage(p.getPackageName());
                PackageStateInternal ps = mSettings.getPackage(p.getPackageName());
                if (ps != null) {
                if (ps != null) {
@@ -5522,7 +5526,7 @@ public class ComputerEngine implements Computer {
    }
    }


    /**
    /**
     * Only keep package names that refer to {@link AndroidPackage#isSystem system} packages.
     * Only keep package names that refer to {@link PackageState#isSystem system} packages.
     *
     *
     * @param pkgNames The packages to filter
     * @param pkgNames The packages to filter
     *
     *
@@ -5542,13 +5546,13 @@ public class ComputerEngine implements Computer {
                continue;
                continue;
            }
            }


            AndroidPackage pkg = getPackage(pkgName);
            var packageState = getPackageStateInternal(pkgName);
            if (pkg == null) {
            if (packageState == null || packageState.getAndroidPackage() == null) {
                Log.w(TAG, "Could not find package " + pkgName);
                Log.w(TAG, "Could not find package " + pkgName);
                continue;
                continue;
            }
            }


            if (!pkg.isSystem()) {
            if (!packageState.isSystem()) {
                Log.w(TAG, pkgName + " is not system");
                Log.w(TAG, pkgName + " is not system");
                continue;
                continue;
            }
            }
+1 −1
Original line number Original line Diff line number Diff line
@@ -536,7 +536,7 @@ final class DeletePackageHelper {
                    nextUserId);
                    nextUserId);
            mPm.mDomainVerificationManager.clearPackageForUser(ps.getPackageName(), nextUserId);
            mPm.mDomainVerificationManager.clearPackageForUser(ps.getPackageName(), nextUserId);
        }
        }
        mPermissionManager.onPackageUninstalled(ps.getPackageName(), ps.getAppId(), pkg,
        mPermissionManager.onPackageUninstalled(ps.getPackageName(), ps.getAppId(), ps, pkg,
                sharedUserPkgs, userId);
                sharedUserPkgs, userId);


        if (outInfo != null) {
        if (outInfo != null) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -139,7 +139,7 @@ public final class DexOptHelper {


            boolean useProfileForDexopt = false;
            boolean useProfileForDexopt = false;


            if ((mPm.isFirstBoot() || mPm.isDeviceUpgrading()) && pkg.isSystem()) {
            if ((mPm.isFirstBoot() || mPm.isDeviceUpgrading()) && packageState.isSystem()) {
                // Copy over initial preopt profiles since we won't get any JIT samples for methods
                // Copy over initial preopt profiles since we won't get any JIT samples for methods
                // that are already compiled.
                // that are already compiled.
                File profileFile = new File(getPrebuildProfilePath(pkg));
                File profileFile = new File(getPrebuildProfilePath(pkg));
Loading