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

Commit 32b5fbb1 authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Unit tests for GsmCdmaPhone.

Also creating abstract class TelephonyTest that can be extended
by other unit tests.

Bug: 25691379
Change-Id: I9437642a0bab68c6b573954e587181ff7d04d217
parent 73ea8804
Loading
Loading
Loading
Loading
+59 −89
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ import java.util.ArrayList;
 * {@hide}
 */
public class GsmCdmaCallTracker extends CallTracker {
    static final String LOG_TAG = "GsmCdmaCallTracker";
    private static final String LOG_TAG = "GsmCdmaCallTracker";
    private static final boolean REPEAT_POLLING = false;

    private static final boolean DBG_POLL = false;
@@ -59,44 +59,42 @@ public class GsmCdmaCallTracker extends CallTracker {

    //***** Constants

    static final int MAX_CONNECTIONS_GSM = 19;   // 7 allowed in GSM + 12 from IMS for SRVCC
    static final int MAX_CONNECTIONS_PER_CALL_GSM = 5; // only 5 connections allowed per call
    public static final int MAX_CONNECTIONS_GSM = 19;   //7 allowed in GSM + 12 from IMS for SRVCC
    private static final int MAX_CONNECTIONS_PER_CALL_GSM = 5; //only 5 connections allowed per call

    static final int MAX_CONNECTIONS_CDMA = 8;
    static final int MAX_CONNECTIONS_PER_CALL_CDMA = 1; // only 1 connection allowed per call
    private static final int MAX_CONNECTIONS_CDMA = 8;
    private static final int MAX_CONNECTIONS_PER_CALL_CDMA = 1; //only 1 connection allowed per call

    //***** Instance Variables
    GsmCdmaConnection mConnections[];
    RegistrantList mVoiceCallEndedRegistrants = new RegistrantList();
    RegistrantList mVoiceCallStartedRegistrants = new RegistrantList();
    private GsmCdmaConnection mConnections[];
    private RegistrantList mVoiceCallEndedRegistrants = new RegistrantList();
    private RegistrantList mVoiceCallStartedRegistrants = new RegistrantList();

    // connections dropped during last poll
    ArrayList<GsmCdmaConnection> mDroppedDuringPoll
        = new ArrayList<GsmCdmaConnection>(MAX_CONNECTIONS_GSM);
    private ArrayList<GsmCdmaConnection> mDroppedDuringPoll =
            new ArrayList<GsmCdmaConnection>(MAX_CONNECTIONS_GSM);

    public GsmCdmaCall mRingingCall = new GsmCdmaCall(this);
    // A call that is ringing or (call) waiting
    public GsmCdmaCall mForegroundCall = new GsmCdmaCall(this);
    public GsmCdmaCall mBackgroundCall = new GsmCdmaCall(this);

    GsmCdmaConnection mPendingMO;
    boolean mHangupPendingMO;
    private GsmCdmaConnection mPendingMO;
    private boolean mHangupPendingMO;

    private GsmCdmaPhone mPhone;

    boolean mDesiredMute = false;    // false = mute off
    private boolean mDesiredMute = false;    // false = mute off

    public PhoneConstants.State mState = PhoneConstants.State.IDLE;

    Call.SrvccState mSrvccState = Call.SrvccState.NONE;

    private TelephonyEventLog mEventLog;

    // Following member variables are for CDMA only
    RegistrantList mCallWaitingRegistrants = new RegistrantList();
    boolean mPendingCallInEcm;
    boolean mIsInEmergencyCall;
    int mPendingCallClirMode;
    private RegistrantList mCallWaitingRegistrants = new RegistrantList();
    private boolean mPendingCallInEcm;
    private boolean mIsInEmergencyCall;
    private int mPendingCallClirMode;
    private boolean mIsEcmTimerCanceled;
    private int m3WayCallFlashDelay;

@@ -141,7 +139,7 @@ public class GsmCdmaCallTracker extends CallTracker {

    //***** Constructors

    GsmCdmaCallTracker (GsmCdmaPhone phone) {
    public GsmCdmaCallTracker (GsmCdmaPhone phone) {
        this.mPhone = phone;
        mCi = phone.mCi;
        mCi.registerForCallStateChanged(this, EVENT_CALL_STATE_CHANGE, null);
@@ -236,8 +234,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        mCallWaitingRegistrants.remove(h);
    }

    private void
    fakeHoldForegroundBeforeDial() {
    private void fakeHoldForegroundBeforeDial() {
        List<Connection> connCopy;

        // We need to make a copy here, since fakeHoldBeforeDial()
@@ -255,8 +252,8 @@ public class GsmCdmaCallTracker extends CallTracker {
    /**
     * clirMode is one of the CLIR_ constants
     */
    synchronized Connection
    dial (String dialString, int clirMode, UUSInfo uusInfo, Bundle intentExtras)
    public synchronized Connection dial(String dialString, int clirMode, UUSInfo uusInfo,
                                        Bundle intentExtras)
            throws CallStateException {
        // note that this triggers call state changed notif
        clearDisconnected();
@@ -354,7 +351,7 @@ public class GsmCdmaCallTracker extends CallTracker {
    }

    //CDMA
    protected void setIsInEmergencyCall() {
    public void setIsInEmergencyCall() {
        mIsInEmergencyCall = true;
        mPhone.mDcTracker.setInternalDataEnabled(false);
        mPhone.notifyEmergencyCallRegistrants(true);
@@ -365,8 +362,7 @@ public class GsmCdmaCallTracker extends CallTracker {
    /**
     * clirMode is one of the CLIR_ constants
     */
    Connection
    dial (String dialString, int clirMode) throws CallStateException {
    private Connection dial(String dialString, int clirMode) throws CallStateException {
        // note that this triggers call state changed notif
        clearDisconnected();

@@ -452,8 +448,7 @@ public class GsmCdmaCallTracker extends CallTracker {
    }

    //CDMA
    private Connection
    dialThreeWay (String dialString) {
    private Connection dialThreeWay(String dialString) {
        if (!mForegroundCall.isIdle()) {
            // Check data call
            disableDataCallInEmergencyCall(dialString);
@@ -475,8 +470,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        return null;
    }

    public Connection
    dial(String dialString) throws CallStateException {
    public Connection dial(String dialString) throws CallStateException {
        if (isPhoneTypeGsm()) {
            return dial(dialString, CommandsInterface.CLIR_DEFAULT, null);
        } else {
@@ -485,19 +479,18 @@ public class GsmCdmaCallTracker extends CallTracker {
    }

    //GSM
    Connection
    dial(String dialString, UUSInfo uusInfo, Bundle intentExtras) throws CallStateException {
    public Connection dial(String dialString, UUSInfo uusInfo, Bundle intentExtras)
            throws CallStateException {
        return dial(dialString, CommandsInterface.CLIR_DEFAULT, uusInfo, intentExtras);
    }

    //GSM
    Connection
    dial(String dialString, int clirMode, Bundle intentExtras) throws CallStateException {
    private Connection dial(String dialString, int clirMode, Bundle intentExtras)
            throws CallStateException {
        return dial(dialString, clirMode, null, intentExtras);
    }

    public void
    acceptCall () throws CallStateException {
    public void acceptCall() throws CallStateException {
        // FIXME if SWITCH fails, should retry with ANSWER
        // in case the active/holding call disappeared and this
        // is no longer call waiting
@@ -527,8 +520,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        }
    }

    public void
    rejectCall () throws CallStateException {
    public void rejectCall() throws CallStateException {
        // AT+CHLD=0 means "release held or UDUB"
        // so if the phone isn't ringing, this could hang up held
        if (mRingingCall.getState().isRinging()) {
@@ -545,8 +537,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        mPhone.notifyPreciseCallStateChanged();
    }

    void
    switchWaitingOrHoldingAndActive() throws CallStateException {
    public void switchWaitingOrHoldingAndActive() throws CallStateException {
        // Should we bother with this check?
        if (mRingingCall.getState() == GsmCdmaCall.State.INCOMING) {
            throw new CallStateException("cannot be in the incoming state");
@@ -568,8 +559,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        }
    }

    void
    conference() {
    public void conference() {
        if (isPhoneTypeGsm()) {
            mCi.conference(obtainCompleteMessage(EVENT_CONFERENCE_RESULT));
        } else {
@@ -578,29 +568,25 @@ public class GsmCdmaCallTracker extends CallTracker {
        }
    }

    void
    explicitCallTransfer() {
    public void explicitCallTransfer() {
        mCi.explicitCallTransfer(obtainCompleteMessage(EVENT_ECT_RESULT));
    }

    void
    clearDisconnected() {
    public void clearDisconnected() {
        internalClearDisconnected();

        updatePhoneState();
        mPhone.notifyPreciseCallStateChanged();
    }

    boolean
    canConference() {
    public boolean canConference() {
        return mForegroundCall.getState() == GsmCdmaCall.State.ACTIVE
                && mBackgroundCall.getState() == GsmCdmaCall.State.HOLDING
                && !mBackgroundCall.isFull()
                && !mForegroundCall.isFull();
    }

    boolean
    canDial() {
    private boolean canDial() {
        boolean ret;
        int serviceState = mPhone.getServiceState().getState();
        String disableCall = SystemProperties.get(
@@ -637,8 +623,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        return ret;
    }

    boolean
    canTransfer() {
    public boolean canTransfer() {
        if (isPhoneTypeGsm()) {
            return (mForegroundCall.getState() == GsmCdmaCall.State.ACTIVE
                    || mForegroundCall.getState() == GsmCdmaCall.State.ALERTING
@@ -652,8 +637,7 @@ public class GsmCdmaCallTracker extends CallTracker {

    //***** Private Instance Methods

    private void
    internalClearDisconnected() {
    private void internalClearDisconnected() {
        mRingingCall.clearDisconnected();
        mForegroundCall.clearDisconnected();
        mBackgroundCall.clearDisconnected();
@@ -663,8 +647,7 @@ public class GsmCdmaCallTracker extends CallTracker {
     * Obtain a message to use for signalling "invoke getCurrentCalls() when
     * this operation and all other pending operations are complete
     */
    private Message
    obtainCompleteMessage() {
    private Message obtainCompleteMessage() {
        return obtainCompleteMessage(EVENT_OPERATION_COMPLETE);
    }

@@ -672,8 +655,7 @@ public class GsmCdmaCallTracker extends CallTracker {
     * Obtain a message to use for signalling "invoke getCurrentCalls() when
     * this operation and all other pending operations are complete
     */
    private Message
    obtainCompleteMessage(int what) {
    private Message obtainCompleteMessage(int what) {
        mPendingOperations++;
        mLastRelevantPoll = null;
        mNeedsPoll = true;
@@ -684,8 +666,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        return obtainMessage(what);
    }

    private void
    operationComplete() {
    private void operationComplete() {
        mPendingOperations--;

        if (DBG_POLL) log("operationComplete: pendingOperations=" +
@@ -701,8 +682,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        }
    }

    private void
    updatePhoneState() {
    private void updatePhoneState() {
        PhoneConstants.State oldState = mState;
        if (mRingingCall.isRinging()) {
            mState = PhoneConstants.State.RINGING;
@@ -736,8 +716,7 @@ public class GsmCdmaCallTracker extends CallTracker {
    // ***** Overwritten from CallTracker

    @Override
    protected synchronized void
    handlePollCalls(AsyncResult ar) {
    protected synchronized void handlePollCalls(AsyncResult ar) {
        List polledCalls;

        if (VDBG) log("handlePollCalls");
@@ -1084,16 +1063,14 @@ public class GsmCdmaCallTracker extends CallTracker {
        //dumpState();
    }

    private void
    handleRadioNotAvailable() {
    private void handleRadioNotAvailable() {
        // handlePollCalls will clear out its
        // call list when it gets the CommandException
        // error result from this
        pollCallsWhenSafe();
    }

    private void
    dumpState() {
    private void dumpState() {
        List l;

        Rlog.i(LOG_TAG,"Phone State:" + mState);
@@ -1123,7 +1100,7 @@ public class GsmCdmaCallTracker extends CallTracker {

    //***** Called from GsmCdmaConnection

    /*package*/ void hangup (GsmCdmaConnection conn) throws CallStateException {
    public void hangup(GsmCdmaConnection conn) throws CallStateException {
        if (conn.mOwner != this) {
            throw new CallStateException ("GsmCdmaConnection " + conn
                                    + "does not belong to GsmCdmaCallTracker " + this);
@@ -1168,8 +1145,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        conn.onHangupLocal();
    }

    /*package*/ void
    separate (GsmCdmaConnection conn) throws CallStateException {
    public void separate(GsmCdmaConnection conn) throws CallStateException {
        if (conn.mOwner != this) {
            throw new CallStateException ("GsmCdmaConnection " + conn
                                    + "does not belong to GsmCdmaCallTracker " + this);
@@ -1186,14 +1162,12 @@ public class GsmCdmaCallTracker extends CallTracker {

    //***** Called from GsmCdmaPhone

    /*package*/ void
    setMute(boolean mute) {
    public void setMute(boolean mute) {
        mDesiredMute = mute;
        mCi.setMute(mDesiredMute, null);
    }

    /*package*/ boolean
    getMute() {
    public boolean getMute() {
        return mDesiredMute;
    }

@@ -1240,19 +1214,17 @@ public class GsmCdmaCallTracker extends CallTracker {
        mPhone.notifyPreciseCallStateChanged();
    }

    /* package */
    void hangupWaitingOrBackground() {
    public void hangupWaitingOrBackground() {
        if (Phone.DEBUG_PHONE) log("hangupWaitingOrBackground");
        mCi.hangupWaitingOrBackground(obtainCompleteMessage());
    }

    /* package */
    void hangupForegroundResumeBackground() {
    public void hangupForegroundResumeBackground() {
        if (Phone.DEBUG_PHONE) log("hangupForegroundResumeBackground");
        mCi.hangupForegroundResumeBackground(obtainCompleteMessage());
    }

    void hangupConnectionByIndex(GsmCdmaCall call, int index)
    public void hangupConnectionByIndex(GsmCdmaCall call, int index)
            throws CallStateException {
        int count = call.mConnections.size();
        for (int i = 0; i < count; i++) {
@@ -1266,7 +1238,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        throw new CallStateException("no GsmCdma index found");
    }

    void hangupAllConnections(GsmCdmaCall call) {
    public void hangupAllConnections(GsmCdmaCall call) {
        try {
            int count = call.mConnections.size();
            for (int i = 0; i < count; i++) {
@@ -1278,8 +1250,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        }
    }

    /* package */
    GsmCdmaConnection getConnectionByIndex(GsmCdmaCall call, int index)
    public GsmCdmaConnection getConnectionByIndex(GsmCdmaCall call, int index)
            throws CallStateException {
        int count = call.mConnections.size();
        for (int i = 0; i < count; i++) {
@@ -1326,8 +1297,7 @@ public class GsmCdmaCallTracker extends CallTracker {
    //****** Overridden from Handler

    @Override
    public void
    handleMessage (Message msg) {
    public void handleMessage(Message msg) {
        AsyncResult ar;

        switch (msg.what) {
@@ -1573,7 +1543,7 @@ public class GsmCdmaCallTracker extends CallTracker {
     * @return true if it is in emergency call
     *         false if it is not in emergency call
     */
    boolean isInEmergencyCall() {
    public boolean isInEmergencyCall() {
        return mIsInEmergencyCall;
    }

+2 −11
Original line number Diff line number Diff line
@@ -1009,6 +1009,7 @@ public class SimulatedCommands extends BaseCommands
     */
    @Override
    public void sendBurstDtmf(String dtmfString, int on, int off, Message result) {
        SimulatedCommandsVerifier.getInstance().sendBurstDtmf(dtmfString, on, off, result);
        resultSuccess(result, null);
    }

@@ -1529,51 +1530,43 @@ public class SimulatedCommands extends BaseCommands
    @Override
    public void
    getDeviceIdentity(Message response) {
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
        unimplemented(response);
    }

    @Override
    public void
    getCDMASubscription(Message response) {
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
        unimplemented(response);
    }

    @Override
    public void
    setCdmaSubscriptionSource(int cdmaSubscriptionType, Message response) {
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
        unimplemented(response);
    }

    @Override
    public void queryCdmaRoamingPreference(Message response) {
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
        unimplemented(response);
    }

    @Override
    public void setCdmaRoamingPreference(int cdmaRoamingType, Message response) {
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
        unimplemented(response);
    }

    @Override
    public void
    setPhoneType(int phoneType) {
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
    }

    @Override
    public void getPreferredVoicePrivacy(Message result) {
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
        unimplemented(result);
    }

    @Override
    public void setPreferredVoicePrivacy(boolean enable, Message result) {
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
        unimplemented(result);
    }

@@ -1605,7 +1598,6 @@ public class SimulatedCommands extends BaseCommands
     */
    @Override
    public void queryTTYMode(Message response) {
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
        unimplemented(response);
    }

@@ -1614,7 +1606,6 @@ public class SimulatedCommands extends BaseCommands
     */
    @Override
    public void sendCDMAFeatureCode(String FeatureCode, Message response) {
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
        unimplemented(response);
    }

@@ -1623,8 +1614,8 @@ public class SimulatedCommands extends BaseCommands
     */
    @Override
    public void sendCdmaSms(byte[] pdu, Message response){
        Rlog.w(LOG_TAG, "CDMA not implemented in SimulatedCommands");
        SimulatedCommandsVerifier.getInstance().sendCdmaSms(pdu, response);
        resultSuccess(response, null);
    }

    @Override
+8 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
@@ -63,6 +64,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import static org.mockito.Matchers.anyBoolean;
@@ -291,8 +293,8 @@ public class ContextFixture implements TestFixture<Context> {
            return 0;
        }

        public boolean testMethod1() {
            return true;
        public int testMethod1() {
            return 0;
        }
    }

@@ -317,6 +319,7 @@ public class ContextFixture implements TestFixture<Context> {
    // when(...) logic to be used to add specific little responses where needed.

    private final Resources mResources = mock(Resources.class);
    private final Configuration mConfiguration = new Configuration();
    private final PackageManager mPackageManager = mock(PackageManager.class);
    private final TelephonyManager mTelephonyManager = mock(TelephonyManager.class);
    private final AppOpsManager mAppOpsManager = mock(AppOpsManager.class);
@@ -363,6 +366,9 @@ public class ContextFixture implements TestFixture<Context> {

        doReturn(mBundle).when(mCarrierConfigManager).getConfigForSubId(anyInt());

        mConfiguration.locale = Locale.getDefaultLocaleFromSystemProperties();
        doReturn(mConfiguration).when(mResources).getConfiguration();

        mContentResolver.addProvider(Telephony.Sms.CONTENT_URI.getAuthority(), mContentProvider);
        mContentResolver.addProvider(Settings.System.CONTENT_URI.getAuthority(), mContentProvider);
    }
+83 −141

File changed.

Preview size limit exceeded, changes collapsed.

+179 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncResult;
import android.os.HandlerThread;
import android.os.IDeviceIdleController;
import android.os.Message;
import android.os.RegistrantList;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.CellLocation;
import android.telephony.ServiceState;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;

import com.android.ims.ImsManager;
import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
import com.android.internal.telephony.dataconnection.DcTracker;
import com.android.internal.telephony.test.SimulatedCommands;
import com.android.internal.telephony.test.SimulatedCommandsVerifier;
import com.android.internal.telephony.uicc.IccCardProxy;
import com.android.internal.telephony.uicc.UiccController;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.lang.reflect.Field;
import java.util.HashMap;

public abstract class TelephonyTest {
    protected static String TAG;

    @Mock
    protected Phone mPhone;
    @Mock
    protected ServiceStateTracker mSST;
    @Mock
    protected GsmCdmaCallTracker mCT;
    @Mock
    protected UiccController mUiccController;
    @Mock
    protected IccCardProxy mIccCardProxy;
    @Mock
    protected CallManager mCallManager;
    @Mock
    protected PhoneNotifier mNotifier;
    @Mock
    protected TelephonyComponentFactory mTelephonyComponentFactory;
    @Mock
    protected CdmaSubscriptionSourceManager mCdmaSSM;
    @Mock
    protected RegistrantList mRegistrantList;
    @Mock
    protected IccPhoneBookInterfaceManager mIccPhoneBookIntManager;
    @Mock
    protected HashMap<Integer, ImsManager> mImsManagerInstances;
    @Mock
    protected DcTracker mDcTracker;
    @Mock
    protected GsmCdmaCall mGsmCdmaCall;
    @Mock
    protected SubscriptionController mSubscriptionController;
    @Mock
    protected ServiceState mServiceState;
    @Mock
    protected SimulatedCommandsVerifier mSimulatedCommandsVerifier;
    @Mock
    protected IDeviceIdleController mIDeviceIdleController;

    protected SimulatedCommands mSimulatedCommands;
    protected ContextFixture mContextFixture;
    protected Object mLock = new Object();
    protected boolean mReady;

    protected void waitUntilReady() {
        while(true) {
            synchronized (mLock) {
                if (mReady) {
                    break;
                }
            }
        }
    }

    protected void setReady(boolean ready) {
        synchronized (mLock) {
            mReady = ready;
        }
    }

    protected void setUp(String tag) throws Exception {
        TAG = tag;
        MockitoAnnotations.initMocks(this);

        //Use reflection to mock singleton
        Field field = CallManager.class.getDeclaredField("INSTANCE");
        field.setAccessible(true);
        field.set(null, mCallManager);

        //Use reflection to mock singleton
        field = UiccController.class.getDeclaredField("mInstance");
        field.setAccessible(true);
        field.set(null, mUiccController);

        //Use reflection to mock singleton
        field = CdmaSubscriptionSourceManager.class.getDeclaredField("sInstance");
        field.setAccessible(true);
        field.set(null, mCdmaSSM);

        //Use reflection to mock singleton
        field = ImsManager.class.getDeclaredField("sImsManagerInstances");
        field.setAccessible(true);
        field.set(null, mImsManagerInstances);

        //Use reflection to mock singleton
        field = SubscriptionController.class.getDeclaredField("sInstance");
        field.setAccessible(true);
        field.set(null, mSubscriptionController);

        field = CdmaSubscriptionSourceManager.class.getDeclaredField(
                "mCdmaSubscriptionSourceChangedRegistrants");
        field.setAccessible(true);
        field.set(mCdmaSSM, mRegistrantList);

        field = SimulatedCommandsVerifier.class.getDeclaredField("sInstance");
        field.setAccessible(true);
        field.set(null, mSimulatedCommandsVerifier);

        mSimulatedCommands = new SimulatedCommands();
        mContextFixture = new ContextFixture();
        mPhone.mCi = mSimulatedCommands;

        doReturn(mSST).when(mTelephonyComponentFactory).
                makeServiceStateTracker(any(GsmCdmaPhone.class), any(CommandsInterface.class));
        doReturn(mIccCardProxy).when(mTelephonyComponentFactory).
                makeIccCardProxy(any(Context.class), any(CommandsInterface.class), anyInt());
        doReturn(mCT).when(mTelephonyComponentFactory).
                makeGsmCdmaCallTracker(any(GsmCdmaPhone.class));
        doReturn(mIccPhoneBookIntManager).when(mTelephonyComponentFactory).
                makeIccPhoneBookInterfaceManager(any(Phone.class));
        doReturn(mDcTracker).when(mTelephonyComponentFactory).
                makeDcTracker(any(Phone.class));
        doReturn(true).when(mImsManagerInstances).containsKey(anyInt());
        doReturn(mIDeviceIdleController).when(mTelephonyComponentFactory).
                getIDeviceIdleController();
        doReturn(mContextFixture.getTestDouble()).when(mPhone).getContext();

        setReady(false);
    }

    protected static void logd(String s) {
        Log.d(TAG, s);
    }
}
 No newline at end of file
Loading