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

Commit 57c334d6 authored by Tony Mak's avatar Tony Mak
Browse files

Relax the sharedpreference check to look at StorageManager.isUserKeyUnlocked

Bug: 37778488

Test: In a FBE device, turning on and off work profile quickly.
Observe that no more this exception in the log.

Change-Id: I38d72ff5fbb275cf13936abd56f7f4f7b51eea0a
parent 5a421ad0
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.IStorageManager;
import android.os.storage.StorageManager;
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
@@ -376,7 +377,9 @@ class ContextImpl extends Context {
        checkMode(mode);
        if (getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.O) {
            if (isCredentialProtectedStorage()
                    && !getSystemService(UserManager.class).isUserUnlocked() && !isBuggy()) {
                    && !getSystemService(StorageManager.class).isUserKeyUnlocked(
                            UserHandle.myUserId())
                    && !isBuggy()) {
                throw new IllegalStateException("SharedPreferences in credential encrypted "
                        + "storage are not available until after user is unlocked");
            }