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.notification
18 
19 import android.platform.test.annotations.Postsubmit
20 import android.platform.test.annotations.Presubmit
21 import android.tools.flicker.junit.FlickerParametersRunnerFactory
22 import android.tools.flicker.legacy.FlickerBuilder
23 import android.tools.flicker.legacy.LegacyFlickerTest
24 import android.tools.flicker.legacy.LegacyFlickerTestFactory
25 import android.tools.helpers.wakeUpAndGoToHomeScreen
26 import android.tools.traces.component.ComponentNameMatcher
27 import androidx.test.filters.FlakyTest
28 import androidx.test.filters.RequiresDevice
29 import com.android.server.wm.flicker.helpers.ShowWhenLockedAppHelper
30 import org.junit.FixMethodOrder
31 import org.junit.Ignore
32 import org.junit.Test
33 import org.junit.runner.RunWith
34 import org.junit.runners.MethodSorters
35 import org.junit.runners.Parameterized
36 
37 /**
38  * Test cold launching an app from a notification from the lock screen when there is an app overlaid
39  * on the lock screen.
40  *
41  * This test assumes the device doesn't have AOD enabled
42  *
43  * To run this test:
44  * `atest FlickerTestsNotification:OpenAppFromLockscreenNotificationWithOverlayAppTest`
45  */
46 @RequiresDevice
47 @RunWith(Parameterized::class)
48 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
49 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
50 @Postsubmit
51 class OpenAppFromLockscreenNotificationWithOverlayAppTest(flicker: LegacyFlickerTest) :
52     OpenAppFromLockscreenNotificationColdTest(flicker) {
53     private val showWhenLockedApp = ShowWhenLockedAppHelper(instrumentation)
54 
55     override val transition: FlickerBuilder.() -> Unit
<lambda>null56         get() = {
57             transitions {
58                 device.wakeUp()
59                 // Although we are technically still locked here, the overlay app means we should
60                 // open the
61                 // notification shade as if we were unlocked.
62                 openAppFromNotification()
63                 wmHelper.StateSyncBuilder().withFullScreenApp(testApp).waitForAndVerify()
64             }
65 
66             setup {
67                 device.wakeUpAndGoToHomeScreen()
68                 launchAppAndPostNotification()
69                 clearOverview()
70                 // Launch an activity that is shown when the device is locked
71                 showWhenLockedApp.launchViaIntent(wmHelper)
72                 wmHelper.StateSyncBuilder().withFullScreenApp(showWhenLockedApp).waitForAndVerify()
73 
74                 device.sleep()
75                 wmHelper.StateSyncBuilder().withoutTopVisibleAppWindows().waitForAndVerify()
76             }
77 
78             teardown {
79                 testApp.exit(wmHelper)
80                 showWhenLockedApp.exit(wmHelper)
81             }
82         }
83 
84     @Test
85     @FlakyTest(bugId = 227143265)
showWhenLockedAppWindowBecomesVisiblenull86     fun showWhenLockedAppWindowBecomesVisible() {
87         flicker.assertWm {
88             this.hasNoVisibleAppWindow()
89                 .then()
90                 .isAppWindowOnTop(ComponentNameMatcher.SNAPSHOT, isOptional = true)
91                 .then()
92                 .isAppWindowOnTop(showWhenLockedApp)
93         }
94     }
95 
96     @Test
97     @FlakyTest(bugId = 227143265)
showWhenLockedAppLayerBecomesVisiblenull98     fun showWhenLockedAppLayerBecomesVisible() {
99         flicker.assertLayers {
100             this.isInvisible(showWhenLockedApp)
101                 .then()
102                 .isVisible(ComponentNameMatcher.SNAPSHOT, isOptional = true)
103                 .then()
104                 .isVisible(showWhenLockedApp)
105         }
106     }
107 
108     /** {@inheritDoc} */
appLayerBecomesVisiblenull109     @Presubmit @Test override fun appLayerBecomesVisible() = super.appLayerBecomesVisible()
110 
111     /** {@inheritDoc} */
112     @FlakyTest(bugId = 227143265)
113     @Test
114     override fun visibleLayersShownMoreThanOneConsecutiveEntry() =
115         super.visibleLayersShownMoreThanOneConsecutiveEntry()
116 
117     /** {@inheritDoc} */
118     @Test
119     @Ignore("Not applicable to this CUJ. Display starts off and app is full screen at the end")
120     override fun navBarLayerIsVisibleAtStartAndEnd() {}
121 
122     /** {@inheritDoc} */
123     @Presubmit
124     @Test
navBarWindowIsAlwaysVisiblenull125     override fun navBarWindowIsAlwaysVisible() = super.navBarWindowIsAlwaysVisible()
126 
127     @FlakyTest(bugId = 227143265)
128     @Test
129     override fun entireScreenCovered() = super.entireScreenCovered()
130 
131     @FlakyTest(bugId = 278227468)
132     @Test
133     override fun visibleWindowsShownMoreThanOneConsecutiveEntry() =
134         super.visibleWindowsShownMoreThanOneConsecutiveEntry()
135 
136     companion object {
137         /**
138          * Creates the test configurations.
139          *
140          * See [LegacyFlickerTestFactory.nonRotationTests] for configuring screen orientation and
141          * navigation modes.
142          */
143         @Parameterized.Parameters(name = "{0}")
144         @JvmStatic
145         fun getParams() = LegacyFlickerTestFactory.nonRotationTests()
146     }
147 }
148