From 93a5bde8b9d03c5285bf504c1180946abd83de64 Mon Sep 17 00:00:00 2001 From: Shashank Mittal Date: Fri, 5 Sep 2014 16:03:20 -0700 Subject: wifi: Confirm user permission before toggling wifi Check user permissions before enabling/disabling wifi. Change-Id: I1ddae6e47f42b6d3fc831c2c135ece75cf9e935d --- wifi/java/android/net/wifi/WifiManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'wifi/java') 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) { -- cgit v1.1