diff options
author | Pawit Pornkitprasan <p.pawit@gmail.com> | 2012-11-30 19:30:08 +0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.cyanogenmod.com> | 2012-12-09 03:27:26 -0800 |
commit | e7111f6792ce1e8a821189972f83a12b1440325a (patch) | |
tree | 97e78ffb42cbc5847fc75e1418abfea14350dabf /src/java | |
parent | e15ecd0fa9e5858b35a35702852ce702ac3ba5f6 (diff) | |
download | frameworks_opt_telephony-e7111f6792ce1e8a821189972f83a12b1440325a.zip frameworks_opt_telephony-e7111f6792ce1e8a821189972f83a12b1440325a.tar.gz frameworks_opt_telephony-e7111f6792ce1e8a821189972f83a12b1440325a.tar.bz2 |
Add Samsung STK support (telephony part)
Support for SMS-based SIM applications.
Partially rewritten the original patch by Jüri Schultz to be less intrusive.
Change-Id: I15d2de1781a2823e24941dd792db3d372578aa9f
Diffstat (limited to 'src/java')
8 files changed, 301 insertions, 1 deletions
diff --git a/src/java/com/android/internal/telephony/BaseCommands.java b/src/java/com/android/internal/telephony/BaseCommands.java index 88c3130..b240afd 100644 --- a/src/java/com/android/internal/telephony/BaseCommands.java +++ b/src/java/com/android/internal/telephony/BaseCommands.java @@ -84,6 +84,7 @@ public abstract class BaseCommands implements CommandsInterface { protected Registrant mCatProCmdRegistrant; protected Registrant mCatEventRegistrant; protected Registrant mCatCallSetUpRegistrant; + protected Registrant mCatSendSmsResultRegistrant; protected Registrant mIccSmsFullRegistrant; protected Registrant mEmergencyCallbackModeRegistrant; protected Registrant mRingRegistrant; @@ -349,6 +350,15 @@ public abstract class BaseCommands implements CommandsInterface { mCatCallSetUpRegistrant.clear(); } + // For Samsung STK + public void setOnCatSendSmsResult(Handler h, int what, Object obj) { + mCatSendSmsResultRegistrant = new Registrant(h, what, obj); + } + + public void unSetOnCatSendSmsResult(Handler h) { + mCatSendSmsResultRegistrant.clear(); + } + public void setOnIccSmsFull(Handler h, int what, Object obj) { mIccSmsFullRegistrant = new Registrant (h, what, obj); } diff --git a/src/java/com/android/internal/telephony/CommandsInterface.java b/src/java/com/android/internal/telephony/CommandsInterface.java index bbcd077..a88aded 100644 --- a/src/java/com/android/internal/telephony/CommandsInterface.java +++ b/src/java/com/android/internal/telephony/CommandsInterface.java @@ -1588,4 +1588,12 @@ public interface CommandsInterface { * CM-specific: Ask the RIL about the presence of back-compat flags */ public boolean needsOldRilFeature(String feature); + + /** + * @hide + * samsung stk service implementation - set up registrant for sending + * sms send result from modem(RIL) to catService + */ + void setOnCatSendSmsResult(Handler h, int what, Object obj); + void unSetOnCatSendSmsResult(Handler h); } diff --git a/src/java/com/android/internal/telephony/RIL.java b/src/java/com/android/internal/telephony/RIL.java index 5e3e084..207aa77 100644 --- a/src/java/com/android/internal/telephony/RIL.java +++ b/src/java/com/android/internal/telephony/RIL.java @@ -2563,6 +2563,7 @@ public class RIL extends BaseCommands implements CommandsInterface { case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break; case RIL_UNSOL_RIL_CONNECTED: ret = responseInts(p); break; case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: ret = responseInts(p); break; + case RIL_UNSOL_STK_SEND_SMS_RESULT: ret = responseInts(p); break; // Samsung STK default: throw new RuntimeException("Unrecognized unsol response: " + response); @@ -2924,6 +2925,19 @@ public class RIL extends BaseCommands implements CommandsInterface { notifyRegistrantsRilConnectionChanged(((int[])ret)[0]); break; } + + // Samsung STK + case RIL_UNSOL_STK_SEND_SMS_RESULT: + if (Resources.getSystem(). + getBoolean(com.android.internal.R.bool.config_samsung_stk)) { + if (RILJ_LOGD) unsljLogRet(response, ret); + + if (mCatSendSmsResultRegistrant != null) { + mCatSendSmsResultRegistrant.notifyRegistrant( + new AsyncResult (null, ret, null)); + } + } + break; } } @@ -3733,6 +3747,7 @@ public class RIL extends BaseCommands implements CommandsInterface { case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE"; case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED"; case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED"; + case RIL_UNSOL_STK_SEND_SMS_RESULT: return "RIL_UNSOL_STK_SEND_SMS_RESULT"; default: return "<unknown reponse>"; } } diff --git a/src/java/com/android/internal/telephony/cat/CallControlResult.java b/src/java/com/android/internal/telephony/cat/CallControlResult.java new file mode 100644 index 0000000..2dbc0d4 --- /dev/null +++ b/src/java/com/android/internal/telephony/cat/CallControlResult.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.telephony.cat; + + +public enum CallControlResult { + + CALL_CONTROL_NO_CONTROL(0x00), + CALL_CONTROL_ALLOWED_NO_MOD(0x01), + CALL_CONTROL_NOT_ALLOWED(0x02), + CALL_CONTROL_ALLOWED_WITH_MOD(0x03); + private int mValue; + + CallControlResult(int value) { + mValue = value; + } + + public static CallControlResult fromInt(int value) { + for (CallControlResult e : CallControlResult.values()) { + if (e.mValue == value) { + return e; + } + } + return null; + } + + public int value() { + return mValue; + } +} diff --git a/src/java/com/android/internal/telephony/cat/CatService.java b/src/java/com/android/internal/telephony/cat/CatService.java index f327d31..ca062af 100644 --- a/src/java/com/android/internal/telephony/cat/CatService.java +++ b/src/java/com/android/internal/telephony/cat/CatService.java @@ -76,6 +76,10 @@ public class CatService extends Handler implements AppInterface { private CatCmdMessage mCurrntCmd = null; private CatCmdMessage mMenuCmd = null; + // Samsung STK + private int mTimeoutDest = 0; + private int mCallControlResultCode = 0; + private RilMessageDecoder mMsgDecoder = null; private boolean mStkAppInstalled = false; @@ -88,7 +92,9 @@ public class CatService extends Handler implements AppInterface { static final int MSG_ID_RESPONSE = 6; static final int MSG_ID_SIM_READY = 7; + static final int MSG_ID_TIMEOUT = 9; // Samsung STK static final int MSG_ID_RIL_MSG_DECODED = 10; + static final int MSG_ID_SEND_SMS_RESULT = 12; // Samsung STK // Events to signal SIM presence or absent in the device. private static final int MSG_ID_ICC_RECORDS_LOADED = 20; @@ -102,6 +108,14 @@ public class CatService extends Handler implements AppInterface { static final String STK_DEFAULT = "Defualt Message"; + // Samsung STK SEND_SMS + static final int WAITING_SMS_RESULT = 2; + static final int WAITING_SMS_RESULT_TIME = 60000; + + static final int SMS_SEND_OK = 0; + static final int SMS_SEND_FAIL = 32790; + static final int SMS_SEND_RETRY = 32810; + /* Intentionally private for singleton */ private CatService(CommandsInterface ci, UiccCardApplication ca, IccRecords ir, Context context, IccFileHandler fh, UiccCard ic) { @@ -121,6 +135,7 @@ public class CatService extends Handler implements AppInterface { mCmdIf.setOnCatProactiveCmd(this, MSG_ID_PROACTIVE_COMMAND, null); mCmdIf.setOnCatEvent(this, MSG_ID_EVENT_NOTIFY, null); mCmdIf.setOnCatCallSetUp(this, MSG_ID_CALL_SETUP, null); + mCmdIf.setOnCatSendSmsResult(this, MSG_ID_SEND_SMS_RESULT, null); // Samsung STK //mCmdIf.setOnSimRefresh(this, MSG_ID_REFRESH, null); mIccRecords = ir; @@ -142,6 +157,7 @@ public class CatService extends Handler implements AppInterface { mCmdIf.unSetOnCatProactiveCmd(this); mCmdIf.unSetOnCatEvent(this); mCmdIf.unSetOnCatCallSetUp(this); + mCmdIf.unSetOnCatSendSmsResult(this); this.removeCallbacksAndMessages(null); } @@ -271,6 +287,11 @@ public class CatService extends Handler implements AppInterface { break; case SEND_DTMF: case SEND_SMS: + if (mContext.getResources(). + getBoolean(com.android.internal.R.bool.config_samsung_stk)) { + handleProactiveCommandSendSMS((SendSMSParams) cmdParams); + } + // Fall through case SEND_SS: case SEND_USSD: if ((((DisplayTextParams)cmdParams).textMsg.text != null) @@ -654,6 +675,76 @@ public class CatService extends Handler implements AppInterface { CatLog.d(this, "SIM ready. Reporting STK service running now..."); mCmdIf.reportStkServiceIsRunning(null); break; + case MSG_ID_TIMEOUT: // Should only be called for Samsung STK + if (mTimeoutDest == WAITING_SMS_RESULT) { + CatLog.d(this, "SMS SEND TIMEOUT"); + if (CallControlResult.fromInt(mCallControlResultCode) == + CallControlResult.CALL_CONTROL_NOT_ALLOWED) + sendTerminalResponse(mCurrntCmd.mCmdDet, + ResultCode.USIM_CALL_CONTROL_PERMANENT, true, 1, null); + else + sendTerminalResponse(mCurrntCmd.mCmdDet, + ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS, false, 0, null); + break; + } + break; + case MSG_ID_SEND_SMS_RESULT: // Samsung STK SEND_SMS + if (mContext.getResources(). + getBoolean(com.android.internal.R.bool.config_samsung_stk)) { + int[] sendResult; + AsyncResult ar; + CatLog.d(this, "handleMsg : MSG_ID_SEND_SMS_RESULT"); + cancelTimeOut(); + CatLog.d(this, "The Msg ID data:" + msg.what); + if (msg.obj == null) + break; + ar = (AsyncResult) msg.obj; + if (ar == null || ar.result == null || mCurrntCmd == null || mCurrntCmd.mCmdDet == null) + break; + sendResult = (int[]) ar.result; + switch (sendResult[0]) { + default: + CatLog.d(this, "SMS SEND GENERIC FAIL"); + if (CallControlResult.fromInt(mCallControlResultCode) == + CallControlResult.CALL_CONTROL_NOT_ALLOWED) + sendTerminalResponse(mCurrntCmd.mCmdDet, + ResultCode.USIM_CALL_CONTROL_PERMANENT, true, 1, null); + else + sendTerminalResponse(mCurrntCmd.mCmdDet, + ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS, false, 0, null); + break; + case SMS_SEND_OK: // '\0' + CatLog.d(this, "SMS SEND OK"); + if (CallControlResult.fromInt(mCallControlResultCode) == + CallControlResult.CALL_CONTROL_NOT_ALLOWED) + sendTerminalResponse(mCurrntCmd.mCmdDet, + ResultCode.USIM_CALL_CONTROL_PERMANENT, true, 1, null); + else + sendTerminalResponse(mCurrntCmd.mCmdDet, ResultCode.OK, false, 0, null); + break; + case SMS_SEND_FAIL: + CatLog.d(this, "SMS SEND FAIL - MEMORY NOT AVAILABLE"); + if (CallControlResult.fromInt(mCallControlResultCode) == + CallControlResult.CALL_CONTROL_NOT_ALLOWED) + sendTerminalResponse(mCurrntCmd.mCmdDet, + ResultCode.USIM_CALL_CONTROL_PERMANENT, true, 1, null); + else + sendTerminalResponse(mCurrntCmd.mCmdDet, + ResultCode.TERMINAL_CRNTLY_UNABLE_TO_PROCESS, false, 0, null); + break; + case SMS_SEND_RETRY: + CatLog.d(this, "SMS SEND FAIL RETRY"); + if (CallControlResult.fromInt(mCallControlResultCode) == + CallControlResult.CALL_CONTROL_NOT_ALLOWED) + sendTerminalResponse(mCurrntCmd.mCmdDet, + ResultCode.USIM_CALL_CONTROL_PERMANENT, true, 1, null); + else + sendTerminalResponse(mCurrntCmd.mCmdDet, + ResultCode.NETWORK_CRNTLY_UNABLE_TO_PROCESS, false, 0, null); + break; + } + } + break; default: throw new AssertionError("Unrecognized CAT command: " + msg.what); } @@ -776,4 +867,26 @@ public class CatService extends Handler implements AppInterface { return (numReceiver > 0); } + + /** + * Samsung STK SEND_SMS + * @param cmdPar + */ + private void handleProactiveCommandSendSMS(SendSMSParams cmdPar) { + CatLog.d(this, "The smscaddress is: " + cmdPar.smscAddress); + CatLog.d(this, "The SMS tpdu is: " + cmdPar.pdu); + mCmdIf.sendSMS(cmdPar.smscAddress, cmdPar.pdu, null); + startTimeOut(WAITING_SMS_RESULT, WAITING_SMS_RESULT_TIME); + } + + private void cancelTimeOut() { + removeMessages(MSG_ID_TIMEOUT); + mTimeoutDest = 0; + } + + private void startTimeOut(int timeout, int delay) { + cancelTimeOut(); + mTimeoutDest = timeout; + sendMessageDelayed(obtainMessage(MSG_ID_TIMEOUT), delay); + } } diff --git a/src/java/com/android/internal/telephony/cat/CommandParams.java b/src/java/com/android/internal/telephony/cat/CommandParams.java index 79f6ad2..b3463be 100644 --- a/src/java/com/android/internal/telephony/cat/CommandParams.java +++ b/src/java/com/android/internal/telephony/cat/CommandParams.java @@ -197,3 +197,15 @@ class BIPClientParams extends CommandParams { return false; } } + +// Samsung STK +class SendSMSParams extends DisplayTextParams { + String pdu; + String smscAddress; + + SendSMSParams(CommandDetails cmdDet, TextMessage textmessage, String smscaddress, String smsPdu) { + super(cmdDet, textmessage); + smscAddress = smscaddress; + pdu = smsPdu; + } +} diff --git a/src/java/com/android/internal/telephony/cat/CommandParamsFactory.java b/src/java/com/android/internal/telephony/cat/CommandParamsFactory.java index a554012..edd57c1 100644 --- a/src/java/com/android/internal/telephony/cat/CommandParamsFactory.java +++ b/src/java/com/android/internal/telephony/cat/CommandParamsFactory.java @@ -16,6 +16,7 @@ package com.android.internal.telephony.cat; +import android.content.res.Resources; import android.graphics.Bitmap; import android.os.Handler; import android.os.Message; @@ -643,7 +644,35 @@ class CommandParamsFactory extends Handler { } textMsg.responseNeeded = false; - mCmdParams = new DisplayTextParams(cmdDet, textMsg); + // Samsung STK + AppInterface.CommandType cmdType = AppInterface.CommandType.fromInt(cmdDet.typeOfCommand); + boolean isSamsungStk = Resources.getSystem().getBoolean(com.android.internal.R.bool.config_samsung_stk); + if (cmdType == AppInterface.CommandType.SEND_SMS && isSamsungStk) { + String smscAddress = null; + String pdu = null; + + ctlv = searchForTag(ComprehensionTlvTag.ADDRESS, ctlvs); + if (ctlv != null) { + smscAddress = ValueParser.retrieveSMSCaddress(ctlv); + CatLog.d(this, "The smsc address is " + smscAddress); + } + else { + CatLog.d(this, "The smsc address is null"); + } + + ctlv = searchForTag(ComprehensionTlvTag.SMS_TPDU, ctlvs); + if (ctlv != null) { + pdu = ValueParser.retrieveSMSTPDU(ctlv); + CatLog.d(this, "The SMS tpdu is " + pdu); + } + else { + CatLog.d(this, "The SMS tpdu is null"); + } + mCmdParams = new SendSMSParams(cmdDet, textMsg, smscAddress, pdu); + } + else { + mCmdParams = new DisplayTextParams(cmdDet, textMsg); + } if (iconId != null) { mIconLoadState = LOAD_SINGLE_ICON; diff --git a/src/java/com/android/internal/telephony/cat/ValueParser.java b/src/java/com/android/internal/telephony/cat/ValueParser.java index 584d96c..06242cb 100644 --- a/src/java/com/android/internal/telephony/cat/ValueParser.java +++ b/src/java/com/android/internal/telephony/cat/ValueParser.java @@ -338,4 +338,73 @@ abstract class ValueParser { throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); } } + + /** + * Samsung STK: Read SMSC Address + * + * @param ctlv A SMSC Address COMPREHENSION-TLV object + * @return A Java String object decoded from the SMSC Address object + * @throws ResultException + */ + static String retrieveSMSCaddress(ComprehensionTlv ctlv) + throws ResultException { + byte[] rawValue = ctlv.getRawValue(); + int valueIndex = ctlv.getValueIndex(); + int length = ctlv.getLength(); + byte[] outputValue = new byte[length + 1]; + + for (int k = 0; k <= length; k++) { + try { + outputValue[k] = rawValue[k + (valueIndex - 1)]; + } + catch (IndexOutOfBoundsException indexoutofboundsexception) { + throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); + } + } + if (length != 0) + return IccUtils.bytesToHexString(outputValue); + else + throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); + } + + /** + * Samsung STK: Read SMS TPDU Address + * + * @param ctlv A SMS TPDU COMPREHENSION-TLV object + * @return A Java String object decoded from the SMS TPDU object + * @throws ResultException + */ + static String retrieveSMSTPDU(ComprehensionTlv ctlv) + throws ResultException { + byte[] rawValue = ctlv.getRawValue(); + int valueIndex = ctlv.getValueIndex(); + int pduLength = ctlv.getLength(); + byte[] outputValue; + int k; + String result; + if (rawValue[valueIndex + 2] % 2 == 0) + k = rawValue[valueIndex + 2] / 2; + else + k = (1 + rawValue[valueIndex + 2]) / 2; + + if (pduLength == k + 6) + outputValue = new byte[pduLength + 1]; + else + outputValue = new byte[pduLength]; + + for (int l = 0; l < pduLength; l++) { + try { + outputValue[l] = rawValue[valueIndex + l]; + } + catch (IndexOutOfBoundsException ex) { + throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); + } + } + if (pduLength != 0) + result = IccUtils.bytesToHexString(outputValue); + else + throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); + + return result; + } } |