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.server.wm.flicker.launch
18 
19 import android.os.SystemClock
20 import android.platform.test.annotations.Postsubmit
21 import android.tools.device.apphelpers.CameraAppHelper
22 import android.tools.device.apphelpers.StandardAppHelper
23 import android.tools.flicker.junit.FlickerParametersRunnerFactory
24 import android.tools.flicker.legacy.FlickerBuilder
25 import android.tools.flicker.legacy.LegacyFlickerTest
26 import android.tools.flicker.legacy.LegacyFlickerTestFactory
27 import android.tools.flicker.rules.RemoveAllTasksButHomeRule
28 import android.tools.flicker.subject.layers.LayersTraceSubject
29 import android.tools.traces.component.ComponentNameMatcher
30 import android.view.KeyEvent
31 import androidx.test.filters.RequiresDevice
32 import com.android.server.wm.flicker.helpers.setRotation
33 import com.android.server.wm.flicker.launch.common.OpenAppFromLauncherTransition
34 import org.junit.FixMethodOrder
35 import org.junit.Ignore
36 import org.junit.Test
37 import org.junit.runner.RunWith
38 import org.junit.runners.MethodSorters
39 import org.junit.runners.Parameterized
40 
41 /**
42  * Test cold launching camera from launcher by double pressing power button
43  *
44  * To run this test: `atest FlickerTestsAppLaunch:OpenCameraFromHomeOnDoubleClickPowerButtonTest`
45  *
46  * Actions:
47  * ```
48  *     Make sure no apps are running on the device
49  *     Launch an app [testApp] and wait animation to complete
50  * ```
51  *
52  * Notes:
53  * ```
54  *     1. Some default assertions (e.g., nav bar, status bar and screen covered)
55  *        are inherited [OpenAppTransition]
56  *     2. Part of the test setup occurs automatically via
57  *        [com.android.server.wm.flicker.TransitionRunnerWithRules],
58  *        including configuring navigation mode, initial orientation and ensuring no
59  *        apps are running before setup
60  * ```
61  */
62 @RequiresDevice
63 @RunWith(Parameterized::class)
64 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
65 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
66 class OpenCameraFromHomeOnDoubleClickPowerButtonTest(flicker: LegacyFlickerTest) :
67     OpenAppFromLauncherTransition(flicker) {
68     private val cameraApp = CameraAppHelper(instrumentation)
69     override val testApp: StandardAppHelper
70         get() = cameraApp
71 
72     override val transition: FlickerBuilder.() -> Unit
<lambda>null73         get() = {
74             setup {
75                 RemoveAllTasksButHomeRule.removeAllTasksButHome()
76                 this.setRotation(flicker.scenario.startRotation)
77             }
78             transitions {
79                 device.pressKeyCode(KeyEvent.KEYCODE_POWER)
80                 SystemClock.sleep(100)
81                 device.pressKeyCode(KeyEvent.KEYCODE_POWER)
82                 wmHelper.StateSyncBuilder().withWindowSurfaceAppeared(cameraApp).waitForAndVerify()
83             }
84             teardown { RemoveAllTasksButHomeRule.removeAllTasksButHome() }
85         }
86 
appLayerBecomesVisiblenull87     @Postsubmit @Test override fun appLayerBecomesVisible() = super.appLayerBecomesVisible()
88 
89     @Postsubmit @Test override fun appWindowAsTopWindowAtEnd() = super.appWindowAsTopWindowAtEnd()
90 
91     @Postsubmit @Test override fun appWindowBecomesTopWindow() = super.appWindowBecomesTopWindow()
92 
93     @Postsubmit @Test override fun appWindowBecomesVisible() = super.appWindowBecomesVisible()
94 
95     @Postsubmit @Test override fun appLayerReplacesLauncher() = super.appLayerReplacesLauncher()
96 
97     @Postsubmit @Test override fun appWindowIsTopWindowAtEnd() = super.appWindowIsTopWindowAtEnd()
98 
99     @Postsubmit
100     @Test
101     override fun appWindowReplacesLauncherAsTopWindow() =
102         super.appWindowReplacesLauncherAsTopWindow()
103 
104     @Postsubmit @Test override fun focusChanges() = super.focusChanges()
105 
106     @Postsubmit @Test override fun entireScreenCovered() = super.entireScreenCovered()
107 
108     @Ignore("Not applicable to this CUJ. App is full screen at the end")
109     @Test
110     override fun navBarLayerIsVisibleAtStartAndEnd() = super.navBarLayerIsVisibleAtStartAndEnd()
111 
112     @Postsubmit
113     @Test
114     override fun navBarLayerPositionAtStartAndEnd() = super.navBarLayerPositionAtStartAndEnd()
115 
116     @Postsubmit
117     @Test
118     override fun navBarWindowIsAlwaysVisible() = super.navBarWindowIsAlwaysVisible()
119 
120     @Ignore("Status bar visibility depends on whether the permission dialog is displayed or not")
121     @Test
122     override fun statusBarLayerIsVisibleAtStartAndEnd() =
123         super.statusBarLayerIsVisibleAtStartAndEnd()
124 
125     @Ignore("Status bar visibility depends on whether the permission dialog is displayed or not")
126     @Test
127     override fun statusBarLayerPositionAtStartAndEnd() = super.statusBarLayerPositionAtStartAndEnd()
128 
129     @Ignore("Status bar visibility depends on whether the permission dialog is displayed or not")
130     @Test
131     override fun statusBarWindowIsAlwaysVisible() = super.statusBarWindowIsAlwaysVisible()
132 
133     @Ignore("Not applicable to this CUJ. App is full screen at the end")
134     @Test
135     override fun taskBarLayerIsVisibleAtStartAndEnd() = super.taskBarLayerIsVisibleAtStartAndEnd()
136 
137     @Ignore("Not applicable to this CUJ. App is full screen at the end")
138     @Test
139     override fun taskBarWindowIsAlwaysVisible() = super.taskBarWindowIsAlwaysVisible()
140 
141     @Postsubmit
142     @Test
143     override fun visibleLayersShownMoreThanOneConsecutiveEntry() =
144         super.visibleLayersShownMoreThanOneConsecutiveEntry()
145 
146     @Postsubmit
147     @Test
148     override fun visibleWindowsShownMoreThanOneConsecutiveEntry() =
149         super.visibleWindowsShownMoreThanOneConsecutiveEntry()
150 
151     @Ignore("Not applicable to this CUJ. App is full screen at the end")
152     @Test
153     override fun navBarWindowIsVisibleAtStartAndEnd() {
154         super.navBarWindowIsVisibleAtStartAndEnd()
155     }
156 
157     companion object {
158         /**
159          * Creates the test configurations.
160          *
161          * See [LegacyFlickerTestFactory.nonRotationTests] for configuring screen orientation and
162          * navigation modes.
163          */
164         @Parameterized.Parameters(name = "{0}")
165         @JvmStatic
getParamsnull166         fun getParams() = LegacyFlickerTestFactory.nonRotationTests()
167     }
168 }
169