Merge "Migrate AppDataHelper reconcileAppsData to snapshot" into tm-dev
This commit is contained in:
commit
50d61a67fe
@ -386,6 +386,7 @@ final class AppDataHelper {
|
||||
final File ceDir = Environment.getDataUserCeDirectory(volumeUuid, userId);
|
||||
final File deDir = Environment.getDataUserDeDirectory(volumeUuid, userId);
|
||||
|
||||
final Computer snapshot = mPm.snapshotComputer();
|
||||
// First look for stale data that doesn't belong, and check if things
|
||||
// have changed since we did our last restorecon
|
||||
if ((flags & StorageManager.FLAG_STORAGE_CE) != 0) {
|
||||
@ -400,7 +401,7 @@ final class AppDataHelper {
|
||||
for (File file : files) {
|
||||
final String packageName = file.getName();
|
||||
try {
|
||||
assertPackageStorageValid(volumeUuid, packageName, userId);
|
||||
assertPackageStorageValid(snapshot, volumeUuid, packageName, userId);
|
||||
} catch (PackageManagerException e) {
|
||||
logCriticalInfo(Log.WARN, "Destroying " + file + " due to: " + e);
|
||||
try {
|
||||
@ -417,7 +418,7 @@ final class AppDataHelper {
|
||||
for (File file : files) {
|
||||
final String packageName = file.getName();
|
||||
try {
|
||||
assertPackageStorageValid(volumeUuid, packageName, userId);
|
||||
assertPackageStorageValid(snapshot, volumeUuid, packageName, userId);
|
||||
} catch (PackageManagerException e) {
|
||||
logCriticalInfo(Log.WARN, "Destroying " + file + " due to: " + e);
|
||||
try {
|
||||
@ -434,12 +435,9 @@ final class AppDataHelper {
|
||||
// installed for this volume and user
|
||||
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "prepareAppDataAndMigrate");
|
||||
Installer.Batch batch = new Installer.Batch();
|
||||
final List<PackageSetting> packages;
|
||||
synchronized (mPm.mLock) {
|
||||
packages = mPm.mSettings.getVolumePackagesLPr(volumeUuid);
|
||||
}
|
||||
List<? extends PackageStateInternal> packages = snapshot.getVolumePackages(volumeUuid);
|
||||
int preparedCount = 0;
|
||||
for (PackageSetting ps : packages) {
|
||||
for (PackageStateInternal ps : packages) {
|
||||
final String packageName = ps.getPackageName();
|
||||
if (ps.getPkg() == null) {
|
||||
Slog.w(TAG, "Odd, missing scanned package " + packageName);
|
||||
@ -453,7 +451,7 @@ final class AppDataHelper {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ps.getInstalled(userId)) {
|
||||
if (ps.getUserStateOrDefault(userId).isInstalled()) {
|
||||
prepareAppDataAndMigrate(batch, ps.getPkg(), userId, flags, migrateAppData);
|
||||
preparedCount++;
|
||||
}
|
||||
@ -469,35 +467,25 @@ final class AppDataHelper {
|
||||
* Asserts that storage path is valid by checking that {@code packageName} is present,
|
||||
* installed for the given {@code userId} and can have app data.
|
||||
*/
|
||||
private void assertPackageStorageValid(String volumeUuid, String packageName, int userId)
|
||||
throws PackageManagerException {
|
||||
synchronized (mPm.mLock) {
|
||||
// Normalize package name to handle renamed packages
|
||||
packageName = normalizePackageNameLPr(packageName);
|
||||
|
||||
final PackageSetting ps = mPm.mSettings.getPackageLPr(packageName);
|
||||
if (ps == null) {
|
||||
throw new PackageManagerException("Package " + packageName + " is unknown");
|
||||
} else if (!TextUtils.equals(volumeUuid, ps.getVolumeUuid())) {
|
||||
throw new PackageManagerException(
|
||||
"Package " + packageName + " found on unknown volume " + volumeUuid
|
||||
+ "; expected volume " + ps.getVolumeUuid());
|
||||
} else if (!ps.getInstalled(userId)) {
|
||||
throw new PackageManagerException(
|
||||
"Package " + packageName + " not installed for user " + userId);
|
||||
} else if (ps.getPkg() != null && !shouldHaveAppStorage(ps.getPkg())) {
|
||||
throw new PackageManagerException(
|
||||
"Package " + packageName + " shouldn't have storage");
|
||||
}
|
||||
private void assertPackageStorageValid(@NonNull Computer snapshot, String volumeUuid,
|
||||
String packageName, int userId) throws PackageManagerException {
|
||||
final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
|
||||
if (packageState == null) {
|
||||
throw new PackageManagerException("Package " + packageName + " is unknown");
|
||||
} else if (!TextUtils.equals(volumeUuid, packageState.getVolumeUuid())) {
|
||||
throw new PackageManagerException(
|
||||
"Package " + packageName + " found on unknown volume " + volumeUuid
|
||||
+ "; expected volume " + packageState.getVolumeUuid());
|
||||
} else if (!packageState.getUserStateOrDefault(userId).isInstalled()) {
|
||||
throw new PackageManagerException(
|
||||
"Package " + packageName + " not installed for user " + userId);
|
||||
} else if (packageState.getPkg() != null
|
||||
&& !shouldHaveAppStorage(packageState.getPkg())) {
|
||||
throw new PackageManagerException(
|
||||
"Package " + packageName + " shouldn't have storage");
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("mPm.mLock")
|
||||
private String normalizePackageNameLPr(String packageName) {
|
||||
String normalizedPackageName = mPm.mSettings.getRenamedPackageLPr(packageName);
|
||||
return normalizedPackageName != null ? normalizedPackageName : packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare storage for system user really early during boot,
|
||||
* since core system apps like SettingsProvider and SystemUI
|
||||
|
@ -599,4 +599,7 @@ public interface Computer extends PackageDataSnapshot {
|
||||
void dumpPackagesProto(@NonNull ProtoOutputStream proto);
|
||||
|
||||
void dumpSharedLibrariesProto(@NonNull ProtoOutputStream protoOutputStream);
|
||||
|
||||
@NonNull
|
||||
List<? extends PackageStateInternal> getVolumePackages(@NonNull String volumeUuid);
|
||||
}
|
||||
|
@ -354,6 +354,11 @@ public class ComputerEngine implements Computer {
|
||||
public void dumpSharedUsersProto(ProtoOutputStream proto) {
|
||||
mSettings.dumpSharedUsersProto(proto);
|
||||
}
|
||||
|
||||
public List<? extends PackageStateInternal> getVolumePackages(
|
||||
@NonNull String volumeUuid) {
|
||||
return mSettings.getVolumePackagesLPr(volumeUuid);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Comparator<ProviderInfo> sProviderInitOrderSorter = (p1, p2) -> {
|
||||
@ -5812,4 +5817,10 @@ public class ComputerEngine implements Computer {
|
||||
public void dumpSharedLibrariesProto(@NonNull ProtoOutputStream proto) {
|
||||
mSharedLibraries.dumpProto(proto);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<? extends PackageStateInternal> getVolumePackages(@NonNull String volumeUuid) {
|
||||
return mSettings.getVolumePackages(volumeUuid);
|
||||
}
|
||||
}
|
||||
|
@ -4342,8 +4342,8 @@ public final class Settings implements Watchable, Snappable {
|
||||
* Return all {@link PackageSetting} that are actively installed on the
|
||||
* given {@link VolumeInfo#fsUuid}.
|
||||
*/
|
||||
List<PackageSetting> getVolumePackagesLPr(String volumeUuid) {
|
||||
ArrayList<PackageSetting> res = new ArrayList<>();
|
||||
List<? extends PackageStateInternal> getVolumePackagesLPr(String volumeUuid) {
|
||||
ArrayList<PackageStateInternal> res = new ArrayList<>();
|
||||
for (int i = 0; i < mPackages.size(); i++) {
|
||||
final PackageSetting setting = mPackages.valueAt(i);
|
||||
if (Objects.equals(volumeUuid, setting.getVolumeUuid())) {
|
||||
|
@ -109,8 +109,9 @@ public final class StorageEventHelper extends StorageEventListener {
|
||||
|
||||
// Remove any apps installed on the forgotten volume
|
||||
synchronized (mPm.mLock) {
|
||||
final List<PackageSetting> packages = mPm.mSettings.getVolumePackagesLPr(fsUuid);
|
||||
for (PackageSetting ps : packages) {
|
||||
final List<? extends PackageStateInternal> packages =
|
||||
mPm.mSettings.getVolumePackagesLPr(fsUuid);
|
||||
for (PackageStateInternal ps : packages) {
|
||||
Slog.d(TAG, "Destroying " + ps.getPackageName()
|
||||
+ " because volume was forgotten");
|
||||
mPm.deletePackageVersioned(new VersionedPackage(ps.getPackageName(),
|
||||
@ -145,14 +146,14 @@ public final class StorageEventHelper extends StorageEventListener {
|
||||
final int parseFlags = mPm.getDefParseFlags() | ParsingPackageUtils.PARSE_EXTERNAL_STORAGE;
|
||||
|
||||
final Settings.VersionInfo ver;
|
||||
final List<PackageSetting> packages;
|
||||
final List<? extends PackageStateInternal> packages;
|
||||
final InstallPackageHelper installPackageHelper = new InstallPackageHelper(mPm);
|
||||
synchronized (mPm.mLock) {
|
||||
ver = mPm.mSettings.findOrCreateVersion(volumeUuid);
|
||||
packages = mPm.mSettings.getVolumePackagesLPr(volumeUuid);
|
||||
}
|
||||
|
||||
for (PackageSetting ps : packages) {
|
||||
for (PackageStateInternal ps : packages) {
|
||||
freezers.add(mPm.freezePackage(ps.getPackageName(), "loadPrivatePackagesInner"));
|
||||
synchronized (mPm.mInstallLock) {
|
||||
final AndroidPackage pkg;
|
||||
@ -243,9 +244,9 @@ public final class StorageEventHelper extends StorageEventListener {
|
||||
final ArrayList<AndroidPackage> unloaded = new ArrayList<>();
|
||||
synchronized (mPm.mInstallLock) {
|
||||
synchronized (mPm.mLock) {
|
||||
final List<PackageSetting> packages =
|
||||
final List<? extends PackageStateInternal> packages =
|
||||
mPm.mSettings.getVolumePackagesLPr(volumeUuid);
|
||||
for (PackageSetting ps : packages) {
|
||||
for (PackageStateInternal ps : packages) {
|
||||
if (ps.getPkg() == null) continue;
|
||||
|
||||
final AndroidPackage pkg = ps.getPkg();
|
||||
|
Loading…
x
Reference in New Issue
Block a user