Fix bssid might be null

This commit is contained in:
Mygod
2021-07-24 22:50:01 -04:00
parent c7d53db7e3
commit 9652804f9a
2 changed files with 10 additions and 6 deletions

View File

@@ -272,15 +272,19 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
val channel = SoftApConfigurationCompat.frequencyToChannel(frequency)
val bandwidth = SoftApInfo.channelWidthLookup(info.bandwidth, true)
if (Build.VERSION.SDK_INT >= 31) {
var bssid = makeMacSpan(info.bssid.toString())
info.apInstanceIdentifier?.let { // take the fast route if possible
bssid = if (bssid is String) "$bssid%$it" else SpannableStringBuilder(bssid).append("%$it")
}
val bssid = info.bssid.let { if (it == null) null else makeMacSpan(it.toString()) }
val bssidAp = info.apInstanceIdentifier?.let {
when (bssid) {
null -> it
is String -> "$bssid%$it" // take the fast route if possible
else -> SpannableStringBuilder(bssid).append("%$it")
}
} ?: bssid ?: "?"
val timeout = info.autoShutdownTimeoutMillis
parent.getText(if (timeout == 0L) {
R.string.tethering_manage_wifi_info_timeout_disabled
} else R.string.tethering_manage_wifi_info_timeout_enabled).format(locale,
frequency, channel, bandwidth, bssid, info.wifiStandard,
frequency, channel, bandwidth, bssidAp, info.wifiStandard,
// http://unicode.org/cldr/trac/ticket/3407
DateUtils.formatElapsedTime(timeout / 1000))
} else parent.getText(R.string.tethering_manage_wifi_info).format(locale,

View File

@@ -30,7 +30,7 @@ value class SoftApInfo(val inner: Parcelable) {
val frequency get() = getFrequency(inner) as Int
val bandwidth get() = getBandwidth(inner) as Int
@get:RequiresApi(31)
val bssid get() = getBssid(inner) as MacAddress
val bssid get() = getBssid(inner) as MacAddress?
@get:RequiresApi(31)
val wifiStandard get() = getWifiStandard(inner) as Int
@get:RequiresApi(31)