Misc refinements

This commit is contained in:
Mygod
2020-05-31 07:42:23 +08:00
parent d17cd0bab3
commit a3027812f0
2 changed files with 13 additions and 4 deletions

View File

@@ -94,7 +94,7 @@ class BluetoothTethering(context: Context, val stateListener: (Int) -> Unit) :
return BluetoothAdapter.getDefaultAdapter()?.state == BluetoothAdapter.STATE_ON && try {
isTetheringOn.invoke(pan) as Boolean
} catch (e: InvocationTargetException) {
activeFailureCause = e
activeFailureCause = e.cause ?: e
if (e.cause is SecurityException && BuildCompat.isAtLeastR()) Timber.d(e) else Timber.w(e)
return null
}

View File

@@ -1,8 +1,13 @@
package be.mygod.vpnhotspot.net
import android.net.MacAddress
import androidx.annotation.RequiresApi
import java.nio.ByteBuffer
import java.nio.ByteOrder
/**
* Compat support class for [MacAddress].
*/
inline class MacAddressCompat(val addr: Long) {
companion object {
private const val ETHER_ADDR_LEN = 6
@@ -23,7 +28,6 @@ inline class MacAddressCompat(val addr: Long) {
return addr.joinToString(":") { "%02x".format(it) }
}
@Throws(IllegalArgumentException::class)
fun fromString(addr: String) = MacAddressCompat(ByteBuffer.allocate(8).run {
order(ByteOrder.LITTLE_ENDIAN)
mark()
@@ -37,9 +41,14 @@ inline class MacAddressCompat(val addr: Long) {
})
}
override fun toString() = ByteBuffer.allocate(8).run {
fun toList() = ByteBuffer.allocate(8).run {
order(ByteOrder.LITTLE_ENDIAN)
putLong(addr)
bytesToString(array().take(6))
array().take(6)
}
@RequiresApi(28)
fun toPlatform() = MacAddress.fromBytes(toList().toByteArray())
override fun toString() = bytesToString(toList())
}