diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 87643b23688eb..28d4433f1e21e 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -849,8 +849,10 @@ public final class ActivityThread extends ClientTransactionHandler @UnsupportedAppUsage Intent intent; boolean rebind; + long bindSeq; public String toString() { - return "BindServiceData{token=" + token + " intent=" + intent + "}"; + return "BindServiceData{token=" + token + " intent=" + intent + + " bindSeq=" + bindSeq + "}"; } } @@ -1107,12 +1109,13 @@ public final class ActivityThread extends ClientTransactionHandler } public final void scheduleBindService(IBinder token, Intent intent, - boolean rebind, int processState) { + boolean rebind, int processState, long bindSeq) { updateProcessState(processState, false); BindServiceData s = new BindServiceData(); s.token = token; s.intent = intent; s.rebind = rebind; + s.bindSeq = bindSeq; if (DEBUG_SERVICE) Slog.v(TAG, "scheduleBindService token=" + token + " intent=" + intent + " uid=" @@ -1124,6 +1127,7 @@ public final class ActivityThread extends ClientTransactionHandler BindServiceData s = new BindServiceData(); s.token = token; s.intent = intent; + s.bindSeq = -1; sendMessage(H.UNBIND_SERVICE, s); } diff --git a/core/java/android/app/IApplicationThread.aidl b/core/java/android/app/IApplicationThread.aidl index 4f77203c8c6f2..6b5f6b03028e0 100644 --- a/core/java/android/app/IApplicationThread.aidl +++ b/core/java/android/app/IApplicationThread.aidl @@ -95,7 +95,7 @@ oneway interface IApplicationThread { void processInBackground(); @UnsupportedAppUsage void scheduleBindService(IBinder token, - in Intent intent, boolean rebind, int processState); + in Intent intent, boolean rebind, int processState, long bindSeq); @UnsupportedAppUsage void scheduleUnbindService(IBinder token, in Intent intent); diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index c5008fa2e07eb..9bde039d06afc 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -336,6 +336,13 @@ public final class ActiveServices { */ final ArrayMap mFgsDelegations = new ArrayMap<>(); + /** + * A global counter for generating sequence numbers to uniquely identify bindService requests. + * It is purely for logging purposes. + */ + @GuardedBy("mAm") + private long mBindServiceSeqCounter = 0; + /** * Whether there is a rate limit that suppresses immediate re-deferral of new FGS * notifications from each app. On by default, disabled only by shell command for @@ -4429,8 +4436,12 @@ public final class ActiveServices { try { bumpServiceExecutingLocked(r, execInFg, "bind", OomAdjuster.OOM_ADJ_REASON_BIND_SERVICE); + if (Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { + Trace.instant(Trace.TRACE_TAG_ACTIVITY_MANAGER, "requestServiceBinding=" + + i.intent.getIntent() + ". bindSeq=" + mBindServiceSeqCounter); + } r.app.getThread().scheduleBindService(r, i.intent.getIntent(), rebind, - r.app.mState.getReportedProcState()); + r.app.mState.getReportedProcState(), mBindServiceSeqCounter++); if (!rebind) { i.requested = true; }