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

Commit a48bd2e7 authored by Tommy Webb's avatar Tommy Webb Committed by Michael Bestas
Browse files

Fix secondary user crash with system user locked



Resolve an incorrect exception causing a crash to boot animation
when unlocking secondary users, if Backup Manager is enabled for
the user and the system user has yet to be unlocked:
`java.lang.IllegalStateException: SharedPreferences in credential
encrypted storage are not available until after user is unlocked`

Provide the user's context for creating UserBackupPreferences, and
use this context's userId when determining whether credential encrypted
storage is available or not, when calling Context#getSharedPreferences.

Test: Manual: Set a screen lock for system user. Turn on Settings >
Multiple Users and create a secondary user. Run: `adb shell
settings put global allow_user_switching_when_system_user_locked 1`.
Enable Backup Manager for the user, e.g.
`adb shell bmgr --user 10 enable true` (if the user is id 10; see
`adb shell pm list users`). Reboot. Switch to the secondary user
before unlocking system. Device no longer crashes to boot animation.

Issue: calyxos#1352
Co-authored-by: default avatarOliver Scott <olivercscott@gmail.com>
Change-Id: I8354307d10cafe12f556ac13a38122d53399c1d8
parent 48c72f4c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -652,7 +652,7 @@ class ContextImpl extends Context {
                                    + "if UserManager is not available. "
                                    + "(e.g. from inside an isolated process)");
                        }
                        if (!um.isUserUnlockingOrUnlocked(UserHandle.myUserId())) {
                        if (!um.isUserUnlockingOrUnlocked(getUserId())) {
                            throw new IllegalStateException("SharedPreferences in "
                                    + "credential encrypted storage are not available until after "
                                    + "user (id " + UserHandle.myUserId() + ") is unlocked");
+1 −1
Original line number Diff line number Diff line
@@ -605,7 +605,7 @@ public class UserBackupManagerService {
                backupManagerMonitorDumpsysUtils::deleteExpiredBMMEvents,
                INITIALIZATION_DELAY_MILLIS);

        mBackupPreferences = new UserBackupPreferences(mContext, mBaseStateDir);
        mBackupPreferences = new UserBackupPreferences(userContext, mBaseStateDir);

        // Power management
        mWakelock =