Merge "Log FGS ENTER event synchronously." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9515d87dbb
@@ -1877,7 +1877,6 @@ public final class ActiveServices {
|
|||||||
active.mNumActive++;
|
active.mNumActive++;
|
||||||
}
|
}
|
||||||
r.isForeground = true;
|
r.isForeground = true;
|
||||||
r.mLogEntering = true;
|
|
||||||
// The logging of FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER event could
|
// The logging of FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER event could
|
||||||
// be deferred, make a copy of mAllowStartForeground and
|
// be deferred, make a copy of mAllowStartForeground and
|
||||||
// mAllowWhileInUsePermissionInFgs.
|
// mAllowWhileInUsePermissionInFgs.
|
||||||
@@ -1903,6 +1902,9 @@ public final class ActiveServices {
|
|||||||
AppOpsManager.ATTRIBUTION_CHAIN_ID_NONE);
|
AppOpsManager.ATTRIBUTION_CHAIN_ID_NONE);
|
||||||
registerAppOpCallbackLocked(r);
|
registerAppOpCallbackLocked(r);
|
||||||
mAm.updateForegroundServiceUsageStats(r.name, r.userId, true);
|
mAm.updateForegroundServiceUsageStats(r.name, r.userId, true);
|
||||||
|
logFGSStateChangeLocked(r,
|
||||||
|
FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
// Even if the service is already a FGS, we need to update the notification,
|
// Even if the service is already a FGS, we need to update the notification,
|
||||||
// so we need to call it again.
|
// so we need to call it again.
|
||||||
@@ -1958,6 +1960,7 @@ public final class ActiveServices {
|
|||||||
FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__EXIT,
|
FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__EXIT,
|
||||||
r.mFgsExitTime > r.mFgsEnterTime
|
r.mFgsExitTime > r.mFgsEnterTime
|
||||||
? (int)(r.mFgsExitTime - r.mFgsEnterTime) : 0);
|
? (int)(r.mFgsExitTime - r.mFgsEnterTime) : 0);
|
||||||
|
r.mFgsNotificationWasDeferred = false;
|
||||||
resetFgsRestrictionLocked(r);
|
resetFgsRestrictionLocked(r);
|
||||||
mAm.updateForegroundServiceUsageStats(r.name, r.userId, false);
|
mAm.updateForegroundServiceUsageStats(r.name, r.userId, false);
|
||||||
if (r.app != null) {
|
if (r.app != null) {
|
||||||
@@ -2162,6 +2165,7 @@ public final class ActiveServices {
|
|||||||
}
|
}
|
||||||
r.fgDisplayTime = when;
|
r.fgDisplayTime = when;
|
||||||
r.mFgsNotificationDeferred = true;
|
r.mFgsNotificationDeferred = true;
|
||||||
|
r.mFgsNotificationWasDeferred = true;
|
||||||
r.mFgsNotificationShown = false;
|
r.mFgsNotificationShown = false;
|
||||||
mPendingFgsNotifications.add(r);
|
mPendingFgsNotifications.add(r);
|
||||||
if (DEBUG_FOREGROUND_SERVICE) {
|
if (DEBUG_FOREGROUND_SERVICE) {
|
||||||
@@ -2205,11 +2209,6 @@ public final class ActiveServices {
|
|||||||
Slog.d(TAG_SERVICE, " - service no longer running/fg, ignoring");
|
Slog.d(TAG_SERVICE, " - service no longer running/fg, ignoring");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Regardless of whether we needed to post the notification or the
|
|
||||||
// service is no longer running, we may not have logged its FGS
|
|
||||||
// transition yet depending on the timing and API sequence that led
|
|
||||||
// to this point - so make sure to do so.
|
|
||||||
maybeLogFGSStateEnteredLocked(r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DEBUG_FOREGROUND_SERVICE) {
|
if (DEBUG_FOREGROUND_SERVICE) {
|
||||||
@@ -2252,16 +2251,6 @@ public final class ActiveServices {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeLogFGSStateEnteredLocked(ServiceRecord r) {
|
|
||||||
if (r.mLogEntering) {
|
|
||||||
logFGSStateChangeLocked(r,
|
|
||||||
FrameworkStatsLog
|
|
||||||
.FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER,
|
|
||||||
0);
|
|
||||||
r.mLogEntering = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback from NotificationManagerService whenever it posts a notification
|
* Callback from NotificationManagerService whenever it posts a notification
|
||||||
* associated with a foreground service. This is the unified handling point
|
* associated with a foreground service. This is the unified handling point
|
||||||
@@ -2280,9 +2269,7 @@ public final class ActiveServices {
|
|||||||
&& id == sr.foregroundId
|
&& id == sr.foregroundId
|
||||||
&& sr.appInfo.packageName.equals(pkg)) {
|
&& sr.appInfo.packageName.equals(pkg)) {
|
||||||
// Found it. If 'shown' is false, it means that the notification
|
// Found it. If 'shown' is false, it means that the notification
|
||||||
// subsystem will not be displaying it yet, so all we do is log
|
// subsystem will not be displaying it yet.
|
||||||
// the "fgs entered" transition noting deferral, then we're done.
|
|
||||||
maybeLogFGSStateEnteredLocked(sr);
|
|
||||||
if (shown) {
|
if (shown) {
|
||||||
if (DEBUG_FOREGROUND_SERVICE) {
|
if (DEBUG_FOREGROUND_SERVICE) {
|
||||||
Slog.d(TAG_SERVICE, "Notification shown; canceling deferral of "
|
Slog.d(TAG_SERVICE, "Notification shown; canceling deferral of "
|
||||||
@@ -4240,6 +4227,7 @@ public final class ActiveServices {
|
|||||||
r.isForeground = false;
|
r.isForeground = false;
|
||||||
r.foregroundId = 0;
|
r.foregroundId = 0;
|
||||||
r.foregroundNoti = null;
|
r.foregroundNoti = null;
|
||||||
|
r.mFgsNotificationWasDeferred = false;
|
||||||
resetFgsRestrictionLocked(r);
|
resetFgsRestrictionLocked(r);
|
||||||
|
|
||||||
// Clear start entries.
|
// Clear start entries.
|
||||||
@@ -6263,7 +6251,7 @@ public final class ActiveServices {
|
|||||||
? r.mRecentCallerApplicationInfo.targetSdkVersion : 0,
|
? r.mRecentCallerApplicationInfo.targetSdkVersion : 0,
|
||||||
r.mInfoTempFgsAllowListReason != null
|
r.mInfoTempFgsAllowListReason != null
|
||||||
? r.mInfoTempFgsAllowListReason.mCallingUid : INVALID_UID,
|
? r.mInfoTempFgsAllowListReason.mCallingUid : INVALID_UID,
|
||||||
r.mFgsNotificationDeferred,
|
r.mFgsNotificationWasDeferred,
|
||||||
r.mFgsNotificationShown,
|
r.mFgsNotificationShown,
|
||||||
durationMs,
|
durationMs,
|
||||||
r.mStartForegroundCount,
|
r.mStartForegroundCount,
|
||||||
|
|||||||
@@ -109,7 +109,6 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
|
|||||||
boolean fgWaiting; // is a timeout for going foreground already scheduled?
|
boolean fgWaiting; // is a timeout for going foreground already scheduled?
|
||||||
boolean isNotAppComponentUsage; // is service binding not considered component/package usage?
|
boolean isNotAppComponentUsage; // is service binding not considered component/package usage?
|
||||||
boolean isForeground; // is service currently in foreground mode?
|
boolean isForeground; // is service currently in foreground mode?
|
||||||
boolean mLogEntering; // need to report fgs transition once deferral policy is known
|
|
||||||
int foregroundId; // Notification ID of last foreground req.
|
int foregroundId; // Notification ID of last foreground req.
|
||||||
Notification foregroundNoti; // Notification record of foreground state.
|
Notification foregroundNoti; // Notification record of foreground state.
|
||||||
long fgDisplayTime; // time at which the FGS notification should become visible
|
long fgDisplayTime; // time at which the FGS notification should become visible
|
||||||
@@ -167,8 +166,10 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
|
|||||||
long mFgsEnterTime = 0;
|
long mFgsEnterTime = 0;
|
||||||
// The uptime when the service exits FGS state.
|
// The uptime when the service exits FGS state.
|
||||||
long mFgsExitTime = 0;
|
long mFgsExitTime = 0;
|
||||||
// FGS notification was deferred.
|
// FGS notification is deferred.
|
||||||
boolean mFgsNotificationDeferred;
|
boolean mFgsNotificationDeferred;
|
||||||
|
// FGS notification was deferred.
|
||||||
|
boolean mFgsNotificationWasDeferred;
|
||||||
// FGS notification was shown before the FGS finishes, or it wasn't deferred in the first place.
|
// FGS notification was shown before the FGS finishes, or it wasn't deferred in the first place.
|
||||||
boolean mFgsNotificationShown;
|
boolean mFgsNotificationShown;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user