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

Commit 7f101873 authored by Nazanin Bakhshi's avatar Nazanin Bakhshi Committed by android-build-merger
Browse files

Merge "Notify activeDataSubIdChanged when data switches."

am: cf40db40

Change-Id: Id8d6022f0ad01a3ed6aa08746cd18ded4e73b2e2
parents e4f8f434 cf40db40
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -599,6 +599,10 @@ public class PhoneSwitcher extends Handler {
                    activate(phoneId);
                }
            }

            notifyActiveDataSubIdChanged(mSubscriptionController.getSubIdUsingPhoneId(
                    mPreferredDataPhoneId));

            // Notify all registrants.
            mActivePhoneRegistrants.notifyRegistrants();
        }
@@ -859,7 +863,6 @@ public class PhoneSwitcher extends Handler {
            logDataSwitchEvent(TelephonyEvent.EventState.EVENT_STATE_START,
                    DataSwitch.Reason.DATA_SWITCH_REASON_CBRS);
            onEvaluate(REQUESTS_UNCHANGED, "preferredDataSubscriptionIdChanged");
            notifyPreferredDataSubIdChanged();
            registerDefaultNetworkChangeCallback();
        }
    }
@@ -884,16 +887,6 @@ public class PhoneSwitcher extends Handler {
                subId, needValidation ? 1 : 0, callback).sendToTarget();
    }

    private void notifyPreferredDataSubIdChanged() {
        ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
                "telephony.registry"));
        try {
            tr.notifyPreferredDataSubIdChanged(mPreferredDataSubId);
        } catch (RemoteException ex) {
            // Should never happen because TelephonyRegistry service should always be available.
        }
    }

    private boolean isCallActive(Phone phone) {
        if (phone == null) {
            return false;
@@ -922,6 +915,18 @@ public class PhoneSwitcher extends Handler {
        dataSwitch.state = state;
        dataSwitch.reason = reason;
        TelephonyMetrics.getInstance().writeDataSwitch(dataSwitch);

    }

    private void notifyActiveDataSubIdChanged(int activeDataSubId) {
        ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
                "telephony.registry"));
        try {
            log("notifyActiveDataSubIdChanged to " + activeDataSubId);
            tr.notifyActiveDataSubIdChanged(activeDataSubId);
        } catch (RemoteException ex) {
            // Should never happen because its always available.
        }
    }

    public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
+7 −1
Original line number Diff line number Diff line
@@ -642,7 +642,13 @@ public class PhoneSwitcherTest extends TelephonyTest {
        doReturn(mDefaultDataSub).when(mSubscriptionController).getDefaultDataSubId();
        doAnswer(invocation -> {
            int phoneId = (int) invocation.getArguments()[0];
            if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
                return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
            } else if (phoneId == SubscriptionManager.DEFAULT_PHONE_INDEX) {
                return mSlotIndexToSubId[0][0];
            } else {
                return mSlotIndexToSubId[phoneId][0];
            }
        }).when(mSubscriptionController).getSubIdUsingPhoneId(anyInt());

        doAnswer(invocation -> {
+12 −12
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@
 */
package com.android.internal.telephony;

import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBID_CHANGE;
import static android.telephony.PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE;
import static android.telephony.PhoneStateListener.LISTEN_PREFERRED_DATA_SUBID_CHANGE;
import static android.telephony.PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED;

import static org.junit.Assert.assertEquals;
@@ -44,7 +44,7 @@ public class TelephonyRegistryTest extends TelephonyTest {
    private PhoneStateListener mPhoneStateListener;
    private TelephonyRegistry mTelephonyRegistry;
    private PhoneCapability mPhoneCapability;
    private int mPreferredSubId;
    private int mActiveSubId;
    private int mSrvccState = -1;

    public class PhoneStateListenerWrapper extends PhoneStateListener {
@@ -60,8 +60,8 @@ public class TelephonyRegistryTest extends TelephonyTest {
            setReady(true);
        }
        @Override
        public void onPreferredDataSubIdChanged(int preferredSubId) {
            mPreferredSubId = preferredSubId;
        public void onActiveDataSubIdChanged(int activeSubId) {
            mActiveSubId = activeSubId;
            setReady(true);
        }
    }
@@ -121,23 +121,23 @@ public class TelephonyRegistryTest extends TelephonyTest {


    @Test @SmallTest
    public void testPreferredDataSubChanged() {
    public void testActiveDataSubChanged() {
        // mTelephonyRegistry.listen with notifyNow = true should trigger callback immediately.
        setReady(false);
        int preferredSubId = 0;
        mTelephonyRegistry.notifyPreferredDataSubIdChanged(preferredSubId);
        int activeSubId = 0;
        mTelephonyRegistry.notifyActiveDataSubIdChanged(activeSubId);
        mTelephonyRegistry.listen(mContext.getOpPackageName(),
                mPhoneStateListener.callback,
                LISTEN_PREFERRED_DATA_SUBID_CHANGE, true);
                LISTEN_ACTIVE_DATA_SUBID_CHANGE, true);
        waitUntilReady();
        assertEquals(preferredSubId, mPreferredSubId);
        assertEquals(activeSubId, mActiveSubId);

        // notifyPhoneCapabilityChanged with a new capability. Callback should be triggered.
        setReady(false);
        mPreferredSubId = 1;
        mTelephonyRegistry.notifyPreferredDataSubIdChanged(preferredSubId);
        mActiveSubId = 1;
        mTelephonyRegistry.notifyActiveDataSubIdChanged(activeSubId);
        waitUntilReady();
        assertEquals(preferredSubId, mPreferredSubId);
        assertEquals(activeSubId, mActiveSubId);
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -427,12 +427,12 @@ public class TelephonyRegistryMock extends ITelephonyRegistry.Stub {
    }

    @Override
    public void notifyRadioPowerStateChanged(int state) {
    public void notifyActiveDataSubIdChanged(int subId) {
        throw new RuntimeException("Not implemented");
    }

    @Override
    public void notifyPreferredDataSubIdChanged(int subId) {
    public void notifyRadioPowerStateChanged(int state) {
        throw new RuntimeException("Not implemented");
    }