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
This commit is contained in:
Alex Buynytskyy
2022-07-18 11:56:39 -07:00
parent 7023f28bd0
commit dde0b6292e
3 changed files with 23 additions and 16 deletions

View File

@@ -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());

View File

@@ -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;
}

View File

@@ -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);
}
/**