summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-05-25 01:12:47 -0700
committerRebecca Silberstein <silberst@google.com>2017-05-26 13:32:21 -0700
commitde6ff4c1fc87364efc5fa15de31325b4450548b0 (patch)
tree799e74bdb5f9f5c3a7985dae79ec8c36678ada95 /tests
parentf9b25d48b7cadff8cb8eead96114f8b6725cc800 (diff)
WifiServiceImpl: setWifiEnabled permission check
Instead of using the package name to determine if the caller of setWifiEnabled is from settings or sysui, switch over to use the NETWORK_SETTINGS permission. This permission check will be done to avoid stopping softap mode by third-party apps. Bug: 38163947 Test: frameworks/base/wifi/tests/runtests.sh Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: manually tested attempting to enable wifi from settings, quick settings and quick quick settings when wifi tethering was active Test: cts-tradefed run cts-dev --module CtsNetTestCases -t android.net.wifi.cts.WifiManagerTest#testSetWifiEnabledByAppDoesNotStopHotspot Merged-In: I05a3cab6bc2b4b725badcbb7416f3f5bcd0dc3e9 Change-Id: I05a3cab6bc2b4b725badcbb7416f3f5bcd0dc3e9
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java24
1 files changed, 10 insertions, 14 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 0c608d9ea..64100e217 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -56,6 +56,7 @@ import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.IntentFilter;
+import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.IpConfiguration;
import android.net.wifi.ScanSettings;
@@ -110,7 +111,6 @@ public class WifiServiceImplTest {
private static final long WIFI_BACKGROUND_SCAN_INTERVAL = 10000;
private static final String ANDROID_SYSTEM_PACKAGE = "android";
private static final String TEST_PACKAGE_NAME = "TestPackage";
- private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
private static final String SYSUI_PACKAGE_NAME = "com.android.systemui";
private static final int TEST_PID = 6789;
private static final int TEST_PID2 = 9876;
@@ -363,23 +363,16 @@ public class WifiServiceImplTest {
}
/**
- * Verify that a call from Settings can enable wifi if we are in softap mode.
+ * Verify that a call from an app with the NETWORK_SETTINGS permission can enable wifi if we
+ * are in softap mode.
*/
@Test
- public void testSetWifiEnabledFromSettingsWhenApEnabled() throws Exception {
- when(mWifiStateMachine.syncGetWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED);
- when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true);
- assertTrue(mWifiServiceImpl.setWifiEnabled(SETTINGS_PACKAGE_NAME, true));
- verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED));
- }
-
- /**
- * Verify that a call from SysUI can enable wifi if we are in softap mode.
- */
- @Test
- public void testSetWifiEnabledFromSysUiWhenApEnabled() throws Exception {
+ public void testSetWifiEnabledFromNetworkSettingsHolderWhenApEnabled() throws Exception {
when(mWifiStateMachine.syncGetWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED);
when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true);
+ when(mContext.checkCallingOrSelfPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS)))
+ .thenReturn(PackageManager.PERMISSION_GRANTED);
assertTrue(mWifiServiceImpl.setWifiEnabled(SYSUI_PACKAGE_NAME, true));
verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED));
}
@@ -390,6 +383,9 @@ public class WifiServiceImplTest {
@Test
public void testSetWifiEnabledFromAppFailsWhenApEnabled() throws Exception {
when(mWifiStateMachine.syncGetWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED);
+ when(mContext.checkCallingOrSelfPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS)))
+ .thenReturn(PackageManager.PERMISSION_DENIED);
assertFalse(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, true));
verify(mSettingsStore, never()).handleWifiToggled(anyBoolean());
verify(mWifiController, never()).sendMessage(eq(CMD_WIFI_TOGGLED));