Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85a66108 authored by Shashank Mittal's avatar Shashank Mittal
Browse files

wifi: Confirm user permission before toggling wifi.

Check user permissions before enabling/disabling wifi.

Change-Id: I1ddae6e47f42b6d3fc831c2c135ece75cf9e935d
parent fe088650
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -195,7 +195,9 @@ public class AppOpsManager {
    /** @hide Continually monitoring location data with a relatively high power request. */
    public static final int OP_MONITOR_HIGH_POWER_LOCATION = 42;
    /** @hide */
    public static final int _NUM_OP = 43;
    public static final int OP_WIFI_CHANGE = 43;
    /** @hide */
    public static final int _NUM_OP = 44;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION =
@@ -262,6 +264,7 @@ public class AppOpsManager {
            OP_WAKE_LOCK,
            OP_COARSE_LOCATION,
            OP_COARSE_LOCATION,
            OP_WIFI_CHANGE,
    };

    /**
@@ -312,6 +315,7 @@ public class AppOpsManager {
            null,
            OPSTR_MONITOR_LOCATION,
            OPSTR_MONITOR_HIGH_POWER_LOCATION,
            null,
    };

    /**
@@ -362,6 +366,7 @@ public class AppOpsManager {
            "WAKE_LOCK",
            "MONITOR_LOCATION",
            "MONITOR_HIGH_POWER_LOCATION",
            "WIFI_CHANGE",
    };

    /**
@@ -412,6 +417,7 @@ public class AppOpsManager {
            android.Manifest.permission.WAKE_LOCK,
            null, // no permission for generic location monitoring
            null, // no permission for high power location monitoring
            android.Manifest.permission.CHANGE_WIFI_STATE,
    };

    /**
@@ -461,6 +467,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED, // OP_WAKE_LOCK
            AppOpsManager.MODE_ALLOWED, // OP_MONITOR_LOCATION
            AppOpsManager.MODE_ALLOWED, // OP_MONITOR_HIGH_POWER_LOCATION
            AppOpsManager.MODE_ALLOWED, // OP_WIFI_CHANGE
    };

    /**
@@ -510,6 +517,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED, // OP_WAKE_LOCK
            AppOpsManager.MODE_ALLOWED, // OP_MONITOR_LOCATION
            AppOpsManager.MODE_ASK,     // OP_MONITOR_HIGH_POWER_LOCATION
            AppOpsManager.MODE_ASK,     // OP_WIFI_CHANGE
    };


@@ -564,6 +572,7 @@ public class AppOpsManager {
            false,
            false,
            false,
            false,
    };

    private static HashMap<String, Integer> sOpStrToOp = new HashMap<String, Integer>();
+1 −0
Original line number Diff line number Diff line
@@ -1356,5 +1356,6 @@
        <item>Trying to Keep device awake</item>
        <item>Trying to access location</item>
        <item>Trying to access location</item>
        <item>Trying to turn on/off Wifi</item>
    </string-array>
</resources>
+6 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.net.wifi;

import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.AppOpsManager;
import android.content.Context;
import android.net.DhcpInfo;
import android.os.Binder;
@@ -546,6 +547,7 @@ public class WifiManager {
    private static final Object sThreadRefLock = new Object();
    private static int sThreadRefCount;
    private static HandlerThread sHandlerThread;
    private final AppOpsManager mAppOps;

    /**
     * Create a new WifiManager instance.
@@ -561,6 +563,7 @@ public class WifiManager {
        mContext = context;
        mService = service;
        init();
        mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
    }

    /**
@@ -1004,6 +1007,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) {