OSDN Git Service

WifiManager: update API for LOHS
authorRebecca Silberstein <silberst@google.com>
Sun, 30 Apr 2017 21:05:00 +0000 (14:05 -0700)
committerRebecca Silberstein <silberst@google.com>
Mon, 1 May 2017 18:41:53 +0000 (11:41 -0700)
Add a return code for disallowed tethering for the user.  Also updated
call to startLocalOnlyHotspot in WifiServiceImpl to return a code
instead of a config.  This allows us to return different failure modes
to the application instead of assuming an incompatible mode error.

Also updated method name to retrieve the wifi config.

Bug: 37073685
Test: frameworks/base/wifi/tests/runtests.sh
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: Iaa442f7062145dbfbdc8e26ae5479d14307addf8

wifi/java/android/net/wifi/IWifiManager.aidl
wifi/java/android/net/wifi/WifiManager.java
wifi/tests/src/android/net/wifi/WifiManagerTest.java

index faae90b..d942d05 100644 (file)
@@ -131,7 +131,7 @@ interface IWifiManager
 
     boolean stopSoftAp();
 
-    WifiConfiguration startLocalOnlyHotspot(in Messenger messenger, in IBinder binder);
+    int startLocalOnlyHotspot(in Messenger messenger, in IBinder binder);
 
     void stopLocalOnlyHotspot();
 
index 8fbf472..5101118 100644 (file)
@@ -478,7 +478,6 @@ public class WifiManager {
      */
     public static final int IFACE_IP_MODE_LOCAL_ONLY = 2;
 
-
     /**
      * Broadcast intent action indicating that a connection to the supplicant has
      * been established (and it is now possible
@@ -1850,8 +1849,9 @@ public class WifiManager {
      * Tethering to provide an upstream to another device, LocalOnlyHotspot will not start due to
      * an incompatible mode. The possible error codes include:
      * {@link LocalOnlyHotspotCallback#ERROR_NO_CHANNEL},
-     * {@link LocalOnlyHotspotCallback#ERROR_GENERIC} and
-     * {@link LocalOnlyHotspotCallback#ERROR_INCOMPATIBLE_MODE}.
+     * {@link LocalOnlyHotspotCallback#ERROR_GENERIC},
+     * {@link LocalOnlyHotspotCallback#ERROR_INCOMPATIBLE_MODE} and
+     * {@link LocalOnlyHotspotCallback#ERROR_TETHERING_DISALLOWED}.
      * <p>
      * Internally, requests will be tracked to prevent the hotspot from being torn down while apps
      * are still using it.  The {@link LocalOnlyHotspotReservation} object passed in the  {@link
@@ -1892,12 +1892,10 @@ public class WifiManager {
             LocalOnlyHotspotCallbackProxy proxy =
                     new LocalOnlyHotspotCallbackProxy(this, looper, callback);
             try {
-                WifiConfiguration config = mService.startLocalOnlyHotspot(
-                        proxy.getMessenger(), new Binder());
-                if (config == null) {
+                int returnCode = mService.startLocalOnlyHotspot(proxy.getMessenger(), new Binder());
+                if (returnCode != LocalOnlyHotspotCallback.REQUEST_REGISTERED) {
                     // Send message to the proxy to make sure we call back on the correct thread
-                    proxy.notifyFailed(
-                            LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE);
+                    proxy.notifyFailed(returnCode);
                     return;
                 }
                 mLOHSCallbackProxy = proxy;
@@ -2289,7 +2287,7 @@ public class WifiManager {
             mCloseGuard.open("close");
         }
 
-        public WifiConfiguration getConfig() {
+        public WifiConfiguration getWifiConfiguration() {
             return mConfig;
         }
 
@@ -2322,9 +2320,13 @@ public class WifiManager {
      * @hide
      */
     public static class LocalOnlyHotspotCallback {
+        /** @hide */
+        public static final int REQUEST_REGISTERED = 0;
+
         public static final int ERROR_NO_CHANNEL = 1;
         public static final int ERROR_GENERIC = 2;
         public static final int ERROR_INCOMPATIBLE_MODE = 3;
+        public static final int ERROR_TETHERING_DISALLOWED = 4;
 
         /** LocalOnlyHotspot start succeeded. */
         public void onStarted(LocalOnlyHotspotReservation reservation) {};
@@ -2345,7 +2347,8 @@ public class WifiManager {
          * {@link WifiManager#startLocalOnlyHotspot(LocalOnlyHotspotCallback, Handler)} again at
          * a later time.
          * <p>
-         * @param reason The reason for failure could be one of: {@link #ERROR_INCOMPATIBLE_MODE},
+         * @param reason The reason for failure could be one of: {@link
+         * #ERROR_TETHERING_DISALLOWED}, {@link #ERROR_INCOMPATIBLE_MODE},
          * {@link #ERROR_NO_CHANNEL}, or {@link #ERROR_GENERIC}.
          */
         public void onFailed(int reason) { };
index 3c0fc6e..03ef319 100644 (file)
@@ -22,6 +22,7 @@ import static android.net.wifi.WifiManager.HOTSPOT_STOPPED;
 import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_GENERIC;
 import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE;
 import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_NO_CHANNEL;
+import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.REQUEST_REGISTERED;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -125,12 +126,12 @@ public class WifiManagerTest {
     public void testCreationAndCloseOfLocalOnlyHotspotReservation() throws Exception {
         TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
         when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)))
-                            .thenReturn(mApConfig);
+                            .thenReturn(REQUEST_REGISTERED);
         mWifiManager.startLocalOnlyHotspot(callback, mHandler);
 
         callback.onStarted(mWifiManager.new LocalOnlyHotspotReservation(mApConfig));
 
-        assertEquals(mApConfig, callback.mRes.getConfig());
+        assertEquals(mApConfig, callback.mRes.getWifiConfiguration());
         callback.mRes.close();
         verify(mWifiService).stopLocalOnlyHotspot();
     }
@@ -143,13 +144,13 @@ public class WifiManagerTest {
             throws Exception {
         TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
         when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)))
-                .thenReturn(mApConfig);
+                .thenReturn(REQUEST_REGISTERED);
         mWifiManager.startLocalOnlyHotspot(callback, mHandler);
 
         callback.onStarted(mWifiManager.new LocalOnlyHotspotReservation(mApConfig));
 
         try (WifiManager.LocalOnlyHotspotReservation res = callback.mRes) {
-            assertEquals(mApConfig, res.getConfig());
+            assertEquals(mApConfig, res.getWifiConfiguration());
         }
 
         verify(mWifiService).stopLocalOnlyHotspot();
@@ -337,7 +338,7 @@ public class WifiManagerTest {
         // record thread from looper.getThread and check ids.
         TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
         when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)))
-                .thenReturn(null);
+                .thenReturn(ERROR_INCOMPATIBLE_MODE);
         mWifiManager.startLocalOnlyHotspot(callback, mHandler);
         mLooper.dispatchAll();
         assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason);
@@ -355,7 +356,7 @@ public class WifiManagerTest {
         when(mContext.getMainLooper()).thenReturn(altLooper.getLooper());
         TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
         when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)))
-                .thenReturn(null);
+                .thenReturn(ERROR_INCOMPATIBLE_MODE);
         mWifiManager.startLocalOnlyHotspot(callback, null);
         altLooper.dispatchAll();
         assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason);
@@ -372,7 +373,7 @@ public class WifiManagerTest {
         TestLooper callbackLooper = new TestLooper();
         Handler callbackHandler = new Handler(callbackLooper.getLooper());
         when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(),
-                  any(IBinder.class))).thenReturn(mApConfig);
+                  any(IBinder.class))).thenReturn(REQUEST_REGISTERED);
         mWifiManager.startLocalOnlyHotspot(callback, callbackHandler);
         callbackLooper.dispatchAll();
         mLooper.dispatchAll();
@@ -386,7 +387,7 @@ public class WifiManagerTest {
         mLooper.dispatchAll();
         callbackLooper.dispatchAll();
         assertTrue(callback.mOnStartedCalled);
-        assertEquals(mApConfig, callback.mRes.getConfig());
+        assertEquals(mApConfig, callback.mRes.getWifiConfiguration());
     }
 
     /**
@@ -399,7 +400,7 @@ public class WifiManagerTest {
         TestLooper callbackLooper = new TestLooper();
         Handler callbackHandler = new Handler(callbackLooper.getLooper());
         when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(),
-                  any(IBinder.class))).thenReturn(mApConfig);
+                  any(IBinder.class))).thenReturn(REQUEST_REGISTERED);
         mWifiManager.startLocalOnlyHotspot(callback, callbackHandler);
         callbackLooper.dispatchAll();
         mLooper.dispatchAll();
@@ -424,7 +425,7 @@ public class WifiManagerTest {
         TestLooper callbackLooper = new TestLooper();
         Handler callbackHandler = new Handler(callbackLooper.getLooper());
         when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(),
-                  any(IBinder.class))).thenReturn(mApConfig);
+                  any(IBinder.class))).thenReturn(REQUEST_REGISTERED);
         mWifiManager.startLocalOnlyHotspot(callback, callbackHandler);
         callbackLooper.dispatchAll();
         mLooper.dispatchAll();
@@ -447,7 +448,7 @@ public class WifiManagerTest {
         TestLooper callbackLooper = new TestLooper();
         Handler callbackHandler = new Handler(callbackLooper.getLooper());
         when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(),
-                  any(IBinder.class))).thenReturn(mApConfig);
+                  any(IBinder.class))).thenReturn(REQUEST_REGISTERED);
         mWifiManager.startLocalOnlyHotspot(callback, callbackHandler);
         callbackLooper.dispatchAll();
         mLooper.dispatchAll();
@@ -470,7 +471,7 @@ public class WifiManagerTest {
     public void testLocalOnlyHotspotCallbackFullOnNullConfig() throws Exception {
         TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
         when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)))
-                .thenReturn(null);
+                .thenReturn(ERROR_INCOMPATIBLE_MODE);
         mWifiManager.startLocalOnlyHotspot(callback, mHandler);
         mLooper.dispatchAll();
         assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason);
@@ -508,7 +509,7 @@ public class WifiManagerTest {
     public void testLocalOnlyHotspotCallbackFullOnNoChannelError() throws Exception {
         TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
         when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)))
-                .thenReturn(mApConfig);
+                .thenReturn(REQUEST_REGISTERED);
         mWifiManager.startLocalOnlyHotspot(callback, mHandler);
         mLooper.dispatchAll();
         //assertEquals(ERROR_NO_CHANNEL, callback.mFailureReason);
@@ -524,7 +525,7 @@ public class WifiManagerTest {
     public void testCancelLocalOnlyHotspotRequestCallsStopOnWifiService() throws Exception {
         TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
         when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)))
-                .thenReturn(mApConfig);
+                .thenReturn(REQUEST_REGISTERED);
         mWifiManager.startLocalOnlyHotspot(callback, mHandler);
         mWifiManager.cancelLocalOnlyHotspotRequest();
         verify(mWifiService).stopLocalOnlyHotspot();
@@ -546,7 +547,7 @@ public class WifiManagerTest {
     public void testCallbackAfterLocalOnlyHotspotWasCancelled() throws Exception {
         TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
         when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)))
-                .thenReturn(mApConfig);
+                .thenReturn(REQUEST_REGISTERED);
         mWifiManager.startLocalOnlyHotspot(callback, mHandler);
         mWifiManager.cancelLocalOnlyHotspotRequest();
         verify(mWifiService).stopLocalOnlyHotspot();
@@ -565,7 +566,7 @@ public class WifiManagerTest {
     public void testCancelAfterLocalOnlyHotspotCallbackTriggered() throws Exception {
         TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
         when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)))
-                .thenReturn(null);
+                .thenReturn(ERROR_INCOMPATIBLE_MODE);
         mWifiManager.startLocalOnlyHotspot(callback, mHandler);
         mLooper.dispatchAll();
         assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason);