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:
@@ -1364,6 +1364,16 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the user should be hidden in Settings when it's in quiet mode.
|
||||
*/
|
||||
public static boolean shouldHideUser(
|
||||
@NonNull UserHandle userHandle, @NonNull UserManager userManager) {
|
||||
UserProperties userProperties = userManager.getUserProperties(userHandle);
|
||||
return userProperties.getShowInQuietMode() == UserProperties.SHOW_IN_QUIET_MODE_HIDDEN
|
||||
&& userManager.isQuietModeEnabled(userHandle);
|
||||
}
|
||||
|
||||
private static FaceManager.RemovalCallback faceManagerRemovalCallback(int userId) {
|
||||
return new FaceManager.RemovalCallback() {
|
||||
@Override
|
||||
|
@@ -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() {
|
||||
|
@@ -25,7 +25,6 @@ import android.content.DialogInterface.OnDismissListener;
|
||||
import android.content.DialogInterface.OnShowListener;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.pm.UserProperties;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -42,6 +41,7 @@ import com.android.internal.widget.DialogTitle;
|
||||
import com.android.internal.widget.LinearLayoutManager;
|
||||
import com.android.internal.widget.RecyclerView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
@@ -186,7 +186,7 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O
|
||||
UserInfo userInfo = userManager.getUserInfo(userHandles.get(i).getIdentifier());
|
||||
if (userInfo == null
|
||||
|| userInfo.isCloneProfile()
|
||||
|| shouldHideUserInQuietMode(userHandles.get(i), userManager)) {
|
||||
|| Utils.shouldHideUser(userHandles.get(i), userManager)) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Delete the user: " + userHandles.get(i).getIdentifier());
|
||||
}
|
||||
@@ -219,7 +219,7 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O
|
||||
UserInfo userInfo = userManager.getUserInfo(userHandle.getIdentifier());
|
||||
if (userInfo == null
|
||||
|| userInfo.isCloneProfile()
|
||||
|| shouldHideUserInQuietMode(userHandle, userManager)) {
|
||||
|| Utils.shouldHideUser(userHandle, userManager)) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Delete the user: " + userHandle.getIdentifier());
|
||||
}
|
||||
@@ -228,11 +228,4 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldHideUserInQuietMode(
|
||||
UserHandle userHandle, UserManager userManager) {
|
||||
UserProperties userProperties = userManager.getUserProperties(userHandle);
|
||||
return userProperties.getShowInQuietMode() == UserProperties.SHOW_IN_QUIET_MODE_HIDDEN
|
||||
&& userManager.isQuietModeEnabled(userHandle);
|
||||
}
|
||||
}
|
||||
|
@@ -64,7 +64,11 @@ public class UserAdapter extends BaseAdapter {
|
||||
UserInfo userInfo = um.getUserInfo(mUserHandle.getIdentifier());
|
||||
int tintColor = Utils.getColorAttrDefaultColor(context,
|
||||
com.android.internal.R.attr.materialColorPrimary);
|
||||
if (userInfo.isManagedProfile()) {
|
||||
if (userInfo.isManagedProfile()
|
||||
|| (android.os.Flags.allowPrivateProfile()
|
||||
&& android.multiuser.Flags.enablePrivateSpaceFeatures()
|
||||
&& android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace()
|
||||
&& userInfo.isPrivateProfile())) {
|
||||
mIcon = context.getPackageManager().getUserBadgeForDensityNoBackground(
|
||||
userHandle, /* density= */ 0);
|
||||
mIcon.setTint(tintColor);
|
||||
@@ -88,6 +92,7 @@ public class UserAdapter extends BaseAdapter {
|
||||
() -> context.getString(com.android.settingslib.R.string.category_work));
|
||||
} else if (android.os.Flags.allowPrivateProfile()
|
||||
&& android.multiuser.Flags.enablePrivateSpaceFeatures()
|
||||
&& android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace()
|
||||
&& mUserManager.getUserInfo(userId).isPrivateProfile()) {
|
||||
return resources.getString(PRIVATE_CATEGORY_HEADER,
|
||||
() -> context.getString(com.android.settingslib.R.string.category_private));
|
||||
@@ -209,6 +214,7 @@ public class UserAdapter extends BaseAdapter {
|
||||
|
||||
private static UserAdapter createUserAdapter(
|
||||
UserManager userManager, Context context, List<UserHandle> userProfiles) {
|
||||
updateUserHandlesIfNeeded(userManager, userProfiles);
|
||||
ArrayList<UserDetails> userDetails = new ArrayList<>(userProfiles.size());
|
||||
for (UserHandle userProfile : userProfiles) {
|
||||
userDetails.add(new UserDetails(userProfile, userManager, context));
|
||||
@@ -216,6 +222,15 @@ public class UserAdapter extends BaseAdapter {
|
||||
return new UserAdapter(context, userDetails);
|
||||
}
|
||||
|
||||
private static void updateUserHandlesIfNeeded(
|
||||
UserManager userManager, List<UserHandle> userProfiles) {
|
||||
for (int i = userProfiles.size() - 1; i >= 0; --i) {
|
||||
if (com.android.settings.Utils.shouldHideUser(userProfiles.get(i), userManager)) {
|
||||
userProfiles.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private final ImageView mIconView;
|
||||
private final TextView mTitleView;
|
||||
|
Reference in New Issue
Block a user