• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.internal.telephony.test;
18 
19 import android.compat.annotation.UnsupportedAppUsage;
20 import android.hardware.radio.RadioError;
21 import android.hardware.radio.V1_0.DataRegStateResult;
22 import android.hardware.radio.V1_0.SetupDataCallResult;
23 import android.hardware.radio.V1_0.VoiceRegStateResult;
24 import android.hardware.radio.modem.ImeiInfo;
25 import android.net.KeepalivePacketData;
26 import android.net.LinkProperties;
27 import android.os.AsyncResult;
28 import android.os.Handler;
29 import android.os.HandlerThread;
30 import android.os.Looper;
31 import android.os.Message;
32 import android.os.Parcel;
33 import android.os.SystemClock;
34 import android.os.WorkSource;
35 import android.telephony.CarrierRestrictionRules;
36 import android.telephony.CellInfo;
37 import android.telephony.CellInfoGsm;
38 import android.telephony.CellSignalStrengthCdma;
39 import android.telephony.CellSignalStrengthGsm;
40 import android.telephony.CellSignalStrengthLte;
41 import android.telephony.CellSignalStrengthNr;
42 import android.telephony.CellSignalStrengthTdscdma;
43 import android.telephony.CellSignalStrengthWcdma;
44 import android.telephony.IccOpenLogicalChannelResponse;
45 import android.telephony.ImsiEncryptionInfo;
46 import android.telephony.NetworkRegistrationInfo;
47 import android.telephony.NetworkScanRequest;
48 import android.telephony.PcoData;
49 import android.telephony.ServiceState;
50 import android.telephony.SignalStrength;
51 import android.telephony.SignalThresholdInfo;
52 import android.telephony.TelephonyManager;
53 import android.telephony.data.DataCallResponse;
54 import android.telephony.data.DataProfile;
55 import android.telephony.data.NetworkSliceInfo;
56 import android.telephony.data.TrafficDescriptor;
57 import android.telephony.emergency.EmergencyNumber;
58 
59 import com.android.internal.annotations.VisibleForTesting;
60 import com.android.internal.telephony.BaseCommands;
61 import com.android.internal.telephony.CallFailCause;
62 import com.android.internal.telephony.CommandException;
63 import com.android.internal.telephony.CommandsInterface;
64 import com.android.internal.telephony.LastCallFailCause;
65 import com.android.internal.telephony.Phone;
66 import com.android.internal.telephony.PhoneConstants;
67 import com.android.internal.telephony.RILUtils;
68 import com.android.internal.telephony.RadioCapability;
69 import com.android.internal.telephony.SmsResponse;
70 import com.android.internal.telephony.SrvccConnection;
71 import com.android.internal.telephony.UUSInfo;
72 import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
73 import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
74 import com.android.internal.telephony.gsm.SuppServiceNotification;
75 import com.android.internal.telephony.uicc.AdnCapacity;
76 import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState;
77 import com.android.internal.telephony.uicc.IccCardStatus;
78 import com.android.internal.telephony.uicc.IccIoResult;
79 import com.android.internal.telephony.uicc.IccSlotStatus;
80 import com.android.internal.telephony.uicc.ReceivedPhonebookRecords;
81 import com.android.internal.telephony.uicc.SimPhonebookRecord;
82 import com.android.telephony.Rlog;
83 
84 import java.util.ArrayList;
85 import java.util.List;
86 import java.util.concurrent.atomic.AtomicBoolean;
87 import java.util.concurrent.atomic.AtomicInteger;
88 
89 public class SimulatedCommands extends BaseCommands
90         implements CommandsInterface, SimulatedRadioControl {
91     private static final String LOG_TAG = "SimulatedCommands";
92     private boolean mSupportsEid = true;
93 
94     private enum SimLockState {
95         NONE,
96         REQUIRE_PIN,
97         REQUIRE_PUK,
98         SIM_PERM_LOCKED
99     }
100 
101     private enum SimFdnState {
102         NONE,
103         REQUIRE_PIN2,
104         REQUIRE_PUK2,
105         SIM_PERM_LOCKED
106     }
107 
108     private static final SimLockState INITIAL_LOCK_STATE = SimLockState.NONE;
109     public static final String DEFAULT_SIM_PIN_CODE = "1234";
110     private static final String SIM_PUK_CODE = "12345678";
111     private static final SimFdnState INITIAL_FDN_STATE = SimFdnState.NONE;
112     public static final String DEFAULT_SIM_PIN2_CODE = "5678";
113     private static final String SIM_PUK2_CODE = "87654321";
114     public static final String FAKE_LONG_NAME = "Fake long name";
115     public static final String FAKE_SHORT_NAME = "Fake short name";
116     public static final String FAKE_MCC_MNC = "310260";
117     public static final String FAKE_IMEI = "012345678901234";
118     public static final String FAKE_IMEISV = "99";
119     public static final String FAKE_ESN = "1234";
120     public static final String FAKE_MEID = "1234";
121     public static final int DEFAULT_PIN1_ATTEMPT = 5;
122     public static final int DEFAULT_PIN2_ATTEMPT = 5;
123     public static final int ICC_AUTHENTICATION_MODE_DEFAULT = 0;
124     public static final int ICC_AUTHENTICATION_MODE_NULL = 1;
125     public static final int ICC_AUTHENTICATION_MODE_TIMEOUT = 2;
126     // Maximum time in millisecond to wait for a IccSim Challenge before assuming it will not
127     // arrive and returning null to the callers.
128     public static final  long ICC_SIM_CHALLENGE_TIMEOUT_MILLIS = 2500;
129 
130     private String mImei;
131     private String mImeiSv;
132 
133     //***** Instance Variables
134 
135     @UnsupportedAppUsage
136     SimulatedGsmCallState simulatedCallState;
137     HandlerThread mHandlerThread;
138     SimLockState mSimLockedState;
139     boolean mSimLockEnabled;
140     int mPinUnlockAttempts;
141     int mPukUnlockAttempts;
142     String mPinCode;
143     int mPin1attemptsRemaining = DEFAULT_PIN1_ATTEMPT;
144     SimFdnState mSimFdnEnabledState;
145     boolean mSimFdnEnabled;
146     int mPin2UnlockAttempts;
147     int mPuk2UnlockAttempts;
148     int mPreferredNetworkType;
149     int mAllowedNetworkType;
150     String mPin2Code;
151     boolean mSsnNotifyOn = false;
152     private int mVoiceRegState = NetworkRegistrationInfo.REGISTRATION_STATE_HOME;
153     private int mVoiceRadioTech = ServiceState.RIL_RADIO_TECHNOLOGY_UMTS;
154     private int mDataRegState = NetworkRegistrationInfo.REGISTRATION_STATE_HOME;
155     private int mDataRadioTech = ServiceState.RIL_RADIO_TECHNOLOGY_UMTS;
156     public boolean mCssSupported;
157     public int mRoamingIndicator;
158     public int mSystemIsInPrl;
159     public int mDefaultRoamingIndicator;
160     public int mReasonForDenial;
161     public int mMaxDataCalls;
162     public boolean mSendSetGsmBroadcastConfigResponse = true;
163     public boolean mSendGetSmscAddressResponse = true;
164 
165     private SignalStrength mSignalStrength;
166     private List<CellInfo> mCellInfoList = null;
167     private boolean mShouldReturnCellInfo = true;
168     private int[] mImsRegState;
169     private IccCardStatus mIccCardStatus;
170     private IccSlotStatus mIccSlotStatus;
171     private IccIoResult mIccIoResultForApduLogicalChannel;
172     private int mChannelId = IccOpenLogicalChannelResponse.INVALID_CHANNEL;
173 
174     private Object mDataRegStateResult;
175     private Object mVoiceRegStateResult;
176 
177     int mPausedResponseCount;
178     ArrayList<Message> mPausedResponses = new ArrayList<Message>();
179 
180     int mNextCallFailCause = CallFailCause.NORMAL_CLEARING;
181 
182     @UnsupportedAppUsage
183     private boolean mDcSuccess = true;
184     private SetupDataCallResult mSetupDataCallResult;
185     private boolean mIsRadioPowerFailResponse = false;
186     private boolean mIsReportSmsMemoryStatusFailResponse = false;
187 
188     public boolean mSetRadioPowerForEmergencyCall;
189     public boolean mSetRadioPowerAsSelectedPhoneForEmergencyCall;
190 
191     public boolean mCallWaitActivated = false;
192     private SrvccConnection[] mSrvccConnections;
193 
194     // mode for Icc Sim Authentication
195     private int mAuthenticationMode;
196 
197     private int[] mImsRegistrationInfo = new int[4];
198 
199     private boolean mN1ModeEnabled = false;
200     private boolean mVonrEnabled = false;
201 
202     //***** Constructor
203     public
SimulatedCommands()204     SimulatedCommands() {
205         super(null);  // Don't log statistics
206         mHandlerThread = new HandlerThread("SimulatedCommands");
207         mHandlerThread.start();
208         Looper looper = mHandlerThread.getLooper();
209 
210         simulatedCallState = new SimulatedGsmCallState(looper);
211 
212         setRadioState(TelephonyManager.RADIO_POWER_ON, false /* forceNotifyRegistrants */);
213         mSimLockedState = INITIAL_LOCK_STATE;
214         mSimLockEnabled = (mSimLockedState != SimLockState.NONE);
215         mPinCode = DEFAULT_SIM_PIN_CODE;
216         mSimFdnEnabledState = INITIAL_FDN_STATE;
217         mSimFdnEnabled = (mSimFdnEnabledState != SimFdnState.NONE);
218         mPin2Code = DEFAULT_SIM_PIN2_CODE;
219         mAuthenticationMode = ICC_AUTHENTICATION_MODE_DEFAULT;
220     }
221 
dispose()222     public void dispose() throws Exception {
223         if (mHandlerThread != null) {
224             mHandlerThread.quit();
225             mHandlerThread.join();
226         }
227     }
228 
log(String str)229     private void log(String str) {
230         Rlog.d(LOG_TAG, str);
231     }
232 
233     //***** CommandsInterface implementation
234 
235     @Override
getIccCardStatus(Message result)236     public void getIccCardStatus(Message result) {
237         SimulatedCommandsVerifier.getInstance().getIccCardStatus(result);
238         if (mIccCardStatus != null) {
239             resultSuccess(result, mIccCardStatus);
240         } else {
241             resultFail(result, null, new RuntimeException("IccCardStatus not set"));
242         }
243     }
244 
setIccSlotStatus(IccSlotStatus iccSlotStatus)245     public void setIccSlotStatus(IccSlotStatus iccSlotStatus) {
246         mIccSlotStatus = iccSlotStatus;
247     }
248 
249     @Override
getIccSlotsStatus(Message result)250     public void getIccSlotsStatus(Message result) {
251         SimulatedCommandsVerifier.getInstance().getIccSlotsStatus(result);
252         if (mIccSlotStatus != null) {
253             resultSuccess(result, mIccSlotStatus);
254         } else {
255             resultFail(result, null,
256                     new CommandException(CommandException.Error.REQUEST_NOT_SUPPORTED));
257         }
258     }
259 
260     @Override
setLogicalToPhysicalSlotMapping(int[] physicalSlots, Message result)261     public void setLogicalToPhysicalSlotMapping(int[] physicalSlots, Message result) {
262         unimplemented(result);
263     }
264 
265     @Override
supplyIccPin(String pin, Message result)266     public void supplyIccPin(String pin, Message result)  {
267         if (mSimLockedState != SimLockState.REQUIRE_PIN) {
268             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPin: wrong state, state=" +
269                     mSimLockedState);
270             CommandException ex = new CommandException(
271                     CommandException.Error.PASSWORD_INCORRECT);
272             resultFail(result, null, ex);
273             return;
274         }
275 
276         if (pin != null && pin.equals(mPinCode)) {
277             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPin: success!");
278             mPinUnlockAttempts = 0;
279             mSimLockedState = SimLockState.NONE;
280             mIccStatusChangedRegistrants.notifyRegistrants();
281 
282             resultSuccess(result, null);
283 
284             return;
285         }
286 
287         if (result != null) {
288             mPinUnlockAttempts ++;
289 
290             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPin: failed! attempt=" +
291                     mPinUnlockAttempts);
292             if (mPinUnlockAttempts >= DEFAULT_PIN1_ATTEMPT) {
293                 Rlog.i(LOG_TAG, "[SimCmd] supplyIccPin: set state to REQUIRE_PUK");
294                 mSimLockedState = SimLockState.REQUIRE_PUK;
295             }
296 
297             CommandException ex = new CommandException(
298                     CommandException.Error.PASSWORD_INCORRECT);
299             resultFail(result, null, ex);
300         }
301     }
302 
303     @Override
supplyIccPuk(String puk, String newPin, Message result)304     public void supplyIccPuk(String puk, String newPin, Message result)  {
305         if (mSimLockedState != SimLockState.REQUIRE_PUK) {
306             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPuk: wrong state, state=" +
307                     mSimLockedState);
308             CommandException ex = new CommandException(
309                     CommandException.Error.PASSWORD_INCORRECT);
310             resultFail(result, null, ex);
311             return;
312         }
313 
314         if (puk != null && puk.equals(SIM_PUK_CODE)) {
315             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPuk: success!");
316             mSimLockedState = SimLockState.NONE;
317             mPukUnlockAttempts = 0;
318             mIccStatusChangedRegistrants.notifyRegistrants();
319 
320             resultSuccess(result, null);
321             return;
322         }
323 
324         if (result != null) {
325             mPukUnlockAttempts ++;
326 
327             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPuk: failed! attempt=" +
328                     mPukUnlockAttempts);
329             if (mPukUnlockAttempts >= 10) {
330                 Rlog.i(LOG_TAG, "[SimCmd] supplyIccPuk: set state to SIM_PERM_LOCKED");
331                 mSimLockedState = SimLockState.SIM_PERM_LOCKED;
332             }
333 
334             CommandException ex = new CommandException(
335                     CommandException.Error.PASSWORD_INCORRECT);
336             resultFail(result, null, ex);
337         }
338     }
339 
340     @Override
supplyIccPin2(String pin2, Message result)341     public void supplyIccPin2(String pin2, Message result)  {
342         if (mSimFdnEnabledState != SimFdnState.REQUIRE_PIN2) {
343             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPin2: wrong state, state=" +
344                     mSimFdnEnabledState);
345             CommandException ex = new CommandException(
346                     CommandException.Error.PASSWORD_INCORRECT);
347             resultFail(result, null, ex);
348             return;
349         }
350 
351         if (pin2 != null && pin2.equals(mPin2Code)) {
352             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPin2: success!");
353             mPin2UnlockAttempts = 0;
354             mSimFdnEnabledState = SimFdnState.NONE;
355 
356             resultSuccess(result, null);
357             return;
358         }
359 
360         if (result != null) {
361             mPin2UnlockAttempts ++;
362 
363             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPin2: failed! attempt=" +
364                     mPin2UnlockAttempts);
365             if (mPin2UnlockAttempts >= DEFAULT_PIN2_ATTEMPT) {
366                 Rlog.i(LOG_TAG, "[SimCmd] supplyIccPin2: set state to REQUIRE_PUK2");
367                 mSimFdnEnabledState = SimFdnState.REQUIRE_PUK2;
368             }
369 
370             CommandException ex = new CommandException(
371                     CommandException.Error.PASSWORD_INCORRECT);
372             resultFail(result, null, ex);
373         }
374     }
375 
376     @Override
supplyIccPuk2(String puk2, String newPin2, Message result)377     public void supplyIccPuk2(String puk2, String newPin2, Message result)  {
378         if (mSimFdnEnabledState != SimFdnState.REQUIRE_PUK2) {
379             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPuk2: wrong state, state=" +
380                     mSimLockedState);
381             CommandException ex = new CommandException(
382                     CommandException.Error.PASSWORD_INCORRECT);
383             resultFail(result, null, ex);
384             return;
385         }
386 
387         if (puk2 != null && puk2.equals(SIM_PUK2_CODE)) {
388             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPuk2: success!");
389             mSimFdnEnabledState = SimFdnState.NONE;
390             mPuk2UnlockAttempts = 0;
391 
392             resultSuccess(result, null);
393             return;
394         }
395 
396         if (result != null) {
397             mPuk2UnlockAttempts ++;
398 
399             Rlog.i(LOG_TAG, "[SimCmd] supplyIccPuk2: failed! attempt=" +
400                     mPuk2UnlockAttempts);
401             if (mPuk2UnlockAttempts >= 10) {
402                 Rlog.i(LOG_TAG, "[SimCmd] supplyIccPuk2: set state to SIM_PERM_LOCKED");
403                 mSimFdnEnabledState = SimFdnState.SIM_PERM_LOCKED;
404             }
405 
406             CommandException ex = new CommandException(
407                     CommandException.Error.PASSWORD_INCORRECT);
408             resultFail(result, null, ex);
409         }
410     }
411 
412     @Override
changeIccPin(String oldPin, String newPin, Message result)413     public void changeIccPin(String oldPin, String newPin, Message result)  {
414         if (oldPin != null && oldPin.equals(mPinCode)) {
415             mPinCode = newPin;
416             resultSuccess(result, null);
417 
418             return;
419         }
420 
421         Rlog.i(LOG_TAG, "[SimCmd] changeIccPin: pin failed!");
422 
423         CommandException ex = new CommandException(
424                 CommandException.Error.PASSWORD_INCORRECT);
425         resultFail(result, null, ex);
426     }
427 
428     @Override
changeIccPin2(String oldPin2, String newPin2, Message result)429     public void changeIccPin2(String oldPin2, String newPin2, Message result) {
430         if (oldPin2 != null && oldPin2.equals(mPin2Code)) {
431             mPin2Code = newPin2;
432             resultSuccess(result, null);
433 
434             return;
435         }
436 
437         Rlog.i(LOG_TAG, "[SimCmd] changeIccPin2: pin2 failed!");
438 
439         CommandException ex = new CommandException(
440                 CommandException.Error.PASSWORD_INCORRECT);
441         resultFail(result, null, ex);
442     }
443 
444     @Override
445     public void
changeBarringPassword(String facility, String oldPwd, String newPwd, Message result)446     changeBarringPassword(String facility, String oldPwd, String newPwd, Message result) {
447         unimplemented(result);
448     }
449 
450     @Override
451     public void
setSuppServiceNotifications(boolean enable, Message result)452     setSuppServiceNotifications(boolean enable, Message result) {
453         resultSuccess(result, null);
454 
455         if (enable && mSsnNotifyOn) {
456             Rlog.w(LOG_TAG, "Supp Service Notifications already enabled!");
457         }
458 
459         mSsnNotifyOn = enable;
460     }
461 
462     @Override
queryFacilityLock(String facility, String pin, int serviceClass, Message result)463     public void queryFacilityLock(String facility, String pin,
464                                    int serviceClass, Message result) {
465         queryFacilityLockForApp(facility, pin, serviceClass, null, result);
466     }
467 
468     @Override
queryFacilityLockForApp(String facility, String pin, int serviceClass, String appId, Message result)469     public void queryFacilityLockForApp(String facility, String pin, int serviceClass,
470             String appId, Message result) {
471         if (facility != null && facility.equals(CommandsInterface.CB_FACILITY_BA_SIM)) {
472             if (result != null) {
473                 int[] r = new int[1];
474                 r[0] = (mSimLockEnabled ? 1 : 0);
475                 Rlog.i(LOG_TAG, "[SimCmd] queryFacilityLock: SIM is "
476                         + (r[0] == 0 ? "unlocked" : "locked"));
477                 resultSuccess(result, r);
478             }
479             return;
480         } else if (facility != null && facility.equals(CommandsInterface.CB_FACILITY_BA_FD)) {
481             if (result != null) {
482                 int[] r = new int[1];
483                 r[0] = (mSimFdnEnabled ? 1 : 0);
484                 Rlog.i(LOG_TAG, "[SimCmd] queryFacilityLock: FDN is "
485                         + (r[0] == 0 ? "disabled" : "enabled"));
486                 resultSuccess(result, r);
487             }
488             return;
489         }
490 
491         unimplemented(result);
492     }
493 
494     @Override
setFacilityLock(String facility, boolean lockEnabled, String pin, int serviceClass, Message result)495     public void setFacilityLock(String facility, boolean lockEnabled, String pin, int serviceClass,
496             Message result) {
497         setFacilityLockForApp(facility, lockEnabled, pin, serviceClass, null, result);
498     }
499 
500     @Override
setFacilityLockForApp(String facility, boolean lockEnabled, String pin, int serviceClass, String appId, Message result)501     public void setFacilityLockForApp(String facility, boolean lockEnabled,
502                                  String pin, int serviceClass, String appId,
503                                  Message result) {
504         if (facility != null &&
505                 facility.equals(CommandsInterface.CB_FACILITY_BA_SIM)) {
506             if (pin != null && pin.equals(mPinCode)) {
507                 Rlog.i(LOG_TAG, "[SimCmd] setFacilityLock: pin is valid");
508                 mSimLockEnabled = lockEnabled;
509 
510                 resultSuccess(result, null);
511 
512                 return;
513             }
514 
515             Rlog.i(LOG_TAG, "[SimCmd] setFacilityLock: pin failed!");
516 
517             CommandException ex = new CommandException(
518                     CommandException.Error.GENERIC_FAILURE);
519             resultFail(result, null, ex);
520 
521             return;
522         }  else if (facility != null &&
523                 facility.equals(CommandsInterface.CB_FACILITY_BA_FD)) {
524             if (pin != null && pin.equals(mPin2Code)) {
525                 Rlog.i(LOG_TAG, "[SimCmd] setFacilityLock: pin2 is valid");
526                 mSimFdnEnabled = lockEnabled;
527 
528                 resultSuccess(result, null);
529 
530                 return;
531             }
532 
533             Rlog.i(LOG_TAG, "[SimCmd] setFacilityLock: pin2 failed!");
534 
535             CommandException ex = new CommandException(
536                     CommandException.Error.GENERIC_FAILURE);
537             resultFail(result, null, ex);
538 
539             return;
540         }
541 
542         unimplemented(result);
543     }
544 
545     @Override
supplyNetworkDepersonalization(String netpin, Message result)546     public void supplyNetworkDepersonalization(String netpin, Message result) {
547         unimplemented(result);
548     }
549 
550     @Override
supplySimDepersonalization(PersoSubState persoType, String conrolKey, Message result)551     public void supplySimDepersonalization(PersoSubState persoType,
552             String conrolKey, Message result) {
553         unimplemented(result);
554     }
555 
556     /**
557      *  returned message
558      *  retMsg.obj = AsyncResult ar
559      *  ar.exception carries exception on failure
560      *  ar.userObject contains the original value of result.obj
561      *  ar.result contains a List of DriverCall
562      *      The ar.result List is sorted by DriverCall.index
563      */
564     @Override
getCurrentCalls(Message result)565     public void getCurrentCalls (Message result) {
566         SimulatedCommandsVerifier.getInstance().getCurrentCalls(result);
567         if ((mState == TelephonyManager.RADIO_POWER_ON) && !isSimLocked()) {
568             //Rlog.i("GSM", "[SimCmds] getCurrentCalls");
569             resultSuccess(result, simulatedCallState.getDriverCalls());
570         } else {
571             //Rlog.i("GSM", "[SimCmds] getCurrentCalls: RADIO_OFF or SIM not ready!");
572             resultFail(result, null,
573                 new CommandException(CommandException.Error.RADIO_NOT_AVAILABLE));
574         }
575     }
576 
577     /**
578      *  @deprecated
579      */
580     @Deprecated
581     @Override
getPDPContextList(Message result)582     public void getPDPContextList(Message result) {
583         getDataCallList(result);
584     }
585 
586     /**
587      *  returned message
588      *  retMsg.obj = AsyncResult ar
589      *  ar.exception carries exception on failure
590      *  ar.userObject contains the original value of result.obj
591      *  ar.result contains a List of DataCallResponse
592      */
593     @Override
getDataCallList(Message result)594     public void getDataCallList(Message result) {
595         ArrayList<SetupDataCallResult> dcCallList = new ArrayList<SetupDataCallResult>(0);
596         SimulatedCommandsVerifier.getInstance().getDataCallList(result);
597         if (mSetupDataCallResult != null) {
598             dcCallList.add(mSetupDataCallResult);
599         }
600         resultSuccess(result, dcCallList);
601     }
602 
603     /**
604      *  returned message
605      *  retMsg.obj = AsyncResult ar
606      *  ar.exception carries exception on failure
607      *  ar.userObject contains the original value of result.obj
608      *  ar.result is null on success and failure
609      *
610      * CLIR_DEFAULT     == on "use subscription default value"
611      * CLIR_SUPPRESSION == on "CLIR suppression" (allow CLI presentation)
612      * CLIR_INVOCATION  == on "CLIR invocation" (restrict CLI presentation)
613      */
614     @Override
dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, Message result)615     public void dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo,
616                      boolean hasKnownUserIntentEmergency, int clirMode, Message result) {
617         SimulatedCommandsVerifier.getInstance().dial(address, isEmergencyCall,
618                 emergencyNumberInfo, hasKnownUserIntentEmergency, clirMode, result);
619         simulatedCallState.onDial(address);
620 
621         resultSuccess(result, null);
622     }
623 
624     /**
625      *  returned message
626      *  retMsg.obj = AsyncResult ar
627      *  ar.exception carries exception on failure
628      *  ar.userObject contains the original value of result.obj
629      *  ar.result is null on success and failure
630      *
631      * CLIR_DEFAULT     == on "use subscription default value"
632      * CLIR_SUPPRESSION == on "CLIR suppression" (allow CLI presentation)
633      * CLIR_INVOCATION  == on "CLIR invocation" (restrict CLI presentation)
634      */
635     @Override
dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo, boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo, Message result)636     public void dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo,
637                      boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo,
638                      Message result) {
639         SimulatedCommandsVerifier.getInstance().dial(address, isEmergencyCall,
640                 emergencyNumberInfo, hasKnownUserIntentEmergency, clirMode, uusInfo, result);
641         simulatedCallState.onDial(address);
642 
643         resultSuccess(result, null);
644     }
645 
646     @Override
getIMSI(Message result)647     public void getIMSI(Message result) {
648         getIMSIForApp(null, result);
649     }
650     /**
651      *  returned message
652      *  retMsg.obj = AsyncResult ar
653      *  ar.exception carries exception on failure
654      *  ar.userObject contains the original value of result.obj
655      *  ar.result is String containing IMSI on success
656      */
657     @Override
getIMSIForApp(String aid, Message result)658     public void getIMSIForApp(String aid, Message result) {
659         resultSuccess(result, "012345678901234");
660     }
661 
setIMEI(String imei)662     public void setIMEI(String imei) {
663         mImei = imei;
664     }
665 
666     /**
667      *  returned message
668      *  retMsg.obj = AsyncResult ar
669      *  ar.exception carries exception on failure
670      *  ar.userObject contains the original value of result.obj
671      *  ar.result is String containing IMEI on success
672      */
673     @Override
getIMEI(Message result)674     public void getIMEI(Message result) {
675         SimulatedCommandsVerifier.getInstance().getIMEI(result);
676         resultSuccess(result, mImei != null ? mImei : FAKE_IMEI);
677     }
678 
setIMEISV(String imeisv)679     public void setIMEISV(String imeisv) {
680         mImeiSv = imeisv;
681     }
682 
683     /**
684      *  returned message
685      *  retMsg.obj = AsyncResult ar
686      *  ar.exception carries exception on failure
687      *  ar.userObject contains the original value of result.obj
688      *  ar.result is String containing IMEISV on success
689      */
690     @Override
getIMEISV(Message result)691     public void getIMEISV(Message result) {
692         SimulatedCommandsVerifier.getInstance().getIMEISV(result);
693         resultSuccess(result, mImeiSv != null ? mImeiSv : FAKE_IMEISV);
694     }
695 
696     /**
697      * Hang up one individual connection.
698      *  returned message
699      *  retMsg.obj = AsyncResult ar
700      *  ar.exception carries exception on failure
701      *  ar.userObject contains the original value of result.obj
702      *  ar.result is null on success and failure
703      *
704      *  3GPP 22.030 6.5.5
705      *  "Releases a specific active call X"
706      */
707     @Override
hangupConnection(int gsmIndex, Message result)708     public void hangupConnection (int gsmIndex, Message result) {
709         boolean success;
710 
711         success = simulatedCallState.onChld('1', (char)('0'+gsmIndex));
712 
713         if (!success){
714             Rlog.i("GSM", "[SimCmd] hangupConnection: resultFail");
715             resultFail(result, null, new RuntimeException("Hangup Error"));
716         } else {
717             Rlog.i("GSM", "[SimCmd] hangupConnection: resultSuccess");
718             resultSuccess(result, null);
719         }
720     }
721 
722     /**
723      * 3GPP 22.030 6.5.5
724      *  "Releases all held calls or sets User Determined User Busy (UDUB)
725      *   for a waiting call."
726      *  ar.exception carries exception on failure
727      *  ar.userObject contains the original value of result.obj
728      *  ar.result is null on success and failure
729      */
730     @Override
hangupWaitingOrBackground(Message result)731     public void hangupWaitingOrBackground (Message result) {
732         boolean success;
733 
734         success = simulatedCallState.onChld('0', '\0');
735 
736         if (!success){
737             resultFail(result, null, new RuntimeException("Hangup Error"));
738         } else {
739             resultSuccess(result, null);
740         }
741     }
742 
743     /**
744      * 3GPP 22.030 6.5.5
745      * "Releases all active calls (if any exist) and accepts
746      *  the other (held or waiting) call."
747      *
748      *  ar.exception carries exception on failure
749      *  ar.userObject contains the original value of result.obj
750      *  ar.result is null on success and failure
751      */
752     @Override
hangupForegroundResumeBackground(Message result)753     public void hangupForegroundResumeBackground (Message result) {
754         boolean success;
755 
756         success = simulatedCallState.onChld('1', '\0');
757 
758         if (!success){
759             resultFail(result, null, new RuntimeException("Hangup Error"));
760         } else {
761             resultSuccess(result, null);
762         }
763     }
764 
765     /**
766      * 3GPP 22.030 6.5.5
767      * "Places all active calls (if any exist) on hold and accepts
768      *  the other (held or waiting) call."
769      *
770      *  ar.exception carries exception on failure
771      *  ar.userObject contains the original value of result.obj
772      *  ar.result is null on success and failure
773      */
774     @Override
switchWaitingOrHoldingAndActive(Message result)775     public void switchWaitingOrHoldingAndActive (Message result) {
776         boolean success;
777 
778         success = simulatedCallState.onChld('2', '\0');
779 
780         if (!success){
781             resultFail(result, null, new RuntimeException("Hangup Error"));
782         } else {
783             resultSuccess(result, null);
784         }
785     }
786 
787     /**
788      * 3GPP 22.030 6.5.5
789      * "Adds a held call to the conversation"
790      *
791      *  ar.exception carries exception on failure
792      *  ar.userObject contains the original value of result.obj
793      *  ar.result is null on success and failure
794      */
795     @Override
conference(Message result)796     public void conference (Message result) {
797         boolean success;
798 
799         success = simulatedCallState.onChld('3', '\0');
800 
801         if (!success){
802             resultFail(result, null, new RuntimeException("Hangup Error"));
803         } else {
804             resultSuccess(result, null);
805         }
806     }
807 
808     /**
809      * 3GPP 22.030 6.5.5
810      * "Connects the two calls and disconnects the subscriber from both calls"
811      *
812      *  ar.exception carries exception on failure
813      *  ar.userObject contains the original value of result.obj
814      *  ar.result is null on success and failure
815      */
816     @Override
explicitCallTransfer(Message result)817     public void explicitCallTransfer (Message result) {
818         boolean success;
819 
820         success = simulatedCallState.onChld('4', '\0');
821 
822         if (!success){
823             resultFail(result, null, new RuntimeException("Hangup Error"));
824         } else {
825             resultSuccess(result, null);
826         }
827     }
828 
829     /**
830      * 3GPP 22.030 6.5.5
831      * "Places all active calls on hold except call X with which
832      *  communication shall be supported."
833      */
834     @Override
separateConnection(int gsmIndex, Message result)835     public void separateConnection (int gsmIndex, Message result) {
836         boolean success;
837 
838         char ch = (char)(gsmIndex + '0');
839         success = simulatedCallState.onChld('2', ch);
840 
841         if (!success){
842             resultFail(result, null, new RuntimeException("Hangup Error"));
843         } else {
844             resultSuccess(result, null);
845         }
846     }
847 
848     /**
849      *
850      *  ar.exception carries exception on failure
851      *  ar.userObject contains the original value of result.obj
852      *  ar.result is null on success and failure
853      */
854     @UnsupportedAppUsage
855     @Override
acceptCall(Message result)856     public void acceptCall (Message result) {
857         boolean success;
858 
859         SimulatedCommandsVerifier.getInstance().acceptCall(result);
860         success = simulatedCallState.onAnswer();
861 
862         if (!success){
863             resultFail(result, null, new RuntimeException("Hangup Error"));
864         } else {
865             resultSuccess(result, null);
866         }
867     }
868 
869     /**
870      *  also known as UDUB
871      *  ar.exception carries exception on failure
872      *  ar.userObject contains the original value of result.obj
873      *  ar.result is null on success and failure
874      */
875     @Override
rejectCall(Message result)876     public void rejectCall (Message result) {
877         boolean success;
878 
879         success = simulatedCallState.onChld('0', '\0');
880 
881         if (!success){
882             resultFail(result, null, new RuntimeException("Hangup Error"));
883         } else {
884             resultSuccess(result, null);
885         }
886     }
887 
888     /**
889      * cause code returned as Integer in Message.obj.response
890      * Returns integer cause code defined in TS 24.008
891      * Annex H or closest approximation.
892      * Most significant codes:
893      * - Any defined in 22.001 F.4 (for generating busy/congestion)
894      * - Cause 68: ACM >= ACMMax
895      */
896     @Override
getLastCallFailCause(Message result)897     public void getLastCallFailCause (Message result) {
898         LastCallFailCause mFailCause = new LastCallFailCause();
899         mFailCause.causeCode = mNextCallFailCause;
900         resultSuccess(result, mFailCause);
901     }
902 
903     /**
904      * @deprecated
905      */
906     @Deprecated
907     @Override
getLastPdpFailCause(Message result)908     public void getLastPdpFailCause (Message result) {
909         unimplemented(result);
910     }
911 
912     @Override
getLastDataCallFailCause(Message result)913     public void getLastDataCallFailCause(Message result) {
914         //
915         unimplemented(result);
916     }
917 
918     @Override
setMute(boolean enableMute, Message result)919     public void setMute (boolean enableMute, Message result) {unimplemented(result);}
920 
921     @Override
getMute(Message result)922     public void getMute (Message result) {unimplemented(result);}
923 
setSignalStrength(SignalStrength signalStrength)924     public void setSignalStrength(SignalStrength signalStrength) {
925         mSignalStrength = signalStrength;
926     }
927 
928     @Override
getSignalStrength(Message result)929     public void getSignalStrength (Message result) {
930         if (mSignalStrength == null) {
931             mSignalStrength = new SignalStrength(
932                     new CellSignalStrengthCdma(),
933                     new CellSignalStrengthGsm(20, 0, CellInfo.UNAVAILABLE),
934                     new CellSignalStrengthWcdma(),
935                     new CellSignalStrengthTdscdma(),
936                     new CellSignalStrengthLte(),
937                     new CellSignalStrengthNr());
938         }
939         resultSuccess(result, mSignalStrength);
940     }
941 
942      /**
943      * Assign a specified band for RF configuration.
944      *
945      * @param bandMode one of BM_*_BAND
946      * @param result is callback message
947      */
948     @Override
setBandMode(int bandMode, Message result)949     public void setBandMode (int bandMode, Message result) {
950         resultSuccess(result, null);
951     }
952 
953     /**
954      * Query the list of band mode supported by RF.
955      *
956      * @param result is callback message
957      *        ((AsyncResult)response.obj).result  is an int[] where int[0] is
958      *        the size of the array and the rest of each element representing
959      *        one available BM_*_BAND
960      */
961     @Override
queryAvailableBandMode(Message result)962     public void queryAvailableBandMode (Message result) {
963         int ret[] = new int [4];
964 
965         ret[0] = 4;
966         ret[1] = Phone.BM_US_BAND;
967         ret[2] = Phone.BM_JPN_BAND;
968         ret[3] = Phone.BM_AUS_BAND;
969 
970         resultSuccess(result, ret);
971     }
972 
973     /**
974      * {@inheritDoc}
975      */
976     @Override
sendTerminalResponse(String contents, Message response)977     public void sendTerminalResponse(String contents, Message response) {
978         resultSuccess(response, null);
979     }
980 
981     /**
982      * {@inheritDoc}
983      */
984     @Override
sendEnvelope(String contents, Message response)985     public void sendEnvelope(String contents, Message response) {
986         resultSuccess(response, null);
987     }
988 
989     /**
990      * {@inheritDoc}
991      */
992     @Override
sendEnvelopeWithStatus(String contents, Message response)993     public void sendEnvelopeWithStatus(String contents, Message response) {
994         resultSuccess(response, null);
995     }
996 
997     /**
998      * {@inheritDoc}
999      */
1000     @Override
handleCallSetupRequestFromSim( boolean accept, Message response)1001     public void handleCallSetupRequestFromSim(
1002             boolean accept, Message response) {
1003         resultSuccess(response, null);
1004     }
1005 
setVoiceRadioTech(int voiceRadioTech)1006     public void setVoiceRadioTech(int voiceRadioTech) {
1007         mVoiceRadioTech = voiceRadioTech;
1008     }
1009 
setVoiceRegState(int voiceRegState)1010     public void setVoiceRegState(int voiceRegState) {
1011         mVoiceRegState = voiceRegState;
1012     }
1013 
1014     /**
1015      * response.obj.result is an String[14]
1016      * See ril.h for details
1017      *
1018      * Please note that registration state 4 ("unknown") is treated
1019      * as "out of service" above
1020      */
1021     @Override
getVoiceRegistrationState(Message result)1022     public void getVoiceRegistrationState(Message result) {
1023         mGetVoiceRegistrationStateCallCount.incrementAndGet();
1024 
1025         Object ret = mVoiceRegStateResult;
1026         if (ret == null) {
1027             ret = new VoiceRegStateResult();
1028             ((VoiceRegStateResult) ret).regState = mVoiceRegState;
1029             ((VoiceRegStateResult) ret).rat = mVoiceRadioTech;
1030             ((VoiceRegStateResult) ret).cssSupported = mCssSupported;
1031             ((VoiceRegStateResult) ret).roamingIndicator = mRoamingIndicator;
1032             ((VoiceRegStateResult) ret).systemIsInPrl = mSystemIsInPrl;
1033             ((VoiceRegStateResult) ret).defaultRoamingIndicator = mDefaultRoamingIndicator;
1034             ((VoiceRegStateResult) ret).reasonForDenial = mReasonForDenial;
1035         }
1036 
1037         resultSuccess(result, ret);
1038     }
1039 
1040     private final AtomicInteger mGetVoiceRegistrationStateCallCount = new AtomicInteger(0);
1041 
1042     @VisibleForTesting
getGetVoiceRegistrationStateCallCount()1043     public int getGetVoiceRegistrationStateCallCount() {
1044         return mGetVoiceRegistrationStateCallCount.get();
1045     }
1046 
setDataRadioTech(int radioTech)1047     public void setDataRadioTech(int radioTech) {
1048         mDataRadioTech = radioTech;
1049     }
1050 
setDataRegState(int dataRegState)1051     public void setDataRegState(int dataRegState) {
1052         mDataRegState = dataRegState;
1053     }
1054 
1055     @Override
getDataRegistrationState(Message result)1056     public void getDataRegistrationState(Message result) {
1057         mGetDataRegistrationStateCallCount.incrementAndGet();
1058 
1059         Object ret = mDataRegStateResult;
1060         if (ret == null) {
1061             ret = new DataRegStateResult();
1062             ((DataRegStateResult) ret).regState = mDataRegState;
1063             ((DataRegStateResult) ret).rat = mDataRadioTech;
1064             ((DataRegStateResult) ret).maxDataCalls = mMaxDataCalls;
1065             ((DataRegStateResult) ret).reasonDataDenied = mReasonForDenial;
1066         }
1067 
1068         resultSuccess(result, ret);
1069     }
1070 
1071     private final AtomicInteger mGetDataRegistrationStateCallCount = new AtomicInteger(0);
1072 
1073     @VisibleForTesting
getGetDataRegistrationStateCallCount()1074     public int getGetDataRegistrationStateCallCount() {
1075         return mGetDataRegistrationStateCallCount.get();
1076     }
1077 
1078     /**
1079      * response.obj.result is a String[3]
1080      * response.obj.result[0] is long alpha or null if unregistered
1081      * response.obj.result[1] is short alpha or null if unregistered
1082      * response.obj.result[2] is numeric or null if unregistered
1083      */
1084     @Override
getOperator(Message result)1085     public void getOperator(Message result) {
1086         mGetOperatorCallCount.incrementAndGet();
1087         String[] ret = new String[3];
1088 
1089         ret[0] = FAKE_LONG_NAME;
1090         ret[1] = FAKE_SHORT_NAME;
1091         ret[2] = FAKE_MCC_MNC;
1092 
1093         resultSuccess(result, ret);
1094     }
1095 
1096     private final AtomicInteger mGetOperatorCallCount = new AtomicInteger(0);
1097 
1098     @VisibleForTesting
getGetOperatorCallCount()1099     public int getGetOperatorCallCount() {
1100         final int count = mGetOperatorCallCount.get();
1101         return mGetOperatorCallCount.get();
1102     }
1103 
1104     /**
1105      *  ar.exception carries exception on failure
1106      *  ar.userObject contains the original value of result.obj
1107      *  ar.result is null on success and failure
1108      */
1109     @Override
sendDtmf(char c, Message result)1110     public void sendDtmf(char c, Message result) {
1111         resultSuccess(result, null);
1112     }
1113 
1114     /**
1115      *  ar.exception carries exception on failure
1116      *  ar.userObject contains the original value of result.obj
1117      *  ar.result is null on success and failure
1118      */
1119     @Override
startDtmf(char c, Message result)1120     public void startDtmf(char c, Message result) {
1121         resultSuccess(result, null);
1122     }
1123 
1124     /**
1125      *  ar.exception carries exception on failure
1126      *  ar.userObject contains the original value of result.obj
1127      *  ar.result is null on success and failure
1128      */
1129     @Override
stopDtmf(Message result)1130     public void stopDtmf(Message result) {
1131         resultSuccess(result, null);
1132     }
1133 
1134     /**
1135      *  ar.exception carries exception on failure
1136      *  ar.userObject contains the original value of result.obj
1137      *  ar.result is null on success and failure
1138      */
1139     @Override
sendBurstDtmf(String dtmfString, int on, int off, Message result)1140     public void sendBurstDtmf(String dtmfString, int on, int off, Message result) {
1141         SimulatedCommandsVerifier.getInstance().sendBurstDtmf(dtmfString, on, off, result);
1142         resultSuccess(result, null);
1143     }
1144 
1145     /**
1146      * smscPDU is smsc address in PDU form GSM BCD format prefixed
1147      *      by a length byte (as expected by TS 27.005) or NULL for default SMSC
1148      * pdu is SMS in PDU format as an ASCII hex string
1149      *      less the SMSC address
1150      */
1151     @Override
sendSMS(String smscPDU, String pdu, Message result)1152     public void sendSMS (String smscPDU, String pdu, Message result) {
1153         SimulatedCommandsVerifier.getInstance().sendSMS(smscPDU, pdu, result);
1154         resultSuccess(result, new SmsResponse(0 /*messageRef*/, null, SmsResponse.NO_ERROR_CODE));
1155     }
1156 
1157     /**
1158      * Send an SMS message, Identical to sendSMS,
1159      * except that more messages are expected to be sent soon
1160      * smscPDU is smsc address in PDU form GSM BCD format prefixed
1161      *      by a length byte (as expected by TS 27.005) or NULL for default SMSC
1162      * pdu is SMS in PDU format as an ASCII hex string
1163      *      less the SMSC address
1164      */
1165     @Override
sendSMSExpectMore(String smscPDU, String pdu, Message result)1166     public void sendSMSExpectMore (String smscPDU, String pdu, Message result) {
1167         SimulatedCommandsVerifier.getInstance().sendSMSExpectMore(smscPDU, pdu, result);
1168         resultSuccess(result, new SmsResponse(0 /*messageRef*/, null, SmsResponse.NO_ERROR_CODE));
1169     }
1170 
1171     @Override
deleteSmsOnSim(int index, Message response)1172     public void deleteSmsOnSim(int index, Message response) {
1173         Rlog.d(LOG_TAG, "Delete message at index " + index);
1174         unimplemented(response);
1175     }
1176 
1177     @Override
deleteSmsOnRuim(int index, Message response)1178     public void deleteSmsOnRuim(int index, Message response) {
1179         Rlog.d(LOG_TAG, "Delete RUIM message at index " + index);
1180         unimplemented(response);
1181     }
1182 
1183     @Override
writeSmsToSim(int status, String smsc, String pdu, Message response)1184     public void writeSmsToSim(int status, String smsc, String pdu, Message response) {
1185         Rlog.d(LOG_TAG, "Write SMS to SIM with status " + status);
1186         unimplemented(response);
1187     }
1188 
1189     @Override
writeSmsToRuim(int status, byte[] pdu, Message response)1190     public void writeSmsToRuim(int status, byte[] pdu, Message response) {
1191         Rlog.d(LOG_TAG, "Write SMS to RUIM with status " + status);
1192         unimplemented(response);
1193     }
1194 
setDataCallResult(final boolean success, final SetupDataCallResult dcResult)1195     public void setDataCallResult(final boolean success, final SetupDataCallResult dcResult) {
1196         mSetupDataCallResult = dcResult;
1197         mDcSuccess = success;
1198     }
1199 
triggerNITZupdate(String NITZStr)1200     public void triggerNITZupdate(String NITZStr) {
1201         if (NITZStr != null) {
1202             mNITZTimeRegistrant.notifyRegistrant(new AsyncResult (null, new Object[]{NITZStr,
1203                     SystemClock.elapsedRealtime()}, null));
1204         }
1205     }
1206 
triggerNITZupdate(String NITZStr, long ageMs)1207     public void triggerNITZupdate(String NITZStr, long ageMs) {
1208         if (NITZStr != null) {
1209             mNITZTimeRegistrant.notifyRegistrant(new AsyncResult (null, new Object[]{NITZStr,
1210                     SystemClock.elapsedRealtime(), ageMs}, null));
1211         }
1212     }
1213 
1214     @Override
setupDataCall(int accessNetworkType, DataProfile dataProfile, boolean isRoaming, boolean allowRoaming, int reason, LinkProperties linkProperties, int pduSessionId, NetworkSliceInfo sliceInfo, TrafficDescriptor trafficDescriptor, boolean matchAllRuleAllowed, Message result)1215     public void setupDataCall(int accessNetworkType, DataProfile dataProfile, boolean isRoaming,
1216             boolean allowRoaming, int reason, LinkProperties linkProperties, int pduSessionId,
1217             NetworkSliceInfo sliceInfo, TrafficDescriptor trafficDescriptor,
1218             boolean matchAllRuleAllowed, Message result) {
1219 
1220         SimulatedCommandsVerifier.getInstance().setupDataCall(accessNetworkType, dataProfile,
1221                 isRoaming, allowRoaming, reason, linkProperties, pduSessionId, sliceInfo,
1222                 trafficDescriptor, matchAllRuleAllowed, result);
1223 
1224         if (mSetupDataCallResult == null) {
1225             try {
1226                 mSetupDataCallResult = new SetupDataCallResult();
1227                 mSetupDataCallResult.status = 0;
1228                 mSetupDataCallResult.suggestedRetryTime = -1;
1229                 mSetupDataCallResult.cid = 1;
1230                 mSetupDataCallResult.active = 2;
1231                 mSetupDataCallResult.type = "IP";
1232                 mSetupDataCallResult.ifname = "rmnet_data7";
1233                 mSetupDataCallResult.addresses = "12.34.56.78";
1234                 mSetupDataCallResult.dnses = "98.76.54.32";
1235                 mSetupDataCallResult.gateways = "11.22.33.44";
1236                 mSetupDataCallResult.pcscf =
1237                         "fd00:976a:c305:1d::8 fd00:976a:c202:1d::7 fd00:976a:c305:1d::5";
1238                 mSetupDataCallResult.mtu = 1440;
1239             } catch (Exception e) {
1240 
1241             }
1242         }
1243 
1244         DataCallResponse response = RILUtils.convertHalDataCallResult(mSetupDataCallResult);
1245         if (mDcSuccess) {
1246             resultSuccess(result, response);
1247         } else {
1248             resultFail(result, response, new RuntimeException("Setup data call failed!"));
1249         }
1250     }
1251 
1252     @Override
deactivateDataCall(int cid, int reason, Message result)1253     public void deactivateDataCall(int cid, int reason, Message result) {
1254         SimulatedCommandsVerifier.getInstance().deactivateDataCall(cid, reason, result);
1255         resultSuccess(result, RadioError.NONE);
1256     }
1257 
1258     @Override
setPreferredNetworkType(int networkType , Message result)1259     public void setPreferredNetworkType(int networkType , Message result) {
1260         SimulatedCommandsVerifier.getInstance().setPreferredNetworkType(networkType, result);
1261         mPreferredNetworkType = networkType;
1262         resultSuccess(result, null);
1263     }
1264 
1265     @Override
getPreferredNetworkType(Message result)1266     public void getPreferredNetworkType(Message result) {
1267         SimulatedCommandsVerifier.getInstance().getPreferredNetworkType(result);
1268         int ret[] = new int[1];
1269 
1270         ret[0] = mPreferredNetworkType;
1271         resultSuccess(result, ret);
1272     }
1273 
1274     @Override
setAllowedNetworkTypesBitmap( @elephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message response)1275     public void setAllowedNetworkTypesBitmap(
1276             @TelephonyManager.NetworkTypeBitMask int networkTypeBitmask, Message response) {
1277         SimulatedCommandsVerifier.getInstance()
1278             .setAllowedNetworkTypesBitmap(networkTypeBitmask, response);
1279         mAllowedNetworkType = networkTypeBitmask;
1280         resultSuccess(response, null);
1281     }
1282 
1283     @Override
getAllowedNetworkTypesBitmap(Message response)1284     public void getAllowedNetworkTypesBitmap(Message response) {
1285         SimulatedCommandsVerifier.getInstance().getAllowedNetworkTypesBitmap(response);
1286         int[] ret = new int[1];
1287 
1288         ret[0] = mAllowedNetworkType;
1289         resultSuccess(response, ret);
1290     }
1291 
1292     @Override
setLocationUpdates(boolean enable, Message response)1293     public void setLocationUpdates(boolean enable, Message response) {
1294         SimulatedCommandsVerifier.getInstance().setLocationUpdates(enable, response);
1295         resultSuccess(response, null);
1296     }
1297 
1298     @Override
getSmscAddress(Message result)1299     public void getSmscAddress(Message result) {
1300         SimulatedCommandsVerifier.getInstance().getSmscAddress(result);
1301         if (mSendGetSmscAddressResponse) {
1302             unimplemented(result);
1303         }
1304     }
1305 
1306     @Override
setSmscAddress(String address, Message result)1307     public void setSmscAddress(String address, Message result) {
1308         unimplemented(result);
1309     }
1310 
1311     @Override
reportSmsMemoryStatus(boolean available, Message result)1312     public void reportSmsMemoryStatus(boolean available, Message result) {
1313         if (!mIsReportSmsMemoryStatusFailResponse) {
1314             resultSuccess(result, null);
1315         } else {
1316             CommandException ex = new CommandException(CommandException.Error.GENERIC_FAILURE);
1317             resultFail(result, null, ex);
1318         }
1319         SimulatedCommandsVerifier.getInstance().reportSmsMemoryStatus(available, result);
1320     }
1321 
setReportSmsMemoryStatusFailResponse(boolean fail)1322     public void setReportSmsMemoryStatusFailResponse(boolean fail) {
1323         mIsReportSmsMemoryStatusFailResponse = fail;
1324     }
1325 
1326     @Override
reportStkServiceIsRunning(Message result)1327     public void reportStkServiceIsRunning(Message result) {
1328         resultSuccess(result, null);
1329     }
1330 
1331     @Override
getCdmaSubscriptionSource(Message result)1332     public void getCdmaSubscriptionSource(Message result) {
1333         unimplemented(result);
1334     }
1335 
isSimLocked()1336     private boolean isSimLocked() {
1337         if (mSimLockedState != SimLockState.NONE) {
1338             return true;
1339         }
1340         return false;
1341     }
1342 
1343     @Override
setRadioPower(boolean on, boolean forEmergencyCall, boolean preferredForEmergencyCall, Message result)1344     public void setRadioPower(boolean on, boolean forEmergencyCall,
1345             boolean preferredForEmergencyCall, Message result) {
1346         if (mIsRadioPowerFailResponse) {
1347             resultFail(result, null, new RuntimeException("setRadioPower failed!"));
1348             return;
1349         }
1350 
1351         mSetRadioPowerForEmergencyCall = forEmergencyCall;
1352         mSetRadioPowerAsSelectedPhoneForEmergencyCall = preferredForEmergencyCall;
1353 
1354         if(on) {
1355             setRadioState(TelephonyManager.RADIO_POWER_ON, false /* forceNotifyRegistrants */);
1356         } else {
1357             setRadioState(TelephonyManager.RADIO_POWER_OFF, false /* forceNotifyRegistrants */);
1358         }
1359         resultSuccess(result, null);
1360     }
1361 
1362 
1363     @Override
acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result)1364     public void acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result) {
1365         unimplemented(result);
1366         SimulatedCommandsVerifier.getInstance().
1367                 acknowledgeLastIncomingGsmSms(success, cause, result);
1368     }
1369 
1370     @Override
acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result)1371     public void acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result) {
1372         unimplemented(result);
1373     }
1374 
1375     @Override
acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result)1376     public void acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu,
1377             Message result) {
1378         unimplemented(result);
1379     }
1380 
1381     @Override
iccIO(int command, int fileid, String path, int p1, int p2, int p3, String data, String pin2, Message response)1382     public void iccIO(int command, int fileid, String path, int p1, int p2, int p3, String data,
1383             String pin2, Message response) {
1384         iccIOForApp(command, fileid, path, p1, p2, p3, data, pin2, null, response);
1385     }
1386 
1387     /**
1388      * parameters equivalent to 27.007 AT+CRSM command
1389      * response.obj will be an AsyncResult
1390      * response.obj.userObj will be a SimIoResult on success
1391      */
1392     @Override
iccIOForApp(int command, int fileid, String path, int p1, int p2, int p3, String data, String pin2, String aid, Message result)1393     public void iccIOForApp (int command, int fileid, String path, int p1, int p2,
1394                        int p3, String data, String pin2, String aid, Message result) {
1395         unimplemented(result);
1396     }
1397 
1398     /**
1399      * (AsyncResult)response.obj).result is an int[] with element [0] set to
1400      * 1 for "CLIP is provisioned", and 0 for "CLIP is not provisioned".
1401      *
1402      * @param response is callback message
1403      */
1404     @Override
queryCLIP(Message response)1405     public void queryCLIP(Message response) { unimplemented(response); }
1406 
1407 
1408     /**
1409      * response.obj will be a an int[2]
1410      *
1411      * response.obj[0] will be TS 27.007 +CLIR parameter 'n'
1412      *  0 presentation indicator is used according to the subscription of the CLIR service
1413      *  1 CLIR invocation
1414      *  2 CLIR suppression
1415      *
1416      * response.obj[1] will be TS 27.007 +CLIR parameter 'm'
1417      *  0 CLIR not provisioned
1418      *  1 CLIR provisioned in permanent mode
1419      *  2 unknown (e.g. no network, etc.)
1420      *  3 CLIR temporary mode presentation restricted
1421      *  4 CLIR temporary mode presentation allowed
1422      */
1423 
1424     @Override
getCLIR(Message result)1425     public void getCLIR(Message result) {unimplemented(result);}
1426 
1427     /**
1428      * clirMode is one of the CLIR_* constants above
1429      *
1430      * response.obj is null
1431      */
1432 
1433     @Override
setCLIR(int clirMode, Message result)1434     public void setCLIR(int clirMode, Message result) {unimplemented(result);}
1435 
1436     /**
1437      * (AsyncResult)response.obj).result is an int[] with element [0] set to
1438      * 0 for disabled, 1 for enabled.
1439      *
1440      * @param serviceClass is a sum of SERVICE_CLASS_*
1441      * @param response is callback message
1442      */
1443 
1444     @Override
queryCallWaiting(int serviceClass, Message response)1445     public void queryCallWaiting(int serviceClass, Message response) {
1446         if (response != null && serviceClass == SERVICE_CLASS_NONE) {
1447             int[] r = new int[2];
1448             r[0] = (mCallWaitActivated ? 1 : 0);
1449             r[1] = (mCallWaitActivated ? SERVICE_CLASS_VOICE : SERVICE_CLASS_NONE);
1450             resultSuccess(response, r);
1451             return;
1452         }
1453 
1454         unimplemented(response);
1455     }
1456 
1457     /**
1458      * @param enable is true to enable, false to disable
1459      * @param serviceClass is a sum of SERVICE_CLASS_*
1460      * @param response is callback message
1461      */
1462     @Override
setCallWaiting(boolean enable, int serviceClass, Message response)1463     public void setCallWaiting(boolean enable, int serviceClass,
1464             Message response) {
1465         if ((serviceClass & SERVICE_CLASS_VOICE) == SERVICE_CLASS_VOICE) {
1466             mCallWaitActivated = enable;
1467         }
1468         if (response != null) {
1469             resultSuccess(response, null);
1470         }
1471     }
1472 
1473     /**
1474      * @param action is one of CF_ACTION_*
1475      * @param cfReason is one of CF_REASON_*
1476      * @param serviceClass is a sum of SERVICE_CLASSS_*
1477      */
1478     @Override
setCallForward(int action, int cfReason, int serviceClass, String number, int timeSeconds, Message result)1479     public void setCallForward(int action, int cfReason, int serviceClass,
1480             String number, int timeSeconds, Message result) {
1481         SimulatedCommandsVerifier.getInstance().setCallForward(action, cfReason, serviceClass,
1482                 number, timeSeconds, result);
1483         resultSuccess(result, null);
1484     }
1485 
1486     /**
1487      * cfReason is one of CF_REASON_*
1488      *
1489      * ((AsyncResult)response.obj).result will be an array of
1490      * CallForwardInfo's
1491      *
1492      * An array of length 0 means "disabled for all codes"
1493      */
1494     @Override
queryCallForwardStatus(int cfReason, int serviceClass, String number, Message result)1495     public void queryCallForwardStatus(int cfReason, int serviceClass,
1496             String number, Message result) {
1497         SimulatedCommandsVerifier.getInstance().queryCallForwardStatus(cfReason, serviceClass,
1498                 number, result);
1499         resultSuccess(result, null);
1500     }
1501 
1502     @Override
setNetworkSelectionModeAutomatic(Message result)1503     public void setNetworkSelectionModeAutomatic(Message result) {
1504         SimulatedCommandsVerifier.getInstance().setNetworkSelectionModeAutomatic(result);
1505         mMockNetworkSelectionMode = 0;
1506     }
1507     @Override
exitEmergencyCallbackMode(Message result)1508     public void exitEmergencyCallbackMode(Message result) {unimplemented(result);}
1509     @Override
setNetworkSelectionModeManual(String operatorNumeric, int ran, Message result)1510     public void setNetworkSelectionModeManual(String operatorNumeric, int ran, Message result) {
1511         SimulatedCommandsVerifier.getInstance().setNetworkSelectionModeManual(
1512                 operatorNumeric, ran, result);
1513         mMockNetworkSelectionMode = 1;
1514     }
1515 
1516     /**
1517      * Queries whether the current network selection mode is automatic
1518      * or manual
1519      *
1520      * ((AsyncResult)response.obj).result  is an int[] with element [0] being
1521      * a 0 for automatic selection and a 1 for manual selection
1522      */
1523 
1524     @Override
getNetworkSelectionMode(Message result)1525     public void getNetworkSelectionMode(Message result) {
1526         SimulatedCommandsVerifier.getInstance().getNetworkSelectionMode(result);
1527         getNetworkSelectionModeCallCount.incrementAndGet();
1528         int ret[] = new int[1];
1529 
1530         ret[0] = mMockNetworkSelectionMode;
1531         resultSuccess(result, ret);
1532     }
1533 
1534     /** 0 for automatic selection and a 1 for manual selection. */
1535     private int mMockNetworkSelectionMode = 0;
1536 
1537     private final AtomicInteger getNetworkSelectionModeCallCount = new AtomicInteger(0);
1538 
1539     @VisibleForTesting
getGetNetworkSelectionModeCallCount()1540     public int getGetNetworkSelectionModeCallCount() {
1541         return getNetworkSelectionModeCallCount.get();
1542     }
1543 
1544     /**
1545      * Queries the currently available networks
1546      *
1547      * ((AsyncResult)response.obj).result  is a List of NetworkInfo objects
1548      */
1549     @Override
getAvailableNetworks(Message result)1550     public void getAvailableNetworks(Message result) {
1551         unimplemented(result);
1552     }
1553 
1554     /**
1555      * Starts a network scan
1556      */
1557     @Override
startNetworkScan(NetworkScanRequest nsr, Message result)1558     public void startNetworkScan(NetworkScanRequest nsr, Message result) {
1559         unimplemented(result);
1560     }
1561 
1562     /**
1563      * Stops an ongoing network scan
1564      */
1565     @Override
stopNetworkScan(Message result)1566     public void stopNetworkScan(Message result) {
1567         unimplemented(result);
1568     }
1569 
1570     @Override
getBasebandVersion(Message result)1571     public void getBasebandVersion (Message result) {
1572         SimulatedCommandsVerifier.getInstance().getBasebandVersion(result);
1573         resultSuccess(result, "SimulatedCommands");
1574     }
1575 
1576     /**
1577      * Simulates an Stk Call Control Alpha message
1578      * @param alphaString Alpha string to send.
1579      */
triggerIncomingStkCcAlpha(String alphaString)1580     public void triggerIncomingStkCcAlpha(String alphaString) {
1581         if (mCatCcAlphaRegistrant != null) {
1582             mCatCcAlphaRegistrant.notifyResult(alphaString);
1583         }
1584     }
1585 
sendStkCcAplha(String alphaString)1586     public void sendStkCcAplha(String alphaString) {
1587         triggerIncomingStkCcAlpha(alphaString);
1588     }
1589 
1590     /**
1591      * Simulates an incoming USSD message
1592      * @param statusCode  Status code string. See <code>setOnUSSD</code>
1593      * in CommandsInterface.java
1594      * @param message Message text to send or null if none
1595      */
1596     @Override
triggerIncomingUssd(String statusCode, String message)1597     public void triggerIncomingUssd(String statusCode, String message) {
1598         if (mUSSDRegistrant != null) {
1599             String[] result = {statusCode, message};
1600             mUSSDRegistrant.notifyResult(result);
1601         }
1602     }
1603 
1604 
1605     @Override
sendUSSD(String ussdString, Message result)1606     public void sendUSSD (String ussdString, Message result) {
1607 
1608         // We simulate this particular sequence
1609         if (ussdString.equals("#646#")) {
1610             resultSuccess(result, null);
1611 
1612             // 0 == USSD-Notify
1613             triggerIncomingUssd("0", "You have NNN minutes remaining.");
1614         } else {
1615             resultSuccess(result, null);
1616 
1617             triggerIncomingUssd("0", "All Done");
1618         }
1619     }
1620 
1621     // inherited javadoc suffices
1622     @Override
cancelPendingUssd(Message response)1623     public void cancelPendingUssd (Message response) {
1624         resultSuccess(response, null);
1625     }
1626 
1627 
1628     @Override
resetRadio(Message result)1629     public void resetRadio(Message result) {
1630         unimplemented(result);
1631     }
1632 
1633     @Override
invokeOemRilRequestRaw(byte[] data, Message response)1634     public void invokeOemRilRequestRaw(byte[] data, Message response) {
1635         // Just echo back data
1636         if (response != null) {
1637             AsyncResult.forMessage(response).result = data;
1638             response.sendToTarget();
1639         }
1640     }
1641 
1642     @Override
setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo, Message response)1643     public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo,
1644                                                 Message response) {
1645         // Just echo back data
1646         if (response != null) {
1647             AsyncResult.forMessage(response).result = imsiEncryptionInfo;
1648             response.sendToTarget();
1649         }
1650     }
1651 
1652     @Override
invokeOemRilRequestStrings(String[] strings, Message response)1653     public void invokeOemRilRequestStrings(String[] strings, Message response) {
1654         // Just echo back data
1655         if (response != null) {
1656             AsyncResult.forMessage(response).result = strings;
1657             response.sendToTarget();
1658         }
1659     }
1660 
1661     //***** SimulatedRadioControl
1662 
1663 
1664     /** Start the simulated phone ringing */
1665     @Override
1666     public void
triggerRing(String number)1667     triggerRing(String number) {
1668         simulatedCallState.triggerRing(number);
1669         mCallStateRegistrants.notifyRegistrants();
1670     }
1671 
1672     @Override
1673     public void
progressConnectingCallState()1674     progressConnectingCallState() {
1675         simulatedCallState.progressConnectingCallState();
1676         mCallStateRegistrants.notifyRegistrants();
1677     }
1678 
1679     /** If a call is DIALING or ALERTING, progress it all the way to ACTIVE */
1680     @Override
1681     public void
progressConnectingToActive()1682     progressConnectingToActive() {
1683         simulatedCallState.progressConnectingToActive();
1684         mCallStateRegistrants.notifyRegistrants();
1685     }
1686 
1687     /** automatically progress mobile originated calls to ACTIVE.
1688      *  default to true
1689      */
1690     @Override
1691     public void
setAutoProgressConnectingCall(boolean b)1692     setAutoProgressConnectingCall(boolean b) {
1693         simulatedCallState.setAutoProgressConnectingCall(b);
1694     }
1695 
1696     @Override
1697     public void
setNextDialFailImmediately(boolean b)1698     setNextDialFailImmediately(boolean b) {
1699         simulatedCallState.setNextDialFailImmediately(b);
1700     }
1701 
1702     @Override
1703     public void
setNextCallFailCause(int gsmCause)1704     setNextCallFailCause(int gsmCause) {
1705         mNextCallFailCause = gsmCause;
1706     }
1707 
1708     @Override
1709     public void
triggerHangupForeground()1710     triggerHangupForeground() {
1711         simulatedCallState.triggerHangupForeground();
1712         mCallStateRegistrants.notifyRegistrants();
1713     }
1714 
1715     /** hangup holding calls */
1716     @Override
1717     public void
triggerHangupBackground()1718     triggerHangupBackground() {
1719         simulatedCallState.triggerHangupBackground();
1720         mCallStateRegistrants.notifyRegistrants();
1721     }
1722 
1723     @Override
triggerSsn(int type, int code)1724     public void triggerSsn(int type, int code) {
1725         SuppServiceNotification not = new SuppServiceNotification();
1726         not.notificationType = type;
1727         not.code = code;
1728         mSsnRegistrant.notifyRegistrant(new AsyncResult(null, not, null));
1729     }
1730 
1731     @Override
1732     public void
shutdown()1733     shutdown() {
1734         setRadioState(TelephonyManager.RADIO_POWER_UNAVAILABLE, false /* forceNotifyRegistrants */);
1735         Looper looper = mHandlerThread.getLooper();
1736         if (looper != null) {
1737             looper.quit();
1738         }
1739     }
1740 
1741     /** hangup all */
1742 
1743     @Override
1744     public void
triggerHangupAll()1745     triggerHangupAll() {
1746         simulatedCallState.triggerHangupAll();
1747         mCallStateRegistrants.notifyRegistrants();
1748     }
1749 
1750     @Override
1751     public void
triggerIncomingSMS(String message)1752     triggerIncomingSMS(String message) {
1753         //TODO
1754     }
1755 
1756     @Override
1757     public void
pauseResponses()1758     pauseResponses() {
1759         mPausedResponseCount++;
1760     }
1761 
1762     @Override
1763     public void
resumeResponses()1764     resumeResponses() {
1765         mPausedResponseCount--;
1766 
1767         if (mPausedResponseCount == 0) {
1768             for (int i = 0, s = mPausedResponses.size(); i < s ; i++) {
1769                 mPausedResponses.get(i).sendToTarget();
1770             }
1771             mPausedResponses.clear();
1772         } else {
1773             Rlog.e("GSM", "SimulatedCommands.resumeResponses < 0");
1774         }
1775     }
1776 
1777     //***** Private Methods
1778 
1779     @UnsupportedAppUsage
unimplemented(Message result)1780     private void unimplemented(Message result) {
1781         if (result != null) {
1782             AsyncResult.forMessage(result).exception
1783                 = new RuntimeException("Unimplemented");
1784 
1785             if (mPausedResponseCount > 0) {
1786                 mPausedResponses.add(result);
1787             } else {
1788                 result.sendToTarget();
1789             }
1790         }
1791     }
1792 
1793     @UnsupportedAppUsage
resultSuccess(Message result, Object ret)1794     protected void resultSuccess(Message result, Object ret) {
1795         if (result != null) {
1796             AsyncResult.forMessage(result).result = ret;
1797             if (mPausedResponseCount > 0) {
1798                 mPausedResponses.add(result);
1799             } else {
1800                 result.sendToTarget();
1801             }
1802         }
1803     }
1804 
1805     @UnsupportedAppUsage
resultFail(Message result, Object ret, Throwable tr)1806     private void resultFail(Message result, Object ret, Throwable tr) {
1807         if (result != null) {
1808             AsyncResult.forMessage(result, ret, tr);
1809             if (mPausedResponseCount > 0) {
1810                 mPausedResponses.add(result);
1811             } else {
1812                 result.sendToTarget();
1813             }
1814         }
1815     }
1816 
1817     // ***** Methods for CDMA support
1818     @Override
1819     public void
getDeviceIdentity(Message response)1820     getDeviceIdentity(Message response) {
1821         SimulatedCommandsVerifier.getInstance().getDeviceIdentity(response);
1822         resultSuccess(response, new String[] {FAKE_IMEI, FAKE_IMEISV, FAKE_ESN, FAKE_MEID});
1823     }
1824 
1825     @Override
getImei(Message response)1826     public void getImei(Message response) {
1827         SimulatedCommandsVerifier.getInstance().getImei(response);
1828         ImeiInfo imeiInfo = new ImeiInfo();
1829         imeiInfo.imei = FAKE_IMEI;
1830         imeiInfo.svn = FAKE_IMEISV;
1831         imeiInfo.type = ImeiInfo.ImeiType.SECONDARY;
1832         resultSuccess(response, imeiInfo);
1833     }
1834 
1835     @Override
1836     public void
getCDMASubscription(Message result)1837     getCDMASubscription(Message result) {
1838         String ret[] = new String[5];
1839         ret[0] = "123";
1840         ret[1] = "456";
1841         ret[2] = "789";
1842         ret[3] = "234";
1843         ret[4] = "345";
1844         resultSuccess(result, ret);
1845     }
1846 
1847     @Override
1848     public void
setCdmaSubscriptionSource(int cdmaSubscriptionType, Message response)1849     setCdmaSubscriptionSource(int cdmaSubscriptionType, Message response) {
1850         unimplemented(response);
1851     }
1852 
1853     @Override
queryCdmaRoamingPreference(Message response)1854     public void queryCdmaRoamingPreference(Message response) {
1855         unimplemented(response);
1856     }
1857 
1858     @Override
setCdmaRoamingPreference(int cdmaRoamingType, Message response)1859     public void setCdmaRoamingPreference(int cdmaRoamingType, Message response) {
1860         unimplemented(response);
1861     }
1862 
1863     @Override
1864     public void
setPhoneType(int phoneType)1865     setPhoneType(int phoneType) {
1866     }
1867 
1868     @Override
getPreferredVoicePrivacy(Message result)1869     public void getPreferredVoicePrivacy(Message result) {
1870         unimplemented(result);
1871     }
1872 
1873     @Override
setPreferredVoicePrivacy(boolean enable, Message result)1874     public void setPreferredVoicePrivacy(boolean enable, Message result) {
1875         unimplemented(result);
1876     }
1877 
1878     /**
1879      *  Set the TTY mode
1880      *
1881      * @param ttyMode is one of the following:
1882      * - {@link com.android.internal.telephony.Phone#TTY_MODE_OFF}
1883      * - {@link com.android.internal.telephony.Phone#TTY_MODE_FULL}
1884      * - {@link com.android.internal.telephony.Phone#TTY_MODE_HCO}
1885      * - {@link com.android.internal.telephony.Phone#TTY_MODE_VCO}
1886      * @param response is callback message
1887      */
1888     @Override
setTTYMode(int ttyMode, Message response)1889     public void setTTYMode(int ttyMode, Message response) {
1890         Rlog.w(LOG_TAG, "Not implemented in SimulatedCommands");
1891         unimplemented(response);
1892     }
1893 
1894     /**
1895      *  Query the TTY mode
1896      * (AsyncResult)response.obj).result is an int[] with element [0] set to
1897      * tty mode:
1898      * - {@link com.android.internal.telephony.Phone#TTY_MODE_OFF}
1899      * - {@link com.android.internal.telephony.Phone#TTY_MODE_FULL}
1900      * - {@link com.android.internal.telephony.Phone#TTY_MODE_HCO}
1901      * - {@link com.android.internal.telephony.Phone#TTY_MODE_VCO}
1902      * @param response is callback message
1903      */
1904     @Override
queryTTYMode(Message response)1905     public void queryTTYMode(Message response) {
1906         unimplemented(response);
1907     }
1908 
1909     /**
1910      * {@inheritDoc}
1911      */
1912     @Override
sendCDMAFeatureCode(String FeatureCode, Message response)1913     public void sendCDMAFeatureCode(String FeatureCode, Message response) {
1914         unimplemented(response);
1915     }
1916 
1917     /**
1918      * {@inheritDoc}
1919      */
1920     @Override
sendCdmaSms(byte[] pdu, Message response)1921     public void sendCdmaSms(byte[] pdu, Message response){
1922         SimulatedCommandsVerifier.getInstance().sendCdmaSms(pdu, response);
1923         resultSuccess(response, null);
1924     }
1925 
1926     /**
1927      * {@inheritDoc}
1928      */
1929     @Override
sendCdmaSMSExpectMore(byte[] pdu, Message response)1930     public void sendCdmaSMSExpectMore(byte[] pdu, Message response){
1931     }
1932 
1933     @Override
setCdmaBroadcastActivation(boolean activate, Message response)1934     public void setCdmaBroadcastActivation(boolean activate, Message response) {
1935         SimulatedCommandsVerifier.getInstance().setCdmaBroadcastActivation(activate, response);
1936         resultSuccess(response, null);
1937     }
1938 
1939     @Override
getCdmaBroadcastConfig(Message response)1940     public void getCdmaBroadcastConfig(Message response) {
1941         unimplemented(response);
1942 
1943     }
1944 
1945     @Override
setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message response)1946     public void setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message response) {
1947         SimulatedCommandsVerifier.getInstance().setCdmaBroadcastConfig(configs, response);
1948         resultSuccess(response, null);
1949     }
1950 
forceDataDormancy(Message response)1951     public void forceDataDormancy(Message response) {
1952         unimplemented(response);
1953     }
1954 
1955 
1956     @Override
setGsmBroadcastActivation(boolean activate, Message response)1957     public void setGsmBroadcastActivation(boolean activate, Message response) {
1958         SimulatedCommandsVerifier.getInstance().setGsmBroadcastActivation(activate, response);
1959         resultSuccess(response, null);
1960     }
1961 
1962 
1963     @Override
setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message response)1964     public void setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message response) {
1965         SimulatedCommandsVerifier.getInstance().setGsmBroadcastConfig(config, response);
1966         if (mSendSetGsmBroadcastConfigResponse) {
1967             resultSuccess(response, null);
1968         }
1969     }
1970 
1971     @Override
getGsmBroadcastConfig(Message response)1972     public void getGsmBroadcastConfig(Message response) {
1973         unimplemented(response);
1974     }
1975 
1976     @Override
supplyIccPinForApp(String pin, String aid, Message response)1977     public void supplyIccPinForApp(String pin, String aid, Message response) {
1978         SimulatedCommandsVerifier.getInstance().supplyIccPinForApp(pin, aid, response);
1979         if (mPinCode != null && mPinCode.equals(pin)) {
1980             resultSuccess(response, null);
1981             return;
1982         }
1983 
1984         Rlog.i(LOG_TAG, "[SimCmd] supplyIccPinForApp: pin failed!");
1985         CommandException ex = new CommandException(
1986                 CommandException.Error.PASSWORD_INCORRECT);
1987         resultFail(response, new int[]{
1988                 (--mPin1attemptsRemaining < 0) ? 0 : mPin1attemptsRemaining}, ex);
1989     }
1990 
1991     @Override
supplyIccPukForApp(String puk, String newPin, String aid, Message response)1992     public void supplyIccPukForApp(String puk, String newPin, String aid, Message response) {
1993         unimplemented(response);
1994     }
1995 
1996     @Override
supplyIccPin2ForApp(String pin2, String aid, Message response)1997     public void supplyIccPin2ForApp(String pin2, String aid, Message response) {
1998         unimplemented(response);
1999     }
2000 
2001     @Override
supplyIccPuk2ForApp(String puk2, String newPin2, String aid, Message response)2002     public void supplyIccPuk2ForApp(String puk2, String newPin2, String aid, Message response) {
2003         unimplemented(response);
2004     }
2005 
2006     @Override
changeIccPinForApp(String oldPin, String newPin, String aidPtr, Message response)2007     public void changeIccPinForApp(String oldPin, String newPin, String aidPtr, Message response) {
2008         SimulatedCommandsVerifier.getInstance().changeIccPinForApp(oldPin, newPin, aidPtr,
2009                 response);
2010         changeIccPin(oldPin, newPin, response);
2011     }
2012 
2013     @Override
changeIccPin2ForApp(String oldPin2, String newPin2, String aidPtr, Message response)2014     public void changeIccPin2ForApp(String oldPin2, String newPin2, String aidPtr,
2015             Message response) {
2016         unimplemented(response);
2017     }
2018 
2019     @Override
requestIccSimAuthentication(int authContext, String data, String aid, Message response)2020     public void requestIccSimAuthentication(int authContext, String data, String aid, Message response) {
2021         switch (mAuthenticationMode) {
2022             case ICC_AUTHENTICATION_MODE_TIMEOUT:
2023                 break;
2024 
2025             case ICC_AUTHENTICATION_MODE_NULL:
2026                 sendMessageResponse(response, null);
2027                 break;
2028 
2029             default:
2030                 if (data == null || data.length() == 0) {
2031                     sendMessageResponse(response,  null);
2032                 } else {
2033                     sendMessageResponse(response, new IccIoResult(0, 0, (byte[]) data.getBytes()));
2034                 }
2035                 break;
2036         }
2037     }
2038 
2039     /**
2040      * Helper function to send response msg
2041      * @param msg Response message to be sent
2042      * @param ret Return object to be included in the response message
2043      */
sendMessageResponse(Message msg, Object ret)2044     private void sendMessageResponse(Message msg, Object ret) {
2045         if (msg != null) {
2046             AsyncResult.forMessage(msg, ret, null);
2047             msg.sendToTarget();
2048         }
2049     }
2050 
setAuthenticationMode(int authenticationMode)2051     public void setAuthenticationMode(int authenticationMode) {
2052         mAuthenticationMode = authenticationMode;
2053     }
2054 
2055     @Override
getVoiceRadioTechnology(Message response)2056     public void getVoiceRadioTechnology(Message response) {
2057         SimulatedCommandsVerifier.getInstance().getVoiceRadioTechnology(response);
2058         int ret[] = new int[1];
2059         ret[0] = mVoiceRadioTech;
2060         resultSuccess(response, ret);
2061     }
2062 
setCellInfoList(List<CellInfo> list)2063     public void setCellInfoList(List<CellInfo> list) {
2064         mCellInfoList = list;
2065     }
2066 
getCellInfoGsm()2067     private CellInfoGsm getCellInfoGsm() {
2068         Parcel p = Parcel.obtain();
2069         // CellInfo
2070         p.writeInt(1);
2071         p.writeInt(1);
2072         p.writeInt(2);
2073         p.writeLong(1453510289108L);
2074         p.writeInt(0);
2075         // CellIdentity
2076         p.writeInt(1);
2077         p.writeString("310");
2078         p.writeString("260");
2079         p.writeString("long");
2080         p.writeString("short");
2081         // CellIdentityGsm
2082         p.writeInt(123);
2083         p.writeInt(456);
2084         p.writeInt(950);
2085         p.writeInt(27);
2086         // CellSignalStrength
2087         p.writeInt(99);
2088         p.writeInt(0);
2089         p.writeInt(3);
2090         p.setDataPosition(0);
2091 
2092         return CellInfoGsm.CREATOR.createFromParcel(p);
2093     }
2094 
setCellInfoListBehavior(boolean shouldReturn)2095     public synchronized void setCellInfoListBehavior(boolean shouldReturn) {
2096         mShouldReturnCellInfo = shouldReturn;
2097     }
2098 
2099     @Override
getCellInfoList(Message response, WorkSource workSource)2100     public synchronized void getCellInfoList(Message response, WorkSource workSource) {
2101         if (!mShouldReturnCellInfo) return;
2102 
2103         if (mCellInfoList == null) {
2104             ArrayList<CellInfo> mCellInfoList = new ArrayList();
2105             mCellInfoList.add(getCellInfoGsm());
2106         }
2107 
2108         resultSuccess(response, mCellInfoList);
2109     }
2110 
2111     @Override
getRilVersion()2112     public int getRilVersion() {
2113         return 11;
2114     }
2115 
2116     @Override
setCellInfoListRate(int rateInMillis, Message response, WorkSource workSource)2117     public void setCellInfoListRate(int rateInMillis, Message response, WorkSource workSource) {
2118         unimplemented(response);
2119     }
2120 
2121     @Override
setInitialAttachApn(DataProfile dataProfile, boolean isRoaming, Message result)2122     public void setInitialAttachApn(DataProfile dataProfile, boolean isRoaming, Message result) {
2123         SimulatedCommandsVerifier.getInstance().setInitialAttachApn(dataProfile, isRoaming, result);
2124         resultSuccess(result, null);
2125     }
2126 
2127     @Override
setDataProfile(DataProfile[] dps, boolean isRoaming, Message result)2128     public void setDataProfile(DataProfile[] dps, boolean isRoaming, Message result) {
2129         SimulatedCommandsVerifier.getInstance().setDataProfile(dps, isRoaming, result);
2130         resultSuccess(result, null);
2131     }
2132 
2133     @Override
startHandover(Message result, int callId)2134     public void startHandover(Message result, int callId) {
2135         SimulatedCommandsVerifier.getInstance().startHandover(result, callId);
2136         resultSuccess(result, null);
2137     };
2138 
2139     @Override
cancelHandover(Message result, int callId)2140     public void cancelHandover(Message result, int callId) {
2141         SimulatedCommandsVerifier.getInstance().cancelHandover(result, callId);
2142         resultSuccess(result, null);
2143     };
2144 
setImsRegistrationState(int[] regState)2145     public void setImsRegistrationState(int[] regState) {
2146         mImsRegState = regState;
2147     }
2148 
2149     @Override
getImsRegistrationState(Message response)2150     public void getImsRegistrationState(Message response) {
2151         if (mImsRegState == null) {
2152             mImsRegState = new int[]{1, PhoneConstants.PHONE_TYPE_NONE};
2153         }
2154 
2155         resultSuccess(response, mImsRegState);
2156     }
2157 
2158     @Override
sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message response)2159     public void sendImsCdmaSms(byte[] pdu, int retry, int messageRef,
2160             Message response){
2161         SimulatedCommandsVerifier.getInstance().sendImsCdmaSms(pdu, retry, messageRef, response);
2162         resultSuccess(response, new SmsResponse(0 /*messageRef*/, null, SmsResponse.NO_ERROR_CODE));
2163     }
2164 
2165     @Override
sendImsGsmSms(String smscPDU, String pdu, int retry, int messageRef, Message response)2166     public void sendImsGsmSms(String smscPDU, String pdu,
2167             int retry, int messageRef, Message response){
2168         SimulatedCommandsVerifier.getInstance().sendImsGsmSms(smscPDU, pdu, retry, messageRef,
2169                 response);
2170         resultSuccess(response, new SmsResponse(0 /*messageRef*/, null, SmsResponse.NO_ERROR_CODE));
2171     }
2172 
2173     @Override
iccOpenLogicalChannel(String AID, int p2, Message response)2174     public void iccOpenLogicalChannel(String AID, int p2, Message response) {
2175         SimulatedCommandsVerifier.getInstance().iccOpenLogicalChannel(AID, p2, response);
2176         Object result = new int[]{mChannelId};
2177         resultSuccess(response, result);
2178     }
2179 
2180     @Override
iccCloseLogicalChannel(int channel, boolean isEs10, Message response)2181     public void iccCloseLogicalChannel(int channel, boolean isEs10, Message response) {
2182         unimplemented(response);
2183     }
2184 
2185     @Override
iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2, int p3, String data, boolean isEs10Command, Message response)2186     public void iccTransmitApduLogicalChannel(int channel, int cla, int instruction,
2187             int p1, int p2, int p3, String data, boolean isEs10Command, Message response) {
2188         SimulatedCommandsVerifier.getInstance().iccTransmitApduLogicalChannel(channel, cla,
2189                 instruction, p1, p2, p3, data, isEs10Command, response);
2190         if (mIccIoResultForApduLogicalChannel != null) {
2191             resultSuccess(response, mIccIoResultForApduLogicalChannel);
2192         } else {
2193             resultFail(response, null, new RuntimeException("IccIoResult not set"));
2194         }
2195     }
2196 
2197     @Override
iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3, String data, Message response)2198     public void iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2,
2199             int p3, String data, Message response) {
2200         unimplemented(response);
2201     }
2202 
2203     @Override
nvReadItem(int itemID, Message response, WorkSource workSource)2204     public void nvReadItem(int itemID, Message response, WorkSource workSource) {
2205         unimplemented(response);
2206     }
2207 
2208     @Override
nvWriteItem(int itemID, String itemValue, Message response, WorkSource workSource)2209     public void nvWriteItem(int itemID, String itemValue, Message response, WorkSource workSource) {
2210         unimplemented(response);
2211     }
2212 
2213     @Override
nvWriteCdmaPrl(byte[] preferredRoamingList, Message response)2214     public void nvWriteCdmaPrl(byte[] preferredRoamingList, Message response) {
2215         unimplemented(response);
2216     }
2217 
2218     @Override
nvResetConfig(int resetType, Message response)2219     public void nvResetConfig(int resetType, Message response) {
2220         unimplemented(response);
2221     }
2222 
2223     @Override
getHardwareConfig(Message result)2224     public void getHardwareConfig(Message result) {
2225         unimplemented(result);
2226     }
2227 
2228     @Override
requestShutdown(Message result)2229     public void requestShutdown(Message result) {
2230         setRadioState(TelephonyManager.RADIO_POWER_UNAVAILABLE, false /* forceNotifyRegistrants */);
2231     }
2232 
2233     @Override
startLceService(int report_interval_ms, boolean pullMode, Message result)2234     public void startLceService(int report_interval_ms, boolean pullMode, Message result) {
2235         SimulatedCommandsVerifier.getInstance().startLceService(report_interval_ms, pullMode,
2236                 result);
2237     }
2238 
2239     @Override
stopLceService(Message result)2240     public void stopLceService(Message result) {
2241         unimplemented(result);
2242     }
2243 
2244     @Override
pullLceData(Message result)2245     public void pullLceData(Message result) {
2246         unimplemented(result);
2247     }
2248 
2249     @Override
registerForLceInfo(Handler h, int what, Object obj)2250     public void registerForLceInfo(Handler h, int what, Object obj) {
2251         SimulatedCommandsVerifier.getInstance().registerForLceInfo(h, what, obj);
2252     }
2253 
2254     @Override
unregisterForLceInfo(Handler h)2255     public void unregisterForLceInfo(Handler h) {
2256         SimulatedCommandsVerifier.getInstance().unregisterForLceInfo(h);
2257     }
2258 
2259     @Override
getModemActivityInfo(Message result, WorkSource workSource)2260     public void getModemActivityInfo(Message result, WorkSource workSource) {
2261         unimplemented(result);
2262     }
2263 
2264     @Override
setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules, Message result, WorkSource workSource)2265     public void setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules,
2266             Message result, WorkSource workSource) {
2267         unimplemented(result);
2268     }
2269 
2270     @Override
getAllowedCarriers(Message result, WorkSource workSource)2271     public void getAllowedCarriers(Message result, WorkSource workSource) {
2272         unimplemented(result);
2273     }
2274 
2275     @Override
getRadioCapability(Message result)2276     public void getRadioCapability(Message result) {
2277         SimulatedCommandsVerifier.getInstance().getRadioCapability(result);
2278         resultSuccess(result, new RadioCapability(0, 0, 0, 0xFFFF, null, 0));
2279     }
notifySmsStatus(Object result)2280     public void notifySmsStatus(Object result) {
2281         if (mSmsStatusRegistrant != null) {
2282             mSmsStatusRegistrant.notifyRegistrant(new AsyncResult(null, result, null));
2283         }
2284     }
2285 
notifyGsmBroadcastSms(Object result)2286     public void notifyGsmBroadcastSms(Object result) {
2287         if (mGsmBroadcastSmsRegistrant != null) {
2288             mGsmBroadcastSmsRegistrant.notifyRegistrant(new AsyncResult(null, result, null));
2289         }
2290     }
2291 
notifyIccSmsFull()2292     public void notifyIccSmsFull() {
2293         if (mIccSmsFullRegistrant != null) {
2294             mIccSmsFullRegistrant.notifyRegistrant();
2295         }
2296     }
2297 
notifyEmergencyCallbackMode()2298     public void notifyEmergencyCallbackMode() {
2299         if (mEmergencyCallbackModeRegistrant != null) {
2300             mEmergencyCallbackModeRegistrant.notifyRegistrant();
2301         }
2302     }
2303 
2304     @Override
setEmergencyCallbackMode(Handler h, int what, Object obj)2305     public void setEmergencyCallbackMode(Handler h, int what, Object obj) {
2306         SimulatedCommandsVerifier.getInstance().setEmergencyCallbackMode(h, what, obj);
2307         super.setEmergencyCallbackMode(h, what, obj);
2308     }
2309 
notifyExitEmergencyCallbackMode()2310     public void notifyExitEmergencyCallbackMode() {
2311         if (mExitEmergencyCallbackModeRegistrants != null) {
2312             mExitEmergencyCallbackModeRegistrants.notifyRegistrants(
2313                     new AsyncResult (null, null, null));
2314         }
2315     }
2316 
notifyImsNetworkStateChanged()2317     public void notifyImsNetworkStateChanged() {
2318         if(mImsNetworkStateChangedRegistrants != null) {
2319             mImsNetworkStateChangedRegistrants.notifyRegistrants();
2320         }
2321     }
2322 
notifyModemReset()2323     public void notifyModemReset() {
2324         if (mModemResetRegistrants != null) {
2325             mModemResetRegistrants.notifyRegistrants(new AsyncResult(null, "Test", null));
2326         }
2327     }
2328 
2329     @Override
registerForExitEmergencyCallbackMode(Handler h, int what, Object obj)2330     public void registerForExitEmergencyCallbackMode(Handler h, int what, Object obj) {
2331         SimulatedCommandsVerifier.getInstance().registerForExitEmergencyCallbackMode(h, what, obj);
2332         super.registerForExitEmergencyCallbackMode(h, what, obj);
2333     }
2334 
2335     @Override
registerForSrvccStateChanged(Handler h, int what, Object obj)2336     public void registerForSrvccStateChanged(Handler h, int what, Object obj) {
2337         SimulatedCommandsVerifier.getInstance().registerForSrvccStateChanged(h, what, obj);
2338         super.registerForSrvccStateChanged(h, what, obj);
2339     }
2340 
notifyRadioOn()2341     public void notifyRadioOn() {
2342         mOnRegistrants.notifyRegistrants();
2343     }
2344 
2345     @VisibleForTesting
notifyNetworkStateChanged()2346     public void notifyNetworkStateChanged() {
2347         mNetworkStateRegistrants.notifyRegistrants();
2348     }
2349 
2350     @VisibleForTesting
notifyOtaProvisionStatusChanged()2351     public void notifyOtaProvisionStatusChanged() {
2352         if (mOtaProvisionRegistrants != null) {
2353             int ret[] = new int[1];
2354             ret[0] = Phone.CDMA_OTA_PROVISION_STATUS_COMMITTED;
2355             mOtaProvisionRegistrants.notifyRegistrants(new AsyncResult(null, ret, null));
2356         }
2357     }
2358 
notifySignalStrength()2359     public void notifySignalStrength() {
2360         if (mSignalStrength == null) {
2361             mSignalStrength = new SignalStrength(
2362                     new CellSignalStrengthCdma(),
2363                     new CellSignalStrengthGsm(20, 0, CellInfo.UNAVAILABLE),
2364                     new CellSignalStrengthWcdma(),
2365                     new CellSignalStrengthTdscdma(),
2366                     new CellSignalStrengthLte(),
2367                     new CellSignalStrengthNr());
2368         }
2369 
2370         if (mSignalStrengthRegistrant != null) {
2371             mSignalStrengthRegistrant.notifyRegistrant(
2372                     new AsyncResult (null, mSignalStrength, null));
2373         }
2374     }
2375 
setIccCardStatus(IccCardStatus iccCardStatus)2376     public void setIccCardStatus(IccCardStatus iccCardStatus){
2377         mIccCardStatus = iccCardStatus;
2378     }
2379 
setIccIoResultForApduLogicalChannel(IccIoResult iccIoResult)2380     public void setIccIoResultForApduLogicalChannel(IccIoResult iccIoResult) {
2381         mIccIoResultForApduLogicalChannel = iccIoResult;
2382     }
2383 
setOpenChannelId(int channelId)2384     public void setOpenChannelId(int channelId) {
2385         mChannelId = channelId;
2386     }
2387 
setPin1RemainingAttempt(int pin1attemptsRemaining)2388     public void setPin1RemainingAttempt(int pin1attemptsRemaining) {
2389         mPin1attemptsRemaining = pin1attemptsRemaining;
2390     }
2391 
2392     private AtomicBoolean mAllowed = new AtomicBoolean(false);
2393 
2394     @Override
setDataAllowed(boolean allowed, Message result)2395     public void setDataAllowed(boolean allowed, Message result) {
2396         log("setDataAllowed = " + allowed);
2397         mAllowed.set(allowed);
2398         resultSuccess(result, null);
2399     }
2400 
2401     @VisibleForTesting
isDataAllowed()2402     public boolean isDataAllowed() {
2403         return mAllowed.get();
2404     }
2405 
2406     @Override
registerForPcoData(Handler h, int what, Object obj)2407     public void registerForPcoData(Handler h, int what, Object obj) {
2408         SimulatedCommandsVerifier.getInstance().registerForPcoData(h, what, obj);
2409         mPcoDataRegistrants.addUnique(h, what, obj);
2410     }
2411 
2412     @Override
unregisterForPcoData(Handler h)2413     public void unregisterForPcoData(Handler h) {
2414         SimulatedCommandsVerifier.getInstance().unregisterForPcoData(h);
2415         mPcoDataRegistrants.remove(h);
2416     }
2417 
2418     @Override
registerForNotAvailable(Handler h, int what, Object obj)2419     public void registerForNotAvailable(Handler h, int what, Object obj) {
2420         SimulatedCommandsVerifier.getInstance().registerForNotAvailable(h, what, obj);
2421         super.registerForNotAvailable(h, what, obj);
2422     }
2423 
2424     @Override
unregisterForNotAvailable(Handler h)2425     public void unregisterForNotAvailable(Handler h) {
2426         SimulatedCommandsVerifier.getInstance().unregisterForNotAvailable(h);
2427         super.unregisterForNotAvailable(h);
2428     }
2429 
2430     @Override
registerForModemReset(Handler h, int what, Object obj)2431     public void registerForModemReset(Handler h, int what, Object obj) {
2432         SimulatedCommandsVerifier.getInstance().registerForModemReset(h, what, obj);
2433         super.registerForModemReset(h, what, obj);
2434     }
2435 
2436     @Override
sendDeviceState(int stateType, boolean state, Message result)2437     public void sendDeviceState(int stateType, boolean state, Message result) {
2438         SimulatedCommandsVerifier.getInstance().sendDeviceState(stateType, state, result);
2439         resultSuccess(result, null);
2440     }
2441 
2442     @Override
setUnsolResponseFilter(int filter, Message result)2443     public void setUnsolResponseFilter(int filter, Message result) {
2444         SimulatedCommandsVerifier.getInstance().setUnsolResponseFilter(filter, result);
2445         resultSuccess(result, null);
2446     }
2447 
2448     @Override
setSignalStrengthReportingCriteria(List<SignalThresholdInfo> signalThresholdInfos, Message result)2449     public void setSignalStrengthReportingCriteria(List<SignalThresholdInfo> signalThresholdInfos,
2450             Message result) {
2451         SimulatedCommandsVerifier.getInstance().setSignalStrengthReportingCriteria(
2452                 signalThresholdInfos, result);
2453         resultSuccess(result, null);
2454     }
2455 
2456     @Override
setLinkCapacityReportingCriteria(int hysteresisMs, int hysteresisDlKbps, int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran, Message result)2457     public void setLinkCapacityReportingCriteria(int hysteresisMs, int hysteresisDlKbps,
2458             int hysteresisUlKbps, int[] thresholdsDlKbps, int[] thresholdsUlKbps, int ran,
2459             Message result) {
2460     }
2461 
2462     @Override
setSimCardPower(int state, Message result, WorkSource workSource)2463     public void setSimCardPower(int state, Message result, WorkSource workSource) {
2464     }
2465 
2466     @VisibleForTesting
triggerRestrictedStateChanged(int restrictedState)2467     public void triggerRestrictedStateChanged(int restrictedState) {
2468         if (mRestrictedStateRegistrant != null) {
2469             mRestrictedStateRegistrant.notifyRegistrant(
2470                     new AsyncResult(null, restrictedState, null));
2471         }
2472     }
2473 
2474     @Override
setOnRestrictedStateChanged(Handler h, int what, Object obj)2475     public void setOnRestrictedStateChanged(Handler h, int what, Object obj) {
2476         super.setOnRestrictedStateChanged(h, what, obj);
2477         SimulatedCommandsVerifier.getInstance().setOnRestrictedStateChanged(h, what, obj);
2478     }
2479 
setRadioPowerFailResponse(boolean fail)2480     public void setRadioPowerFailResponse(boolean fail) {
2481         mIsRadioPowerFailResponse = fail;
2482     }
2483 
2484     @Override
registerForIccRefresh(Handler h, int what, Object obj)2485     public void registerForIccRefresh(Handler h, int what, Object obj) {
2486         super.registerForIccRefresh(h, what, obj);
2487         SimulatedCommandsVerifier.getInstance().registerForIccRefresh(h, what, obj);
2488     }
2489 
2490     @Override
unregisterForIccRefresh(Handler h)2491     public void unregisterForIccRefresh(Handler h) {
2492         super.unregisterForIccRefresh(h);
2493         SimulatedCommandsVerifier.getInstance().unregisterForIccRefresh(h);
2494     }
2495 
2496     @Override
registerForNattKeepaliveStatus(Handler h, int what, Object obj)2497     public void registerForNattKeepaliveStatus(Handler h, int what, Object obj) {
2498         SimulatedCommandsVerifier.getInstance().registerForNattKeepaliveStatus(h, what, obj);
2499     }
2500 
2501     @Override
unregisterForNattKeepaliveStatus(Handler h)2502     public void unregisterForNattKeepaliveStatus(Handler h) {
2503         SimulatedCommandsVerifier.getInstance().unregisterForNattKeepaliveStatus(h);
2504     }
2505 
2506     @Override
startNattKeepalive( int contextId, KeepalivePacketData packetData, int intervalMillis, Message result)2507     public void startNattKeepalive(
2508             int contextId, KeepalivePacketData packetData, int intervalMillis, Message result) {
2509         SimulatedCommandsVerifier.getInstance().startNattKeepalive(
2510                 contextId, packetData, intervalMillis, result);
2511     }
2512 
2513     @Override
stopNattKeepalive(int sessionHandle, Message result)2514     public void stopNattKeepalive(int sessionHandle, Message result) {
2515         SimulatedCommandsVerifier.getInstance().stopNattKeepalive(sessionHandle, result);
2516     }
2517 
getHandler()2518     public Handler getHandler() {
2519         return mHandlerThread.getThreadHandler();
2520     }
2521 
2522     @Override
getBarringInfo(Message result)2523     public void getBarringInfo(Message result) {
2524         SimulatedCommandsVerifier.getInstance().getBarringInfo(result);
2525         resultSuccess(result, null);
2526     }
2527 
2528     @Override
allocatePduSessionId(Message message)2529     public void allocatePduSessionId(Message message) {
2530         SimulatedCommandsVerifier.getInstance().allocatePduSessionId(message);
2531         resultSuccess(message, 1);
2532     }
2533 
2534     @Override
releasePduSessionId(Message message, int pduSessionId)2535     public void releasePduSessionId(Message message, int pduSessionId) {
2536         SimulatedCommandsVerifier.getInstance().releasePduSessionId(message, pduSessionId);
2537         resultSuccess(message, null);
2538     }
2539 
2540     @Override
getSlicingConfig(Message result)2541     public void getSlicingConfig(Message result) {
2542         SimulatedCommandsVerifier.getInstance().getSlicingConfig(result);
2543         resultSuccess(result, null);
2544     }
2545 
2546     @VisibleForTesting
setDataRegStateResult(Object regStateResult)2547     public void setDataRegStateResult(Object regStateResult) {
2548         mDataRegStateResult = regStateResult;
2549     }
2550 
2551     @VisibleForTesting
setVoiceRegStateResult(Object regStateResult)2552     public void setVoiceRegStateResult(Object regStateResult) {
2553         mVoiceRegStateResult = regStateResult;
2554     }
2555 
2556     @Override
getSimPhonebookRecords(Message result)2557     public void getSimPhonebookRecords(Message result) {
2558         resultSuccess(result, null);
2559 
2560         // send a fake result
2561         List<SimPhonebookRecord> phonebookRecordInfoGroup = new ArrayList<SimPhonebookRecord>();
2562         mSimPhonebookRecordsReceivedRegistrants.notifyRegistrants(
2563                 new AsyncResult(null,
2564                 new ReceivedPhonebookRecords(4, phonebookRecordInfoGroup), null));
2565     }
2566 
setSupportsEid(boolean supportsEid)2567     public void setSupportsEid(boolean supportsEid) {
2568         mSupportsEid = supportsEid;
2569     }
2570 
2571     @Override
supportsEid()2572     public boolean supportsEid() {
2573         return mSupportsEid;
2574     }
2575 
2576     @Override
getSimPhonebookCapacity(Message result)2577     public void getSimPhonebookCapacity(Message result) {
2578         resultSuccess(result, new AdnCapacity(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
2579     }
2580 
2581     @Override
updateSimPhonebookRecord(SimPhonebookRecord phonebookRecord, Message result)2582     public void updateSimPhonebookRecord(SimPhonebookRecord phonebookRecord, Message result) {
2583         int recordId = phonebookRecord.getRecordId();
2584         // Based on design, the record ID starts from 1.
2585         // So if the record ID passed from upper layer is 0, it indicates to insert one new record
2586         // without record ID specific.
2587         if (recordId == 0) {
2588             recordId = 1; // hack code for unit test
2589         }
2590         resultSuccess(result, new int[]{recordId});
2591         notifySimPhonebookChanged();
2592     }
2593 
2594     @VisibleForTesting
notifySimPhonebookChanged()2595     public void notifySimPhonebookChanged() {
2596         mSimPhonebookChangedRegistrants.notifyRegistrants();
2597     }
2598 
triggerPcoData(int cid, String bearerProto, int pcoId, byte[] contents)2599     public void triggerPcoData(int cid, String bearerProto, int pcoId, byte[] contents) {
2600         PcoData response = new PcoData(cid, bearerProto, pcoId, contents);
2601         mPcoDataRegistrants.notifyRegistrants(new AsyncResult(null, response, null));
2602     }
2603 
2604     @Override
setSrvccCallInfo(SrvccConnection[] srvccConnections, Message result)2605     public void setSrvccCallInfo(SrvccConnection[] srvccConnections, Message result) {
2606         mSrvccConnections = srvccConnections;
2607     }
2608 
getSrvccConnections()2609     public SrvccConnection[] getSrvccConnections() {
2610         return mSrvccConnections;
2611     }
2612 
2613     @Override
updateImsRegistrationInfo(int regState, int imsRadioTech, int suggestedAction, int capabilities, Message result)2614     public void updateImsRegistrationInfo(int regState,
2615             int imsRadioTech, int suggestedAction, int capabilities, Message result) {
2616         mImsRegistrationInfo[0] = regState;
2617         mImsRegistrationInfo[1] = imsRadioTech;
2618         mImsRegistrationInfo[2] = suggestedAction;
2619         mImsRegistrationInfo[3] = capabilities;
2620     }
2621 
getImsRegistrationInfo()2622     public int[] getImsRegistrationInfo() {
2623         return mImsRegistrationInfo;
2624     }
2625 
2626     @Override
setN1ModeEnabled(boolean enable, Message result)2627     public void setN1ModeEnabled(boolean enable, Message result) {
2628         mN1ModeEnabled = enable;
2629     }
2630 
isN1ModeEnabled()2631     public boolean isN1ModeEnabled() {
2632         return mN1ModeEnabled;
2633     }
2634 
2635     @Override
isVoNrEnabled(Message message, WorkSource workSource)2636     public void isVoNrEnabled(Message message, WorkSource workSource) {
2637         resultSuccess(message, (Object) mVonrEnabled);
2638     }
2639 
setVonrEnabled(boolean vonrEnable)2640     public void setVonrEnabled(boolean vonrEnable) {
2641         mVonrEnabled = vonrEnable;
2642     }
2643 }
2644