Merge "TetheringServiceTest: test caller permission" am: 366eae572d
Change-Id: I5064eb5e27d7803c0f86b75c391b56f1e3cb4d7d
This commit is contained in:
@@ -16,9 +16,6 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.android.networkstack.tethering.tests.unit">
|
package="com.android.networkstack.tethering.tests.unit">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
|
|
||||||
<uses-permission android:name="android.permission.TETHER_PRIVILEGED"/>
|
|
||||||
|
|
||||||
<application android:debuggable="true">
|
<application android:debuggable="true">
|
||||||
<uses-library android:name="android.test.runner" />
|
<uses-library android:name="android.test.runner" />
|
||||||
<service
|
<service
|
||||||
|
|||||||
@@ -16,20 +16,29 @@
|
|||||||
|
|
||||||
package com.android.networkstack.tethering;
|
package com.android.networkstack.tethering;
|
||||||
|
|
||||||
|
import static android.Manifest.permission.ACCESS_NETWORK_STATE;
|
||||||
|
import static android.Manifest.permission.TETHER_PRIVILEGED;
|
||||||
|
import static android.Manifest.permission.WRITE_SETTINGS;
|
||||||
import static android.net.TetheringManager.TETHERING_WIFI;
|
import static android.net.TetheringManager.TETHERING_WIFI;
|
||||||
|
import static android.net.TetheringManager.TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION;
|
||||||
|
import static android.net.TetheringManager.TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION;
|
||||||
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
|
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.reset;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.UiAutomation;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.IIntResultListener;
|
import android.net.IIntResultListener;
|
||||||
import android.net.ITetheringConnector;
|
import android.net.ITetheringConnector;
|
||||||
import android.net.ITetheringEventCallback;
|
import android.net.ITetheringEventCallback;
|
||||||
import android.net.TetheringRequestParcel;
|
import android.net.TetheringRequestParcel;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
|
|
||||||
import androidx.test.InstrumentationRegistry;
|
import androidx.test.InstrumentationRegistry;
|
||||||
@@ -51,13 +60,14 @@ import org.mockito.MockitoAnnotations;
|
|||||||
@SmallTest
|
@SmallTest
|
||||||
public final class TetheringServiceTest {
|
public final class TetheringServiceTest {
|
||||||
private static final String TEST_IFACE_NAME = "test_wlan0";
|
private static final String TEST_IFACE_NAME = "test_wlan0";
|
||||||
private static final String TEST_CALLER_PKG = "test_pkg";
|
private static final String TEST_CALLER_PKG = "com.android.shell";
|
||||||
private static final String TEST_ATTRIBUTION_TAG = null;
|
private static final String TEST_ATTRIBUTION_TAG = null;
|
||||||
@Mock private ITetheringEventCallback mITetheringEventCallback;
|
@Mock private ITetheringEventCallback mITetheringEventCallback;
|
||||||
@Rule public ServiceTestRule mServiceTestRule;
|
@Rule public ServiceTestRule mServiceTestRule;
|
||||||
private Tethering mTethering;
|
private Tethering mTethering;
|
||||||
private Intent mMockServiceIntent;
|
private Intent mMockServiceIntent;
|
||||||
private ITetheringConnector mTetheringConnector;
|
private ITetheringConnector mTetheringConnector;
|
||||||
|
private UiAutomation mUiAutomation;
|
||||||
|
|
||||||
private class TestTetheringResult extends IIntResultListener.Stub {
|
private class TestTetheringResult extends IIntResultListener.Stub {
|
||||||
private int mResult = -1; // Default value that does not match any result code.
|
private int mResult = -1; // Default value that does not match any result code.
|
||||||
@@ -71,9 +81,26 @@ public final class TetheringServiceTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class MyResultReceiver extends ResultReceiver {
|
||||||
|
MyResultReceiver(Handler handler) {
|
||||||
|
super(handler);
|
||||||
|
}
|
||||||
|
private int mResult = -1; // Default value that does not match any result code.
|
||||||
|
@Override
|
||||||
|
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
||||||
|
mResult = resultCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assertResult(int expected) {
|
||||||
|
assertEquals(expected, mResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mUiAutomation =
|
||||||
|
InstrumentationRegistry.getInstrumentation().getUiAutomation();
|
||||||
mServiceTestRule = new ServiceTestRule();
|
mServiceTestRule = new ServiceTestRule();
|
||||||
mMockServiceIntent = new Intent(
|
mMockServiceIntent = new Intent(
|
||||||
InstrumentationRegistry.getTargetContext(),
|
InstrumentationRegistry.getTargetContext(),
|
||||||
@@ -83,115 +110,364 @@ public final class TetheringServiceTest {
|
|||||||
mTetheringConnector = mockConnector.getTetheringConnector();
|
mTetheringConnector = mockConnector.getTetheringConnector();
|
||||||
final MockTetheringService service = mockConnector.getService();
|
final MockTetheringService service = mockConnector.getService();
|
||||||
mTethering = service.getTethering();
|
mTethering = service.getTethering();
|
||||||
when(mTethering.isTetheringSupported()).thenReturn(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
mServiceTestRule.unbindService();
|
mServiceTestRule.unbindService();
|
||||||
|
mUiAutomation.dropShellPermissionIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface TestTetheringCall {
|
||||||
|
void runTetheringCall(TestTetheringResult result) throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runAsNoPermission(final TestTetheringCall test) throws Exception {
|
||||||
|
runTetheringCall(test, new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runAsTetherPrivileged(final TestTetheringCall test) throws Exception {
|
||||||
|
runTetheringCall(test, TETHER_PRIVILEGED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runAsAccessNetworkState(final TestTetheringCall test) throws Exception {
|
||||||
|
runTetheringCall(test, ACCESS_NETWORK_STATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runAsWriteSettings(final TestTetheringCall test) throws Exception {
|
||||||
|
runTetheringCall(test, WRITE_SETTINGS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runTetheringCall(final TestTetheringCall test, String... permissions)
|
||||||
|
throws Exception {
|
||||||
|
if (permissions.length > 0) mUiAutomation.adoptShellPermissionIdentity(permissions);
|
||||||
|
try {
|
||||||
|
when(mTethering.isTetheringSupported()).thenReturn(true);
|
||||||
|
test.runTetheringCall(new TestTetheringResult());
|
||||||
|
} finally {
|
||||||
|
mUiAutomation.dropShellPermissionIdentity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyNoMoreInteractionsForTethering() {
|
||||||
|
verifyNoMoreInteractions(mTethering);
|
||||||
|
verifyNoMoreInteractions(mITetheringEventCallback);
|
||||||
|
reset(mTethering, mITetheringEventCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runTether(final TestTetheringResult result) throws Exception {
|
||||||
|
when(mTethering.tether(TEST_IFACE_NAME)).thenReturn(TETHER_ERROR_NO_ERROR);
|
||||||
|
mTetheringConnector.tether(TEST_IFACE_NAME, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG, result);
|
||||||
|
verify(mTethering).isTetheringSupported();
|
||||||
|
verify(mTethering).tether(TEST_IFACE_NAME);
|
||||||
|
result.assertResult(TETHER_ERROR_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTether() throws Exception {
|
public void testTether() throws Exception {
|
||||||
when(mTethering.tether(TEST_IFACE_NAME)).thenReturn(TETHER_ERROR_NO_ERROR);
|
runAsNoPermission((result) -> {
|
||||||
final TestTetheringResult result = new TestTetheringResult();
|
mTetheringConnector.tether(TEST_IFACE_NAME, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG,
|
||||||
mTetheringConnector.tether(TEST_IFACE_NAME, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG, result);
|
result);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsTetherPrivileged((result) -> {
|
||||||
|
runTether(result);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsWriteSettings((result) -> {
|
||||||
|
runTether(result);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runUnTether(final TestTetheringResult result) throws Exception {
|
||||||
|
when(mTethering.untether(TEST_IFACE_NAME)).thenReturn(TETHER_ERROR_NO_ERROR);
|
||||||
|
mTetheringConnector.untether(TEST_IFACE_NAME, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG,
|
||||||
|
result);
|
||||||
verify(mTethering).isTetheringSupported();
|
verify(mTethering).isTetheringSupported();
|
||||||
verify(mTethering).tether(TEST_IFACE_NAME);
|
verify(mTethering).untether(TEST_IFACE_NAME);
|
||||||
verifyNoMoreInteractions(mTethering);
|
|
||||||
result.assertResult(TETHER_ERROR_NO_ERROR);
|
result.assertResult(TETHER_ERROR_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUntether() throws Exception {
|
public void testUntether() throws Exception {
|
||||||
when(mTethering.untether(TEST_IFACE_NAME)).thenReturn(TETHER_ERROR_NO_ERROR);
|
runAsNoPermission((result) -> {
|
||||||
final TestTetheringResult result = new TestTetheringResult();
|
mTetheringConnector.untether(TEST_IFACE_NAME, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG,
|
||||||
mTetheringConnector.untether(TEST_IFACE_NAME, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG,
|
result);
|
||||||
result);
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsTetherPrivileged((result) -> {
|
||||||
|
runUnTether(result);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsWriteSettings((result) -> {
|
||||||
|
runUnTether(result);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runSetUsbTethering(final TestTetheringResult result) throws Exception {
|
||||||
|
when(mTethering.setUsbTethering(true /* enable */)).thenReturn(TETHER_ERROR_NO_ERROR);
|
||||||
|
mTetheringConnector.setUsbTethering(true /* enable */, TEST_CALLER_PKG,
|
||||||
|
TEST_ATTRIBUTION_TAG, result);
|
||||||
verify(mTethering).isTetheringSupported();
|
verify(mTethering).isTetheringSupported();
|
||||||
verify(mTethering).untether(TEST_IFACE_NAME);
|
verify(mTethering).setUsbTethering(true /* enable */);
|
||||||
verifyNoMoreInteractions(mTethering);
|
|
||||||
result.assertResult(TETHER_ERROR_NO_ERROR);
|
result.assertResult(TETHER_ERROR_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetUsbTethering() throws Exception {
|
public void testSetUsbTethering() throws Exception {
|
||||||
when(mTethering.setUsbTethering(true /* enable */)).thenReturn(TETHER_ERROR_NO_ERROR);
|
runAsNoPermission((result) -> {
|
||||||
final TestTetheringResult result = new TestTetheringResult();
|
mTetheringConnector.setUsbTethering(true /* enable */, TEST_CALLER_PKG,
|
||||||
mTetheringConnector.setUsbTethering(true /* enable */, TEST_CALLER_PKG,
|
TEST_ATTRIBUTION_TAG, result);
|
||||||
TEST_ATTRIBUTION_TAG, result);
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsTetherPrivileged((result) -> {
|
||||||
|
runSetUsbTethering(result);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsWriteSettings((result) -> {
|
||||||
|
runSetUsbTethering(result);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runStartTethering(final TestTetheringResult result,
|
||||||
|
final TetheringRequestParcel request) throws Exception {
|
||||||
|
mTetheringConnector.startTethering(request, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG,
|
||||||
|
result);
|
||||||
verify(mTethering).isTetheringSupported();
|
verify(mTethering).isTetheringSupported();
|
||||||
verify(mTethering).setUsbTethering(true /* enable */);
|
verify(mTethering).startTethering(eq(request), eq(result));
|
||||||
verifyNoMoreInteractions(mTethering);
|
|
||||||
result.assertResult(TETHER_ERROR_NO_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartTethering() throws Exception {
|
public void testStartTethering() throws Exception {
|
||||||
final TestTetheringResult result = new TestTetheringResult();
|
|
||||||
final TetheringRequestParcel request = new TetheringRequestParcel();
|
final TetheringRequestParcel request = new TetheringRequestParcel();
|
||||||
request.tetheringType = TETHERING_WIFI;
|
request.tetheringType = TETHERING_WIFI;
|
||||||
mTetheringConnector.startTethering(request, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG, result);
|
|
||||||
verify(mTethering).isTetheringSupported();
|
runAsNoPermission((result) -> {
|
||||||
verify(mTethering).startTethering(eq(request), eq(result));
|
mTetheringConnector.startTethering(request, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG,
|
||||||
verifyNoMoreInteractions(mTethering);
|
result);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsTetherPrivileged((result) -> {
|
||||||
|
runStartTethering(result, request);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsWriteSettings((result) -> {
|
||||||
|
runStartTethering(result, request);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStopTethering() throws Exception {
|
public void testStartTetheringWithExemptFromEntitlementCheck() throws Exception {
|
||||||
final TestTetheringResult result = new TestTetheringResult();
|
final TetheringRequestParcel request = new TetheringRequestParcel();
|
||||||
mTetheringConnector.stopTethering(TETHERING_WIFI, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG,
|
request.tetheringType = TETHERING_WIFI;
|
||||||
result);
|
request.exemptFromEntitlementCheck = true;
|
||||||
|
|
||||||
|
runAsTetherPrivileged((result) -> {
|
||||||
|
runStartTethering(result, request);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsWriteSettings((result) -> {
|
||||||
|
mTetheringConnector.startTethering(request, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG,
|
||||||
|
result);
|
||||||
|
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runStopTethering(final TestTetheringResult result) throws Exception {
|
||||||
|
mTetheringConnector.stopTethering(TETHERING_WIFI, TEST_CALLER_PKG,
|
||||||
|
TEST_ATTRIBUTION_TAG, result);
|
||||||
verify(mTethering).isTetheringSupported();
|
verify(mTethering).isTetheringSupported();
|
||||||
verify(mTethering).stopTethering(TETHERING_WIFI);
|
verify(mTethering).stopTethering(TETHERING_WIFI);
|
||||||
verifyNoMoreInteractions(mTethering);
|
|
||||||
result.assertResult(TETHER_ERROR_NO_ERROR);
|
result.assertResult(TETHER_ERROR_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestLatestTetheringEntitlementResult() throws Exception {
|
public void testStopTethering() throws Exception {
|
||||||
final ResultReceiver result = new ResultReceiver(null);
|
runAsNoPermission((result) -> {
|
||||||
|
mTetheringConnector.stopTethering(TETHERING_WIFI, TEST_CALLER_PKG,
|
||||||
|
TEST_ATTRIBUTION_TAG, result);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsTetherPrivileged((result) -> {
|
||||||
|
runStopTethering(result);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsWriteSettings((result) -> {
|
||||||
|
runStopTethering(result);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runRequestLatestTetheringEntitlementResult() throws Exception {
|
||||||
|
final MyResultReceiver result = new MyResultReceiver(null);
|
||||||
mTetheringConnector.requestLatestTetheringEntitlementResult(TETHERING_WIFI, result,
|
mTetheringConnector.requestLatestTetheringEntitlementResult(TETHERING_WIFI, result,
|
||||||
true /* showEntitlementUi */, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG);
|
true /* showEntitlementUi */, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG);
|
||||||
verify(mTethering).isTetheringSupported();
|
verify(mTethering).isTetheringSupported();
|
||||||
verify(mTethering).requestLatestTetheringEntitlementResult(eq(TETHERING_WIFI),
|
verify(mTethering).requestLatestTetheringEntitlementResult(eq(TETHERING_WIFI),
|
||||||
eq(result), eq(true) /* showEntitlementUi */);
|
eq(result), eq(true) /* showEntitlementUi */);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRequestLatestTetheringEntitlementResult() throws Exception {
|
||||||
|
// Run as no permission.
|
||||||
|
final MyResultReceiver result = new MyResultReceiver(null);
|
||||||
|
mTetheringConnector.requestLatestTetheringEntitlementResult(TETHERING_WIFI, result,
|
||||||
|
true /* showEntitlementUi */, TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||||
verifyNoMoreInteractions(mTethering);
|
verifyNoMoreInteractions(mTethering);
|
||||||
|
|
||||||
|
runAsTetherPrivileged((none) -> {
|
||||||
|
runRequestLatestTetheringEntitlementResult();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsWriteSettings((none) -> {
|
||||||
|
runRequestLatestTetheringEntitlementResult();
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runRegisterTetheringEventCallback() throws Exception {
|
||||||
|
mTetheringConnector.registerTetheringEventCallback(mITetheringEventCallback,
|
||||||
|
TEST_CALLER_PKG);
|
||||||
|
verify(mTethering).registerTetheringEventCallback(eq(mITetheringEventCallback));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegisterTetheringEventCallback() throws Exception {
|
public void testRegisterTetheringEventCallback() throws Exception {
|
||||||
mTetheringConnector.registerTetheringEventCallback(mITetheringEventCallback,
|
runAsNoPermission((result) -> {
|
||||||
|
mTetheringConnector.registerTetheringEventCallback(mITetheringEventCallback,
|
||||||
|
TEST_CALLER_PKG);
|
||||||
|
verify(mITetheringEventCallback).onCallbackStopped(
|
||||||
|
TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsTetherPrivileged((none) -> {
|
||||||
|
runRegisterTetheringEventCallback();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsAccessNetworkState((none) -> {
|
||||||
|
runRegisterTetheringEventCallback();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runUnregisterTetheringEventCallback() throws Exception {
|
||||||
|
mTetheringConnector.unregisterTetheringEventCallback(mITetheringEventCallback,
|
||||||
TEST_CALLER_PKG);
|
TEST_CALLER_PKG);
|
||||||
verify(mTethering).registerTetheringEventCallback(eq(mITetheringEventCallback));
|
verify(mTethering).unregisterTetheringEventCallback(eq(mITetheringEventCallback));
|
||||||
verifyNoMoreInteractions(mTethering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnregisterTetheringEventCallback() throws Exception {
|
public void testUnregisterTetheringEventCallback() throws Exception {
|
||||||
mTetheringConnector.unregisterTetheringEventCallback(mITetheringEventCallback,
|
runAsNoPermission((result) -> {
|
||||||
TEST_CALLER_PKG);
|
mTetheringConnector.unregisterTetheringEventCallback(mITetheringEventCallback,
|
||||||
verify(mTethering).unregisterTetheringEventCallback(
|
TEST_CALLER_PKG);
|
||||||
eq(mITetheringEventCallback));
|
verify(mITetheringEventCallback).onCallbackStopped(
|
||||||
verifyNoMoreInteractions(mTethering);
|
TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsTetherPrivileged((none) -> {
|
||||||
|
runUnregisterTetheringEventCallback();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsAccessNetworkState((none) -> {
|
||||||
|
runUnregisterTetheringEventCallback();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runStopAllTethering(final TestTetheringResult result) throws Exception {
|
||||||
|
mTetheringConnector.stopAllTethering(TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG, result);
|
||||||
|
verify(mTethering).isTetheringSupported();
|
||||||
|
verify(mTethering).untetherAll();
|
||||||
|
result.assertResult(TETHER_ERROR_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStopAllTethering() throws Exception {
|
public void testStopAllTethering() throws Exception {
|
||||||
final TestTetheringResult result = new TestTetheringResult();
|
runAsNoPermission((result) -> {
|
||||||
mTetheringConnector.stopAllTethering(TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG, result);
|
mTetheringConnector.stopAllTethering(TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG, result);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsTetherPrivileged((result) -> {
|
||||||
|
runStopAllTethering(result);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsWriteSettings((result) -> {
|
||||||
|
runStopAllTethering(result);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runIsTetheringSupported(final TestTetheringResult result) throws Exception {
|
||||||
|
mTetheringConnector.isTetheringSupported(TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG, result);
|
||||||
verify(mTethering).isTetheringSupported();
|
verify(mTethering).isTetheringSupported();
|
||||||
verify(mTethering).untetherAll();
|
|
||||||
verifyNoMoreInteractions(mTethering);
|
|
||||||
result.assertResult(TETHER_ERROR_NO_ERROR);
|
result.assertResult(TETHER_ERROR_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsTetheringSupported() throws Exception {
|
public void testIsTetheringSupported() throws Exception {
|
||||||
final TestTetheringResult result = new TestTetheringResult();
|
runAsNoPermission((result) -> {
|
||||||
mTetheringConnector.isTetheringSupported(TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG, result);
|
mTetheringConnector.isTetheringSupported(TEST_CALLER_PKG, TEST_ATTRIBUTION_TAG,
|
||||||
verify(mTethering).isTetheringSupported();
|
result);
|
||||||
verifyNoMoreInteractions(mTethering);
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
result.assertResult(TETHER_ERROR_NO_ERROR);
|
result.assertResult(TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsTetherPrivileged((result) -> {
|
||||||
|
runIsTetheringSupported(result);
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
|
|
||||||
|
runAsWriteSettings((result) -> {
|
||||||
|
runIsTetheringSupported(result);
|
||||||
|
verify(mTethering).isTetherProvisioningRequired();
|
||||||
|
verifyNoMoreInteractionsForTethering();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user