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

Commit 94ab1a66 authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

Init of OverlayManagerService on a parallel thread

Expensive parts of initialization (like idmap) are now done on a separate
init thread.

The service waits for init to complete in PHASE_SYSTEM_SERVICES_READY,
before affected apps can start.

Boot time saving: ~300ms on marlin.

Test: rebooted and verified that OverlayManagerService init is completed
      before any app process is started
Bug: 35949883

Change-Id: Ibdf0174c50cfa95fc8f1cb014ad0a03ff49f4d1f
parent a3d279fa
Loading
Loading
Loading
Loading
+35 −20
Original line number Diff line number Diff line
@@ -53,9 +53,11 @@ import android.util.AtomicFile;
import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.util.ConcurrentUtils;
import com.android.server.FgThread;
import com.android.server.IoThread;
import com.android.server.LocalServices;
import com.android.server.SystemServerInitThreadPool;
import com.android.server.SystemService;
import com.android.server.pm.Installer;
import com.android.server.pm.UserManagerService;
@@ -74,6 +76,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;

/**
@@ -219,6 +222,8 @@ public final class OverlayManagerService extends SystemService {

    private final AtomicBoolean mPersistSettingsScheduled = new AtomicBoolean(false);

    private Future<?> mInitCompleteSignal;

    public OverlayManagerService(@NonNull final Context context,
            @NonNull final Installer installer) {
        super(context);
@@ -230,7 +235,7 @@ public final class OverlayManagerService extends SystemService {
        mSettings = new OverlayManagerSettings();
        mImpl = new OverlayManagerServiceImpl(mPackageManager, im, mSettings,
                getDefaultOverlayPackages());

        mInitCompleteSignal = SystemServerInitThreadPool.get().submit(() -> {
            final IntentFilter packageFilter = new IntentFilter();
            packageFilter.addAction(ACTION_PACKAGE_ADDED);
            packageFilter.addAction(ACTION_PACKAGE_CHANGED);
@@ -252,6 +257,7 @@ public final class OverlayManagerService extends SystemService {

            publishBinderService(Context.OVERLAY_SERVICE, mService);
            publishLocalService(OverlayManagerService.class, this);
        }, "Init OverlayManagerService");
    }

    @Override
@@ -259,6 +265,15 @@ public final class OverlayManagerService extends SystemService {
        // Intentionally left empty.
    }

    @Override
    public void onBootPhase(int phase) {
        if (phase == PHASE_SYSTEM_SERVICES_READY) {
            ConcurrentUtils.waitForFutureNoInterrupt(mInitCompleteSignal,
                    "Wait for OverlayManagerService init");
            mInitCompleteSignal = null;
        }
    }

    @Override
    public void onSwitchUser(final int newUserId) {
        // ensure overlays in the settings are up-to-date, and propagate