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

Commit 10af37eb authored by Shashank Mittal's avatar Shashank Mittal Committed by Sam Mortimer
Browse files

wifi: Confirm user permission before toggling wifi.

Check user permissions before enabling/disabling wifi.

Change-Id: I1ddae6e47f42b6d3fc831c2c135ece75cf9e935d
parent 6a12d12f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public class WifiCommand extends Svc.Command {
                IWifiManager wifiMgr
                        = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
                try {
                    wifiMgr.setWifiEnabled(flag);
                    wifiMgr.setWifiEnabled("com.android.commands.svc", flag);
                }
                catch (RemoteException e) {
                    System.err.println("Wi-Fi operation failed: " + e);
+6 −1
Original line number Diff line number Diff line
@@ -101,7 +101,8 @@ public class AppOpsManager {
    public static final int OP_READ_CLIPBOARD = 29;
    public static final int OP_WRITE_CLIPBOARD = 30;
    /** @hide */
    public static final int _NUM_OP = 31;
    public static final int OP_WIFI_CHANGE = 31;
    public static final int _NUM_OP = 32;

    /**
     * Map to check if each operation is strict or not, to determine default
@@ -141,6 +142,7 @@ public class AppOpsManager {
        true,   //OP_PLAY_AUDIO
        false,  //OP_READ_CLIPBOARD
        false,  //OP_WRITE_CLIPBOARD
        true,   //OP_WIFI_CHANGE
    };

    /**
@@ -183,6 +185,7 @@ public class AppOpsManager {
            OP_PLAY_AUDIO,
            OP_READ_CLIPBOARD,
            OP_WRITE_CLIPBOARD,
            OP_WIFI_CHANGE,
    };

    /**
@@ -221,6 +224,7 @@ public class AppOpsManager {
            "PLAY_AUDIO",
            "READ_CLIPBOARD",
            "WRITE_CLIPBOARD",
            "WIFI_CHANGE",
    };

    /**
@@ -259,6 +263,7 @@ public class AppOpsManager {
            null, // no permission for playing audio
            null, // no permission for reading clipboard
            null, // no permission for writing clipboard
            android.Manifest.permission.CHANGE_WIFI_STATE,
    };

    /**
+1 −0
Original line number Diff line number Diff line
@@ -85,5 +85,6 @@
        <item>Trying to play audio</item>
        <item>Trying to read clipboard</item>
        <item>Trying to modify clipboard</item>
        <item>Trying to turn on/off Wifi</item>
    </string-array>
</resources>
+8 −2
Original line number Diff line number Diff line
@@ -274,7 +274,7 @@ public final class WifiService extends IWifiManager.Stub {

        // If we are already disabled (could be due to airplane mode), avoid changing persist
        // state here
        if (wifiEnabled) setWifiEnabled(wifiEnabled);
        if (wifiEnabled) setWifiEnabled(mContext.getBasePackageName(), wifiEnabled);

        mWifiWatchdogStateMachine = WifiWatchdogStateMachine.
               makeWifiWatchdogStateMachine(mContext);
@@ -332,8 +332,14 @@ public final class WifiService extends IWifiManager.Stub {
     * @return {@code true} if the enable/disable operation was
     *         started or is already in the queue.
     */
    public synchronized boolean setWifiEnabled(boolean enable) {
    public synchronized boolean setWifiEnabled(String callingPackage, boolean enable) {
        enforceChangePermission();

        int uid = Binder.getCallingUid();
        if (mAppOps.noteOp(AppOpsManager.OP_WIFI_CHANGE, uid, callingPackage)
            != AppOpsManager.MODE_ALLOWED)
            return false;

        Slog.d(TAG, "setWifiEnabled: " + enable + " pid=" + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid());
        if (DBG) {
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ interface IWifiManager

    WifiInfo getConnectionInfo();

    boolean setWifiEnabled(boolean enable);
    boolean setWifiEnabled(String callingPackage, boolean enable);

    int getWifiEnabledState();

Loading