From 504b019c04a3aa6c1319dcaab20576fe832faf6b Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Fri, 3 Mar 2023 15:59:16 -0800 Subject: [PATCH] A few changes around SHORT_SERVICE - Add the FGS type to the ServiceRecord proto - Add some logging Test: atest CtsShortFgsTestCases Bug: 260748204 Change-Id: I8cb94a65180f825cd677486a7fd6158b8951c57a --- .../proto/android/server/activitymanagerservice.proto | 1 + .../java/com/android/server/am/ActiveServices.java | 11 +++++++++++ .../java/com/android/server/am/ServiceRecord.java | 2 ++ 3 files changed, 14 insertions(+) diff --git a/core/proto/android/server/activitymanagerservice.proto b/core/proto/android/server/activitymanagerservice.proto index ab7b0ab8d1fc7..c6fe18a90d517 100644 --- a/core/proto/android/server/activitymanagerservice.proto +++ b/core/proto/android/server/activitymanagerservice.proto @@ -439,6 +439,7 @@ message ServiceRecordProto { optional int32 id = 1; optional .android.app.NotificationProto notification = 2; + optional int32 foregroundServiceType = 3; } optional Foreground foreground = 13; diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index f90a3ce76e71a..24c9e0f55ab9d 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -2092,6 +2092,17 @@ public final class ActiveServices { r.appInfo.uid, r.intent.getIntent(), r, r.userId, BackgroundStartPrivileges.NONE, false /* isBindService */); + if (r.mAllowStartForeground == REASON_DENIED) { + Slog.w(TAG_SERVICE, "FGS type change to/from SHORT_SERVICE: " + + " BFSL DENIED."); + } else { + if (DEBUG_SHORT_SERVICE) { + Slog.w(TAG_SERVICE, "FGS type change to/from SHORT_SERVICE: " + + " BFSL Allowed: " + + PowerExemptionManager.reasonCodeToString( + r.mAllowStartForeground)); + } + } final boolean fgsStartAllowed = !isBgFgsRestrictionEnabledForService diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java index ae8ceab628964..61801177ffba7 100644 --- a/services/core/java/com/android/server/am/ServiceRecord.java +++ b/services/core/java/com/android/server/am/ServiceRecord.java @@ -468,6 +468,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN long fgToken = proto.start(ServiceRecordProto.FOREGROUND); proto.write(ServiceRecordProto.Foreground.ID, foregroundId); foregroundNoti.dumpDebug(proto, ServiceRecordProto.Foreground.NOTIFICATION); + proto.write(ServiceRecordProto.Foreground.FOREGROUND_SERVICE_TYPE, + foregroundServiceType); proto.end(fgToken); } ProtoUtils.toDuration(proto, ServiceRecordProto.CREATE_REAL_TIME, createRealTime, nowReal);