summaryrefslogtreecommitdiffstats
path: root/wifi/java/android
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2011-03-25 14:29:19 -0700
committerIrfan Sheriff <isheriff@google.com>2011-04-06 09:11:15 -0700
commit2b7f63887e39079a52592fb4507d8daaf90e8afa (patch)
treeca7a52132f7dd38e083cc8cc7e0571a789fa70b0 /wifi/java/android
parent3b2c5a9a09057ad07331bceae983ce0d4ce852ac (diff)
downloadframeworks_base-2b7f63887e39079a52592fb4507d8daaf90e8afa.zip
frameworks_base-2b7f63887e39079a52592fb4507d8daaf90e8afa.tar.gz
frameworks_base-2b7f63887e39079a52592fb4507d8daaf90e8afa.tar.bz2
Add support for supplicant SCAN_INTERVAL
Also, allow scan interval for framework and supplicant to be configured at build time or run time Bug: 4144882 Change-Id: I877f4bcc872597b44d3f4da85cf2bc0f16e09444
Diffstat (limited to 'wifi/java/android')
-rw-r--r--wifi/java/android/net/wifi/WifiNative.java4
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java64
2 files changed, 48 insertions, 20 deletions
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index 909605dc..6e13d0f 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -171,5 +171,7 @@ public class WifiNative {
*/
public native static String waitForEvent();
- public native static void enableBackgroundScan(boolean enable);
+ public native static void enableBackgroundScanCommand(boolean enable);
+
+ public native static void setScanIntervalCommand(int scanInterval);
}
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 4346b327..46c07a3 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -339,10 +339,20 @@ public class WifiStateMachine extends HierarchicalStateMachine {
private static final int POWER_MODE_AUTO = 0;
/**
- * See {@link Settings.Secure#WIFI_SCAN_INTERVAL_MS}. This is the default value if a
- * Settings.Secure value is not present.
+ * Default framework scan interval in milliseconds. This is used in the scenario in which
+ * wifi chipset does not support background scanning to set up a
+ * periodic wake up scan so that the device can connect to a new access
+ * point on the move. {@link Settings.Secure#WIFI_FRAMEWORK_SCAN_INTERVAL_MS} can
+ * override this.
*/
- private static final long DEFAULT_SCAN_INTERVAL_MS = 60 * 1000; /* 1 minute */
+ private final int mDefaultFrameworkScanIntervalMs;
+
+ /**
+ * Default supplicant scan interval in milliseconds.
+ * {@link Settings.Secure#WIFI_SUPPLICANT_SCAN_INTERVAL_MS} can override this.
+ */
+ private final int mDefaultSupplicantScanIntervalMs;
+
private static final int MIN_RSSI = -200;
private static final int MAX_RSSI = 256;
@@ -472,6 +482,12 @@ public class WifiStateMachine extends HierarchicalStateMachine {
Intent scanIntent = new Intent(ACTION_START_SCAN, null);
mScanIntent = PendingIntent.getBroadcast(mContext, SCAN_REQUEST, scanIntent, 0);
+ mDefaultFrameworkScanIntervalMs = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_wifi_framework_scan_interval);
+
+ mDefaultSupplicantScanIntervalMs = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_wifi_supplicant_scan_interval);
+
mContext.registerReceiver(
new BroadcastReceiver() {
@Override
@@ -819,7 +835,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
sendMessage(obtainMessage(CMD_ENABLE_RSSI_POLL, enabled ? 1 : 0, 0));
}
- public void enableBackgroundScan(boolean enabled) {
+ public void enableBackgroundScanCommand(boolean enabled) {
sendMessage(obtainMessage(CMD_ENABLE_BACKGROUND_SCAN, enabled ? 1 : 0, 0));
}
@@ -1949,6 +1965,11 @@ public class WifiStateMachine extends HierarchicalStateMachine {
mIsScanMode = false;
/* Wifi is available as long as we have a connection to supplicant */
mNetworkInfo.setIsAvailable(true);
+ /* Set scan interval */
+ long supplicantScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
+ Settings.Secure.WIFI_SUPPLICANT_SCAN_INTERVAL_MS,
+ mDefaultSupplicantScanIntervalMs);
+ WifiNative.setScanIntervalCommand((int)supplicantScanIntervalMs / 1000);
}
@Override
public boolean processMessage(Message message) {
@@ -2800,17 +2821,21 @@ public class WifiStateMachine extends HierarchicalStateMachine {
class DisconnectedState extends HierarchicalState {
private boolean mAlarmEnabled = false;
- private long mScanIntervalMs;
+ /* This is set from the overlay config file or from a secure setting.
+ * A value of 0 disables scanning in the framework.
+ */
+ private long mFrameworkScanIntervalMs;
private void setScanAlarm(boolean enabled) {
if (enabled == mAlarmEnabled) return;
if (enabled) {
- mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
- System.currentTimeMillis() + mScanIntervalMs,
- mScanIntervalMs,
- mScanIntent);
-
- mAlarmEnabled = true;
+ if (mFrameworkScanIntervalMs > 0) {
+ mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
+ System.currentTimeMillis() + mFrameworkScanIntervalMs,
+ mFrameworkScanIntervalMs,
+ mScanIntent);
+ mAlarmEnabled = true;
+ }
} else {
mAlarmManager.cancel(mScanIntent);
mAlarmEnabled = false;
@@ -2822,8 +2847,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
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);
+ mFrameworkScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
+ Settings.Secure.WIFI_FRAMEWORK_SCAN_INTERVAL_MS,
+ mDefaultFrameworkScanIntervalMs);
/*
* We initiate background scanning if it is enabled, otherwise we
* initiate an infrequent scan that wakes up the device to ensure
@@ -2837,7 +2863,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
* cleared
*/
if (!mScanResultIsPending) {
- WifiNative.enableBackgroundScan(true);
+ WifiNative.enableBackgroundScanCommand(true);
}
} else {
setScanAlarm(true);
@@ -2859,10 +2885,10 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_ENABLE_BACKGROUND_SCAN:
mEnableBackgroundScan = (message.arg1 == 1);
if (mEnableBackgroundScan) {
- WifiNative.enableBackgroundScan(true);
+ WifiNative.enableBackgroundScanCommand(true);
setScanAlarm(false);
} else {
- WifiNative.enableBackgroundScan(false);
+ WifiNative.enableBackgroundScanCommand(false);
setScanAlarm(true);
}
break;
@@ -2877,14 +2903,14 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_START_SCAN:
/* Disable background scan temporarily during a regular scan */
if (mEnableBackgroundScan) {
- WifiNative.enableBackgroundScan(false);
+ WifiNative.enableBackgroundScanCommand(false);
}
/* Handled in parent state */
return NOT_HANDLED;
case SCAN_RESULTS_EVENT:
/* Re-enable background scan when a pending scan result is received */
if (mEnableBackgroundScan && mScanResultIsPending) {
- WifiNative.enableBackgroundScan(true);
+ WifiNative.enableBackgroundScanCommand(true);
}
/* Handled in parent state */
return NOT_HANDLED;
@@ -2899,7 +2925,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
public void exit() {
/* No need for a background scan upon exit from a disconnected state */
if (mEnableBackgroundScan) {
- WifiNative.enableBackgroundScan(false);
+ WifiNative.enableBackgroundScanCommand(false);
}
setScanAlarm(false);
}