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

Commit 3a0daaa3 authored by Brad Ebinger's avatar Brad Ebinger
Browse files

If FEATURE_TELEPHONY_IMS is not available, don't spin up IMS

Do not start ImsResolver and ImsPhone if FEATURE_TELEPHONY_IMS
is not available.

Bug: 118823723
Test: atest FrameworksTelephonyTests
Change-Id: I7a722b274d7cf3d138d120268aab08263bdf5a06
parent 353672ec
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -590,8 +590,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
            if (imsManager != null && !imsManager.isDynamicBinding()) {
                filter.addAction(ImsManager.ACTION_IMS_SERVICE_UP);
                filter.addAction(ImsManager.ACTION_IMS_SERVICE_DOWN);
            }
                mContext.registerReceiver(mImsIntentReceiver, filter);
            }

            // Monitor IMS service - but first poll to see if already up (could miss
            // intent). Also, when using new ImsResolver APIs, the service will be available soon,
+30 −19
Original line number Diff line number Diff line
@@ -143,18 +143,6 @@ public class PhoneFactory {
                   where as in single SIM mode only instance. isMultiSimEnabled() function checks
                   whether it is single SIM or multi SIM mode */
                int numPhones = TelephonyManager.getDefault().getPhoneCount();
                // Return whether or not the device should use dynamic binding or the static
                // implementation (deprecated)
                boolean isDynamicBinding = sContext.getResources().getBoolean(
                        com.android.internal.R.bool.config_dynamic_bind_ims);
                // Get the package name of the default IMS implementation.
                String defaultImsPackage = sContext.getResources().getString(
                        com.android.internal.R.string.config_ims_package);
                // Start ImsResolver and bind to ImsServices.
                Rlog.i(LOG_TAG, "ImsResolver: defaultImsPackage: " + defaultImsPackage);
                sImsResolver = new ImsResolver(sContext, defaultImsPackage, numPhones,
                        isDynamicBinding);
                sImsResolver.initPopulateCacheAndStartBind();

                int[] networkModes = new int[numPhones];
                sPhones = new Phone[numPhones];
@@ -228,13 +216,32 @@ public class PhoneFactory {
                        BackgroundThread.get().getLooper(), context, sPhones, sCommandsInterfaces);
                SubscriptionController.getInstance().updatePhonesAvailability(sPhones);


                // Only bring up IMS if the device supports having an IMS stack.
                if (context.getPackageManager().hasSystemFeature(
                        PackageManager.FEATURE_TELEPHONY_IMS)) {
                    // Return whether or not the device should use dynamic binding or the static
                    // implementation (deprecated)
                    boolean isDynamicBinding = sContext.getResources().getBoolean(
                            com.android.internal.R.bool.config_dynamic_bind_ims);
                    // Get the package name of the default IMS implementation.
                    String defaultImsPackage = sContext.getResources().getString(
                            com.android.internal.R.string.config_ims_package);
                    // Start ImsResolver and bind to ImsServices.
                    Rlog.i(LOG_TAG, "ImsResolver: defaultImsPackage: " + defaultImsPackage);
                    sImsResolver = new ImsResolver(sContext, defaultImsPackage, numPhones,
                            isDynamicBinding);
                    sImsResolver.initPopulateCacheAndStartBind();
                    // Start monitoring after defaults have been made.
                // Default phone must be ready before ImsPhone is created because ImsService might
                // need it when it is being opened. This should initialize multiple ImsPhones for
                // ImsResolver implementations of ImsService.
                    // Default phone must be ready before ImsPhone is created because ImsService
                    // might need it when it is being opened. This should initialize multiple
                    // ImsPhones for ImsResolver implementations of ImsService.
                    for (int i = 0; i < numPhones; i++) {
                        sPhones[i].startMonitoringImsService();
                    }
                } else {
                    Rlog.i(LOG_TAG, "IMS is not supported on this device, skipping ImsResolver.");
                }

                ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(
                        ServiceManager.getService("telephony.registry"));
@@ -316,7 +323,11 @@ public class PhoneFactory {
        return sSubInfoRecordUpdater;
    }

    public static ImsResolver getImsResolver() {
    /**
     * @return The ImsResolver instance or null if IMS is not supported
     * (FEATURE_TELEPHONY_IMS is not defined).
     */
    public static @Nullable ImsResolver getImsResolver() {
        return sImsResolver;
    }

+12 −5
Original line number Diff line number Diff line
@@ -19,10 +19,12 @@ package android.telephony.ims;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;

import android.os.IBinder;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.telephony.AccessNetworkConstants;
import android.telephony.ims.aidl.IImsRegistrationCallback;
import android.telephony.ims.stub.ImsRegistrationImplBase;
@@ -40,9 +42,9 @@ import org.mockito.Mock;
public class ImsMmTelManagerTests extends TelephonyTest {

    @Mock
    IBinder mMockBinder;
    ITelephony.Stub mMockTelephonyInterface;
    @Mock
    ITelephony mMockTelephonyInterface;
    IPackageManager.Stub mMockPackageManager;

    public class LocalCallback extends ImsMmTelManager.RegistrationCallback {
        int mRegResult = -1;
@@ -56,8 +58,13 @@ public class ImsMmTelManagerTests extends TelephonyTest {
    @Before
    public void setUp() throws Exception {
        super.setUp("ImsMmTelManagerTests");
        doReturn(mMockTelephonyInterface).when(mMockBinder).queryLocalInterface(anyString());
        mServiceManagerMockedServices.put("phone", mMockBinder);
        doReturn(mMockTelephonyInterface).when(mMockTelephonyInterface).queryLocalInterface(
                anyString());
        doReturn(mMockPackageManager).when(mMockPackageManager).queryLocalInterface(anyString());
        doReturn(true).when(mMockPackageManager).hasSystemFeature(
                eq(PackageManager.FEATURE_TELEPHONY_IMS), anyInt());
        mServiceManagerMockedServices.put("phone", mMockTelephonyInterface);
        mServiceManagerMockedServices.put("package", mMockPackageManager);
    }

    @After
+9 −0
Original line number Diff line number Diff line
@@ -528,6 +528,7 @@ public class ContextFixture implements TestFixture<Context> {
    private final Multimap<Intent, BroadcastReceiver> mOrderedBroadcastReceivers =
            ArrayListMultimap.create();
    private final HashSet<String> mPermissionTable = new HashSet<>();
    private final HashSet<String> mSystemFeatures = new HashSet<>();



@@ -586,6 +587,10 @@ public class ContextFixture implements TestFixture<Context> {
            }
        }).when(mPackageManager).queryIntentServicesAsUser((Intent) any(), anyInt(), anyInt());

        doAnswer((Answer<Boolean>)
                invocation -> mSystemFeatures.contains((String) invocation.getArgument(0)))
                .when(mPackageManager).hasSystemFeature(any());

        doReturn(mBundle).when(mCarrierConfigManager).getConfigForSubId(anyInt());
        //doReturn(mBundle).when(mCarrierConfigManager).getConfig(anyInt());
        doReturn(mBundle).when(mCarrierConfigManager).getConfig();
@@ -697,6 +702,10 @@ public class ContextFixture implements TestFixture<Context> {
        }
    }

    public void addSystemFeature(String feature) {
        mSystemFeatures.add(feature);
    }

    private static void logd(String s) {
        Log.d(TAG, s);
    }
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
@@ -95,6 +96,7 @@ public class ImsManagerTest extends TelephonyTest {
        mServiceManagerMockedServices.put("isub", mBinder);

        doReturn(true).when(mMmTelFeatureConnection).isBinderAlive();
        mContextFixture.addSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS);

        mImsManagerInstances.remove(mPhoneId);

Loading