2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.internal.telephony.gsm;
19 import android.content.Context;
20 import android.os.AsyncResult;
21 import android.os.Message;
22 import android.os.SystemClock;
23 import android.telephony.Rlog;
25 import com.android.internal.telephony.BaseCommands;
26 import com.android.internal.telephony.IccIoResult;
27 import com.android.internal.telephony.UUSInfo;
29 import junit.framework.Assert;
32 * Dummy BaseCommands for UsimDataDownloadTest. Only implements UICC envelope and
33 * SMS acknowledgement commands.
35 class UsimDataDownloadCommands extends BaseCommands {
36 private static final String TAG = "UsimDataDownloadCommands";
38 private boolean mExpectingAcknowledgeGsmSms; // true if expecting ack GSM SMS
39 private boolean mExpectingAcknowledgeGsmSmsSuccess; // true if expecting ack SMS success
40 private int mExpectingAcknowledgeGsmSmsFailureCause; // expecting ack SMS failure cause
41 private String mExpectingAcknowledgeGsmSmsPdu; // expecting ack SMS PDU
43 private boolean mExpectingSendEnvelope; // true to expect a send envelope command
44 private String mExpectingSendEnvelopeContents; // expected string for send envelope
45 private int mExpectingSendEnvelopeResponseSw1; // SW1/SW2 response status
46 private int mExpectingSendEnvelopeResponseSw2; // SW1/SW2 response status
47 private String mExpectingSendEnvelopeResponse; // Response string for Send Envelope
49 UsimDataDownloadCommands(Context context) {
54 * Expect a call to acknowledgeLastIncomingGsmSms with success flag and failure cause.
55 * @param success true if expecting success; false if expecting failure
56 * @param cause the failure cause, if success is false
58 synchronized void expectAcknowledgeGsmSms(boolean success, int cause) {
59 Assert.assertFalse("expectAcknowledgeGsmSms called twice", mExpectingAcknowledgeGsmSms);
60 mExpectingAcknowledgeGsmSms = true;
61 mExpectingAcknowledgeGsmSmsSuccess = success;
62 mExpectingAcknowledgeGsmSmsFailureCause = cause;
66 * Expect a call to acknowledgeLastIncomingGsmSmsWithPdu with success flag and PDU.
67 * @param success true if expecting success; false if expecting failure
68 * @param ackPdu the acknowledgement PDU to expect
70 synchronized void expectAcknowledgeGsmSmsWithPdu(boolean success, String ackPdu) {
71 Assert.assertFalse("expectAcknowledgeGsmSms called twice", mExpectingAcknowledgeGsmSms);
72 mExpectingAcknowledgeGsmSms = true;
73 mExpectingAcknowledgeGsmSmsSuccess = success;
74 mExpectingAcknowledgeGsmSmsPdu = ackPdu;
78 * Expect a call to sendEnvelopeWithStatus().
79 * @param contents expected envelope contents to send
80 * @param sw1 simulated SW1 status to return
81 * @param sw2 simulated SW2 status to return
82 * @param response simulated envelope response to return
84 synchronized void expectSendEnvelope(String contents, int sw1, int sw2, String response) {
85 Assert.assertFalse("expectSendEnvelope called twice", mExpectingSendEnvelope);
86 mExpectingSendEnvelope = true;
87 mExpectingSendEnvelopeContents = contents;
88 mExpectingSendEnvelopeResponseSw1 = sw1;
89 mExpectingSendEnvelopeResponseSw2 = sw2;
90 mExpectingSendEnvelopeResponse = response;
93 synchronized void assertExpectedMethodsCalled() {
94 long stopTime = SystemClock.elapsedRealtime() + 5000;
95 while ((mExpectingAcknowledgeGsmSms || mExpectingSendEnvelope)
96 && SystemClock.elapsedRealtime() < stopTime) {
99 } catch (InterruptedException ignored) {}
101 Assert.assertFalse("expecting SMS acknowledge call", mExpectingAcknowledgeGsmSms);
102 Assert.assertFalse("expecting send envelope call", mExpectingSendEnvelope);
106 public synchronized void acknowledgeLastIncomingGsmSms(boolean success, int cause,
108 Rlog.d(TAG, "acknowledgeLastIncomingGsmSms: success=" + success + ", cause=" + cause);
109 Assert.assertTrue("unexpected call to acknowledge SMS", mExpectingAcknowledgeGsmSms);
110 Assert.assertEquals(mExpectingAcknowledgeGsmSmsSuccess, success);
111 Assert.assertEquals(mExpectingAcknowledgeGsmSmsFailureCause, cause);
112 mExpectingAcknowledgeGsmSms = false;
113 if (response != null) {
114 AsyncResult.forMessage(response);
115 response.sendToTarget();
117 notifyAll(); // wake up assertExpectedMethodsCalled()
121 public synchronized void acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu,
123 Rlog.d(TAG, "acknowledgeLastIncomingGsmSmsWithPdu: success=" + success
124 + ", ackPDU= " + ackPdu);
125 Assert.assertTrue("unexpected call to acknowledge SMS", mExpectingAcknowledgeGsmSms);
126 Assert.assertEquals(mExpectingAcknowledgeGsmSmsSuccess, success);
127 Assert.assertEquals(mExpectingAcknowledgeGsmSmsPdu, ackPdu);
128 mExpectingAcknowledgeGsmSms = false;
129 if (response != null) {
130 AsyncResult.forMessage(response);
131 response.sendToTarget();
133 notifyAll(); // wake up assertExpectedMethodsCalled()
137 public synchronized void sendEnvelopeWithStatus(String contents, Message response) {
138 // Add spaces between hex bytes for readability
139 StringBuilder builder = new StringBuilder();
140 for (int i = 0; i < contents.length(); i += 2) {
141 builder.append(contents.charAt(i)).append(contents.charAt(i+1)).append(' ');
143 Rlog.d(TAG, "sendEnvelopeWithStatus: " + builder.toString());
145 Assert.assertTrue("unexpected call to send envelope", mExpectingSendEnvelope);
146 Assert.assertEquals(mExpectingSendEnvelopeContents, contents);
147 mExpectingSendEnvelope = false;
149 IccIoResult result = new IccIoResult(mExpectingSendEnvelopeResponseSw1,
150 mExpectingSendEnvelopeResponseSw2, mExpectingSendEnvelopeResponse);
152 if (response != null) {
153 AsyncResult.forMessage(response, result, null);
154 response.sendToTarget();
156 notifyAll(); // wake up assertExpectedMethodsCalled()
160 public void setSuppServiceNotifications(boolean enable, Message result) {
164 public void supplyIccPin(String pin, Message result) {
168 public void supplyIccPinForApp(String pin, String aid, Message result) {
172 public void supplyIccPuk(String puk, String newPin, Message result) {
176 public void supplyIccPukForApp(String puk, String newPin, String aid, Message result) {
180 public void supplyIccPin2(String pin2, Message result) {
184 public void supplyIccPin2ForApp(String pin2, String aid, Message result) {
188 public void supplyIccPuk2(String puk2, String newPin2, Message result) {
192 public void supplyIccPuk2ForApp(String puk2, String newPin2, String aid, Message result) {
196 public void changeIccPin(String oldPin, String newPin, Message result) {
200 public void changeIccPinForApp(String oldPin, String newPin, String aidPtr, Message result) {
204 public void changeIccPin2(String oldPin2, String newPin2, Message result) {
208 public void changeIccPin2ForApp(String oldPin2, String newPin2, String aidPtr, Message result) {
212 public void changeBarringPassword(String facility, String oldPwd, String newPwd,
217 public void supplyNetworkDepersonalization(String netpin, Message result) {
221 public void getCurrentCalls(Message result) {
225 public void getPDPContextList(Message result) {
229 public void getDataCallList(Message result) {
233 public void dial(String address, int clirMode, Message result) {
237 public void dial(String address, int clirMode, UUSInfo uusInfo, Message result) {
241 public void getIMSI(Message result) {
245 public void getIMEI(Message result) {
249 public void getIMEISV(Message result) {
253 public void hangupConnection(int gsmIndex, Message result) {
257 public void hangupWaitingOrBackground(Message result) {
261 public void hangupForegroundResumeBackground(Message result) {
265 public void switchWaitingOrHoldingAndActive(Message result) {
269 public void conference(Message result) {
273 public void setPreferredVoicePrivacy(boolean enable, Message result) {
277 public void getPreferredVoicePrivacy(Message result) {
281 public void separateConnection(int gsmIndex, Message result) {
285 public void acceptCall(Message result) {
289 public void rejectCall(Message result) {
293 public void explicitCallTransfer(Message result) {
297 public void getLastCallFailCause(Message result) {
301 public void getLastPdpFailCause(Message result) {
305 public void getLastDataCallFailCause(Message result) {
309 public void setMute(boolean enableMute, Message response) {
313 public void getMute(Message response) {
317 public void getSignalStrength(Message response) {
321 public void getVoiceRegistrationState(Message response) {
325 public void getDataRegistrationState(Message response) {
329 public void getOperator(Message response) {
333 public void sendDtmf(char c, Message result) {
337 public void startDtmf(char c, Message result) {
341 public void stopDtmf(Message result) {
345 public void sendBurstDtmf(String dtmfString, int on, int off, Message result) {
349 public void sendSMS(String smscPDU, String pdu, Message response) {
353 public void sendCdmaSms(byte[] pdu, Message response) {
357 public void deleteSmsOnSim(int index, Message response) {
361 public void deleteSmsOnRuim(int index, Message response) {
365 public void writeSmsToSim(int status, String smsc, String pdu, Message response) {
369 public void writeSmsToRuim(int status, String pdu, Message response) {
373 public void setRadioPower(boolean on, Message response) {
377 public void acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message response) {
381 public void iccIO(int command, int fileid, String path, int p1, int p2, int p3, String data,
382 String pin2, Message response) {
386 public void queryCLIP(Message response) {
390 public void getCLIR(Message response) {
394 public void setCLIR(int clirMode, Message response) {
398 public void queryCallWaiting(int serviceClass, Message response) {
402 public void setCallWaiting(boolean enable, int serviceClass, Message response) {
406 public void setCallForward(int action, int cfReason, int serviceClass, String number,
407 int timeSeconds, Message response) {
411 public void queryCallForwardStatus(int cfReason, int serviceClass, String number,
416 public void setNetworkSelectionModeAutomatic(Message response) {
420 public void setNetworkSelectionModeManual(String operatorNumeric, Message response) {
424 public void getNetworkSelectionMode(Message response) {
428 public void getAvailableNetworks(Message response) {
432 public void getBasebandVersion(Message response) {
436 public void queryFacilityLock(String facility, String password, int serviceClass,
441 public void queryFacilityLockForApp(String facility, String password, int serviceClass,
442 String appId, Message response) {
446 public void setFacilityLock(String facility, boolean lockState, String password,
447 int serviceClass, Message response) {
451 public void setFacilityLockForApp(String facility, boolean lockState, String password,
452 int serviceClass, String appId, Message response) {
456 public void sendUSSD(String ussdString, Message response) {
460 public void cancelPendingUssd(Message response) {
464 public void resetRadio(Message result) {
468 public void setBandMode(int bandMode, Message response) {
472 public void queryAvailableBandMode(Message response) {
476 public void setPreferredNetworkType(int networkType, Message response) {
480 public void getPreferredNetworkType(Message response) {
484 public void getNeighboringCids(Message response) {
488 public void setLocationUpdates(boolean enable, Message response) {
492 public void getSmscAddress(Message result) {
496 public void setSmscAddress(String address, Message result) {
500 public void reportSmsMemoryStatus(boolean available, Message result) {
504 public void reportStkServiceIsRunning(Message result) {
508 public void invokeOemRilRequestRaw(byte[] data, Message response) {
512 public void invokeOemRilRequestStrings(String[] strings, Message response) {
516 public void sendTerminalResponse(String contents, Message response) {
520 public void sendEnvelope(String contents, Message response) {
524 public void handleCallSetupRequestFromSim(boolean accept, Message response) {
528 public void setGsmBroadcastActivation(boolean activate, Message result) {
532 public void setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message response) {
536 public void getGsmBroadcastConfig(Message response) {
540 public void getDeviceIdentity(Message response) {
544 public void getCDMASubscription(Message response) {
548 public void sendCDMAFeatureCode(String FeatureCode, Message response) {
552 public void setPhoneType(int phoneType) {
556 public void queryCdmaRoamingPreference(Message response) {
560 public void setCdmaRoamingPreference(int cdmaRoamingType, Message response) {
564 public void setCdmaSubscriptionSource(int cdmaSubscriptionType, Message response) {
568 public void getCdmaSubscriptionSource(Message response) {
572 public void setTTYMode(int ttyMode, Message response) {
576 public void queryTTYMode(Message response) {
580 public void setupDataCall(String radioTechnology, String profile, String apn, String user,
581 String password, String authType, String protocol, Message result) {
585 public void deactivateDataCall(int cid, int reason, Message result) {
589 public void setCdmaBroadcastActivation(boolean activate, Message result) {
593 public void setCdmaBroadcastConfig(int[] configValuesArray, Message result) {
597 public void getCdmaBroadcastConfig(Message result) {
601 public void exitEmergencyCallbackMode(Message response) {
605 public void getIccCardStatus(Message result) {
609 public void requestIsimAuthentication(String nonce, Message response) {
613 public void getVoiceRadioTechnology(Message response) {
617 public void getIMSIForApp(String aid, Message result) {
621 public void iccIOForApp(int command, int fileid, String path, int p1, int p2, int p3,
622 String data, String pin2, String aid, Message response) {