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

Commit 7ba844e3 authored by Calvin Pan's avatar Calvin Pan
Browse files

Prevent GsmCdmaPhoneTest breaking by permission issue

GsmCdmaPhoneTest will fail if we add logic that read the sim_info value
by SubscriptionController.getSubscriptionProperty() in
ImsManager.isVolteEnabledByPlatform().

Mock ImsManager and return true in ImsManager.isVolteEnabledByPlatform()

Bug: 177010143
Test: atest
Change-Id: I324bfeb30264891fee22af4a96415538f4c07b8a
Merged-In: I324bfeb30264891fee22af4a96415538f4c07b8a
parent f50bfdf6
Loading
Loading
Loading
Loading
+39 −1
Original line number Original line 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)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private IccSmsInterfaceManager mIccSmsInterfaceManager;
    private IccSmsInterfaceManager mIccSmsInterfaceManager;


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


    private final SettingsObserver mSettingsObserver;
    private final SettingsObserver mSettingsObserver;


    private final ImsManagerFactory mImsManagerFactory;

    // Constructors
    // Constructors


    public GsmCdmaPhone(Context context, CommandsInterface ci, PhoneNotifier notifier, int phoneId,
    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,
    public GsmCdmaPhone(Context context, CommandsInterface ci, PhoneNotifier notifier,
                        boolean unitTestMode, int phoneId, int precisePhoneType,
                        boolean unitTestMode, int phoneId, int precisePhoneType,
                        TelephonyComponentFactory telephonyComponentFactory) {
                        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",
        super(precisePhoneType == PhoneConstants.PHONE_TYPE_GSM ? "GSM" : "CDMA",
                notifier, context, ci, unitTestMode, phoneId, telephonyComponentFactory);
                notifier, context, ci, unitTestMode, phoneId, telephonyComponentFactory);


        // phone type needs to be set before other initialization as other objects rely on it
        // phone type needs to be set before other initialization as other objects rely on it
        mPrecisePhoneType = precisePhoneType;
        mPrecisePhoneType = precisePhoneType;
        mVoiceCallSessionStats = new VoiceCallSessionStats(mPhoneId, this);
        mVoiceCallSessionStats = new VoiceCallSessionStats(mPhoneId, this);
        mImsManagerFactory = imsManagerFactory;
        initOnce(ci);
        initOnce(ci);
        initRatSpecific(precisePhoneType);
        initRatSpecific(precisePhoneType);
        // CarrierSignalAgent uses CarrierActionAgent in construction so it needs to be created
        // 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);
                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 Original line Diff line number Diff line
@@ -4364,20 +4364,6 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mCi.unregisterForRadioCapabilityChanged(this);
        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.
     * Determines if the connection to IMS services are available yet.
     * @return {@code true} if the connection to IMS services are available.
     * @return {@code true} if the connection to IMS services are available.
+4 −2
Original line number Original line Diff line number Diff line
@@ -72,6 +72,7 @@ import android.testing.TestableLooper;


import androidx.test.filters.FlakyTest;
import androidx.test.filters.FlakyTest;


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


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


        mPhoneUT = new GsmCdmaPhone(mContext, mSimulatedCommands, mNotifier, true, 0,
        mPhoneUT = new GsmCdmaPhone(mContext, mSimulatedCommands, mNotifier, true, 0,
            PhoneConstants.PHONE_TYPE_GSM, mTelephonyComponentFactory);
            PhoneConstants.PHONE_TYPE_GSM, mTelephonyComponentFactory, (c, p) -> mImsManager);
        mPhoneUT.setVoiceCallSessionStats(mVoiceCallSessionStats);
        mPhoneUT.setVoiceCallSessionStats(mVoiceCallSessionStats);
        ArgumentCaptor<Integer> integerArgumentCaptor = ArgumentCaptor.forClass(Integer.class);
        ArgumentCaptor<Integer> integerArgumentCaptor = ArgumentCaptor.forClass(Integer.class);
        verify(mUiccController).registerForIccChanged(eq(mPhoneUT), integerArgumentCaptor.capture(),
        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,
        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);
        phone.setVoiceCallSessionStats(mVoiceCallSessionStats);
        ArgumentCaptor<Integer> integerArgumentCaptor = ArgumentCaptor.forClass(Integer.class);
        ArgumentCaptor<Integer> integerArgumentCaptor = ArgumentCaptor.forClass(Integer.class);
        verify(mUiccController).registerForIccChanged(eq(phone), integerArgumentCaptor.capture(),
        verify(mUiccController).registerForIccChanged(eq(phone), integerArgumentCaptor.capture(),