Merge changes from topic 'LOHSapi' into oc-dev

* changes:
  WifiManager: expose base LOHS apis
  WifiManager: update API for LOHS
This commit is contained in:
Jeff Sharkey
2017-05-01 22:35:01 +00:00
committed by Android (Google) Code Review
6 changed files with 82 additions and 33 deletions

View File

@@ -26525,6 +26525,7 @@ package android.net.wifi {
method public void setTdlsEnabled(java.net.InetAddress, boolean);
method public void setTdlsEnabledWithMacAddress(java.lang.String, boolean);
method public boolean setWifiEnabled(boolean);
method public void startLocalOnlyHotspot(android.net.wifi.WifiManager.LocalOnlyHotspotCallback, android.os.Handler);
method public boolean startScan();
method public void startWps(android.net.wifi.WpsInfo, android.net.wifi.WifiManager.WpsCallback);
method public int updateNetwork(android.net.wifi.WifiConfiguration);
@@ -26575,6 +26576,22 @@ package android.net.wifi {
field public static final int WPS_WEP_PROHIBITED = 4; // 0x4
}
public static class WifiManager.LocalOnlyHotspotCallback {
ctor public WifiManager.LocalOnlyHotspotCallback();
method public void onFailed(int);
method public void onStarted(android.net.wifi.WifiManager.LocalOnlyHotspotReservation);
method public void onStopped();
field public static final int ERROR_GENERIC = 2; // 0x2
field public static final int ERROR_INCOMPATIBLE_MODE = 3; // 0x3
field public static final int ERROR_NO_CHANNEL = 1; // 0x1
field public static final int ERROR_TETHERING_DISALLOWED = 4; // 0x4
}
public class WifiManager.LocalOnlyHotspotReservation implements java.lang.AutoCloseable {
method public void close();
method public android.net.wifi.WifiConfiguration getWifiConfiguration();
}
public class WifiManager.MulticastLock {
method public void acquire();
method public boolean isHeld();

View File

@@ -29063,6 +29063,7 @@ package android.net.wifi {
method public boolean setWifiApConfiguration(android.net.wifi.WifiConfiguration);
method public boolean setWifiApEnabled(android.net.wifi.WifiConfiguration, boolean);
method public boolean setWifiEnabled(boolean);
method public void startLocalOnlyHotspot(android.net.wifi.WifiManager.LocalOnlyHotspotCallback, android.os.Handler);
method public deprecated boolean startLocationRestrictedScan(android.os.WorkSource);
method public boolean startScan();
method public boolean startScan(android.os.WorkSource);
@@ -29140,6 +29141,22 @@ package android.net.wifi {
method public abstract void onSuccess();
}
public static class WifiManager.LocalOnlyHotspotCallback {
ctor public WifiManager.LocalOnlyHotspotCallback();
method public void onFailed(int);
method public void onStarted(android.net.wifi.WifiManager.LocalOnlyHotspotReservation);
method public void onStopped();
field public static final int ERROR_GENERIC = 2; // 0x2
field public static final int ERROR_INCOMPATIBLE_MODE = 3; // 0x3
field public static final int ERROR_NO_CHANNEL = 1; // 0x1
field public static final int ERROR_TETHERING_DISALLOWED = 4; // 0x4
}
public class WifiManager.LocalOnlyHotspotReservation implements java.lang.AutoCloseable {
method public void close();
method public android.net.wifi.WifiConfiguration getWifiConfiguration();
}
public class WifiManager.MulticastLock {
method public void acquire();
method public boolean isHeld();

View File

@@ -26633,6 +26633,7 @@ package android.net.wifi {
method public void setTdlsEnabled(java.net.InetAddress, boolean);
method public void setTdlsEnabledWithMacAddress(java.lang.String, boolean);
method public boolean setWifiEnabled(boolean);
method public void startLocalOnlyHotspot(android.net.wifi.WifiManager.LocalOnlyHotspotCallback, android.os.Handler);
method public boolean startScan();
method public void startWps(android.net.wifi.WpsInfo, android.net.wifi.WifiManager.WpsCallback);
method public int updateNetwork(android.net.wifi.WifiConfiguration);
@@ -26683,6 +26684,22 @@ package android.net.wifi {
field public static final int WPS_WEP_PROHIBITED = 4; // 0x4
}
public static class WifiManager.LocalOnlyHotspotCallback {
ctor public WifiManager.LocalOnlyHotspotCallback();
method public void onFailed(int);
method public void onStarted(android.net.wifi.WifiManager.LocalOnlyHotspotReservation);
method public void onStopped();
field public static final int ERROR_GENERIC = 2; // 0x2
field public static final int ERROR_INCOMPATIBLE_MODE = 3; // 0x3
field public static final int ERROR_NO_CHANNEL = 1; // 0x1
field public static final int ERROR_TETHERING_DISALLOWED = 4; // 0x4
}
public class WifiManager.LocalOnlyHotspotReservation implements java.lang.AutoCloseable {
method public void close();
method public android.net.wifi.WifiConfiguration getWifiConfiguration();
}
public class WifiManager.MulticastLock {
method public void acquire();
method public boolean isHeld();

View 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();

View 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
@@ -1882,8 +1882,6 @@ public class WifiManager {
* operating status.
* @param handler Handler to be used for callbacks. If the caller passes a null Handler, the
* main thread will be used.
*
* @hide
*/
public void startLocalOnlyHotspot(LocalOnlyHotspotCallback callback,
@Nullable Handler handler) {
@@ -1892,12 +1890,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;
@@ -2274,8 +2270,6 @@ public class WifiManager {
* any further callbacks. If the LocalOnlyHotspot is stopped due to a
* user triggered mode change, applications will be notified via the {@link
* LocalOnlyHotspotCallback#onStopped()} callback.
*
* @hide
*/
public class LocalOnlyHotspotReservation implements AutoCloseable {
@@ -2289,7 +2283,7 @@ public class WifiManager {
mCloseGuard.open("close");
}
public WifiConfiguration getConfig() {
public WifiConfiguration getWifiConfiguration() {
return mConfig;
}
@@ -2318,13 +2312,15 @@ public class WifiManager {
/**
* Callback class for applications to receive updates about the LocalOnlyHotspot status.
*
* @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 +2341,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) { };

View 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);