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

Commit 347acbe4 authored by Kun Liang's avatar Kun Liang Committed by Sam Mortimer
Browse files

AppOps: Add data connect control into AppOps

Check user permission before enabling/disabling mobile data.

Change-Id: I6e1895b130788dfccbc0a8523dadf1559b698988
parent f7676eb8
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -103,7 +103,8 @@ public class AppOpsManager {
    /** @hide */
    public static final int OP_WIFI_CHANGE = 31;
    public static final int OP_BLUETOOTH_CHANGE = 32;
    public static final int _NUM_OP = 33;
    public static final int OP_DATA_CONNECT_CHANGE = 33;
    public static final int _NUM_OP = 34;

    /**
     * Map to check if each operation is strict or not, to determine default
@@ -145,6 +146,7 @@ public class AppOpsManager {
        false,  //OP_WRITE_CLIPBOARD
        true,   //OP_WIFI_CHANGE
        true,   //OP_BLUETOOTH_CHANGE
        true,   //OP_DATA_CONNECT_CHANGE
    };

    /**
@@ -189,6 +191,7 @@ public class AppOpsManager {
            OP_WRITE_CLIPBOARD,
            OP_WIFI_CHANGE,
            OP_BLUETOOTH_CHANGE,
            OP_DATA_CONNECT_CHANGE,
    };

    /**
@@ -229,6 +232,7 @@ public class AppOpsManager {
            "WRITE_CLIPBOARD",
            "WIFI_CHANGE",
            "BLUETOOTH_CHANGE",
            "DATA_CONNECT_CHANGE",
    };

    /**
@@ -269,6 +273,7 @@ public class AppOpsManager {
            null, // no permission for writing clipboard
            android.Manifest.permission.CHANGE_WIFI_STATE,
            android.Manifest.permission.BLUETOOTH,
            android.Manifest.permission.CHANGE_NETWORK_STATE,
    };

    /**
+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;
@@ -849,7 +850,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
@@ -72,7 +72,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
@@ -87,5 +87,6 @@
        <item>Trying to modify clipboard</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>
+9 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static android.net.ConnectivityManager.isNetworkTypeValid;
import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;

import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -1716,10 +1717,17 @@ 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));
    }