summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-04-02 19:19:11 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-04-02 19:19:11 +0000
commita6116a569b3f30fa0b775e2d33477b193f07dbcc (patch)
tree3dcdd51fae663e43a3b545d59438a106a047cb78 /service
parent7429ec81f02431a20c219d6ecc3be9b051bb8c1f (diff)
parentc2f909d87ad83b654dba9c1b381ec6d9c5a05366 (diff)
Merge "WifiService: setWifiEnabled bypass for older apps"
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java23
1 files changed, 19 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 17d7ef848..88bd3a865 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -874,16 +874,31 @@ public class WifiServiceImpl extends BaseWifiService {
*/
@Override
public synchronized boolean setWifiEnabled(String packageName, boolean enable) {
- mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_WIFI_STATE,
- "WifiService");
- // only privileged apps like settings, setup wizard, etc can toggle wifi.
- if (!isPrivileged(Binder.getCallingPid(), Binder.getCallingUid())
+ if (enforceChangePermission(packageName) != MODE_ALLOWED) {
+ return false;
+ }
+ boolean isPrivileged = isPrivileged(Binder.getCallingPid(), Binder.getCallingUid());
+ if (!isPrivileged
+ && !mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q)
// Default car dock app is allowed to turn on wifi (but, cannot turn off)
&& !(isDefaultCarDock(packageName) && enable)) {
mLog.info("setWifiEnabled not allowed for uid=%")
.c(Binder.getCallingUid()).flush();
return false;
}
+ // If Airplane mode is enabled, only privileged apps are allowed to toggle Wifi
+ if (mSettingsStore.isAirplaneModeOn() && !isPrivileged) {
+ mLog.err("setWifiEnabled in Airplane mode: only Settings can toggle wifi").flush();
+ return false;
+ }
+
+ // If SoftAp is enabled, only privileged apps are allowed to toggle wifi
+ boolean apEnabled = mWifiApState == WifiManager.WIFI_AP_STATE_ENABLED;
+ if (apEnabled && !isPrivileged) {
+ mLog.err("setWifiEnabled SoftAp enabled: only Settings can toggle wifi").flush();
+ return false;
+ }
+
mLog.info("setWifiEnabled package=% uid=% enable=%").c(packageName)
.c(Binder.getCallingUid()).c(enable).flush();
long ident = Binder.clearCallingIdentity();