From 0cdf54a9927454b67706eade7826d3548ffaec57 Mon Sep 17 00:00:00 2001 From: Devin Bileck <603793+devinbileck@users.noreply.github.com> Date: Tue, 17 Sep 2019 00:13:18 -0700 Subject: [PATCH 1/2] Update MobileModel parseDescriptor to support iPhone 11 It was parsing only the first digit of the version and using that in a comparison check to determine if the version is greater than 5. This meant for the iPhone 11 it was comparing 1 > 5, returning an incorrect result. It now supports multi-digit version numbers (i.e. 11), including support for a suffix in the version (i.e. 11S), just in case... --- .../bisq/core/notifications/MobileModel.java | 18 ++++++++++++++++-- .../core/notifications/MobileModelTest.java | 11 +++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/bisq/core/notifications/MobileModel.java b/core/src/main/java/bisq/core/notifications/MobileModel.java index 2c212e7e4e9..ceacf4feeab 100644 --- a/core/src/main/java/bisq/core/notifications/MobileModel.java +++ b/core/src/main/java/bisq/core/notifications/MobileModel.java @@ -22,6 +22,8 @@ import com.google.common.annotations.VisibleForTesting; +import java.util.Arrays; + import lombok.Data; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -107,6 +109,12 @@ boolean parseDescriptor(String descriptor) { iPhone 8 iPhone 8 Plus iPhone X + iPhone XS + iPhone XS Max + iPhone XR + iPhone 11 + iPhone 11 Pro + iPhone 11 Pro Max iPad 2 iPad 3 iPad 4 @@ -131,9 +139,15 @@ boolean parseDescriptor(String descriptor) { String model = descriptorTokens[0]; if (model.equals("iPhone")) { String versionString = descriptorTokens[1]; - versionString = versionString.substring(0, 1); - if (versionString.equals("X") || versionString.equals("SE")) + String[] validVersions = {"X", "XS", "XR"}; + if (Arrays.asList(validVersions).contains(versionString)) { return true; + } + if (versionString.matches("\\d[^\\d]")) { + versionString = versionString.substring(0, 1); + } else if (versionString.matches("\\d{2}[^\\d]")) { + versionString = versionString.substring(0, 2); + } try { int version = Integer.parseInt(versionString); return version > 5; diff --git a/core/src/test/java/bisq/core/notifications/MobileModelTest.java b/core/src/test/java/bisq/core/notifications/MobileModelTest.java index bb69e802ff1..a7540f4bd2c 100644 --- a/core/src/test/java/bisq/core/notifications/MobileModelTest.java +++ b/core/src/test/java/bisq/core/notifications/MobileModelTest.java @@ -54,6 +54,14 @@ public void testParseDescriptor() { new Tuple2<>("iPhone 8", true), new Tuple2<>("iPhone 8 Plus", true), new Tuple2<>("iPhone X", true), + new Tuple2<>("iPhone XS", true), + new Tuple2<>("iPhone XS Max", true), + new Tuple2<>("iPhone XR", true), + new Tuple2<>("iPhone 11", true), + new Tuple2<>("iPhone 11 Pro", true), + new Tuple2<>("iPhone 11 Pro Max", true), + new Tuple2<>("iPhone 11S", true), // not sure if this model will exist, but based on past versioning it is possible + // need to ensure it will be parsed correctly just in case new Tuple2<>("iPad 2", false), new Tuple2<>("iPad 3", false), @@ -74,8 +82,7 @@ public void testParseDescriptor() { ); list.forEach(tuple -> { - log.error(tuple.toString()); - + log.info(tuple.toString()); assertEquals("tuple: " + tuple, mobileModel.parseDescriptor(tuple.first), tuple.second); }); From 4c27d08b73c950b5a7669e1891c409aec6138d12 Mon Sep 17 00:00:00 2001 From: Devin Bileck <603793+devinbileck@users.noreply.github.com> Date: Tue, 29 Oct 2019 17:09:21 -0700 Subject: [PATCH 2/2] Update to reflect isContentAvailable supports iPhone 6s and newer --- .../src/main/java/bisq/core/notifications/MobileModel.java | 7 +++++-- .../test/java/bisq/core/notifications/MobileModelTest.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/bisq/core/notifications/MobileModel.java b/core/src/main/java/bisq/core/notifications/MobileModel.java index ceacf4feeab..90532fb6663 100644 --- a/core/src/main/java/bisq/core/notifications/MobileModel.java +++ b/core/src/main/java/bisq/core/notifications/MobileModel.java @@ -131,7 +131,7 @@ boolean parseDescriptor(String descriptor) { iPad Pro 12.9 Inch 2. Generation iPad Pro 10.5 Inch */ - // iPhone 6 does not support isContentAvailable, iPhone 7 does. + // iPhone 6 does not support isContentAvailable, iPhone 6s and 7 does. // We don't know for other versions, but lets assume all above iPhone 6 are ok. if (descriptor != null) { String[] descriptorTokens = descriptor.split(" "); @@ -143,14 +143,17 @@ boolean parseDescriptor(String descriptor) { if (Arrays.asList(validVersions).contains(versionString)) { return true; } + String versionSuffix = ""; if (versionString.matches("\\d[^\\d]")) { + versionSuffix = versionString.substring(1); versionString = versionString.substring(0, 1); } else if (versionString.matches("\\d{2}[^\\d]")) { + versionSuffix = versionString.substring(2); versionString = versionString.substring(0, 2); } try { int version = Integer.parseInt(versionString); - return version > 5; + return version > 6 || (version == 6 && versionSuffix.equalsIgnoreCase("s")); } catch (Throwable ignore) { } } else { diff --git a/core/src/test/java/bisq/core/notifications/MobileModelTest.java b/core/src/test/java/bisq/core/notifications/MobileModelTest.java index a7540f4bd2c..4790d54c3a7 100644 --- a/core/src/test/java/bisq/core/notifications/MobileModelTest.java +++ b/core/src/test/java/bisq/core/notifications/MobileModelTest.java @@ -43,8 +43,8 @@ public void testParseDescriptor() { new Tuple2<>("iPhone 5c", false), new Tuple2<>("iPhone 5s", false), - new Tuple2<>("iPhone 6", true), - new Tuple2<>("iPhone 6 Plus", true), + new Tuple2<>("iPhone 6", false), + new Tuple2<>("iPhone 6 Plus", false), new Tuple2<>("iPhone 6s", true), new Tuple2<>("iPhone 6s Plus", true),