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

Commit 237a06e0 authored by Wilson Wu's avatar Wilson Wu
Browse files

Fix keyboard settings crash in multi-user case

We have CL[1] to fix the NPE when keyboard settings
is launched by work app. CL[1] overlooked the work
profile with multi-user case.

Work profile user ID is not available(return null)
when calling Utils#getManagedProfile by work identity.

For work case, distinguish it's running on managed
profile user(launched by work app) or not. And use
corresponding userId as:

-. If it's a managed profile user, use currentUserId.
-. For a owner user, get managed profile userId.

[1]: Iea573922ee789d9932c0de05bf71179c4f005eeb

Bug: 216395439
Test: Manual test with bugs steps
Test: make RunSettingsRoboTests ROBOTEST_FILTER=AvailableVirtualKeyboardFragmentTest
Change-Id: If018d2fddbbcf932927d2235bb8e99393df1e67c
parent 4440e7a0
Loading
Loading
Loading
Loading
+5 −9
Original line number Diff line number Diff line
@@ -74,15 +74,11 @@ public class AvailableVirtualKeyboardFragment extends DashboardFragment
        final Context newUserAwareContext;
        switch (profileType) {
            case ProfileSelectFragment.ProfileType.WORK: {
                final UserHandle workUser;
                if (currentUserId == UserHandle.MIN_SECONDARY_USER_ID) {
                    newUserId = currentUserId;
                    workUser = UserHandle.of(currentUserId);
                } else {
                    newUserId = Utils.getManagedProfileId(userManager, currentUserId);
                    workUser = Utils.getManagedProfile(userManager);
                }
                newUserAwareContext = context.createContextAsUser(workUser, 0);
                // If the user is a managed profile user, use currentUserId directly. Or get the
                // managed profile userId instead.
                newUserId = userManager.isManagedProfile()
                        ? currentUserId : Utils.getManagedProfileId(userManager, currentUserId);
                newUserAwareContext = context.createContextAsUser(UserHandle.of(newUserId), 0);
                break;
            }
            case ProfileSelectFragment.ProfileType.PERSONAL: {