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

Commit e19b4979 authored by Sarah Chin's avatar Sarah Chin Committed by Jack Yu
Browse files

SetDataEnabled indicate calling package

Test: atest TelephonyManagerTest, DataNetworkControllerTest
Bug: 226149142
Merged-In: Iaaa1759c06bcd1ea106c5d5f69f61282466e98d4
Change-Id: Iaaa1759c06bcd1ea106c5d5f69f61282466e98d4
parent 5701e772
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -3266,7 +3266,8 @@ public class GsmCdmaPhone extends Phone {
                boolean enabled = (boolean) ar.result;
                if (isUsingNewDataStack()) {
                    getDataSettingsManager().setDataEnabled(
                            TelephonyManager.DATA_ENABLED_REASON_CARRIER, enabled);
                            TelephonyManager.DATA_ENABLED_REASON_CARRIER, enabled,
                            mContext.getOpPackageName());
                    return;
                }
                mDataEnabledSettings.setDataEnabled(TelephonyManager.DATA_ENABLED_REASON_CARRIER,
+4 −2
Original line number Diff line number Diff line
@@ -792,7 +792,8 @@ public class MultiSimSettingController extends Handler {
                log("setting data to false on " + phone.getSubId());
                if (phone.isUsingNewDataStack()) {
                    phone.getDataSettingsManager().setDataEnabled(
                            TelephonyManager.DATA_ENABLED_REASON_USER, false);
                            TelephonyManager.DATA_ENABLED_REASON_USER, false,
                            mContext.getOpPackageName());
                } else {
                    phone.getDataEnabledSettings().setDataEnabled(
                            TelephonyManager.DATA_ENABLED_REASON_USER, false);
@@ -834,7 +835,8 @@ public class MultiSimSettingController extends Handler {
                if (phone != null) {
                    if (phone.isUsingNewDataStack()) {
                        phone.getDataSettingsManager().setDataEnabled(
                                TelephonyManager.DATA_ENABLED_REASON_USER, enable);
                                TelephonyManager.DATA_ENABLED_REASON_USER, enable,
                                mContext.getOpPackageName());
                    } else {
                        phone.getDataEnabledSettings().setUserDataEnabled(enable, false);
                    }
+23 −14
Original line number Diff line number Diff line
@@ -189,19 +189,20 @@ public class DataSettingsManager extends Handler {
                break;
            }
            case EVENT_SET_DATA_ENABLED_FOR_REASON: {
                String callingPackage = (String) msg.obj;
                boolean enabled = msg.arg2 == 1;
                switch (msg.arg1) {
                    case TelephonyManager.DATA_ENABLED_REASON_USER:
                        setUserDataEnabled(enabled);
                        setUserDataEnabled(enabled, callingPackage);
                        break;
                    case TelephonyManager.DATA_ENABLED_REASON_CARRIER:
                        setCarrierDataEnabled(enabled);
                        setCarrierDataEnabled(enabled, callingPackage);
                        break;
                    case TelephonyManager.DATA_ENABLED_REASON_POLICY:
                        setPolicyDataEnabled(enabled);
                        setPolicyDataEnabled(enabled, callingPackage);
                        break;
                    case TelephonyManager.DATA_ENABLED_REASON_THERMAL:
                        setThermalDataEnabled(enabled);
                        setThermalDataEnabled(enabled, callingPackage);
                        break;
                    default:
                        log("Cannot set data enabled for reason: "
@@ -303,9 +304,12 @@ public class DataSettingsManager extends Handler {
     * Enable or disable data for a specific {@link TelephonyManager.DataEnabledReason}.
     * @param reason The reason the data enabled change is taking place.
     * @param enabled {@code true} to enable data for the given reason and {@code false} to disable.
     * @param callingPackage The package that changed the data enabled state.
     */
    public void setDataEnabled(@TelephonyManager.DataEnabledReason int reason, boolean enabled) {
        obtainMessage(EVENT_SET_DATA_ENABLED_FOR_REASON, reason, enabled ? 1 : 0).sendToTarget();
    public void setDataEnabled(@TelephonyManager.DataEnabledReason int reason, boolean enabled,
            String callingPackage) {
        obtainMessage(EVENT_SET_DATA_ENABLED_FOR_REASON, reason, enabled ? 1 : 0, callingPackage)
                .sendToTarget();
    }

    /**
@@ -402,13 +406,15 @@ public class DataSettingsManager extends Handler {
    /**
     * Enable or disable user data.
     * @param enabled {@code true} to enable user data and {@code false} to disable.
     * @param callingPackage The package that changed the data enabled state.
     */
    private void setUserDataEnabled(boolean enabled) {
    private void setUserDataEnabled(boolean enabled, String callingPackage) {
        // Can't disable data for stand alone opportunistic subscription.
        if (isStandAloneOpportunistic(mSubId, mPhone.getContext()) && !enabled) return;
        boolean changed = GlobalSettingsHelper.setInt(mPhone.getContext(),
                Settings.Global.MOBILE_DATA, mSubId, (enabled ? 1 : 0));
        log("Set user data enabled to " + enabled + ", changed=" + changed);
        log("Set user data enabled to " + enabled + ", changed=" + changed + ", callingPackage="
                + callingPackage);
        if (changed) {
            logl("UserDataEnabled changed to " + enabled);
            mPhone.notifyUserMobileDataStateChanged(enabled);
@@ -441,10 +447,11 @@ public class DataSettingsManager extends Handler {
    /**
     * Enable or disable policy data.
     * @param enabled {@code true} to enable policy data and {@code false} to disable.
     * @param callingPackage The package that changed the data enabled state.
     */
    private void setPolicyDataEnabled(boolean enabled) {
    private void setPolicyDataEnabled(boolean enabled, String callingPackage) {
        if (mDataEnabledSettings.get(TelephonyManager.DATA_ENABLED_REASON_POLICY) != enabled) {
            logl("PolicyDataEnabled changed to " + enabled);
            logl("PolicyDataEnabled changed to " + enabled + ", callingPackage=" + callingPackage);
            mDataEnabledSettings.put(TelephonyManager.DATA_ENABLED_REASON_POLICY, enabled);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_POLICY);
        }
@@ -453,10 +460,11 @@ public class DataSettingsManager extends Handler {
    /**
     * Enable or disable carrier data.
     * @param enabled {@code true} to enable carrier data and {@code false} to disable.
     * @param callingPackage The package that changed the data enabled state.
     */
    private void setCarrierDataEnabled(boolean enabled) {
    private void setCarrierDataEnabled(boolean enabled, String callingPackage) {
        if (mDataEnabledSettings.get(TelephonyManager.DATA_ENABLED_REASON_CARRIER) != enabled) {
            logl("CarrierDataEnabled changed to " + enabled);
            logl("CarrierDataEnabled changed to " + enabled + ", callingPackage=" + callingPackage);
            mDataEnabledSettings.put(TelephonyManager.DATA_ENABLED_REASON_CARRIER, enabled);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_CARRIER);
        }
@@ -465,10 +473,11 @@ public class DataSettingsManager extends Handler {
    /**
     * Enable or disable thermal data.
     * @param enabled {@code true} to enable thermal data and {@code false} to disable.
     * @param callingPackage The package that changed the data enabled state.
     */
    private void setThermalDataEnabled(boolean enabled) {
    private void setThermalDataEnabled(boolean enabled, String callingPackage) {
        if (mDataEnabledSettings.get(TelephonyManager.DATA_ENABLED_REASON_THERMAL) != enabled) {
            logl("ThermalDataEnabled changed to " + enabled);
            logl("ThermalDataEnabled changed to " + enabled + ", callingPackage=" + callingPackage);
            mDataEnabledSettings.put(TelephonyManager.DATA_ENABLED_REASON_THERMAL, enabled);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_THERMAL);
        }
+12 −12
Original line number Diff line number Diff line
@@ -1058,7 +1058,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
    @Test
    public void testDataEnabledChanged() throws Exception {
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_INTERNET));
        processAllMessages();
@@ -1069,7 +1069,7 @@ public class DataNetworkControllerTest extends TelephonyTest {

        // User data enabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, true);
                TelephonyManager.DATA_ENABLED_REASON_USER, true, mContext.getOpPackageName());
        processAllMessages();

        // Verify data is restored.
@@ -1078,7 +1078,7 @@ public class DataNetworkControllerTest extends TelephonyTest {

        // User data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        processAllMessages();

        // Verify data is torn down.
@@ -1089,7 +1089,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
    public void testMmsAlwaysAllowedDataDisabled() throws Exception {
        // Data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        // Always allow MMS
        mDataNetworkControllerUT.getDataSettingsManager().setAlwaysAllowMmsData(true);
        processAllMessages();
@@ -1134,7 +1134,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                .getPreferredTransportByNetworkCapability(anyInt());
        // Data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_INTERNET));
        processAllMessages();
@@ -1191,7 +1191,7 @@ public class DataNetworkControllerTest extends TelephonyTest {

        // Data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());

        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_MMS));
@@ -1206,7 +1206,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
    public void testEmergencyRequest() throws Exception {
        // Data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        mDataNetworkControllerUT.addNetworkRequest(
                createNetworkRequest(NetworkCapabilities.NET_CAPABILITY_EIMS));
        processAllMessages();
@@ -1756,7 +1756,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
    public void testDataDisableNotTearingDownUnmetered() throws Exception {
        // User data enabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, true);
                TelephonyManager.DATA_ENABLED_REASON_USER, true, mContext.getOpPackageName());
        processAllMessages();

        testSetupImsDataNetwork();
@@ -1764,7 +1764,7 @@ public class DataNetworkControllerTest extends TelephonyTest {

        // User data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        processAllMessages();

        // There shouldn't be all data disconnected event.
@@ -1908,7 +1908,7 @@ public class DataNetworkControllerTest extends TelephonyTest {

        // User data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        processAllMessages();

        mDataNetworkControllerUT.addNetworkRequest(
@@ -1952,7 +1952,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
    public void testRestrictedNetworkRequestDataDisabled() throws Exception {
        // User data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        processAllMessages();

        // Create a restricted network request.
@@ -2121,7 +2121,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
    public void testEmergencySuplDataDisabled() throws Exception {
        // Data disabled
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, false);
                TelephonyManager.DATA_ENABLED_REASON_USER, false, mContext.getOpPackageName());
        processAllMessages();
        doReturn(true).when(mPhone).isInEmergencyCall();
        mDataNetworkControllerUT.addNetworkRequest(