From 25e7ce5b1aa7cb4ed0ade99c99f7e0ef77207830 Mon Sep 17 00:00:00 2001 From: Deepak Kundra Date: Tue, 24 May 2016 15:52:59 -0700 Subject: Support playing the alert and vibrate until dismissed Issue-id:FEIJ-507 Change-Id: I647c21ef17c6e41f8b1a74144fa4b19226d21080 --- .../cellbroadcastreceiver/CellBroadcastAlertAudio.java | 17 ++++++++++++----- .../CellBroadcastAlertService.java | 5 ++++- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java index 2381689f..989124d6 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java @@ -275,6 +275,8 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI // This extra should always be provided by CellBroadcastAlertService, // but default to 10.5 seconds just to be safe (CMAS requirement). int duration = intent.getIntExtra(ALERT_AUDIO_DURATION_EXTRA, 10500); + if (DBG) log(TAG + "Recvd intent = " + intent + " hasExtras = " + + intent.hasExtra(ALERT_AUDIO_DURATION_EXTRA) + duration); // Get text to speak (if enabled by user) mMessageBody = intent.getStringExtra(ALERT_AUDIO_MESSAGE_BODY); @@ -339,9 +341,9 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI if (DBG) log("play()"); - // Start the vibration first. + // Start the vibration first, can be set to 0 = "Till Alert Dialog Dismissed" if (mEnableVibrate) { - mVibrator.vibrate(sVibratePattern, -1); + mVibrator.vibrate(sVibratePattern, (duration!=0 ? -1 : 0)); } if (mEnableAudio) { @@ -377,8 +379,10 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI } } - // stop alert after the specified duration - mHandler.sendMessageDelayed(mHandler.obtainMessage(ALERT_SOUND_FINISHED), duration); + // stop alert after the specified duration, can be set to 0 = "Till Alert Dialog Dismissed" + if (DBG) log(TAG + " play() alert duration = " + duration); + if(duration!=0) mHandler.sendMessageDelayed(mHandler.obtainMessage(ALERT_SOUND_FINISHED), + duration); mState = STATE_ALERTING; } @@ -421,7 +425,7 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI * Stops alert audio and speech. */ public void stop() { - if (DBG) log("stop()"); + if (DBG) log("stop() state = " + mState); if (mPlayReminderIntent != null) { mPlayReminderIntent.cancel(); @@ -453,6 +457,9 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI // catch "Unable to retrieve AudioTrack pointer for stop()" exception loge("exception trying to stop text-to-speech"); } + + // Stop vibrator + mVibrator.cancel(); } mState = STATE_IDLE; diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java index 75de2c09..d2f8394b 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java @@ -347,10 +347,13 @@ public class CellBroadcastAlertService extends Service { audioIntent.setAction(CellBroadcastAlertAudio.ACTION_START_ALERT_AUDIO); int duration; // alert audio duration in ms - if (message.isCmasMessage()) { + if (message.isCmasMessage() && + (this.getResources().getBoolean(R.bool.use_sound_duration) == false)) { + Log.d(TAG, "isCmasMessage == true"); // CMAS requirement: duration of the audio attention signal is 10.5 seconds. duration = 10500; } else { + Log.d(TAG, "isCmasMessage == false"); duration = SubscriptionManager.getIntegerSubscriptionProperty(message.getSubId(), SubscriptionManager.CB_ALERT_SOUND_DURATION, Integer.parseInt(CellBroadcastSettings.ALERT_SOUND_DEFAULT_DURATION), this) -- cgit v1.2.3