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

Commit 5aaea028 authored by Shashank Mittal's avatar Shashank Mittal Committed by Ricardo Cerqueira
Browse files

wifi: Confirm user permission before toggling wifi

Check user permissions before enabling/disabling wifi.

Change-Id: I1ddae6e47f42b6d3fc831c2c135ece75cf9e935d
parent 948e1317
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -219,7 +219,9 @@ public class AppOpsManager {
    /** @hide Activate a VPN connection without user intervention. */
    public static final int OP_ACTIVATE_VPN = 47;
    /** @hide */
    public static final int _NUM_OP = 48;
    public static final int OP_WIFI_CHANGE = 48;
    /** @hide */
    public static final int _NUM_OP = 49;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION =
@@ -324,6 +326,8 @@ public class AppOpsManager {
            "android:toast_window";
    private static final String OPSTR_PROJECT_MEDIA =
            "android:project_media";
    private static final String OPSTR_WIFI_CHANGE =
            "android:wifi_change";

    /**
     * This maps each operation to the operation that serves as the
@@ -382,6 +386,7 @@ public class AppOpsManager {
            OP_TOAST_WINDOW,
            OP_PROJECT_MEDIA,
            OP_ACTIVATE_VPN,
            OP_WIFI_CHANGE,
    };

    /**
@@ -437,6 +442,7 @@ public class AppOpsManager {
            null,
            null,
            OPSTR_ACTIVATE_VPN,
            null,
    };

    /**
@@ -492,6 +498,7 @@ public class AppOpsManager {
        OPSTR_TOAST_WINDOW,
        OPSTR_PROJECT_MEDIA,
        OPSTR_ACTIVATE_VPN,
        OPSTR_WIFI_CHANGE,
    };

    /**
@@ -547,6 +554,7 @@ public class AppOpsManager {
            "TOAST_WINDOW",
            "PROJECT_MEDIA",
            "ACTIVATE_VPN",
            "WIFI_CHANGE",
    };

    /**
@@ -602,6 +610,7 @@ public class AppOpsManager {
            null, // no permission for displaying toasts
            null, // no permission for projecting media
            null, // no permission for activating vpn
            android.Manifest.permission.CHANGE_WIFI_STATE,
    };

    /**
@@ -658,6 +667,7 @@ public class AppOpsManager {
            UserManager.DISALLOW_CREATE_WINDOWS, // TOAST_WINDOW
            null, //PROJECT_MEDIA
            UserManager.DISALLOW_CONFIG_VPN, // ACTIVATE_VPN
            null, //WIFI_CHANGE
    };

    /**
@@ -713,6 +723,7 @@ public class AppOpsManager {
            true, //TOAST_WINDOW
            false, //PROJECT_MEDIA
            false, //ACTIVATE_VPN
            false, // WIFI_CHANGE
    };

    /**
@@ -767,6 +778,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_IGNORED, // OP_PROJECT_MEDIA
            AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
            AppOpsManager.MODE_ALLOWED,
    };

    /**
@@ -822,6 +834,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED, // OP_TOAST_WINDOW
            AppOpsManager.MODE_IGNORED, // OP_PROJECT_MEDIA
            AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
            AppOpsManager.MODE_ASK,     // OP_WIFI_CHANGE
    };

    /**
@@ -876,6 +889,7 @@ public class AppOpsManager {
        false,    // OP_TOAST_WINDOW
        false,    // OP_PROJECT_MEDIA
        false,    // OP_ACTIVATE_VPN
        true,     // OP_WIFI_CHANGE
    };

    /**
@@ -934,6 +948,7 @@ public class AppOpsManager {
            false,
            false,
            false,
            false,     // OP_WIFI_CHANGE
    };

    private static HashMap<String, Integer> sOpStrToOp = new HashMap<String, Integer>();
+1 −0
Original line number Diff line number Diff line
@@ -1951,5 +1951,6 @@
        <item>Trying to toast window</item>
        <item>Trying to project media</item>
        <item>Trying to activate vpn</item>
        <item>Trying to turn on/off Wifi</item>
    </string-array>
</resources>
+9 −0
Original line number Diff line number Diff line
/*
 * 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.DhcpInfo;
import android.net.wifi.ScanSettings;
@@ -558,6 +562,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.
@@ -573,6 +578,7 @@ public class WifiManager {
        mContext = context;
        mService = service;
        init();
        mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
    }

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