Merge branch 'v2.4' into q-beta

This commit is contained in:
Mygod
2019-06-01 07:58:55 +08:00
4 changed files with 16 additions and 9 deletions

View File

@@ -191,6 +191,8 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
WifiApManager.configuration = configuration
} catch (e: IllegalArgumentException) {
SmartSnackbar.make(R.string.configuration_rejected).show()
} catch (e: InvocationTargetException) {
SmartSnackbar.make(e.targetException).show()
}
else -> super.onActivityResult(requestCode, resultCode, data)
}

View File

@@ -194,8 +194,13 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
false
}
R.id.share_qr -> {
QRCodeDialog().withArg(ret.configuration.toQRString())
.show(fragmentManager ?: return false, "QRCodeDialog")
val qrString = try {
ret.configuration.toQRString()
} catch (e: IllegalArgumentException) {
SmartSnackbar.make(e).show()
return false
}
QRCodeDialog().withArg(qrString).show(fragmentManager ?: return false, "QRCodeDialog")
true
}
else -> false

View File

@@ -70,9 +70,9 @@ fun frequencyToChannel(frequency: Int) = when (frequency % 5) {
else -> throw IllegalArgumentException("Invalid frequency $frequency")
}
val WifiConfiguration.apKeyManagement get() = allowedKeyManagement.nextSetBit(0).also { selected ->
check(selected >= 0) { "No key management selected" }
val WifiConfiguration.apKeyManagement get() = allowedKeyManagement.nextSetBit(0).let { selected ->
check(allowedKeyManagement.nextSetBit(selected + 1) < 0) { "More than 1 key managements supplied" }
if (selected < 0) WifiConfiguration.KeyMgmt.NONE else selected // getAuthType returns NONE if nothing is selected
}
private val qrSanitizer = Regex("([\\\\\":;,])")