summaryrefslogtreecommitdiffstats
path: root/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
diff options
context:
space:
mode:
authorJake Hamby <jhamby@google.com>2012-08-03 14:21:30 -0700
committerJake Hamby <jhamby@google.com>2012-08-03 14:50:15 -0700
commitd716ca0cb5e074ec73099dd4b6b69dad55ae97d6 (patch)
tree4d3086b154fd801d9d3cccc72960b10b67ef64d7 /src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
parent21f2b9ac08ca93cee099292ba597b9a45e846030 (diff)
downloadandroid_packages_apps_CellBroadcastReceiver-d716ca0cb5e074ec73099dd4b6b69dad55ae97d6.tar.gz
android_packages_apps_CellBroadcastReceiver-d716ca0cb5e074ec73099dd4b6b69dad55ae97d6.tar.bz2
android_packages_apps_CellBroadcastReceiver-d716ca0cb5e074ec73099dd4b6b69dad55ae97d6.zip
Add message ID cache to detect duplicate broadcasts.
Ignore received broadcasts with message ID and geo scope matching an already received cell broadcast. This prevents the display of duplicate alerts when the user has deleted the original broadcast. Bug: 6853691 Change-Id: I879be8fbdd092e4b6d26ecc074034ce79a4e284c
Diffstat (limited to 'src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java')
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
index 5161dbb7..dc1021fb 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
@@ -31,9 +31,12 @@ import android.preference.PreferenceManager;
import android.provider.Telephony;
import android.telephony.CellBroadcastMessage;
import android.telephony.SmsCbCmasInfo;
+import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.util.Log;
+import java.util.HashSet;
+
/**
* This service manages the display and animation of broadcast messages.
* Emergency messages display with a flashing animated exclamation mark icon,
@@ -62,6 +65,42 @@ public class CellBroadcastAlertService extends Service {
/** Hold the wake lock for 5 seconds, which should be enough time to display the alert. */
private static final int WAKE_LOCK_TIMEOUT = 5000;
+ /** Container for message ID and geographical scope, for duplicate message detection. */
+ private static final class MessageIdAndScope {
+ private final int mMessageId;
+ private final SmsCbLocation mLocation;
+
+ MessageIdAndScope(int messageId, SmsCbLocation location) {
+ mMessageId = messageId;
+ mLocation = location;
+ }
+
+ @Override
+ public int hashCode() {
+ return mMessageId * 31 + mLocation.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ }
+ if (o instanceof MessageIdAndScope) {
+ MessageIdAndScope other = (MessageIdAndScope) o;
+ return (mMessageId == other.mMessageId && mLocation.equals(other.mLocation));
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "{messageId: " + mMessageId + " location: " + mLocation.toString() + '}';
+ }
+ }
+
+ /** Cache of received message IDs, for duplicate message detection. */
+ private static final HashSet<MessageIdAndScope> sCmasIdList = new HashSet<MessageIdAndScope>(8);
+
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent.getAction();
@@ -97,6 +136,14 @@ public class CellBroadcastAlertService extends Service {
return;
}
+ // Set.add() returns false if message ID has already been added
+ MessageIdAndScope messageIdAndScope = new MessageIdAndScope(message.getSerialNumber(),
+ message.getLocation());
+ if (!sCmasIdList.add(messageIdAndScope)) {
+ Log.d(TAG, "ignoring duplicate alert with " + messageIdAndScope);
+ return;
+ }
+
final Intent alertIntent = new Intent(SHOW_NEW_ALERT_ACTION);
alertIntent.setClass(this, CellBroadcastAlertService.class);
alertIntent.putExtra("message", cbm);