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

Commit ecac744a authored by Amit Mahajan's avatar Amit Mahajan
Browse files

First unit test for ImsPhone.

Bug: 25691379
Change-Id: I61a2f0805220782e7dbebaf50604b596ef3ba24b
parent 3e1a34f2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import com.android.ims.ImsManager;
import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
import com.android.internal.telephony.cdma.EriManager;
import com.android.internal.telephony.dataconnection.DcTracker;
import com.android.internal.telephony.imsphone.ImsPhone;
import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
import com.android.internal.telephony.uicc.IccCardProxy;

/**
@@ -101,6 +103,10 @@ public class TelephonyComponentFactory {
                sequenceNumber, messageCount, is3gpp2WapPdu);
    }

    public ImsPhoneCallTracker makeImsPhoneCallTracker(ImsPhone imsPhone) {
        return new ImsPhoneCallTracker(imsPhone);
    }

    public CdmaSubscriptionSourceManager
    getCdmaSubscriptionSourceManagerInstance(Context context, CommandsInterface ci, Handler h,
                                             int what, Object obj) {
+1 −1
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ public class GsmInboundSmsHandler extends InboundSmsHandler {
        return dispatchNormalMessage(smsb);
    }

    /* package */ void updateMessageWaitingIndicator(int voicemailCount) {
    private void updateMessageWaitingIndicator(int voicemailCount) {
        // range check
        if (voicemailCount < 0) {
            voicemailCount = -1;
+49 −58
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ import com.android.internal.telephony.GsmCdmaPhone;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneNotifier;
import com.android.internal.telephony.TelephonyComponentFactory;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyProperties;
import com.android.internal.telephony.UUSInfo;
@@ -103,13 +104,13 @@ public class ImsPhone extends ImsPhoneBase {
    private static final boolean DBG = true;
    private static final boolean VDBG = false; // STOPSHIP if true

    protected static final int EVENT_SET_CALL_BARRING_DONE          = EVENT_LAST + 1;
    protected static final int EVENT_GET_CALL_BARRING_DONE          = EVENT_LAST + 2;
    protected static final int EVENT_SET_CALL_WAITING_DONE          = EVENT_LAST + 3;
    protected static final int EVENT_GET_CALL_WAITING_DONE          = EVENT_LAST + 4;
    protected static final int EVENT_SET_CLIR_DONE                  = EVENT_LAST + 5;
    protected static final int EVENT_GET_CLIR_DONE                  = EVENT_LAST + 6;
    protected static final int EVENT_DEFAULT_PHONE_DATA_STATE_CHANGED  = EVENT_LAST + 7;
    private static final int EVENT_SET_CALL_BARRING_DONE             = EVENT_LAST + 1;
    private static final int EVENT_GET_CALL_BARRING_DONE             = EVENT_LAST + 2;
    private static final int EVENT_SET_CALL_WAITING_DONE             = EVENT_LAST + 3;
    private static final int EVENT_GET_CALL_WAITING_DONE             = EVENT_LAST + 4;
    private static final int EVENT_SET_CLIR_DONE                     = EVENT_LAST + 5;
    private static final int EVENT_GET_CLIR_DONE                     = EVENT_LAST + 6;
    private static final int EVENT_DEFAULT_PHONE_DATA_STATE_CHANGED  = EVENT_LAST + 7;

    static final int RESTART_ECM_TIMER = 0; // restart Ecm timer
    static final int CANCEL_ECM_TIMER  = 1; // cancel Ecm timer
@@ -120,16 +121,16 @@ public class ImsPhone extends ImsPhoneBase {
    // Instance Variables
    Phone mDefaultPhone;
    ImsPhoneCallTracker mCT;
    ArrayList <ImsPhoneMmiCode> mPendingMMIs = new ArrayList<ImsPhoneMmiCode>();
    private ArrayList <ImsPhoneMmiCode> mPendingMMIs = new ArrayList<ImsPhoneMmiCode>();

    Registrant mPostDialHandler;
    ServiceState mSS = new ServiceState();
    private ServiceState mSS = new ServiceState();

    // To redial silently through GSM or CDMA when dialing through IMS fails
    private String mLastDialString;

    WakeLock mWakeLock;
    protected boolean mIsPhoneInEcmState;
    private WakeLock mWakeLock;
    private boolean mIsPhoneInEcmState;

    // mEcmExitRespRegistrant is informed after the phone has been exited the emergency
    // callback mode keep track of if phone is in emergency callback mode
@@ -168,11 +169,11 @@ public class ImsPhone extends ImsPhoneBase {

    // Constructors

    ImsPhone(Context context, PhoneNotifier notifier, Phone defaultPhone) {
    public ImsPhone(Context context, PhoneNotifier notifier, Phone defaultPhone) {
        super("ImsPhone", context, notifier);

        mDefaultPhone = (Phone) defaultPhone;
        mCT = new ImsPhoneCallTracker(this);
        mDefaultPhone = defaultPhone;
        mCT = TelephonyComponentFactory.getInstance().makeImsPhoneCallTracker(this);
        mSS.setStateOff();

        mPhoneId = mDefaultPhone.getPhoneId();
@@ -194,6 +195,7 @@ public class ImsPhone extends ImsPhoneBase {
        updateDataServiceState();
    }

    //todo: get rid of this function. It is not needed since parentPhone obj never changes
    @Override
    public void updateParentPhone(Phone parentPhone) {
        synchronized (Phone.lockForRadioTechnologyChange) {
@@ -250,7 +252,6 @@ public class ImsPhone extends ImsPhoneBase {
        return mPendingMMIs;
    }


    @Override
    public void
    acceptCall(int videoState) throws CallStateException {
@@ -342,7 +343,6 @@ public class ImsPhone extends ImsPhoneBase {
        return true;
    }


    private boolean handleCallWaitingIncallSupplementaryService(
            String dialString) {
        int len = dialString.length();
@@ -504,6 +504,7 @@ public class ImsPhone extends ImsPhoneBase {
        mDefaultPhone.notifyUnknownConnectionP(c);
    }

    @Override
    public void notifyForVideoCapabilityChanged(boolean isVideoCapable) {
        mIsVideoCapable = isVideoCapable;
        mDefaultPhone.notifyForVideoCapabilityChanged(isVideoCapable);
@@ -523,7 +524,7 @@ public class ImsPhone extends ImsPhoneBase {
        return dialInternal (dialString, videoState, intentExtras);
    }

    protected Connection dialInternal(String dialString, int videoState, Bundle intentExtras)
    private Connection dialInternal(String dialString, int videoState, Bundle intentExtras)
            throws CallStateException {
        // Need to make sure dialString gets parsed properly
        String newDialString = PhoneNumberUtils.stripSeparators(dialString);
@@ -899,8 +900,7 @@ public class ImsPhone extends ImsPhoneBase {
        mCT.cancelUSSD();
    }

    /* package */
    void sendErrorResponse(Message onComplete) {
    private void sendErrorResponse(Message onComplete) {
        Rlog.d(LOG_TAG, "sendErrorResponse");
        if (onComplete != null) {
            AsyncResult.forMessage(onComplete, null,
@@ -918,21 +918,7 @@ public class ImsPhone extends ImsPhoneBase {
        }
    }

    /* package */
    void sendErrorResponse(Message onComplete, ImsReasonInfo reasonInfo) {
        Rlog.d(LOG_TAG, "sendErrorResponse reasonCode=" + reasonInfo.getCode());
        if (onComplete != null) {
            AsyncResult.forMessage(onComplete, null, getCommandException(reasonInfo.getCode()));
            onComplete.sendToTarget();
        }
    }

    /* package */
    CommandException getCommandException(int code) {
        return getCommandException(code, null);
    }

    CommandException getCommandException(int code, String errorString) {
    private CommandException getCommandException(int code, String errorString) {
        Rlog.d(LOG_TAG, "getCommandException code= " + code
                + ", errorString= " + errorString);
        CommandException.Error error = CommandException.Error.GENERIC_FAILURE;
@@ -953,8 +939,7 @@ public class ImsPhone extends ImsPhoneBase {
        return new CommandException(error, errorString);
    }

    /* package */
    CommandException getCommandException(Throwable e) {
    private CommandException getCommandException(Throwable e) {
        CommandException ex = null;

        if (e instanceof ImsException) {
@@ -1182,7 +1167,6 @@ public class ImsPhone extends ImsPhoneBase {
    @Override
    public void handleMessage(Message msg) {
        AsyncResult ar = (AsyncResult) msg.obj;
        Message onComplete;

        if (DBG) Rlog.d(LOG_TAG, "handleMessage what=" + msg.what);
        switch (msg.what) {
@@ -1264,15 +1248,17 @@ public class ImsPhone extends ImsPhoneBase {
                }
            };

    @Override
    public boolean isInEmergencyCall() {
        return mCT.isInEmergencyCall();
    }

    @Override
    public boolean isInEcm() {
        return mIsPhoneInEcmState;
    }

    void sendEmergencyCallbackModeChange() {
    private void sendEmergencyCallbackModeChange() {
        // Send an Intent
        Intent intent = new Intent(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
        intent.putExtra(PhoneConstants.PHONE_IN_ECM_STATE, mIsPhoneInEcmState);
@@ -1361,10 +1347,12 @@ public class ImsPhone extends ImsPhoneBase {
        }
    }

    @Override
    public void setOnEcbModeExitResponse(Handler h, int what, Object obj) {
        mEcmExitRespRegistrant = new Registrant(h, what, obj);
    }

    @Override
    public void unsetOnEcbModeExitResponse(Handler h) {
        mEcmExitRespRegistrant.clear();
    }
@@ -1373,6 +1361,7 @@ public class ImsPhone extends ImsPhoneBase {
        mDefaultPhone.getServiceStateTracker().onImsCapabilityChanged();
    }

    @Override
    public boolean isVolteEnabled() {
        return mCT.isVolteEnabled();
    }
@@ -1392,6 +1381,7 @@ public class ImsPhone extends ImsPhoneBase {
        return mDefaultPhone;
    }

    @Override
    public boolean isImsRegistered() {
        return mImsRegistered;
    }
@@ -1521,6 +1511,7 @@ public class ImsPhone extends ImsPhoneBase {
        }
    }

    @Override
    public boolean isUtEnabled() {
        return mCT.isUtEnabled();
    }
+4 −4
Original line number Diff line number Diff line
@@ -182,12 +182,12 @@ public class ImsPhoneCallTracker extends CallTracker {
    private RegistrantList mVoiceCallEndedRegistrants = new RegistrantList();
    private RegistrantList mVoiceCallStartedRegistrants = new RegistrantList();

    public final ImsPhoneCall mRingingCall = new ImsPhoneCall(this, ImsPhoneCall.CONTEXT_RINGING);
    public final ImsPhoneCall mForegroundCall = new ImsPhoneCall(this,
    public ImsPhoneCall mRingingCall = new ImsPhoneCall(this, ImsPhoneCall.CONTEXT_RINGING);
    public ImsPhoneCall mForegroundCall = new ImsPhoneCall(this,
            ImsPhoneCall.CONTEXT_FOREGROUND);
    public final ImsPhoneCall mBackgroundCall = new ImsPhoneCall(this,
    public ImsPhoneCall mBackgroundCall = new ImsPhoneCall(this,
            ImsPhoneCall.CONTEXT_BACKGROUND);
    public final ImsPhoneCall mHandoverCall = new ImsPhoneCall(this, ImsPhoneCall.CONTEXT_HANDOVER);
    public ImsPhoneCall mHandoverCall = new ImsPhoneCall(this, ImsPhoneCall.CONTEXT_HANDOVER);

    private ImsPhoneConnection mPendingMO;
    private int mClirMode = CommandsInterface.CLIR_DEFAULT;
+1 −1
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ public class GsmCdmaPhoneTest extends TelephonyTest {

    @Before
    public void setUp() throws Exception {
        super.setUp("GsmCdmaPhoneTest");
        super.setUp(getClass().getSimpleName());

        doReturn(false).when(mSST).isDeviceShuttingDown();
        mTelephonyManager = TelephonyManager.from(mContext);
Loading