Merge "Add a toggle on whether or not to prompt the user on long-running FGS" into tm-dev am: c772fd959c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18960077 Change-Id: I0df56e64f8e3bd575233ef4bc0ef4abd90b12eaf Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -1114,6 +1114,14 @@ public final class AppRestrictionController {
|
|||||||
static final String KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING =
|
static final String KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING =
|
||||||
DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "prompt_fgs_with_noti_on_long_running";
|
DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "prompt_fgs_with_noti_on_long_running";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The behavior for an app with a FGS, when the system detects it's running for
|
||||||
|
* a very long time, should we prompt the user.
|
||||||
|
* {@code true} - we'll show the prompt to user, {@code false} - we'll not show it.
|
||||||
|
*/
|
||||||
|
static final String KEY_BG_PROMPT_FGS_ON_LONG_RUNNING =
|
||||||
|
DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "prompt_fgs_on_long_running";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of packages to be exempted from all these background restrictions.
|
* The list of packages to be exempted from all these background restrictions.
|
||||||
*/
|
*/
|
||||||
@@ -1153,6 +1161,11 @@ public final class AppRestrictionController {
|
|||||||
*/
|
*/
|
||||||
static final boolean DEFAULT_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING = false;
|
static final boolean DEFAULT_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default value to {@link #mBgPromptFgsOnLongRunning}.
|
||||||
|
*/
|
||||||
|
static final boolean DEFAULT_BG_PROMPT_FGS_ON_LONG_RUNNING = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default value to {@link #mBgPromptFgsWithNotiToBgRestricted}.
|
* Default value to {@link #mBgPromptFgsWithNotiToBgRestricted}.
|
||||||
*/
|
*/
|
||||||
@@ -1190,6 +1203,11 @@ public final class AppRestrictionController {
|
|||||||
*/
|
*/
|
||||||
volatile boolean mBgPromptFgsWithNotiOnLongRunning;
|
volatile boolean mBgPromptFgsWithNotiOnLongRunning;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #KEY_BG_PROMPT_FGS_ON_LONG_RUNNING.
|
||||||
|
*/
|
||||||
|
volatile boolean mBgPromptFgsOnLongRunning;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED.
|
* @see #KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED.
|
||||||
*/
|
*/
|
||||||
@@ -1228,6 +1246,9 @@ public final class AppRestrictionController {
|
|||||||
case KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING:
|
case KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING:
|
||||||
updateBgPromptFgsWithNotiOnLongRunning();
|
updateBgPromptFgsWithNotiOnLongRunning();
|
||||||
break;
|
break;
|
||||||
|
case KEY_BG_PROMPT_FGS_ON_LONG_RUNNING:
|
||||||
|
updateBgPromptFgsOnLongRunning();
|
||||||
|
break;
|
||||||
case KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED:
|
case KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED:
|
||||||
updateBgPromptAbusiveAppToBgRestricted();
|
updateBgPromptAbusiveAppToBgRestricted();
|
||||||
break;
|
break;
|
||||||
@@ -1269,6 +1290,7 @@ public final class AppRestrictionController {
|
|||||||
updateBgLongFgsNotificationMinimalInterval();
|
updateBgLongFgsNotificationMinimalInterval();
|
||||||
updateBgPromptFgsWithNotiToBgRestricted();
|
updateBgPromptFgsWithNotiToBgRestricted();
|
||||||
updateBgPromptFgsWithNotiOnLongRunning();
|
updateBgPromptFgsWithNotiOnLongRunning();
|
||||||
|
updateBgPromptFgsOnLongRunning();
|
||||||
updateBgPromptAbusiveAppToBgRestricted();
|
updateBgPromptAbusiveAppToBgRestricted();
|
||||||
updateBgRestrictionExemptedPackages();
|
updateBgRestrictionExemptedPackages();
|
||||||
}
|
}
|
||||||
@@ -1319,6 +1341,13 @@ public final class AppRestrictionController {
|
|||||||
DEFAULT_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING);
|
DEFAULT_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateBgPromptFgsOnLongRunning() {
|
||||||
|
mBgPromptFgsOnLongRunning = DeviceConfig.getBoolean(
|
||||||
|
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||||
|
KEY_BG_PROMPT_FGS_ON_LONG_RUNNING,
|
||||||
|
DEFAULT_BG_PROMPT_FGS_ON_LONG_RUNNING);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateBgPromptAbusiveAppToBgRestricted() {
|
private void updateBgPromptAbusiveAppToBgRestricted() {
|
||||||
mBgPromptAbusiveAppsToBgRestricted = DeviceConfig.getBoolean(
|
mBgPromptAbusiveAppsToBgRestricted = DeviceConfig.getBoolean(
|
||||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||||
@@ -1365,6 +1394,14 @@ public final class AppRestrictionController {
|
|||||||
pw.print('=');
|
pw.print('=');
|
||||||
pw.println(mBgLongFgsNotificationMinIntervalMs);
|
pw.println(mBgLongFgsNotificationMinIntervalMs);
|
||||||
pw.print(prefix);
|
pw.print(prefix);
|
||||||
|
pw.print(KEY_BG_PROMPT_FGS_ON_LONG_RUNNING);
|
||||||
|
pw.print('=');
|
||||||
|
pw.println(mBgPromptFgsOnLongRunning);
|
||||||
|
pw.print(prefix);
|
||||||
|
pw.print(KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING);
|
||||||
|
pw.print('=');
|
||||||
|
pw.println(mBgPromptFgsWithNotiOnLongRunning);
|
||||||
|
pw.print(prefix);
|
||||||
pw.print(KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_TO_BG_RESTRICTED);
|
pw.print(KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_TO_BG_RESTRICTED);
|
||||||
pw.print('=');
|
pw.print('=');
|
||||||
pw.println(mBgPromptFgsWithNotiToBgRestricted);
|
pw.println(mBgPromptFgsWithNotiToBgRestricted);
|
||||||
@@ -2500,6 +2537,12 @@ public final class AppRestrictionController {
|
|||||||
ActivityManager.isLowRamDeviceStatic(),
|
ActivityManager.isLowRamDeviceStatic(),
|
||||||
mBgController.getRestrictionLevel(uid));
|
mBgController.getRestrictionLevel(uid));
|
||||||
PendingIntent pendingIntent;
|
PendingIntent pendingIntent;
|
||||||
|
if (!mBgController.mConstantsObserver.mBgPromptFgsOnLongRunning) {
|
||||||
|
if (DEBUG_BG_RESTRICTION_CONTROLLER) {
|
||||||
|
Slog.i(TAG, "Long-running FGS prompt is disabled.");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!mBgController.mConstantsObserver.mBgPromptFgsWithNotiOnLongRunning
|
if (!mBgController.mConstantsObserver.mBgPromptFgsWithNotiOnLongRunning
|
||||||
&& mBgController.hasForegroundServiceNotifications(packageName, uid)) {
|
&& mBgController.hasForegroundServiceNotifications(packageName, uid)) {
|
||||||
if (DEBUG_BG_RESTRICTION_CONTROLLER) {
|
if (DEBUG_BG_RESTRICTION_CONTROLLER) {
|
||||||
|
|||||||
@@ -1141,6 +1141,7 @@ public final class BackgroundRestrictionTest {
|
|||||||
DeviceConfigSession<Long> longRunningFGSWindow = null;
|
DeviceConfigSession<Long> longRunningFGSWindow = null;
|
||||||
DeviceConfigSession<Long> longRunningFGSThreshold = null;
|
DeviceConfigSession<Long> longRunningFGSThreshold = null;
|
||||||
DeviceConfigSession<Boolean> longRunningFGSWithNotification = null;
|
DeviceConfigSession<Boolean> longRunningFGSWithNotification = null;
|
||||||
|
DeviceConfigSession<Boolean> longRunningFGS = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
longRunningFGSMonitor = new DeviceConfigSession<>(
|
longRunningFGSMonitor = new DeviceConfigSession<>(
|
||||||
@@ -1171,6 +1172,13 @@ public final class BackgroundRestrictionTest {
|
|||||||
ConstantsObserver.DEFAULT_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING);
|
ConstantsObserver.DEFAULT_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING);
|
||||||
longRunningFGSWithNotification.set(true);
|
longRunningFGSWithNotification.set(true);
|
||||||
|
|
||||||
|
longRunningFGS = new DeviceConfigSession<>(
|
||||||
|
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||||
|
ConstantsObserver.KEY_BG_PROMPT_FGS_ON_LONG_RUNNING,
|
||||||
|
DeviceConfig::getBoolean,
|
||||||
|
ConstantsObserver.DEFAULT_BG_PROMPT_FGS_ON_LONG_RUNNING);
|
||||||
|
longRunningFGS.set(true);
|
||||||
|
|
||||||
// Basic case
|
// Basic case
|
||||||
mAppFGSTracker.onForegroundServiceStateChanged(testPkgName1, testUid1,
|
mAppFGSTracker.onForegroundServiceStateChanged(testPkgName1, testUid1,
|
||||||
testPid1, true);
|
testPid1, true);
|
||||||
@@ -1214,6 +1222,23 @@ public final class BackgroundRestrictionTest {
|
|||||||
testPid2, false);
|
testPid2, false);
|
||||||
checkNotificationGone(testPkgName2, timeout(windowMs), notificationId);
|
checkNotificationGone(testPkgName2, timeout(windowMs), notificationId);
|
||||||
|
|
||||||
|
// Turn OFF the notification.
|
||||||
|
longRunningFGS.set(false);
|
||||||
|
clearInvocations(mInjector.getNotificationManager());
|
||||||
|
mBgRestrictionController.resetRestrictionSettings();
|
||||||
|
// Start the FGS again.
|
||||||
|
mAppFGSTracker.onForegroundServiceStateChanged(testPkgName2, testUid2,
|
||||||
|
testPid2, true);
|
||||||
|
// Verify we do NOT have the notification.
|
||||||
|
checkNotificationShown(
|
||||||
|
new String[] {testPkgName2}, timeout(windowMs * 2).times(0), false);
|
||||||
|
// Stop this FGS
|
||||||
|
mAppFGSTracker.onForegroundServiceStateChanged(testPkgName2, testUid2,
|
||||||
|
testPid2, false);
|
||||||
|
|
||||||
|
// Turn it back ON.
|
||||||
|
longRunningFGS.set(true);
|
||||||
|
|
||||||
// Start over with concurrent cases.
|
// Start over with concurrent cases.
|
||||||
clearInvocations(mInjector.getNotificationManager());
|
clearInvocations(mInjector.getNotificationManager());
|
||||||
mBgRestrictionController.resetRestrictionSettings();
|
mBgRestrictionController.resetRestrictionSettings();
|
||||||
@@ -1306,6 +1331,7 @@ public final class BackgroundRestrictionTest {
|
|||||||
closeIfNotNull(longRunningFGSWindow);
|
closeIfNotNull(longRunningFGSWindow);
|
||||||
closeIfNotNull(longRunningFGSThreshold);
|
closeIfNotNull(longRunningFGSThreshold);
|
||||||
closeIfNotNull(longRunningFGSWithNotification);
|
closeIfNotNull(longRunningFGSWithNotification);
|
||||||
|
closeIfNotNull(longRunningFGS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1332,6 +1358,7 @@ public final class BackgroundRestrictionTest {
|
|||||||
DeviceConfigSession<Long> mediaPlaybackFGSThreshold = null;
|
DeviceConfigSession<Long> mediaPlaybackFGSThreshold = null;
|
||||||
DeviceConfigSession<Long> locationFGSThreshold = null;
|
DeviceConfigSession<Long> locationFGSThreshold = null;
|
||||||
DeviceConfigSession<Boolean> longRunningFGSWithNotification = null;
|
DeviceConfigSession<Boolean> longRunningFGSWithNotification = null;
|
||||||
|
DeviceConfigSession<Boolean> longRunningFGS = null;
|
||||||
|
|
||||||
doReturn(testPkgName1).when(mInjector).getPackageName(testPid1);
|
doReturn(testPkgName1).when(mInjector).getPackageName(testPid1);
|
||||||
doReturn(testPkgName2).when(mInjector).getPackageName(testPid2);
|
doReturn(testPkgName2).when(mInjector).getPackageName(testPid2);
|
||||||
@@ -1379,6 +1406,13 @@ public final class BackgroundRestrictionTest {
|
|||||||
ConstantsObserver.DEFAULT_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING);
|
ConstantsObserver.DEFAULT_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING);
|
||||||
longRunningFGSWithNotification.set(true);
|
longRunningFGSWithNotification.set(true);
|
||||||
|
|
||||||
|
longRunningFGS = new DeviceConfigSession<>(
|
||||||
|
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||||
|
ConstantsObserver.KEY_BG_PROMPT_FGS_ON_LONG_RUNNING,
|
||||||
|
DeviceConfig::getBoolean,
|
||||||
|
ConstantsObserver.DEFAULT_BG_PROMPT_FGS_ON_LONG_RUNNING);
|
||||||
|
longRunningFGS.set(true);
|
||||||
|
|
||||||
// Long-running FGS with type "location", but ran for a very short time.
|
// Long-running FGS with type "location", but ran for a very short time.
|
||||||
runTestLongFGSExemptionOnce(testPkgName1, testUid1, testPid1,
|
runTestLongFGSExemptionOnce(testPkgName1, testUid1, testPid1,
|
||||||
FOREGROUND_SERVICE_TYPE_LOCATION, 0, null, OP_NONE, null, null,
|
FOREGROUND_SERVICE_TYPE_LOCATION, 0, null, OP_NONE, null, null,
|
||||||
@@ -1487,6 +1521,7 @@ public final class BackgroundRestrictionTest {
|
|||||||
closeIfNotNull(mediaPlaybackFGSThreshold);
|
closeIfNotNull(mediaPlaybackFGSThreshold);
|
||||||
closeIfNotNull(locationFGSThreshold);
|
closeIfNotNull(locationFGSThreshold);
|
||||||
closeIfNotNull(longRunningFGSWithNotification);
|
closeIfNotNull(longRunningFGSWithNotification);
|
||||||
|
closeIfNotNull(longRunningFGS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user