• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.spy;
22 import static org.mockito.Mockito.when;
23 
24 import android.app.NotificationManager;
25 import android.content.ComponentName;
26 import android.content.Context;
27 import android.content.res.Resources;
28 import android.media.AudioManager;
29 import android.os.Vibrator;
30 import android.provider.DeviceConfig;
31 import android.telephony.TelephonyManager;
32 
33 import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
34 import com.android.settings.testutils.shadow.ShadowDeviceConfig;
35 
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mock;
40 import org.mockito.MockitoAnnotations;
41 import org.robolectric.RobolectricTestRunner;
42 import org.robolectric.RuntimeEnvironment;
43 import org.robolectric.annotation.Config;
44 import org.robolectric.shadows.ShadowApplication;
45 
46 @RunWith(RobolectricTestRunner.class)
47 @Config(shadows = {ShadowDeviceConfig.class})
48 public class SeparateRingVolumePreferenceControllerTest {
49 
50     @Mock
51     private AudioHelper mHelper;
52     @Mock
53     private TelephonyManager mTelephonyManager;
54     @Mock
55     private AudioManager mAudioManager;
56     @Mock
57     private Vibrator mVibrator;
58     @Mock
59     private NotificationManager mNotificationManager;
60     @Mock
61     private ComponentName mSuppressor;
62     @Mock
63     private Resources mResources;
64 
65     private Context mContext;
66 
67     private SeparateRingVolumePreferenceController mController;
68 
69     @Before
setUp()70     public void setUp() {
71         MockitoAnnotations.initMocks(this);
72         ShadowApplication shadowContext = ShadowApplication.getInstance();
73         shadowContext.setSystemService(Context.TELEPHONY_SERVICE, mTelephonyManager);
74         shadowContext.setSystemService(Context.AUDIO_SERVICE, mAudioManager);
75         shadowContext.setSystemService(Context.VIBRATOR_SERVICE, mVibrator);
76         shadowContext.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
77         mContext = spy(RuntimeEnvironment.application);
78         when(mNotificationManager.getEffectsSuppressor()).thenReturn(mSuppressor);
79         when(mContext.getResources()).thenReturn(mResources);
80         mController = new SeparateRingVolumePreferenceController(mContext);
81         mController.setAudioHelper(mHelper);
82     }
83 
84     @Test
isAvailable_ringNotificationAliased_shouldReturnFalse()85     public void isAvailable_ringNotificationAliased_shouldReturnFalse() {
86         when(mHelper.isSingleVolume()).thenReturn(true);
87         when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
88 
89         assertThat(mController.isAvailable()).isFalse();
90     }
91 
92     /**
93      * Maintain that the device does not need to be voice capable to display this slider
94      */
95     @Test
isAvailable_ringNotificationSeparated_isNotVoiceCapable_shouldReturnTrue()96     public void isAvailable_ringNotificationSeparated_isNotVoiceCapable_shouldReturnTrue() {
97         DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
98                 SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
99         when(mHelper.isSingleVolume()).thenReturn(false);
100         when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
101 
102         assertThat(mController.isAvailable()).isTrue();
103     }
104 
105     @Test
getAudioStream_shouldReturnRing()106     public void getAudioStream_shouldReturnRing() {
107         assertThat(mController.getAudioStream()).isEqualTo(AudioManager.STREAM_RING);
108     }
109 
110     @Test
isSliceableCorrectKey_returnsTrue()111     public void isSliceableCorrectKey_returnsTrue() {
112         final SeparateRingVolumePreferenceController controller =
113                 new SeparateRingVolumePreferenceController(mContext);
114         assertThat(controller.isSliceable()).isTrue();
115     }
116 
117     @Test
isPublicSlice_returnTrue()118     public void isPublicSlice_returnTrue() {
119         assertThat(mController.isPublicSlice()).isTrue();
120     }
121 
122 }
123