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

Commit dde0b629 authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

Assign all flags during initial package scan or update.

This is a partial revert of ag/16103275.

Bug: 238734637
Fixes: 238734637
Test: atest PackageManagerSettingsTests
Change-Id: Idf50050c5c7603f1127344b502fdd18b4681ebba
parent 7023f28b
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -427,8 +427,7 @@ final class ScanPackageUtils {
        pkgSetting.setLastModifiedTime(scanFileTime);
        // TODO(b/135203078): Remove, move to constructor
        pkgSetting.setPkg(parsedPackage)
                .setFlags(PackageInfoUtils.appInfoFlags(parsedPackage, pkgSetting))
                .setPrivateFlags(
                .setPkgFlags(PackageInfoUtils.appInfoFlags(parsedPackage, pkgSetting),
                        PackageInfoUtils.appInfoPrivateFlags(parsedPackage, pkgSetting));
        if (parsedPackage.getLongVersionCode() != pkgSetting.getVersionCode()) {
            pkgSetting.setLongVersionCode(parsedPackage.getLongVersionCode());
+11 −0
Original line number Diff line number Diff line
@@ -146,6 +146,17 @@ public abstract class SettingBase implements Watchable, Snappable {
        return this;
    }

    /**
     * Unconditionally set both mPkgFlags and mPkgPrivateFlags.
     * Should not be used outside pkgSetting initialization or update.
     */
    SettingBase setPkgFlags(int flags, int privateFlags) {
        this.mPkgFlags = flags;
        this.mPkgPrivateFlags = privateFlags;
        onChanged();
        return this;
    }

    public int getFlags() {
        return mPkgFlags;
    }
+11 −14
Original line number Diff line number Diff line
@@ -987,8 +987,7 @@ public final class Settings implements Watchable, Snappable {
                    // Update new package state.
                    .setLastModifiedTime(codePath.lastModified())
                    .setDomainSetId(domainSetId);
            pkgSetting.setFlags(pkgFlags)
                    .setPrivateFlags(pkgPrivateFlags);
            pkgSetting.setPkgFlags(pkgFlags, pkgPrivateFlags);
        } else {
            pkgSetting = new PackageSetting(pkgName, realPkgName, codePath,
                    legacyNativeLibraryPath, primaryCpuAbi, secondaryCpuAbi,
@@ -1175,15 +1174,15 @@ public final class Settings implements Watchable, Snappable {
                    .setUsesStaticLibrariesVersions(null);
        }

        // These two flags are preserved from the existing PackageSetting. Copied from prior code,
        // unclear if this is actually necessary.
        boolean wasExternalStorage = (pkgSetting.getFlags()
                & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
        if (wasExternalStorage) {
            pkgFlags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
        } else {
            pkgFlags &= ~ApplicationInfo.FLAG_EXTERNAL_STORAGE;
        }
        // If what we are scanning is a system (and possibly privileged) package,
        // then make it so, regardless of whether it was previously installed only
        // in the data partition. Reset first.
        int newPkgFlags = pkgSetting.getFlags();
        newPkgFlags &= ~ApplicationInfo.FLAG_SYSTEM;
        newPkgFlags |= pkgFlags & ApplicationInfo.FLAG_SYSTEM;
        // Only set pkgFlags.
        pkgSetting.setPkgFlags(newPkgFlags, pkgSetting.getPrivateFlags());

        boolean wasRequiredForSystemUser = (pkgSetting.getPrivateFlags()
                & ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER) != 0;
        if (wasRequiredForSystemUser) {
@@ -1191,9 +1190,7 @@ public final class Settings implements Watchable, Snappable {
        } else {
            pkgPrivateFlags &= ~ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER;
        }

        pkgSetting.setFlags(pkgFlags)
                .setPrivateFlags(pkgPrivateFlags);
        pkgSetting.setPrivateFlags(pkgPrivateFlags);
    }

    /**