Merge "Fix FGS enter/exit statslog semantics" into sc-dev am: d3a0befee4 am: 587acbbc2f
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14823656 Change-Id: Ie3a0ec1e1fbfe09c45fe6770e81dd98083590283
This commit is contained in:
@@ -486,11 +486,11 @@ public abstract class ActivityManagerInternal {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback from the notification subsystem that the given FGS notification has
|
* Callback from the notification subsystem that the given FGS notification has
|
||||||
* been shown or updated. This can happen after either Service.startForeground()
|
* been evaluated, and either shown or explicitly overlooked. This can happen
|
||||||
* or NotificationManager.notify().
|
* after either Service.startForeground() or NotificationManager.notify().
|
||||||
*/
|
*/
|
||||||
public abstract void onForegroundServiceNotificationUpdate(Notification notification,
|
public abstract void onForegroundServiceNotificationUpdate(boolean shown,
|
||||||
int id, String pkg, @UserIdInt int userId);
|
Notification notification, int id, String pkg, @UserIdInt int userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the given app has any FGSs whose notifications are in the given channel,
|
* If the given app has any FGSs whose notifications are in the given channel,
|
||||||
|
|||||||
@@ -2221,8 +2221,9 @@ public final class ActiveServices {
|
|||||||
* visibility, starting with both Service.startForeground() and
|
* visibility, starting with both Service.startForeground() and
|
||||||
* NotificationManager.notify().
|
* NotificationManager.notify().
|
||||||
*/
|
*/
|
||||||
public void onForegroundServiceNotificationUpdateLocked(Notification notification,
|
public void onForegroundServiceNotificationUpdateLocked(boolean shown,
|
||||||
final int id, final String pkg, @UserIdInt final int userId) {
|
Notification notification, final int id, final String pkg,
|
||||||
|
@UserIdInt final int userId) {
|
||||||
// If this happens to be a Notification for an FGS still in its deferral period,
|
// If this happens to be a Notification for an FGS still in its deferral period,
|
||||||
// drop the deferral and make sure our content bookkeeping is up to date.
|
// drop the deferral and make sure our content bookkeeping is up to date.
|
||||||
for (int i = mPendingFgsNotifications.size() - 1; i >= 0; i--) {
|
for (int i = mPendingFgsNotifications.size() - 1; i >= 0; i--) {
|
||||||
@@ -2230,17 +2231,26 @@ public final class ActiveServices {
|
|||||||
if (userId == sr.userId
|
if (userId == sr.userId
|
||||||
&& id == sr.foregroundId
|
&& id == sr.foregroundId
|
||||||
&& sr.appInfo.packageName.equals(pkg)) {
|
&& sr.appInfo.packageName.equals(pkg)) {
|
||||||
if (DEBUG_FOREGROUND_SERVICE) {
|
// Found it. If 'shown' is false, it means that the notification
|
||||||
Slog.d(TAG_SERVICE, "Notification shown; canceling deferral of "
|
// subsystem will not be displaying it yet, so all we do is log
|
||||||
+ sr);
|
// the "fgs entered" transition noting deferral, then we're done.
|
||||||
}
|
|
||||||
maybeLogFGSStateEnteredLocked(sr);
|
maybeLogFGSStateEnteredLocked(sr);
|
||||||
sr.mFgsNotificationShown = true;
|
if (shown) {
|
||||||
sr.mFgsNotificationDeferred = false;
|
if (DEBUG_FOREGROUND_SERVICE) {
|
||||||
mPendingFgsNotifications.remove(i);
|
Slog.d(TAG_SERVICE, "Notification shown; canceling deferral of "
|
||||||
|
+ sr);
|
||||||
|
}
|
||||||
|
sr.mFgsNotificationShown = true;
|
||||||
|
sr.mFgsNotificationDeferred = false;
|
||||||
|
mPendingFgsNotifications.remove(i);
|
||||||
|
} else {
|
||||||
|
if (DEBUG_FOREGROUND_SERVICE) {
|
||||||
|
Slog.d(TAG_SERVICE, "FGS notification deferred for " + sr);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// And make sure to retain the latest notification content for the FGS
|
// In all cases, make sure to retain the latest notification content for the FGS
|
||||||
ServiceMap smap = mServiceMap.get(userId);
|
ServiceMap smap = mServiceMap.get(userId);
|
||||||
if (smap != null) {
|
if (smap != null) {
|
||||||
for (int i = 0; i < smap.mServicesByInstanceName.size(); i++) {
|
for (int i = 0; i < smap.mServicesByInstanceName.size(); i++) {
|
||||||
|
|||||||
@@ -350,8 +350,6 @@ import com.android.internal.util.Preconditions;
|
|||||||
import com.android.internal.util.function.DecFunction;
|
import com.android.internal.util.function.DecFunction;
|
||||||
import com.android.internal.util.function.HeptFunction;
|
import com.android.internal.util.function.HeptFunction;
|
||||||
import com.android.internal.util.function.HexFunction;
|
import com.android.internal.util.function.HexFunction;
|
||||||
import com.android.internal.util.function.NonaFunction;
|
|
||||||
import com.android.internal.util.function.OctFunction;
|
|
||||||
import com.android.internal.util.function.QuadFunction;
|
import com.android.internal.util.function.QuadFunction;
|
||||||
import com.android.internal.util.function.QuintFunction;
|
import com.android.internal.util.function.QuintFunction;
|
||||||
import com.android.internal.util.function.TriFunction;
|
import com.android.internal.util.function.TriFunction;
|
||||||
@@ -16093,11 +16091,11 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onForegroundServiceNotificationUpdate(Notification notification,
|
public void onForegroundServiceNotificationUpdate(boolean shown,
|
||||||
int id, String pkg, @UserIdInt int userId) {
|
Notification notification, int id, String pkg, @UserIdInt int userId) {
|
||||||
synchronized (ActivityManagerService.this) {
|
synchronized (ActivityManagerService.this) {
|
||||||
mServices.onForegroundServiceNotificationUpdateLocked(notification,
|
mServices.onForegroundServiceNotificationUpdateLocked(shown,
|
||||||
id, pkg, userId);
|
notification, id, pkg, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3052,17 +3052,19 @@ public class NotificationManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void maybeReportForegroundServiceUpdate(final NotificationRecord r) {
|
protected void reportForegroundServiceUpdate(boolean shown,
|
||||||
|
final Notification notification, final int id, final String pkg, final int userId) {
|
||||||
|
mHandler.post(() -> {
|
||||||
|
mAmi.onForegroundServiceNotificationUpdate(shown, notification, id, pkg, userId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void maybeReportForegroundServiceUpdate(final NotificationRecord r, boolean shown) {
|
||||||
if (r.isForegroundService()) {
|
if (r.isForegroundService()) {
|
||||||
// snapshot live state for the asynchronous operation
|
// snapshot live state for the asynchronous operation
|
||||||
final StatusBarNotification sbn = r.getSbn();
|
final StatusBarNotification sbn = r.getSbn();
|
||||||
final Notification notification = sbn.getNotification();
|
reportForegroundServiceUpdate(shown, sbn.getNotification(), sbn.getId(),
|
||||||
final int id = sbn.getId();
|
sbn.getPackageName(), sbn.getUser().getIdentifier());
|
||||||
final String pkg = sbn.getPackageName();
|
|
||||||
final int userId = sbn.getUser().getIdentifier();
|
|
||||||
mHandler.post(() -> {
|
|
||||||
mAmi.onForegroundServiceNotificationUpdate(notification, id, pkg, userId);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6194,6 +6196,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
// because the service lifecycle logic has retained responsibility for its
|
// because the service lifecycle logic has retained responsibility for its
|
||||||
// handling.
|
// handling.
|
||||||
if (!isNotificationShownInternal(pkg, tag, id, userId)) {
|
if (!isNotificationShownInternal(pkg, tag, id, userId)) {
|
||||||
|
reportForegroundServiceUpdate(false, notification, id, pkg, userId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7121,7 +7124,7 @@ public class NotificationManagerService extends SystemService {
|
|||||||
|
|
||||||
maybeRecordInterruptionLocked(r);
|
maybeRecordInterruptionLocked(r);
|
||||||
maybeRegisterMessageSent(r);
|
maybeRegisterMessageSent(r);
|
||||||
maybeReportForegroundServiceUpdate(r);
|
maybeReportForegroundServiceUpdate(r, true);
|
||||||
|
|
||||||
// Log event to statsd
|
// Log event to statsd
|
||||||
mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position,
|
mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position,
|
||||||
|
|||||||
Reference in New Issue
Block a user