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

Commit 97085f46 authored by Shashank Mittal's avatar Shashank Mittal Committed by Linux Build Service Account
Browse files

AppOps: Add data connect control into AppOps

Check user permission before enabling/disabling mobile data.

Change-Id: I6e1895b130788dfccbc0a8523dadf1559b698988
parent 596f14a1
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -241,7 +241,9 @@ public class AppOpsManager {
    /** @hide */
    public static final int OP_DELETE_CALL_LOG = 58;
    /** @hide */
    public static final int _NUM_OP = 59;
    public static final int OP_DATA_CONNECT_CHANGE = 59;
    /** @hide */
    public static final int _NUM_OP = 60;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION =
@@ -368,6 +370,8 @@ public class AppOpsManager {
            "android:delete_contacts";
    private static final String OPSTR_DELETE_CALL_LOG =
            "android:delete_call_log";
    private static final String OPSTR_DATA_CONNECT_CHANGE =
            "android:data_connect_change";

    /**
     * This maps each operation to the operation that serves as the
@@ -437,6 +441,7 @@ public class AppOpsManager {
            OP_DELETE_MMS,
            OP_DELETE_CONTACTS,
            OP_DELETE_CALL_LOG,
            OP_DATA_CONNECT_CHANGE,
    };

    /**
@@ -503,6 +508,7 @@ public class AppOpsManager {
            null,
            null,
            null,
            null,
    };

    /**
@@ -569,6 +575,7 @@ public class AppOpsManager {
        OPSTR_DELETE_MMS,
        OPSTR_DELETE_CONTACTS,
        OPSTR_DELETE_CALL_LOG,
        OPSTR_DATA_CONNECT_CHANGE,
    };

    /**
@@ -635,6 +642,7 @@ public class AppOpsManager {
            "DELETE_MMS",
            "DELETE_CONTACTS",
            "DELETE_CALL_LOG",
            "DATA_CONNECT_CHANGE",
    };

    /**
@@ -701,6 +709,7 @@ public class AppOpsManager {
            android.Manifest.permission.WRITE_SMS,
            android.Manifest.permission.WRITE_CONTACTS,
            android.Manifest.permission.WRITE_CALL_LOG,
            android.Manifest.permission.MODIFY_PHONE_STATE,
    };

    /**
@@ -768,6 +777,7 @@ public class AppOpsManager {
            null, //DELETE_MMS
            null, //DELETE_CONTACTS
            null, //DELETE_CALL_LOG
            null, //DATA_CONNECT_CHANGE
    };

    /**
@@ -834,6 +844,7 @@ public class AppOpsManager {
            false, //DELETE_MMS
            false, //DELETE_CONTACTS
            false, //DELETE_CALL_LOG
            false, //DATA_CONNECT_CHANGE
    };

    /**
@@ -899,6 +910,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_ALLOWED,
    };

    /**
@@ -965,6 +977,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ASK,     // OP_DELETE_MMS
            AppOpsManager.MODE_ASK,     // OP_DELETE_CONTACTS
            AppOpsManager.MODE_ASK,     // OP_DELETE_CALL_LOG
            AppOpsManager.MODE_ASK,     // OP_DATA_CONNECT_CHANGE
    };

    /**
@@ -1030,6 +1043,7 @@ public class AppOpsManager {
        true,     // OP_DELETE_MMS
        true,     // OP_DELETE_CONTACTS
        true,     // OP_DELETE_CALL_LOG
        true,     // OP_DATA_CONNECT_CHANGE
    };

    /**
@@ -1099,6 +1113,7 @@ public class AppOpsManager {
            false,     // OP_DELETE_MMS
            false,     // OP_DELETE_CONTACTS
            false,     // OP_DELETE_CALL_LOG
            false,     // OP_DATA_CONNECT_CHANGE
    };

    private static HashMap<String, Integer> sOpStrToOp = new HashMap<String, Integer>();
+1 −0
Original line number Diff line number Diff line
@@ -1965,5 +1965,6 @@
        <item>Trying to delete MMS</item>
        <item>Trying to delete contacts</item>
        <item>Trying to delete call log</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");
@@ -19,6 +22,7 @@ package android.telephony;
import android.annotation.SystemApi;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -3415,9 +3419,16 @@ public class TelephonyManager {
    @SystemApi
    public void setDataEnabledUsingSubId(long subId, boolean enable) {
        try {
            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;
                }
            }
            getITelephony().setDataEnabledUsingSubId(subId, enable);
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelephony#setDataEnabled", e);
            Log.e(TAG, "Error calling setDataEnabled", e);
        }
    }