Merge "Improve the while-in-use logic change detection logic" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
188de4320d
@@ -2214,6 +2214,8 @@ public final class ActiveServices {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean resetNeededForLogging = false;
|
||||||
|
|
||||||
// Re-evaluate mAllowWhileInUsePermissionInFgs and mAllowStartForeground
|
// Re-evaluate mAllowWhileInUsePermissionInFgs and mAllowStartForeground
|
||||||
// (i.e. while-in-use and BFSL flags) if needed.
|
// (i.e. while-in-use and BFSL flags) if needed.
|
||||||
//
|
//
|
||||||
@@ -2296,8 +2298,22 @@ public final class ActiveServices {
|
|||||||
!r.isForeground
|
!r.isForeground
|
||||||
&& delayMs > mAm.mConstants.mFgsStartForegroundTimeoutMs;
|
&& delayMs > mAm.mConstants.mFgsStartForegroundTimeoutMs;
|
||||||
if (resetNeeded) {
|
if (resetNeeded) {
|
||||||
resetFgsRestrictionLocked(r);
|
// We don't want to reset mDebugWhileInUseReasonInBindService here --
|
||||||
|
// we'll instead reset it in the following code, using the simulated
|
||||||
|
// legacy logic.
|
||||||
|
resetFgsRestrictionLocked(r,
|
||||||
|
/*resetDebugWhileInUseReasonInBindService=*/ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Simulate the reset flow in the legacy logic to reset
|
||||||
|
// mDebugWhileInUseReasonInBindService.
|
||||||
|
// (Which is only used to compare to the old logic.)
|
||||||
|
final long legacyDelayMs = SystemClock.elapsedRealtime() - r.createRealTime;
|
||||||
|
if ((r.mStartForegroundCount == 0)
|
||||||
|
&& (legacyDelayMs > mAm.mConstants.mFgsStartForegroundTimeoutMs)) {
|
||||||
|
r.mDebugWhileInUseReasonInBindService = REASON_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
setFgsRestrictionLocked(r.serviceInfo.packageName, r.app.getPid(),
|
setFgsRestrictionLocked(r.serviceInfo.packageName, r.app.getPid(),
|
||||||
r.appInfo.uid, r.intent.getIntent(), r, r.userId,
|
r.appInfo.uid, r.intent.getIntent(), r, r.userId,
|
||||||
BackgroundStartPrivileges.NONE,
|
BackgroundStartPrivileges.NONE,
|
||||||
@@ -2314,12 +2330,24 @@ public final class ActiveServices {
|
|||||||
r.mInfoAllowStartForeground = temp;
|
r.mInfoAllowStartForeground = temp;
|
||||||
}
|
}
|
||||||
r.mLoggedInfoAllowStartForeground = false;
|
r.mLoggedInfoAllowStartForeground = false;
|
||||||
|
|
||||||
|
resetNeededForLogging = resetNeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the service has any bindings and it's not yet a FGS
|
// If the service has any bindings and it's not yet a FGS
|
||||||
// we compare the new and old while-in-use logics.
|
// we compare the new and old while-in-use logics.
|
||||||
// (If it's not the first startForeground() call, we already reset the
|
// (If it's not the first startForeground() call, we already reset the
|
||||||
// while-in-use and BFSL flags, so the logic change wouldn't matter.)
|
// while-in-use and BFSL flags, so the logic change wouldn't matter.)
|
||||||
|
//
|
||||||
|
// Note, mDebugWhileInUseReasonInBindService does *not* fully simulate the
|
||||||
|
// legacy logic, because we'll only set it in bindService(), but the actual
|
||||||
|
// mAllowWhileInUsePermissionInFgsReason can change afterwards, in a subsequent
|
||||||
|
// Service.startForeground(). This check will only provide "rough" check.
|
||||||
|
// But if mDebugWhileInUseReasonInBindService is _not_ DENIED, and
|
||||||
|
// mDebugWhileInUseReasonInStartForeground _is_ DENIED, then that means we'd
|
||||||
|
// now detected a behavior change.
|
||||||
|
// OTOH, if it's changing from non-DENIED to another non-DENIED, that may
|
||||||
|
// not be a problem.
|
||||||
if (enableFgsWhileInUseFix
|
if (enableFgsWhileInUseFix
|
||||||
&& !r.isForeground
|
&& !r.isForeground
|
||||||
&& (r.getConnections().size() > 0)
|
&& (r.getConnections().size() > 0)
|
||||||
@@ -2329,6 +2357,10 @@ public final class ActiveServices {
|
|||||||
+ reasonCodeToString(r.mDebugWhileInUseReasonInBindService)
|
+ reasonCodeToString(r.mDebugWhileInUseReasonInBindService)
|
||||||
+ " new="
|
+ " new="
|
||||||
+ reasonCodeToString(r.mDebugWhileInUseReasonInStartForeground)
|
+ reasonCodeToString(r.mDebugWhileInUseReasonInStartForeground)
|
||||||
|
+ " startForegroundCount=" + r.mStartForegroundCount
|
||||||
|
+ " started=" + r.startRequested
|
||||||
|
+ " num_bindings=" + r.getConnections().size()
|
||||||
|
+ " resetNeeded=" + resetNeededForLogging
|
||||||
+ " "
|
+ " "
|
||||||
+ r.shortInstanceName);
|
+ r.shortInstanceName);
|
||||||
}
|
}
|
||||||
@@ -7574,15 +7606,27 @@ public final class ActiveServices {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset various while-in-use and BFSL related information.
|
||||||
|
*/
|
||||||
void resetFgsRestrictionLocked(ServiceRecord r) {
|
void resetFgsRestrictionLocked(ServiceRecord r) {
|
||||||
|
resetFgsRestrictionLocked(r, /*resetDebugWhileInUseReasonInBindService=*/ true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset various while-in-use and BFSL related information.
|
||||||
|
*/
|
||||||
|
void resetFgsRestrictionLocked(ServiceRecord r,
|
||||||
|
boolean resetDebugWhileInUseReasonInBindService) {
|
||||||
r.mAllowWhileInUsePermissionInFgs = false;
|
r.mAllowWhileInUsePermissionInFgs = false;
|
||||||
r.mAllowWhileInUsePermissionInFgsReason = REASON_DENIED;
|
r.mAllowWhileInUsePermissionInFgsReason = REASON_DENIED;
|
||||||
r.mDebugWhileInUseReasonInStartForeground = REASON_DENIED;
|
r.mDebugWhileInUseReasonInStartForeground = REASON_DENIED;
|
||||||
// We don't reset mWhileInUseReasonInBindService here, because if we do this, we would
|
|
||||||
// lose it in the "reevaluation" case in startForeground(), where we call
|
// In Service.startForeground(), we reset this field using a legacy logic,
|
||||||
// resetFgsRestrictionLocked().
|
// so resetting this field is optional.
|
||||||
// Not resetting this is fine because it's only used in the first Service.startForeground()
|
if (resetDebugWhileInUseReasonInBindService) {
|
||||||
// case, and there's no situations where we call resetFgsRestrictionLocked() before that.
|
r.mDebugWhileInUseReasonInBindService = REASON_DENIED;
|
||||||
|
}
|
||||||
r.mAllowStartForeground = REASON_DENIED;
|
r.mAllowStartForeground = REASON_DENIED;
|
||||||
r.mInfoAllowStartForeground = null;
|
r.mInfoAllowStartForeground = null;
|
||||||
r.mInfoTempFgsAllowListReason = null;
|
r.mInfoTempFgsAllowListReason = null;
|
||||||
|
|||||||
@@ -622,12 +622,13 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
|
|||||||
pw.println(mBackgroundStartPrivilegesByStartMerged);
|
pw.println(mBackgroundStartPrivilegesByStartMerged);
|
||||||
}
|
}
|
||||||
pw.print(prefix); pw.print("mAllowWhileInUsePermissionInFgsReason=");
|
pw.print(prefix); pw.print("mAllowWhileInUsePermissionInFgsReason=");
|
||||||
pw.println(mAllowWhileInUsePermissionInFgsReason);
|
pw.println(PowerExemptionManager.reasonCodeToString(mAllowWhileInUsePermissionInFgsReason));
|
||||||
|
|
||||||
pw.print(prefix); pw.print("debugWhileInUseReasonInStartForeground=");
|
pw.print(prefix); pw.print("debugWhileInUseReasonInStartForeground=");
|
||||||
pw.println(mDebugWhileInUseReasonInStartForeground);
|
pw.println(PowerExemptionManager.reasonCodeToString(
|
||||||
|
mDebugWhileInUseReasonInStartForeground));
|
||||||
pw.print(prefix); pw.print("debugWhileInUseReasonInBindService=");
|
pw.print(prefix); pw.print("debugWhileInUseReasonInBindService=");
|
||||||
pw.println(mDebugWhileInUseReasonInBindService);
|
pw.println(PowerExemptionManager.reasonCodeToString(mDebugWhileInUseReasonInBindService));
|
||||||
|
|
||||||
pw.print(prefix); pw.print("allowUiJobScheduling="); pw.println(mAllowUiJobScheduling);
|
pw.print(prefix); pw.print("allowUiJobScheduling="); pw.println(mAllowUiJobScheduling);
|
||||||
pw.print(prefix); pw.print("recentCallingPackage=");
|
pw.print(prefix); pw.print("recentCallingPackage=");
|
||||||
|
|||||||
Reference in New Issue
Block a user