summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2015-02-05 10:34:20 -0500
committerJason Monk <jmonk@google.com>2015-02-10 13:58:40 +0000
commit6572eae9d278e7199440aeae9a91f9418e8ab4af (patch)
tree0c03e6f8e5786f8c835d556241bcd254b0482274 /packages
parentefee230fe16e5ca69c75a7385ed6fe07063620a5 (diff)
downloadframeworks_base-6572eae9d278e7199440aeae9a91f9418e8ab4af.zip
frameworks_base-6572eae9d278e7199440aeae9a91f9418e8ab4af.tar.gz
frameworks_base-6572eae9d278e7199440aeae9a91f9418e8ab4af.tar.bz2
Fix crash in Wifi QS Panel
When open QS wifi panel while wifi was off was causing a crash from wifi enabling while the WifiTracker was not in a scanning state. Fix plus a test enclosed. Bug: 19322090 Change-Id: Id863cdcbf4aa8d50822de3a200355dbaee74b488
Diffstat (limited to 'packages')
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java35
-rw-r--r--packages/SettingsLib/tests/src/com/android/settingslib/wifi/WifiTrackerTest.java23
2 files changed, 48 insertions, 10 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
index c3e23d2..2eb7abf 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
@@ -127,6 +127,7 @@ public class WifiTracker {
public void pauseScanning() {
if (mScanner != null) {
mScanner.pause();
+ mScanner = null;
}
}
@@ -134,10 +135,10 @@ public class WifiTracker {
* Resume scanning for wifi networks after it has been paused.
*/
public void resumeScanning() {
+ if (mScanner == null) {
+ mScanner = new Scanner();
+ }
if (mWifiManager.isWifiEnabled()) {
- if (mScanner == null) {
- mScanner = new Scanner();
- }
mScanner.resume();
}
updateAccessPoints();
@@ -335,11 +336,17 @@ public class WifiTracker {
private void updateWifiState(int state) {
if (state == WifiManager.WIFI_STATE_ENABLED) {
- mScanner.resume();
+ if (mScanner != null) {
+ // We only need to resume if mScanner isn't null because
+ // that means we want to be scanning.
+ mScanner.resume();
+ }
} else {
mLastInfo = null;
mLastNetworkInfo = null;
- mScanner.pause();
+ if (mScanner != null) {
+ mScanner.pause();
+ }
}
if (mListener != null) {
mListener.onWifiStateChanged(state);
@@ -382,26 +389,34 @@ public class WifiTracker {
@VisibleForTesting
class Scanner extends Handler {
+ private static final int MSG_SCAN = 0;
+
private int mRetry = 0;
void resume() {
- if (!hasMessages(0)) {
- sendEmptyMessage(0);
+ if (!hasMessages(MSG_SCAN)) {
+ sendEmptyMessage(MSG_SCAN);
}
}
void forceScan() {
- removeMessages(0);
- sendEmptyMessage(0);
+ removeMessages(MSG_SCAN);
+ sendEmptyMessage(MSG_SCAN);
}
void pause() {
mRetry = 0;
- removeMessages(0);
+ removeMessages(MSG_SCAN);
+ }
+
+ @VisibleForTesting
+ boolean isScanning() {
+ return hasMessages(MSG_SCAN);
}
@Override
public void handleMessage(Message message) {
+ if (message.what != MSG_SCAN) return;
if (mWifiManager.startScan()) {
mRetry = 0;
} else if (++mRetry >= 3) {
diff --git a/packages/SettingsLib/tests/src/com/android/settingslib/wifi/WifiTrackerTest.java b/packages/SettingsLib/tests/src/com/android/settingslib/wifi/WifiTrackerTest.java
index 73d4938..8eb1ca4 100644
--- a/packages/SettingsLib/tests/src/com/android/settingslib/wifi/WifiTrackerTest.java
+++ b/packages/SettingsLib/tests/src/com/android/settingslib/wifi/WifiTrackerTest.java
@@ -201,6 +201,29 @@ public class WifiTrackerTest extends BaseTest {
assertTrue("Connected to wifi", accessPoints.get(0).isActive());
}
+ public void testEnableResumeScanning() {
+ mWifiTracker.mScanner = null;
+
+ Intent i = new Intent(WifiManager.WIFI_STATE_CHANGED_ACTION);
+ // Make sure disable/enable cycle works with no scanner (no crashing).
+ i.putExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED);
+ mWifiTracker.mReceiver.onReceive(mContext, i);
+ i.putExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_ENABLED);
+ mWifiTracker.mReceiver.onReceive(mContext, i);
+
+ Mockito.when(mWifiManager.isWifiEnabled()).thenReturn(false);
+ i.putExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED);
+ mWifiTracker.mReceiver.onReceive(mContext, i);
+ // Now enable scanning while wifi is off, it shouldn't start.
+ mWifiTracker.resumeScanning();
+ assertFalse(mWifiTracker.mScanner.isScanning());
+
+ // Turn on wifi and make sure scanning starts.
+ i.putExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_ENABLED);
+ mWifiTracker.mReceiver.onReceive(mContext, i);
+ assertTrue(mWifiTracker.mScanner.isScanning());
+ }
+
private String[] generateTestNetworks(List<WifiConfiguration> wifiConfigs,
List<ScanResult> scanResults, boolean connectedIsEphemeral) {
String[] expectedSsids = new String[NUM_NETWORKS];