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
This commit is contained in:
Yabin Cui
2022-02-01 12:15:06 -08:00
parent 9d805c35d0
commit cca4059356

View File

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