Update Trusted credentials page for private profile

screen recording - https://drive.google.com/file/d/1XuDEkgOGSIvHlk1q5r7-EX13BGld0OWh/view?usp=sharing&resourcekey=0-FKRl_ddBn2HAkxfnV2dfKg

Bug: 307896268
Test: manual
Change-Id: Ic4b438282686704deef2a051b5c302b7fae49edc
This commit is contained in:
Manish Singh
2024-03-12 12:54:50 +00:00
parent 7dee0538d6
commit e5028048a0
2 changed files with 69 additions and 15 deletions

View File

@@ -17,6 +17,7 @@
package com.android.settings; package com.android.settings;
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.PRIVATE_CATEGORY_HEADER;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_CATEGORY_HEADER; import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_CATEGORY_HEADER;
import static android.widget.LinearLayout.LayoutParams.MATCH_PARENT; import static android.widget.LinearLayout.LayoutParams.MATCH_PARENT;
import static android.widget.LinearLayout.LayoutParams.WRAP_CONTENT; import static android.widget.LinearLayout.LayoutParams.WRAP_CONTENT;
@@ -108,18 +109,37 @@ public class TrustedCredentialsFragment extends ObservableFragment
mKeyChainConnectionByProfileId = new SparseArray<>(); mKeyChainConnectionByProfileId = new SparseArray<>();
private ViewGroup mFragmentView; private ViewGroup mFragmentView;
private final BroadcastReceiver mWorkProfileChangedReceiver = new BroadcastReceiver() { private final BroadcastReceiver mProfileChangedReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); if (isBroadcastValidForAction(intent)) {
if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action)
|| Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action)
|| Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
mGroupAdapter.load(); mGroupAdapter.load();
} }
} }
}; };
private boolean isBroadcastValidForAction(Intent intent) {
String action = intent.getAction();
if (android.os.Flags.allowPrivateProfile()
&& android.multiuser.Flags.enablePrivateSpaceFeatures()
&& android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace()) {
UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER, UserHandle.class);
if (userHandle == null) {
Log.w(TAG, "received action " + action + " with missing user extra");
return false;
}
UserInfo userInfo = mUserManager.getUserInfo(userHandle.getIdentifier());
return (Intent.ACTION_PROFILE_AVAILABLE.equals(action)
|| Intent.ACTION_PROFILE_UNAVAILABLE.equals(action)
|| Intent.ACTION_PROFILE_ACCESSIBLE.equals(action))
&& (userInfo.isManagedProfile() || userInfo.isPrivateProfile());
}
return (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action)
|| Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action)
|| Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action));
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@@ -142,10 +162,18 @@ public class TrustedCredentialsFragment extends ObservableFragment
} }
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE); if (android.os.Flags.allowPrivateProfile()
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE); && android.multiuser.Flags.enablePrivateSpaceFeatures()
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED); && android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace()) {
activity.registerReceiver(mWorkProfileChangedReceiver, filter); filter.addAction(Intent.ACTION_PROFILE_AVAILABLE);
filter.addAction(Intent.ACTION_PROFILE_UNAVAILABLE);
filter.addAction(Intent.ACTION_PROFILE_ACCESSIBLE);
} else {
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
}
activity.registerReceiver(mProfileChangedReceiver, filter);
} }
@Override @Override
@@ -177,7 +205,16 @@ public class TrustedCredentialsFragment extends ObservableFragment
private void createChildView( private void createChildView(
LayoutInflater inflater, ViewGroup parent, Bundle childState, int i) { LayoutInflater inflater, ViewGroup parent, Bundle childState, int i) {
boolean isWork = mGroupAdapter.getUserInfoByGroup(i).isManagedProfile(); UserInfo userInfo = mGroupAdapter.getUserInfoByGroup(i);
if (Utils.shouldHideUser(userInfo.getUserHandle(), mUserManager)) {
return;
}
boolean isProfile = userInfo.isManagedProfile();
if (android.os.Flags.allowPrivateProfile()
&& android.multiuser.Flags.enablePrivateSpaceFeatures()
&& android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace()) {
isProfile |= userInfo.isPrivateProfile();
}
ChildAdapter adapter = mGroupAdapter.createChildAdapter(i); ChildAdapter adapter = mGroupAdapter.createChildAdapter(i);
LinearLayout containerView = (LinearLayout) inflater.inflate( LinearLayout containerView = (LinearLayout) inflater.inflate(
@@ -186,9 +223,9 @@ public class TrustedCredentialsFragment extends ObservableFragment
int profilesSize = mGroupAdapter.getGroupCount(); int profilesSize = mGroupAdapter.getGroupCount();
adapter.showHeader(profilesSize > 1); adapter.showHeader(profilesSize > 1);
adapter.showDivider(isWork); adapter.showDivider(isProfile);
adapter.setExpandIfAvailable(profilesSize <= 2 || !isWork, childState); adapter.setExpandIfAvailable(profilesSize <= 2 || !isProfile, childState);
if (isWork) { if (isProfile) {
parent.addView(containerView); parent.addView(containerView);
} else { } else {
parent.addView(containerView, 0); parent.addView(containerView, 0);
@@ -203,7 +240,7 @@ public class TrustedCredentialsFragment extends ObservableFragment
@Override @Override
public void onDestroy() { public void onDestroy() {
getActivity().unregisterReceiver(mWorkProfileChangedReceiver); getActivity().unregisterReceiver(mProfileChangedReceiver);
for (AdapterData.AliasLoader aliasLoader : mAliasLoaders) { for (AdapterData.AliasLoader aliasLoader : mAliasLoaders) {
aliasLoader.cancel(true); aliasLoader.cancel(true);
} }
@@ -331,9 +368,16 @@ public class TrustedCredentialsFragment extends ObservableFragment
} }
TextView title = convertView.findViewById(android.R.id.title); TextView title = convertView.findViewById(android.R.id.title);
if (getUserInfoByGroup(groupPosition).isManagedProfile()) { UserInfo userInfo = getUserInfoByGroup(groupPosition);
if (userInfo.isManagedProfile()) {
title.setText(mDevicePolicyManager.getResources().getString(WORK_CATEGORY_HEADER, title.setText(mDevicePolicyManager.getResources().getString(WORK_CATEGORY_HEADER,
() -> getString(com.android.settingslib.R.string.category_work))); () -> getString(com.android.settingslib.R.string.category_work)));
} else if (android.os.Flags.allowPrivateProfile()
&& android.multiuser.Flags.enablePrivateSpaceFeatures()
&& android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace()
&& userInfo.isPrivateProfile()) {
title.setText(mDevicePolicyManager.getResources().getString(PRIVATE_CATEGORY_HEADER,
() -> getString(com.android.settingslib.R.string.category_private)));
} else { } else {
title.setText(mDevicePolicyManager.getResources().getString( title.setText(mDevicePolicyManager.getResources().getString(
PERSONAL_CATEGORY_HEADER, PERSONAL_CATEGORY_HEADER,

View File

@@ -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) { private static FaceManager.RemovalCallback faceManagerRemovalCallback(int userId) {
return new FaceManager.RemovalCallback() { return new FaceManager.RemovalCallback() {
@Override @Override