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

Commit 26f46f63 authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by Android (Google) Code Review
Browse files

Merge "Add PhoneStateListener#onPreferredDataSubIdChanged"

parents 31dd6c98 26063714
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -2310,7 +2310,7 @@ public class SubscriptionController extends ISub.Stub {
            if (mPreferredDataSubId != subId) {
                mPreferredDataSubId = subId;
                PhoneSwitcher.getInstance().setPreferredData(subId);
                //TODO: notifyPreferredDataSubIdChanged();
                notifyPreferredDataSubIdChanged();
            }

            return 0;
@@ -2319,6 +2319,17 @@ public class SubscriptionController extends ISub.Stub {
        }
    }

    private void notifyPreferredDataSubIdChanged() {
        ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
                "telephony.registry"));
        try {
            if (DBG) logd("notifyPreferredDataSubIdChanged:");
            tr.notifyPreferredDataSubIdChanged(mPreferredDataSubId);
        } catch (RemoteException ex) {
            // Should never happen because its always available.
        }
    }

    @Override
    public List<SubscriptionInfo> getOpportunisticSubscriptions(int slotId, String callingPackage) {
        return getSubscriptionInfoListFromCacheHelper(
+28 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.internal.telephony;

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

import static org.junit.Assert.assertEquals;

@@ -38,6 +39,7 @@ public class TelephonyRegistryTest extends TelephonyTest {
    private PhoneStateListener mPhoneStateListener;
    private TelephonyRegistry mTelephonyRegistry;
    private PhoneCapability mPhoneCapability;
    private int mPreferredSubId;

    public class PhoneStateListenerWrapper extends PhoneStateListener {
        @Override
@@ -45,6 +47,11 @@ public class TelephonyRegistryTest extends TelephonyTest {
            mPhoneCapability = capability;
            setReady(true);
        }
        @Override
        public void onPreferredDataSubIdChanged(int preferredSubId) {
            mPreferredSubId = preferredSubId;
            setReady(true);
        }
    }

    private void addTelephonyRegistryService() {
@@ -97,4 +104,25 @@ public class TelephonyRegistryTest extends TelephonyTest {
        waitUntilReady();
        assertEquals(phoneCapability, mPhoneCapability);
    }


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

        // notifyPhoneCapabilityChanged with a new capability. Callback should be triggered.
        setReady(false);
        mPreferredSubId = 1;
        mTelephonyRegistry.notifyPreferredDataSubIdChanged(preferredSubId);
        waitUntilReady();
        assertEquals(preferredSubId, mPreferredSubId);
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -412,4 +412,9 @@ public class TelephonyRegistryMock extends ITelephonyRegistry.Stub {
    public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
        throw new RuntimeException("Not implemented");
    }

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