Loading services/core/java/com/android/server/am/ActiveServices.java +50 −26 Original line number Diff line number Diff line Loading @@ -2059,6 +2059,9 @@ public final class ActiveServices { foregroundServiceType == FOREGROUND_SERVICE_TYPE_SHORT_SERVICE; final boolean isOldTypeShortFgsAndTimedOut = r.shouldTriggerShortFgsTimeout(); // If true, we skip the BFSL check. boolean bypassBfslCheck = false; if (r.isForeground && (isOldTypeShortFgs || isNewTypeShortFgs)) { if (DEBUG_SHORT_SERVICE) { Slog.i(TAG_SERVICE, String.format( Loading Loading @@ -2089,19 +2092,28 @@ public final class ActiveServices { if (isNewTypeShortFgs) { // Only in this case, we extend the SHORT_SERVICE time out. extendShortServiceTimeout = true; if (DEBUG_SHORT_SERVICE) { Slog.i(TAG_SERVICE, "Extending SHORT_SERVICE time out: " + r); } } else { // FGS type is changing from SHORT_SERVICE to another type when // an app is allowed to start FGS, so this will succeed. // The timeout will stop later, in // maybeUpdateShortFgsTrackingLocked(). } } else { if (isNewTypeShortFgs) { // startForeground(SHORT_SERVICE) is called on an already running // SHORT_SERVICE FGS, when BFSL is not allowed. // In this case, the call should succeed // (== ForegroundServiceStartNotAllowedException shouldn't be // thrown), but the short service timeout shouldn't extend // (== extendShortServiceTimeout should be false). // We still do everything else -- e.g. we still need to update // the notification. bypassBfslCheck = true; } else { // We catch this case later, in the // "if (r.mAllowStartForeground == REASON_DENIED...)" block below. } } } else if (r.mStartForegroundCount == 0) { /* Loading Loading @@ -2155,6 +2167,7 @@ public final class ActiveServices { + "location/camera/microphone access: service " + r.shortInstanceName); } if (!bypassBfslCheck) { logFgsBackgroundStart(r); if (r.mAllowStartForeground == REASON_DENIED && isBgFgsRestrictionEnabledForService) { Loading @@ -2174,6 +2187,7 @@ public final class ActiveServices { throw new ForegroundServiceStartNotAllowedException(msg); } } } if (!ignoreForeground) { Pair<Integer, RuntimeException> fgsTypeResult = null; Loading Loading @@ -3114,11 +3128,17 @@ public final class ActiveServices { unscheduleShortFgsTimeoutLocked(sr); return; } final boolean isAlreadyShortFgs = sr.hasShortFgsInfo(); if (extendTimeout || !isAlreadyShortFgs) { if (DEBUG_SHORT_SERVICE) { if (isAlreadyShortFgs) { Slog.i(TAG_SERVICE, "Extending SHORT_SERVICE time out: " + sr); } else { Slog.i(TAG_SERVICE, "Short FGS started: " + sr); } if (extendTimeout || !sr.hasShortFgsInfo()) { } sr.setShortFgsInfo(SystemClock.uptimeMillis()); // We'll restart the timeout. Loading @@ -3128,6 +3148,10 @@ public final class ActiveServices { ActivityManagerService.SERVICE_SHORT_FGS_TIMEOUT_MSG, sr); mAm.mHandler.sendMessageAtTime(msg, sr.getShortFgsInfo().getTimeoutTime()); } else { if (DEBUG_SHORT_SERVICE) { Slog.w(TAG_SERVICE, "NOT extending SHORT_SERVICE time out: " + sr); } // We only (potentially) update the start command, start count, but not the timeout // time. // In this case, we keep the existing timeout running. Loading Loading
services/core/java/com/android/server/am/ActiveServices.java +50 −26 Original line number Diff line number Diff line Loading @@ -2059,6 +2059,9 @@ public final class ActiveServices { foregroundServiceType == FOREGROUND_SERVICE_TYPE_SHORT_SERVICE; final boolean isOldTypeShortFgsAndTimedOut = r.shouldTriggerShortFgsTimeout(); // If true, we skip the BFSL check. boolean bypassBfslCheck = false; if (r.isForeground && (isOldTypeShortFgs || isNewTypeShortFgs)) { if (DEBUG_SHORT_SERVICE) { Slog.i(TAG_SERVICE, String.format( Loading Loading @@ -2089,19 +2092,28 @@ public final class ActiveServices { if (isNewTypeShortFgs) { // Only in this case, we extend the SHORT_SERVICE time out. extendShortServiceTimeout = true; if (DEBUG_SHORT_SERVICE) { Slog.i(TAG_SERVICE, "Extending SHORT_SERVICE time out: " + r); } } else { // FGS type is changing from SHORT_SERVICE to another type when // an app is allowed to start FGS, so this will succeed. // The timeout will stop later, in // maybeUpdateShortFgsTrackingLocked(). } } else { if (isNewTypeShortFgs) { // startForeground(SHORT_SERVICE) is called on an already running // SHORT_SERVICE FGS, when BFSL is not allowed. // In this case, the call should succeed // (== ForegroundServiceStartNotAllowedException shouldn't be // thrown), but the short service timeout shouldn't extend // (== extendShortServiceTimeout should be false). // We still do everything else -- e.g. we still need to update // the notification. bypassBfslCheck = true; } else { // We catch this case later, in the // "if (r.mAllowStartForeground == REASON_DENIED...)" block below. } } } else if (r.mStartForegroundCount == 0) { /* Loading Loading @@ -2155,6 +2167,7 @@ public final class ActiveServices { + "location/camera/microphone access: service " + r.shortInstanceName); } if (!bypassBfslCheck) { logFgsBackgroundStart(r); if (r.mAllowStartForeground == REASON_DENIED && isBgFgsRestrictionEnabledForService) { Loading @@ -2174,6 +2187,7 @@ public final class ActiveServices { throw new ForegroundServiceStartNotAllowedException(msg); } } } if (!ignoreForeground) { Pair<Integer, RuntimeException> fgsTypeResult = null; Loading Loading @@ -3114,11 +3128,17 @@ public final class ActiveServices { unscheduleShortFgsTimeoutLocked(sr); return; } final boolean isAlreadyShortFgs = sr.hasShortFgsInfo(); if (extendTimeout || !isAlreadyShortFgs) { if (DEBUG_SHORT_SERVICE) { if (isAlreadyShortFgs) { Slog.i(TAG_SERVICE, "Extending SHORT_SERVICE time out: " + sr); } else { Slog.i(TAG_SERVICE, "Short FGS started: " + sr); } if (extendTimeout || !sr.hasShortFgsInfo()) { } sr.setShortFgsInfo(SystemClock.uptimeMillis()); // We'll restart the timeout. Loading @@ -3128,6 +3148,10 @@ public final class ActiveServices { ActivityManagerService.SERVICE_SHORT_FGS_TIMEOUT_MSG, sr); mAm.mHandler.sendMessageAtTime(msg, sr.getShortFgsInfo().getTimeoutTime()); } else { if (DEBUG_SHORT_SERVICE) { Slog.w(TAG_SERVICE, "NOT extending SHORT_SERVICE time out: " + sr); } // We only (potentially) update the start command, start count, but not the timeout // time. // In this case, we keep the existing timeout running. Loading