diff options
author | Shashank Mittal <mittals@codeaurora.org> | 2014-09-05 16:03:20 -0700 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2015-10-29 11:01:55 -0700 |
commit | 93a5bde8b9d03c5285bf504c1180946abd83de64 (patch) | |
tree | ac994b443f145764201155efc3778c359f25ab5c | |
parent | 43eded91cdd545b1a41933aa85f8b910b43244dd (diff) | |
download | frameworks_base-93a5bde8b9d03c5285bf504c1180946abd83de64.zip frameworks_base-93a5bde8b9d03c5285bf504c1180946abd83de64.tar.gz frameworks_base-93a5bde8b9d03c5285bf504c1180946abd83de64.tar.bz2 |
wifi: Confirm user permission before toggling wifi
Check user permissions before enabling/disabling wifi.
Change-Id: I1ddae6e47f42b6d3fc831c2c135ece75cf9e935d
-rw-r--r-- | core/java/android/app/AppOpsManager.java | 23 | ||||
-rw-r--r-- | core/res/res/values/qcom_strings.xml | 1 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 9 |
3 files changed, 29 insertions, 4 deletions
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 6006566..3085241 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -250,8 +250,10 @@ public class AppOpsManager { public static final int OP_TURN_SCREEN_ON = 61; /** @hide Get device accounts. */ public static final int OP_GET_ACCOUNTS = 62; + /** @hide Wifi state change **/ + public static final int OP_WIFI_CHANGE = 63; /** @hide */ - public static final int _NUM_OP = 63; + public static final int _NUM_OP = 64; /** Access to coarse location information. */ public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; @@ -349,6 +351,9 @@ public class AppOpsManager { /** @hide Get device accounts. */ public static final String OPSTR_GET_ACCOUNTS = "android:get_accounts"; + /** @hide **/ + private static final String OPSTR_WIFI_CHANGE = + "android:wifi_change"; /** * This maps each operation to the operation that serves as the @@ -422,6 +427,7 @@ public class AppOpsManager { OP_WRITE_EXTERNAL_STORAGE, OP_TURN_SCREEN_ON, OP_GET_ACCOUNTS, + OP_WIFI_CHANGE, }; /** @@ -491,7 +497,8 @@ public class AppOpsManager { OPSTR_READ_EXTERNAL_STORAGE, OPSTR_WRITE_EXTERNAL_STORAGE, null, - OPSTR_GET_ACCOUNTS + OPSTR_GET_ACCOUNTS, + OPSTR_WIFI_CHANGE, }; /** @@ -562,6 +569,7 @@ public class AppOpsManager { "WRITE_EXTERNAL_STORAGE", "TURN_ON_SCREEN", "GET_ACCOUNTS", + "WIFI_CHANGE", }; /** @@ -631,7 +639,8 @@ public class AppOpsManager { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, null, // no permission for turning the screen on - Manifest.permission.GET_ACCOUNTS + Manifest.permission.GET_ACCOUNTS, + Manifest.permission.CHANGE_WIFI_STATE, }; /** @@ -703,6 +712,7 @@ public class AppOpsManager { null, // WRITE_EXTERNAL_STORAGE null, // TURN_ON_SCREEN null, // GET_ACCOUNTS + null, //WIFI_CHANGE }; /** @@ -773,6 +783,7 @@ public class AppOpsManager { false, // WRITE_EXTERNAL_STORAGE false, // TURN_ON_SCREEN false, // GET_ACCOUNTS + false, // WIFI_CHANGE }; /** @@ -842,6 +853,7 @@ public class AppOpsManager { AppOpsManager.MODE_ALLOWED, AppOpsManager.MODE_ALLOWED, // OP_TURN_ON_SCREEN AppOpsManager.MODE_ALLOWED, + AppOpsManager.MODE_ALLOWED, // OP_WIFI_CHANGE }; /** @@ -912,6 +924,7 @@ public class AppOpsManager { AppOpsManager.MODE_ALLOWED, // OP_WRITE_EXTERNAL_STORAGE AppOpsManager.MODE_ALLOWED, // OP_TURN_ON_SCREEN AppOpsManager.MODE_ALLOWED, // OP_GET_ACCOUNTS + AppOpsManager.MODE_ASK, // OP_WIFI_CHANGE }; /** @@ -981,6 +994,7 @@ public class AppOpsManager { true, // WRITE_EXTERNAL_STORAGE false, // TURN_ON_SCREEN false, // GET_ACCOUNTS + true, // OP_WIFI_CHANGE }; /** @@ -1053,7 +1067,8 @@ public class AppOpsManager { false, false, false, - false + false, + false, // OP_WIFI_CHANGE }; /** diff --git a/core/res/res/values/qcom_strings.xml b/core/res/res/values/qcom_strings.xml index 3d4830be..2c53f94 100644 --- a/core/res/res/values/qcom_strings.xml +++ b/core/res/res/values/qcom_strings.xml @@ -84,5 +84,6 @@ <item>Trying to write external storage</item> <item>Trying to turn screen on</item> <item>Trying to get device accounts</item> + <item>Trying to turn on/off Wi-Fi</item> </string-array> </resources> diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 6b6be54e..46ae8d3 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -1,4 +1,7 @@ /* + * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. + * Not a Contribution. + * * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +22,7 @@ package android.net.wifi; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; +import android.app.AppOpsManager; import android.content.Context; import android.net.ConnectivityManager; import android.net.ConnectivityManager.NetworkCallback; @@ -623,6 +627,7 @@ public class WifiManager { private static final Object sThreadRefLock = new Object(); private static int sThreadRefCount; private static HandlerThread sHandlerThread; + private final AppOpsManager mAppOps; @GuardedBy("sCM") // TODO: Introduce refcounting and make this a per-process static callback, instead of a @@ -644,6 +649,7 @@ public class WifiManager { mService = service; mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion; init(); + mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); } /** @@ -1454,6 +1460,9 @@ public class WifiManager { * is the same as the requested state). */ public boolean setWifiEnabled(boolean enabled) { + if (mAppOps.noteOp(AppOpsManager.OP_WIFI_CHANGE) != + AppOpsManager.MODE_ALLOWED) + return false; try { return mService.setWifiEnabled(enabled); } catch (RemoteException e) { |