From b5441bf782938d17ebe91586c0e819a1dbcd0c55 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Thu, 28 Sep 2023 14:48:15 +0000 Subject: [PATCH] Provide SuspendDialogInfo when quarantining an app. Customize the dialog to include a button to allow users to take an app out of the quarantine state. Bug: 297934650 Test: atest tests/robotests/src/com/android/settings/development/quarantine/QuarantinedAppsScreenControllerTest.java Change-Id: I1b6e9f057fed91ae131602fd6d6ddf5e23958a65 --- res/values/strings.xml | 2 ++ .../quarantine/QuarantinedAppsScreenController.java | 12 +++++++++++- .../QuarantinedAppsScreenControllerTest.java | 6 ++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 2cd78066425..977c789c5c0 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -12458,4 +12458,6 @@ Quarantined Apps + + Unquarantine app diff --git a/src/com/android/settings/development/quarantine/QuarantinedAppsScreenController.java b/src/com/android/settings/development/quarantine/QuarantinedAppsScreenController.java index e5373fd0bee..c3cb38dfe30 100644 --- a/src/com/android/settings/development/quarantine/QuarantinedAppsScreenController.java +++ b/src/com/android/settings/development/quarantine/QuarantinedAppsScreenController.java @@ -19,6 +19,7 @@ package com.android.settings.development.quarantine; import android.app.Application; import android.content.Context; import android.content.pm.PackageManager; +import android.content.pm.SuspendDialogInfo; import android.os.UserHandle; import androidx.annotation.VisibleForTesting; @@ -181,8 +182,17 @@ public class QuarantinedAppsScreenController extends BasePreferenceController im private void setPackageQuarantined(String pkg, int uid, boolean quarantined) { final PackageManager pm = mContext.createContextAsUser( UserHandle.getUserHandleForUid(uid), 0).getPackageManager(); + final SuspendDialogInfo dialogInfo; + if (quarantined) { + dialogInfo = new SuspendDialogInfo.Builder() + .setNeutralButtonText(R.string.unquarantine_app_button) + .setNeutralButtonAction(SuspendDialogInfo.BUTTON_ACTION_UNSUSPEND) + .build(); + } else { + dialogInfo = null; + } pm.setPackagesSuspended(new String[] {pkg}, quarantined, null /* appExtras */, - null /* launcherExtras */, null /* dialogInfo */, + null /* launcherExtras */, dialogInfo, PackageManager.FLAG_SUSPEND_QUARANTINED); } diff --git a/tests/robotests/src/com/android/settings/development/quarantine/QuarantinedAppsScreenControllerTest.java b/tests/robotests/src/com/android/settings/development/quarantine/QuarantinedAppsScreenControllerTest.java index 32ad0ad8ab3..a93e5291192 100644 --- a/tests/robotests/src/com/android/settings/development/quarantine/QuarantinedAppsScreenControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/quarantine/QuarantinedAppsScreenControllerTest.java @@ -20,6 +20,7 @@ import static org.mockito.AdditionalMatchers.aryEq; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -28,6 +29,7 @@ import static org.mockito.Mockito.verify; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.content.pm.SuspendDialogInfo; import android.os.UserHandle; import androidx.test.core.app.ApplicationProvider; @@ -70,12 +72,12 @@ public class QuarantinedAppsScreenControllerTest { mController.onPreferenceChange(preference, true); verify(packageManager).setPackagesSuspended(aryEq(new String[] {TEST_PACKAGE}), eq(true), - any(), any(), any(), + isNull(), isNull(), any(SuspendDialogInfo.class), eq(PackageManager.FLAG_SUSPEND_QUARANTINED)); mController.onPreferenceChange(preference, false); verify(packageManager).setPackagesSuspended(aryEq(new String[] {TEST_PACKAGE}), eq(false), - any(), any(), any(), + isNull(), isNull(), isNull(), eq(PackageManager.FLAG_SUSPEND_QUARANTINED)); }