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

Commit 6d089c12 authored by Winson Chung's avatar Winson Chung
Browse files

Simplify exposing external interfaces to Launcher

- Currently, the collection of binders to send to Launcher is inverted
  and managed by OverviewProxyService which has to know about each
  component directly (and a SysUI interface has to be created to support
  this even if there are no other calls in SysUI to that component).

  Instead, we should have each component register itself with the
  ShellController for controllers which can be exposed to an external
  process, and each product can customize which set of controllers it
  needs to support.
- Add missing dump registration for ShellController
- Updating docs for creating remote callable controllers

Bug: 238217847
Test: atest WMShellUnitTests
Change-Id: Icd0ed33bdbd68b1dd9d782b9ba1f5b4a604479ba
parent 0370f2aa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ filegroup {
    srcs: [
        "src/com/android/wm/shell/util/**/*.java",
        "src/com/android/wm/shell/common/split/SplitScreenConstants.java",
        "src/com/android/wm/shell/sysui/ShellSharedConstants.java",
    ],
    path: "src",
}
+0 −7
Original line number Diff line number Diff line
@@ -28,13 +28,6 @@ import com.android.wm.shell.common.annotations.ExternalThread;
@ExternalThread
public interface BackAnimation {

    /**
     * Returns a binder that can be passed to an external process to update back animations.
     */
    default IBackAnimation createExternalInterface() {
        return null;
    }

    /**
     * Called when a {@link MotionEvent} is generated by a back gesture.
     *
+19 −15
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.back;

import static com.android.wm.shell.common.ExecutorUtils.executeRemoteCallWithTaskPermission;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BACK_PREVIEW;
import static com.android.wm.shell.sysui.ShellSharedConstants.KEY_EXTRA_SHELL_BACK_ANIMATION;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -53,10 +54,12 @@ import android.window.IOnBackInvokedCallback;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.common.ProtoLog;
import com.android.wm.shell.common.ExternalInterfaceBinder;
import com.android.wm.shell.common.RemoteCallable;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.annotations.ShellBackgroundThread;
import com.android.wm.shell.common.annotations.ShellMainThread;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;

@@ -102,6 +105,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
    private final IActivityTaskManager mActivityTaskManager;
    private final Context mContext;
    private final ContentResolver mContentResolver;
    private final ShellController mShellController;
    private final ShellExecutor mShellExecutor;
    private final Handler mBgHandler;
    private final Runnable mResetTransitionRunnable = () -> {
@@ -188,11 +192,12 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont

    public BackAnimationController(
            @NonNull ShellInit shellInit,
            @NonNull ShellController shellController,
            @NonNull @ShellMainThread ShellExecutor shellExecutor,
            @NonNull @ShellBackgroundThread Handler backgroundHandler,
            Context context,
            Transitions transitions) {
        this(shellInit, shellExecutor, backgroundHandler,
        this(shellInit, shellController, shellExecutor, backgroundHandler,
                ActivityTaskManager.getService(), context, context.getContentResolver(),
                transitions);
    }
@@ -200,11 +205,13 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
    @VisibleForTesting
    BackAnimationController(
            @NonNull ShellInit shellInit,
            @NonNull ShellController shellController,
            @NonNull @ShellMainThread ShellExecutor shellExecutor,
            @NonNull @ShellBackgroundThread Handler bgHandler,
            @NonNull IActivityTaskManager activityTaskManager,
            Context context, ContentResolver contentResolver,
            Transitions transitions) {
        mShellController = shellController;
        mShellExecutor = shellExecutor;
        mActivityTaskManager = activityTaskManager;
        mContext = context;
@@ -221,6 +228,8 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
            mBackTransitionHandler = new BackTransitionHandler(this);
            mTransitions.addHandler(mBackTransitionHandler);
        }
        mShellController.addExternalInterface(KEY_EXTRA_SHELL_BACK_ANIMATION,
                this::createExternalInterface, this);
    }

    private void setupAnimationDeveloperSettingsObserver(
@@ -253,7 +262,11 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        return mBackAnimation;
    }

    private final BackAnimation mBackAnimation = new BackAnimationImpl();
    private ExternalInterfaceBinder createExternalInterface() {
        return new IBackAnimationImpl(this);
    }

    private final BackAnimationImpl mBackAnimation = new BackAnimationImpl();

    @Override
    public Context getContext() {
@@ -266,17 +279,6 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
    }

    private class BackAnimationImpl implements BackAnimation {
        private IBackAnimationImpl mBackAnimation;

        @Override
        public IBackAnimation createExternalInterface() {
            if (mBackAnimation != null) {
                mBackAnimation.invalidate();
            }
            mBackAnimation = new IBackAnimationImpl(BackAnimationController.this);
            return mBackAnimation;
        }

        @Override
        public void onBackMotion(
                float touchX, float touchY, int keyAction, @BackEvent.SwipeEdge int swipeEdge) {
@@ -295,7 +297,8 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        }
    }

    private static class IBackAnimationImpl extends IBackAnimation.Stub {
    private static class IBackAnimationImpl extends IBackAnimation.Stub
            implements ExternalInterfaceBinder {
        private BackAnimationController mController;

        IBackAnimationImpl(BackAnimationController controller) {
@@ -315,7 +318,8 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
                    (controller) -> controller.clearBackToLauncherCallback());
        }

        void invalidate() {
        @Override
        public void invalidate() {
            mController = null;
        }
    }
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.common;

import android.os.IBinder;

/**
 * An interface for binders which can be registered to be sent to other processes.
 */
public interface ExternalInterfaceBinder {
    /**
     * Invalidates this binder (detaches it from the controller it would call).
     */
    void invalidate();

    /**
     * Returns the IBinder to send.
     */
    IBinder asBinder();
}
+14 −9
Original line number Diff line number Diff line
@@ -258,14 +258,15 @@ public abstract class WMShellBaseModule {
    static Optional<BackAnimationController> provideBackAnimationController(
            Context context,
            ShellInit shellInit,
            ShellController shellController,
            @ShellMainThread ShellExecutor shellExecutor,
            @ShellBackgroundThread Handler backgroundHandler,
            Transitions transitions
    ) {
        if (BackAnimationController.IS_ENABLED) {
            return Optional.of(
                    new BackAnimationController(shellInit, shellExecutor, backgroundHandler,
                            context, transitions));
                    new BackAnimationController(shellInit, shellController, shellExecutor,
                            backgroundHandler, context, transitions));
        }
        return Optional.empty();
    }
@@ -469,6 +470,7 @@ public abstract class WMShellBaseModule {
    static Optional<RecentTasksController> provideRecentTasksController(
            Context context,
            ShellInit shellInit,
            ShellController shellController,
            ShellCommandHandler shellCommandHandler,
            TaskStackListenerImpl taskStackListener,
            ActivityTaskManager activityTaskManager,
@@ -476,9 +478,9 @@ public abstract class WMShellBaseModule {
            @ShellMainThread ShellExecutor mainExecutor
    ) {
        return Optional.ofNullable(
                RecentTasksController.create(context, shellInit, shellCommandHandler,
                        taskStackListener, activityTaskManager, desktopModeTaskRepository,
                        mainExecutor));
                RecentTasksController.create(context, shellInit, shellController,
                        shellCommandHandler, taskStackListener, activityTaskManager,
                        desktopModeTaskRepository, mainExecutor));
    }

    //
@@ -495,14 +497,15 @@ public abstract class WMShellBaseModule {
    @Provides
    static Transitions provideTransitions(Context context,
            ShellInit shellInit,
            ShellController shellController,
            ShellTaskOrganizer organizer,
            TransactionPool pool,
            DisplayController displayController,
            @ShellMainThread ShellExecutor mainExecutor,
            @ShellMainThread Handler mainHandler,
            @ShellAnimationThread ShellExecutor animExecutor) {
        return new Transitions(context, shellInit, organizer, pool, displayController, mainExecutor,
                mainHandler, animExecutor);
        return new Transitions(context, shellInit, shellController, organizer, pool,
                displayController, mainExecutor, mainHandler, animExecutor);
    }

    @WMSingleton
@@ -619,13 +622,15 @@ public abstract class WMShellBaseModule {

    @WMSingleton
    @Provides
    static StartingWindowController provideStartingWindowController(Context context,
    static StartingWindowController provideStartingWindowController(
            Context context,
            ShellInit shellInit,
            ShellController shellController,
            ShellTaskOrganizer shellTaskOrganizer,
            @ShellSplashscreenThread ShellExecutor splashScreenExecutor,
            StartingWindowTypeAlgorithm startingWindowTypeAlgorithm, IconProvider iconProvider,
            TransactionPool pool) {
        return new StartingWindowController(context, shellInit, shellTaskOrganizer,
        return new StartingWindowController(context, shellInit, shellController, shellTaskOrganizer,
                splashScreenExecutor, startingWindowTypeAlgorithm, iconProvider, pool);
    }

Loading