Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenShellCommandHandler.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.wm.shell.splitscreen;
18
19 import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
20
21 import com.android.wm.shell.sysui.ShellCommandHandler;
22
23 import java.io.PrintWriter;
24
25 /**
26 * Handles the shell commands for the SplitscreenController.
27 */
28 public class SplitScreenShellCommandHandler implements
29 ShellCommandHandler.ShellCommandActionHandler {
30
31 private final SplitScreenController mController;
32
33 public SplitScreenShellCommandHandler(SplitScreenController controller) {
34 mController = controller;
35 }
36
37 @Override
38 public boolean onShellCommand(String[] args, PrintWriter pw) {
39 switch (args[0]) {
40 case "moveToSideStage":
41 return runMoveToSideStage(args, pw);
42 case "removeFromSideStage":
43 return runRemoveFromSideStage(args, pw);
44 case "setSideStagePosition":
45 return runSetSideStagePosition(args, pw);
46 default:
47 pw.println("Invalid command: " + args[0]);
48 return false;
49 }
50 }
51
52 private boolean runMoveToSideStage(String[] args, PrintWriter pw) {
53 if (args.length < 3) {
54 // First argument is the action name.
55 pw.println("Error: task id should be provided as arguments");
56 return false;
57 }
58 final int taskId = new Integer(args[1]);
59 final int sideStagePosition = args.length > 2
60 ? new Integer(args[2]) : SPLIT_POSITION_BOTTOM_OR_RIGHT;
61 mController.moveToSideStage(taskId, sideStagePosition);
62 return true;
63 }
64
65 private boolean runRemoveFromSideStage(String[] args, PrintWriter pw) {
66 if (args.length < 2) {
67 // First argument is the action name.
68 pw.println("Error: task id should be provided as arguments");
69 return false;
70 }
71 final int taskId = new Integer(args[1]);
72 mController.removeFromSideStage(taskId);
73 return true;
74 }
75
76 private boolean runSetSideStagePosition(String[] args, PrintWriter pw) {
77 if (args.length < 2) {
78 // First argument is the action name.
79 pw.println("Error: side stage position should be provided as arguments");
80 return false;
81 }
82 final int position = new Integer(args[1]);
83 mController.setSideStagePosition(position);
84 return true;
85 }
86
87 @Override
88 public void printShellCommandHelp(PrintWriter pw, String prefix) {
89 pw.println(prefix + "moveToSideStage <taskId> <SideStagePosition>");
90 pw.println(prefix + " Move a task with given id in split-screen mode.");
91 pw.println(prefix + "removeFromSideStage <taskId>");
92 pw.println(prefix + " Remove a task with given id in split-screen mode.");
93 pw.println(prefix + "setSideStagePosition <SideStagePosition>");
94 pw.println(prefix + " Sets the position of the side-stage.");
95 }
96 }