Merge "Update Trusted credentials page for private profile" into main

This commit is contained in:
Manish Singh
2024-03-19 10:01:26 +00:00
committed by Android (Google) Code Review

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();
if (android.os.Flags.allowPrivateProfile()
&& android.multiuser.Flags.enablePrivateSpaceFeatures()
&& android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace()) {
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_AVAILABLE);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE); filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED); filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
activity.registerReceiver(mWorkProfileChangedReceiver, filter); }
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,