}
// 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
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