diff options
author | Irfan Sheriff <isheriff@google.com> | 2011-02-28 12:08:11 -0800 |
---|---|---|
committer | Irfan Sheriff <isheriff@google.com> | 2011-02-28 12:29:33 -0800 |
commit | f9e2a491176b086cd3c238b209e025cd68d76001 (patch) | |
tree | 89edfd6a6f66d177167d6f4b887cd7be4b71bf39 /wifi/java/android | |
parent | 5404812dee9dccbbd43df81752f3061742235982 (diff) | |
download | frameworks_base-f9e2a491176b086cd3c238b209e025cd68d76001.zip frameworks_base-f9e2a491176b086cd3c238b209e025cd68d76001.tar.gz frameworks_base-f9e2a491176b086cd3c238b209e025cd68d76001.tar.bz2 |
Fix issue to clear scan alarms
If PNO is set after the device is disconnected, the scan
alarm should be cleared to prevent both PNO and alarm
being active at the same time
Bug: 3495698
Change-Id: Id48c87fef68a34a05799e6b82de4088e0573009f
Diffstat (limited to 'wifi/java/android')
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 65f2a19..931fd40 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -2730,11 +2730,30 @@ public class WifiStateMachine extends HierarchicalStateMachine { class DisconnectedState extends HierarchicalState { private boolean mAlarmEnabled = false; + private long mScanIntervalMs; + + private void setScanAlarm(boolean enabled) { + if (enabled == mAlarmEnabled) return; + if (enabled) { + mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, + System.currentTimeMillis() + mScanIntervalMs, + mScanIntervalMs, + mScanIntent); + + mAlarmEnabled = true; + } else { + mAlarmManager.cancel(mScanIntent); + mAlarmEnabled = false; + } + } + @Override public void enter() { if (DBG) Log.d(TAG, getName() + "\n"); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); + mScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(), + Settings.Secure.WIFI_SCAN_INTERVAL_MS, DEFAULT_SCAN_INTERVAL_MS); /* * We initiate background scanning if it is enabled, otherwise we * initiate an infrequent scan that wakes up the device to ensure @@ -2751,12 +2770,7 @@ public class WifiStateMachine extends HierarchicalStateMachine { WifiNative.enableBackgroundScan(true); } } else { - long scanMs = Settings.Secure.getLong(mContext.getContentResolver(), - Settings.Secure.WIFI_SCAN_INTERVAL_MS, DEFAULT_SCAN_INTERVAL_MS); - - mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, - System.currentTimeMillis() + scanMs, scanMs, mScanIntent); - mAlarmEnabled = true; + setScanAlarm(true); } } @Override @@ -2774,7 +2788,13 @@ public class WifiStateMachine extends HierarchicalStateMachine { break; case CMD_ENABLE_BACKGROUND_SCAN: mEnableBackgroundScan = (message.arg1 == 1); - WifiNative.enableBackgroundScan(mEnableBackgroundScan); + if (mEnableBackgroundScan) { + WifiNative.enableBackgroundScan(true); + setScanAlarm(false); + } else { + WifiNative.enableBackgroundScan(false); + setScanAlarm(true); + } break; /* Ignore network disconnect */ case NETWORK_DISCONNECTION_EVENT: @@ -2811,10 +2831,7 @@ public class WifiStateMachine extends HierarchicalStateMachine { if (mEnableBackgroundScan) { WifiNative.enableBackgroundScan(false); } - if (mAlarmEnabled) { - mAlarmManager.cancel(mScanIntent); - mAlarmEnabled = false; - } + setScanAlarm(false); } } |