OSDN Git Service

Tie FAS service-start to the same idleness state as O+ bg restrictions
authorChristopher Tate <ctate@google.com>
Wed, 25 Apr 2018 17:47:23 +0000 (10:47 -0700)
committerChristopher Tate <ctate@google.com>
Thu, 26 Apr 2018 00:14:13 +0000 (17:14 -0700)
Change-Id: I5b80519f7006fcee63644235d91435f0a591ea50
Fixes: 78322423
Test: ApiDemos outside FAS with startService() in Activity#onStop()
Test: ApiDemos in FAS service exercises (checking regressions)
Test: Maps navigation (checking regressions)

services/core/java/com/android/server/am/ActiveServices.java
services/core/java/com/android/server/am/ActivityManagerService.java

index 228171f..f413639 100644 (file)
@@ -422,13 +422,9 @@ public final class ActiveServices {
         }
 
         // If we're starting indirectly (e.g. from PendingIntent), figure out whether
-        // we're launching into an app in a background state.
-        final int uidState = mAm.getUidStateLocked(r.appInfo.uid);
-        if (DEBUG_SERVICE) {
-            Slog.v(TAG_SERVICE, "Uid state " + uidState + " indirect starting " + r.shortName);
-        }
-        final boolean bgLaunch = (uidState >
-                ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND);
+        // we're launching into an app in a background state.  This keys off of the same
+        // idleness state tracking as e.g. O+ background service start policy.
+        final boolean bgLaunch = !mAm.isUidActiveLocked(r.appInfo.uid);
 
         // If the app has strict background restrictions, we treat any bg service
         // start analogously to the legacy-app forced-restrictions case, regardless
@@ -1197,10 +1193,13 @@ public final class ActiveServices {
 
                 if (!ignoreForeground &&
                         appRestrictedAnyInBackground(r.appInfo.uid, r.packageName)) {
-                    ignoreForeground = true;
                     Slog.w(TAG,
                             "Service.startForeground() not allowed due to bg restriction: service "
                             + r.shortName);
+                    // Back off of any foreground expectations around this service, since we've
+                    // just turned down its fg request.
+                    updateServiceForegroundLocked(r.app, false);
+                    ignoreForeground = true;
                 }
 
                 // Apps under strict background restrictions simply don't get to have foreground
index ae26c23..5d34f80 100644 (file)
@@ -26625,8 +26625,7 @@ public class ActivityManagerService extends IActivityManager.Stub
         @Override
         public boolean isUidActive(int uid) {
             synchronized (ActivityManagerService.this) {
-                final UidRecord uidRec = mActiveUids.get(uid);
-                return (uidRec != null) && !uidRec.idle;
+                return isUidActiveLocked(uid);
             }
         }