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

Commit 7bdc3ee7 authored by Yasin Kilicdere's avatar Yasin Kilicdere
Browse files

When an isolated process calls Context.getSharedPreferences it fails

(as expected) because it calls into UserManager which is not allowed
for an isolated process.

This CL adds an extra error message for these calls so that the
application knows not to do this.

Bug: 304579365
Test: None
Flag: None
Change-Id: I3a7fa755e3c1315339cd25f33d3c6d7bff0da802
parent 678678fc
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);