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

Commit 98f15cc9 authored by Winson Chung's avatar Winson Chung
Browse files

Remove ShellInit/ShellCommandHandler interfaces to SysUI

- SysUI now calls init/commands/dump via the ShellController interface
- Move ShellInit/ShellCommandHandler into the sysui package since it's
  only called on sysui startup

Test: atest WMShellUnitTests
Test: atest SystemUITests
Bug: 238217847
Change-Id: I7b05dbab7648cb8a8c6f9381b0b5f545ed3398f1
parent 531b63c1
Loading
Loading
Loading
Loading
+0 −39
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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;

import com.android.wm.shell.common.annotations.ExternalThread;

import java.io.PrintWriter;

/**
 * An entry point into the shell for dumping shell internal state and running adb commands.
 *
 * Use with {@code adb shell dumpsys activity service SystemUIService WMShell ...}.
 */
@ExternalThread
public interface ShellCommandHandler {
    /**
     * Dumps the shell state.
     */
    void dump(PrintWriter pw);

    /**
     * Handles a shell command.
     */
    boolean handleCommand(final String[] args, PrintWriter pw);
}
+0 −30
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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;

import com.android.wm.shell.common.annotations.ExternalThread;

/**
 * An entry point into the shell for initializing shell internal state.
 */
@ExternalThread
public interface ShellInit {
    /**
     * Initializes the shell state.
     */
    void init();
}
+12 −26
Original line number Diff line number Diff line
@@ -29,10 +29,8 @@ import com.android.internal.logging.UiEventLogger;
import com.android.launcher3.icons.IconProvider;
import com.android.wm.shell.RootDisplayAreaOrganizer;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
import com.android.wm.shell.ShellCommandHandler;
import com.android.wm.shell.ShellCommandHandlerImpl;
import com.android.wm.shell.ShellInit;
import com.android.wm.shell.ShellInitImpl;
import com.android.wm.shell.sysui.ShellCommandHandler;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.TaskViewFactory;
import com.android.wm.shell.TaskViewFactoryController;
@@ -624,13 +622,9 @@ public abstract class WMShellBaseModule {

    @WMSingleton
    @Provides
    static ShellInit provideShellInit(ShellInitImpl impl) {
        return impl.asShellInit();
    }

    @WMSingleton
    @Provides
    static ShellInitImpl provideShellInitImpl(DisplayController displayController,
    static ShellInit provideShellInitImpl(
            ShellController shellController,
            DisplayController displayController,
            DisplayImeController displayImeController,
            DisplayInsetsController displayInsetsController,
            DragAndDropController dragAndDropController,
@@ -648,7 +642,8 @@ public abstract class WMShellBaseModule {
            Transitions transitions,
            StartingWindowController startingWindow,
            @ShellMainThread ShellExecutor mainExecutor) {
        return new ShellInitImpl(displayController,
        return new ShellInit(shellController,
                displayController,
                displayImeController,
                displayInsetsController,
                dragAndDropController,
@@ -668,19 +663,10 @@ public abstract class WMShellBaseModule {
                mainExecutor);
    }

    /**
     * Note, this is only optional because we currently pass this to the SysUI component scope and
     * for non-primary users, we may inject a null-optional for that dependency.
     */
    @WMSingleton
    @Provides
    static Optional<ShellCommandHandler> provideShellCommandHandler(ShellCommandHandlerImpl impl) {
        return Optional.of(impl.asShellCommandHandler());
    }

    @WMSingleton
    @Provides
    static ShellCommandHandlerImpl provideShellCommandHandlerImpl(
    static ShellCommandHandler provideShellCommandHandlerImpl(
            ShellController shellController,
            ShellTaskOrganizer shellTaskOrganizer,
            KidsModeTaskOrganizer kidsModeTaskOrganizer,
            Optional<SplitScreenController> splitScreenOptional,
@@ -689,9 +675,9 @@ public abstract class WMShellBaseModule {
            Optional<HideDisplayCutoutController> hideDisplayCutout,
            Optional<RecentTasksController> recentTasksOptional,
            @ShellMainThread ShellExecutor mainExecutor) {
        return new ShellCommandHandlerImpl(shellTaskOrganizer, kidsModeTaskOrganizer,
                splitScreenOptional, pipOptional, oneHandedOptional, hideDisplayCutout,
                recentTasksOptional, mainExecutor);
        return new ShellCommandHandler(shellController, shellTaskOrganizer,
                kidsModeTaskOrganizer, splitScreenOptional, pipOptional, oneHandedOptional,
                hideDisplayCutout, recentTasksOptional, mainExecutor);
    }

    @WMSingleton
+10 −35
Original line number Diff line number Diff line
@@ -14,10 +14,11 @@
 * limitations under the License.
 */

package com.android.wm.shell;
package com.android.wm.shell.sysui;

import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;

import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.hidedisplaycutout.HideDisplayCutoutController;
import com.android.wm.shell.kidsmode.KidsModeTaskOrganizer;
@@ -34,8 +35,8 @@ import java.util.Optional;
 *
 * Use with {@code adb shell dumpsys activity service SystemUIService WMShell ...}.
 */
public final class ShellCommandHandlerImpl {
    private static final String TAG = ShellCommandHandlerImpl.class.getSimpleName();
public final class ShellCommandHandler {
    private static final String TAG = ShellCommandHandler.class.getSimpleName();

    private final Optional<SplitScreenController> mSplitScreenOptional;
    private final Optional<Pip> mPipOptional;
@@ -45,9 +46,9 @@ public final class ShellCommandHandlerImpl {
    private final ShellTaskOrganizer mShellTaskOrganizer;
    private final KidsModeTaskOrganizer mKidsModeTaskOrganizer;
    private final ShellExecutor mMainExecutor;
    private final HandlerImpl mImpl = new HandlerImpl();

    public ShellCommandHandlerImpl(
    public ShellCommandHandler(
            ShellController shellController,
            ShellTaskOrganizer shellTaskOrganizer,
            KidsModeTaskOrganizer kidsModeTaskOrganizer,
            Optional<SplitScreenController> splitScreenOptional,
@@ -64,14 +65,12 @@ public final class ShellCommandHandlerImpl {
        mOneHandedOptional = oneHandedOptional;
        mHideDisplayCutout = hideDisplayCutout;
        mMainExecutor = mainExecutor;
    }

    public ShellCommandHandler asShellCommandHandler() {
        return mImpl;
        // TODO(238217847): To be removed once the command handler dependencies are inverted
        shellController.setShellCommandHandler(this);
    }

    /** Dumps WM Shell internal state. */
    private void dump(PrintWriter pw) {
    public void dump(PrintWriter pw) {
        mShellTaskOrganizer.dump(pw, "");
        pw.println();
        pw.println();
@@ -91,7 +90,7 @@ public final class ShellCommandHandlerImpl {


    /** Returns {@code true} if command was found and executed. */
    private boolean handleCommand(final String[] args, PrintWriter pw) {
    public boolean handleCommand(final String[] args, PrintWriter pw) {
        if (args.length < 2) {
            // Argument at position 0 is "WMShell".
            return false;
@@ -164,28 +163,4 @@ public final class ShellCommandHandlerImpl {
        pw.println("    Sets the position of the side-stage.");
        return true;
    }

    private class HandlerImpl implements ShellCommandHandler {
        @Override
        public void dump(PrintWriter pw) {
            try {
                mMainExecutor.executeBlocking(() -> ShellCommandHandlerImpl.this.dump(pw));
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed to dump the Shell in 2s", e);
            }
        }

        @Override
        public boolean handleCommand(String[] args, PrintWriter pw) {
            try {
                boolean[] result = new boolean[1];
                mMainExecutor.executeBlocking(() -> {
                    result[0] = ShellCommandHandlerImpl.this.handleCommand(args, pw);
                });
                return result[0];
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed to handle Shell command in 2s", e);
            }
        }
    }
}
+53 −0
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ public class ShellController {
    private final ShellExecutor mMainExecutor;
    private final ShellInterfaceImpl mImpl = new ShellInterfaceImpl();

    private ShellInit mShellInit;
    private ShellCommandHandler mShellCommandHandler;

    private final CopyOnWriteArrayList<ConfigurationChangeListener> mConfigChangeListeners =
            new CopyOnWriteArrayList<>();
    private final CopyOnWriteArrayList<KeyguardChangeListener> mKeyguardChangeListeners =
@@ -65,6 +68,24 @@ public class ShellController {
        return mImpl;
    }

    /**
     * Sets the init handler to call back to.
     * TODO(238217847): This is only exposed this way until we can remove the dependencies from the
     *                  init handler to other classes.
     */
    public void setShellInit(ShellInit shellInit) {
        mShellInit = shellInit;
    }

    /**
     * Sets the command handler to call back to.
     * TODO(238217847): This is only exposed this way until we can remove the dependencies from the
     *                  command handler to other classes.
     */
    public void setShellCommandHandler(ShellCommandHandler shellCommandHandler) {
        mShellCommandHandler = shellCommandHandler;
    }

    /**
     * Adds a new configuration listener. The configuration change callbacks are not made in any
     * particular order.
@@ -164,6 +185,38 @@ public class ShellController {
     */
    @ExternalThread
    private class ShellInterfaceImpl implements ShellInterface {

        @Override
        public void onInit() {
            try {
                mMainExecutor.executeBlocking(() -> mShellInit.init());
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed to initialize the Shell in 2s", e);
            }
        }

        @Override
        public void dump(PrintWriter pw) {
            try {
                mMainExecutor.executeBlocking(() -> mShellCommandHandler.dump(pw));
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed to dump the Shell in 2s", e);
            }
        }

        @Override
        public boolean handleCommand(String[] args, PrintWriter pw) {
            try {
                boolean[] result = new boolean[1];
                mMainExecutor.executeBlocking(() -> {
                    result[0] = mShellCommandHandler.handleCommand(args, pw);
                });
                return result[0];
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed to handle Shell command in 2s", e);
            }
        }

        @Override
        public void onConfigurationChanged(Configuration newConfiguration) {
            mMainExecutor.execute(() ->
Loading