1 /* 2 * Copyright (C) 2024 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.policy.ui.dialog 18 19 import android.testing.TestableLooper 20 import androidx.test.ext.junit.runners.AndroidJUnit4 21 import androidx.test.filters.SmallTest 22 import com.android.internal.logging.testing.UiEventLoggerFake 23 import com.android.settingslib.notification.modes.TestModeBuilder 24 import com.android.systemui.SysuiTestCase 25 import com.android.systemui.qs.QSModesEvent 26 import com.google.common.truth.Truth.assertThat 27 import org.junit.Test 28 import org.junit.runner.RunWith 29 30 @SmallTest 31 @RunWith(AndroidJUnit4::class) 32 @TestableLooper.RunWithLooper 33 class ModesDialogEventLoggerTest : SysuiTestCase() { 34 35 private val uiEventLogger = UiEventLoggerFake() 36 private val underTest = ModesDialogEventLogger(uiEventLogger) 37 38 @Test testLogModeOn_manualnull39 fun testLogModeOn_manual() { 40 underTest.logModeOn(TestModeBuilder.MANUAL_DND_INACTIVE) 41 42 assertThat(uiEventLogger.numLogs()).isEqualTo(1) 43 uiEventLogger[0].match(QSModesEvent.QS_MODES_DND_ON, "android") 44 } 45 46 @Test testLogModeOff_manualnull47 fun testLogModeOff_manual() { 48 underTest.logModeOff(TestModeBuilder.MANUAL_DND_ACTIVE) 49 50 assertThat(uiEventLogger.numLogs()).isEqualTo(1) 51 uiEventLogger[0].match(QSModesEvent.QS_MODES_DND_OFF, "android") 52 } 53 54 @Test testLogModeSettings_manualnull55 fun testLogModeSettings_manual() { 56 underTest.logModeSettings(TestModeBuilder.MANUAL_DND_ACTIVE) 57 58 assertThat(uiEventLogger.numLogs()).isEqualTo(1) 59 uiEventLogger[0].match(QSModesEvent.QS_MODES_DND_SETTINGS, "android") 60 } 61 62 @Test testLogModeOn_automaticnull63 fun testLogModeOn_automatic() { 64 underTest.logModeOn(TestModeBuilder().setActive(true).setPackage("pkg1").build()) 65 66 assertThat(uiEventLogger.numLogs()).isEqualTo(1) 67 uiEventLogger[0].match(QSModesEvent.QS_MODES_MODE_ON, "pkg1") 68 } 69 70 @Test testLogModeOff_automaticnull71 fun testLogModeOff_automatic() { 72 underTest.logModeOff(TestModeBuilder().setActive(false).setPackage("pkg2").build()) 73 74 assertThat(uiEventLogger.numLogs()).isEqualTo(1) 75 uiEventLogger[0].match(QSModesEvent.QS_MODES_MODE_OFF, "pkg2") 76 } 77 78 @Test testLogModeSettings_automaticnull79 fun testLogModeSettings_automatic() { 80 underTest.logModeSettings(TestModeBuilder().setPackage("pkg3").build()) 81 82 assertThat(uiEventLogger.numLogs()).isEqualTo(1) 83 uiEventLogger[0].match(QSModesEvent.QS_MODES_MODE_SETTINGS, "pkg3") 84 } 85 86 @Test testLogOpenDurationDialog_manualnull87 fun testLogOpenDurationDialog_manual() { 88 underTest.logOpenDurationDialog(TestModeBuilder.MANUAL_DND_INACTIVE) 89 90 assertThat(uiEventLogger.numLogs()).isEqualTo(1) 91 // package not logged for duration dialog as it only applies to manual mode 92 uiEventLogger[0].match(QSModesEvent.QS_MODES_DURATION_DIALOG, null) 93 } 94 95 @Test testLogOpenDurationDialog_automatic_doesNotLognull96 fun testLogOpenDurationDialog_automatic_doesNotLog() { 97 underTest.logOpenDurationDialog( 98 TestModeBuilder().setActive(false).setPackage("mypkg").build() 99 ) 100 101 // ignore calls to open dialog on something other than the manual rule (shouldn't happen) 102 assertThat(uiEventLogger.numLogs()).isEqualTo(0) 103 } 104 105 @Test testLogDialogSettingsnull106 fun testLogDialogSettings() { 107 underTest.logDialogSettings() 108 assertThat(uiEventLogger.numLogs()).isEqualTo(1) 109 uiEventLogger[0].match(QSModesEvent.QS_MODES_SETTINGS, null) 110 } 111 matchnull112 private fun UiEventLoggerFake.FakeUiEvent.match(event: QSModesEvent, modePackage: String?) { 113 assertThat(eventId).isEqualTo(event.id) 114 assertThat(packageName).isEqualTo(modePackage) 115 } 116 } 117