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.volume; 18 19 import static android.media.AudioManager.CSD_WARNING_DOSE_REACHED_1X; 20 import static android.media.AudioManager.CSD_WARNING_DOSE_REPEATED_5X; 21 22 import static org.mockito.Mockito.any; 23 import static org.mockito.Mockito.eq; 24 import static org.mockito.Mockito.mock; 25 import static org.mockito.Mockito.verify; 26 27 import android.app.Notification; 28 import android.app.NotificationManager; 29 import android.media.AudioManager; 30 import android.test.suitebuilder.annotation.SmallTest; 31 import android.testing.AndroidTestingRunner; 32 import android.testing.TestableLooper; 33 34 import com.android.internal.messages.nano.SystemMessageProto; 35 import com.android.systemui.SysuiTestCase; 36 import com.android.systemui.util.concurrency.FakeExecutor; 37 import com.android.systemui.util.time.FakeSystemClock; 38 39 import org.junit.Before; 40 import org.junit.Test; 41 import org.junit.runner.RunWith; 42 43 @SmallTest 44 @RunWith(AndroidTestingRunner.class) 45 @TestableLooper.RunWithLooper 46 public class CsdWarningDialogTest extends SysuiTestCase { 47 48 private NotificationManager mNotificationManager; 49 private AudioManager mAudioManager; 50 51 @Before setup()52 public void setup() { 53 mNotificationManager = mock(NotificationManager.class); 54 getContext().addMockSystemService(NotificationManager.class, mNotificationManager); 55 56 mAudioManager = mock(AudioManager.class); 57 getContext().addMockSystemService(AudioManager.class, mAudioManager); 58 } 59 60 @Test create1XCsdDialogAndWait_sendsNotification()61 public void create1XCsdDialogAndWait_sendsNotification() { 62 FakeExecutor executor = new FakeExecutor(new FakeSystemClock()); 63 // instantiate directly instead of via factory; we don't want executor to be @Background 64 CsdWarningDialog dialog = new CsdWarningDialog(CSD_WARNING_DOSE_REACHED_1X, mContext, 65 mAudioManager, mNotificationManager, executor, null); 66 67 dialog.show(); 68 executor.advanceClockToLast(); 69 executor.runAllReady(); 70 dialog.dismiss(); 71 72 verify(mNotificationManager).notify( 73 eq(SystemMessageProto.SystemMessage.NOTE_CSD_LOWER_AUDIO), any(Notification.class)); 74 } 75 76 @Test create5XCsdDiSalogAndWait_willSendNotification()77 public void create5XCsdDiSalogAndWait_willSendNotification() { 78 FakeExecutor executor = new FakeExecutor(new FakeSystemClock()); 79 CsdWarningDialog dialog = new CsdWarningDialog(CSD_WARNING_DOSE_REPEATED_5X, mContext, 80 mAudioManager, mNotificationManager, executor, null); 81 82 dialog.show(); 83 84 verify(mNotificationManager).notify( 85 eq(SystemMessageProto.SystemMessage.NOTE_CSD_LOWER_AUDIO), any(Notification.class)); 86 } 87 } 88