Support private profile in spinner adapters

Screenshot - https://screenshot.googleplex.com/35czwQHeevX75pj
Video - https://drive.google.com/file/d/1LkYPJ3i8llArnQBE3ieLPYMctEOw3xdp/view?usp=sharing&resourcekey=0-j-3-VV4OyXJKBPXwAqJvKg

Bug: 328565911
Bug: 313610609
Bug: 302082696
Test: manual
Test: atest UserAdapterTest
Test: atest StylusDevicesControllerTest
Change-Id: If8395eba5cc73809ab4abc95bc13067451c38b8f
This commit is contained in:
Manish Singh
2024-03-08 17:04:23 +00:00
parent 7dee0538d6
commit d7ff6fe966
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() {