diff options
author | Roshan Pius <rpius@google.com> | 2019-08-23 14:48:27 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-08-28 07:14:47 -0700 |
commit | 4a3847085aa7b93ad53556c16a84afbebc23f7a6 (patch) | |
tree | 1b176b3aa63399cbcef8bdc0b549f21649010ac0 /service | |
parent | 54584c1dc32464af1676d4a26fccacbda5af12c3 (diff) |
WifiNative: Allow in-place switch from connectivity to scan only mode
This allows an in-place modification of the client interface type. This
helps to get rid of the ScanOnlyModeManager.
Also, stop requesting low priority STA iface from HalDeviceManager for
ScanOnly mode.
Bug: 139939529
Test: atest com.android.server.wifi.WifiNativeInterfaceManagementTest
Test: Manual verification by hacking ScanOnlyModeManager &
ClientModeManager to use the new transition API.
Change-Id: I3b8ce63442a46f0f9927af238a1ac722fa13b2a5
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiNative.java | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index b24572626..9a594c801 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -129,7 +129,7 @@ public class WifiNative { /** Identifier allocated for the interface */ public final int id; /** Type of the iface: STA (for Connectivity or Scan) or AP */ - public final @IfaceType int type; + public @IfaceType int type; /** Name of the interface */ public String name; /** Is the interface up? This is used to mask up/down notifications to external clients. */ @@ -998,7 +998,7 @@ public class WifiNative { return null; } iface.externalListener = interfaceCallback; - iface.name = createStaIface(iface, /* lowPrioritySta */ true); + iface.name = createStaIface(iface, /* lowPrioritySta */ false); if (TextUtils.isEmpty(iface.name)) { Log.e(TAG, "Failed to create iface in vendor HAL"); mIfaceMgr.removeIface(iface.id); @@ -1085,6 +1085,77 @@ public class WifiNative { } /** + * Switches an existing Client mode interface from connectivity + * {@link Iface#IFACE_TYPE_STA_FOR_CONNECTIVITY} to scan mode + * {@link Iface#IFACE_TYPE_STA_FOR_SCAN}. + * + * @param ifaceName Name of the interface. + * @return true if the operation succeeded, false if there is an error or the iface is already + * in scan mode. + */ + public boolean switchClientInterfaceToScanMode(@NonNull String ifaceName) { + synchronized (mLock) { + final Iface iface = mIfaceMgr.getIface(ifaceName); + if (iface == null) { + Log.e(TAG, "Trying to switch to scan mode on an invalid iface=" + ifaceName); + return false; + } + if (iface.type == Iface.IFACE_TYPE_STA_FOR_SCAN) { + Log.e(TAG, "Already in scan mode on iface=" + ifaceName); + return true; + } + if (!mSupplicantStaIfaceHal.teardownIface(iface.name)) { + Log.e(TAG, "Failed to teardown iface in supplicant on " + iface); + teardownInterface(iface.name); + return false; + } + iface.type = Iface.IFACE_TYPE_STA_FOR_SCAN; + stopSupplicantIfNecessary(); + Log.i(TAG, "Successfully switched to scan mode on iface=" + iface); + return true; + } + } + + /** + * Switches an existing Client mode interface from scan mode + * {@link Iface#IFACE_TYPE_STA_FOR_SCAN} to connectivity mode + * {@link Iface#IFACE_TYPE_STA_FOR_CONNECTIVITY}. + * + * @param ifaceName Name of the interface. + * @return true if the operation succeeded, false if there is an error or the iface is already + * in scan mode. + */ + public boolean switchClientInterfaceToConnectivityMode(@NonNull String ifaceName) { + synchronized (mLock) { + final Iface iface = mIfaceMgr.getIface(ifaceName); + if (iface == null) { + Log.e(TAG, "Trying to switch to connectivity mode on an invalid iface=" + + ifaceName); + return false; + } + if (iface.type == Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY) { + Log.e(TAG, "Already in connectivity mode on iface=" + ifaceName); + return true; + } + if (!startSupplicant()) { + Log.e(TAG, "Failed to start supplicant"); + teardownInterface(iface.name); + mWifiMetrics.incrementNumSetupClientInterfaceFailureDueToSupplicant(); + return false; + } + if (!mSupplicantStaIfaceHal.setupIface(iface.name)) { + Log.e(TAG, "Failed to setup iface in supplicant on " + iface); + teardownInterface(iface.name); + mWifiMetrics.incrementNumSetupClientInterfaceFailureDueToSupplicant(); + return false; + } + iface.type = Iface.IFACE_TYPE_STA_FOR_CONNECTIVITY; + Log.i(TAG, "Successfully switched to connectivity mode on iface=" + iface); + return true; + } + } + + /** * * Check if the interface is up or down. * |