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.platform.test.rule.SettingOverrideRule
22 import android.provider.Settings
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.helpers.wakeUpAndGoToHomeScreen
28 import android.tools.traces.component.ComponentNameMatcher
29 import androidx.test.filters.RequiresDevice
30 import org.junit.ClassRule
31 import org.junit.FixMethodOrder
32 import org.junit.Ignore
33 import org.junit.Test
34 import org.junit.runner.RunWith
35 import org.junit.runners.MethodSorters
36 import org.junit.runners.Parameterized
37 
38 /**
39  * Test cold launching an app from a notification from the lock screen.
40  *
41  * This test assumes the device doesn't have AOD enabled
42  *
43  * To run this test: `atest FlickerTestsNotification:OpenAppFromLockscreenNotificationColdTest`
44  */
45 @RequiresDevice
46 @RunWith(Parameterized::class)
47 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
48 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
49 @Postsubmit
50 open class OpenAppFromLockscreenNotificationColdTest(flicker: LegacyFlickerTest) :
51     OpenAppFromNotificationColdTest(flicker) {
52 
53     override val transition: FlickerBuilder.() -> Unit
<lambda>null54         get() = {
55             transitions {
56                 device.wakeUp()
57                 openAppFromLockNotification()
58             }
59 
60             // Needs to run at the end of the setup, so after the setup defined in super.transition
61             setup {
62                 device.wakeUpAndGoToHomeScreen()
63                 launchAppAndPostNotification()
64                 clearOverview()
65                 device.sleep()
66                 wmHelper.StateSyncBuilder().withoutTopVisibleAppWindows().waitForAndVerify()
67             }
68 
69             teardown { testApp.exit(wmHelper) }
70         }
71 
72     /** {@inheritDoc} */
navBarLayerPositionAtStartAndEndnull73     @Test @Ignore("Display is off at the start") override fun navBarLayerPositionAtStartAndEnd() {}
74 
75     /** {@inheritDoc} */
76     @Test
77     @Ignore("Display is off at the start")
statusBarLayerPositionAtStartAndEndnull78     override fun statusBarLayerPositionAtStartAndEnd() {}
79 
80     /** {@inheritDoc} */
81     @Test
82     @Ignore("Display is off at the start")
taskBarLayerIsVisibleAtStartAndEndnull83     override fun taskBarLayerIsVisibleAtStartAndEnd() {}
84 
85     /** {@inheritDoc} */
taskBarWindowIsAlwaysVisiblenull86     @Test @Ignore("Display is off at the start") override fun taskBarWindowIsAlwaysVisible() {}
87 
88     /** {@inheritDoc} */
89     @Test
90     @Ignore("Display is off at the start")
statusBarLayerIsVisibleAtStartAndEndnull91     override fun statusBarLayerIsVisibleAtStartAndEnd() =
92         super.statusBarLayerIsVisibleAtStartAndEnd()
93 
94     /** {@inheritDoc} */
95     @Test
96     @Ignore("Not applicable to this CUJ. Display starts locked and app is full screen at the end")
97     override fun navBarWindowIsVisibleAtStartAndEnd() = super.navBarWindowIsVisibleAtStartAndEnd()
98 
99     /** {@inheritDoc} */
100     @Test
101     @Ignore("Not applicable to this CUJ. Display starts locked and app is full screen at the end")
102     override fun navBarLayerIsVisibleAtStartAndEnd() = super.navBarLayerIsVisibleAtStartAndEnd()
103 
104     /** {@inheritDoc} */
105     @Test
106     @Ignore("Not applicable to this CUJ. Display starts locked and app is full screen at the end")
107     override fun navBarWindowIsAlwaysVisible() {}
108 
109     /** {@inheritDoc} */
110     @Postsubmit
111     @Test
visibleLayersShownMoreThanOneConsecutiveEntrynull112     override fun visibleLayersShownMoreThanOneConsecutiveEntry() =
113         super.visibleLayersShownMoreThanOneConsecutiveEntry()
114 
115     @Presubmit
116     @Test
117     override fun visibleWindowsShownMoreThanOneConsecutiveEntry() {
118         flicker.assertWm {
119             this.visibleWindowsShownMoreThanOneConsecutiveEntry(
120                 listOf(
121                     ComponentNameMatcher.SPLASH_SCREEN,
122                     ComponentNameMatcher.SNAPSHOT,
123                     ComponentNameMatcher.SECONDARY_HOME_HANDLE,
124                     Consts.IMAGE_WALLPAPER
125                 )
126             )
127         }
128     }
129 
130     companion object {
131         /**
132          * Creates the test configurations.
133          *
134          * See [LegacyFlickerTestFactory.nonRotationTests] for configuring screen orientation and
135          * navigation modes.
136          */
137         @Parameterized.Parameters(name = "{0}")
138         @JvmStatic
getParamsnull139         fun getParams() = LegacyFlickerTestFactory.nonRotationTests()
140 
141         /**
142          * Ensures that posted notifications will be visible on the lockscreen and not suppressed
143          * due to being marked as seen.
144          */
145         @ClassRule
146         @JvmField
147         val disableUnseenNotifFilterRule =
148             SettingOverrideRule(
149                 Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS,
150                 /* value = */ "0",
151             )
152     }
153 }
154