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

Commit 427bae3b authored by Ling Ma's avatar Ling Ma
Browse files

Listen to DDS change to update isDataEnabled

Test: manually reproduce and verify by log
Test: basic data browsing + voice call
Fix: 353723350
Flag: EXEMPT bugfix
Change-Id: I3fa3a5e5e31a4734407618366090e0e31600a156
parent 5f944509
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -335,6 +335,16 @@ public class DataSettingsManager extends Handler {
                });
            }
        }
        SubscriptionManagerService.getInstance().registerCallback(
                new SubscriptionManagerService.SubscriptionManagerServiceCallback(this::post) {
                    @Override
                    public void onDefaultDataSubscriptionChanged(int subId) {
                        log((subId == mSubId ? "Became" : "Not")
                                + " default data sub, reevaluating mobile data policies");
                        DataSettingsManager.this.updateDataEnabledAndNotify(
                                TelephonyManager.DATA_ENABLED_REASON_OVERRIDE);
                    }
                });
        updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_UNKNOWN);
    }

+44 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.data.DataSettingsManager.DataSettingsManagerCallback;
import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
import com.android.internal.telephony.subscription.SubscriptionManagerService;

import org.junit.After;
import org.junit.Before;
@@ -183,6 +184,49 @@ public class DataSettingsManagerTest extends TelephonyTest {
        verify(mPhone).notifyDataEnabled(true, TelephonyManager.DATA_ENABLED_REASON_OVERRIDE);
    }

    @Test
    public void testUpdateDataEnabledAndNotifyOverrideDdsChange() throws Exception {
        // Mock 2nd phone the DDS phone.
        int phone2Id = 1;
        int phone2SubId = 2;
        doReturn(phone2SubId).when(mSubscriptionManagerService).getDefaultDataSubId();
        Phone phone2 = Mockito.mock(Phone.class);
        doReturn(phone2Id).when(phone2).getPhoneId();
        doReturn(phone2SubId).when(phone2).getSubId();
        doReturn(phone2Id).when(mSubscriptionManagerService).getPhoneId(phone2SubId);
        DataSettingsManager dataSettingsManager2 = Mockito.mock(DataSettingsManager.class);
        doReturn(dataSettingsManager2).when(phone2).getDataSettingsManager();
        doReturn(true).when(phone2).isUserDataEnabled();

        mPhones = new Phone[] {mPhone, phone2};
        replaceInstance(PhoneFactory.class, "sPhones", null, mPhones);
        ArgumentCaptor<SubscriptionManagerService.SubscriptionManagerServiceCallback>
                callbackArgumentCaptor = ArgumentCaptor
                .forClass(SubscriptionManagerService.SubscriptionManagerServiceCallback.class);

        mDataSettingsManagerUT.sendEmptyMessage(11 /* EVENT_INITIALIZE */);
        mDataSettingsManagerUT.setDataEnabled(TelephonyManager.DATA_ENABLED_REASON_USER, false, "");
        processAllMessages();

        // Verify listening to DDS change callback
        verify(mSubscriptionManagerService, times(2))
                .registerCallback(callbackArgumentCaptor.capture());
        SubscriptionManagerService.SubscriptionManagerServiceCallback callback =
                callbackArgumentCaptor.getValue();

        // Mock the phone as nonDDS auto switch override enabled.
        clearInvocations(mPhones);
        mDataSettingsManagerUT.setMobileDataPolicy(
                TelephonyManager.MOBILE_DATA_POLICY_AUTO_DATA_SWITCH, true);
        processAllMessages();
        verify(mPhone).notifyDataEnabled(true, TelephonyManager.DATA_ENABLED_REASON_OVERRIDE);

        // The phone became DDS, data should be disabled
        doReturn(mPhone.getSubId()).when(mSubscriptionManagerService).getDefaultDataSubId();
        callback.onDefaultDataSubscriptionChanged(mPhone.getSubId());
        verify(mPhone).notifyDataEnabled(false, TelephonyManager.DATA_ENABLED_REASON_OVERRIDE);
    }

    @Test
    public void testNotifyDataEnabledFromNewValidSubId() throws Exception {
        final CountDownLatch latch = new CountDownLatch(1);