Merge "Support private profile in spinner adapters" into main

This commit is contained in:
Manish Singh
2024-03-19 09:54:58 +00:00
committed by Android (Google) Code Review
6 changed files with 197 additions and 32 deletions

View File

@@ -214,7 +214,7 @@ public class StylusDevicesController extends AbstractPreferenceController implem
Intent intent = new Intent(Intent.ACTION_MANAGE_DEFAULT_APP).setPackage(
packageName).putExtra(Intent.EXTRA_ROLE_NAME, RoleManager.ROLE_NOTES);
List<UserHandle> users = getUserAndManagedProfiles();
List<UserHandle> users = getUserProfiles();
if (users.size() <= 1) {
mContext.startActivity(intent);
} else {
@@ -311,22 +311,23 @@ public class StylusDevicesController extends AbstractPreferenceController implem
return inputMethod != null && inputMethod.supportsStylusHandwriting();
}
private List<UserHandle> getUserAndManagedProfiles() {
private List<UserHandle> getUserProfiles() {
UserManager um = mContext.getSystemService(UserManager.class);
final List<UserHandle> userManagedProfiles = new ArrayList<>();
// Add the current user, then add all the associated managed profiles.
final UserHandle currentUser = Process.myUserHandle();
userManagedProfiles.add(currentUser);
final List<UserHandle> userProfiles = new ArrayList<>();
userProfiles.add(currentUser);
final List<UserInfo> userInfos = um.getUsers();
for (UserInfo info : userInfos) {
int userId = info.id;
if (um.isManagedProfile(userId)
&& um.getProfileParent(userId).id == currentUser.getIdentifier()) {
userManagedProfiles.add(UserHandle.of(userId));
final List<UserInfo> userInfos = um.getProfiles(currentUser.getIdentifier());
for (UserInfo userInfo : userInfos) {
if (userInfo.isManagedProfile()
|| (android.os.Flags.allowPrivateProfile()
&& android.multiuser.Flags.enablePrivateSpaceFeatures()
&& android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace()
&& userInfo.isPrivateProfile())) {
userProfiles.add(userInfo.getUserHandle());
}
}
return userManagedProfiles;
return userProfiles;
}
private UserHandle getDefaultNoteTaskProfile() {