return doBooleanCommand(cmdstr, "OK");
}
-
static jboolean android_net_wifi_doDhcpRequest(JNIEnv* env, jobject clazz, jobject info)
{
jint ipaddr, gateway, mask, dns1, dns2, server, lease;
return env->NewStringUTF(::get_dhcp_error_string());
}
+static void android_net_wifi_enableBackgroundScan(JNIEnv* env, jobject clazz, jboolean enable)
+{
+ //Note: BGSCAN-START and BGSCAN-STOP are documented in core/res/res/values/config.xml
+ //and will need an update if the names are changed
+ if (enable) {
+ doBooleanCommand("DRIVER BGSCAN-START", "OK");
+ }
+ else {
+ doBooleanCommand("DRIVER BGSCAN-STOP", "OK");
+ }
+}
+
// ----------------------------------------------------------------------------
/*
(void*) android_net_wifi_setCountryCodeCommand},
{ "doDhcpRequest", "(Landroid/net/DhcpInfo;)Z", (void*) android_net_wifi_doDhcpRequest },
{ "getDhcpError", "()Ljava/lang/String;", (void*) android_net_wifi_getDhcpError },
+ { "enableBackgroundScan", "(Z)V", (void*) android_net_wifi_enableBackgroundScan},
};
int register_android_net_wifi_WifiManager(JNIEnv* env)
private boolean mDeviceIdle;
private int mPluggedType;
+ /* Chipset supports background scan */
+ private final boolean mBackgroundScanSupported;
+
// true if the user enabled Wifi while in airplane mode
private AtomicBoolean mAirplaneModeOverwridden = new AtomicBoolean(false);
Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, 900) * 1000l;
mNotificationEnabledSettingObserver = new NotificationEnabledSettingObserver(new Handler());
mNotificationEnabledSettingObserver.register();
+
+ mBackgroundScanSupported = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_wifi_background_scan_support);
}
/**
// because of any locks so clear that tracking immediately.
reportStartWorkSource();
mWifiStateMachine.enableRssiPolling(true);
+ if (mBackgroundScanSupported) {
+ mWifiStateMachine.enableBackgroundScan(false);
+ }
mWifiStateMachine.enableAllNetworks();
updateWifiState();
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
}
mScreenOff = true;
mWifiStateMachine.enableRssiPolling(false);
+ if (mBackgroundScanSupported) {
+ mWifiStateMachine.enableBackgroundScan(true);
+ }
/*
* Set a timer to put Wi-Fi to sleep, but only if the screen is off
* AND the "stay on while plugged in" setting doesn't match the
private String mLastBssid;
private int mLastNetworkId;
private boolean mEnableRssiPolling = false;
+ private boolean mEnableBackgroundScan = false;
private int mRssiPollToken = 0;
private int mReconnectCount = 0;
private boolean mIsScanMode = false;
+ private boolean mScanResultIsPending = false;
private boolean mBluetoothConnectionActive = false;
static final int CMD_START_WPS = 89;
/* Set the frequency band */
static final int CMD_SET_FREQUENCY_BAND = 90;
+ /* Enable background scan for configured networks */
+ static final int CMD_ENABLE_BACKGROUND_SCAN = 91;
/* Commands from/to the SupplicantStateTracker */
/* Reset the supplicant state tracker */
sendMessage(obtainMessage(CMD_ENABLE_RSSI_POLL, enabled ? 1 : 0, 0));
}
+ public void enableBackgroundScan(boolean enabled) {
+ sendMessage(obtainMessage(CMD_ENABLE_BACKGROUND_SCAN, enabled ? 1 : 0, 0));
+ }
+
public void enableAllNetworks() {
sendMessage(CMD_ENABLE_ALL_NETWORKS);
}
case CMD_ENABLE_RSSI_POLL:
mEnableRssiPolling = (message.arg1 == 1);
break;
+ case CMD_ENABLE_BACKGROUND_SCAN:
+ mEnableBackgroundScan = (message.arg1 == 1);
+ break;
/* Discard */
case CMD_LOAD_DRIVER:
case CMD_UNLOAD_DRIVER:
eventLoggingEnabled = false;
setScanResults(WifiNative.scanResultsCommand());
sendScanResultsAvailableBroadcast();
+ mScanResultIsPending = false;
break;
case CMD_PING_SUPPLICANT:
boolean ok = WifiNative.pingCommand();
case CMD_START_SCAN:
eventLoggingEnabled = false;
WifiNative.scanCommand(message.arg1 == SCAN_ACTIVE);
+ mScanResultIsPending = true;
break;
case CMD_SET_HIGH_PERF_MODE:
setHighPerfModeEnabledNative(message.arg1 == 1);
* back to CONNECT_MODE.
*/
WifiNative.setScanResultHandlingCommand(SCAN_ONLY_MODE);
- WifiNative.scanCommand(message.arg1 == SCAN_ACTIVE);
- break;
+ /* Have the parent state handle the rest */
+ return NOT_HANDLED;
/* Ignore connection to same network */
case CMD_CONNECT_NETWORK:
int netId = message.arg1;
}
class DisconnectedState extends HierarchicalState {
+ private boolean mAlarmEnabled = false;
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
- /**
- * In a disconnected state, an infrequent scan that wakes
- * up the device is needed to ensure a user connects to
- * an access point on the move
+ /*
+ * We initiate background scanning if it is enabled, otherwise we
+ * initiate an infrequent scan that wakes up the device to ensure
+ * a user connects to an access point on the move
*/
- long scanMs = Settings.Secure.getLong(mContext.getContentResolver(),
+ if (mEnableBackgroundScan) {
+ /* If a regular scan result is pending, do not initiate background
+ * scan until the scan results are returned. This is needed because
+ * initiating a background scan will cancel the regular scan and
+ * scan results will not be returned until background scanning is
+ * cleared
+ */
+ if (!mScanResultIsPending) {
+ 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,
+ mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + scanMs, scanMs, mScanIntent);
+ mAlarmEnabled = true;
+ }
}
@Override
public boolean processMessage(Message message) {
transitionTo(mScanModeState);
}
break;
+ case CMD_ENABLE_BACKGROUND_SCAN:
+ mEnableBackgroundScan = (message.arg1 == 1);
+ WifiNative.enableBackgroundScan(mEnableBackgroundScan);
+ break;
/* Ignore network disconnect */
case NETWORK_DISCONNECTION_EVENT:
break;
setNetworkDetailedState(WifiInfo.getDetailedStateOf(stateChangeResult.state));
/* DriverStartedState does the rest of the handling */
return NOT_HANDLED;
+ case CMD_START_SCAN:
+ /* Disable background scan temporarily during a regular scan */
+ if (mEnableBackgroundScan) {
+ WifiNative.enableBackgroundScan(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);
+ }
+ /* Handled in parent state */
+ return NOT_HANDLED;
default:
return NOT_HANDLED;
}
@Override
public void exit() {
- mAlarmManager.cancel(mScanIntent);
+ /* No need for a background scan upon exit from a disconnected state */
+ if (mEnableBackgroundScan) {
+ WifiNative.enableBackgroundScan(false);
+ }
+ if (mAlarmEnabled) {
+ mAlarmManager.cancel(mScanIntent);
+ mAlarmEnabled = false;
+ }
}
}