• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.settings.notification;
18 
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22 
23 import android.content.Context;
24 import android.platform.test.annotations.EnableFlags;
25 import android.platform.test.flag.junit.SetFlagsRule;
26 import android.provider.Settings;
27 
28 import androidx.annotation.Nullable;
29 import androidx.preference.Preference;
30 import androidx.test.core.app.ApplicationProvider;
31 
32 import com.android.server.notification.Flags;
33 
34 import org.junit.Before;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.MockitoAnnotations;
39 import org.robolectric.RobolectricTestRunner;
40 import org.robolectric.RuntimeEnvironment;
41 
42 @RunWith(RobolectricTestRunner.class)
43 @EnableFlags(Flags.FLAG_NOTIFICATION_LOCK_SCREEN_SETTINGS)
44 public class LockScreenWhatToShowControllerTest {
45 
46     @Rule
47     public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
48 
49     private static final String PREFERENCE_KEY = "lockscreen_notification_what_to_show";
50 
51     private LockScreenWhatToShowController mController;
52     private Context mContext;
53     @Nullable
54     private Preference mPreference;
55 
56     @Before
setUp()57     public void setUp() {
58         mContext = ApplicationProvider.getApplicationContext();
59         MockitoAnnotations.initMocks(this);
60         mController = new LockScreenWhatToShowController(
61                 RuntimeEnvironment.application,
62                 PREFERENCE_KEY);
63         mPreference = new Preference(mContext);
64         mPreference.setKey(PREFERENCE_KEY);
65     }
66 
67     @Test
updateState_preferenceVisibleWhenSettingIsOn()68     public void updateState_preferenceVisibleWhenSettingIsOn() {
69         // Before: the show LOCK_SCREEN_SHOW_NOTIFICATIONS setting is on
70         Settings.Secure.putInt(
71                 mContext.getContentResolver(),
72                 Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
73                 LockScreenNotificationsGlobalPreferenceController.ON
74         );
75 
76         // When: update state
77         mController.updateState(mPreference);
78 
79         // Then: the preference is visible
80         assertNotNull(mPreference);
81         assertTrue(mPreference.isVisible());
82     }
83 
84     @Test
updateState_preferenceInvisibleWhenSettingIsOff()85     public void updateState_preferenceInvisibleWhenSettingIsOff() {
86         // Before: the show LOCK_SCREEN_SHOW_NOTIFICATIONS setting is off
87         Settings.Secure.putInt(
88                 mContext.getContentResolver(),
89                 Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
90                 LockScreenNotificationsGlobalPreferenceController.OFF
91         );
92 
93         // When: update state
94         mController.updateState(mPreference);
95 
96         // Then: the preference is not visible
97         assertNotNull(mPreference);
98         assertFalse(mPreference.isVisible());
99     }
100 }
101