diff options
author | Sebastiano Barezzi <seba@sebaubuntu.dev> | 2023-04-15 01:40:49 +0200 |
---|---|---|
committer | Sebastiano Barezzi <seba@sebaubuntu.dev> | 2023-04-25 19:09:15 +0200 |
commit | 2ff7e0d82fcb4f46af68a85e8b9e1c64f4510084 (patch) | |
tree | c247954e763a9a358371ccb10b5cc8a58ddd1b8f | |
parent | 5dcb7791327cb567243d25a62af0516bb9e5bf86 (diff) |
Aperture: Fix crash on malformed Wi-Fi QR code
Change-Id: I6cb36edcfa7b4b89051e9cee2d6b28f40ca2c72f
-rw-r--r-- | app/src/main/java/org/lineageos/aperture/utils/WifiNetwork.kt | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/app/src/main/java/org/lineageos/aperture/utils/WifiNetwork.kt b/app/src/main/java/org/lineageos/aperture/utils/WifiNetwork.kt index 0b8cbd0..d6aeb70 100644 --- a/app/src/main/java/org/lineageos/aperture/utils/WifiNetwork.kt +++ b/app/src/main/java/org/lineageos/aperture/utils/WifiNetwork.kt @@ -25,6 +25,12 @@ data class WifiNetwork( SAE; } + init { + assert((encryptionType == EncryptionType.NONE) == (password == null)) { + "Invalid encryption type/password combination" + } + } + @RequiresApi(Build.VERSION_CODES.Q) fun toNetworkSuggestion(): WifiNetworkSuggestion? = when (encryptionType) { EncryptionType.WEP -> null @@ -63,7 +69,9 @@ data class WifiNetwork( else -> EncryptionType.NONE } - return WifiNetwork(result.ssid, result.isHidden, result.password, encryptionType) + return runCatching { + WifiNetwork(result.ssid, result.isHidden, result.password, encryptionType) + }.getOrNull() } } } |