Skip to content

Commit

Permalink
fix(Android): properly check on pollForValidSSID if network connected
Browse files Browse the repository at this point in the history
this is required as the network state might be 'connecting' to a network
it'd look the same as 'connected' without checking for status
  • Loading branch information
EXio4 committed Aug 13, 2024
1 parent d98ccfc commit 46ab251
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions android/src/main/java/com/reactlibrary/rnwifi/RNWifiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,26 +279,25 @@ public void connectToProtectedWifiSSID(@NonNull ReadableMap options, final Promi
}




/**
* Returns if the device is currently connected to a WiFi network.
*/
@ReactMethod
public void connectionStatus(final Promise promise) {
private boolean getConnectionStatus() {
final ConnectivityManager connectivityManager = (ConnectivityManager) getReactApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager == null) {
promise.resolve(false);
return;
return false;
}

NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (wifiInfo == null) {
promise.resolve(false);
return;
return false;
}
return wifiInfo.isConnected();
}

promise.resolve(wifiInfo.isConnected());
/**
* Returns if the device is currently connected to a WiFi network.
*/
@ReactMethod
public void connectionStatus(final Promise promise) {
promise.resolve(this.getConnectionStatus());
return;
}

/**
Expand Down Expand Up @@ -626,7 +625,8 @@ private boolean pollForValidSSID(int maxSeconds, String expectedSSID) {
try {
for (int i = 0; i < maxSeconds; i++) {
String ssid = this.getWifiSSID();
if (ssid != null && ssid.equalsIgnoreCase(expectedSSID)) {
boolean isConnected = this.getConnectionStatus();
if (ssid != null && ssid.equalsIgnoreCase(expectedSSID) && isConnected) {
return true;
}
Thread.sleep(1000);
Expand Down

0 comments on commit 46ab251

Please sign in to comment.