1 /* 2 * Copyright (C) 2023 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 18 19 import android.app.Instrumentation 20 import android.platform.test.rule.EnsureDeviceSettingsRule 21 import android.platform.test.rule.NavigationModeRule 22 import android.platform.test.rule.PressHomeRule 23 import android.platform.test.rule.UnlockScreenRule 24 import android.tools.NavBar 25 import android.tools.Rotation 26 import android.tools.device.apphelpers.MessagingAppHelper 27 import android.tools.flicker.rules.ArtifactSaverRule 28 import android.tools.flicker.rules.ChangeDisplayOrientationRule 29 import android.tools.flicker.rules.LaunchAppRule 30 import android.tools.flicker.rules.RemoveAllTasksButHomeRule 31 import android.util.Log 32 import androidx.test.platform.app.InstrumentationRegistry 33 import androidx.test.uiautomator.UiDevice 34 import java.io.IOException 35 import org.junit.rules.RuleChain 36 37 object Utils { 38 private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() 39 testSetupRulenull40 fun testSetupRule(navigationMode: NavBar, rotation: Rotation): RuleChain { 41 return RuleChain.outerRule(ArtifactSaverRule()) 42 .around(UnlockScreenRule()) 43 .around(NavigationModeRule(navigationMode.value, false)) 44 .around( 45 LaunchAppRule(MessagingAppHelper(instrumentation), clearCacheAfterParsing = false) 46 ) 47 .around(RemoveAllTasksButHomeRule()) 48 .around( 49 ChangeDisplayOrientationRule( 50 rotation, 51 resetOrientationAfterTest = false, 52 clearCacheAfterParsing = false 53 ) 54 ) 55 .around(PressHomeRule()) 56 .around(EnsureDeviceSettingsRule()) 57 } 58 59 /** 60 * Resets the frozen recent tasks list (ie. commits the quickswitch to the current task and 61 * reorders the current task to the end of the recents list). 62 */ resetFreezeRecentTaskListnull63 fun resetFreezeRecentTaskList() { 64 try { 65 UiDevice.getInstance(instrumentation) 66 .executeShellCommand("wm reset-freeze-recent-tasks") 67 } catch (e: IOException) { 68 Log.e("TestUtils", "Failed to reset frozen recent tasks list", e) 69 } 70 } 71 } 72