Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e366780 authored by Yasin Kilicdere's avatar Yasin Kilicdere Committed by Android (Google) Code Review
Browse files

Merge "When an isolated process calls Context.getSharedPreferences it fails...

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
parents 6ec9ecf7 7bdc3ee7
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -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);