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

Commit 78ca4178 authored by Wei Wang's avatar Wei Wang
Browse files

ContextHubSystemService: Init of ContextHubSystemService in a parallel thread

Expensive parts of initialization (native Initialization) are now done on a separate
init thread.

The service waits for init to complete in PHASE_SYSTEM_SERVICES_READY before expose service.

Test: rebooted and verified that ContextHubSystemService init is completed
Bug: 62667292
Change-Id: I24d7cc7514fcf234a8f97983a9b170da86b0d8be
parent 104b68d0
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -16,17 +16,25 @@

package com.android.server;

import com.android.internal.util.ConcurrentUtils;
import com.android.server.location.ContextHubService;
import com.android.server.SystemServerInitThreadPool;
import android.content.Context;
import android.util.Log;

import java.util.concurrent.Future;

class ContextHubSystemService extends SystemService {
    private static final String TAG = "ContextHubSystemService";
    private final ContextHubService mContextHubService;
    private ContextHubService mContextHubService;

    private Future<?> mInit;

    public ContextHubSystemService(Context context) {
        super(context);
        mInit = SystemServerInitThreadPool.get().submit(() -> {
            mContextHubService = new ContextHubService(context);
        }, "Init ContextHubSystemService");
    }

    @Override
@@ -37,6 +45,9 @@ class ContextHubSystemService extends SystemService {
    public void onBootPhase(int phase) {
        if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
            Log.d(TAG, "onBootPhase: PHASE_SYSTEM_SERVICES_READY");
            ConcurrentUtils.waitForFutureNoInterrupt(mInit,
                    "Wait for ContextHubSystemService init");
            mInit = null;
            publishBinderService(Context.CONTEXTHUB_SERVICE, mContextHubService);
        }
    }