diff options
author | Jack Yu <jackyu@google.com> | 2015-06-22 11:21:45 -0700 |
---|---|---|
committer | Jack Yu <jackyu@google.com> | 2015-06-22 13:49:01 -0700 |
commit | 50595fdfb0e3b876c80a5937b43d1cc95c36b846 (patch) | |
tree | 1f9a216c086996a50c2227c2cdd5dd02fe3d6b92 /src/com/android | |
parent | 75e70083cfaab821a3847b56e7cbb55c8283687a (diff) | |
download | android_packages_apps_CellBroadcastReceiver-50595fdfb0e3b876c80a5937b43d1cc95c36b846.tar.gz android_packages_apps_CellBroadcastReceiver-50595fdfb0e3b876c80a5937b43d1cc95c36b846.tar.bz2 android_packages_apps_CellBroadcastReceiver-50595fdfb0e3b876c80a5937b43d1cc95c36b846.zip |
Added the body hash code to the message id for duplicate message detection.
bug: 21103998
Change-Id: If077d89867f75659bd2ee73985f950dd2f5d37c8
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java index fa78a276..7f880833 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java @@ -59,22 +59,27 @@ public class CellBroadcastAlertService extends Service { static final String CB_AREA_INFO_RECEIVED_ACTION = "android.cellbroadcastreceiver.CB_AREA_INFO_RECEIVED"; - /** Container for message ID and geographical scope, for duplicate message detection. */ + /** + * Container for service category, serial number, location, and message body hash code for + * duplicate message detection. + */ private static final class MessageServiceCategoryAndScope { private final int mServiceCategory; private final int mSerialNumber; private final SmsCbLocation mLocation; + private final int mBodyHash; MessageServiceCategoryAndScope(int serviceCategory, int serialNumber, - SmsCbLocation location) { + SmsCbLocation location, int bodyHash) { mServiceCategory = serviceCategory; mSerialNumber = serialNumber; mLocation = location; + mBodyHash = bodyHash; } @Override public int hashCode() { - return mLocation.hashCode() + 5 * mServiceCategory + 7 * mSerialNumber; + return mLocation.hashCode() + 5 * mServiceCategory + 7 * mSerialNumber + 13 * mBodyHash; } @Override @@ -86,7 +91,8 @@ public class CellBroadcastAlertService extends Service { MessageServiceCategoryAndScope other = (MessageServiceCategoryAndScope) o; return (mServiceCategory == other.mServiceCategory && mSerialNumber == other.mSerialNumber && - mLocation.equals(other.mLocation)); + mLocation.equals(other.mLocation) && + mBodyHash == other.mBodyHash); } return false; } @@ -94,7 +100,7 @@ public class CellBroadcastAlertService extends Service { @Override public String toString() { return "{mServiceCategory: " + mServiceCategory + " serial number: " + mSerialNumber + - " location: " + mLocation.toString() + '}'; + " location: " + mLocation.toString() + " body hash: " + mBodyHash + '}'; } } @@ -160,7 +166,8 @@ public class CellBroadcastAlertService extends Service { // are stored in volatile memory. If the maximum of 65535 messages is reached, the // message ID of the oldest message is deleted from the list. MessageServiceCategoryAndScope newCmasId = new MessageServiceCategoryAndScope( - message.getServiceCategory(), message.getSerialNumber(), message.getLocation()); + message.getServiceCategory(), message.getSerialNumber(), message.getLocation(), + message.getMessageBody().hashCode()); // Add the new message ID to the list. It's okay if this is a duplicate message ID, // because the list is only used for removing old message IDs from the hash set. |