Merge "Assign all flags during initial package scan or update." into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-07-21 13:25:12 +00:00
committed by Android (Google) Code Review
3 changed files with 23 additions and 16 deletions

View File

@@ -427,8 +427,7 @@ final class ScanPackageUtils {
pkgSetting.setLastModifiedTime(scanFileTime); pkgSetting.setLastModifiedTime(scanFileTime);
// TODO(b/135203078): Remove, move to constructor // TODO(b/135203078): Remove, move to constructor
pkgSetting.setPkg(parsedPackage) pkgSetting.setPkg(parsedPackage)
.setFlags(PackageInfoUtils.appInfoFlags(parsedPackage, pkgSetting)) .setPkgFlags(PackageInfoUtils.appInfoFlags(parsedPackage, pkgSetting),
.setPrivateFlags(
PackageInfoUtils.appInfoPrivateFlags(parsedPackage, pkgSetting)); PackageInfoUtils.appInfoPrivateFlags(parsedPackage, pkgSetting));
if (parsedPackage.getLongVersionCode() != pkgSetting.getVersionCode()) { if (parsedPackage.getLongVersionCode() != pkgSetting.getVersionCode()) {
pkgSetting.setLongVersionCode(parsedPackage.getLongVersionCode()); pkgSetting.setLongVersionCode(parsedPackage.getLongVersionCode());

View File

@@ -146,6 +146,17 @@ public abstract class SettingBase implements Watchable, Snappable {
return this; 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() { public int getFlags() {
return mPkgFlags; return mPkgFlags;
} }

View File

@@ -987,8 +987,7 @@ public final class Settings implements Watchable, Snappable {
// Update new package state. // Update new package state.
.setLastModifiedTime(codePath.lastModified()) .setLastModifiedTime(codePath.lastModified())
.setDomainSetId(domainSetId); .setDomainSetId(domainSetId);
pkgSetting.setFlags(pkgFlags) pkgSetting.setPkgFlags(pkgFlags, pkgPrivateFlags);
.setPrivateFlags(pkgPrivateFlags);
} else { } else {
pkgSetting = new PackageSetting(pkgName, realPkgName, codePath, pkgSetting = new PackageSetting(pkgName, realPkgName, codePath,
legacyNativeLibraryPath, primaryCpuAbi, secondaryCpuAbi, legacyNativeLibraryPath, primaryCpuAbi, secondaryCpuAbi,
@@ -1175,15 +1174,15 @@ public final class Settings implements Watchable, Snappable {
.setUsesStaticLibrariesVersions(null); .setUsesStaticLibrariesVersions(null);
} }
// These two flags are preserved from the existing PackageSetting. Copied from prior code, // If what we are scanning is a system (and possibly privileged) package,
// unclear if this is actually necessary. // then make it so, regardless of whether it was previously installed only
boolean wasExternalStorage = (pkgSetting.getFlags() // in the data partition. Reset first.
& ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0; int newPkgFlags = pkgSetting.getFlags();
if (wasExternalStorage) { newPkgFlags &= ~ApplicationInfo.FLAG_SYSTEM;
pkgFlags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; newPkgFlags |= pkgFlags & ApplicationInfo.FLAG_SYSTEM;
} else { // Only set pkgFlags.
pkgFlags &= ~ApplicationInfo.FLAG_EXTERNAL_STORAGE; pkgSetting.setPkgFlags(newPkgFlags, pkgSetting.getPrivateFlags());
}
boolean wasRequiredForSystemUser = (pkgSetting.getPrivateFlags() boolean wasRequiredForSystemUser = (pkgSetting.getPrivateFlags()
& ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER) != 0; & ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER) != 0;
if (wasRequiredForSystemUser) { if (wasRequiredForSystemUser) {
@@ -1191,9 +1190,7 @@ public final class Settings implements Watchable, Snappable {
} else { } else {
pkgPrivateFlags &= ~ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER; pkgPrivateFlags &= ~ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER;
} }
pkgSetting.setPrivateFlags(pkgPrivateFlags);
pkgSetting.setFlags(pkgFlags)
.setPrivateFlags(pkgPrivateFlags);
} }
/** /**