Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cca40593 authored by Yabin Cui's avatar Yabin Cui
Browse files

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
parent 9d805c35
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -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);
            }