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.systemui.statusbar.notification.interruption
18 
19 import android.platform.test.annotations.DisableFlags
20 import androidx.test.ext.junit.runners.AndroidJUnit4
21 import androidx.test.filters.SmallTest
22 import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
23 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision
24 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision.FSI_DEVICE_NOT_INTERACTIVE
25 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision.NO_FSI_NOT_IMPORTANT_ENOUGH
26 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision.NO_FSI_SUPPRESSED_BY_DND
27 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision.NO_FSI_SUPPRESSED_ONLY_BY_DND
28 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderWrapper.DecisionImpl
29 import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderWrapper.FullScreenIntentDecisionImpl
30 import java.util.Optional
31 import org.junit.Assert.assertEquals
32 import org.junit.Assert.assertFalse
33 import org.junit.Assert.assertTrue
34 import org.junit.Test
35 import org.junit.runner.RunWith
36 
37 @SmallTest
38 @RunWith(AndroidJUnit4::class)
39 @DisableFlags(VisualInterruptionRefactor.FLAG_NAME)
40 class NotificationInterruptStateProviderWrapperTest : VisualInterruptionDecisionProviderTestBase() {
<lambda>null41     override val provider by lazy {
42         NotificationInterruptStateProviderWrapper(
43             NotificationInterruptStateProviderImpl(
44                 powerManager,
45                 ambientDisplayConfiguration,
46                 batteryController,
47                 statusBarStateController,
48                 keyguardStateController,
49                 headsUpManager,
50                 oldLogger,
51                 mainHandler,
52                 flags,
53                 keyguardNotificationVisibilityProvider,
54                 uiEventLogger,
55                 userTracker,
56                 deviceProvisionedController,
57                 systemClock,
58                 globalSettings,
59                 eventLog,
60                 Optional.of(bubbles)
61             )
62         )
63     }
64 
65     // Tests of internals of the wrapper:
66 
67     @Test
decisionOfTruenull68     fun decisionOfTrue() {
69         assertTrue(DecisionImpl.of(true).shouldInterrupt)
70     }
71 
72     @Test
decisionOfFalsenull73     fun decisionOfFalse() {
74         assertFalse(DecisionImpl.of(false).shouldInterrupt)
75     }
76 
77     @Test
decisionOfTrueInternednull78     fun decisionOfTrueInterned() {
79         assertEquals(DecisionImpl.of(true), DecisionImpl.of(true))
80     }
81 
82     @Test
decisionOfFalseInternednull83     fun decisionOfFalseInterned() {
84         assertEquals(DecisionImpl.of(false), DecisionImpl.of(false))
85     }
86 
87     @Test
fullScreenIntentDecisionShouldInterruptnull88     fun fullScreenIntentDecisionShouldInterrupt() {
89         makeFsiDecision(FSI_DEVICE_NOT_INTERACTIVE).let {
90             assertTrue(it.shouldInterrupt)
91             assertFalse(it.wouldInterruptWithoutDnd)
92         }
93     }
94 
95     @Test
fullScreenIntentDecisionShouldNotInterruptnull96     fun fullScreenIntentDecisionShouldNotInterrupt() {
97         makeFsiDecision(NO_FSI_NOT_IMPORTANT_ENOUGH).let {
98             assertFalse(it.shouldInterrupt)
99             assertFalse(it.wouldInterruptWithoutDnd)
100         }
101     }
102 
103     @Test
fullScreenIntentDecisionWouldInterruptWithoutDndnull104     fun fullScreenIntentDecisionWouldInterruptWithoutDnd() {
105         makeFsiDecision(NO_FSI_SUPPRESSED_ONLY_BY_DND).let {
106             assertFalse(it.shouldInterrupt)
107             assertTrue(it.wouldInterruptWithoutDnd)
108         }
109     }
110 
111     @Test
fullScreenIntentDecisionWouldNotInterruptEvenWithoutDndnull112     fun fullScreenIntentDecisionWouldNotInterruptEvenWithoutDnd() {
113         makeFsiDecision(NO_FSI_SUPPRESSED_BY_DND).let {
114             assertFalse(it.shouldInterrupt)
115             assertFalse(it.wouldInterruptWithoutDnd)
116         }
117     }
118 
makeFsiDecisionnull119     private fun makeFsiDecision(originalDecision: FullScreenIntentDecision) =
120         FullScreenIntentDecisionImpl(NotificationEntryBuilder().build(), originalDecision)
121 }
122