Merge "Marking SoftApCallback methods as SystemAPI"

This commit is contained in:
James Mattis
2019-11-15 23:17:54 +00:00
committed by Gerrit Code Review
5 changed files with 36 additions and 22 deletions

View File

@@ -4704,6 +4704,7 @@ package android.net.wifi {
method public boolean isPortableHotspotSupported(); method public boolean isPortableHotspotSupported();
method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public boolean isWifiApEnabled(); method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public boolean isWifiApEnabled();
method public boolean isWifiScannerSupported(); method public boolean isWifiScannerSupported();
method @RequiresPermission("android.permission.NETWORK_SETTINGS") public void registerSoftApCallback(@NonNull android.net.wifi.WifiManager.SoftApCallback, @Nullable java.util.concurrent.Executor);
method @RequiresPermission("android.permission.WIFI_UPDATE_USABILITY_STATS_SCORE") public void removeOnWifiUsabilityStatsListener(@NonNull android.net.wifi.WifiManager.OnWifiUsabilityStatsListener); method @RequiresPermission("android.permission.WIFI_UPDATE_USABILITY_STATS_SCORE") public void removeOnWifiUsabilityStatsListener(@NonNull android.net.wifi.WifiManager.OnWifiUsabilityStatsListener);
method @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", android.Manifest.permission.NETWORK_SETUP_WIZARD, "android.permission.NETWORK_STACK"}) public void save(@NonNull android.net.wifi.WifiConfiguration, @Nullable android.net.wifi.WifiManager.ActionListener); method @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", android.Manifest.permission.NETWORK_SETUP_WIZARD, "android.permission.NETWORK_STACK"}) public void save(@NonNull android.net.wifi.WifiConfiguration, @Nullable android.net.wifi.WifiManager.ActionListener);
method @RequiresPermission("android.permission.WIFI_SET_DEVICE_MOBILITY_STATE") public void setDeviceMobilityState(int); method @RequiresPermission("android.permission.WIFI_SET_DEVICE_MOBILITY_STATE") public void setDeviceMobilityState(int);
@@ -4762,6 +4763,11 @@ package android.net.wifi {
method public void onWifiUsabilityStats(int, boolean, @NonNull android.net.wifi.WifiUsabilityStatsEntry); method public void onWifiUsabilityStats(int, boolean, @NonNull android.net.wifi.WifiUsabilityStatsEntry);
} }
public static interface WifiManager.SoftApCallback {
method public void onConnectedClientsChanged(@NonNull java.util.List<android.net.wifi.WifiClient>);
method public void onStateChanged(int, int);
}
public class WifiNetworkConnectionStatistics implements android.os.Parcelable { public class WifiNetworkConnectionStatistics implements android.os.Parcelable {
ctor public WifiNetworkConnectionStatistics(int, int); ctor public WifiNetworkConnectionStatistics(int, int);
ctor public WifiNetworkConnectionStatistics(); ctor public WifiNetworkConnectionStatistics();

View File

@@ -24,6 +24,7 @@ import android.net.ConnectivityManager;
import android.net.wifi.WifiClient; import android.net.wifi.WifiClient;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.UserManager; import android.os.UserManager;
import android.util.Log; import android.util.Log;
@@ -109,7 +110,8 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
mCallbacks.add(callback); mCallbacks.add(callback);
if (mWifiManager != null) { if (mWifiManager != null) {
if (mCallbacks.size() == 1) { if (mCallbacks.size() == 1) {
mWifiManager.registerSoftApCallback(this, mMainHandler); mWifiManager.registerSoftApCallback(this,
new HandlerExecutor(mMainHandler));
} else { } else {
// mWifiManager#registerSoftApCallback triggers a call to // mWifiManager#registerSoftApCallback triggers a call to
// onConnectedClientsChanged on the Main Handler. In order to always update // onConnectedClientsChanged on the Main Handler. In order to always update

View File

@@ -43,6 +43,7 @@ import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.Executor;
@SmallTest @SmallTest
@RunWith(AndroidTestingRunner.class) @RunWith(AndroidTestingRunner.class)
@@ -73,7 +74,7 @@ public class HotspotControllerImplTest extends SysuiTestCase {
.onConnectedClientsChanged(new ArrayList<>()); .onConnectedClientsChanged(new ArrayList<>());
return null; return null;
}).when(mWifiManager).registerSoftApCallback(any(WifiManager.SoftApCallback.class), }).when(mWifiManager).registerSoftApCallback(any(WifiManager.SoftApCallback.class),
any(Handler.class)); any(Executor.class));
mController = new HotspotControllerImpl(mContext, new Handler(mLooper.getLooper())); mController = new HotspotControllerImpl(mContext, new Handler(mLooper.getLooper()));
} }

View File

@@ -3121,6 +3121,7 @@ public class WifiManager {
* *
* @hide * @hide
*/ */
@SystemApi
public interface SoftApCallback { public interface SoftApCallback {
/** /**
* Called when soft AP state changes. * Called when soft AP state changes.
@@ -3149,11 +3150,11 @@ public class WifiManager {
* @hide * @hide
*/ */
private class SoftApCallbackProxy extends ISoftApCallback.Stub { private class SoftApCallbackProxy extends ISoftApCallback.Stub {
private final Handler mHandler; private final Executor mExecutor;
private final SoftApCallback mCallback; private final SoftApCallback mCallback;
SoftApCallbackProxy(Looper looper, SoftApCallback callback) { SoftApCallbackProxy(Executor executor, SoftApCallback callback) {
mHandler = new Handler(looper); mExecutor = executor;
mCallback = callback; mCallback = callback;
} }
@@ -3164,7 +3165,8 @@ public class WifiManager {
+ ", failureReason=" + failureReason); + ", failureReason=" + failureReason);
} }
mHandler.post(() -> { Binder.clearCallingIdentity();
mExecutor.execute(() -> {
mCallback.onStateChanged(state, failureReason); mCallback.onStateChanged(state, failureReason);
}); });
} }
@@ -3176,7 +3178,8 @@ public class WifiManager {
+ clients.size() + " clients"); + clients.size() + " clients");
} }
mHandler.post(() -> { Binder.clearCallingIdentity();
mExecutor.execute(() -> {
mCallback.onConnectedClientsChanged(clients); mCallback.onConnectedClientsChanged(clients);
}); });
} }
@@ -3195,21 +3198,22 @@ public class WifiManager {
* <p> * <p>
* *
* @param callback Callback for soft AP events * @param callback Callback for soft AP events
* @param handler The Handler on whose thread to execute the callbacks of the {@code callback} * @param executor The executor to execute the callbacks of the {@code executor}
* object. If null, then the application's main thread will be used. * object. If null, then the application's main executor will be used.
* *
* @hide * @hide
*/ */
@SystemApi
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
public void registerSoftApCallback(@NonNull SoftApCallback callback, public void registerSoftApCallback(@NonNull SoftApCallback callback,
@Nullable Handler handler) { @Nullable @CallbackExecutor Executor executor) {
if (callback == null) throw new IllegalArgumentException("callback cannot be null"); if (callback == null) throw new IllegalArgumentException("callback cannot be null");
Log.v(TAG, "registerSoftApCallback: callback=" + callback + ", handler=" + handler); Log.v(TAG, "registerSoftApCallback: callback=" + callback + ", executor=" + executor);
Looper looper = (handler == null) ? mContext.getMainLooper() : handler.getLooper(); executor = (executor == null) ? mContext.getMainExecutor() : executor;
Binder binder = new Binder(); Binder binder = new Binder();
try { try {
mService.registerSoftApCallback(binder, new SoftApCallbackProxy(looper, callback), mService.registerSoftApCallback(binder, new SoftApCallbackProxy(executor, callback),
callback.hashCode()); callback.hashCode());
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();

View File

@@ -66,6 +66,7 @@ import android.net.wifi.WifiManager.SoftApCallback;
import android.net.wifi.WifiManager.TrafficStateCallback; import android.net.wifi.WifiManager.TrafficStateCallback;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
@@ -685,7 +686,7 @@ public class WifiManagerTest {
@Test @Test
public void registerSoftApCallbackThrowsIllegalArgumentExceptionOnNullArgumentForCallback() { public void registerSoftApCallbackThrowsIllegalArgumentExceptionOnNullArgumentForCallback() {
try { try {
mWifiManager.registerSoftApCallback(null, mHandler); mWifiManager.registerSoftApCallback(null, new HandlerExecutor(mHandler));
fail("expected IllegalArgumentException"); fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
} }
@@ -710,7 +711,7 @@ public class WifiManagerTest {
public void registerSoftApCallbackUsesMainLooperOnNullArgumentForHandler() { public void registerSoftApCallbackUsesMainLooperOnNullArgumentForHandler() {
when(mContext.getMainLooper()).thenReturn(mLooper.getLooper()); when(mContext.getMainLooper()).thenReturn(mLooper.getLooper());
mWifiManager.registerSoftApCallback(mSoftApCallback, null); mWifiManager.registerSoftApCallback(mSoftApCallback, null);
verify(mContext).getMainLooper(); verify(mContext).getMainExecutor();
} }
/** /**
@@ -718,7 +719,7 @@ public class WifiManagerTest {
*/ */
@Test @Test
public void registerSoftApCallbackCallGoesToWifiServiceImpl() throws Exception { public void registerSoftApCallbackCallGoesToWifiServiceImpl() throws Exception {
mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler));
verify(mWifiService).registerSoftApCallback(any(IBinder.class), verify(mWifiService).registerSoftApCallback(any(IBinder.class),
any(ISoftApCallback.Stub.class), anyInt()); any(ISoftApCallback.Stub.class), anyInt());
} }
@@ -729,7 +730,7 @@ public class WifiManagerTest {
@Test @Test
public void unregisterSoftApCallbackCallGoesToWifiServiceImpl() throws Exception { public void unregisterSoftApCallbackCallGoesToWifiServiceImpl() throws Exception {
ArgumentCaptor<Integer> callbackIdentifier = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<Integer> callbackIdentifier = ArgumentCaptor.forClass(Integer.class);
mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler));
verify(mWifiService).registerSoftApCallback(any(IBinder.class), verify(mWifiService).registerSoftApCallback(any(IBinder.class),
any(ISoftApCallback.Stub.class), callbackIdentifier.capture()); any(ISoftApCallback.Stub.class), callbackIdentifier.capture());
@@ -744,7 +745,7 @@ public class WifiManagerTest {
public void softApCallbackProxyCallsOnStateChanged() throws Exception { public void softApCallbackProxyCallsOnStateChanged() throws Exception {
ArgumentCaptor<ISoftApCallback.Stub> callbackCaptor = ArgumentCaptor<ISoftApCallback.Stub> callbackCaptor =
ArgumentCaptor.forClass(ISoftApCallback.Stub.class); ArgumentCaptor.forClass(ISoftApCallback.Stub.class);
mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler));
verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(), verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(),
anyInt()); anyInt());
@@ -760,7 +761,7 @@ public class WifiManagerTest {
public void softApCallbackProxyCallsOnConnectedClientsChanged() throws Exception { public void softApCallbackProxyCallsOnConnectedClientsChanged() throws Exception {
ArgumentCaptor<ISoftApCallback.Stub> callbackCaptor = ArgumentCaptor<ISoftApCallback.Stub> callbackCaptor =
ArgumentCaptor.forClass(ISoftApCallback.Stub.class); ArgumentCaptor.forClass(ISoftApCallback.Stub.class);
mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler));
verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(), verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(),
anyInt()); anyInt());
@@ -777,7 +778,7 @@ public class WifiManagerTest {
public void softApCallbackProxyCallsOnMultipleUpdates() throws Exception { public void softApCallbackProxyCallsOnMultipleUpdates() throws Exception {
ArgumentCaptor<ISoftApCallback.Stub> callbackCaptor = ArgumentCaptor<ISoftApCallback.Stub> callbackCaptor =
ArgumentCaptor.forClass(ISoftApCallback.Stub.class); ArgumentCaptor.forClass(ISoftApCallback.Stub.class);
mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler));
verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(), verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(),
anyInt()); anyInt());
@@ -801,7 +802,7 @@ public class WifiManagerTest {
ArgumentCaptor.forClass(ISoftApCallback.Stub.class); ArgumentCaptor.forClass(ISoftApCallback.Stub.class);
TestLooper altLooper = new TestLooper(); TestLooper altLooper = new TestLooper();
Handler altHandler = new Handler(altLooper.getLooper()); Handler altHandler = new Handler(altLooper.getLooper());
mWifiManager.registerSoftApCallback(mSoftApCallback, altHandler); mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(altHandler));
verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(), verify(mWifiService).registerSoftApCallback(any(IBinder.class), callbackCaptor.capture(),
anyInt()); anyInt());
@@ -815,7 +816,7 @@ public class WifiManagerTest {
*/ */
@Test @Test
public void testCorrectLooperIsUsedForSoftApCallbackHandler() throws Exception { public void testCorrectLooperIsUsedForSoftApCallbackHandler() throws Exception {
mWifiManager.registerSoftApCallback(mSoftApCallback, mHandler); mWifiManager.registerSoftApCallback(mSoftApCallback, new HandlerExecutor(mHandler));
mLooper.dispatchAll(); mLooper.dispatchAll();
verify(mWifiService).registerSoftApCallback(any(IBinder.class), verify(mWifiService).registerSoftApCallback(any(IBinder.class),
any(ISoftApCallback.Stub.class), anyInt()); any(ISoftApCallback.Stub.class), anyInt());