Skip to content

Commit d4d3516

Browse files
Wink SavilleAndroid (Google) Code Review
authored andcommitted
Merge "Add support of dislaying Alpha tag for BIP commands" into ics-mr1
2 parents c97d0e4 + 81fa7f3 commit d4d3516

File tree

5 files changed

+150
-11
lines changed

5 files changed

+150
-11
lines changed

telephony/java/com/android/internal/telephony/cat/AppInterface.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public interface AppInterface {
4242
* Enumeration for representing "Type of Command" of proactive commands.
4343
* Those are the only commands which are supported by the Telephony. Any app
4444
* implementation should support those.
45+
* Refer to ETSI TS 102.223 section 9.4
4546
*/
4647
public static enum CommandType {
4748
DISPLAY_TEXT(0x21),
@@ -59,7 +60,11 @@ public static enum CommandType {
5960
SET_UP_IDLE_MODE_TEXT(0x28),
6061
SET_UP_MENU(0x25),
6162
SET_UP_CALL(0x10),
62-
PROVIDE_LOCAL_INFORMATION(0x26);
63+
PROVIDE_LOCAL_INFORMATION(0x26),
64+
OPEN_CHANNEL(0x40),
65+
CLOSE_CHANNEL(0x41),
66+
RECEIVE_DATA(0x42),
67+
SEND_DATA(0x43);
6368

6469
private int mValue;
6570

telephony/java/com/android/internal/telephony/cat/CatCmdMessage.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ public class CallSettings {
8585
mCallSettings.confirmMsg = ((CallSetupParams) cmdParams).confirmMsg;
8686
mCallSettings.callMsg = ((CallSetupParams) cmdParams).callMsg;
8787
break;
88+
case OPEN_CHANNEL:
89+
case CLOSE_CHANNEL:
90+
case RECEIVE_DATA:
91+
case SEND_DATA:
92+
BIPClientParams param = (BIPClientParams) cmdParams;
93+
mTextMsg = param.textMsg;
94+
break;
8895
}
8996
}
9097

telephony/java/com/android/internal/telephony/cat/CatService.java

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import android.content.Context;
2020
import android.content.Intent;
21+
import android.content.pm.PackageManager;
22+
import android.content.pm.ResolveInfo;
2123
import android.os.AsyncResult;
2224
import android.os.Handler;
2325
import android.os.HandlerThread;
@@ -32,6 +34,7 @@
3234

3335

3436
import java.io.ByteArrayOutputStream;
37+
import java.util.List;
3538
import java.util.Locale;
3639

3740
class RilMessage {
@@ -72,6 +75,7 @@ public class CatService extends Handler implements AppInterface {
7275
private CatCmdMessage mMenuCmd = null;
7376

7477
private RilMessageDecoder mMsgDecoder = null;
78+
private boolean mStkAppInstalled = false;
7579

7680
// Service constants.
7781
static final int MSG_ID_SESSION_END = 1;
@@ -125,7 +129,10 @@ private CatService(CommandsInterface ci, IccRecords ir, Context context,
125129
mCmdIf.registerForNVReady(this, MSG_ID_SIM_READY, null);
126130
mIccRecords.registerForRecordsLoaded(this, MSG_ID_ICC_RECORDS_LOADED, null);
127131

128-
CatLog.d(this, "Is running");
132+
// Check if STK application is availalbe
133+
mStkAppInstalled = isStkAppInstalled();
134+
135+
CatLog.d(this, "Running CAT service. STK app installed:" + mStkAppInstalled);
129136
}
130137

131138
public void dispose() {
@@ -154,7 +161,7 @@ private void handleRilMsg(RilMessage rilMsg) {
154161
if (rilMsg.mResCode == ResultCode.OK) {
155162
cmdParams = (CommandParams) rilMsg.mData;
156163
if (cmdParams != null) {
157-
handleProactiveCommand(cmdParams);
164+
handleCommand(cmdParams, false);
158165
}
159166
}
160167
break;
@@ -170,7 +177,7 @@ private void handleRilMsg(RilMessage rilMsg) {
170177
}
171178
if (cmdParams != null) {
172179
if (rilMsg.mResCode == ResultCode.OK) {
173-
handleProactiveCommand(cmdParams);
180+
handleCommand(cmdParams, true);
174181
} else {
175182
// for proactive commands that couldn't be decoded
176183
// successfully respond with the code generated by the
@@ -183,7 +190,7 @@ private void handleRilMsg(RilMessage rilMsg) {
183190
case MSG_ID_REFRESH:
184191
cmdParams = (CommandParams) rilMsg.mData;
185192
if (cmdParams != null) {
186-
handleProactiveCommand(cmdParams);
193+
handleCommand(cmdParams, false);
187194
}
188195
break;
189196
case MSG_ID_SESSION_END:
@@ -197,11 +204,13 @@ private void handleRilMsg(RilMessage rilMsg) {
197204
}
198205

199206
/**
200-
* Handles RIL_UNSOL_STK_PROACTIVE_COMMAND unsolicited command from RIL.
207+
* Handles RIL_UNSOL_STK_EVENT_NOTIFY or RIL_UNSOL_STK_PROACTIVE_COMMAND command
208+
* from RIL.
201209
* Sends valid proactive command data to the application using intents.
202-
*
210+
* RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE will be send back if the command is
211+
* from RIL_UNSOL_STK_PROACTIVE_COMMAND.
203212
*/
204-
private void handleProactiveCommand(CommandParams cmdParams) {
213+
private void handleCommand(CommandParams cmdParams, boolean isProactiveCmd) {
205214
CatLog.d(this, cmdParams.getCommandType().name());
206215

207216
CharSequence message;
@@ -235,15 +244,16 @@ private void handleProactiveCommand(CommandParams cmdParams) {
235244
case CommandParamsFactory.DTTZ_SETTING:
236245
resp = new DTTZResponseData(null);
237246
sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, resp);
238-
return;
247+
break;
239248
case CommandParamsFactory.LANGUAGE_SETTING:
240249
resp = new LanguageResponseData(Locale.getDefault().getLanguage());
241250
sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, resp);
242-
return;
251+
break;
243252
default:
244253
sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, null);
245-
return;
246254
}
255+
// No need to start STK app here.
256+
return;
247257
case LAUNCH_BROWSER:
248258
if ((((LaunchBrowserParams) cmdParams).confirmMsg.text != null)
249259
&& (((LaunchBrowserParams) cmdParams).confirmMsg.text.equals(STK_DEFAULT))) {
@@ -274,6 +284,42 @@ private void handleProactiveCommand(CommandParams cmdParams) {
274284
((CallSetupParams) cmdParams).confirmMsg.text = message.toString();
275285
}
276286
break;
287+
case OPEN_CHANNEL:
288+
case CLOSE_CHANNEL:
289+
case RECEIVE_DATA:
290+
case SEND_DATA:
291+
BIPClientParams cmd = (BIPClientParams) cmdParams;
292+
if (cmd.bHasAlphaId && (cmd.textMsg.text == null)) {
293+
CatLog.d(this, "cmd " + cmdParams.getCommandType() + " with null alpha id");
294+
// If alpha length is zero, we just respond with OK.
295+
if (isProactiveCmd) {
296+
sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, null);
297+
}
298+
return;
299+
}
300+
// Respond with permanent failure to avoid retry if STK app is not present.
301+
if (!mStkAppInstalled) {
302+
CatLog.d(this, "No STK application found.");
303+
if (isProactiveCmd) {
304+
sendTerminalResponse(cmdParams.cmdDet,
305+
ResultCode.BEYOND_TERMINAL_CAPABILITY,
306+
false, 0, null);
307+
return;
308+
}
309+
}
310+
/*
311+
* CLOSE_CHANNEL, RECEIVE_DATA and SEND_DATA can be delivered by
312+
* either PROACTIVE_COMMAND or EVENT_NOTIFY.
313+
* If PROACTIVE_COMMAND is used for those commands, send terminal
314+
* response here.
315+
*/
316+
if (isProactiveCmd &&
317+
((cmdParams.getCommandType() == CommandType.CLOSE_CHANNEL) ||
318+
(cmdParams.getCommandType() == CommandType.RECEIVE_DATA) ||
319+
(cmdParams.getCommandType() == CommandType.SEND_DATA))) {
320+
sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, null);
321+
}
322+
break;
277323
default:
278324
CatLog.d(this, "Unsupported command");
279325
return;
@@ -684,6 +730,7 @@ private void handleCmdResponse(CatResponseMessage resMsg) {
684730
case NO_RESPONSE_FROM_USER:
685731
case UICC_SESSION_TERM_BY_USER:
686732
case BACKWARD_MOVE_BY_USER:
733+
case USER_NOT_ACCEPT:
687734
resp = null;
688735
break;
689736
default:
@@ -692,4 +739,14 @@ private void handleCmdResponse(CatResponseMessage resMsg) {
692739
sendTerminalResponse(cmdDet, resMsg.resCode, false, 0, resp);
693740
mCurrntCmd = null;
694741
}
742+
743+
private boolean isStkAppInstalled() {
744+
Intent intent = new Intent(AppInterface.CAT_CMD_ACTION);
745+
PackageManager pm = mContext.getPackageManager();
746+
List<ResolveInfo> broadcastReceivers =
747+
pm.queryBroadcastReceivers(intent, PackageManager.GET_META_DATA);
748+
int numReceiver = broadcastReceivers == null ? 0 : broadcastReceivers.size();
749+
750+
return (numReceiver > 0);
751+
}
695752
}

telephony/java/com/android/internal/telephony/cat/CommandParams.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,29 @@ boolean setIcon(Bitmap icon) {
166166
}
167167
}
168168

169+
/*
170+
* BIP (Bearer Independent Protocol) is the mechanism for SIM card applications
171+
* to access data connection through the mobile device.
172+
*
173+
* SIM utilizes proactive commands (OPEN CHANNEL, CLOSE CHANNEL, SEND DATA and
174+
* RECEIVE DATA to control/read/write data for BIP. Refer to ETSI TS 102 223 for
175+
* the details of proactive commands procedures and their structures.
176+
*/
177+
class BIPClientParams extends CommandParams {
178+
TextMessage textMsg;
179+
boolean bHasAlphaId;
180+
181+
BIPClientParams(CommandDetails cmdDet, TextMessage textMsg, boolean has_alpha_id) {
182+
super(cmdDet);
183+
this.textMsg = textMsg;
184+
this.bHasAlphaId = has_alpha_id;
185+
}
169186

187+
boolean setIcon(Bitmap icon) {
188+
if (icon != null && textMsg != null) {
189+
textMsg.icon = icon;
190+
return true;
191+
}
192+
return false;
193+
}
194+
}

telephony/java/com/android/internal/telephony/cat/CommandParamsFactory.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ void make(BerTlv berTlv) {
165165
case PROVIDE_LOCAL_INFORMATION:
166166
cmdPending = processProvideLocalInfo(cmdDet, ctlvs);
167167
break;
168+
case OPEN_CHANNEL:
169+
case CLOSE_CHANNEL:
170+
case RECEIVE_DATA:
171+
case SEND_DATA:
172+
cmdPending = processBIPClient(cmdDet, ctlvs);
173+
break;
168174
default:
169175
// unsupported proactive commands
170176
mCmdParams = new CommandParams(cmdDet);
@@ -893,4 +899,43 @@ private boolean processProvideLocalInfo(CommandDetails cmdDet, List<Comprehensio
893899
}
894900
return false;
895901
}
902+
903+
private boolean processBIPClient(CommandDetails cmdDet,
904+
List<ComprehensionTlv> ctlvs) throws ResultException {
905+
AppInterface.CommandType commandType =
906+
AppInterface.CommandType.fromInt(cmdDet.typeOfCommand);
907+
if (commandType != null) {
908+
CatLog.d(this, "process "+ commandType.name());
909+
}
910+
911+
TextMessage textMsg = new TextMessage();
912+
IconId iconId = null;
913+
ComprehensionTlv ctlv = null;
914+
boolean has_alpha_id = false;
915+
916+
// parse alpha identifier
917+
ctlv = searchForTag(ComprehensionTlvTag.ALPHA_ID, ctlvs);
918+
if (ctlv != null) {
919+
textMsg.text = ValueParser.retrieveAlphaId(ctlv);
920+
CatLog.d(this, "alpha TLV text=" + textMsg.text);
921+
has_alpha_id = true;
922+
}
923+
924+
// parse icon identifier
925+
ctlv = searchForTag(ComprehensionTlvTag.ICON_ID, ctlvs);
926+
if (ctlv != null) {
927+
iconId = ValueParser.retrieveIconId(ctlv);
928+
textMsg.iconSelfExplanatory = iconId.selfExplanatory;
929+
}
930+
931+
textMsg.responseNeeded = false;
932+
mCmdParams = new BIPClientParams(cmdDet, textMsg, has_alpha_id);
933+
934+
if (iconId != null) {
935+
mIconLoadState = LOAD_SINGLE_ICON;
936+
mIconLoader.loadIcon(iconId.recordNumber, this.obtainMessage(MSG_ID_LOAD_ICON_DONE));
937+
return true;
938+
}
939+
return false;
940+
}
896941
}

0 commit comments

Comments
 (0)