From cca4059356f8e8e0ea9efeea8dd15fabbfe6f9de Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Tue, 1 Feb 2022 12:15:06 -0800 Subject: [PATCH] profcollectd: register callback to wait until ETM is ready. ETM may not be ready after boot. So after connecting to profcollectd, register ProviderStatusCallback to wait until ETM is ready. Bug: 213519191 Test: on oriole EVT and DVT devices, profcollectd can record applaunch Test: profiles. Change-Id: I15326b0c95afcf44cd2e85d063496311dda0d04d --- .../ProfcollectForwardingService.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java b/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java index 62a16f7f24fdc..c5f990d52b82a 100644 --- a/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java +++ b/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java @@ -60,6 +60,12 @@ public final class ProfcollectForwardingService extends SystemService { private static ProfcollectForwardingService sSelfService; private final Handler mHandler = new ProfcollectdHandler(IoThread.getHandler().getLooper()); + private IProviderStatusCallback mProviderStatusCallback = new IProviderStatusCallback.Stub() { + public void onProviderReady() { + mHandler.sendEmptyMessage(ProfcollectdHandler.MESSAGE_REGISTER_SCHEDULERS); + } + }; + public ProfcollectForwardingService(Context context) { super(context); @@ -93,13 +99,23 @@ public final class ProfcollectForwardingService extends SystemService { } BackgroundThread.get().getThreadHandler().post(() -> { if (serviceHasSupportedTraceProvider()) { - registerObservers(); - ProfcollectBGJobService.schedule(getContext()); + registerProviderStatusCallback(); } }); } } + private void registerProviderStatusCallback() { + if (mIProfcollect == null) { + return; + } + try { + mIProfcollect.registerProviderStatusCallback(mProviderStatusCallback); + } catch (RemoteException e) { + Log.e(LOG_TAG, e.getMessage()); + } + } + private boolean serviceHasSupportedTraceProvider() { if (mIProfcollect == null) { return false; @@ -141,6 +157,7 @@ public final class ProfcollectForwardingService extends SystemService { } public static final int MESSAGE_BINDER_CONNECT = 0; + public static final int MESSAGE_REGISTER_SCHEDULERS = 1; @Override public void handleMessage(android.os.Message message) { @@ -148,6 +165,10 @@ public final class ProfcollectForwardingService extends SystemService { case MESSAGE_BINDER_CONNECT: connectNativeService(); break; + case MESSAGE_REGISTER_SCHEDULERS: + registerObservers(); + ProfcollectBGJobService.schedule(getContext()); + break; default: throw new AssertionError("Unknown message: " + message); }