summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNate(Qiang) Jiang <qiangjiang@google.com>2019-11-20 10:33:26 -0800
committerNate(Qiang) Jiang <qiangjiang@google.com>2019-11-22 10:48:13 -0800
commit60d3492416526fae3e4582321faecd918ebe678f (patch)
tree1a3bcbadf4f74d9a4b571883c05da4eade20029b /tests
parentac05d66117dfbc724019ff3494b0744aec22dfdd (diff)
User binder as callback identifier
User binder as identifier and integrated with remoteCallbackList Bug: 143138047 Test: atest android.net.wifi Test: atest com.android.server.wifi Change-Id: Ia763c9b22337263956a58c923069e5307970371c
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java68
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java43
2 files changed, 43 insertions, 68 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
index 33de69106..0e5cbd592 100644
--- a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
@@ -29,11 +29,10 @@ import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
-import android.net.wifi.IScanResultsListener;
+import android.net.wifi.IScanResultsCallback;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiScanner;
-import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.UserHandle;
@@ -87,8 +86,8 @@ public class ScanRequestProxyTest extends WifiBaseTest {
@Mock private Clock mClock;
@Mock private FrameworkFacade mFrameworkFacade;
@Mock private WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager;
- @Mock private IScanResultsListener mScanResultsListener;
- @Mock private IScanResultsListener mAnotherScanResultsListener;
+ @Mock private IScanResultsCallback mScanResultsCallback;
+ @Mock private IScanResultsCallback mAnotherScanResultsCallback;
@Mock private TestLooper mLooper;
@Mock private IBinder mBinder;
@Mock private IBinder mAnotherBinder;
@@ -146,6 +145,8 @@ public class ScanRequestProxyTest extends WifiBaseTest {
new ScanRequestProxy(mContext, mAppOps, mActivityManager, mWifiInjector,
mWifiConfigManager, mWifiPermissionsUtil, mWifiMetrics, mClock,
mFrameworkFacade, new Handler(mLooper.getLooper()));
+ when(mScanResultsCallback.asBinder()).thenReturn(mBinder);
+ when(mAnotherScanResultsCallback.asBinder()).thenReturn(mAnotherBinder);
}
@After
@@ -957,85 +958,68 @@ public class ScanRequestProxyTest extends WifiBaseTest {
}
/**
- * Test register two different scan result listener, all of them will receive the event.
+ * Test register two different scan result Callback, all of them will receive the event.
*/
@Test
- public void testScanSuccessWithMultipleListener() throws Exception {
- Binder binder1 = new Binder();
- Binder binder2 = new Binder();
- mScanRequestProxy.registerScanResultsListener(binder1, mScanResultsListener,
- mScanResultsListener.hashCode());
- mScanRequestProxy.registerScanResultsListener(binder2, mAnotherScanResultsListener,
- mAnotherScanResultsListener.hashCode());
- mLooper.dispatchAll();
+ public void testScanSuccessWithMultipleCallback() throws Exception {
+ mScanRequestProxy.registerScanResultsCallback(mScanResultsCallback);
+ mScanRequestProxy.registerScanResultsCallback(mAnotherScanResultsCallback);
testStartScanSuccess();
// Verify the scan results processing.
mGlobalScanListenerArgumentCaptor.getValue().onResults(mTestScanDatas1);
mLooper.dispatchAll();
- verify(mScanResultsListener).onScanResultsAvailable();
- verify(mAnotherScanResultsListener).onScanResultsAvailable();
validateScanResultsAvailableBroadcastSent(true);
- reset(mScanResultsListener);
- reset(mAnotherScanResultsListener);
- mScanRequestProxy.unregisterScanResultsListener(mScanResultsListener.hashCode());
- mLooper.dispatchAll();
- mGlobalScanListenerArgumentCaptor.getValue().onResults(mTestScanDatas1);
+ mScanRequestProxy.unregisterScanResultsCallback(mScanResultsCallback);
+ mGlobalScanListenerArgumentCaptor.getValue().onResults(mTestScanDatas2);
mLooper.dispatchAll();
- verify(mScanResultsListener, never()).onScanResultsAvailable();
- verify(mAnotherScanResultsListener).onScanResultsAvailable();
validateScanResultsAvailableBroadcastSent(true);
+ verify(mScanResultsCallback).onScanResultsAvailable();
+ verify(mAnotherScanResultsCallback, times(2)).onScanResultsAvailable();
}
/**
- * Verify that registering twice with same listenerIdentifier will replace the first listener.
+ * Verify that registering twice with same Callback will replace the first Callback.
*/
@Test
- public void testReplacesOldListenerWithNewListenerWhenRegisteringTwice() throws Exception {
- mScanRequestProxy.registerScanResultsListener(mBinder, mScanResultsListener,
- mScanResultsListener.hashCode());
- mScanRequestProxy.registerScanResultsListener(mAnotherBinder, mAnotherScanResultsListener,
- mScanResultsListener.hashCode());
+ public void testReplacesOldListenerWithNewCallbackWhenRegisteringTwice() throws Exception {
+ mScanRequestProxy.registerScanResultsCallback(mScanResultsCallback);
+ mScanRequestProxy.registerScanResultsCallback(mScanResultsCallback);
mLooper.dispatchAll();
// Verify old listener is replaced.
- verify(mBinder).linkToDeath(any(), anyInt());
+ verify(mBinder, times(2)).linkToDeath(any(), anyInt());
verify(mBinder).unlinkToDeath(any(), anyInt());
- verify(mAnotherBinder).linkToDeath(any(), anyInt());
- verify(mAnotherBinder, never()).unlinkToDeath(any(), anyInt());
testStartScanSuccess();
// Verify the scan results processing.
mGlobalScanListenerArgumentCaptor.getValue().onResults(mTestScanDatas1);
mLooper.dispatchAll();
- verify(mScanResultsListener, never()).onScanResultsAvailable();
- verify(mAnotherScanResultsListener).onScanResultsAvailable();
+ verify(mScanResultsCallback).onScanResultsAvailable();
validateScanResultsAvailableBroadcastSent(true);
}
/**
- * Test registered scan result listener will be unregistered when calling binder is died.
+ * Test registered scan result Callback will be unregistered when calling binder is died.
*/
@Test
- public void testUnregisterScanResultListenerOnBinderDied() throws Exception {
- final int callbackIdentifier = 1;
+ public void testUnregisterScanResultCallbackOnBinderDied() throws Exception {
ArgumentCaptor<IBinder.DeathRecipient> drCaptor =
ArgumentCaptor.forClass(IBinder.DeathRecipient.class);
- mScanRequestProxy.registerScanResultsListener(mBinder, mScanResultsListener,
- callbackIdentifier);
+ mScanRequestProxy.registerScanResultsCallback(mScanResultsCallback);
verify(mBinder).linkToDeath(drCaptor.capture(), anyInt());
testStartScanSuccess();
// Verify the scan results processing.
mGlobalScanListenerArgumentCaptor.getValue().onResults(mTestScanDatas1);
mLooper.dispatchAll();
- verify(mScanResultsListener).onScanResultsAvailable();
validateScanResultsAvailableBroadcastSent(true);
- reset(mScanResultsListener);
+ verify(mScanResultsCallback).onScanResultsAvailable();
drCaptor.getValue().binderDied();
mLooper.dispatchAll();
- verify(mBinder).unlinkToDeath(drCaptor.capture(), eq(0));
+ reset(mScanResultsCallback);
// Verify the scan results processing.
mGlobalScanListenerArgumentCaptor.getValue().onResults(mTestScanDatas1);
mLooper.dispatchAll();
- verify(mScanResultsListener, never()).onScanResultsAvailable();
validateScanResultsAvailableBroadcastSent(true);
+ verify(mScanResultsCallback, never()).onScanResultsAvailable();
+
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 782a8db57..c29bb15e3 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -95,7 +95,7 @@ import android.net.wifi.IDppCallback;
import android.net.wifi.ILocalOnlyHotspotCallback;
import android.net.wifi.INetworkRequestMatchCallback;
import android.net.wifi.IOnWifiUsabilityStatsListener;
-import android.net.wifi.IScanResultsListener;
+import android.net.wifi.IScanResultsCallback;
import android.net.wifi.ISoftApCallback;
import android.net.wifi.ISuggestionConnectionStatusListener;
import android.net.wifi.ITrafficStateCallback;
@@ -278,7 +278,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
@Mock IDppCallback mDppCallback;
@Mock SarManager mSarManager;
@Mock ILocalOnlyHotspotCallback mLohsCallback;
- @Mock IScanResultsListener mClientScanResultsListener;
+ @Mock IScanResultsCallback mScanResultsCallback;
@Mock ISuggestionConnectionStatusListener mSuggestionConnectionStatusListener;
WifiLog mLog = new LogcatLog(TAG);
@@ -4371,53 +4371,44 @@ public class WifiServiceImplTest extends WifiBaseTest {
}
/**
- * Test register scan result listener without permission.
+ * Test register scan result callback without permission.
*/
@Test(expected = SecurityException.class)
- public void testRegisterScanResultListenerWithMissingPermission() throws Exception {
+ public void testRegisterScanResultCallbackWithMissingPermission() throws Exception {
doThrow(new SecurityException()).when(mContext).enforceCallingOrSelfPermission(
eq(android.Manifest.permission.ACCESS_WIFI_STATE), eq("WifiService"));
- final int listenerIdentifier = 1;
- mWifiServiceImpl.registerScanResultsListener(mAppBinder,
- mClientScanResultsListener,
- listenerIdentifier);
+ mWifiServiceImpl.registerScanResultsCallback(mScanResultsCallback);
}
/**
- * Test unregister scan result listener without permission.
+ * Test unregister scan result callback without permission.
*/
@Test(expected = SecurityException.class)
- public void testUnregisterScanResultListenerWithMissingPermission() throws Exception {
+ public void testUnregisterScanResultCallbackWithMissingPermission() throws Exception {
doThrow(new SecurityException()).when(mContext).enforceCallingOrSelfPermission(
eq(android.Manifest.permission.ACCESS_WIFI_STATE), eq("WifiService"));
- final int listenerIdentifier = 1;
- mWifiServiceImpl.unregisterScanResultsListener(listenerIdentifier);
+ mWifiServiceImpl.unregisterScanResultsCallback(mScanResultsCallback);
}
/**
- * Test register scan result listener with illegal argument.
+ * Test register scan result callback with illegal argument.
*/
@Test(expected = IllegalArgumentException.class)
- public void testRegisterScanResultListenerWithIllegalArgument() throws Exception {
- final int listenerIdentifier = 1;
- mWifiServiceImpl.registerScanResultsListener(mAppBinder, null, listenerIdentifier);
+ public void testRegisterScanResultCallbackWithIllegalArgument() throws Exception {
+ mWifiServiceImpl.registerScanResultsCallback(null);
}
/**
- * Test register and unregister listener will go to ScanRequestProxy;
+ * Test register and unregister callback will go to ScanRequestProxy;
*/
@Test
- public void testRegisterUnregisterScanResultListener() throws Exception {
- final int listenerIdentifier = 1;
- mWifiServiceImpl.registerScanResultsListener(mAppBinder,
- mClientScanResultsListener,
- listenerIdentifier);
+ public void testRegisterUnregisterScanResultCallback() throws Exception {
+ mWifiServiceImpl.registerScanResultsCallback(mScanResultsCallback);
mLooper.dispatchAll();
- verify(mScanRequestProxy).registerScanResultsListener(eq(mAppBinder),
- eq(mClientScanResultsListener), eq(listenerIdentifier));
- mWifiServiceImpl.unregisterScanResultsListener(listenerIdentifier);
+ verify(mScanRequestProxy).registerScanResultsCallback(mScanResultsCallback);
+ mWifiServiceImpl.unregisterScanResultsCallback(mScanResultsCallback);
mLooper.dispatchAll();
- verify(mScanRequestProxy).unregisterScanResultsListener(eq(listenerIdentifier));
+ verify(mScanRequestProxy).unregisterScanResultsCallback(mScanResultsCallback);
}
/**