summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorTony Hill <tonyhill@motorola.com>2015-11-04 14:08:13 +0000
committerJack Yu <jackyu@google.com>2015-12-31 00:09:08 +0000
commit989e0de22d0f915e17785623ffe1b9820787aeda (patch)
treea8bf9b043b22d61c58291a45d5a843b6bbd84ba9 /src/com
parent802f1d5baa573c31bd039dec3ccdf39f0241bea7 (diff)
downloadandroid_packages_apps_CellBroadcastReceiver-989e0de22d0f915e17785623ffe1b9820787aeda.tar.gz
android_packages_apps_CellBroadcastReceiver-989e0de22d0f915e17785623ffe1b9820787aeda.tar.bz2
android_packages_apps_CellBroadcastReceiver-989e0de22d0f915e17785623ffe1b9820787aeda.zip
Support CMAS regulatory requirements
Fixes an issue where the 10.5s CMAS alert audio can be truncated because the code relied on a timer and assumed playback would start with zero lag. The alert audio file is changed to include the full 10.5s alert sequence and is played in full without a timer if the requested duration is 10.5s. Change-Id: I0fff72579cad74bdb0ef5ab2fe6be8daf5c3b837 BZ: 25728174
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java
index 32f38aa4..d03e67a1 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java
@@ -25,6 +25,7 @@ import android.content.res.Resources;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
+import android.media.MediaPlayer.OnCompletionListener;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
@@ -85,6 +86,9 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI
/** Pause duration between alert sound and alert speech. */
private static final int PAUSE_DURATION_BEFORE_SPEAKING_MSEC = 1000;
+ /** Duration of a CMAS alert. */
+ private static final int CMAS_DURATION_MSEC = 10500;
+
/** Vibration uses the same on/off pattern as the CMAS alert tone */
private static final long[] sVibratePattern = { 0, 2000, 500, 1000, 500, 1000, 500,
2000, 500, 1000, 500, 1000};
@@ -296,7 +300,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);
+ int duration = intent.getIntExtra(ALERT_AUDIO_DURATION_EXTRA, CMAS_DURATION_MSEC);
+ if (DBG) log("Duration: " + duration);
// Get text to speak (if enabled by user)
mMessageBody = intent.getStringExtra(ALERT_AUDIO_MESSAGE_BODY);
@@ -380,6 +385,14 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI
}
});
+ mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
+ public void onCompletion(MediaPlayer mp) {
+ if (DBG) log("Audio playback complete.");
+ mHandler.sendMessage(mHandler.obtainMessage(ALERT_SOUND_FINISHED));
+ return;
+ }
+ });
+
try {
// Check if we are in a call. If we are, play the alert
// sound at a low volume to not disrupt the call.
@@ -394,22 +407,28 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI
R.raw.attention_signal);
mAudioManager.requestAudioFocus(null, AudioManager.STREAM_NOTIFICATION,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
- startAlarm(mMediaPlayer);
+ // if the duration isn't equal to one play of the full 10.5s file then play
+ // with looping enabled.
+ startAlarm(mMediaPlayer, duration != CMAS_DURATION_MSEC);
} catch (Exception ex) {
loge("Failed to play alert sound: " + ex);
}
}
- // stop alert after the specified duration
- mHandler.sendMessageDelayed(mHandler.obtainMessage(ALERT_SOUND_FINISHED), duration);
+ // stop alert after the specified duration, unless we are playing the full 10.5s file once
+ // in which case we'll use the end of playback callback rather than a delayed message.
+ // This is to avoid the CMAS alert potentially being truncated due to audio playback lag.
+ if (duration != CMAS_DURATION_MSEC) {
+ mHandler.sendMessageDelayed(mHandler.obtainMessage(ALERT_SOUND_FINISHED), duration);
+ }
mState = STATE_ALERTING;
}
// Do the common stuff when starting the alarm.
- private static void startAlarm(MediaPlayer player)
+ private static void startAlarm(MediaPlayer player, boolean looping)
throws java.io.IOException, IllegalArgumentException, IllegalStateException {
player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
- player.setLooping(true);
+ player.setLooping(looping);
player.prepare();
player.start();
}