Merge "Follow-up to Ifb322f9603aad841b4947038574d5d1a42d3dc10" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
100eaf664f
@@ -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.
|
||||
@@ -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
|
||||
@@ -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.
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
@@ -7501,19 +7493,15 @@ 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,
|
||||
// PROCESS_STATE_PERSISTENT_UI or PROCESS_STATE_TOP.
|
||||
if (uidState <= PROCESS_STATE_TOP) {
|
||||
ret = getReasonCodeFromProcState(uidState);
|
||||
}
|
||||
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,
|
||||
// PROCESS_STATE_PERSISTENT_UI or PROCESS_STATE_TOP.
|
||||
if (uidState <= PROCESS_STATE_TOP) {
|
||||
ret = getReasonCodeFromProcState(uidState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
@@ -8163,7 +8151,7 @@ public final class ActiveServices {
|
||||
String callingPackage) {
|
||||
return shouldAllowFgsWhileInUsePermissionLocked(callingPackage, callingPid, callingUid,
|
||||
/* targetProcess */ null,
|
||||
BackgroundStartPrivileges.NONE, false)
|
||||
BackgroundStartPrivileges.NONE)
|
||||
!= REASON_DENIED;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user