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