mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
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...
This commit is contained in:
parent
85f9ead931
commit
0cdf54a992
2 changed files with 25 additions and 4 deletions
|
@ -22,6 +22,8 @@ import javax.inject.Singleton;
|
|||
|
||||
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 @@ public class MobileModel {
|
|||
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 @@ public class MobileModel {
|
|||
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;
|
||||
|
|
|
@ -54,6 +54,14 @@ public class MobileModelTest {
|
|||
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 class MobileModelTest {
|
|||
);
|
||||
|
||||
list.forEach(tuple -> {
|
||||
log.error(tuple.toString());
|
||||
|
||||
log.info(tuple.toString());
|
||||
assertEquals("tuple: " + tuple, mobileModel.parseDescriptor(tuple.first), tuple.second);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue