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

Commit baebd832 authored by Ling Ma's avatar Ling Ma Committed by Jack Yu
Browse files

Broadcast subId upon service initialized

Bug: 274346711
Test: verify the broadcast in log
Merged-In: Ifea042359646423e2b4b2a753096d9582651fa43
Change-Id: Ifea042359646423e2b4b2a753096d9582651fa43
parent 311f3743
Loading
Loading
Loading
Loading
+27 −16
Original line number Diff line number Diff line
@@ -509,6 +509,13 @@ public class SubscriptionManagerService extends ISub.Stub {
                    }
                });

        // Broadcast sub Id on service initialized.
        broadcastSubId(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED,
                getDefaultDataSubId());
        broadcastSubId(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED,
                getDefaultVoiceSubId());
        broadcastSubId(SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED,
                getDefaultSmsSubId());
        updateDefaultSubId();

        TelephonyServiceManager.ServiceRegisterer subscriptionServiceRegisterer =
@@ -2681,7 +2688,7 @@ public class SubscriptionManagerService extends ISub.Stub {
            Intent intent = new Intent(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
            SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId, subId);
            mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
            mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
        }
    }

@@ -2753,11 +2760,8 @@ public class SubscriptionManagerService extends ISub.Stub {

                MultiSimSettingController.getInstance().notifyDefaultDataSubChanged();

                Intent intent = new Intent(
                        TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
                intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
                SubscriptionManager.putSubscriptionIdExtra(intent, subId);
                mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
                broadcastSubId(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED,
                        subId);

                updateDefaultSubId();
            }
@@ -2809,11 +2813,8 @@ public class SubscriptionManagerService extends ISub.Stub {
        final long token = Binder.clearCallingIdentity();
        try {
            if (mDefaultVoiceSubId.set(subId)) {
                Intent intent = new Intent(
                        TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED);
                intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
                SubscriptionManager.putSubscriptionIdExtra(intent, subId);
                mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
                broadcastSubId(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED,
                        subId);

                PhoneAccountHandle newHandle = subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
                        ? null : mTelephonyManager.getPhoneAccountHandleForSubscriptionId(subId);
@@ -2858,11 +2859,8 @@ public class SubscriptionManagerService extends ISub.Stub {
        final long token = Binder.clearCallingIdentity();
        try {
            if (mDefaultSmsSubId.set(subId)) {
                Intent intent = new Intent(
                        SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED);
                intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
                SubscriptionManager.putSubscriptionIdExtra(intent, subId);
                mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
                broadcastSubId(SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED,
                        subId);
            }

        } finally {
@@ -2870,6 +2868,19 @@ public class SubscriptionManagerService extends ISub.Stub {
        }
    }

    /**
     * Broadcast a sub Id with the given action.
     * @param action The intent action.
     * @param newSubId The sub Id to broadcast.
     */
    private void broadcastSubId(@NonNull String action, int newSubId) {
        Intent intent = new Intent(action);
        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
        SubscriptionManager.putSubscriptionIdExtra(intent, newSubId);
        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
        log("broadcastSubId action: " + action + " subId= " + newSubId);
    }

    /**
     * Get the active subscription id list.
     *
+18 −3
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
@@ -302,6 +303,17 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        doReturn(mResources).when(mContext).getResources();
    }

    @Test
    public void testBroadcastOnInitialization() {
        ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class);
        verify(mContext, times(3)).sendBroadcastAsUser(
                captorIntent.capture(), eq(UserHandle.ALL));
        assertThat(captorIntent.getAllValues().stream().map(Intent::getAction).toList())
                .containsExactly(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED,
                        TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED,
                        SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED);
    }

    @Test
    public void testAddSubInfo() {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
@@ -573,6 +585,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {

    @Test
    public void testSetDefaultVoiceSubId() throws Exception {
        clearInvocations(mContext);
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        insertSubscription(FAKE_SUBSCRIPTION_INFO2);

@@ -590,7 +603,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        assertThat(Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION)).isEqualTo(1);
        ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class);
        verify(mContext, times(2)).sendStickyBroadcastAsUser(
        verify(mContext, times(2)).sendBroadcastAsUser(
                captorIntent.capture(), eq(UserHandle.ALL));

        Intent intent = captorIntent.getAllValues().get(0);
@@ -614,6 +627,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {

    @Test
    public void testSetDefaultDataSubId() throws Exception {
        clearInvocations(mContext);
        doReturn(false).when(mTelephonyManager).isVoiceCapable();
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        insertSubscription(FAKE_SUBSCRIPTION_INFO2);
@@ -633,7 +647,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        assertThat(Settings.Global.getInt(mContext.getContentResolver(),
                        Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION)).isEqualTo(1);
        ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class);
        verify(mContext, times(2)).sendStickyBroadcastAsUser(
        verify(mContext, times(2)).sendBroadcastAsUser(
                captorIntent.capture(), eq(UserHandle.ALL));

        Intent intent = captorIntent.getAllValues().get(0);
@@ -657,6 +671,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {

    @Test
    public void testSetDefaultSmsSubId() throws Exception {
        clearInvocations(mContext);
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        insertSubscription(FAKE_SUBSCRIPTION_INFO2);

@@ -673,7 +688,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        assertThat(Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION)).isEqualTo(1);
        ArgumentCaptor<Intent> captorIntent = ArgumentCaptor.forClass(Intent.class);
        verify(mContext).sendStickyBroadcastAsUser(captorIntent.capture(), eq(UserHandle.ALL));
        verify(mContext).sendBroadcastAsUser(captorIntent.capture(), eq(UserHandle.ALL));

        Intent intent = captorIntent.getValue();
        assertThat(intent.getAction()).isEqualTo(