Fix wrong user in personal profile

If the user is profile, it should use the current
user's profile parent to create the context instead
of always using the primary user(system user).

Bug: 264867495
Test: Manual test with work profile enabled, multi user flow, etc
Test: make RunSettingsRoboTests ROBOTEST_FILTER=AvailableVirtualKeyboardFragmentTest
Change-Id: I66d1462441359c40dda2a38c7534500791db9c83
This commit is contained in:
Wilson Wu
2023-03-28 20:51:46 +08:00
parent 6dfcad2cb2
commit a7620427b5
2 changed files with 41 additions and 8 deletions

View File

@@ -55,7 +55,10 @@ public class AvailableVirtualKeyboardFragment extends DashboardFragment
@VisibleForTesting
InputMethodSettingValuesWrapper mInputMethodSettingValues;
private Context mUserAwareContext;
@VisibleForTesting
Context mUserAwareContext;
private int mUserId;
@Override
@@ -82,9 +85,16 @@ public class AvailableVirtualKeyboardFragment extends DashboardFragment
break;
}
case ProfileSelectFragment.ProfileType.PERSONAL: {
final UserHandle primaryUser = userManager.getPrimaryUser().getUserHandle();
newUserId = primaryUser.getIdentifier();
newUserAwareContext = context.createContextAsUser(primaryUser, 0);
// Use the parent user of the current user if the current user is profile.
final UserHandle currentUser = UserHandle.of(currentUserId);
final UserHandle userProfileParent = userManager.getProfileParent(currentUser);
if (userProfileParent != null) {
newUserId = userProfileParent.getIdentifier();
newUserAwareContext = context.createContextAsUser(userProfileParent, 0);
} else {
newUserId = currentUserId;
newUserAwareContext = context;
}
break;
}
default: