diff options
author | Nalla Kartheek <karthe@codeaurora.org> | 2016-07-14 20:11:09 +0530 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2016-08-24 08:07:57 -0600 |
commit | 1ee1fbfd13eaf49103b5fa8382b6ce14750ab016 (patch) | |
tree | a803d5f7887fe1fcd5d433d4332198a43fbbf78f | |
parent | b2f445178cdfd827ac6f59eb9ac056dce9234267 (diff) | |
download | android_frameworks_opt_net_wifi-1ee1fbfd13eaf49103b5fa8382b6ce14750ab016.tar.gz android_frameworks_opt_net_wifi-1ee1fbfd13eaf49103b5fa8382b6ce14750ab016.tar.bz2 android_frameworks_opt_net_wifi-1ee1fbfd13eaf49103b5fa8382b6ce14750ab016.zip |
Wifi: Implement auto connection
Auto connection dictates capability of hand-off between LTE and Wi-Fi
network and also selection of a specific Wi-Fi network. Trigger for auto
connection is done via user interface.
Change-Id: I2a161aa8721a42681d92e30017a128b2897607f2
CRs-Fixed: 982864
3 files changed, 108 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/WifiQualifiedNetworkSelector.java b/service/java/com/android/server/wifi/WifiQualifiedNetworkSelector.java index 241ddb8af..41ecba2b9 100644 --- a/service/java/com/android/server/wifi/WifiQualifiedNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiQualifiedNetworkSelector.java @@ -54,6 +54,7 @@ public class WifiQualifiedNetworkSelector { private WifiNetworkScoreCache mNetworkScoreCache; private Clock mClock; private static final String TAG = "WifiQualifiedNetworkSelector:"; + private boolean skipQualifiedNetworkSelectionForAutoConnect = false; // Always enable debugging logs for now since QNS is still a new feature. private static final boolean FORCE_DEBUG = true; private boolean mDbg = FORCE_DEBUG; @@ -258,6 +259,9 @@ public class WifiQualifiedNetworkSelector { return true; } + public void skipQualifiedNetworkSelectionForAutoConnect(boolean enable) { + skipQualifiedNetworkSelectionForAutoConnect = enable; + } /** * check whether QualifiedNetworkSelection is needed or not * @@ -284,6 +288,10 @@ public class WifiQualifiedNetworkSelector { localLog("Need not Qualified Network Selection during L2 debouncing"); return false; } + if (skipQualifiedNetworkSelectionForAutoConnect) { + localLog("Skip network selction, since auto connection disabled"); + return false; + } if (isConnected) { //already connected. Just try to find better candidate diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 8193ec8cb..782b68568 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -566,6 +566,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss // Provide packet filter capabilities to ConnectivityService. private final NetworkMisc mNetworkMisc = new NetworkMisc(); + private static final int WIFI_AUTO_CONNECT_TYPE_AUTO = 0; /* The base for wifi message types */ static final int BASE = Protocol.BASE_WIFI; @@ -1135,6 +1136,14 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss }, new IntentFilter(Intent.ACTION_BOOT_COMPLETED)); + mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor( + Settings.Global.WIFI_AUTO_CONNECT_TYPE), false, + new ContentObserver(getHandler()) { + @Override + public void onChange(boolean selfChange) { + checkAndSetAutoConnection(); + } + }); PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getName()); @@ -3568,7 +3577,16 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss stopRssiMonitoringOffload(); clearCurrentConfigBSSID("handleNetworkDisconnect"); - + if (mContext.getResources().getBoolean(R.bool.wifi_autocon) + && !shouldAutoConnect()) { + /* + * The following logic shall address the requirement for the DUT to + * not reconnect to the last connected network when the Auto + * Connect is disabled. This asks for the user prompt for any + * connection attempt (as per the requirement) + */ + disableLastNetwork(); + } stopIpManager(); /* Reset data structures */ @@ -4404,6 +4422,10 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss if (mWifiConfigManager.mEnableVerboseLogging.get() > 0) { enableVerboseLogging(mWifiConfigManager.mEnableVerboseLogging.get()); } + if (mContext.getResources().getBoolean(R.bool.wifi_autocon) + && !shouldAutoConnect()) { + mWifiConfigManager.disableAllNetworksNative(); + } initializeWpsDetails(); sendSupplicantConnectionChangedBroadcast(true); @@ -4463,6 +4485,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss setRandomMacOui(); mWifiNative.enableAutoConnect(false); + checkAndSetAutoConnection(); mCountryCode.setReadyForChange(true); } @@ -4826,7 +4849,14 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss break; case CMD_START_DRIVER: if (mOperationalMode == CONNECT_MODE) { - mWifiConfigManager.enableAllNetworks(); + if (mContext.getResources().getBoolean(R.bool.wifi_autocon) + && !shouldAutoConnect()) { + if (DBG) { + logd("Auto connect disabled, skip enable networks"); + } + } else { + mWifiConfigManager.enableAllNetworks(); + } } break; case CMD_SET_SUSPEND_OPT_ENABLED: @@ -5040,7 +5070,14 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss mWifiConfigManager.loadAndEnableAllNetworks(); mWifiP2pChannel.sendMessage(CMD_ENABLE_P2P); } else { - mWifiConfigManager.enableAllNetworks(); + if (mContext.getResources().getBoolean(R.bool.wifi_autocon) + && !shouldAutoConnect()) { + if (DBG) { + logd("No auto, skip enable networks on mode change"); + } + } else { + mWifiConfigManager.enableAllNetworks(); + } } // Loose last selection choice since user toggled WiFi @@ -7073,8 +7110,20 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss testNetworkDisconnectCounter, 0), 15000); } - // Reenable all networks, allow for hidden networks to be scanned - mWifiConfigManager.enableAllNetworks(); + if (!getEnableAutoJoinWhenAssociated()) { + if (mContext.getResources().getBoolean(R.bool.wifi_autocon) + && !shouldAutoConnect()) { + if (DBG) { + logd("Auto connect disabled, skip enable networks"); + } + } else { + // Reenable all networks, allow for hidden networks to be scanned + mWifiConfigManager.enableAllNetworks(); + } + } else { + // Reenable all networks, allow for hidden networks to be scanned + mWifiConfigManager.enableAllNetworks(); + } mLastDriverRoamAttempt = 0; mTargetNetworkId = WifiConfiguration.INVALID_NETWORK_ID; @@ -8229,4 +8278,41 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss } return null; } + + boolean shouldAutoConnect() { + int autoConnectPolicy = Settings.Global.getInt( + mContext.getContentResolver(), + Settings.Global.WIFI_AUTO_CONNECT_TYPE, + WIFI_AUTO_CONNECT_TYPE_AUTO); + if (DBG) { + if (autoConnectPolicy == WIFI_AUTO_CONNECT_TYPE_AUTO) { + Log.d(TAG, "Wlan connection type is auto, should auto connect"); + } else { + Log.d(TAG, "Shouldn't auto connect"); + } + } + return (autoConnectPolicy == WIFI_AUTO_CONNECT_TYPE_AUTO); + } + + void disableLastNetwork() { + if (getCurrentState() != mSupplicantStoppingState) { + mWifiConfigManager.disableNetwork(mLastNetworkId); + } + } + + void checkAndSetAutoConnection() { + if (mContext.getResources().getBoolean(R.bool.wifi_autocon)) { + if (shouldAutoConnect()){ + mWifiQualifiedNetworkSelector.skipQualifiedNetworkSelectionForAutoConnect(false); + } else { + mWifiQualifiedNetworkSelector.skipQualifiedNetworkSelectionForAutoConnect(true); + /* + * This is AutoConnect -> Manual selection case + * Device should not auto connect to network, hence + * disable supplicants auto connection ability. + */ + mWifiNative.enableAutoConnect(false); + } + } + } } diff --git a/service/java/com/android/server/wifi/scanner/SupplicantWifiScannerImpl.java b/service/java/com/android/server/wifi/scanner/SupplicantWifiScannerImpl.java index 3f93c9074..ab013b1e0 100644 --- a/service/java/com/android/server/wifi/scanner/SupplicantWifiScannerImpl.java +++ b/service/java/com/android/server/wifi/scanner/SupplicantWifiScannerImpl.java @@ -25,6 +25,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.util.Log; +import android.provider.Settings; import com.android.internal.R; import com.android.server.wifi.Clock; @@ -665,6 +666,14 @@ public class SupplicantWifiScannerImpl extends WifiScannerImpl implements Handle Log.e(TAG, "Set priority failed for: " + network.networkId); return false; } + int autoConnectPolicy = Settings.Global.getInt( + mContext.getContentResolver(), + Settings.Global.WIFI_AUTO_CONNECT_TYPE,0); + if (autoConnectPolicy == 1) { + Log.d(TAG,"Do not enable network,since auto connect disabled"); + return true; + } + if (!mWifiNative.enableNetworkWithoutConnect(network.networkId)) { Log.e(TAG, "Enable network failed for: " + network.networkId); return false; |