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