Skip to content

Commit 450a4f1

Browse files
authored
Merge pull request #66 from tuaminen/master
Handle null return values from WifiManager.getConfiguredNetworks().
2 parents da108dd + dbf616c commit 450a4f1

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
@@ -256,6 +256,10 @@ public Boolean connectTo(ScanResult result, String password, String ssid) {
256256
}
257257

258258
List<WifiConfiguration> mWifiConfigList = wifi.getConfiguredNetworks();
259+
if (mWifiConfigList == null) {
260+
return false;
261+
}
262+
259263
int updateNetwork = -1;
260264

261265
// Use the existing network config if exists
@@ -319,6 +323,11 @@ public int setWifiConfig(String ssid, String sharedKey) {
319323
@ReactMethod
320324
public void connectToHiddenNetwork(String ssid, String password, Callback networkAdded) {
321325
List<WifiConfiguration> list = wifi.getConfiguredNetworks();
326+
if (list == null) {
327+
networkAdded.invoke(false);
328+
return;
329+
}
330+
322331
int updateNetwork = -1;
323332

324333
// check if network config exists and it's hidden
@@ -422,6 +431,10 @@ public void getIP(final Callback callback) {
422431
@ReactMethod
423432
public void isRemoveWifiNetwork(String ssid, final Callback callback) {
424433
List<WifiConfiguration> mWifiConfigList = wifi.getConfiguredNetworks();
434+
if (mWifiConfigList == null) {
435+
return;
436+
}
437+
425438
for (WifiConfiguration wifiConfig : mWifiConfigList) {
426439
String comparableSSID = ('"' + ssid + '"'); //Add quotes because wifiConfig.SSID has them
427440
if(wifiConfig.SSID.equals(comparableSSID)) {
@@ -467,6 +480,10 @@ public static String longToIP(int longIp){
467480

468481
private WifiConfiguration IsExist(String SSID) {
469482
List<WifiConfiguration> existingConfigs = wifi.getConfiguredNetworks();
483+
if (existingConfigs == null) {
484+
return null;
485+
}
486+
470487
for (WifiConfiguration existingConfig : existingConfigs) {
471488
if (existingConfig.SSID.equals("\"" + SSID + "\"")) {
472489
return existingConfig;

0 commit comments

Comments
 (0)