Skip to content

Commit dbf616c

Browse files
committed
Handle null return values from WifiManager.getConfiguredNetworks(). It seems to occur in some instances.
1 parent d45f3bc commit dbf616c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

android/src/main/java/com/devstepbcn/wifi/AndroidWifiModule.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ public Boolean connectTo(ScanResult result, String password, String ssid) {
253253
}
254254

255255
List<WifiConfiguration> mWifiConfigList = wifi.getConfiguredNetworks();
256+
if (mWifiConfigList == null) {
257+
return false;
258+
}
259+
256260
int updateNetwork = -1;
257261

258262
// Use the existing network config if exists
@@ -316,6 +320,11 @@ public int setWifiConfig(String ssid, String sharedKey) {
316320
@ReactMethod
317321
public void connectToHiddenNetwork(String ssid, String password, Callback networkAdded) {
318322
List<WifiConfiguration> list = wifi.getConfiguredNetworks();
323+
if (list == null) {
324+
networkAdded.invoke(false);
325+
return;
326+
}
327+
319328
int updateNetwork = -1;
320329

321330
// check if network config exists and it's hidden
@@ -419,6 +428,10 @@ public void getIP(final Callback callback) {
419428
@ReactMethod
420429
public void isRemoveWifiNetwork(String ssid, final Callback callback) {
421430
List<WifiConfiguration> mWifiConfigList = wifi.getConfiguredNetworks();
431+
if (mWifiConfigList == null) {
432+
return;
433+
}
434+
422435
for (WifiConfiguration wifiConfig : mWifiConfigList) {
423436
String comparableSSID = ('"' + ssid + '"'); //Add quotes because wifiConfig.SSID has them
424437
if(wifiConfig.SSID.equals(comparableSSID)) {
@@ -464,6 +477,10 @@ public static String longToIP(int longIp){
464477

465478
private WifiConfiguration IsExist(String SSID) {
466479
List<WifiConfiguration> existingConfigs = wifi.getConfiguredNetworks();
480+
if (existingConfigs == null) {
481+
return null;
482+
}
483+
467484
for (WifiConfiguration existingConfig : existingConfigs) {
468485
if (existingConfig.SSID.equals("\"" + SSID + "\"")) {
469486
return existingConfig;

0 commit comments

Comments
 (0)