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