diff options
-rw-r--r-- | res/raw/watch_info.ogg | bin | 0 -> 36497 bytes | |||
-rw-r--r-- | src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java | 9 | ||||
-rw-r--r-- | tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertAudioTest.java | 48 |
3 files changed, 56 insertions, 1 deletions
diff --git a/res/raw/watch_info.ogg b/res/raw/watch_info.ogg Binary files differnew file mode 100644 index 000000000..2b9bed7ba --- /dev/null +++ b/res/raw/watch_info.ogg diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java index b6581d553..b59ccca56 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java @@ -32,6 +32,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.res.AssetFileDescriptor; import android.content.res.Resources; import android.hardware.camera2.CameraAccessException; @@ -540,7 +541,13 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI break; case INFO: case AREA: - mMediaPlayer.setDataSource(this, Settings.System.DEFAULT_NOTIFICATION_URI); + if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) { + //TODO(b/279183006): remove watch workaround when URI supported. + setDataSourceFromResource(res, mMediaPlayer, R.raw.watch_info); + } else { + mMediaPlayer.setDataSource(this, + Settings.System.DEFAULT_NOTIFICATION_URI); + } break; case TEST: case DEFAULT: diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertAudioTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertAudioTest.java index 6cb54d98d..ac5544c5c 100644 --- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertAudioTest.java +++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertAudioTest.java @@ -119,6 +119,15 @@ public class CellBroadcastAlertAudioTest extends super.tearDown(); } + private Intent createStartAudioIntent() { + Intent intent = new Intent(mContext, CellBroadcastAlertAudio.class); + intent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_MESSAGE_BODY, + TEST_MESSAGE_BODY); + intent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_VIBRATION_PATTERN_EXTRA, + TEST_VIBRATION_PATTERN); + return intent; + } + public void testStartService() throws Throwable { PhoneStateListenerHandler phoneStateListenerHandler = new PhoneStateListenerHandler( "testStartService", @@ -145,6 +154,45 @@ public class CellBroadcastAlertAudioTest extends phoneStateListenerHandler.quit(); } + public void testPlayAlertToneInfo() throws Throwable { + setWatchFeatureEnabled(false); + doReturn(AudioManager.RINGER_MODE_NORMAL).when( + mMockedAudioManager).getRingerMode(); + PhoneStateListenerHandler phoneStateListenerHandler = new PhoneStateListenerHandler( + "testPlayAlertToneInfo", + () -> { + Intent intent = createStartAudioIntent(); + intent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_TONE_TYPE, + CellBroadcastAlertService.AlertType.INFO); + startService(intent); + }); + phoneStateListenerHandler.start(); + waitUntilReady(); + verify(mMockedAudioManager).getRingerMode(); + verify(mMockedVibrator).vibrate(any(), any(AudioAttributes.class)); + phoneStateListenerHandler.quit(); + } + + public void testPlayAlertToneInfoForWatch() throws Throwable { + setWatchFeatureEnabled(true); + doReturn(AudioManager.RINGER_MODE_NORMAL).when( + mMockedAudioManager).getRingerMode(); + PhoneStateListenerHandler phoneStateListenerHandler = new PhoneStateListenerHandler( + "testPlayAlertToneInfoForWatch", + () -> { + + Intent intent = createStartAudioIntent(); + intent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_TONE_TYPE, + CellBroadcastAlertService.AlertType.INFO); + startService(intent); + }); + phoneStateListenerHandler.start(); + waitUntilReady(); + verify(mMockedAudioManager).getRingerMode(); + verify(mMockedVibrator).vibrate(any(), any(AudioAttributes.class)); + phoneStateListenerHandler.quit(); + } + /** * If the user is currently not in a call and the override DND flag is set, the volume will be * set to max. |