diff options
author | Irfan Sheriff <isheriff@google.com> | 2012-09-14 14:35:44 -0700 |
---|---|---|
committer | Irfan Sheriff <isheriff@google.com> | 2012-09-14 16:42:58 -0700 |
commit | 633fe60b78665979109d4796ba22430b7b1cd758 (patch) | |
tree | 6396a289e3bcb7713c5284207b4212c0ddc8eff8 | |
parent | fd2ccaffc7bb9e3b735438c461902cbeab759ace (diff) | |
download | frameworks_base-633fe60b78665979109d4796ba22430b7b1cd758.zip frameworks_base-633fe60b78665979109d4796ba22430b7b1cd758.tar.gz frameworks_base-633fe60b78665979109d4796ba22430b7b1cd758.tar.bz2 |
Fix suspend bugs
Listen to screen broadcast all the time to avoid situations of losing
this information when wifi is turned on and off
Avoid duplicate suspend commands to driver
Bug: 7156907
Change-Id: I162b7ba249ae8925119a534229045965c0c13d1f
-rw-r--r-- | wifi/java/android/net/wifi/WifiNative.java | 3 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 18 |
2 files changed, 10 insertions, 11 deletions
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index 805faa6..4c5fc5d 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -49,6 +49,7 @@ public class WifiNative { static final int BLUETOOTH_COEXISTENCE_MODE_SENSE = 2; String mInterface = ""; + private boolean mSuspendOptEnabled = false; public native static boolean loadDriver(); @@ -349,6 +350,8 @@ public class WifiNative { } public boolean setSuspendOptimizations(boolean enabled) { + if (mSuspendOptEnabled == enabled) return true; + mSuspendOptEnabled = enabled; if (enabled) { return doBooleanCommand("DRIVER SETSUSPENDMODE 1"); } else { diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 4cbb824..5e69482 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -141,8 +141,6 @@ public class WifiStateMachine extends StateMachine { private boolean mBluetoothConnectionActive = false; - private BroadcastReceiver mScreenReceiver; - private IntentFilter mScreenFilter; private PowerManager.WakeLock mSuspendWakeLock; /** @@ -628,15 +626,16 @@ public class WifiStateMachine extends StateMachine { }, new IntentFilter(ACTION_START_SCAN)); - mScreenFilter = new IntentFilter(); - mScreenFilter.addAction(Intent.ACTION_SCREEN_ON); - mScreenFilter.addAction(Intent.ACTION_SCREEN_OFF); - mScreenReceiver = new BroadcastReceiver() { + IntentFilter screenFilter = new IntentFilter(); + screenFilter.addAction(Intent.ACTION_SCREEN_ON); + screenFilter.addAction(Intent.ACTION_SCREEN_OFF); + BroadcastReceiver screenReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_SCREEN_ON)) { + if (DBG) log("ACTION_SCREEN_ON"); enableRssiPolling(true); if (mBackgroundScanSupported) { enableBackgroundScanCommand(false); @@ -647,6 +646,7 @@ public class WifiStateMachine extends StateMachine { sendMessage(obtainMessage(CMD_SET_SUSPEND_OPT_ENABLED, 0, 0)); } } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { + if (DBG) log("ACTION_SCREEN_OFF"); enableRssiPolling(false); if (mBackgroundScanSupported) { enableBackgroundScanCommand(true); @@ -660,6 +660,7 @@ public class WifiStateMachine extends StateMachine { } } }; + mContext.registerReceiver(screenReceiver, screenFilter); mContext.registerReceiver( new BroadcastReceiver() { @@ -1335,12 +1336,10 @@ public class WifiStateMachine extends StateMachine { /* None of dhcp, screen or highperf need it disabled and user wants it enabled */ if (mSuspendOptNeedsDisabled == 0 && mUserWantsSuspendOpt.get()) { mWifiNative.setSuspendOptimizations(true); - if (DBG) log("Enabled, mSuspendOptNeedsDisabled " + mSuspendOptNeedsDisabled); } } else { mSuspendOptNeedsDisabled |= reason; mWifiNative.setSuspendOptimizations(false); - if (DBG) log("Disabled, mSuspendOptNeedsDisabled " + mSuspendOptNeedsDisabled); } } @@ -2723,8 +2722,6 @@ public class WifiStateMachine extends StateMachine { } if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P); - - mContext.registerReceiver(mScreenReceiver, mScreenFilter); } @Override public boolean processMessage(Message message) { @@ -2861,7 +2858,6 @@ public class WifiStateMachine extends StateMachine { mScanResults = new ArrayList<ScanResult>(); if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P); - mContext.unregisterReceiver(mScreenReceiver); } } |