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

Commit ad1a04a7 authored by Shashank Mittal's avatar Shashank Mittal Committed by Roman Birg
Browse files

AppOps: Add data connect control into AppOps

Check user permission before enabling/disabling mobile data.

Change-Id: I6e1895b130788dfccbc0a8523dadf1559b698988
parent 58330fdc
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -259,7 +259,9 @@ public class AppOpsManager {
    /** @hide */
    public static final int OP_NFC_CHANGE = 66;
    /** @hide */
    public static final int _NUM_OP = 67;
    public static final int OP_DATA_CONNECT_CHANGE = 67;
    /** @hide */
    public static final int _NUM_OP = 68;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION = "android:coarse_location";
@@ -366,6 +368,8 @@ public class AppOpsManager {
            "android:boot_completed";
    private static final String OPSTR_NFC_CHANGE =
            "android:nfc_change";
    private static final String OPSTR_DATA_CONNECT_CHANGE =
            "android:data_connect_change";

    /**
     * This maps each operation to the operation that serves as the
@@ -443,6 +447,7 @@ public class AppOpsManager {
            OP_BLUETOOTH_CHANGE,
            OP_BOOT_COMPLETED,
            OP_NFC_CHANGE,
            OP_DATA_CONNECT_CHANGE,
    };

    /**
@@ -517,6 +522,7 @@ public class AppOpsManager {
            OPSTR_BLUETOOTH_CHANGE,
            OPSTR_BOOT_COMPLETED,
            OPSTR_NFC_CHANGE,
            OPSTR_DATA_CONNECT_CHANGE,
    };

    /**
@@ -591,6 +597,7 @@ public class AppOpsManager {
            "BLUETOOTH_CHANGE",
            "BOOT_COMPLETED",
            "NFC_CHANGE",
            "DATA_CONNECT_CHANGE",
    };

    /**
@@ -665,6 +672,7 @@ public class AppOpsManager {
            Manifest.permission.BLUETOOTH,
            Manifest.permission.RECEIVE_BOOT_COMPLETED,
            Manifest.permission.NFC,
            Manifest.permission.MODIFY_PHONE_STATE,
    };

    /**
@@ -740,6 +748,7 @@ public class AppOpsManager {
            null, //BLUETOOTH_CHANGE
            null, //BOOT_COMPLETED
            null, //NFC_CHANGE
            null, //DATA_CONNECT_CHANGE
    };

    /**
@@ -814,6 +823,7 @@ public class AppOpsManager {
            false, // BLUETOOTH_CHANGE
            false, // BOOT_COMPLETED
            false, // NFC_CHANGE
            false, //DATA_CONNECT_CHANGE
    };

    /**
@@ -887,6 +897,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ASK,     // OP_BLUETOOTH_CHANGE
            AppOpsManager.MODE_ALLOWED, // OP_BOOT_COMPLETED
            AppOpsManager.MODE_ALLOWED, // OP_NFC_CHANGE
            AppOpsManager.MODE_ALLOWED,
    };

    /**
@@ -961,6 +972,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ASK,     // OP_BLUETOOTH_CHANGE
            AppOpsManager.MODE_ALLOWED, // OP_BOOT_COMPLETED
            AppOpsManager.MODE_ASK,     // OP_NFC_CHANGE
            AppOpsManager.MODE_ASK,     // OP_DATA_CONNECT_CHANGE
    };

    /**
@@ -1034,6 +1046,7 @@ public class AppOpsManager {
        true,     // OP_BLUETOOTH_CHANGE
        false,    // OP_BOOT_COMPLETED
        true,     // OP_NFC_CHANGE
        true,     // OP_DATA_CONNECT_CHANGE
    };

    /**
@@ -1111,6 +1124,7 @@ public class AppOpsManager {
            false,     // OP_BLUETOOTH_CHANGE
            false,     // OP_BOOT_COMPLETED
            false,     // OP_NFC_CHANGE
            false,     // OP_DATA_CONNECT_CHANGE
    };

    /**
+1 −0
Original line number Diff line number Diff line
@@ -88,5 +88,6 @@
        <item>Trying to trun on/off Bluetooth</item>
        <item>Trying to start at bootup</item>
        <item>Trying to turn on/off NFC</item>
        <item>Trying to turn on mobile data</item>
    </string-array>
</resources>
+12 −1
Original line number Diff line number Diff line
/*
 * Copyright (c) 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");
@@ -23,6 +26,7 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.ActivityThread;
import android.content.ContentResolver;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
@@ -4239,11 +4243,18 @@ public class TelephonyManager {
    public void setDataEnabled(int subId, boolean enable) {
        try {
            Log.d(TAG, "setDataEnabled: enabled=" + enable);
            AppOpsManager appOps = (AppOpsManager)mContext.getSystemService(Context.APP_OPS_SERVICE);
            if (enable) {
                if (appOps.noteOp(AppOpsManager.OP_DATA_CONNECT_CHANGE) != AppOpsManager.MODE_ALLOWED) {
                    Log.w(TAG, "Permission denied by user.");
                    return;
                }
            }
            ITelephony telephony = getITelephony();
            if (telephony != null)
                telephony.setDataEnabled(subId, enable);
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelephony#setDataEnabled", e);
            Log.e(TAG, "Error calling setDataEnabled", e);
        }
    }