From 43caafa2b6468c0852b753952d29a4949ee68e46 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Tue, 20 Sep 2016 16:06:22 -0700 Subject: [PATCH] Don't inform usage stats of interaction for a toast If the process is forced to the foreground due to a toast, don't inform usage stats of an interaction. Otherwise app standby will be defeated easily. Bug: 31544592 Test: cts-tradefed run commandAndExit cts -m CtsHostsideNetworkTests -t com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testAppIdle_toast Change-Id: I100d839ef8cf361704fd5db4b26dcc878672a235 --- .../java/com/android/server/am/ActivityManagerService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 91f493c98e2d2..7ca38609e29b8 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -20700,8 +20700,10 @@ public final class ActivityManagerService extends ActivityManagerNative isInteraction = nowElapsed > app.fgInteractionTime + SERVICE_USAGE_INTERACTION_TIME; } } else { - isInteraction = app.curProcState - <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND; + // If the app was being forced to the foreground, by say a Toast, then + // no need to treat it as an interaction + isInteraction = app.forcingToForeground == null + && app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND; app.fgInteractionTime = 0; } if (isInteraction && (!app.reportedInteraction