this code base uses integer values for SDK_INT checks

This commit is contained in:
Hans-Christoph Steiner
2026-07-08 13:05:45 +02:00
parent cf996d28d2
commit b56e58f749
2 changed files with 6 additions and 6 deletions

View File

@@ -544,7 +544,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
return false;
}
// use new isNumericAddress method if possible, otherwise attempt to use regex
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= 29) {
return InetAddresses.isNumericAddress(host);
} else {
// regex found online, verified with unit testing
@@ -568,7 +568,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
private static boolean isIpv4(String host) {
// use new parseNumericAddress method if possible, otherwise attempt to check for format
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= 29) {
try {
InetAddress i = InetAddresses.parseNumericAddress(host);
return (i instanceof Inet4Address);
@@ -583,7 +583,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
private static boolean isIpv6(String host) {
// use new parseNumericAddress method if possible, otherwise attempt to check for format
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= 29) {
try {
InetAddress i = InetAddresses.parseNumericAddress(host);
return (i instanceof Inet6Address);

View File

@@ -73,21 +73,21 @@ public class SwapWorkflowActivityTest {
// ------------------------------------------------------------------
@Test
@Config(sdk = Build.VERSION_CODES.R)
@Config(sdk = 30)
public void testValidSwapUrlModern() {
assertTrue(SwapWorkflowActivity.isSwapUrl("192.168.0.50", 8888));
assertTrue(SwapWorkflowActivity.isSwapUrl("2001:db8:abcd::1234", 8888));
}
@Test
@Config(sdk = Build.VERSION_CODES.R)
@Config(sdk = 30)
public void testOutOfSubnetModern() {
assertFalse(SwapWorkflowActivity.isSwapUrl("10.0.0.50", 8888));
assertFalse(SwapWorkflowActivity.isSwapUrl("2010:db8:abcd::1234", 8888));
}
@Test
@Config(sdk = Build.VERSION_CODES.R)
@Config(sdk = 30)
public void testHostnameIsNeverResolvedModern() {
// a hostname must be rejected outright, never resolved via DNS
// several of these are considered numeric due to a Robolectric issue, but fail