diff options
author | Rebecca Silberstein <silberst@google.com> | 2017-05-12 13:53:23 -0700 |
---|---|---|
committer | Rebecca Silberstein <silberst@google.com> | 2017-05-19 09:32:43 -0700 |
commit | a39790ac184ea4b5fb5422c06d0aea0f03fbc6db (patch) | |
tree | 88e605691754ae6a5ccad67fde13dbd76c11f52e /service | |
parent | a2cbd2429606052cf6f2306c54f8c590d7a55174 (diff) |
WifiServiceImpl: implement startLOHS
When an application requests LOHS, check current state for incompatible
modes, outstanding requests and then register a request object for that
caller. If this is the first caller, WifiServiceImpl will then trigger
WifiController to start softap mode. When the softap mode switch
completes, callers will be notified of the outcome via the
LocalOnlyHotspotCallback api.
Bug: 31466854
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: If54756914f4daf5aab1663e6d747ead68d42fd1e
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiServiceImpl.java | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 703294ee5..aa1316d4e 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -26,6 +26,7 @@ import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED; import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLING; import static android.net.wifi.WifiManager.WIFI_AP_STATE_FAILED; +import static com.android.server.connectivity.tethering.IControlsTethering.STATE_LOCAL_ONLY; import static com.android.server.connectivity.tethering.IControlsTethering.STATE_TETHERED; import static com.android.server.wifi.LocalOnlyHotspotRequestInfo.HOTSPOT_NO_ERROR; import static com.android.server.wifi.WifiController.CMD_AIRPLANE_TOGGLED; @@ -930,6 +931,11 @@ public class WifiServiceImpl extends IWifiManager.Stub { mLog.trace("startSoftAp uid=%").c(Binder.getCallingUid()).flush(); + // TODO: determine if we need to stop softap and clean up state if a tethering request comes + // from the user while we are just setting up. For now, the second CMD_START_AP will be + // ignored in WifiStateMachine. This will still bring up tethering and the registered LOHS + // requests will be cleared when we get the interface ip tethered status. + return startSoftApInternal(wifiConfig, STATE_TETHERED); } @@ -1093,7 +1099,6 @@ public class WifiServiceImpl extends IWifiManager.Stub { * Temporary method used for testing while startLocalOnlyHotspot is not fully implemented. This * method allows unit tests to register callbacks directly for testing mechanisms triggered by * softap mode changes. - * TODO: remove when startLocalOnlyHotspot is implemented. */ @VisibleForTesting void registerLOHSForTest(int pid, LocalOnlyHotspotRequestInfo request) { @@ -1142,19 +1147,16 @@ public class WifiServiceImpl extends IWifiManager.Stub { mLog.trace("startLocalOnlyHotspot uid=% pid=%").c(uid).c(pid).flush(); - // check current mode to see if we can start localOnlyHotspot - boolean apDisabled = - mWifiStateMachine.syncGetWifiApState() == WifiManager.WIFI_AP_STATE_DISABLED; - synchronized (mLocalOnlyHotspotRequests) { - if (!apDisabled && mLocalOnlyHotspotRequests.isEmpty()) { + // check if we are currently tethering + if (mIfaceIpModes.contains(WifiManager.IFACE_IP_MODE_TETHERED)) { // Tethering is enabled, cannot start LocalOnlyHotspot mLog.trace("Cannot start localOnlyHotspot when WiFi Tethering is active."); return LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE; } // does this caller already have a request? - LocalOnlyHotspotRequestInfo request = mLocalOnlyHotspotRequests.get(uid); + LocalOnlyHotspotRequestInfo request = mLocalOnlyHotspotRequests.get(pid); if (request != null) { mLog.trace("caller already has an active request"); throw new IllegalStateException( @@ -1164,24 +1166,26 @@ public class WifiServiceImpl extends IWifiManager.Stub { // now create the new LOHS request info object request = new LocalOnlyHotspotRequestInfo(binder, messenger, new LocalOnlyRequestorCallback()); - // TODO: move this below when start is implemented - mLocalOnlyHotspotRequests.put(uid, request); - // check if LOHS is already active, if so, record the request and trigger the callback + // check current operating state and take action if needed if (mIfaceIpModes.contains(WifiManager.IFACE_IP_MODE_LOCAL_ONLY)) { + // LOHS is already active, send out what is running try { - Slog.d(TAG, "LOHS already up, send started"); + mLog.trace("LOHS already up, trigger onStarted callback"); request.sendHotspotStartedMessage(mLocalOnlyHotspotConfig); - // TODO: move this return value out of the try when start is implemented - return LocalOnlyHotspotCallback.REQUEST_REGISTERED; } catch (RemoteException e) { - mLocalOnlyHotspotRequests.remove(uid); return LocalOnlyHotspotCallback.ERROR_GENERIC; } + } else if (mLocalOnlyHotspotRequests.isEmpty()) { + // this is the first request, then set up our config and start LOHS + mLocalOnlyHotspotConfig = + WifiApConfigStore.generateLocalOnlyHotspotConfig(mContext); + startSoftApInternal(mLocalOnlyHotspotConfig, STATE_LOCAL_ONLY); } - } - throw new UnsupportedOperationException("LocalOnlyHotspot is still in development"); + mLocalOnlyHotspotRequests.put(pid, request); + return LocalOnlyHotspotCallback.REQUEST_REGISTERED; + } } /** @@ -1224,6 +1228,7 @@ public class WifiServiceImpl extends IWifiManager.Stub { if (mLocalOnlyHotspotRequests.isEmpty()) { mLocalOnlyHotspotConfig = null; + updateInterfaceIpStateInternal(null, WifiManager.IFACE_IP_MODE_UNSPECIFIED); // if that was the last caller, then call stopSoftAp as WifiService long identity = Binder.clearCallingIdentity(); try { |