Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MobileModel parseDescriptor to support iPhone 11 #3277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 21 additions & 4 deletions core/src/main/java/bisq/core/notifications/MobileModel.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -123,20 +131,29 @@ 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(" ");
if (descriptorTokens.length >= 1) {
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;
}
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 {
Expand Down
15 changes: 11 additions & 4 deletions core/src/test/java/bisq/core/notifications/MobileModelTest.java
Expand Up @@ -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),

Expand All @@ -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),
Expand All @@ -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);
});

Expand Down