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

Commit 697f7204 authored by Calvin Pan's avatar Calvin Pan Committed by Automerger Merge Worker
Browse files

Prevent GsmCdmaPhoneTest breaking by permission issue am: 7ba844e3

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1689668

Change-Id: I6c4c5e9520b8ba0ca5cb480e678aebd3695313c3
parents 2647ef1a 7ba844e3
Loading
Loading
Loading
Loading
+39 −1
Original line number Diff line number Diff line
@@ -239,6 +239,17 @@ public class GsmCdmaPhone extends Phone {
        }
    }

    /**
     * Used to create ImsManager instances, which may be injected during testing.
     */
    @VisibleForTesting
    public interface ImsManagerFactory {
        /**
         * Create a new instance of ImsManager for the specified phoneId.
         */
        ImsManager create(Context context, int phoneId);
    }

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private IccSmsInterfaceManager mIccSmsInterfaceManager;

@@ -251,6 +262,8 @@ public class GsmCdmaPhone extends Phone {

    private final SettingsObserver mSettingsObserver;

    private final ImsManagerFactory mImsManagerFactory;

    // Constructors

    public GsmCdmaPhone(Context context, CommandsInterface ci, PhoneNotifier notifier, int phoneId,
@@ -261,12 +274,23 @@ public class GsmCdmaPhone extends Phone {
    public GsmCdmaPhone(Context context, CommandsInterface ci, PhoneNotifier notifier,
                        boolean unitTestMode, int phoneId, int precisePhoneType,
                        TelephonyComponentFactory telephonyComponentFactory) {
        this(context, ci, notifier,
                unitTestMode, phoneId, precisePhoneType,
                telephonyComponentFactory,
                ImsManager::getInstance);
    }

    public GsmCdmaPhone(Context context, CommandsInterface ci, PhoneNotifier notifier,
            boolean unitTestMode, int phoneId, int precisePhoneType,
            TelephonyComponentFactory telephonyComponentFactory,
            ImsManagerFactory imsManagerFactory) {
        super(precisePhoneType == PhoneConstants.PHONE_TYPE_GSM ? "GSM" : "CDMA",
                notifier, context, ci, unitTestMode, phoneId, telephonyComponentFactory);

        // phone type needs to be set before other initialization as other objects rely on it
        mPrecisePhoneType = precisePhoneType;
        mVoiceCallSessionStats = new VoiceCallSessionStats(mPhoneId, this);
        mImsManagerFactory = imsManagerFactory;
        initOnce(ci);
        initRatSpecific(precisePhoneType);
        // CarrierSignalAgent uses CarrierActionAgent in construction so it needs to be created
@@ -4616,4 +4640,18 @@ public class GsmCdmaPhone extends Phone {
                loge("Invalid cdma_roaming_mode settings: " + config_cdma_roaming_mode);
        }
    }

    /**
     * Determines if IMS is enabled for call.
     *
     * @return {@code true} if IMS calling is enabled.
     */
    public boolean isImsUseEnabled() {
        ImsManager imsManager = mImsManagerFactory.create(mContext, mPhoneId);
        boolean imsUseEnabled = ((imsManager.isVolteEnabledByPlatform()
                && imsManager.isEnhanced4gLteModeSettingEnabledByUser())
                || (imsManager.isWfcEnabledByPlatform() && imsManager.isWfcEnabledByUser())
                && imsManager.isNonTtyOrTtyOnVolteEnabled());
        return imsUseEnabled;
    }
}
+0 −14
Original line number Diff line number Diff line
@@ -4364,20 +4364,6 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mCi.unregisterForRadioCapabilityChanged(this);
    }

    /**
     * Determines if  IMS is enabled for call.
     *
     * @return {@code true} if IMS calling is enabled.
     */
    public boolean isImsUseEnabled() {
        ImsManager imsManager = ImsManager.getInstance(mContext, mPhoneId);
        boolean imsUseEnabled = ((imsManager.isVolteEnabledByPlatform()
                && imsManager.isEnhanced4gLteModeSettingEnabledByUser())
                || (imsManager.isWfcEnabledByPlatform() && imsManager.isWfcEnabledByUser())
                && imsManager.isNonTtyOrTtyOnVolteEnabled());
        return imsUseEnabled;
    }

    /**
     * Determines if the connection to IMS services are available yet.
     * @return {@code true} if the connection to IMS services are available.
+4 −2
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import android.testing.TestableLooper;

import androidx.test.filters.FlakyTest;

import com.android.ims.ImsManager;
import com.android.internal.telephony.test.SimulatedCommands;
import com.android.internal.telephony.test.SimulatedCommandsVerifier;
import com.android.internal.telephony.uicc.IccCardApplicationStatus;
@@ -133,9 +134,10 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        super.setUp(getClass().getSimpleName());

        doReturn(false).when(mSST).isDeviceShuttingDown();
        doReturn(true).when(mImsManager).isVolteEnabledByPlatform();

        mPhoneUT = new GsmCdmaPhone(mContext, mSimulatedCommands, mNotifier, true, 0,
            PhoneConstants.PHONE_TYPE_GSM, mTelephonyComponentFactory);
            PhoneConstants.PHONE_TYPE_GSM, mTelephonyComponentFactory, (c, p) -> mImsManager);
        mPhoneUT.setVoiceCallSessionStats(mVoiceCallSessionStats);
        ArgumentCaptor<Integer> integerArgumentCaptor = ArgumentCaptor.forClass(Integer.class);
        verify(mUiccController).registerForIccChanged(eq(mPhoneUT), integerArgumentCaptor.capture(),
@@ -998,7 +1000,7 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        };

        Phone phone = new GsmCdmaPhone(mContext, sc, mNotifier, true, 0,
                PhoneConstants.PHONE_TYPE_GSM, mTelephonyComponentFactory);
                PhoneConstants.PHONE_TYPE_GSM, mTelephonyComponentFactory, (c, p) -> mImsManager);
        phone.setVoiceCallSessionStats(mVoiceCallSessionStats);
        ArgumentCaptor<Integer> integerArgumentCaptor = ArgumentCaptor.forClass(Integer.class);
        verify(mUiccController).registerForIccChanged(eq(phone), integerArgumentCaptor.capture(),