diff options
21 files changed, 154 insertions, 295 deletions
diff --git a/PermissionController/role-controller/java/com/android/role/controller/model/Role.java b/PermissionController/role-controller/java/com/android/role/controller/model/Role.java index fe062ef53..51730a1df 100644 --- a/PermissionController/role-controller/java/com/android/role/controller/model/Role.java +++ b/PermissionController/role-controller/java/com/android/role/controller/model/Role.java @@ -17,9 +17,12 @@ package com.android.role.controller.model; import android.app.ActivityManager; +import android.app.admin.DevicePolicyManager; +import android.app.ecm.EnhancedConfirmationManager; import android.app.role.RoleManager; import android.content.ComponentName; import android.content.Context; +import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.SharedLibraryInfo; @@ -27,6 +30,9 @@ import android.content.pm.Signature; import android.content.res.Resources; import android.os.Build; import android.os.UserHandle; +import android.os.UserManager; +import android.permission.flags.Flags; +import android.provider.Settings; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; @@ -970,7 +976,7 @@ public class Role { * Check whether this role should be visible to user. * * @param user the user to check for - * @param context the `Context` to retrieve system services + * @param context the {@code Context} to retrieve system services * * @return whether this role should be visible to user */ @@ -1000,6 +1006,76 @@ public class Role { return behavior.isApplicationVisibleAsUser(this, applicationInfo, user, context); } + /** + * Check whether this role is restricted and return the {@code Intent} for the restriction if it + * is. + * <p> + * If a role is restricted, it is implied that all applications are restricted for the role as + * well. + * + * @param user the user to check for + * @param context the {@code Context} to retrieve system services + * + * @return the {@code Intent} for the restriction if this role is restricted, or {@code null} + * otherwise. + */ + @Nullable + public Intent getRestrictionIntentAsUser(@NonNull UserHandle user, @NonNull Context context) { + if (SdkLevel.isAtLeastU() && mExclusive) { + UserManager userManager = context.getSystemService(UserManager.class); + if (userManager.hasUserRestrictionForUser(UserManager.DISALLOW_CONFIG_DEFAULT_APPS, + user)) { + return new Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS) + .putExtra(DevicePolicyManager.EXTRA_RESTRICTION, + UserManager.DISALLOW_CONFIG_DEFAULT_APPS); + } + } + return null; + } + + /** + * Check whether an application is restricted for this role and return the {@code Intent} for + * the restriction if it is. + * <p> + * If a role is restricted, it is implied that all applications are restricted for the role as + * well. + * + * @param applicationInfo the {@link ApplicationInfo} for the application + * @param user the user to check for + * @param context the {@code Context} to retrieve system services + * + * @return the {@code Intent} for the restriction if the application is restricted for this + * role, or {@code null} otherwise. + */ + @Nullable + public Intent getApplicationRestrictionIntentAsUser(@NonNull ApplicationInfo applicationInfo, + @NonNull UserHandle user, @NonNull Context context) { + if (SdkLevel.isAtLeastV() && Flags.enhancedConfirmationModeApisEnabled()) { + Context userContext = UserUtils.getUserContext(context, user); + EnhancedConfirmationManager userEnhancedConfirmationManager = + userContext.getSystemService(EnhancedConfirmationManager.class); + String packageName = applicationInfo.packageName; + boolean isRestricted; + try { + isRestricted = userEnhancedConfirmationManager.isRestricted(packageName, mName); + } catch (PackageManager.NameNotFoundException e) { + Log.w(LOG_TAG, "Cannot check enhanced confirmation restriction for package: " + + packageName, e); + isRestricted = false; + } + if (isRestricted) { + try { + return userEnhancedConfirmationManager.createRestrictedSettingDialogIntent( + packageName, mName); + } catch (PackageManager.NameNotFoundException e) { + Log.w(LOG_TAG, "Cannot create enhanced confirmation restriction intent for" + + " package: " + packageName, e); + } + } + } + return getRestrictionIntentAsUser(user, context); + } + @Override public String toString() { return "Role{" diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppChildFragment.java b/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppChildFragment.java index a8b16c521..145031b63 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppChildFragment.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppChildFragment.java @@ -214,6 +214,8 @@ public class DefaultAppChildFragment<PF extends PreferenceFragmentCompat preference.setChecked(checked); if (applicationInfo != null) { + roleApplicationPreference.setRestrictionIntent( + mRole.getApplicationRestrictionIntentAsUser(applicationInfo, mUser, context)); RoleUiBehaviorUtils.prepareApplicationPreferenceAsUser(mRole, roleApplicationPreference, applicationInfo, mUser, context); } diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppListChildFragment.java b/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppListChildFragment.java index e68fa88a0..a1c4d84a5 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppListChildFragment.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppListChildFragment.java @@ -182,6 +182,7 @@ public class DefaultAppListChildFragment<PF extends PreferenceFragmentCompat preference = rolePreference.asPreference(); } + rolePreference.setRestrictionIntent(role.getRestrictionIntentAsUser(user, context)); List<ApplicationInfo> holderApplicationInfos = roleItem.getHolderApplicationInfos(); if (holderApplicationInfos.isEmpty()) { preference.setIcon(null); diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreference.java b/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreference.java index 71b0ef98b..f68253161 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreference.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreference.java @@ -16,9 +16,8 @@ package com.android.permissioncontroller.role.ui; -import android.os.UserHandle; +import android.content.Intent; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** @@ -27,13 +26,7 @@ import androidx.annotation.Nullable; public interface RestrictionAwarePreference { /** - * Specifies user restriction that blocks this preference. + * Set the restriction intent that blocks this preference. */ - void setUserRestriction(@Nullable String userRestriction, @NonNull UserHandle user); - - /** - * Specifies enhanced confirmation restrictions that block this preference. - */ - void setEnhancedConfirmationRestriction(@Nullable String packageName, - @Nullable String settingIdentifier, @NonNull UserHandle user); + void setRestrictionIntent(@Nullable Intent restrictionIntent); } diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreferenceMixin.java b/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreferenceMixin.java index b5177834c..8d757324f 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreferenceMixin.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreferenceMixin.java @@ -16,25 +16,13 @@ package com.android.permissioncontroller.role.ui; -import android.app.admin.DevicePolicyManager; -import android.app.ecm.EnhancedConfirmationManager; -import android.content.Context; import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.UserHandle; -import android.provider.Settings; -import android.util.Log; -import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; -import com.android.modules.utils.build.SdkLevel; -import com.android.permissioncontroller.DeviceUtils; -import com.android.permissioncontroller.role.utils.UserUtils; - /** * Mixin for implementing {@link RestrictionAwarePreference}. */ @@ -46,96 +34,35 @@ public class RestrictionAwarePreferenceMixin { private final Preference mPreference; @Nullable - private String mUserRestriction; - - @Nullable - private String mEnhancedConfirmationRestrictedPackageName; - @Nullable - private String mEnhancedConfirmationRestrictedSettingIdentifier; - - @Nullable - private UserHandle mUser; + private Intent mRestrictionIntent; public RestrictionAwarePreferenceMixin(@NonNull Preference preference) { mPreference = preference; } /** - * Implementation for {@link RestrictionAwarePreference#setUserRestriction}. + * Implementation for {@link RestrictionAwarePreference#setRestrictionIntent}. */ - public void setUserRestriction(@Nullable String userRestriction, @NonNull UserHandle user) { - mUserRestriction = userRestriction; - mUser = user; - updateEnabled(); - } - - /** - * Implementation for {@link RestrictionAwarePreference#setEnhancedConfirmationRestriction}. - */ - public void setEnhancedConfirmationRestriction(@Nullable String packageName, - @Nullable String settingIdentifier, @NonNull UserHandle user) { - if (!isEnhancedConfirmationRestrictionEnabled()) { - return; - } - mEnhancedConfirmationRestrictedPackageName = packageName; - mEnhancedConfirmationRestrictedSettingIdentifier = settingIdentifier; - mUser = user; - updateEnabled(); - } - - private boolean isEnhancedConfirmationRestrictionEnabled() { - // Enhanced confirmation restriction is currently applied only to handheld. - Context context = mPreference.getContext(); - return !(DeviceUtils.isAuto(context) || DeviceUtils.isTelevision(context) - || DeviceUtils.isWear(context)); - } - - private void updateEnabled() { - mPreference.setEnabled(mUserRestriction == null - && (mEnhancedConfirmationRestrictedPackageName == null - || mEnhancedConfirmationRestrictedSettingIdentifier == null)); + public void setRestrictionIntent(@Nullable Intent restrictionIntent) { + mRestrictionIntent = restrictionIntent; + mPreference.setEnabled(mRestrictionIntent == null); } /** * Call after {@link Preference#onBindViewHolder} to apply blocking effects. */ public void onAfterBindViewHolder(@NonNull PreferenceViewHolder holder) { - View.OnClickListener onClickListener = null; - if (SdkLevel.isAtLeastV() - && mEnhancedConfirmationRestrictedPackageName != null - && mEnhancedConfirmationRestrictedSettingIdentifier != null - && mUser != null) { - Context context = UserUtils.getUserContext(holder.itemView.getContext(), mUser); - onClickListener = (view) -> { - EnhancedConfirmationManager enhancedConfirmationManager = - context.getSystemService(EnhancedConfirmationManager.class); - try { - context.startActivity( - enhancedConfirmationManager.createRestrictedSettingDialogIntent( - mEnhancedConfirmationRestrictedPackageName, - mEnhancedConfirmationRestrictedSettingIdentifier)); - } catch (PackageManager.NameNotFoundException e) { - Log.e(LOG_TAG, "Package name is not found.", e); - } - }; - } else if (mUserRestriction != null) { - Intent userRestrictionIntent = new Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS) - .putExtra(DevicePolicyManager.EXTRA_RESTRICTION, mUserRestriction); - onClickListener = (view) -> { - holder.itemView.getContext().startActivity(userRestrictionIntent); - }; - } - - // We set the item view to enabled to make the preference row clickable. - // Normal disabled preferences have the whole view hierarchy disabled, so by making only - // the top-level itemView enabled, we don't change the fact that the whole preference - // still "looks" disabled (see Preference.onBindViewHolder). - // Preference.onBindViewHolder sets the onClickListener as well on each preference, so - // we don't need to unset the listener here (we wouldn't know the correct one anyway). - // This approach is used already by com.android.settingslib.RestrictedPreferenceHelper. - if (onClickListener != null) { + if (mRestrictionIntent != null) { + // We set the item view to enabled to make the preference row clickable. + // Normal disabled preferences have the whole view hierarchy disabled, so by making only + // the top-level itemView enabled, we don't change the fact that the whole preference + // still "looks" disabled (see Preference.onBindViewHolder). + // Preference.onBindViewHolder sets the onClickListener as well on each preference, so + // we don't need to unset the listener here (we wouldn't know the correct one anyway). + // This approach is used already by com.android.settingslib.RestrictedPreferenceHelper. holder.itemView.setEnabled(true); - holder.itemView.setOnClickListener(onClickListener); + holder.itemView.setOnClickListener( + view -> view.getContext().startActivity(mRestrictionIntent)); } } } diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/RolePreference.java b/PermissionController/src/com/android/permissioncontroller/role/ui/RolePreference.java index becbbea62..bbc123cfe 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/RolePreference.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/RolePreference.java @@ -16,6 +16,7 @@ package com.android.permissioncontroller.role.ui; +import androidx.annotation.NonNull; import androidx.preference.Preference; /** @@ -25,5 +26,6 @@ public interface RolePreference extends TwoTargetPreference, RestrictionAwarePre /** * Return this preference as {@link Preference}. */ + @NonNull Preference asPreference(); } diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/TwoTargetPreference.java b/PermissionController/src/com/android/permissioncontroller/role/ui/TwoTargetPreference.java index 3a8cd55d3..ab2387686 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/TwoTargetPreference.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/TwoTargetPreference.java @@ -41,6 +41,7 @@ public interface TwoTargetPreference { /** * Return this preference as {@link Preference}. */ + @NonNull Preference asPreference(); /** diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoRadioPreference.java b/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoRadioPreference.java index ebeba0482..764c07497 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoRadioPreference.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoRadioPreference.java @@ -17,7 +17,7 @@ package com.android.permissioncontroller.role.ui.auto; import android.content.Context; -import android.os.UserHandle; +import android.content.Intent; import android.widget.RadioButton; import androidx.annotation.NonNull; @@ -37,7 +37,7 @@ public class AutoRadioPreference extends TwoStatePreference implements private final RestrictionAwarePreferenceMixin mRestrictionAwarePreferenceMixin = new RestrictionAwarePreferenceMixin(this); - public AutoRadioPreference(Context context) { + public AutoRadioPreference(@NonNull Context context) { super(context, null, TypedArrayUtils.getAttr(context, androidx.preference.R.attr.preferenceStyle, android.R.attr.preferenceStyle)); @@ -50,7 +50,7 @@ public class AutoRadioPreference extends TwoStatePreference implements } @Override - public void onBindViewHolder(PreferenceViewHolder holder) { + public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { super.onBindViewHolder(holder); RadioButton radioButton = (RadioButton) holder.findViewById(R.id.radio_button); @@ -60,17 +60,11 @@ public class AutoRadioPreference extends TwoStatePreference implements } @Override - public void setUserRestriction(@Nullable String userRestriction, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setUserRestriction(userRestriction, user); - } - - @Override - public void setEnhancedConfirmationRestriction(@Nullable String packageName, - @Nullable String settingIdentifier, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setEnhancedConfirmationRestriction(packageName, - settingIdentifier, user); + public void setRestrictionIntent(@Nullable Intent restrictionIntent) { + mRestrictionAwarePreferenceMixin.setRestrictionIntent(restrictionIntent); } + @NonNull @Override public AutoRadioPreference asTwoStatePreference() { return this; diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoRolePreference.java b/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoRolePreference.java index af4f0cc0a..15fd117d1 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoRolePreference.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoRolePreference.java @@ -17,11 +17,13 @@ package com.android.permissioncontroller.role.ui.auto; import android.content.Context; -import android.os.UserHandle; +import android.content.Intent; import android.util.AttributeSet; +import androidx.annotation.AttrRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.StyleRes; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; @@ -39,12 +41,12 @@ public class AutoRolePreference extends Preference implements RolePreference { new RestrictionAwarePreferenceMixin(this); public AutoRolePreference(@NonNull Context context, - @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { + @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public AutoRolePreference(@NonNull Context context, @Nullable AttributeSet attrs, - int defStyleAttr) { + @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); } @@ -57,28 +59,21 @@ public class AutoRolePreference extends Preference implements RolePreference { } @Override - public void setOnSecondTargetClickListener(@Nullable OnSecondTargetClickListener listener) { - } - - @Override - public void setUserRestriction(@Nullable String userRestriction, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setUserRestriction(userRestriction, user); - } + public void setOnSecondTargetClickListener(@Nullable OnSecondTargetClickListener listener) {} @Override - public void setEnhancedConfirmationRestriction(@Nullable String packageName, - @Nullable String settingIdentifier, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setEnhancedConfirmationRestriction(packageName, - settingIdentifier, user); + public void setRestrictionIntent(@Nullable Intent restrictionIntent) { + mRestrictionAwarePreferenceMixin.setRestrictionIntent(restrictionIntent); } @Override - public void onBindViewHolder(PreferenceViewHolder holder) { + public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { super.onBindViewHolder(holder); mRestrictionAwarePreferenceMixin.onAfterBindViewHolder(holder); } + @NonNull @Override public AutoRolePreference asPreference() { return this; diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoSwitchPreference.java b/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoSwitchPreference.java index a21bc8d8b..bfb2b5d1d 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoSwitchPreference.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/auto/AutoSwitchPreference.java @@ -17,7 +17,7 @@ package com.android.permissioncontroller.role.ui.auto; import android.content.Context; -import android.os.UserHandle; +import android.content.Intent; import android.util.AttributeSet; import androidx.annotation.AttrRes; @@ -58,19 +58,12 @@ public class AutoSwitchPreference extends SwitchPreference } @Override - public void setUserRestriction(@Nullable String userRestriction, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setUserRestriction(userRestriction, user); + public void setRestrictionIntent(@Nullable Intent restrictionIntent) { + mRestrictionAwarePreferenceMixin.setRestrictionIntent(restrictionIntent); } @Override - public void setEnhancedConfirmationRestriction(@Nullable String packageName, - @Nullable String settingIdentifier, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setEnhancedConfirmationRestriction(packageName, - settingIdentifier, user); - } - - @Override - public void onBindViewHolder(PreferenceViewHolder holder) { + public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { super.onBindViewHolder(holder); mRestrictionAwarePreferenceMixin.onAfterBindViewHolder(holder); diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/handheld/HandheldRadioPreference.java b/PermissionController/src/com/android/permissioncontroller/role/ui/handheld/HandheldRadioPreference.java index 4c7d636d7..67f04051c 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/handheld/HandheldRadioPreference.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/handheld/HandheldRadioPreference.java @@ -17,7 +17,7 @@ package com.android.permissioncontroller.role.ui.handheld; import android.content.Context; -import android.os.UserHandle; +import android.content.Intent; import android.util.AttributeSet; import androidx.annotation.NonNull; @@ -56,19 +56,12 @@ public class HandheldRadioPreference extends SelectorWithWidgetPreference implem } @Override - public void setUserRestriction(@Nullable String userRestriction, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setUserRestriction(userRestriction, user); + public void setRestrictionIntent(@Nullable Intent restrictionIntent) { + mRestrictionAwarePreferenceMixin.setRestrictionIntent(restrictionIntent); } @Override - public void setEnhancedConfirmationRestriction(@Nullable String packageName, - @Nullable String settingIdentifier, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setEnhancedConfirmationRestriction(packageName, - settingIdentifier, user); - } - - @Override - public void onBindViewHolder(PreferenceViewHolder holder) { + public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { super.onBindViewHolder(holder); mRestrictionAwarePreferenceMixin.onAfterBindViewHolder(holder); diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/handheld/HandheldRolePreference.java b/PermissionController/src/com/android/permissioncontroller/role/ui/handheld/HandheldRolePreference.java index 270e3a928..3d09f0b46 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/handheld/HandheldRolePreference.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/handheld/HandheldRolePreference.java @@ -17,7 +17,7 @@ package com.android.permissioncontroller.role.ui.handheld; import android.content.Context; -import android.os.UserHandle; +import android.content.Intent; import android.util.AttributeSet; import android.view.View; @@ -94,15 +94,8 @@ public class HandheldRolePreference extends TwoTargetPreference implements RoleP } @Override - public void setUserRestriction(@Nullable String userRestriction, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setUserRestriction(userRestriction, user); - } - - @Override - public void setEnhancedConfirmationRestriction(@Nullable String packageName, - @Nullable String settingIdentifier, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setEnhancedConfirmationRestriction(packageName, - settingIdentifier, user); + public void setRestrictionIntent(@Nullable Intent restrictionIntent) { + mRestrictionAwarePreferenceMixin.setRestrictionIntent(restrictionIntent); } @Override @@ -124,6 +117,7 @@ public class HandheldRolePreference extends TwoTargetPreference implements RoleP mRestrictionAwarePreferenceMixin.onAfterBindViewHolder(holder); } + @NonNull @Override public HandheldRolePreference asPreference() { return this; diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessChildFragment.java b/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessChildFragment.java index b95440bbd..4b397343c 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessChildFragment.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessChildFragment.java @@ -164,6 +164,9 @@ public class SpecialAppAccessChildFragment<PF extends PreferenceFragmentCompat preference.setChecked(isHolderPackage); UserHandle user = UserHandle.getUserHandleForUid(qualifyingApplicationInfo.uid); + roleApplicationPreference.setRestrictionIntent( + mRole.getApplicationRestrictionIntentAsUser(qualifyingApplicationInfo, user, + context)); RoleUiBehaviorUtils.prepareApplicationPreferenceAsUser(mRole, roleApplicationPreference, qualifyingApplicationInfo, user, context); preferenceScreen.addPreference(preference); diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessListChildFragment.java b/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessListChildFragment.java index b06904930..cacb4377f 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessListChildFragment.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessListChildFragment.java @@ -115,10 +115,11 @@ public class SpecialAppAccessListChildFragment<PF extends PreferenceFragmentComp } else { preference = rolePreference.asPreference(); } + + rolePreference.setRestrictionIntent(role.getRestrictionIntentAsUser( + Process.myUserHandle(), context)); RoleUiBehaviorUtils.preparePreferenceAsUser(role, roleItem.getHolderApplicationInfos(), - rolePreference, - Process.myUserHandle(), - context); + rolePreference, Process.myUserHandle(), context); preferenceScreen.addPreference(preference); } diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/handheld/HandheldSwitchPreference.java b/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/handheld/HandheldSwitchPreference.java index d5081566d..ded6d5cb5 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/handheld/HandheldSwitchPreference.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/handheld/HandheldSwitchPreference.java @@ -17,7 +17,7 @@ package com.android.permissioncontroller.role.ui.specialappaccess.handheld; import android.content.Context; -import android.os.UserHandle; +import android.content.Intent; import android.util.AttributeSet; import androidx.annotation.AttrRes; @@ -56,19 +56,12 @@ public class HandheldSwitchPreference extends AppSwitchPreference } @Override - public void setUserRestriction(@Nullable String userRestriction, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setUserRestriction(userRestriction, user); + public void setRestrictionIntent(@Nullable Intent restrictionIntent) { + mRestrictionAwarePreferenceMixin.setRestrictionIntent(restrictionIntent); } @Override - public void setEnhancedConfirmationRestriction(@Nullable String packageName, - @Nullable String settingIdentifier, @NonNull UserHandle user) { - mRestrictionAwarePreferenceMixin.setEnhancedConfirmationRestriction(packageName, - settingIdentifier, user); - } - - @Override - public void onBindViewHolder(PreferenceViewHolder holder) { + public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { super.onBindViewHolder(holder); mRestrictionAwarePreferenceMixin.onAfterBindViewHolder(holder); diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/wear/WearRoleApplicationPreference.kt b/PermissionController/src/com/android/permissioncontroller/role/ui/wear/WearRoleApplicationPreference.kt index 430860bbb..abaa33a56 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/wear/WearRoleApplicationPreference.kt +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/wear/WearRoleApplicationPreference.kt @@ -16,11 +16,8 @@ package com.android.permissioncontroller.role.ui.wear -import android.app.admin.DevicePolicyManager import android.content.Context import android.content.Intent -import android.os.UserHandle -import android.provider.Settings import androidx.preference.TwoStatePreference import com.android.permissioncontroller.role.ui.RoleApplicationPreference @@ -33,36 +30,15 @@ class WearRoleApplicationPreference( val label: String, val checked: Boolean, val onDefaultCheckChanged: (Boolean) -> Unit = {}, - private var restriction: String? = null, - private var user: UserHandle? = null + private var restrictionIntent: Intent? = null ) : TwoStatePreference(context), RoleApplicationPreference { fun getOnCheckChanged(): (Boolean) -> Unit = - restriction?.let { - return { _ -> - context.startActivity( - Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS) - .putExtra(DevicePolicyManager.EXTRA_RESTRICTION, restriction) - ) - } - } - ?: onDefaultCheckChanged + restrictionIntent?.let { { _ -> context.startActivity(it) } } ?: onDefaultCheckChanged - override fun setUserRestriction(userRestriction: String?, userHandle: UserHandle) { - restriction = userRestriction - user = userHandle - setEnabled(restriction == null) + override fun setRestrictionIntent(restrictionIntent: Intent?) { + this.restrictionIntent = restrictionIntent + setEnabled(restrictionIntent == null) } - override fun setEnhancedConfirmationRestriction( - packageName: String?, - settingIdentifier: String?, - user: UserHandle - ) { - // no-op because Enhanced Confirmation Restriction is not applied to wear yet. - return - } - - override fun asTwoStatePreference(): TwoStatePreference { - return this - } + override fun asTwoStatePreference(): TwoStatePreference = this } diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/wear/WearRolePreference.kt b/PermissionController/src/com/android/permissioncontroller/role/ui/wear/WearRolePreference.kt index 9acaa158d..43acf4293 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/wear/WearRolePreference.kt +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/wear/WearRolePreference.kt @@ -16,11 +16,8 @@ package com.android.permissioncontroller.role.ui.wear -import android.app.admin.DevicePolicyManager import android.content.Context import android.content.Intent -import android.os.UserHandle -import android.provider.Settings import androidx.preference.Preference import com.android.permissioncontroller.role.ui.RolePreference import com.android.permissioncontroller.role.ui.TwoTargetPreference.OnSecondTargetClickListener @@ -31,41 +28,20 @@ class WearRolePreference( context: Context, val label: String, val onDefaultClicked: () -> Unit = {}, - private var restriction: String? = null, - private var user: UserHandle? = null + private var restrictionIntent: Intent? = null ) : TwoTargetPreference(context), RolePreference { override fun setOnSecondTargetClickListener(listener: OnSecondTargetClickListener?) { // no-op } - override fun setUserRestriction(userRestriction: String?, userHandle: UserHandle) { - restriction = userRestriction - user = userHandle - setEnabled(restriction == null) + override fun setRestrictionIntent(restrictionIntent: Intent?) { + this.restrictionIntent = restrictionIntent + setEnabled(restrictionIntent == null) } - override fun setEnhancedConfirmationRestriction( - packageName: String?, - settingIdentifier: String?, - user: UserHandle - ) { - // no-op because Enhanced Confirmation Restriction is not applied to wear yet. - return - } - - override fun asPreference(): Preference { - return this - } + override fun asPreference(): Preference = this fun getOnClicked(): () -> Unit = - restriction?.let { - return { - context.startActivity( - Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS) - .putExtra(DevicePolicyManager.EXTRA_RESTRICTION, restriction) - ) - } - } - ?: onDefaultClicked + restrictionIntent?.let { { context.startActivity(it) } } ?: onDefaultClicked } diff --git a/PermissionController/src/com/android/permissioncontroller/role/utils/RoleUiBehaviorUtils.java b/PermissionController/src/com/android/permissioncontroller/role/utils/RoleUiBehaviorUtils.java index 175bd71e5..21d16695c 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/utils/RoleUiBehaviorUtils.java +++ b/PermissionController/src/com/android/permissioncontroller/role/utils/RoleUiBehaviorUtils.java @@ -16,21 +16,15 @@ package com.android.permissioncontroller.role.utils; -import android.app.ecm.EnhancedConfirmationManager; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; import android.os.UserHandle; -import android.os.UserManager; -import android.permission.flags.Flags; import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.android.modules.utils.build.SdkLevel; -import com.android.permissioncontroller.role.ui.RestrictionAwarePreference; import com.android.permissioncontroller.role.ui.RoleApplicationPreference; import com.android.permissioncontroller.role.ui.RolePreference; import com.android.permissioncontroller.role.ui.behavior.RoleUiBehavior; @@ -85,8 +79,6 @@ public final class RoleUiBehaviorUtils { public static void preparePreferenceAsUser(@NonNull Role role, @NonNull List<ApplicationInfo> applicationInfos, @NonNull RolePreference preference, @NonNull UserHandle user, @NonNull Context context) { - prepareUserRestrictionAwarePreferenceAsUser(role, preference, user, context); - RoleUiBehavior uiBehavior = getUiBehavior(role); if (uiBehavior == null) { return; @@ -101,9 +93,6 @@ public final class RoleUiBehaviorUtils { @NonNull RoleApplicationPreference preference, @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user, @NonNull Context context) { - prepareUserRestrictionAwarePreferenceAsUser(role, preference, user, context); - prepareEnhancedConfirmationRestrictionAwarePreferenceAsUser(role, preference, - applicationInfo.packageName, user, context); RoleUiBehavior uiBehavior = getUiBehavior(role); if (uiBehavior == null) { return; @@ -113,55 +102,6 @@ public final class RoleUiBehaviorUtils { context); } - private static void prepareUserRestrictionAwarePreferenceAsUser(@NonNull Role role, - @NonNull RestrictionAwarePreference preference, @NonNull UserHandle user, - @NonNull Context context) { - if (SdkLevel.isAtLeastU() && role.isExclusive()) { - UserManager userManager = context.getSystemService(UserManager.class); - boolean hasDisallowConfigDefaultApps = userManager.hasUserRestrictionForUser( - UserManager.DISALLOW_CONFIG_DEFAULT_APPS, user); - preference.setUserRestriction(hasDisallowConfigDefaultApps - ? UserManager.DISALLOW_CONFIG_DEFAULT_APPS : null, user); - } - } - - private static void prepareEnhancedConfirmationRestrictionAwarePreferenceAsUser( - @NonNull Role role, @NonNull RestrictionAwarePreference preference, - @NonNull String packageName, @NonNull UserHandle user, @NonNull Context context) { - if (isEnhancedConfirmationRestrictedAsUser(packageName, role.getName(), user, context)) { - preference.setEnhancedConfirmationRestriction(packageName, role.getName(), user); - } else { - preference.setEnhancedConfirmationRestriction(null, null, user); - } - } - - /** - * This method checks if the package is restricted from a specific role with the given user. - * - * @param packageName the package name to check for - * @param user the user to check for - * @param context the {@code Context} to retrieve system services - * - * @return whether the package is restricted for a role - */ - private static boolean isEnhancedConfirmationRestrictedAsUser(@NonNull String packageName, - @NonNull String roleName, @NonNull UserHandle user, @NonNull Context context) { - if (SdkLevel.isAtLeastV() - && Flags.enhancedConfirmationModeApisEnabled()) { - Context userContext = UserUtils.getUserContext(context, user); - EnhancedConfirmationManager enhancedConfirmationManager = - userContext.getSystemService(EnhancedConfirmationManager.class); - try { - if (enhancedConfirmationManager.isRestricted(packageName, roleName)) { - return true; - } - } catch (PackageManager.NameNotFoundException e) { - Log.w(LOG_TAG, "Cannot find package name:" + packageName, e); - } - } - return false; - } - /** * @see RoleUiBehavior#getConfirmationMessage */ diff --git a/service/Android.bp b/service/Android.bp index 97a1a89ee..f9342deb9 100644 --- a/service/Android.bp +++ b/service/Android.bp @@ -163,6 +163,7 @@ java_library { ":statslog-service-permission-java-gen", ], libs: [ + "androidx.annotation_annotation", "framework-statsd.stubs.module_lib", ], apex_available: [ diff --git a/service/java/com/android/ecm/EnhancedConfirmationService.java b/service/java/com/android/ecm/EnhancedConfirmationService.java index f9f66e728..d91e04dfa 100644 --- a/service/java/com/android/ecm/EnhancedConfirmationService.java +++ b/service/java/com/android/ecm/EnhancedConfirmationService.java @@ -91,7 +91,7 @@ public class EnhancedConfirmationService extends SystemService { ArrayMap<String, List<byte[]>> trustedPackageMap = new ArrayMap<>(); for (SignedPackage signedPackage : signedPackages) { ArrayList<byte[]> certDigests = (ArrayList<byte[]>) trustedPackageMap.computeIfAbsent( - signedPackage.getPkgName(), pkgName -> new ArrayList<>(1)); + signedPackage.getPackageName(), packageName -> new ArrayList<>(1)); certDigests.add(signedPackage.getCertificateDigest()); } return trustedPackageMap; diff --git a/tests/cts/permissionpolicy/Android.bp b/tests/cts/permissionpolicy/Android.bp index 7a481b7ff..a2860e264 100644 --- a/tests/cts/permissionpolicy/Android.bp +++ b/tests/cts/permissionpolicy/Android.bp @@ -25,8 +25,6 @@ android_test { test_suites: [ "cts", "general-tests", - "mts-permission", - "mcts-permission", ], libs: ["android.test.base"], static_libs: [ |