Bug 1095914 - Fix NPE in WifiScanner. r=vng, a=lsblakk
authorGarvan Keeley <gkeeley@mozilla.com>
Sat, 08 Nov 2014 09:06:00 -0500
changeset 233998 bd7fbe828b1080f9b7e66f66cd4550e0501caf9b
parent 233997 75e35dfbebcbdbc02aff786b755e4dab39091556
child 233999 a3ae3d724956576aafc6609d961ed28d75de3cd7
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvng, lsblakk
bugs1095914
milestone35.0a2
Bug 1095914 - Fix NPE in WifiScanner. r=vng, a=lsblakk https://github.com/mozilla/MozStumbler/pull/1192 1169: ACRA Report: NPE WifiScanner.java:98
mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/scanners/WifiScanner.java
--- a/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/scanners/WifiScanner.java
+++ b/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/scanners/WifiScanner.java
@@ -60,17 +60,21 @@ public class WifiScanner extends Broadca
         mContext = c;
     }
 
     private boolean isWifiEnabled() {
         return (sIsTestMode) || getWifiManager().isWifiEnabled();
     }
 
     private List<ScanResult> getScanResults() {
-        return (sIsTestMode)? mTestModeFakeScanResults : getWifiManager().getScanResults();
+        WifiManager manager = getWifiManager();
+        if (manager == null) {
+            return null;
+        }
+        return getWifiManager().getScanResults();
     }
 
 
     public synchronized void start(final ActiveOrPassiveStumbling stumblingMode) {
         if (mStarted) {
             return;
         }
         mStarted = true;
@@ -100,18 +104,22 @@ public class WifiScanner extends Broadca
 
         if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
             if (isWifiEnabled()) {
                 activatePeriodicScan(ActiveOrPassiveStumbling.ACTIVE_STUMBLING);
             } else {
                 deactivatePeriodicScan();
             }
         } else if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action)) {
-            ArrayList<ScanResult> scanResults = new ArrayList<ScanResult>();
-            for (ScanResult scanResult : getScanResults()) {
+            final List<ScanResult> scanResultList = getScanResults();
+            if (scanResultList == null) {
+                return;
+            }
+            final ArrayList<ScanResult> scanResults = new ArrayList<ScanResult>();
+            for (ScanResult scanResult : scanResultList) {
                 scanResult.BSSID = BSSIDBlockList.canonicalizeBSSID(scanResult.BSSID);
                 if (shouldLog(scanResult)) {
                     scanResults.add(scanResult);
                     mAPs.add(scanResult.BSSID);
                 }
             }
             mVisibleAPs.set(scanResults.size());
             reportScanResults(scanResults);