Inputting MAC address no longer requires :
This commit is contained in:
@@ -56,13 +56,22 @@ inline class MacAddressCompat(val addr: Long) {
|
|||||||
*/
|
*/
|
||||||
fun fromString(addr: String) = ByteBuffer.allocate(Long.SIZE_BYTES).run {
|
fun fromString(addr: String) = ByteBuffer.allocate(Long.SIZE_BYTES).run {
|
||||||
order(ByteOrder.LITTLE_ENDIAN)
|
order(ByteOrder.LITTLE_ENDIAN)
|
||||||
val bytes = try {
|
var start = 0
|
||||||
addr.split(':').map { Integer.parseInt(it, 16).toByte() }.toByteArray()
|
var i = 0
|
||||||
} catch (e: NumberFormatException) {
|
while (position() < ETHER_ADDR_LEN && start < addr.length) {
|
||||||
throw IllegalArgumentException(e)
|
val end = i
|
||||||
|
if (addr.getOrElse(i) { ':' } == ':') ++i else if (i < start + 2) {
|
||||||
|
++i
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
put(if (start == end) 0 else try {
|
||||||
|
Integer.parseInt(addr.substring(start, end), 16).toByte()
|
||||||
|
} catch (e: NumberFormatException) {
|
||||||
|
throw IllegalArgumentException(e)
|
||||||
|
})
|
||||||
|
start = i
|
||||||
}
|
}
|
||||||
require(bytes.size == ETHER_ADDR_LEN)
|
require(position() == ETHER_ADDR_LEN) { "MAC address too short" }
|
||||||
put(bytes)
|
|
||||||
rewind()
|
rewind()
|
||||||
MacAddressCompat(long)
|
MacAddressCompat(long)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
|||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.net.MacAddress
|
|
||||||
import android.net.wifi.SoftApConfiguration
|
import android.net.wifi.SoftApConfiguration
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
@@ -130,9 +129,9 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
|||||||
}
|
}
|
||||||
isClientControlByUserEnabled = dialogView.clientUserControl.isChecked
|
isClientControlByUserEnabled = dialogView.clientUserControl.isChecked
|
||||||
allowedClientList = (dialogView.allowedList.text ?: "").split(nonMacChars)
|
allowedClientList = (dialogView.allowedList.text ?: "").split(nonMacChars)
|
||||||
.filter { it.isNotEmpty() }.map { MacAddress.fromString(it) }
|
.filter { it.isNotEmpty() }.map { MacAddressCompat.fromString(it).toPlatform() }
|
||||||
blockedClientList = (dialogView.blockedList.text ?: "").split(nonMacChars)
|
blockedClientList = (dialogView.blockedList.text ?: "").split(nonMacChars)
|
||||||
.filter { it.isNotEmpty() }.map { MacAddress.fromString(it) }
|
.filter { it.isNotEmpty() }.map { MacAddressCompat.fromString(it).toPlatform() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +271,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
|||||||
dialogView.maxClientWrapper.error = maxClientError
|
dialogView.maxClientWrapper.error = maxClientError
|
||||||
val blockedListError = try {
|
val blockedListError = try {
|
||||||
(dialogView.blockedList.text ?: "").split(nonMacChars)
|
(dialogView.blockedList.text ?: "").split(nonMacChars)
|
||||||
.filter { it.isNotEmpty() }.forEach { MacAddress.fromString(it) }
|
.filter { it.isNotEmpty() }.forEach { MacAddressCompat.fromString(it).toPlatform() }
|
||||||
null
|
null
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
e.readableMessage
|
e.readableMessage
|
||||||
@@ -280,7 +279,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
|||||||
dialogView.blockedListWrapper.error = blockedListError
|
dialogView.blockedListWrapper.error = blockedListError
|
||||||
val allowedListError = try {
|
val allowedListError = try {
|
||||||
(dialogView.allowedList.text ?: "").split(nonMacChars)
|
(dialogView.allowedList.text ?: "").split(nonMacChars)
|
||||||
.filter { it.isNotEmpty() }.forEach { MacAddress.fromString(it) }
|
.filter { it.isNotEmpty() }.forEach { MacAddressCompat.fromString(it).toPlatform() }
|
||||||
null
|
null
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
e.readableMessage
|
e.readableMessage
|
||||||
|
|||||||
Reference in New Issue
Block a user