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

Commit 21b6775d authored by Kun Liang's avatar Kun Liang Committed by Shashank Mittal
Browse files

AppOps: Add data connect control into AppOps

Check user permission before enabling/disabling mobile data.

Change-Id: I6e1895b130788dfccbc0a8523dadf1559b698988
parent 13853bb7
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -199,7 +199,9 @@ public class AppOpsManager {
    /** @hide */
    public static final int OP_BLUETOOTH_CHANGE = 44;
    /** @hide */
    public static final int _NUM_OP = 45;
    public static final int OP_DATA_CONNECT_CHANGE = 45;
    /** @hide */
    public static final int _NUM_OP = 46;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION =
@@ -268,6 +270,7 @@ public class AppOpsManager {
            OP_COARSE_LOCATION,
            OP_WIFI_CHANGE,
            OP_BLUETOOTH_CHANGE,
            OP_DATA_CONNECT_CHANGE,
    };

    /**
@@ -320,6 +323,7 @@ public class AppOpsManager {
            OPSTR_MONITOR_HIGH_POWER_LOCATION,
            null,
            null,
            null,
    };

    /**
@@ -372,6 +376,7 @@ public class AppOpsManager {
            "MONITOR_HIGH_POWER_LOCATION",
            "WIFI_CHANGE",
            "BLUETOOTH_CHANGE",
            "DATA_CONNECT_CHANGE",
    };

    /**
@@ -424,6 +429,7 @@ public class AppOpsManager {
            null, // no permission for high power location monitoring
            android.Manifest.permission.CHANGE_WIFI_STATE,
            android.Manifest.permission.BLUETOOTH,
            android.Manifest.permission.CHANGE_NETWORK_STATE,
    };

    /**
@@ -475,6 +481,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED, // OP_MONITOR_HIGH_POWER_LOCATION
            AppOpsManager.MODE_ALLOWED, // OP_WIFI_CHANGE
            AppOpsManager.MODE_ALLOWED, // OP_BLUETOOTH_CHANGE
            AppOpsManager.MODE_ALLOWED, // OP_DATA_CHANGE
    };

    /**
@@ -526,6 +533,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ASK,     // OP_MONITOR_HIGH_POWER_LOCATION
            AppOpsManager.MODE_ASK,     // OP_WIFI_CHANGE
            AppOpsManager.MODE_ASK,     // OP_BLUETOOTH_CHANGE
            AppOpsManager.MODE_ASK,     // OP_DATA_CHANGE
    };


@@ -582,6 +590,7 @@ public class AppOpsManager {
            false,
            false,
            false,
            false,
    };

    private static HashMap<String, Integer> sOpStrToOp = new HashMap<String, Integer>();
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.internal.util.Preconditions.checkNotNull;

import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.ActivityThread;
import android.content.Context;
import android.os.Binder;
import android.os.Build.VERSION_CODES;
@@ -890,7 +891,7 @@ public class ConnectivityManager {
     */
    public void setMobileDataEnabled(boolean enabled) {
        try {
            mService.setMobileDataEnabled(enabled);
            mService.setMobileDataEnabled(ActivityThread.currentPackageName(), enabled);
        } catch (RemoteException e) {
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ interface IConnectivityManager
    boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress);

    boolean getMobileDataEnabled();
    void setMobileDataEnabled(boolean enabled);
    void setMobileDataEnabled(String callingPackage, boolean enabled);

    /** Policy control over specific {@link NetworkStateTracker}. */
    void setPolicyDataEnable(int networkType, boolean enabled);
+1 −0
Original line number Diff line number Diff line
@@ -1358,5 +1358,6 @@
        <item>Trying to access location</item>
        <item>Trying to turn on/off Wifi</item>
        <item>Trying to turn on/off bluetooth</item>
        <item>Trying to turn on/off mobile data</item>
    </string-array>
</resources>
+8 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;

import android.app.AlarmManager;
import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -1818,10 +1819,16 @@ public class ConnectivityService extends IConnectivityManager.Stub {
    /**
     * @see ConnectivityManager#setMobileDataEnabled(boolean)
     */
    public void setMobileDataEnabled(boolean enabled) {
    public void setMobileDataEnabled(String callingPackage, boolean enabled) {
        enforceChangePermission();
        if (DBG) log("setMobileDataEnabled(" + enabled + ")");

        AppOpsManager appOps = (AppOpsManager)mContext.getSystemService(Context.APP_OPS_SERVICE);
        int callingUid = Binder.getCallingUid();
        if (appOps.noteOp(AppOpsManager.OP_DATA_CONNECT_CHANGE, callingUid, callingPackage) !=
            AppOpsManager.MODE_ALLOWED)
            return;

        mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_MOBILE_DATA,
                (enabled ? ENABLED : DISABLED), 0));
    }