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

Commit f15ce68e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Prevent SystemCaptionsManagerService init from blocking unlockUser"...

Merge "Prevent SystemCaptionsManagerService init from blocking unlockUser" into rvc-dev am: ae34fd76 am: 32b618a6 am: 1fecaba4 am: 63d5301e

Change-Id: Ia21660ddba4f918df8f7065fcc149972b35d7284
parents 818e6b7b 63d5301e
Loading
Loading
Loading
Loading
+28 −6
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.systemcaptions;

import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;

import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Context;
@@ -37,6 +39,8 @@ final class RemoteSystemCaptionsManagerService {
    private static final String SERVICE_INTERFACE =
            "android.service.systemcaptions.SystemCaptionsManagerService";

    private static final int MSG_BIND = 1;

    private final Object mLock = new Object();

    private final Context mContext;
@@ -71,18 +75,26 @@ final class RemoteSystemCaptionsManagerService {
        if (mVerbose) {
            Slog.v(TAG, "initialize()");
        }
        ensureBound();
        scheduleBind();
    }

    /**
     * Destroys this service.
     */
    public void destroy() {
        mHandler.sendMessage(
                obtainMessage(RemoteSystemCaptionsManagerService::handleDestroy, this));
    }

    void destroy() {
    void handleDestroy() {
        if (mVerbose) {
            Slog.v(TAG, "destroy()");
            Slog.v(TAG, "handleDestroy()");
        }

        synchronized (mLock) {
            if (mDestroyed) {
                if (mVerbose) {
                    Slog.v(TAG, "destroy(): Already destroyed");
                    Slog.v(TAG, "handleDestroy(): Already destroyed");
                }
                return;
            }
@@ -97,14 +109,24 @@ final class RemoteSystemCaptionsManagerService {
        }
    }

    private void ensureBound() {
    private void scheduleBind() {
        if (mHandler.hasMessages(MSG_BIND)) {
            if (mVerbose) Slog.v(TAG, "scheduleBind(): already scheduled");
            return;
        }
        mHandler.sendMessage(
                obtainMessage(RemoteSystemCaptionsManagerService::handleEnsureBound, this)
                .setWhat(MSG_BIND));
    }

    private void handleEnsureBound() {
        synchronized (mLock) {
            if (mService != null || mBinding) {
                return;
            }

            if (mVerbose) {
                Slog.v(TAG, "ensureBound(): binding");
                Slog.v(TAG, "handleEnsureBound(): binding");
            }
            mBinding = true;