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

Commit ff54af16 authored by Ling Ma's avatar Ling Ma
Browse files

Use onUserDataEnabledChanged to set DDS

With the introduction of auto data switch, onUserDataEnabledChanged no longer necessarily triggers onDataEnabledChanged, so listen to onUserDataEnabledChanged instead in order to always get the user data enabled change event.

Fix: 287567971
Test: manual reproduce and verify
Change-Id: I79fccc1fa2677e755a3987d93599ad7ca2b29067
parent ced77ee0
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -163,15 +163,13 @@ public class MultiSimSettingController extends Handler {
        }

        @Override
        public void onDataEnabledChanged(boolean enabled,
                @TelephonyManager.DataEnabledChangedReason int reason, String callingPackage) {
        public void onUserDataEnabledChanged(boolean enabled, @NonNull String callingPackage) {
            int subId = mPhone.getSubId();
            // notifyUserDataEnabled if the change is called from external and reason is
            // DATA_ENABLED_REASON_USER
            // only notifyUserDataEnabled if the change is called from external to avoid
            // setUserDataEnabledForGroup infinite loop
            if (SubscriptionManager.isValidSubscriptionId(subId)
                    && reason == TelephonyManager.DATA_ENABLED_REASON_USER
                    && !getInstance().mContext.getOpPackageName().equals(callingPackage)) {
                getInstance().notifyUserDataEnabled(mPhone.getSubId(), enabled);
                getInstance().notifyUserDataEnabled(subId, enabled);
            }
        }

+7 −4
Original line number Diff line number Diff line
@@ -134,8 +134,9 @@ public class DataSettingsManager extends Handler {
         * Called when user data enabled state changed.
         *
         * @param enabled {@code true} indicates user mobile data is enabled.
         * @param callingPackage The package that changed the data enabled state.
         */
        public void onUserDataEnabledChanged(boolean enabled) {}
        public void onUserDataEnabledChanged(boolean enabled, @NonNull String callingPackage) {}

        /**
         * Called when overall data enabled state changed.
@@ -305,9 +306,11 @@ public class DataSettingsManager extends Handler {
                phone.getDataSettingsManager().registerCallback(new DataSettingsManagerCallback(
                        this::post) {
                    @Override
                    public void onUserDataEnabledChanged(boolean enabled) {
                    public void onUserDataEnabledChanged(boolean enabled,
                            @NonNull String callingPackage) {
                        log("phone" + phone.getPhoneId() + " onUserDataEnabledChanged "
                                + enabled + ", reevaluating mobile data policies");
                                + enabled + " by " + callingPackage
                                + ", reevaluating mobile data policies");
                        DataSettingsManager.this.updateDataEnabledAndNotify(
                                TelephonyManager.DATA_ENABLED_REASON_OVERRIDE);
                    }
@@ -442,7 +445,7 @@ public class DataSettingsManager extends Handler {
            logl("UserDataEnabled changed to " + enabled);
            mPhone.notifyUserMobileDataStateChanged(enabled);
            mDataSettingsManagerCallbacks.forEach(callback -> callback.invokeFromExecutor(
                    () -> callback.onUserDataEnabledChanged(enabled)));
                    () -> callback.onUserDataEnabledChanged(enabled, callingPackage)));
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_USER,
                    callingPackage, false);
        }
+17 −2
Original line number Diff line number Diff line
@@ -1641,13 +1641,27 @@ public class DataNetworkControllerTest extends TelephonyTest {
        doReturn(true).when(controller).isCarrierConfigLoadedForAllSub();
        replaceInstance(MultiSimSettingController.class, "sInstance", null, controller);

        // Mock Data Overall data is always enabled due to auto data switch,
        // verify the test shouldn't rely on the overall data status
        doReturn(1).when(mPhone).getSubId();
        doReturn(2).when(mSubscriptionManagerService).getDefaultDataSubId();
        Phone phone2 = Mockito.mock(Phone.class);
        phone2.mCi = mSimulatedCommands;
        doReturn(true).when(phone2).isUserDataEnabled();
        doReturn(mDataSettingsManager).when(phone2).getDataSettingsManager();
        replaceInstance(PhoneFactory.class, "sPhones", null, new Phone[]{mPhone, phone2});
        mDataNetworkControllerUT.getDataSettingsManager().setMobileDataPolicy(TelephonyManager
                .MOBILE_DATA_POLICY_AUTO_DATA_SWITCH, true);
        processAllMessages();
        clearInvocations(mPhone);

        controller.notifyAllSubscriptionLoaded();
        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
                TelephonyManager.DATA_ENABLED_REASON_USER, !isDataEnabled,
                mContext.getOpPackageName());
        processAllMessages();

        // Verify not to notify MultiSimSettingController
        // Verify not to notify MultiSimSettingController due to internal calling package
        verify(controller, never()).notifyUserDataEnabled(anyInt(), anyBoolean());

        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
@@ -1655,7 +1669,7 @@ public class DataNetworkControllerTest extends TelephonyTest {
                mContext.getOpPackageName());
        processAllMessages();

        // Verify not to notify MultiSimSettingController
        // Verify not to notify MultiSimSettingController due to internal calling package
        verify(controller, never()).notifyUserDataEnabled(anyInt(), anyBoolean());

        mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled(
@@ -1666,6 +1680,7 @@ public class DataNetworkControllerTest extends TelephonyTest {

        // Verify to notify MultiSimSettingController exactly 2 times
        verify(controller, times(2)).notifyUserDataEnabled(anyInt(), anyBoolean());
        verify(mPhone, never()).notifyDataEnabled(anyBoolean(), anyInt());
    }

    @Test
+1 −1
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ public class DataSettingsManagerTest extends TelephonyTest {

        // Verify the override takes effect upon DDS user enabled.
        doReturn(true).when(phone2).isUserDataEnabled();
        callback.onUserDataEnabledChanged(true);
        callback.onUserDataEnabledChanged(true, "callingPackage");
        verify(mPhone).notifyDataEnabled(true, TelephonyManager.DATA_ENABLED_REASON_OVERRIDE);
    }