diff options
4 files changed, 15 insertions, 25 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreferenceMixin.java b/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreferenceMixin.java index 81908de16..b5177834c 100644 --- a/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreferenceMixin.java +++ b/PermissionController/src/com/android/permissioncontroller/role/ui/RestrictionAwarePreferenceMixin.java @@ -16,7 +16,6 @@ package com.android.permissioncontroller.role.ui; -import android.app.PendingIntent; import android.app.admin.DevicePolicyManager; import android.app.ecm.EnhancedConfirmationManager; import android.content.Context; @@ -108,14 +107,13 @@ public class RestrictionAwarePreferenceMixin { && mUser != null) { Context context = UserUtils.getUserContext(holder.itemView.getContext(), mUser); onClickListener = (view) -> { + EnhancedConfirmationManager enhancedConfirmationManager = + context.getSystemService(EnhancedConfirmationManager.class); try { - context.getSystemService(EnhancedConfirmationManager.class) - .getRestrictedSettingDialogIntent( + context.startActivity( + enhancedConfirmationManager.createRestrictedSettingDialogIntent( mEnhancedConfirmationRestrictedPackageName, - mEnhancedConfirmationRestrictedSettingIdentifier) - .send(); - } catch (PendingIntent.CanceledException e) { - Log.e(LOG_TAG, "Pending intent fail to be sent.", e); + mEnhancedConfirmationRestrictedSettingIdentifier)); } catch (PackageManager.NameNotFoundException e) { Log.e(LOG_TAG, "Package name is not found.", e); } diff --git a/framework-s/api/system-current.txt b/framework-s/api/system-current.txt index 61af606e9..e15887576 100644 --- a/framework-s/api/system-current.txt +++ b/framework-s/api/system-current.txt @@ -3,7 +3,7 @@ package android.app.ecm { @FlaggedApi("android.permission.flags.enhanced_confirmation_mode_apis_enabled") public final class EnhancedConfirmationManager { method @RequiresPermission(android.Manifest.permission.MANAGE_ENHANCED_CONFIRMATION_STATES) public void clearRestriction(@NonNull String) throws android.content.pm.PackageManager.NameNotFoundException; - method @NonNull public android.app.PendingIntent getRestrictedSettingDialogIntent(@NonNull String, @NonNull String) throws android.content.pm.PackageManager.NameNotFoundException; + method @NonNull public android.content.Intent createRestrictedSettingDialogIntent(@NonNull String, @NonNull String) throws android.content.pm.PackageManager.NameNotFoundException; method @RequiresPermission(android.Manifest.permission.MANAGE_ENHANCED_CONFIRMATION_STATES) public boolean isClearRestrictionAllowed(@NonNull String) throws android.content.pm.PackageManager.NameNotFoundException; method @RequiresPermission(android.Manifest.permission.MANAGE_ENHANCED_CONFIRMATION_STATES) public boolean isRestricted(@NonNull String, @NonNull String) throws android.content.pm.PackageManager.NameNotFoundException; method @RequiresPermission(android.Manifest.permission.MANAGE_ENHANCED_CONFIRMATION_STATES) public void setClearRestrictionAllowed(@NonNull String) throws android.content.pm.PackageManager.NameNotFoundException; diff --git a/framework-s/java/android/app/ecm/EnhancedConfirmationManager.java b/framework-s/java/android/app/ecm/EnhancedConfirmationManager.java index 86aa222c6..e304fc21e 100644 --- a/framework-s/java/android/app/ecm/EnhancedConfirmationManager.java +++ b/framework-s/java/android/app/ecm/EnhancedConfirmationManager.java @@ -26,7 +26,6 @@ import android.annotation.SystemApi; import android.annotation.SystemService; import android.annotation.TargetApi; import android.app.AppOpsManager; -import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -40,7 +39,6 @@ import android.util.ArraySet; import androidx.annotation.NonNull; import java.lang.annotation.Retention; -import java.util.concurrent.atomic.AtomicInteger; /** * This class provides the core API for ECM (Enhanced Confirmation Mode). ECM is a feature that @@ -53,7 +51,7 @@ import java.util.concurrent.atomic.AtomicInteger; * <ol> * <li>Check whether a setting is restricted from an app ({@link #isRestricted}) * <li>Get an intent that will open the "Restricted setting" dialog ({@link - * #getRestrictedSettingDialogIntent}) (a dialog that informs the user that the operation + * #createRestrictedSettingDialogIntent}) (a dialog that informs the user that the operation * they've attempted to perform is restricted) * <li>Check whether an app is eligible to have its restriction status cleared ({@link * #isClearRestrictionAllowed}) @@ -117,7 +115,7 @@ import java.util.concurrent.atomic.AtomicInteger; * on-screen is restricted from the accessibility service setting. It uses this to visually * "gray out" restricted apps.** * <li>The user tries to register the app as an accessibility service. - * <p>**This screen then calls {@link #getRestrictedSettingDialogIntent} and starts the + * <p>**This screen then calls {@link #createRestrictedSettingDialogIntent} and starts the * intent. This opens the "Restricted setting" dialog.** * <li>The user is presented with a "Restricted setting" dialog explaining that the attempted * action is restricted. (No "allow" button is shown, but a link is given to a screen with @@ -229,8 +227,6 @@ public final class EnhancedConfirmationManager { private final @NonNull IEnhancedConfirmationManager mService; - private static final AtomicInteger sNextRequestCode = new AtomicInteger(1); - /** * @hide */ @@ -316,7 +312,7 @@ public final class EnhancedConfirmationManager { * Mark the app as eligible to have its restriction status cleared. * * <p>This should be called from the "Restricted setting" dialog (which {@link - * #getRestrictedSettingDialogIntent} directs to) upon being presented to the user. + * #createRestrictedSettingDialogIntent} directs to) upon being presented to the user. * * @param packageName package name of the application which should be considered acknowledged * @throws NameNotFoundException if the provided package was not found @@ -343,13 +339,12 @@ public final class EnhancedConfirmationManager { * @param packageName package name of the application to open the dialog for * @throws NameNotFoundException if the provided package was not found */ - public @NonNull PendingIntent getRestrictedSettingDialogIntent(@NonNull String packageName, + public @NonNull Intent createRestrictedSettingDialogIntent(@NonNull String packageName, @NonNull String settingIdentifier) throws NameNotFoundException { Intent intent = new Intent(Settings.ACTION_SHOW_RESTRICTED_SETTING_DIALOG); intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName); intent.putExtra(Intent.EXTRA_UID, getPackageUid(packageName)); - return PendingIntent.getActivity(mContext, sNextRequestCode.getAndIncrement(), - intent, PendingIntent.FLAG_IMMUTABLE); + return intent; } private int getPackageUid(String packageName) throws NameNotFoundException { diff --git a/tests/cts/permissionui/src/android/permissionui/cts/EnhancedConfirmationManagerTest.kt b/tests/cts/permissionui/src/android/permissionui/cts/EnhancedConfirmationManagerTest.kt index 42017a51e..4d1118a6f 100644 --- a/tests/cts/permissionui/src/android/permissionui/cts/EnhancedConfirmationManagerTest.kt +++ b/tests/cts/permissionui/src/android/permissionui/cts/EnhancedConfirmationManagerTest.kt @@ -32,7 +32,7 @@ import androidx.test.platform.app.InstrumentationRegistry import com.android.compatibility.common.util.SystemUtil.eventually import com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity import org.junit.Assert.assertFalse -import org.junit.Assert.assertNotEquals +import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test @@ -122,15 +122,12 @@ class EnhancedConfirmationManagerTest : BaseUsePermissionTest() { @RequiresFlagsEnabled(Flags.FLAG_ENHANCED_CONFIRMATION_MODE_APIS_ENABLED) @Test - fun getRestrictedSettingDialogIntentReturnsUniqueObjects() { + fun createRestrictedSettingDialogIntentReturnsIntent() { installPackageWithInstallSourceAndMetadataFromDownloadedFile(apkName) - val pendingIntent1 = - ecm.getRestrictedSettingDialogIntent(APP_PACKAGE_NAME, PROTECTED_SETTING) - val pendingIntent2 = - ecm.getRestrictedSettingDialogIntent(APP_PACKAGE_NAME, PROTECTED_SETTING) + val intent = ecm.createRestrictedSettingDialogIntent(APP_PACKAGE_NAME, PROTECTED_SETTING) - assertNotEquals(pendingIntent1, pendingIntent2) + assertNotNull(intent) } companion object { |