diff options
| author | 2024-03-12 11:31:11 +0000 | |
|---|---|---|
| committer | 2024-03-12 11:31:11 +0000 | |
| commit | 1e3667808b6962715d13257ee4112e003c14c46c (patch) | |
| tree | b50b5afef509b80ea0300b9900f7d5fb2322de02 | |
| parent | 6ec9ecf78d24fdc4a86f39f41eb3cf28a2a4ef78 (diff) | |
| parent | 7bdc3ee7043abad2cdc6cbafd9b3471279fe0caf (diff) | |
Merge "When an isolated process calls Context.getSharedPreferences it fails (as expected) because it calls into UserManager which is not allowed for an isolated process." into main
| -rw-r--r-- | core/java/android/app/ContextImpl.java | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index af56cb4d55b2..df566db5ba97 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -597,12 +597,18 @@ class ContextImpl extends Context { if (sp == null) { checkMode(mode); if (getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.O) { - if (isCredentialProtectedStorage() - && !getSystemService(UserManager.class) - .isUserUnlockingOrUnlocked(UserHandle.myUserId())) { - throw new IllegalStateException("SharedPreferences in credential encrypted " - + "storage are not available until after user (id " - + UserHandle.myUserId() + ") is unlocked"); + if (isCredentialProtectedStorage()) { + final UserManager um = getSystemService(UserManager.class); + if (um == null) { + throw new IllegalStateException("SharedPreferences cannot be accessed " + + "if UserManager is not available. " + + "(e.g. from inside an isolated process)"); + } + if (!um.isUserUnlockingOrUnlocked(UserHandle.myUserId())) { + throw new IllegalStateException("SharedPreferences in " + + "credential encrypted storage are not available until after " + + "user (id " + UserHandle.myUserId() + ") is unlocked"); + } } } sp = new SharedPreferencesImpl(file, mode); |