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
This commit is contained in:
Sudheer Shanka
2023-09-28 14:48:15 +00:00
parent 6bf04986ac
commit b5441bf782
3 changed files with 17 additions and 3 deletions

View File

@@ -12458,4 +12458,6 @@
<!-- Developer settings: Title for the screen allowing user to control Quarantined apps [CHAR LIMIT=50] --> <!-- Developer settings: Title for the screen allowing user to control Quarantined apps [CHAR LIMIT=50] -->
<string name="quarantined_apps_title">Quarantined Apps</string> <string name="quarantined_apps_title">Quarantined Apps</string>
<!-- Developer settings: Button to unquarantine an app [CHAR LIMIT=20] -->
<string name="unquarantine_app_button">Unquarantine app</string>
</resources> </resources>

View File

@@ -19,6 +19,7 @@ package com.android.settings.development.quarantine;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.SuspendDialogInfo;
import android.os.UserHandle; import android.os.UserHandle;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
@@ -181,8 +182,17 @@ public class QuarantinedAppsScreenController extends BasePreferenceController im
private void setPackageQuarantined(String pkg, int uid, boolean quarantined) { private void setPackageQuarantined(String pkg, int uid, boolean quarantined) {
final PackageManager pm = mContext.createContextAsUser( final PackageManager pm = mContext.createContextAsUser(
UserHandle.getUserHandleForUid(uid), 0).getPackageManager(); 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 */, pm.setPackagesSuspended(new String[] {pkg}, quarantined, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, null /* launcherExtras */, dialogInfo,
PackageManager.FLAG_SUSPEND_QUARANTINED); PackageManager.FLAG_SUSPEND_QUARANTINED);
} }

View File

@@ -20,6 +20,7 @@ import static org.mockito.AdditionalMatchers.aryEq;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@@ -28,6 +29,7 @@ import static org.mockito.Mockito.verify;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.SuspendDialogInfo;
import android.os.UserHandle; import android.os.UserHandle;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -70,12 +72,12 @@ public class QuarantinedAppsScreenControllerTest {
mController.onPreferenceChange(preference, true); mController.onPreferenceChange(preference, true);
verify(packageManager).setPackagesSuspended(aryEq(new String[] {TEST_PACKAGE}), eq(true), verify(packageManager).setPackagesSuspended(aryEq(new String[] {TEST_PACKAGE}), eq(true),
any(), any(), any(), isNull(), isNull(), any(SuspendDialogInfo.class),
eq(PackageManager.FLAG_SUSPEND_QUARANTINED)); eq(PackageManager.FLAG_SUSPEND_QUARANTINED));
mController.onPreferenceChange(preference, false); mController.onPreferenceChange(preference, false);
verify(packageManager).setPackagesSuspended(aryEq(new String[] {TEST_PACKAGE}), eq(false), verify(packageManager).setPackagesSuspended(aryEq(new String[] {TEST_PACKAGE}), eq(false),
any(), any(), any(), isNull(), isNull(), isNull(),
eq(PackageManager.FLAG_SUSPEND_QUARANTINED)); eq(PackageManager.FLAG_SUSPEND_QUARANTINED));
} }