diff options
author | Youngtae Cha <youngtaecha@google.com> | 2022-12-15 08:07:00 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-12-15 08:07:00 +0000 |
commit | 4eb0d955a3ff2876a54b029a176f899b4dfeb733 (patch) | |
tree | b579106533e761e3a810e09b10717388fc66e7c9 | |
parent | 78a4263ff0a394a2346018de73b67c976aa1f310 (diff) | |
parent | 268a0509eaecd9df46ffa063545763a8f5161f96 (diff) | |
download | CellBroadcastReceiver-4eb0d955a3ff2876a54b029a176f899b4dfeb733.tar.gz |
Merge "Support mute feature for each channel" into tm-mainline-prod
5 files changed, 82 insertions, 7 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java index cbfbd44ad..b6581d553 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java @@ -416,7 +416,7 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI } } - if (mEnableAudio || mEnableVibrate) { + if ((mEnableAudio || mEnableVibrate) && (mAlertType != AlertType.MUTE)) { playAlertTone(mAlertType, mVibrationPattern); } else { if (DBG) log("No audio/vibrate playing. Stop CellBroadcastAlertAudio service"); diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java index 566d0bb3c..d2788df73 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java @@ -162,6 +162,7 @@ public class CellBroadcastAlertService extends Service { TEST, AREA, INFO, + MUTE, OTHER } @@ -717,6 +718,7 @@ public class CellBroadcastAlertService extends Service { message.getSubscriptionId()); audioIntent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_DURATION, (range != null) ? range.mAlertDuration : -1); + startService(audioIntent); ArrayList<SmsCbMessage> messageList = new ArrayList<>(); diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertAudioTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertAudioTest.java index 2bb87cb96..724e97cd6 100644 --- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertAudioTest.java +++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertAudioTest.java @@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -38,6 +39,7 @@ import android.speech.tts.TextToSpeech; import android.telephony.TelephonyManager; import com.android.cellbroadcastreceiver.CellBroadcastAlertAudio; +import com.android.cellbroadcastreceiver.CellBroadcastAlertService; import com.android.cellbroadcastreceiver.CellBroadcastSettings; import org.junit.After; @@ -338,4 +340,39 @@ public class CellBroadcastAlertAudioTest extends phoneStateListenerHandler.quit(); waitUntilReady(); } + + /** + * Even the user is currently not in a call and the override DND flag is set, the alert is + * set to mute. + */ + public void testStartServiceMuteWithOverrideDnd() throws Throwable { + PhoneStateListenerHandler phoneStateListenerHandler = new PhoneStateListenerHandler( + "testStartServiceMuteWithOverrideDnd", + () -> { + doReturn(AudioManager.RINGER_MODE_SILENT).when( + mMockedAudioManager).getRingerMode(); + doReturn(TelephonyManager.CALL_STATE_IDLE).when( + mMockedTelephonyManager).getCallState(); + doReturn(TEST_MAX_VOLUME).when(mMockedAudioManager).getStreamMaxVolume( + anyInt()); + + Intent intent = new Intent(mContext, CellBroadcastAlertAudio.class); + intent.setAction(SHOW_NEW_ALERT_ACTION); + intent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_MESSAGE_BODY, + TEST_MESSAGE_BODY); + intent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_VIBRATION_PATTERN_EXTRA, + TEST_VIBRATION_PATTERN); + intent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_OVERRIDE_DND_EXTRA, true); + intent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_TONE_TYPE, + CellBroadcastAlertService.AlertType.MUTE); + startService(intent); + }); + phoneStateListenerHandler.start(); + waitUntilReady(); + verify(mMockedAudioManager).getRingerMode(); + verify(mMockedVibrator, never()).vibrate(any(), any(AudioAttributes.class)); + verify(mMockedTelephonyManager, never()).getCallState(); + verify(mMockedAudioManager, never()).requestAudioFocus(any(), any(), anyInt(), anyInt()); + phoneStateListenerHandler.quit(); + } } diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertServiceTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertServiceTest.java index 2bdb61c36..704d70e13 100644 --- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertServiceTest.java +++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertServiceTest.java @@ -20,6 +20,7 @@ import static com.android.cellbroadcastreceiver.CellBroadcastAlertAudio.ALERT_AU import static com.android.cellbroadcastreceiver.CellBroadcastAlertService.SHOW_NEW_ALERT_ACTION; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertNotEquals; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; @@ -518,4 +519,31 @@ public class CellBroadcastAlertServiceTest extends assertTrue("Should display the message", cellBroadcastAlertService.shouldDisplayMessage(message3)); } + + public void testMuteAlert() { + doReturn(new String[]{ + "0x1113:rat=gsm, type=mute, emergency=true, always_on=true", + "0x112F:rat=gsm, emergency=true"}).when(mResources).getStringArray( + eq(com.android.cellbroadcastreceiver.R.array + .additional_cbs_channels_strings)); + + Intent intent = new Intent(mContext, CellBroadcastAlertService.class); + intent.setAction(SHOW_NEW_ALERT_ACTION); + + SmsCbMessage message = createMessageForCmasMessageClass(13788634, 0x1113, 0x1113); + intent.putExtra("message", message); + startService(intent); + waitForServiceIntent(); + + assertEquals(CellBroadcastAlertService.AlertType.MUTE, + mServiceIntentToVerify.getSerializableExtra(ALERT_AUDIO_TONE_TYPE)); + + message = createMessageForCmasMessageClass(14788634, 0x112F, 0x112F); + intent.putExtra("message", message); + startService(intent); + waitForServiceIntent(); + + assertNotEquals(CellBroadcastAlertService.AlertType.MUTE, + mServiceIntentToVerify.getSerializableExtra(ALERT_AUDIO_TONE_TYPE)); + } } diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastChannelManagerTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastChannelManagerTest.java index e9abecf9e..f52069886 100644 --- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastChannelManagerTest.java +++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastChannelManagerTest.java @@ -57,7 +57,9 @@ public class CellBroadcastChannelManagerTest extends CellBroadcastTest { "0xA901:type=test, emergency=true, pulsation=0xFFFFFFFF", "0xA902:type=test, emergency=true, pulsation=0xFFFFFFFF|30000", "0xA903:type=test, emergency=true, pulsation=0xFFFFFFFF|30000|1000|1000", + "0x1113:type=mute, emergency=true, always_on=true", "0x111E:debug_build=true"}; + private static final String[] CHANNEL_CONFIG2 = { "12:type=etws_earthquake, emergency=true, display=true, always_on=false", "456:type=etws_tsunami, emergency=true, alert_duration=20000, scope=domestic", @@ -119,7 +121,7 @@ public class CellBroadcastChannelManagerTest extends CellBroadcastTest { private void verifyChannelRangesForConfig1(List<CellBroadcastChannelRange> list) throws Exception { - assertEquals(9, list.size()); + assertEquals(10, list.size()); assertEquals(12, list.get(0).mStartId); assertEquals(12, list.get(0).mEndId); @@ -192,23 +194,29 @@ public class CellBroadcastChannelManagerTest extends CellBroadcastTest { assertFalse(list.get(5).mDisplayDialogWithNotification); assertEquals(0xA901, list.get(6).mStartId); - assertEquals(0xA901, list.get(6).mStartId); + assertEquals(0xA901, list.get(6).mEndId); assertEquals(1, list.get(6).mPulsationPattern.length); assertEquals(0xFFFFFFFF, list.get(6).mPulsationPattern[0]); assertEquals(0xA902, list.get(7).mStartId); - assertEquals(0xA902, list.get(7).mStartId); + assertEquals(0xA902, list.get(7).mEndId); assertEquals(2, list.get(7).mPulsationPattern.length); assertEquals(0xFFFFFFFF, list.get(7).mPulsationPattern[0]); assertEquals(30000, list.get(7).mPulsationPattern[1]); assertEquals(0xA903, list.get(8).mStartId); - assertEquals(0xA903, list.get(8).mStartId); + assertEquals(0xA903, list.get(8).mEndId); assertEquals(4, list.get(8).mPulsationPattern.length); assertEquals(0xFFFFFFFF, list.get(8).mPulsationPattern[0]); assertEquals(30000, list.get(8).mPulsationPattern[1]); assertEquals(1000, list.get(8).mPulsationPattern[2]); assertEquals(1000, list.get(8).mPulsationPattern[3]); + + assertEquals(0x1113, list.get(9).mStartId); + assertEquals(0x1113, list.get(9).mEndId); + assertEquals(AlertType.MUTE, list.get(9).mAlertType); + assertEquals(CellBroadcastChannelRange.LEVEL_EMERGENCY, list.get(9).mEmergencyLevel); + assertTrue(list.get(9).mAlwaysOn); } private void verifyChannelRangesForConfig2(List<CellBroadcastChannelRange> list) @@ -289,9 +297,9 @@ public class CellBroadcastChannelManagerTest extends CellBroadcastTest { ranges = mChannelManager2.getAllCellBroadcastChannelRanges(); - assertEquals(13, ranges.size()); + assertEquals(14, ranges.size()); verifyChannelRangesForConfig2(new ArrayList<>(ranges).subList(0, 3)); - verifyChannelRangesForConfig1(new ArrayList<>(ranges).subList(4, 13)); + verifyChannelRangesForConfig1(new ArrayList<>(ranges).subList(4, 14)); } @Test |