Support truncating SSID on buggy old devices

This commit is contained in:
Mygod
2023-05-19 17:59:31 -04:00
parent 434539986a
commit 7bf8be1df6
2 changed files with 4 additions and 2 deletions

View File

@@ -354,7 +354,7 @@ data class SoftApConfigurationCompat(
@Deprecated("Class deprecated in framework")
@Suppress("DEPRECATION")
fun android.net.wifi.WifiConfiguration.toCompat() = SoftApConfigurationCompat(
WifiSsidCompat.fromUtf8Text(SSID),
WifiSsidCompat.fromUtf8Text(SSID, true),
BSSID?.let { MacAddress.fromString(it) },
preSharedKey,
hiddenSSID,

View File

@@ -24,7 +24,9 @@ data class WifiSsidCompat(val bytes: ByteArray) : Parcelable {
}
@Contract("null -> null; !null -> !null")
fun fromUtf8Text(text: CharSequence?) = text?.toString()?.toByteArray()?.let { WifiSsidCompat(it) }
fun fromUtf8Text(text: CharSequence?, truncate: Boolean = false) = text?.toString()?.toByteArray()?.let {
WifiSsidCompat(if (truncate && it.size > 32) it.sliceArray(0 until 32) else it)
}
fun toMeCard(text: String) = qrSanitizer.replace(text) { "\\${it.groupValues[1]}" }