OSDN Git Service

Fix issue to clear scan alarms
authorIrfan Sheriff <isheriff@google.com>
Mon, 28 Feb 2011 20:08:11 +0000 (12:08 -0800)
committerIrfan Sheriff <isheriff@google.com>
Mon, 28 Feb 2011 20:29:33 +0000 (12:29 -0800)
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

wifi/java/android/net/wifi/WifiStateMachine.java

index 65f2a19..931fd40 100644 (file)
@@ -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);
         }
     }