-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/ handle connect wifi error state #1189
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 3890097.
@@ -35,13 +39,17 @@ class _OnBoardingTimeZoneSelectorState extends State<OnBoardingTimeZoneSelector> | |||
@override | |||
void dispose() { | |||
searchController.dispose(); | |||
countryListFocusNode.dispose(); | |||
timezoneListFocusNode.dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unnecessary focus it is not used
late List<Country> countriesList; | ||
late List<String> selectedCountryTimezones; | ||
final TextEditingController searchController = TextEditingController(); | ||
final FocusNode countryListFocusNode = FocusNode(); | ||
final FocusNode timezoneListFocusNode = FocusNode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unnecessary focus it is not used
val networkSSID = call.argument<String>("ssid") | ||
val password = call.argument<String>("password") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we check if they are null ? for not null exceptions
while (wifiManager.getConnectionInfo().networkId == -1 && connectionAttempts < 3) { | ||
Thread.sleep(500) | ||
connectionAttempts++ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i used ai to get more improvement for this part.
it is not recommended to use while loop. it will lead to many memory and infi problems.
fun connectToNetworkWPA(call: MethodCall, result: MethodChannel.Result) {
val networkSSID = call.argument<String>("ssid")
val password = call.argument<String>("password")
if (networkSSID == null) {
result.error("INVALID_ARGUMENT", "SSID cannot be null", null)
return
}
val wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
val connectivityManager = applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val conf = WifiConfiguration().apply {
SSID = "\"$networkSSID\""
status = WifiConfiguration.Status.ENABLED
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP)
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP)
allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP)
allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP)
if (password.isNullOrEmpty()) {
allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE)
} else {
preSharedKey = "\"$password\""
allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK)
}
}
val networkCallback = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
super.onAvailable(network)
connectivityManager.unregisterNetworkCallback(this)
result.success(true)
}
override fun onUnavailable() {
super.onUnavailable()
connectivityManager.unregisterNetworkCallback(this)
result.success(false)
}
}
val networkId = wifiManager.addNetwork(conf)
if (networkId == -1) {
result.success(false)
return
}
wifiManager.disconnect()
wifiManager.enableNetwork(networkId, true)
wifiManager.reconnect()
val request = NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.build()
connectivityManager.registerNetworkCallback(request, networkCallback)
// Set a timeout
Handler(Looper.getMainLooper()).postDelayed({
connectivityManager.unregisterNetworkCallback(networkCallback)
result.success(false)
}, 30000) // 30 seconds timeout
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface NetworkCallback {
fun onConnected()
fun onFailed(reason: String)
}
@ghassenbenzahra123 make sure to make dart linter analysis |
This reverts commit bc2f74c.
…awaqit/android-tv-app into fix/handle-failed-wifi-connect
📝 Summary
Description
Checklist: