Add a bindService sequence counter

This counter will be emitted in system_server and the bound app
and will help associate bindService requests all the way from binding app
through the system_server and to the bound app

Test: Manual
Bug: 271944973
Change-Id: I16994935a573311eeb82ed389104b94855a95878
This commit is contained in:
Zim
2023-03-09 16:03:15 +00:00
committed by Zimuzo Ezeozue
parent a5991fc129
commit 42d0210633
3 changed files with 19 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -336,6 +336,13 @@ public final class ActiveServices {
*/
final ArrayMap<ForegroundServiceDelegation, ServiceRecord> 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
@@ -4420,8 +4427,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;
}