summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-05-30 16:02:56 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-05-30 16:02:57 +0000
commitd01882a64facb9824327b06daf9931a32b0e0494 (patch)
tree2326598271fdc7ef29f9f66dc9ac9c711d7005e6
parent296cdef42bd9a8b998536e52acc07395f8ee9a51 (diff)
parent584a9023ae5f9c88593a2f5c5c2451a26729cc53 (diff)
Merge "WifiServiceImpl: setWifiEnabled permission check"
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java16
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java23
2 files changed, 20 insertions, 19 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index b5487ebb6..b33e8be7d 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -140,9 +140,10 @@ public class WifiServiceImpl extends IWifiManager.Stub {
private static final boolean DBG = true;
private static final boolean VDBG = false;
- // Package names for Settings, QuickSettings and QuickQuickSettings
- private static final String SYSUI_PACKAGE_NAME = "com.android.systemui";
- private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
+ // Dumpsys argument to enable/disable disconnect on IP reachability failures.
+ private static final String DUMP_ARG_SET_IPREACH_DISCONNECT = "set-ipreach-disconnect";
+ private static final String DUMP_ARG_SET_IPREACH_DISCONNECT_ENABLED = "enabled";
+ private static final String DUMP_ARG_SET_IPREACH_DISCONNECT_DISABLED = "disabled";
// Default scan background throttling interval if not overriden in settings
private static final long DEFAULT_SCAN_BACKGROUND_THROTTLE_INTERVAL_MS = 30 * 60 * 1000;
@@ -717,6 +718,12 @@ public class WifiServiceImpl extends IWifiManager.Stub {
mWifiPermissionsUtil.enforceLocationPermission(pkgName, uid);
}
+ private boolean checkNetworkSettingsPermission() {
+ int result = mContext.checkCallingOrSelfPermission(
+ android.Manifest.permission.NETWORK_SETTINGS);
+ return result == PackageManager.PERMISSION_GRANTED;
+ }
+
/**
* see {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)}
* @param enable {@code true} to enable, {@code false} to disable.
@@ -735,8 +742,7 @@ public class WifiServiceImpl extends IWifiManager.Stub {
// If SoftAp is enabled, only Settings is allowed to toggle wifi
boolean apEnabled =
mWifiStateMachine.syncGetWifiApState() != WifiManager.WIFI_AP_STATE_DISABLED;
- boolean isFromSettings =
- packageName.equals(SYSUI_PACKAGE_NAME) || packageName.equals(SETTINGS_PACKAGE_NAME);
+ boolean isFromSettings = checkNetworkSettingsPermission();
if (apEnabled && !isFromSettings) {
mLog.trace("setWifiEnabled SoftAp not disabled: only Settings can enable wifi").flush();
return false;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 01f243db7..01ab0755f 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -113,7 +113,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;
@@ -366,23 +365,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));
}
@@ -393,6 +385,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));