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

Commit cb72f0a2 authored by Evan Severson's avatar Evan Severson
Browse files

Create thread for UI operations for selection toolbar

This takes all work off of the main thread. The SurfaceControlViewHost
uses the thread it was created on as the ui thread since it creates it's
ViewRootImpl on this thread as opposed to being created through
ActivityThread.

Test: CtsWidgetTestCases
      CopyContentInSplitGesturalNavPortraitMicrobenchmark
Bug: 421408244
Flag: android.permission.flags.system_selection_toolbar_enabled
Change-Id: I7ceaf4c475e84a98cedacb61e34ca591ffda5008
parent 8c74fe43
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Service;
import android.content.Intent;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
@@ -30,6 +31,8 @@ import android.view.selectiontoolbar.WidgetInfo;

import com.android.internal.annotations.GuardedBy;

import java.util.concurrent.Executor;

/**
 * Service for rendering selection toolbar.
 *
@@ -52,6 +55,17 @@ public abstract class SelectionToolbarRenderService extends Service {
    private final Object mLock = new Object();
    private volatile ISelectionToolbarRenderServiceCallback mServiceCallback;

    private final HandlerThread mThread =
            new HandlerThread(SelectionToolbarRenderService.class.getSimpleName());

    public SelectionToolbarRenderService() {
        mThread.start();
    }

    protected final Executor getToolbarUiExecutor() {
        return mThread.getThreadExecutor();
    }

    /**
     * Binder to receive calls from system server.
     */
+3 −3
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ class SysUiSelectionToolbarRenderService : SelectionToolbarRenderService() {
                ::onPasteAction,
            )
        toolbarCache[uid] = toolbar
        mainThreadHandler.post { toolbar.show(showInfo) }
        toolbarUiExecutor.execute { toolbar.show(showInfo) }

        Slog.v(TAG, "onShow() for uid: $uid")
    }
@@ -56,7 +56,7 @@ class SysUiSelectionToolbarRenderService : SelectionToolbarRenderService() {
        val toolbar = toolbarCache[uid]
        if (toolbar != null) {
            Slog.v(TAG, "onHide() for uid: $uid")
            mainThreadHandler.post { toolbar.hide(uid) }
            toolbarUiExecutor.execute { toolbar.hide(uid) }
        }
    }

@@ -68,7 +68,7 @@ class SysUiSelectionToolbarRenderService : SelectionToolbarRenderService() {
    private fun removeAndDismissToolbar(uid: Int) {
        val toolbar = toolbarCache[uid]
        if (toolbar != null) {
            mainThreadHandler.post { toolbar.dismiss(uid) }
            toolbarUiExecutor.execute { toolbar.dismiss(uid) }
            toolbarCache -= uid
        }
    }