diff --git a/CHANGELOG.md b/CHANGELOG.md index 82913b7d8..77a9e06bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,16 @@ Android ChangeLog [Migration Guides](https://github.com/urbanairship/android-library/tree/master/documentation/migration) +Version 9.7.2 - August 30, 2019 +=============================== +Fixes an issue where push message could result in duplicate push notifications. Applications that are +running 9.4.0 - 9.7.1 should update. + +Changes +------- +- Fixes issue with double processing messages on older devices. + + Version 9.7.1 - March 14, 2019 ============================== diff --git a/airship.properties b/airship.properties index abb59f22c..e5b9ff7d6 100644 --- a/airship.properties +++ b/airship.properties @@ -1,5 +1,5 @@ # Airship Version - major.minor.patch -version = 9.7.1 +version = 9.7.2 # Airship Version Qualifier beta, release, etc... #versionQualifier = beta diff --git a/urbanairship-core/src/main/java/com/urbanairship/push/PushManager.java b/urbanairship-core/src/main/java/com/urbanairship/push/PushManager.java index 4c7f813de..96e9aad96 100644 --- a/urbanairship-core/src/main/java/com/urbanairship/push/PushManager.java +++ b/urbanairship-core/src/main/java/com/urbanairship/push/PushManager.java @@ -272,6 +272,7 @@ static final class QuietTime { private final Object tagLock = new Object(); + private final Object uniqueIdLock = new Object(); /** @@ -1186,32 +1187,34 @@ boolean isUniqueCanonicalId(@Nullable String canonicalId) { return true; } - JsonList jsonList = null; - try { - jsonList = JsonValue.parseString(preferenceDataStore.getString(LAST_CANONICAL_IDS_KEY, null)).getList(); - } catch (JsonException e) { - Logger.debug("PushJobHandler - Unable to parse canonical Ids.", e); - } + synchronized (uniqueIdLock) { + JsonList jsonList = null; + try { + jsonList = JsonValue.parseString(preferenceDataStore.getString(LAST_CANONICAL_IDS_KEY, null)).getList(); + } catch (JsonException e) { + Logger.debug("PushJobHandler - Unable to parse canonical Ids.", e); + } - List canonicalIds = jsonList == null ? new ArrayList() : jsonList.getList(); + List canonicalIds = jsonList == null ? new ArrayList() : jsonList.getList(); - // Wrap the canonicalId - JsonValue id = JsonValue.wrap(canonicalId); + // Wrap the canonicalId + JsonValue id = JsonValue.wrap(canonicalId); - // Check if the list contains the canonicalId - if (canonicalIds.contains(id)) { - return false; - } + // Check if the list contains the canonicalId + if (canonicalIds.contains(id)) { + return false; + } - // Add it - canonicalIds.add(id); - if (canonicalIds.size() > MAX_CANONICAL_IDS) { - canonicalIds = canonicalIds.subList(canonicalIds.size() - MAX_CANONICAL_IDS, canonicalIds.size()); - } + // Add it + canonicalIds.add(id); + if (canonicalIds.size() > MAX_CANONICAL_IDS) { + canonicalIds = canonicalIds.subList(canonicalIds.size() - MAX_CANONICAL_IDS, canonicalIds.size()); + } - // Store the new list - preferenceDataStore.put(LAST_CANONICAL_IDS_KEY, JsonValue.wrapOpt(canonicalIds).toString()); + // Store the new list + preferenceDataStore.put(LAST_CANONICAL_IDS_KEY, JsonValue.wrapOpt(canonicalIds).toString()); - return true; + return true; + } } } diff --git a/urbanairship-core/src/main/java/com/urbanairship/push/PushService.java b/urbanairship-core/src/main/java/com/urbanairship/push/PushService.java index f1829cad3..1bae3d3ca 100644 --- a/urbanairship-core/src/main/java/com/urbanairship/push/PushService.java +++ b/urbanairship-core/src/main/java/com/urbanairship/push/PushService.java @@ -59,9 +59,6 @@ public void run() { handler.post(new Runnable() { @Override public void run() { - // Process the push - pushRunnable.run(); - pushes--; if (pushes <= 0) { stopSelf(lastStartId);