1 /* 2 * Copyright (C) 2020 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 android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.app.ActivityManager; 23 import android.graphics.Rect; 24 import android.os.Bundle; 25 import android.window.RemoteTransition; 26 27 import com.android.internal.logging.InstanceId; 28 import com.android.wm.shell.common.split.SplitScreenConstants.PersistentSnapPosition; 29 import com.android.wm.shell.common.split.SplitScreenConstants.SplitPosition; 30 import com.android.wm.shell.shared.annotations.ExternalThread; 31 32 import java.util.concurrent.Executor; 33 34 /** 35 * Interface to engage split-screen feature. 36 * TODO: Figure out which of these are actually needed outside of the Shell 37 */ 38 @ExternalThread 39 public interface SplitScreen { 40 /** 41 * Stage type isn't specified normally meaning to use what ever the default is. 42 * E.g. exit split-screen and launch the app in fullscreen. 43 */ 44 int STAGE_TYPE_UNDEFINED = -1; 45 /** 46 * The main stage type. 47 * @see MainStage 48 */ 49 int STAGE_TYPE_MAIN = 0; 50 51 /** 52 * The side stage type. 53 * @see SideStage 54 */ 55 int STAGE_TYPE_SIDE = 1; 56 57 @IntDef(prefix = { "STAGE_TYPE_" }, value = { 58 STAGE_TYPE_UNDEFINED, 59 STAGE_TYPE_MAIN, 60 STAGE_TYPE_SIDE 61 }) 62 @interface StageType {} 63 64 /** Callback interface for listening to changes in a split-screen stage. */ 65 interface SplitScreenListener { onStagePositionChanged(@tageType int stage, @SplitPosition int position)66 default void onStagePositionChanged(@StageType int stage, @SplitPosition int position) {} onTaskStageChanged(int taskId, @StageType int stage, boolean visible)67 default void onTaskStageChanged(int taskId, @StageType int stage, boolean visible) {} onSplitBoundsChanged(Rect rootBounds, Rect mainBounds, Rect sideBounds)68 default void onSplitBoundsChanged(Rect rootBounds, Rect mainBounds, Rect sideBounds) {} onSplitVisibilityChanged(boolean visible)69 default void onSplitVisibilityChanged(boolean visible) {} 70 } 71 72 /** 73 * Callback interface for listening to requests to enter split select. Used for desktop -> split 74 */ 75 interface SplitSelectListener { onRequestEnterSplitSelect(ActivityManager.RunningTaskInfo taskInfo, int splitPosition, Rect taskBounds)76 default boolean onRequestEnterSplitSelect(ActivityManager.RunningTaskInfo taskInfo, 77 int splitPosition, Rect taskBounds) { 78 return false; 79 } 80 } 81 82 /** Launches a pair of tasks into splitscreen */ startTasks(int taskId1, @Nullable Bundle options1, int taskId2, @Nullable Bundle options2, @SplitPosition int splitPosition, @PersistentSnapPosition int snapPosition, @Nullable RemoteTransition remoteTransition, InstanceId instanceId)83 void startTasks(int taskId1, @Nullable Bundle options1, int taskId2, 84 @Nullable Bundle options2, @SplitPosition int splitPosition, 85 @PersistentSnapPosition int snapPosition, @Nullable RemoteTransition remoteTransition, 86 InstanceId instanceId); 87 88 /** Registers listener that gets split screen callback. */ registerSplitScreenListener(@onNull SplitScreenListener listener, @NonNull Executor executor)89 void registerSplitScreenListener(@NonNull SplitScreenListener listener, 90 @NonNull Executor executor); 91 92 /** Unregisters listener that gets split screen callback. */ unregisterSplitScreenListener(@onNull SplitScreenListener listener)93 void unregisterSplitScreenListener(@NonNull SplitScreenListener listener); 94 95 interface SplitInvocationListener { 96 /** 97 * Called whenever shell starts or stops the split screen animation 98 * @param animationRunning if {@code true} the animation has begun, if {@code false} the 99 * animation has finished 100 */ onSplitAnimationInvoked(boolean animationRunning)101 default void onSplitAnimationInvoked(boolean animationRunning) { } 102 } 103 104 /** 105 * Registers a {@link SplitInvocationListener} to notify when the animation to enter split 106 * screen has started and stopped 107 * 108 * @param executor callbacks to the listener will be executed on this executor 109 */ registerSplitAnimationListener(@onNull SplitInvocationListener listener, @NonNull Executor executor)110 void registerSplitAnimationListener(@NonNull SplitInvocationListener listener, 111 @NonNull Executor executor); 112 113 /** Called when device waking up finished. */ onFinishedWakingUp()114 void onFinishedWakingUp(); 115 116 /** Called when requested to go to fullscreen from the current active split app. */ goToFullscreenFromSplit()117 void goToFullscreenFromSplit(); 118 119 /** Called when splitscreen focused app is changed. */ setSplitscreenFocus(boolean leftOrTop)120 void setSplitscreenFocus(boolean leftOrTop); 121 122 /** Get a string representation of a stage type */ stageTypeToString(@tageType int stage)123 static String stageTypeToString(@StageType int stage) { 124 switch (stage) { 125 case STAGE_TYPE_UNDEFINED: return "UNDEFINED"; 126 case STAGE_TYPE_MAIN: return "MAIN"; 127 case STAGE_TYPE_SIDE: return "SIDE"; 128 default: return "UNKNOWN(" + stage + ")"; 129 } 130 } 131 } 132