From 76e6f9d221567f5a3b3726e7a67d3551198356f3 Mon Sep 17 00:00:00 2001 From: Winson Date: Thu, 3 Jun 2021 11:54:18 -0700 Subject: [PATCH] Use StorageManager#isUserKeyUnlocked to determine CE storage in PMS Rather than use isUserUnlockingOrUnlocked, which relies on the user state int to be toggled, this moves to isUserKeyUnlocked, which better represents the actual state of being able to create directories on user credential protected storage. The problem with the user state int is that it's only toggled after reconciling app data to fix up missing directories. This means that between reconcilation finishing and the state int being flipped, there is a period of time where an app could be installed, such as a carrier app responding to a SIM event. This causes the install to see that the user is locked and skip creating the /data/user/ directory. But because reconcilation has already finished, this will never get created until the device is rebooted or the package re-installed. This causes the app to crash when initializing. Instead, by checking the storage key directly, which is guaranteed to be flipped when reconcilation occurs, any apps installed that are not reconciled will also create the right directories. Bug: 187103629 Test: manual, try to install carrier apps during reconcilation Change-Id: If086f5126d508739d1079662776f4951ea339f43 --- .../java/com/android/server/pm/PackageManagerService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 2f8ba6da89a30..720f1bebf69f3 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -22265,7 +22265,7 @@ public class PackageManagerService extends IPackageManager.Stub UserManagerInternal umInternal = mInjector.getUserManagerInternal(); final int flags; - if (umInternal.isUserUnlockingOrUnlocked(userId)) { + if (StorageManager.isUserKeyUnlocked(userId)) { flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE; } else if (umInternal.isUserRunning(userId)) { flags = StorageManager.FLAG_STORAGE_DE; @@ -25124,7 +25124,7 @@ public class PackageManagerService extends IPackageManager.Stub UserManagerInternal umInternal = mInjector.getUserManagerInternal(); for (UserInfo user : mUserManager.getUsers(false /* includeDying */)) { final int flags; - if (umInternal.isUserUnlockingOrUnlocked(user.id)) { + if (StorageManager.isUserKeyUnlocked(user.id)) { flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE; } else if (umInternal.isUserRunning(user.id)) { flags = StorageManager.FLAG_STORAGE_DE; @@ -25464,7 +25464,7 @@ public class PackageManagerService extends IPackageManager.Stub StorageManagerInternal smInternal = mInjector.getLocalService(StorageManagerInternal.class); for (UserInfo user : mUserManager.getUsers(false /*excludeDying*/)) { final int flags; - if (umInternal.isUserUnlockingOrUnlocked(user.id)) { + if (StorageManager.isUserKeyUnlocked(user.id)) { flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE; } else if (umInternal.isUserRunning(user.id)) { flags = StorageManager.FLAG_STORAGE_DE; @@ -25478,7 +25478,7 @@ public class PackageManagerService extends IPackageManager.Stub // Note: this code block is executed with the Installer lock // already held, since it's invoked as a side-effect of // executeBatchLI() - if (umInternal.isUserUnlockingOrUnlocked(user.id)) { + if (StorageManager.isUserKeyUnlocked(user.id)) { // Prepare app data on external storage; currently this is used to // setup any OBB dirs that were created by the installer correctly. int uid = UserHandle.getUid(user.id, UserHandle.getAppId(pkg.getUid()));