From f95dd5ed581b111ed88631ab9955af1d7ca78917 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 20 Jul 2020 09:02:56 +0800 Subject: [PATCH] Use alternative approach if file not found --- mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt index ab069c91..9e81b99e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt @@ -26,6 +26,7 @@ import be.mygod.vpnhotspot.net.MacAddressCompat import be.mygod.vpnhotspot.widget.SmartSnackbar import timber.log.Timber import java.io.File +import java.io.FileNotFoundException import java.lang.invoke.MethodHandles import java.lang.reflect.InvocationHandler import java.lang.reflect.InvocationTargetException @@ -164,4 +165,8 @@ fun InvocationHandler.callSuper(interfaceClass: Class<*>, proxy: Any, method: Me fun if_nametoindex(ifname: String) = if (Build.VERSION.SDK_INT >= 26) { Os.if_nametoindex(ifname) -} else File("/sys/class/net/$ifname/ifindex").inputStream().bufferedReader().use { it.readLine().toInt() } +} else try { + File("/sys/class/net/$ifname/ifindex").inputStream().bufferedReader().use { it.readLine().toInt() } +} catch (_: FileNotFoundException) { + NetworkInterface.getByName(ifname).index +}