Loading services/core/java/com/android/server/am/ActiveServices.java +15 −27 Original line number Diff line number Diff line Loading @@ -2156,9 +2156,7 @@ public final class ActiveServices { } } final boolean fgsTypeChangingFromShortFgs = r.isForeground && isOldTypeShortFgs; if (fgsTypeChangingFromShortFgs) { if (r.isForeground && isOldTypeShortFgs) { // If we get here, that means startForeground(SHORT_SERVICE) is called again // on a SHORT_SERVICE FGS. Loading Loading @@ -2211,9 +2209,7 @@ public final class ActiveServices { // "if (r.mAllowStartForeground == REASON_DENIED...)" block below. } } } if (!fgsTypeChangingFromShortFgs && r.mStartForegroundCount == 0) { } else if (r.mStartForegroundCount == 0) { /* If the service was started with startService(), not startForegroundService(), and if startForeground() isn't called within Loading Loading @@ -2244,7 +2240,7 @@ public final class ActiveServices { r.mLoggedInfoAllowStartForeground = false; } } } else if (!fgsTypeChangingFromShortFgs && r.mStartForegroundCount >= 1) { } else if (r.mStartForegroundCount >= 1) { // We get here if startForeground() is called multiple times // on the same service after it's created, regardless of whether // stopForeground() has been called or not. Loading Loading @@ -7436,14 +7432,10 @@ public final class ActiveServices { r.mAllowWhileInUsePermissionInFgs = true; } // Either (or both) mAllowWhileInUsePermissionInFgs or mAllowStartForeground is // newly allowed? boolean newlyAllowed = false; if (!r.mAllowWhileInUsePermissionInFgs || (r.mAllowStartForeground == REASON_DENIED)) { @ReasonCode final int allowWhileInUse = shouldAllowFgsWhileInUsePermissionLocked( callingPackage, callingPid, callingUid, r.app, backgroundStartPrivileges, isBindService); callingPackage, callingPid, callingUid, r.app, backgroundStartPrivileges); // We store them to compare the old and new while-in-use logics to each other. // (They're not used for any other purposes.) if (!r.mAllowWhileInUsePermissionInFgs) { Loading Loading @@ -7477,7 +7469,7 @@ public final class ActiveServices { } final @ReasonCode int allowWhileInUse = shouldAllowFgsWhileInUsePermissionLocked( callingPackage, callingPid, callingUid, null /* targetProcess */, BackgroundStartPrivileges.NONE, false); BackgroundStartPrivileges.NONE); @ReasonCode int allowStartFgs = shouldAllowFgsStartForegroundNoBindingCheckLocked( allowWhileInUse, callingPid, callingUid, callingPackage, null /* targetService */, BackgroundStartPrivileges.NONE); Loading @@ -7501,12 +7493,9 @@ public final class ActiveServices { */ private @ReasonCode int shouldAllowFgsWhileInUsePermissionLocked(String callingPackage, int callingPid, int callingUid, @Nullable ProcessRecord targetProcess, BackgroundStartPrivileges backgroundStartPrivileges, boolean isBindService) { BackgroundStartPrivileges backgroundStartPrivileges) { int ret = REASON_DENIED; final boolean forStartForeground = !isBindService; if (forStartForeground) { final int uidState = mAm.getUidStateLocked(callingUid); if (ret == REASON_DENIED) { // Allow FGS while-in-use if the caller's process state is PROCESS_STATE_PERSISTENT, Loading @@ -7515,7 +7504,6 @@ public final class ActiveServices { ret = getReasonCodeFromProcState(uidState); } } } if (ret == REASON_DENIED) { // Allow FGS while-in-use if the caller has visible activity. Loading Loading @@ -7734,7 +7722,7 @@ public final class ActiveServices { shouldAllowFgsWhileInUsePermissionLocked( clientPackageName, clientPid, clientUid, null /* targetProcess */, BackgroundStartPrivileges.NONE, false); BackgroundStartPrivileges.NONE); final @ReasonCode int allowStartFgs = shouldAllowFgsStartForegroundNoBindingCheckLocked( allowWhileInUse2, Loading Loading @@ -8163,7 +8151,7 @@ public final class ActiveServices { String callingPackage) { return shouldAllowFgsWhileInUsePermissionLocked(callingPackage, callingPid, callingUid, /* targetProcess */ null, BackgroundStartPrivileges.NONE, false) BackgroundStartPrivileges.NONE) != REASON_DENIED; } Loading @@ -8171,7 +8159,7 @@ public final class ActiveServices { String callingPackage, @Nullable ProcessRecord targetProcess, @NonNull BackgroundStartPrivileges backgroundStartPrivileges) { return shouldAllowFgsWhileInUsePermissionLocked(callingPackage, callingPid, callingUid, targetProcess, backgroundStartPrivileges, false) != REASON_DENIED; targetProcess, backgroundStartPrivileges) != REASON_DENIED; } /** Loading Loading
services/core/java/com/android/server/am/ActiveServices.java +15 −27 Original line number Diff line number Diff line Loading @@ -2156,9 +2156,7 @@ public final class ActiveServices { } } final boolean fgsTypeChangingFromShortFgs = r.isForeground && isOldTypeShortFgs; if (fgsTypeChangingFromShortFgs) { if (r.isForeground && isOldTypeShortFgs) { // If we get here, that means startForeground(SHORT_SERVICE) is called again // on a SHORT_SERVICE FGS. Loading Loading @@ -2211,9 +2209,7 @@ public final class ActiveServices { // "if (r.mAllowStartForeground == REASON_DENIED...)" block below. } } } if (!fgsTypeChangingFromShortFgs && r.mStartForegroundCount == 0) { } else if (r.mStartForegroundCount == 0) { /* If the service was started with startService(), not startForegroundService(), and if startForeground() isn't called within Loading Loading @@ -2244,7 +2240,7 @@ public final class ActiveServices { r.mLoggedInfoAllowStartForeground = false; } } } else if (!fgsTypeChangingFromShortFgs && r.mStartForegroundCount >= 1) { } else if (r.mStartForegroundCount >= 1) { // We get here if startForeground() is called multiple times // on the same service after it's created, regardless of whether // stopForeground() has been called or not. Loading Loading @@ -7436,14 +7432,10 @@ public final class ActiveServices { r.mAllowWhileInUsePermissionInFgs = true; } // Either (or both) mAllowWhileInUsePermissionInFgs or mAllowStartForeground is // newly allowed? boolean newlyAllowed = false; if (!r.mAllowWhileInUsePermissionInFgs || (r.mAllowStartForeground == REASON_DENIED)) { @ReasonCode final int allowWhileInUse = shouldAllowFgsWhileInUsePermissionLocked( callingPackage, callingPid, callingUid, r.app, backgroundStartPrivileges, isBindService); callingPackage, callingPid, callingUid, r.app, backgroundStartPrivileges); // We store them to compare the old and new while-in-use logics to each other. // (They're not used for any other purposes.) if (!r.mAllowWhileInUsePermissionInFgs) { Loading Loading @@ -7477,7 +7469,7 @@ public final class ActiveServices { } final @ReasonCode int allowWhileInUse = shouldAllowFgsWhileInUsePermissionLocked( callingPackage, callingPid, callingUid, null /* targetProcess */, BackgroundStartPrivileges.NONE, false); BackgroundStartPrivileges.NONE); @ReasonCode int allowStartFgs = shouldAllowFgsStartForegroundNoBindingCheckLocked( allowWhileInUse, callingPid, callingUid, callingPackage, null /* targetService */, BackgroundStartPrivileges.NONE); Loading @@ -7501,12 +7493,9 @@ public final class ActiveServices { */ private @ReasonCode int shouldAllowFgsWhileInUsePermissionLocked(String callingPackage, int callingPid, int callingUid, @Nullable ProcessRecord targetProcess, BackgroundStartPrivileges backgroundStartPrivileges, boolean isBindService) { BackgroundStartPrivileges backgroundStartPrivileges) { int ret = REASON_DENIED; final boolean forStartForeground = !isBindService; if (forStartForeground) { final int uidState = mAm.getUidStateLocked(callingUid); if (ret == REASON_DENIED) { // Allow FGS while-in-use if the caller's process state is PROCESS_STATE_PERSISTENT, Loading @@ -7515,7 +7504,6 @@ public final class ActiveServices { ret = getReasonCodeFromProcState(uidState); } } } if (ret == REASON_DENIED) { // Allow FGS while-in-use if the caller has visible activity. Loading Loading @@ -7734,7 +7722,7 @@ public final class ActiveServices { shouldAllowFgsWhileInUsePermissionLocked( clientPackageName, clientPid, clientUid, null /* targetProcess */, BackgroundStartPrivileges.NONE, false); BackgroundStartPrivileges.NONE); final @ReasonCode int allowStartFgs = shouldAllowFgsStartForegroundNoBindingCheckLocked( allowWhileInUse2, Loading Loading @@ -8163,7 +8151,7 @@ public final class ActiveServices { String callingPackage) { return shouldAllowFgsWhileInUsePermissionLocked(callingPackage, callingPid, callingUid, /* targetProcess */ null, BackgroundStartPrivileges.NONE, false) BackgroundStartPrivileges.NONE) != REASON_DENIED; } Loading @@ -8171,7 +8159,7 @@ public final class ActiveServices { String callingPackage, @Nullable ProcessRecord targetProcess, @NonNull BackgroundStartPrivileges backgroundStartPrivileges) { return shouldAllowFgsWhileInUsePermissionLocked(callingPackage, callingPid, callingUid, targetProcess, backgroundStartPrivileges, false) != REASON_DENIED; targetProcess, backgroundStartPrivileges) != REASON_DENIED; } /** Loading