Refrain from using reflection to parse numerical address
This commit is contained in:
@@ -2,6 +2,8 @@ package be.mygod.vpnhotspot.util
|
||||
|
||||
import android.content.*
|
||||
import android.os.Build
|
||||
import android.system.Os
|
||||
import android.system.OsConstants
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.DrawableRes
|
||||
@@ -52,12 +54,8 @@ fun NetworkInterface.formatAddresses() =
|
||||
}))
|
||||
.joinToString("\n")
|
||||
|
||||
private val parseNumericAddress by lazy {
|
||||
InetAddress::class.java.getDeclaredMethod("parseNumericAddress", String::class.java).apply {
|
||||
isAccessible = true
|
||||
}
|
||||
}
|
||||
fun parseNumericAddress(address: String) = parseNumericAddress.invoke(null, address) as InetAddress
|
||||
fun parseNumericAddress(address: String?): InetAddress? =
|
||||
Os.inet_pton(OsConstants.AF_INET, address) ?: Os.inet_pton(OsConstants.AF_INET6, address)
|
||||
|
||||
fun Context.stopAndUnbind(connection: ServiceConnection) {
|
||||
connection.onServiceDisconnected(null)
|
||||
|
||||
Reference in New Issue
Block a user