summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-03-23 01:49:14 -0700
committerRebecca Silberstein <silberst@google.com>2017-04-20 22:29:38 +0000
commitedabcd4004fe1ad46e58ee973906913cc3edc79e (patch)
tree7ec968595861ad0904019aa489319243c250e286 /tests
parent3871ff67f4a6970f1831fc8951392746c9e2bfa2 (diff)
WifiServiceImpl: add new methods to start softap
Add the implementations for two new methods to control softap mode. These methods will be called by other methods in WifiServiceImpl and also by ConnectivityService. The calls are not intended to be called by applications and will be protected by the NETWORK_STACK permission. Note: this CL is adding the calls, they will be used in an upcoming CL. Bug: 36540346 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: frameworks/base/wifi/tests/runtests.sh Change-Id: I6bc664a32c5df03db1dffb8db20330d9dc904113 Merged-In: I6bc664a32c5df03db1dffb8db20330d9dc904113 Merged-In: If1ab98324b4f860efa93286637a4fdcec7d8f775
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java68
1 files changed, 67 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index a09c9132a..6975432b6 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -486,7 +486,7 @@ public class WifiServiceImplTest {
* setWifiApEnabled should fail if the provided config is not valid.
*/
@Test
- public void testSetWIfiApEnabledWithProperPermissionInvalidConfigFails() {
+ public void testSetWifiApEnabledWithProperPermissionInvalidConfigFails() {
when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(true);
when(mUserManager.hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_TETHERING)))
.thenReturn(false);
@@ -520,5 +520,71 @@ public class WifiServiceImplTest {
when(mUserManager.hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_TETHERING)))
.thenReturn(true);
mWifiServiceImpl.setWifiApEnabled(null, true);
+
+ }
+
+ /**
+ * Verify caller with proper permission can call startSoftAp.
+ */
+ @Test
+ public void testStartSoftApWithPermissionsAndNullConfig() {
+ boolean result = mWifiServiceImpl.startSoftAp(null);
+ assertTrue(result);
+ verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(null));
+ }
+
+ /**
+ * Verify caller with proper permissions but an invalid config does not start softap.
+ */
+ @Test
+ public void testStartSoftApWithPermissionsAndInvalidConfig() {
+ boolean result = mWifiServiceImpl.startSoftAp(mApConfig);
+ assertFalse(result);
+ verifyZeroInteractions(mWifiController);
+ }
+
+ /**
+ * Verify caller with proper permission and valid config does start softap.
+ */
+ @Test
+ public void testStartSoftApWithPermissionsAndValidConfig() {
+ WifiConfiguration config = new WifiConfiguration();
+ boolean result = mWifiServiceImpl.startSoftAp(config);
+ assertTrue(result);
+ verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(config));
+ }
+
+ /**
+ * Verify a SecurityException is thrown when a caller without the correct permission attempts to
+ * start softap.
+ */
+ @Test(expected = SecurityException.class)
+ public void testStartSoftApWithoutPermissionThrowsException() throws Exception {
+ doThrow(new SecurityException()).when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_STACK),
+ eq("WifiService"));
+ mWifiServiceImpl.startSoftAp(null);
+ }
+
+ /**
+ * Verify caller with proper permission can call stopSoftAp.
+ */
+ @Test
+ public void testStopSoftApWithPermissions() {
+ boolean result = mWifiServiceImpl.stopSoftAp();
+ assertTrue(result);
+ verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(0), eq(0));
+ }
+
+ /**
+ * Verify SecurityException is thrown when a caller without the correct permission attempts to
+ * stop softap.
+ */
+ @Test(expected = SecurityException.class)
+ public void testStopSoftApWithoutPermissionThrowsException() throws Exception {
+ doThrow(new SecurityException()).when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_STACK),
+ eq("WifiService"));
+ mWifiServiceImpl.stopSoftAp();
}
}