summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2019-09-30 12:29:06 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-09-30 19:45:11 +0200
commitd2b9de740dde600e36a37c838d8aa8c1a4b62dfd (patch)
treef14aad413e0e570b6aac434510e04fc23669b034 /app/src/main/java/com
parenteb45b4b1bd6f6d594de8eceb6ca7827144120336 (diff)
Migrate to Android 10
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r--app/src/main/java/com/wireguard/config/InetAddresses.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/src/main/java/com/wireguard/config/InetAddresses.java b/app/src/main/java/com/wireguard/config/InetAddresses.java
index 69fd6cfb..864082e2 100644
--- a/app/src/main/java/com/wireguard/config/InetAddresses.java
+++ b/app/src/main/java/com/wireguard/config/InetAddresses.java
@@ -5,6 +5,7 @@
package com.wireguard.config;
+import android.os.Build;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Inet4Address;
@@ -15,9 +16,12 @@ import java.net.InetAddress;
* Utility methods for creating instances of {@link InetAddress}.
*/
public final class InetAddresses {
- private static final Method PARSER_METHOD;
+ private static Method PARSER_METHOD;
- static {
+
+ private static Method getParserMethod() {
+ if (PARSER_METHOD != null)
+ return PARSER_METHOD;
try {
// This method is only present on Android.
// noinspection JavaReflectionMemberAccess
@@ -25,6 +29,7 @@ public final class InetAddresses {
} catch (final NoSuchMethodException e) {
throw new RuntimeException(e);
}
+ return PARSER_METHOD;
}
private InetAddresses() {
@@ -41,7 +46,10 @@ public final class InetAddresses {
if (address.isEmpty())
throw new ParseException(InetAddress.class, address, "Empty address");
try {
- return (InetAddress) PARSER_METHOD.invoke(null, address);
+ if (Build.VERSION.SDK_INT < 29)
+ return (InetAddress) getParserMethod().invoke(null, address);
+ else
+ return android.net.InetAddresses.parseNumericAddress(address);
} catch (final IllegalAccessException | InvocationTargetException e) {
final Throwable cause = e.getCause();
// Re-throw parsing exceptions with the original type, as callers might try to catch