2222import android .os .Handler ;
2323import android .os .HandlerThread ;
2424import android .os .Message ;
25+ import android .os .SystemProperties ;
2526
2627import com .android .internal .telephony .IccUtils ;
2728import com .android .internal .telephony .CommandsInterface ;
@@ -245,48 +246,46 @@ private void handleProactiveCommand(CommandParams cmdParams) {
245246
246247 CatCmdMessage cmdMsg = new CatCmdMessage (cmdParams );
247248 switch (cmdParams .getCommandType ()) {
248- case SET_UP_MENU :
249- if (removeMenu (cmdMsg .getMenu ())) {
250- mMenuCmd = null ;
251- } else {
252- mMenuCmd = cmdMsg ;
253- }
254- sendTerminalResponse (cmdParams .cmdDet , ResultCode .OK , false , 0 ,
255- null );
256- break ;
257- case DISPLAY_TEXT :
258- // when application is not required to respond, send an immediate
259- // response.
260- if (!cmdMsg .geTextMessage ().responseNeeded ) {
261- sendTerminalResponse (cmdParams .cmdDet , ResultCode .OK , false ,
262- 0 , null );
263- }
264- break ;
265- case REFRESH :
266- // ME side only handles refresh commands which meant to remove IDLE
267- // MODE TEXT.
268- cmdParams .cmdDet .typeOfCommand = CommandType .SET_UP_IDLE_MODE_TEXT
269- .value ();
270- break ;
271- case SET_UP_IDLE_MODE_TEXT :
272- sendTerminalResponse (cmdParams .cmdDet , ResultCode .OK , false ,
273- 0 , null );
274- break ;
275- case LAUNCH_BROWSER :
276- case SELECT_ITEM :
277- case GET_INPUT :
278- case GET_INKEY :
279- case SEND_DTMF :
280- case SEND_SMS :
281- case SEND_SS :
282- case SEND_USSD :
283- case PLAY_TONE :
284- case SET_UP_CALL :
285- // nothing to do on telephony!
286- break ;
287- default :
288- CatLog .d (this , "Unsupported command" );
289- return ;
249+ case SET_UP_MENU :
250+ if (removeMenu (cmdMsg .getMenu ())) {
251+ mMenuCmd = null ;
252+ } else {
253+ mMenuCmd = cmdMsg ;
254+ }
255+ sendTerminalResponse (cmdParams .cmdDet , ResultCode .OK , false , 0 , null );
256+ break ;
257+ case DISPLAY_TEXT :
258+ // when application is not required to respond, send an immediate response.
259+ if (!cmdMsg .geTextMessage ().responseNeeded ) {
260+ sendTerminalResponse (cmdParams .cmdDet , ResultCode .OK , false , 0 , null );
261+ }
262+ break ;
263+ case REFRESH :
264+ // ME side only handles refresh commands which meant to remove IDLE
265+ // MODE TEXT.
266+ cmdParams .cmdDet .typeOfCommand = CommandType .SET_UP_IDLE_MODE_TEXT .value ();
267+ break ;
268+ case SET_UP_IDLE_MODE_TEXT :
269+ sendTerminalResponse (cmdParams .cmdDet , ResultCode .OK , false , 0 , null );
270+ break ;
271+ case PROVIDE_LOCAL_INFORMATION :
272+ sendTerminalResponse (cmdParams .cmdDet , ResultCode .OK , false , 0 , null );
273+ return ;
274+ case LAUNCH_BROWSER :
275+ case SELECT_ITEM :
276+ case GET_INPUT :
277+ case GET_INKEY :
278+ case SEND_DTMF :
279+ case SEND_SMS :
280+ case SEND_SS :
281+ case SEND_USSD :
282+ case PLAY_TONE :
283+ case SET_UP_CALL :
284+ // nothing to do on telephony!
285+ break ;
286+ default :
287+ CatLog .d (this , "Unsupported command" );
288+ return ;
290289 }
291290 mCurrntCmd = cmdMsg ;
292291 Intent intent = new Intent (AppInterface .CAT_CMD_ACTION );
@@ -315,6 +314,11 @@ private void sendTerminalResponse(CommandDetails cmdDet,
315314 }
316315 ByteArrayOutputStream buf = new ByteArrayOutputStream ();
317316
317+ Input cmdInput = null ;
318+ if (mCurrntCmd != null ) {
319+ cmdInput = mCurrntCmd .geInput ();
320+ }
321+
318322 // command details
319323 int tag = ComprehensionTlvTag .COMMAND_DETAILS .value ();
320324 if (cmdDet .compRequired ) {
@@ -327,7 +331,13 @@ private void sendTerminalResponse(CommandDetails cmdDet,
327331 buf .write (cmdDet .commandQualifier );
328332
329333 // device identities
330- tag = 0x80 | ComprehensionTlvTag .DEVICE_IDENTITIES .value ();
334+ // According to TS102.223/TS31.111 section 6.8 Structure of
335+ // TERMINAL RESPONSE, "For all SIMPLE-TLV objects with Min=N,
336+ // the ME should set the CR(comprehension required) flag to
337+ // comprehension not required.(CR=0)"
338+ // Since DEVICE_IDENTITIES and DURATION TLVs have Min=N,
339+ // the CR flag is not set.
340+ tag = ComprehensionTlvTag .DEVICE_IDENTITIES .value ();
331341 buf .write (tag );
332342 buf .write (0x02 ); // length
333343 buf .write (DEV_ID_TERMINAL ); // source device id
@@ -348,6 +358,8 @@ private void sendTerminalResponse(CommandDetails cmdDet,
348358 // Fill optional data for each corresponding command
349359 if (resp != null ) {
350360 resp .format (buf );
361+ } else {
362+ encodeOptionalTags (cmdDet , resultCode , cmdInput , buf );
351363 }
352364
353365 byte [] rawData = buf .toByteArray ();
@@ -359,6 +371,52 @@ private void sendTerminalResponse(CommandDetails cmdDet,
359371 mCmdIf .sendTerminalResponse (hexString , null );
360372 }
361373
374+ private void encodeOptionalTags (CommandDetails cmdDet ,
375+ ResultCode resultCode , Input cmdInput , ByteArrayOutputStream buf ) {
376+ switch (AppInterface .CommandType .fromInt (cmdDet .typeOfCommand )) {
377+ case GET_INKEY :
378+ // ETSI TS 102 384,27.22.4.2.8.4.2.
379+ // If it is a response for GET_INKEY command and the response timeout
380+ // occured, then add DURATION TLV for variable timeout case.
381+ if ((resultCode .value () == ResultCode .NO_RESPONSE_FROM_USER .value ()) &&
382+ (cmdInput != null ) && (cmdInput .duration != null )) {
383+ getInKeyResponse (buf , cmdInput );
384+ }
385+ break ;
386+ case PROVIDE_LOCAL_INFORMATION :
387+ if ((cmdDet .commandQualifier == CommandParamsFactory .LANGUAGE_SETTING ) &&
388+ (resultCode .value () == ResultCode .OK .value ())) {
389+ getPliResponse (buf );
390+ }
391+ break ;
392+ default :
393+ CatLog .d (this , "encodeOptionalTags() Unsupported Cmd:" + cmdDet .typeOfCommand );
394+ break ;
395+ }
396+ }
397+
398+ private void getInKeyResponse (ByteArrayOutputStream buf , Input cmdInput ) {
399+ int tag = ComprehensionTlvTag .DURATION .value ();
400+
401+ buf .write (tag );
402+ buf .write (0x02 ); // length
403+ buf .write (cmdInput .duration .timeUnit .SECOND .value ()); // Time (Unit,Seconds)
404+ buf .write (cmdInput .duration .timeInterval ); // Time Duration
405+ }
406+
407+ private void getPliResponse (ByteArrayOutputStream buf ) {
408+
409+ // Locale Language Setting
410+ String lang = SystemProperties .get ("persist.sys.language" );
411+
412+ if (lang != null ) {
413+ // tag
414+ int tag = ComprehensionTlvTag .LANGUAGE .value ();
415+ buf .write (tag );
416+ ResponseData .writeLength (buf , lang .length ());
417+ buf .write (lang .getBytes (), 0 , lang .length ());
418+ }
419+ }
362420
363421 private void sendMenuSelection (int menuId , boolean helpRequired ) {
364422
0 commit comments