summaryrefslogtreecommitdiff
path: root/src/com/android
diff options
context:
space:
mode:
authorJoe LaPenna <jlapenna@google.com>2016-12-16 23:20:41 -0800
committerJoe LaPenna <jlapenna@google.com>2016-12-19 09:17:10 -0800
commita4f3efdb60a5685327463c4e386663e26c2bba7f (patch)
treedcfcd8efbe6a65c5cd43ac2f144beb2e88850bf9 /src/com/android
parentd62fb0ce9bd6ff2769e70166e022009b5babcb93 (diff)
downloadNetworkRecommendation-a4f3efdb60a5685327463c4e386663e26c2bba7f.tar.gz
Fix NPE reading scan results.
Didn't seem possible at first glance of the code, but it looks like getScanResults might return null on occasion. BUG: 33710559 Test: adb shell am instrument -w com.android.networkrecommendation.tests/android.support.test.runner.AndroidJUnitRunner Change-Id: Ic5d0ef49d0770e6a11d465c44d1c3c0ebe52a340
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/networkrecommendation/DefaultNetworkRecommendationService.java64
1 files changed, 34 insertions, 30 deletions
diff --git a/src/com/android/networkrecommendation/DefaultNetworkRecommendationService.java b/src/com/android/networkrecommendation/DefaultNetworkRecommendationService.java
index 325ac85..972b35a 100644
--- a/src/com/android/networkrecommendation/DefaultNetworkRecommendationService.java
+++ b/src/com/android/networkrecommendation/DefaultNetworkRecommendationService.java
@@ -173,37 +173,41 @@ public class DefaultNetworkRecommendationService extends Service {
int recommendedScore = Integer.MIN_VALUE;
ScanResult[] results = request.getScanResults();
- for (int i = 0; i < results.length; i++) {
- final ScanResult scanResult = results[i];
- if (VERBOSE) Log.v(TAG, "Scan: " + scanResult + " " + i);
-
- // We only want to recommend open networks. This check is taken from
- // places like WifiNotificationController and will be extracted to ScanResult in
- // a future CL.
- if (!"[ESS]".equals(scanResult.capabilities)) {
- if (VERBOSE) Log.v(TAG, "Discarding closed network: " + scanResult);
- continue;
- }
-
- final NetworkKey networkKey = new NetworkKey(
- new WifiKey(quoteSsid(scanResult), scanResult.BSSID));
- if (VERBOSE) Log.v(TAG, "Evaluating network: " + networkKey);
-
- // We will only score networks we know about.
- final ScoredNetwork network = mStorage.get(networkKey);
- if (network == null) {
- if (VERBOSE) Log.v(TAG, "Discarding unscored network: " + scanResult);
- continue;
- }
-
- final int score = network.rssiCurve.lookupScore(scanResult.level);
- if (VERBOSE) Log.d(TAG, "Scored " + scanResult + ": " + score);
- if (score > recommendedScore) {
- recommendedScanResult = scanResult;
- recommendedScore = score;
- if (VERBOSE) Log.d(TAG, "New recommended network: " + scanResult);
- continue;
+ if (results != null) {
+ for (int i = 0; i < results.length; i++) {
+ final ScanResult scanResult = results[i];
+ if (VERBOSE) Log.v(TAG, "Scan: " + scanResult + " " + i);
+
+ // We only want to recommend open networks. This check is taken from
+ // places like WifiNotificationController and will be extracted to ScanResult in
+ // a future CL.
+ if (!"[ESS]".equals(scanResult.capabilities)) {
+ if (VERBOSE) Log.v(TAG, "Discarding closed network: " + scanResult);
+ continue;
+ }
+
+ final NetworkKey networkKey = new NetworkKey(
+ new WifiKey(quoteSsid(scanResult), scanResult.BSSID));
+ if (VERBOSE) Log.v(TAG, "Evaluating network: " + networkKey);
+
+ // We will only score networks we know about.
+ final ScoredNetwork network = mStorage.get(networkKey);
+ if (network == null) {
+ if (VERBOSE) Log.v(TAG, "Discarding unscored network: " + scanResult);
+ continue;
+ }
+
+ final int score = network.rssiCurve.lookupScore(scanResult.level);
+ if (VERBOSE) Log.d(TAG, "Scored " + scanResult + ": " + score);
+ if (score > recommendedScore) {
+ recommendedScanResult = scanResult;
+ recommendedScore = score;
+ if (VERBOSE) Log.d(TAG, "New recommended network: " + scanResult);
+ continue;
+ }
}
+ } else {
+ Log.w(TAG, "Received null scan results in request.");
}
// If we ended up without a recommendation, recommend the provided configuration