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

Commit b584ffe0 authored by Hunsuk Choi's avatar Hunsuk Choi
Browse files

Initialize DomainSelectionController with the potential multi-SIM configuration

If the device boots with single SIM configuration,
DomainSelectionController is initialized with the single SIM config,
and it's not able to detect the change of multi-SIM configuration.
So, DomainSelectionController isn't initialized for the SIM2
after the configuration change and exception happens
when the dialing on SIM2.

To fix the issue, initialize DomainSelectionController
with the potential multi-SIM configuration.

Flag: EXEMPT bugfix
Bug: 342883602
Test: atest DomainSelectionControllerTest
Change-Id: I1f98959af3cce096f531937752e33f08faab68f8
parent 24b82d67
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -271,7 +271,9 @@ public class DomainSelectionController {
                mHandler,
                mRestartBindingRunnable);

        int numPhones = TelephonyManager.getDefault().getActiveModemCount();
        TelephonyManager tm = mContext.getSystemService(TelephonyManager.class);
        int numPhones = tm.getSupportedModemCount();
        logi("numPhones=" + numPhones);
        mConnectionCounts = new int[numPhones];
        for (int i = 0; i < numPhones; i++) {
            mConnectionCounts[i] = 0;
+50 −1
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package com.android.internal.telephony.domainselection;

import static android.telephony.DomainSelectionService.SELECTOR_TYPE_CALLING;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;

import static org.mockito.ArgumentMatchers.any;
@@ -36,6 +39,8 @@ import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.telephony.DomainSelectionService;
import android.telephony.TelephonyManager;
import android.test.mock.MockContext;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -71,6 +76,8 @@ public class DomainSelectionControllerTest extends TelephonyTest {
                }
            };

    Context mTestContext;

    // Mocked classes
    IDomainSelectionServiceController mMockServiceControllerBinder;
    Context mMockContext;
@@ -84,9 +91,40 @@ public class DomainSelectionControllerTest extends TelephonyTest {
    public void setUp() throws Exception {
        super.setUp(this.getClass().getSimpleName());

        when(mTelephonyManager.getSupportedModemCount()).thenReturn(2);
        mMockContext = mock(Context.class);
        mTestContext = new MockContext() {
            @Override
            public String getSystemServiceName(Class<?> serviceClass) {
                if (serviceClass == TelephonyManager.class) {
                    return Context.TELEPHONY_SERVICE;
                }
                return super.getSystemServiceName(serviceClass);
            }

            @Override
            public Object getSystemService(String name) {
                switch (name) {
                    case (Context.TELEPHONY_SERVICE) : {
                        return mTelephonyManager;
                    }
                }
                return super.getSystemService(name);
            }

            @Override
            public boolean bindService(Intent service, ServiceConnection conn, int flags) {
                return mMockContext.bindService(service, conn, flags);
            }

            @Override
            public void unbindService(ServiceConnection conn) {
                mMockContext.unbindService(conn);
            }
        };

        mMockServiceControllerBinder = mock(IDomainSelectionServiceController.class);
        mTestController = new DomainSelectionController(mMockContext,
        mTestController = new DomainSelectionController(mTestContext,
                Looper.getMainLooper(), BIND_RETRY);
        mHandler = mTestController.getHandlerForTest();

@@ -264,6 +302,17 @@ public class DomainSelectionControllerTest extends TelephonyTest {
        verify(mMockContext, times(1)).bindService(any(), any(), anyInt());
    }

    @SmallTest
    @Test
    public void testGetDomainSelectionConnection() throws Exception {
        when(mPhone.getPhoneId()).thenReturn(1);
        DomainSelectionConnection dsc = mTestController.getDomainSelectionConnection(
                mPhone, SELECTOR_TYPE_CALLING, false);

        assertNotNull(dsc);
        assertTrue(dsc instanceof NormalCallDomainSelectionConnection);
    }

    private void bindAndNullServiceError() {
        ServiceConnection connection = bindService(mTestComponentName);
        connection.onNullBinding(mTestComponentName);