Support Private profile in profile modal selector
Profile selector modal with work profile https://screenshot.googleplex.com/8ugpsT7nZA75VPa Modal without work profile https://screenshot.googleplex.com/9bPFbFG2DKBHhvS Bug: 309635228 Test: manual Change-Id: Id7533f101d2b5693c419c9591d59751925a4b7ce
This commit is contained in:
@@ -25,7 +25,9 @@ import android.content.DialogInterface.OnDismissListener;
|
|||||||
import android.content.DialogInterface.OnShowListener;
|
import android.content.DialogInterface.OnShowListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
|
import android.content.pm.UserProperties;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Flags;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -183,7 +185,10 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O
|
|||||||
final UserManager userManager = UserManager.get(context);
|
final UserManager userManager = UserManager.get(context);
|
||||||
for (int i = userHandles.size() - 1; i >= 0; i--) {
|
for (int i = userHandles.size() - 1; i >= 0; i--) {
|
||||||
UserInfo userInfo = userManager.getUserInfo(userHandles.get(i).getIdentifier());
|
UserInfo userInfo = userManager.getUserInfo(userHandles.get(i).getIdentifier());
|
||||||
if (userInfo == null || userInfo.isCloneProfile()) {
|
if (userInfo == null
|
||||||
|
|| userInfo.isCloneProfile()
|
||||||
|
|| (Flags.allowPrivateProfile()
|
||||||
|
&& shouldHideUserInQuietMode(userHandles.get(i), userManager))) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "Delete the user: " + userHandles.get(i).getIdentifier());
|
Log.d(TAG, "Delete the user: " + userHandles.get(i).getIdentifier());
|
||||||
}
|
}
|
||||||
@@ -214,7 +219,10 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O
|
|||||||
final UserManager userManager = UserManager.get(context);
|
final UserManager userManager = UserManager.get(context);
|
||||||
for (UserHandle userHandle : List.copyOf(tile.pendingIntentMap.keySet())) {
|
for (UserHandle userHandle : List.copyOf(tile.pendingIntentMap.keySet())) {
|
||||||
UserInfo userInfo = userManager.getUserInfo(userHandle.getIdentifier());
|
UserInfo userInfo = userManager.getUserInfo(userHandle.getIdentifier());
|
||||||
if (userInfo == null || userInfo.isCloneProfile()) {
|
if (userInfo == null
|
||||||
|
|| userInfo.isCloneProfile()
|
||||||
|
|| (Flags.allowPrivateProfile()
|
||||||
|
&& shouldHideUserInQuietMode(userHandle, userManager))) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "Delete the user: " + userHandle.getIdentifier());
|
Log.d(TAG, "Delete the user: " + userHandle.getIdentifier());
|
||||||
}
|
}
|
||||||
@@ -223,4 +231,11 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean shouldHideUserInQuietMode(
|
||||||
|
UserHandle userHandle, UserManager userManager) {
|
||||||
|
UserProperties userProperties = userManager.getUserProperties(userHandle);
|
||||||
|
return userProperties.getHideInSettingsInQuietMode()
|
||||||
|
&& userManager.isQuietModeEnabled(userHandle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,6 @@
|
|||||||
package com.android.settings.dashboard.profileselector;
|
package com.android.settings.dashboard.profileselector;
|
||||||
|
|
||||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.PERSONAL_CATEGORY_HEADER;
|
import static android.app.admin.DevicePolicyResources.Strings.Settings.PERSONAL_CATEGORY_HEADER;
|
||||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_CATEGORY_HEADER;
|
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
@@ -51,11 +50,13 @@ public class UserAdapter extends BaseAdapter {
|
|||||||
/** Holder for user details */
|
/** Holder for user details */
|
||||||
public static class UserDetails {
|
public static class UserDetails {
|
||||||
private final UserHandle mUserHandle;
|
private final UserHandle mUserHandle;
|
||||||
|
private final UserManager mUserManager;
|
||||||
private final Drawable mIcon;
|
private final Drawable mIcon;
|
||||||
private final String mTitle;
|
private final String mTitle;
|
||||||
|
|
||||||
public UserDetails(UserHandle userHandle, UserManager um, Context context) {
|
public UserDetails(UserHandle userHandle, UserManager um, Context context) {
|
||||||
mUserHandle = userHandle;
|
mUserHandle = userHandle;
|
||||||
|
mUserManager = um;
|
||||||
UserInfo userInfo = um.getUserInfo(mUserHandle.getIdentifier());
|
UserInfo userInfo = um.getUserInfo(mUserHandle.getIdentifier());
|
||||||
int tintColor = Utils.getColorAttrDefaultColor(context,
|
int tintColor = Utils.getColorAttrDefaultColor(context,
|
||||||
com.android.internal.R.attr.materialColorPrimaryContainer);
|
com.android.internal.R.attr.materialColorPrimaryContainer);
|
||||||
@@ -73,16 +74,13 @@ public class UserAdapter extends BaseAdapter {
|
|||||||
DevicePolicyManager devicePolicyManager =
|
DevicePolicyManager devicePolicyManager =
|
||||||
Objects.requireNonNull(context.getSystemService(DevicePolicyManager.class));
|
Objects.requireNonNull(context.getSystemService(DevicePolicyManager.class));
|
||||||
DevicePolicyResourcesManager resources = devicePolicyManager.getResources();
|
DevicePolicyResourcesManager resources = devicePolicyManager.getResources();
|
||||||
int userHandle = mUserHandle.getIdentifier();
|
int userId = mUserHandle.getIdentifier();
|
||||||
if (userHandle == UserHandle.USER_CURRENT
|
if (userId == UserHandle.USER_CURRENT || userId == ActivityManager.getCurrentUser()) {
|
||||||
|| userHandle == ActivityManager.getCurrentUser()) {
|
|
||||||
return resources.getString(PERSONAL_CATEGORY_HEADER,
|
return resources.getString(PERSONAL_CATEGORY_HEADER,
|
||||||
() -> context.getString(
|
() -> context.getString(
|
||||||
com.android.settingslib.R.string.category_personal));
|
com.android.settingslib.R.string.category_personal));
|
||||||
} else {
|
|
||||||
return resources.getString(WORK_CATEGORY_HEADER,
|
|
||||||
() -> context.getString(com.android.settingslib.R.string.category_work));
|
|
||||||
}
|
}
|
||||||
|
return (String) mUserManager.getBadgedLabelForUser(/* label= */ "", mUserHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user