From f0143cc1c6f9d81e70246f7254f52f23d65ac72c Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 2 May 2016 15:58:44 -0600 Subject: [PATCH] Apply non-FBE migration early during boot. On non-FBE devices, we offer to migrate CE/DE storage of certain system apps during boot. However, if this migration happens after app code has started to run, we end up clobbering open files such as databases. The right way to solve this is to apply all migration early during boot (in the PMS constructor) before any app code can start. Bug: 28512897, 28525109 Change-Id: I17eb9a09e5862d873b86c05ce35874a34386e433 --- .../com/android/server/pm/PackageManagerService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 61e36d9641883..568d425ee7a09 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -2678,8 +2678,14 @@ public class PackageManagerService extends IPackageManager.Stub { // Prepare storage for system user really early during boot, // since core system apps like SettingsProvider and SystemUI // can't wait for user to start + final int storageFlags; + if (StorageManager.isFileEncryptedNativeOrEmulated()) { + storageFlags = StorageManager.FLAG_STORAGE_DE; + } else { + storageFlags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE; + } reconcileAppsDataLI(StorageManager.UUID_PRIVATE_INTERNAL, UserHandle.USER_SYSTEM, - StorageManager.FLAG_STORAGE_DE); + storageFlags); // If this is first boot after an OTA, and a normal boot, then // we need to clear code cache directories. @@ -19124,7 +19130,8 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName()); // 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) { - if (!StorageManager.isUserKeyUnlocked(userId)) { + if (StorageManager.isFileEncryptedNativeOrEmulated() + && !StorageManager.isUserKeyUnlocked(userId)) { throw new RuntimeException( "Yikes, someone asked us to reconcile CE storage while " + userId + " was still locked; this would have caused massive data loss!");