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.desktopmode 18 19 import android.app.ActivityManager.RunningTaskInfo 20 import android.app.WindowConfiguration.ACTIVITY_TYPE_HOME 21 import android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD 22 import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM 23 import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN 24 import android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW 25 import android.graphics.Rect 26 import android.view.Display.DEFAULT_DISPLAY 27 import com.android.wm.shell.MockToken 28 import com.android.wm.shell.TestRunningTaskInfoBuilder 29 30 object DesktopTestHelpers { 31 /** Create a task that has windowing mode set to [WINDOWING_MODE_FREEFORM] */ createFreeformTasknull32 fun createFreeformTask( 33 displayId: Int = DEFAULT_DISPLAY, 34 bounds: Rect? = null, 35 ): RunningTaskInfo = 36 TestRunningTaskInfoBuilder() 37 .setDisplayId(displayId) 38 .setToken(MockToken().token()) 39 .setActivityType(ACTIVITY_TYPE_STANDARD) 40 .setWindowingMode(WINDOWING_MODE_FREEFORM) 41 .setLastActiveTime(100) 42 .apply { bounds?.let { setBounds(it) } } 43 .build() 44 createFullscreenTaskBuildernull45 fun createFullscreenTaskBuilder(displayId: Int = DEFAULT_DISPLAY): TestRunningTaskInfoBuilder = 46 TestRunningTaskInfoBuilder() 47 .setDisplayId(displayId) 48 .setToken(MockToken().token()) 49 .setActivityType(ACTIVITY_TYPE_STANDARD) 50 .setWindowingMode(WINDOWING_MODE_FULLSCREEN) 51 .setLastActiveTime(100) 52 53 /** Create a task that has windowing mode set to [WINDOWING_MODE_FULLSCREEN] */ 54 fun createFullscreenTask(displayId: Int = DEFAULT_DISPLAY): RunningTaskInfo = 55 createFullscreenTaskBuilder(displayId).build() 56 57 /** Create a task that has windowing mode set to [WINDOWING_MODE_MULTI_WINDOW] */ 58 fun createSplitScreenTask(displayId: Int = DEFAULT_DISPLAY): RunningTaskInfo = 59 TestRunningTaskInfoBuilder() 60 .setDisplayId(displayId) 61 .setToken(MockToken().token()) 62 .setActivityType(ACTIVITY_TYPE_STANDARD) 63 .setWindowingMode(WINDOWING_MODE_MULTI_WINDOW) 64 .setLastActiveTime(100) 65 .build() 66 67 fun createHomeTask(displayId: Int = DEFAULT_DISPLAY): RunningTaskInfo = 68 TestRunningTaskInfoBuilder() 69 .setDisplayId(displayId) 70 .setToken(MockToken().token()) 71 .setActivityType(ACTIVITY_TYPE_HOME) 72 .setWindowingMode(WINDOWING_MODE_FULLSCREEN) 73 .setLastActiveTime(100) 74 .build() 75 76 /** Create a new System Modal task, i.e. a task with only transparent activities. */ 77 fun createSystemModalTask(displayId: Int = DEFAULT_DISPLAY): RunningTaskInfo = 78 createFullscreenTaskBuilder(displayId) 79 .setActivityStackTransparent(true) 80 .setNumActivities(1) 81 .build() 82 } 83