Debian Codegraph @

tests/FlickerTests/src/com/android/server/wm/flicker/helpers/TwoActivitiesAppHelper.kt

raw
1 /*
2 * Copyright (C) 2021 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.server.wm.flicker.helpers
18
19 import android.app.Instrumentation
20 import android.support.test.launcherhelper.ILauncherStrategy
21 import android.support.test.launcherhelper.LauncherStrategyFactory
22 import android.view.Display
23 import androidx.test.uiautomator.By
24 import androidx.test.uiautomator.UiDevice
25 import androidx.test.uiautomator.Until
26 import com.android.server.wm.flicker.testapp.ActivityOptions
27 import com.android.server.wm.traces.common.FlickerComponentName
28 import com.android.server.wm.traces.common.WindowManagerConditionsFactory
29 import com.android.server.wm.traces.parser.toFlickerComponent
30 import com.android.server.wm.traces.parser.windowmanager.WindowManagerStateHelper
31
32 class TwoActivitiesAppHelper @JvmOverloads constructor(
33 instr: Instrumentation,
34 launcherName: String = ActivityOptions.BUTTON_ACTIVITY_LAUNCHER_NAME,
35 component: FlickerComponentName =
36 ActivityOptions.BUTTON_ACTIVITY_COMPONENT_NAME.toFlickerComponent(),
37 launcherStrategy: ILauncherStrategy = LauncherStrategyFactory
38 .getInstance(instr)
39 .launcherStrategy
40 ) : StandardAppHelper(instr, launcherName, component, launcherStrategy) {
41
42 private val secondActivityComponent =
43 ActivityOptions.SIMPLE_ACTIVITY_AUTO_FOCUS_COMPONENT_NAME.toFlickerComponent()
44
45 fun openSecondActivity(device: UiDevice, wmHelper: WindowManagerStateHelper) {
46 val launchActivityButton = By.res(getPackage(), LAUNCH_SECOND_ACTIVITY)
47 val button = device.wait(Until.findObject(launchActivityButton), FIND_TIMEOUT)
48
49 require(button != null) {
50 "Button not found, this usually happens when the device " +
51 "was left in an unknown state (e.g. in split screen)"
52 }
53 button.click()
54
55 device.wait(Until.gone(launchActivityButton), FIND_TIMEOUT)
56 wmHelper.waitFor(
57 WindowManagerStateHelper.isAppFullScreen(secondActivityComponent),
58 WindowManagerConditionsFactory.isAppTransitionIdle(Display.DEFAULT_DISPLAY),
59 WindowManagerConditionsFactory.hasLayersAnimating().negate()
60 )
61 }
62
63 companion object {
64 private const val LAUNCH_SECOND_ACTIVITY = "launch_second_activity"
65 }
66 }