Fix WifiManager.startTetheredHotspot mocking am: db7fdac6d9
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/3545540 Change-Id: I9b9e9909924f160b5cfea5c532137692a38ac9a6 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
507df2bbee
1 changed files with 32 additions and 19 deletions
|
|
@ -724,6 +724,7 @@ public class TetheringTest {
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI)).thenReturn(true);
|
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI)).thenReturn(true);
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)).thenReturn(true);
|
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)).thenReturn(true);
|
||||||
mIpServerDependencies = spy(new MockIpServerDependencies());
|
mIpServerDependencies = spy(new MockIpServerDependencies());
|
||||||
|
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
||||||
mTetheringWithSoftApConfigEnabled = SdkLevel.isAtLeastB();
|
mTetheringWithSoftApConfigEnabled = SdkLevel.isAtLeastB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1961,7 +1962,6 @@ public class TetheringTest {
|
||||||
@Test
|
@Test
|
||||||
public void failingWifiTetheringLegacyApBroadcast() throws Exception {
|
public void failingWifiTetheringLegacyApBroadcast() throws Exception {
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
when(mWifiManager.startTetheredHotspot(any(SoftApConfiguration.class))).thenReturn(true);
|
|
||||||
|
|
||||||
// Emulate pressing the WiFi tethering button.
|
// Emulate pressing the WiFi tethering button.
|
||||||
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI), TEST_CALLER_PKG,
|
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI), TEST_CALLER_PKG,
|
||||||
|
|
@ -1998,7 +1998,6 @@ public class TetheringTest {
|
||||||
@Test
|
@Test
|
||||||
public void workingWifiTetheringEnrichedApBroadcast() throws Exception {
|
public void workingWifiTetheringEnrichedApBroadcast() throws Exception {
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
when(mWifiManager.startTetheredHotspot(any(SoftApConfiguration.class))).thenReturn(true);
|
|
||||||
|
|
||||||
// Emulate pressing the WiFi tethering button.
|
// Emulate pressing the WiFi tethering button.
|
||||||
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI), TEST_CALLER_PKG,
|
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI), TEST_CALLER_PKG,
|
||||||
|
|
@ -2047,7 +2046,6 @@ public class TetheringTest {
|
||||||
@Test
|
@Test
|
||||||
public void failureEnablingIpForwarding() throws Exception {
|
public void failureEnablingIpForwarding() throws Exception {
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
doThrow(new RemoteException()).when(mNetd).ipfwdEnableForwarding(TETHERING_NAME);
|
doThrow(new RemoteException()).when(mNetd).ipfwdEnableForwarding(TETHERING_NAME);
|
||||||
|
|
||||||
// Emulate pressing the WiFi tethering button.
|
// Emulate pressing the WiFi tethering button.
|
||||||
|
|
@ -2391,7 +2389,6 @@ public class TetheringTest {
|
||||||
// 2. Enable wifi tethering.
|
// 2. Enable wifi tethering.
|
||||||
UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
|
UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
|
||||||
initTetheringUpstream(upstreamState);
|
initTetheringUpstream(upstreamState);
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
|
|
||||||
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI), TEST_CALLER_PKG,
|
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI), TEST_CALLER_PKG,
|
||||||
null);
|
null);
|
||||||
|
|
@ -2494,7 +2491,6 @@ public class TetheringTest {
|
||||||
callback.expectOffloadStatusChanged(TETHER_HARDWARE_OFFLOAD_STOPPED);
|
callback.expectOffloadStatusChanged(TETHER_HARDWARE_OFFLOAD_STOPPED);
|
||||||
UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
|
UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
|
||||||
initTetheringUpstream(upstreamState);
|
initTetheringUpstream(upstreamState);
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
|
|
||||||
// Enable wifi tethering
|
// Enable wifi tethering
|
||||||
mBinderCallingUid = TEST_CALLER_UID;
|
mBinderCallingUid = TEST_CALLER_UID;
|
||||||
|
|
@ -2568,7 +2564,6 @@ public class TetheringTest {
|
||||||
.setSoftApConfiguration(softApConfig).build();
|
.setSoftApConfiguration(softApConfig).build();
|
||||||
tetheringRequest.setUid(TEST_CALLER_UID);
|
tetheringRequest.setUid(TEST_CALLER_UID);
|
||||||
ResultListener successListener = new ResultListener(TETHER_ERROR_NO_ERROR);
|
ResultListener successListener = new ResultListener(TETHER_ERROR_NO_ERROR);
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
mTethering.startTethering(tetheringRequest, TEST_CALLER_PKG, successListener);
|
mTethering.startTethering(tetheringRequest, TEST_CALLER_PKG, successListener);
|
||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
successListener.assertHasResult();
|
successListener.assertHasResult();
|
||||||
|
|
@ -2625,7 +2620,6 @@ public class TetheringTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFuzzyMatchedWifiCanBeAddedAfterIpServerStopped() throws Exception {
|
public void testFuzzyMatchedWifiCanBeAddedAfterIpServerStopped() throws Exception {
|
||||||
assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
|
assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
|
|
||||||
// Start wifi tethering and mock the ap state change.
|
// Start wifi tethering and mock the ap state change.
|
||||||
|
|
@ -2658,7 +2652,6 @@ public class TetheringTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFuzzyMatchedWifiCanBeAddedAfterIpServerUnwanted() throws Exception {
|
public void testFuzzyMatchedWifiCanBeAddedAfterIpServerUnwanted() throws Exception {
|
||||||
assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
|
assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
|
|
||||||
// Start wifi tethering and mock the ap state change.
|
// Start wifi tethering and mock the ap state change.
|
||||||
|
|
@ -2691,7 +2684,6 @@ public class TetheringTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFuzzyMatchedWifiCanBeAddedAfterIpServerError() throws Exception {
|
public void testFuzzyMatchedWifiCanBeAddedAfterIpServerError() throws Exception {
|
||||||
assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
|
assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
|
|
||||||
// Set up the DHCP server to fail creation.
|
// Set up the DHCP server to fail creation.
|
||||||
|
|
@ -2719,7 +2711,6 @@ public class TetheringTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFuzzyMatchedWifiCanBeAddedAfterStoppingPendingRequest() throws Exception {
|
public void testFuzzyMatchedWifiCanBeAddedAfterStoppingPendingRequest() throws Exception {
|
||||||
assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
|
assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
|
|
||||||
// Start wifi tethering but keep the request pending by not sending the ap state change.
|
// Start wifi tethering but keep the request pending by not sending the ap state change.
|
||||||
|
|
@ -2751,7 +2742,6 @@ public class TetheringTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFuzzyMatchedWifiCanBeAddedAfterStoppingServingRequest() throws Exception {
|
public void testFuzzyMatchedWifiCanBeAddedAfterStoppingServingRequest() throws Exception {
|
||||||
assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
|
assumeTrue(mTetheringDependencies.isTetheringWithSoftApConfigEnabled());
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
|
|
||||||
// Start wifi tethering and mock the ap state change.
|
// Start wifi tethering and mock the ap state change.
|
||||||
|
|
@ -2788,7 +2778,6 @@ public class TetheringTest {
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
|
UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
|
||||||
initTetheringUpstream(upstreamState);
|
initTetheringUpstream(upstreamState);
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
|
|
||||||
// Enable wifi tethering.
|
// Enable wifi tethering.
|
||||||
SoftApConfiguration softApConfig = new SoftApConfiguration.Builder()
|
SoftApConfiguration softApConfig = new SoftApConfiguration.Builder()
|
||||||
|
|
@ -2835,7 +2824,6 @@ public class TetheringTest {
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
|
UpstreamNetworkState upstreamState = buildMobileDualStackUpstreamState();
|
||||||
initTetheringUpstream(upstreamState);
|
initTetheringUpstream(upstreamState);
|
||||||
when(mWifiManager.startTetheredHotspot(null)).thenReturn(true);
|
|
||||||
|
|
||||||
// Enable wifi tethering.
|
// Enable wifi tethering.
|
||||||
SoftApConfiguration softApConfig = new SoftApConfiguration.Builder()
|
SoftApConfiguration softApConfig = new SoftApConfiguration.Builder()
|
||||||
|
|
@ -3224,7 +3212,6 @@ public class TetheringTest {
|
||||||
final int clientAddrParceled = 0xc0a8002a;
|
final int clientAddrParceled = 0xc0a8002a;
|
||||||
final ArgumentCaptor<DhcpServingParamsParcel> dhcpParamsCaptor =
|
final ArgumentCaptor<DhcpServingParamsParcel> dhcpParamsCaptor =
|
||||||
ArgumentCaptor.forClass(DhcpServingParamsParcel.class);
|
ArgumentCaptor.forClass(DhcpServingParamsParcel.class);
|
||||||
when(mWifiManager.startTetheredHotspot(any())).thenReturn(true);
|
|
||||||
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI,
|
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI,
|
||||||
serverLinkAddr, clientLinkAddr, false, CONNECTIVITY_SCOPE_GLOBAL, null),
|
serverLinkAddr, clientLinkAddr, false, CONNECTIVITY_SCOPE_GLOBAL, null),
|
||||||
TEST_CALLER_PKG, null);
|
TEST_CALLER_PKG, null);
|
||||||
|
|
@ -3388,26 +3375,38 @@ public class TetheringTest {
|
||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
verify(mEntitleMgr).stopProvisioningIfNeeded(TETHERING_WIFI);
|
verify(mEntitleMgr).stopProvisioningIfNeeded(TETHERING_WIFI);
|
||||||
reset(mEntitleMgr);
|
reset(mEntitleMgr);
|
||||||
|
}
|
||||||
|
|
||||||
// If one app enables tethering without provisioning check first, then another app enables
|
@Test
|
||||||
// tethering of the same type but does not disable the provisioning check.
|
public void testNonExemptRequestAddedAfterExemptRequestOfSameType() throws Exception {
|
||||||
|
// Note: When fuzzy-matching is enabled, it is not possible yet to have two concurrent
|
||||||
|
// requests of the same type that are subject to carrier entitlement due to fuzzy-matching.
|
||||||
|
mTetheringWithSoftApConfigEnabled = false;
|
||||||
|
initTetheringOnTestThread();
|
||||||
setupForRequiredProvisioning();
|
setupForRequiredProvisioning();
|
||||||
|
final TetheringRequest wifiExemptRequest =
|
||||||
|
createTetheringRequest(TETHERING_WIFI, null, null, true,
|
||||||
|
CONNECTIVITY_SCOPE_GLOBAL, null);
|
||||||
mTethering.startTethering(wifiExemptRequest, TEST_CALLER_PKG, null);
|
mTethering.startTethering(wifiExemptRequest, TEST_CALLER_PKG, null);
|
||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
verify(mEntitleMgr, never()).startProvisioningIfNeeded(TETHERING_WIFI, false);
|
verify(mEntitleMgr, never()).startProvisioningIfNeeded(TETHERING_WIFI, false);
|
||||||
verify(mEntitleMgr).setExemptedDownstreamType(TETHERING_WIFI);
|
verify(mEntitleMgr).setExemptedDownstreamType(TETHERING_WIFI);
|
||||||
assertTrue(mEntitleMgr.isCellularUpstreamPermitted());
|
assertTrue(mEntitleMgr.isCellularUpstreamPermitted());
|
||||||
reset(mEntitleMgr);
|
reset(mEntitleMgr);
|
||||||
|
|
||||||
setupForRequiredProvisioning();
|
setupForRequiredProvisioning();
|
||||||
|
final TetheringRequest wifiNotExemptRequest =
|
||||||
|
createTetheringRequest(TETHERING_WIFI, null, null, false,
|
||||||
|
CONNECTIVITY_SCOPE_GLOBAL, null);
|
||||||
mTethering.startTethering(wifiNotExemptRequest, TEST_CALLER_PKG, null);
|
mTethering.startTethering(wifiNotExemptRequest, TEST_CALLER_PKG, null);
|
||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
|
verify(mEntitleMgr).stopProvisioningIfNeeded(TETHERING_WIFI);
|
||||||
verify(mEntitleMgr).startProvisioningIfNeeded(TETHERING_WIFI, false);
|
verify(mEntitleMgr).startProvisioningIfNeeded(TETHERING_WIFI, false);
|
||||||
verify(mEntitleMgr, never()).setExemptedDownstreamType(TETHERING_WIFI);
|
verify(mEntitleMgr, never()).setExemptedDownstreamType(TETHERING_WIFI);
|
||||||
assertFalse(mEntitleMgr.isCellularUpstreamPermitted());
|
assertFalse(mEntitleMgr.isCellularUpstreamPermitted());
|
||||||
mTethering.stopTethering(TETHERING_WIFI);
|
mTethering.stopTethering(TETHERING_WIFI);
|
||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
verify(mEntitleMgr).stopProvisioningIfNeeded(TETHERING_WIFI);
|
verify(mEntitleMgr, times(2)).stopProvisioningIfNeeded(TETHERING_WIFI);
|
||||||
reset(mEntitleMgr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupForRequiredProvisioning() {
|
private void setupForRequiredProvisioning() {
|
||||||
|
|
@ -4206,6 +4205,21 @@ public class TetheringTest {
|
||||||
assertFalse(sapPrefix.equals(lohsPrefix));
|
assertFalse(sapPrefix.equals(lohsPrefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailStartTetheredHotspotWithoutRequest() throws Exception {
|
||||||
|
mTetheringWithSoftApConfigEnabled = false;
|
||||||
|
initTetheringOnTestThread();
|
||||||
|
when(mWifiManager.startTetheredHotspot(null)).thenReturn(false);
|
||||||
|
|
||||||
|
ResultListener result = new ResultListener(TETHER_ERROR_INTERNAL_ERROR);
|
||||||
|
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI), TEST_CALLER_PKG, result);
|
||||||
|
mLooper.dispatchAll();
|
||||||
|
verify(mWifiManager).startTetheredHotspot(null);
|
||||||
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
|
result.assertHasResult();
|
||||||
|
assertTrue(mTethering.getPendingTetheringRequests().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWifiTetheringWhenP2pActive() throws Exception {
|
public void testWifiTetheringWhenP2pActive() throws Exception {
|
||||||
initTetheringOnTestThread();
|
initTetheringOnTestThread();
|
||||||
|
|
@ -4219,7 +4233,6 @@ public class TetheringTest {
|
||||||
verify(mUpstreamNetworkMonitor, never()).setTryCell(true);
|
verify(mUpstreamNetworkMonitor, never()).setTryCell(true);
|
||||||
assertEquals(TETHER_ERROR_NO_ERROR, mTethering.getLastErrorForTest(TEST_P2P_IFNAME));
|
assertEquals(TETHER_ERROR_NO_ERROR, mTethering.getLastErrorForTest(TEST_P2P_IFNAME));
|
||||||
|
|
||||||
when(mWifiManager.startTetheredHotspot(any())).thenReturn(true);
|
|
||||||
// Emulate pressing the WiFi tethering button.
|
// Emulate pressing the WiFi tethering button.
|
||||||
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI), TEST_CALLER_PKG,
|
mTethering.startTethering(createTetheringRequest(TETHERING_WIFI), TEST_CALLER_PKG,
|
||||||
null);
|
null);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue