private void encodeOptionalTags(
     CommandDetails cmdDet, ResultCode resultCode, Input cmdInput, ByteArrayOutputStream buf) {
   CommandType cmdType = AppInterface.CommandType.fromInt(cmdDet.typeOfCommand);
   if (cmdType != null) {
     switch (cmdType) {
       case GET_INKEY:
         // ETSI TS 102 384,27.22.4.2.8.4.2.
         // If it is a response for GET_INKEY command and the response timeout
         // occured, then add DURATION TLV for variable timeout case.
         if ((resultCode.value() == ResultCode.NO_RESPONSE_FROM_USER.value())
             && (cmdInput != null)
             && (cmdInput.duration != null)) {
           getInKeyResponse(buf, cmdInput);
         }
         break;
       case PROVIDE_LOCAL_INFORMATION:
         if ((cmdDet.commandQualifier == CommandParamsFactory.LANGUAGE_SETTING)
             && (resultCode.value() == ResultCode.OK.value())) {
           getPliResponse(buf);
         }
         break;
       default:
         CatLog.d(this, "encodeOptionalTags() Unsupported Cmd details=" + cmdDet);
         break;
     }
   } else {
     CatLog.d(this, "encodeOptionalTags() bad Cmd details=" + cmdDet);
   }
 }
  private ResultCode setIcons(Object data) {
    Bitmap[] icons = null;
    int iconIndex = 0;

    if (data == null) {
      if (mloadIcon) {
        CatLog.d(this, "Optional Icon data is NULL");
        mCmdParams.loadIconFailed = true;
        mloadIcon = false;
        /**
         * In case of icon load fail consider the * received proactive command as valid (sending
         * RESULT OK)
         */
        return ResultCode.OK;
      }
      return ResultCode.PRFRMD_ICON_NOT_DISPLAYED;
    }
    switch (mIconLoadState) {
      case LOAD_SINGLE_ICON:
        mCmdParams.setIcon((Bitmap) data);
        break;
      case LOAD_MULTI_ICONS:
        icons = (Bitmap[]) data;
        // set each item icon.
        for (Bitmap icon : icons) {
          mCmdParams.setIcon(icon);
          if (icon == null && mloadIcon) {
            CatLog.d(this, "Optional Icon data is NULL while loading multi icons");
            mCmdParams.loadIconFailed = true;
          }
        }
        break;
    }
    return ResultCode.OK;
  }
 private boolean validateResponse(CatResponseMessage resMsg) {
   boolean validResponse = false;
   if ((resMsg.mCmdDet.typeOfCommand == CommandType.SET_UP_EVENT_LIST.value())
       || (resMsg.mCmdDet.typeOfCommand == CommandType.SET_UP_MENU.value())) {
     CatLog.d(this, "CmdType: " + resMsg.mCmdDet.typeOfCommand);
     validResponse = true;
   } else if (mCurrntCmd != null) {
     validResponse = resMsg.mCmdDet.compareTo(mCurrntCmd.mCmdDet);
     CatLog.d(this, "isResponse for last valid cmd: " + validResponse);
   }
   return validResponse;
 }
  /** Handles RIL_UNSOL_STK_SESSION_END unsolicited command from RIL. */
  private void handleSessionEnd() {
    CatLog.d(this, "SESSION END");

    mCurrntCmd = mMenuCmd;
    Intent intent = new Intent(AppInterface.CAT_SESSION_END_ACTION);
    mContext.sendBroadcast(intent);
  }
  /* Intentionally private for singleton */
  private CatService(
      CommandsInterface ci,
      UiccCardApplication ca,
      IccRecords ir,
      Context context,
      IccFileHandler fh,
      UiccCard ic) {
    if (ci == null || ca == null || ir == null || context == null || fh == null || ic == null) {
      throw new NullPointerException("Service: Input parameters must not be null");
    }
    mCmdIf = ci;
    mContext = context;

    // Get the RilMessagesDecoder for decoding the messages.
    mMsgDecoder = RilMessageDecoder.getInstance(this, fh);

    // Register ril events handling.
    mCmdIf.setOnCatSessionEnd(this, MSG_ID_SESSION_END, null);
    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.setOnSimRefresh(this, MSG_ID_REFRESH, null);

    mIccRecords = ir;
    mUiccApplication = ca;

    // Register for SIM ready event.
    mUiccApplication.registerForReady(this, MSG_ID_SIM_READY, null);
    mIccRecords.registerForRecordsLoaded(this, MSG_ID_ICC_RECORDS_LOADED, null);

    // Check if STK application is availalbe
    mStkAppInstalled = isStkAppInstalled();

    CatLog.d(this, "Running CAT service. STK app installed:" + mStkAppInstalled);
  }
  public void dispose() {
    CatLog.d(this, "Disposing CatService object for slot: " + mSlotId);

    // Clean up stk icon if dispose is called
    broadcastCardStateAndIccRefreshResp(CardState.CARDSTATE_ABSENT, null);

    mCmdIf.unSetOnCatSessionEnd(this);
    mCmdIf.unSetOnCatProactiveCmd(this);
    mCmdIf.unSetOnCatEvent(this);
    mCmdIf.unSetOnCatCallSetUp(this);
    mCmdIf.unSetOnCatCcAlphaNotify(this);
    mCmdIf.unSetOnCatSendSmsResult(this);

    mCmdIf.unregisterForIccRefresh(this);
    if (mUiccController != null) {
      mUiccController.unregisterForIccChanged(this);
      mUiccController = null;
    }
    if (mMsgDecoder != null) {
      mMsgDecoder.dispose(mSlotId);
      mMsgDecoder = null;
    }
    mHandlerThread.quit();
    mHandlerThread = null;
    removeCallbacksAndMessages(null);
  }
  /**
   * Processes EVENT_NOTIFY message from baseband.
   *
   * @param cmdDet Command Details container object.
   * @param ctlvs List of ComprehensionTlv objects following Command Details object and Device
   *     Identities object within the proactive command
   * @return true if the command is processing is pending and additional asynchronous processing is
   *     required.
   */
  private boolean processEventNotify(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs)
      throws ResultException {

    CatLog.d(this, "process EventNotify");

    TextMessage textMsg = new TextMessage();
    IconId iconId = null;

    ComprehensionTlv ctlv = searchForTag(ComprehensionTlvTag.ALPHA_ID, ctlvs);
    textMsg.text = ValueParser.retrieveAlphaId(ctlv);

    ctlv = searchForTag(ComprehensionTlvTag.ICON_ID, ctlvs);
    if (ctlv != null) {
      iconId = ValueParser.retrieveIconId(ctlv);
      textMsg.iconSelfExplanatory = iconId.selfExplanatory;
    }

    textMsg.responseNeeded = false;
    mCmdParams = new DisplayTextParams(cmdDet, textMsg);

    if (iconId != null) {
      mloadIcon = true;
      mIconLoadState = LOAD_SINGLE_ICON;
      mIconLoader.loadIcon(iconId.recordNumber, this.obtainMessage(MSG_ID_LOAD_ICON_DONE));
      return true;
    }
    return false;
  }
  /**
   * Processes LAUNCH_BROWSER proactive command from the SIM card.
   *
   * @param cmdDet Command Details container object.
   * @param ctlvs List of ComprehensionTlv objects following Command Details object and Device
   *     Identities object within the proactive command
   * @return true if the command is processing is pending and additional asynchronous processing is
   *     required.
   * @throws ResultException
   */
  private boolean processLaunchBrowser(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs)
      throws ResultException {

    CatLog.d(this, "process LaunchBrowser");

    TextMessage confirmMsg = new TextMessage();
    IconId iconId = null;
    String url = null;

    ComprehensionTlv ctlv = searchForTag(ComprehensionTlvTag.URL, ctlvs);
    if (ctlv != null) {
      try {
        byte[] rawValue = ctlv.getRawValue();
        int valueIndex = ctlv.getValueIndex();
        int valueLen = ctlv.getLength();
        if (valueLen > 0) {
          url = GsmAlphabet.gsm8BitUnpackedToString(rawValue, valueIndex, valueLen);
        } else {
          url = null;
        }
      } catch (IndexOutOfBoundsException e) {
        throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
      }
    }

    // parse alpha identifier.
    ctlv = searchForTag(ComprehensionTlvTag.ALPHA_ID, ctlvs);
    confirmMsg.text = ValueParser.retrieveAlphaId(ctlv);

    // parse icon identifier
    ctlv = searchForTag(ComprehensionTlvTag.ICON_ID, ctlvs);
    if (ctlv != null) {
      iconId = ValueParser.retrieveIconId(ctlv);
      confirmMsg.iconSelfExplanatory = iconId.selfExplanatory;
    }

    // parse command qualifier value.
    LaunchBrowserMode mode;
    switch (cmdDet.commandQualifier) {
      case 0x00:
      default:
        mode = LaunchBrowserMode.LAUNCH_IF_NOT_ALREADY_LAUNCHED;
        break;
      case 0x02:
        mode = LaunchBrowserMode.USE_EXISTING_BROWSER;
        break;
      case 0x03:
        mode = LaunchBrowserMode.LAUNCH_NEW_BROWSER;
        break;
    }

    mCmdParams = new LaunchBrowserParams(cmdDet, confirmMsg, url, mode);

    if (iconId != null) {
      mIconLoadState = LOAD_SINGLE_ICON;
      mIconLoader.loadIcon(iconId.recordNumber, this.obtainMessage(MSG_ID_LOAD_ICON_DONE));
      return true;
    }
    return false;
  }
 private void broadcastCatCmdIntent(CatCmdMessage cmdMsg) {
   Intent intent = new Intent(AppInterface.CAT_CMD_ACTION);
   intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
   intent.putExtra("STK CMD", cmdMsg);
   intent.putExtra("SLOT_ID", mSlotId);
   CatLog.d(this, "Sending CmdMsg: " + cmdMsg + " on slotid:" + mSlotId);
   mContext.sendBroadcast(intent, AppInterface.STK_PERMISSION);
 }
 private void broadcastAlphaMessage(String alphaString) {
   CatLog.d(this, "Broadcasting CAT Alpha message from card: " + alphaString);
   Intent intent = new Intent(AppInterface.CAT_ALPHA_NOTIFY_ACTION);
   intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
   intent.putExtra(AppInterface.ALPHA_STRING, alphaString);
   intent.putExtra("SLOT_ID", mSlotId);
   mContext.sendBroadcast(intent, AppInterface.STK_PERMISSION);
 }
  /**
   * Used for instantiating/updating the Service from the GsmPhone or CdmaPhone constructor.
   *
   * @param ci CommandsInterface object
   * @param ir IccRecords object
   * @param context phone app context
   * @param fh Icc file handler
   * @param ic Icc card
   * @return The only Service object in the system
   */
  public static CatService getInstance(CommandsInterface ci, Context context, UiccCard ic) {
    UiccCardApplication ca = null;
    IccFileHandler fh = null;
    IccRecords ir = null;
    if (ic != null) {
      /* Since Cat is not tied to any application, but rather is Uicc application
       * in itself - just get first FileHandler and IccRecords object
       */
      ca = ic.getApplicationIndex(0);
      if (ca != null) {
        fh = ca.getIccFileHandler();
        ir = ca.getIccRecords();
      }
    }
    synchronized (sInstanceLock) {
      if (sInstance == null) {
        if (ci == null || ca == null || ir == null || context == null || fh == null || ic == null) {
          return null;
        }
        HandlerThread thread = new HandlerThread("Cat Telephony service");
        thread.start();
        sInstance = new CatService(ci, ca, ir, context, fh, ic);
        CatLog.d(sInstance, "NEW sInstance");
      } else if ((ir != null) && (mIccRecords != ir)) {
        if (mIccRecords != null) {
          mIccRecords.unregisterForRecordsLoaded(sInstance);
        }

        if (mUiccApplication != null) {
          mUiccApplication.unregisterForReady(sInstance);
        }
        CatLog.d(sInstance, "Reinitialize the Service with SIMRecords and UiccCardApplication");
        mIccRecords = ir;
        mUiccApplication = ca;

        // re-Register for SIM ready event.
        mIccRecords.registerForRecordsLoaded(sInstance, MSG_ID_ICC_RECORDS_LOADED, null);
        mUiccApplication.registerForReady(sInstance, MSG_ID_SIM_READY, null);
        CatLog.d(sInstance, "sr changed reinitialize and return current sInstance");
      } else {
        CatLog.d(sInstance, "Return current sInstance");
      }
      return sInstance;
    }
  }
  /** Handles RIL_UNSOL_STK_SESSION_END unsolicited command from RIL. */
  private void handleSessionEnd() {
    CatLog.d(this, "SESSION END on " + mSlotId);

    mCurrntCmd = mMenuCmd;
    Intent intent = new Intent(AppInterface.CAT_SESSION_END_ACTION);
    intent.putExtra("SLOT_ID", mSlotId);
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    mContext.sendBroadcast(intent, AppInterface.STK_PERMISSION);
  }
  /**
   * * This function sends a CARD status (ABSENT, PRESENT, REFRESH) to STK_APP. * This is triggered
   * during ICC_REFRESH or CARD STATE changes. In case * REFRESH, additional information is sent in
   * 'refresh_result' *
   */
  private void broadcastCardStateAndIccRefreshResp(
      CardState cardState, IccRefreshResponse iccRefreshState) {
    Intent intent = new Intent(AppInterface.CAT_ICC_STATUS_CHANGE);
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    boolean cardPresent = (cardState == CardState.CARDSTATE_PRESENT);

    if (iccRefreshState != null) {
      // This case is when MSG_ID_ICC_REFRESH is received.
      intent.putExtra(AppInterface.REFRESH_RESULT, iccRefreshState.refreshResult);
      CatLog.d(this, "Sending IccResult with Result: " + iccRefreshState.refreshResult);
    }

    // This sends an intent with CARD_ABSENT (0 - false) /CARD_PRESENT (1 - true).
    intent.putExtra(AppInterface.CARD_STATUS, cardPresent);
    intent.putExtra("SLOT_ID", mSlotId);
    CatLog.d(this, "Sending Card Status: " + cardState + " " + "cardPresent: " + cardPresent);
    mContext.sendBroadcast(intent, AppInterface.STK_PERMISSION);
  }
 private boolean processProvideLocalInfo(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs)
     throws ResultException {
   CatLog.d(this, "process ProvideLocalInfo");
   switch (cmdDet.commandQualifier) {
     case DTTZ_SETTING:
       CatLog.d(this, "PLI [DTTZ_SETTING]");
       mCmdParams = new CommandParams(cmdDet);
       break;
     case LANGUAGE_SETTING:
       CatLog.d(this, "PLI [LANGUAGE_SETTING]");
       mCmdParams = new CommandParams(cmdDet);
       break;
     default:
       CatLog.d(this, "PLI[" + cmdDet.commandQualifier + "] Command Not Supported");
       mCmdParams = new CommandParams(cmdDet);
       throw new ResultException(ResultCode.BEYOND_TERMINAL_CAPABILITY);
   }
   return false;
 }
  private byte byteToBCD(int value) {
    if (value < 0 && value > 99) {
      CatLog.d(
          this,
          "Err: byteToBCD conversion Value is " + value + " Value has to be between 0 and 99");
      return 0;
    }

    return (byte) ((value / 10) | ((value % 10) << 4));
  }
  private void handleRilMsg(RilMessage rilMsg) {
    if (rilMsg == null) {
      return;
    }

    // dispatch messages
    CommandParams cmdParams = null;
    switch (rilMsg.mId) {
      case MSG_ID_EVENT_NOTIFY:
        if (rilMsg.mResCode == ResultCode.OK) {
          cmdParams = (CommandParams) rilMsg.mData;
          if (cmdParams != null) {
            handleCommand(cmdParams, false);
          }
        }
        break;
      case MSG_ID_PROACTIVE_COMMAND:
        try {
          cmdParams = (CommandParams) rilMsg.mData;
        } catch (ClassCastException e) {
          // for error handling : cast exception
          CatLog.d(this, "Fail to parse proactive command");
          // Don't send Terminal Resp if command detail is not available
          if (mCurrntCmd != null) {
            sendTerminalResponse(
                mCurrntCmd.mCmdDet, ResultCode.CMD_DATA_NOT_UNDERSTOOD, false, 0x00, null);
          }
          break;
        }
        if (cmdParams != null) {
          if (rilMsg.mResCode == ResultCode.OK) {
            handleCommand(cmdParams, true);
          } else {
            // for proactive commands that couldn't be decoded
            // successfully respond with the code generated by the
            // message decoder.
            sendTerminalResponse(cmdParams.mCmdDet, rilMsg.mResCode, false, 0, null);
          }
        }
        break;
      case MSG_ID_REFRESH:
        cmdParams = (CommandParams) rilMsg.mData;
        if (cmdParams != null) {
          handleCommand(cmdParams, false);
        }
        break;
      case MSG_ID_SESSION_END:
        handleSessionEnd();
        break;
      case MSG_ID_CALL_SETUP:
        // prior event notify command supplied all the information
        // needed for set up call processing.
        break;
    }
  }
 private boolean removeMenu(Menu menu) {
   try {
     if (menu.items.size() == 1 && menu.items.get(0) == null) {
       return true;
     }
   } catch (NullPointerException e) {
     CatLog.d(this, "Unable to get Menu's items size");
     return true;
   }
   return false;
 }
Пример #18
0
 @Override
 public boolean processMessage(Message msg) {
   if (msg.what == CMD_START) {
     if (decodeMessageParams((RilMessage) msg.obj)) {
       transitionTo(mStateCmdParamsReady);
     }
   } else {
     CatLog.d(this, "StateStart unexpected expecting START=" + CMD_START + " got " + msg.what);
   }
   return true;
 }
  @Override
  public void handleMessage(Message msg) {

    switch (msg.what) {
      case MSG_ID_SESSION_END:
      case MSG_ID_PROACTIVE_COMMAND:
      case MSG_ID_EVENT_NOTIFY:
      case MSG_ID_REFRESH:
        CatLog.d(this, "ril message arrived");
        String data = null;
        if (msg.obj != null) {
          AsyncResult ar = (AsyncResult) msg.obj;
          if (ar != null && ar.result != null) {
            try {
              data = (String) ar.result;
            } catch (ClassCastException e) {
              break;
            }
          }
        }
        mMsgDecoder.sendStartDecodingMessageParams(new RilMessage(msg.what, data));
        break;
      case MSG_ID_CALL_SETUP:
        mMsgDecoder.sendStartDecodingMessageParams(new RilMessage(msg.what, null));
        break;
      case MSG_ID_ICC_RECORDS_LOADED:
        break;
      case MSG_ID_RIL_MSG_DECODED:
        handleRilMsg((RilMessage) msg.obj);
        break;
      case MSG_ID_RESPONSE:
        handleCmdResponse((CatResponseMessage) msg.obj);
        break;
      case MSG_ID_SIM_READY:
        CatLog.d(this, "SIM ready. Reporting STK service running now...");
        mCmdIf.reportStkServiceIsRunning(null);
        break;
      default:
        throw new AssertionError("Unrecognized CAT command: " + msg.what);
    }
  }
Пример #20
0
  private boolean decodeMessageParams(RilMessage rilMsg) {
    boolean decodingStarted;

    mCurrentRilMessage = rilMsg;
    switch (rilMsg.mId) {
      case CatService.MSG_ID_SESSION_END:
      case CatService.MSG_ID_CALL_SETUP:
        mCurrentRilMessage.mResCode = ResultCode.OK;
        sendCmdForExecution(mCurrentRilMessage);
        decodingStarted = false;
        break;
      case CatService.MSG_ID_PROACTIVE_COMMAND:
      case CatService.MSG_ID_EVENT_NOTIFY:
      case CatService.MSG_ID_REFRESH:
        byte[] rawData = null;
        try {
          rawData = IccUtils.hexStringToBytes((String) rilMsg.mData);
        } catch (Exception e) {
          // zombie messages are dropped
          CatLog.d(this, "decodeMessageParams dropping zombie messages");
          decodingStarted = false;
          break;
        }
        try {
          // Start asynch parsing of the command parameters.
          mCmdParamsFactory.make(BerTlv.decode(rawData));
          decodingStarted = true;
        } catch (ResultException e) {
          // send to Service for proper RIL communication.
          CatLog.d(this, "decodeMessageParams: caught ResultException e=" + e);
          mCurrentRilMessage.mResCode = e.result();
          sendCmdForExecution(mCurrentRilMessage);
          decodingStarted = false;
        }
        break;
      default:
        decodingStarted = false;
        break;
    }
    return decodingStarted;
  }
  /**
   * Processes PLAY_TONE proactive command from the SIM card.
   *
   * @param cmdDet Command Details container object.
   * @param ctlvs List of ComprehensionTlv objects following Command Details object and Device
   *     Identities object within the proactive command
   * @return true if the command is processing is pending and additional asynchronous processing is
   *     required.t
   * @throws ResultException
   */
  private boolean processPlayTone(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs)
      throws ResultException {

    CatLog.d(this, "process PlayTone");

    Tone tone = null;
    TextMessage textMsg = new TextMessage();
    Duration duration = null;
    IconId iconId = null;

    ComprehensionTlv ctlv = searchForTag(ComprehensionTlvTag.TONE, ctlvs);
    if (ctlv != null) {
      // Nothing to do for null objects.
      if (ctlv.getLength() > 0) {
        try {
          byte[] rawValue = ctlv.getRawValue();
          int valueIndex = ctlv.getValueIndex();
          int toneVal = rawValue[valueIndex];
          tone = Tone.fromInt(toneVal);
        } catch (IndexOutOfBoundsException e) {
          throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
        }
      }
    }
    // parse alpha identifier
    ctlv = searchForTag(ComprehensionTlvTag.ALPHA_ID, ctlvs);
    if (ctlv != null) {
      textMsg.text = ValueParser.retrieveAlphaId(ctlv);
    }
    // parse tone duration
    ctlv = searchForTag(ComprehensionTlvTag.DURATION, ctlvs);
    if (ctlv != null) {
      duration = ValueParser.retrieveDuration(ctlv);
    }
    // parse icon identifier
    ctlv = searchForTag(ComprehensionTlvTag.ICON_ID, ctlvs);
    if (ctlv != null) {
      iconId = ValueParser.retrieveIconId(ctlv);
      textMsg.iconSelfExplanatory = iconId.selfExplanatory;
    }

    boolean vibrate = (cmdDet.commandQualifier & 0x01) != 0x00;

    textMsg.responseNeeded = false;
    mCmdParams = new PlayToneParams(cmdDet, textMsg, tone, duration, vibrate);

    if (iconId != null) {
      mIconLoadState = LOAD_SINGLE_ICON;
      mIconLoader.loadIcon(iconId.recordNumber, this.obtainMessage(MSG_ID_LOAD_ICON_DONE));
      return true;
    }
    return false;
  }
  /* For multisim catservice should not be singleton */
  CatService(CommandsInterface ci, Context context, IccFileHandler fh, int slotId) {
    if (ci == null || context == null || fh == null) {
      throw new NullPointerException("Service: Input parameters must not be null");
    }
    mCmdIf = ci;
    mContext = context;
    mSlotId = slotId;
    mHandlerThread = new HandlerThread("Cat Telephony service" + slotId);
    mHandlerThread.start();

    // Get the RilMessagesDecoder for decoding the messages.
    mMsgDecoder = RilMessageDecoder.getInstance(this, fh, slotId);
    if (null == mMsgDecoder) {
      CatLog.d(this, "Null RilMessageDecoder instance");
      return;
    }
    mMsgDecoder.start();

    // Register ril events handling.
    mCmdIf.setOnCatSessionEnd(this, MSG_ID_SESSION_END, null);
    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);

    mCmdIf.registerForIccRefresh(this, MSG_ID_ICC_REFRESH, null);
    mCmdIf.setOnCatCcAlphaNotify(this, MSG_ID_ALPHA_NOTIFY, null);

    mUiccController = UiccController.getInstance();
    mUiccController.registerForIccChanged(this, MSG_ID_ICC_CHANGED, null);

    // Check if STK application is availalbe
    mStkAppInstalled = isStkAppInstalled();

    CatLog.d(
        this,
        "Running CAT service on Slotid: " + mSlotId + ". STK app installed:" + mStkAppInstalled);
  }
  /**
   * Processes SET_UP_EVENT_LIST proactive command from the SIM card.
   *
   * @param cmdDet Command Details object retrieved.
   * @param ctlvs List of ComprehensionTlv objects following Command Details object and Device
   *     Identities object within the proactive command
   * @return false. This function always returns false meaning that the command processing is not
   *     pending and additional asynchronous processing is not required.
   */
  private boolean processSetUpEventList(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs) {

    CatLog.d(this, "process SetUpEventList");
    ComprehensionTlv ctlv = searchForTag(ComprehensionTlvTag.EVENT_LIST, ctlvs);
    if (ctlv != null) {
      try {
        byte[] rawValue = ctlv.getRawValue();
        int valueIndex = ctlv.getValueIndex();
        int valueLen = ctlv.getLength();
        int[] eventList = new int[valueLen];
        int eventValue = -1;
        int i = 0;
        while (valueLen > 0) {
          eventValue = rawValue[valueIndex] & 0xff;
          valueIndex++;
          valueLen--;

          switch (eventValue) {
            case USER_ACTIVITY_EVENT:
            case IDLE_SCREEN_AVAILABLE_EVENT:
            case LANGUAGE_SELECTION_EVENT:
            case BROWSER_TERMINATION_EVENT:
            case BROWSING_STATUS_EVENT:
              eventList[i] = eventValue;
              i++;
              break;
            default:
              break;
          }
        }
        mCmdParams = new SetEventListParams(cmdDet, eventList);
      } catch (IndexOutOfBoundsException e) {
        CatLog.d(this, " IndexOutofBoundException in processSetUpEventList");
      }
    }
    return false;
  }
  private boolean processBIPClient(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs)
      throws ResultException {
    AppInterface.CommandType commandType = AppInterface.CommandType.fromInt(cmdDet.typeOfCommand);
    if (commandType != null) {
      CatLog.d(this, "process " + commandType.name());
    }

    TextMessage textMsg = new TextMessage();
    IconId iconId = null;
    ComprehensionTlv ctlv = null;
    boolean has_alpha_id = false;

    // parse alpha identifier
    ctlv = searchForTag(ComprehensionTlvTag.ALPHA_ID, ctlvs);
    if (ctlv != null) {
      textMsg.text = ValueParser.retrieveAlphaId(ctlv);
      CatLog.d(this, "alpha TLV text=" + textMsg.text);
      has_alpha_id = true;
    }

    // parse icon identifier
    ctlv = searchForTag(ComprehensionTlvTag.ICON_ID, ctlvs);
    if (ctlv != null) {
      iconId = ValueParser.retrieveIconId(ctlv);
      textMsg.iconSelfExplanatory = iconId.selfExplanatory;
    }

    textMsg.responseNeeded = false;
    mCmdParams = new BIPClientParams(cmdDet, textMsg, has_alpha_id);

    if (iconId != null) {
      mIconLoadState = LOAD_SINGLE_ICON;
      mIconLoader.loadIcon(iconId.recordNumber, this.obtainMessage(MSG_ID_LOAD_ICON_DONE));
      return true;
    }
    return false;
  }
  /**
   * Processes DISPLAY_TEXT proactive command from the SIM card.
   *
   * @param cmdDet Command Details container object.
   * @param ctlvs List of ComprehensionTlv objects following Command Details object and Device
   *     Identities object within the proactive command
   * @return true if the command is processing is pending and additional asynchronous processing is
   *     required.
   * @throws ResultException
   */
  private boolean processDisplayText(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs)
      throws ResultException {

    CatLog.d(this, "process DisplayText");

    TextMessage textMsg = new TextMessage();
    IconId iconId = null;

    ComprehensionTlv ctlv = searchForTag(ComprehensionTlvTag.TEXT_STRING, ctlvs);
    if (ctlv != null) {
      textMsg.text = ValueParser.retrieveTextString(ctlv);
    }
    // If the tlv object doesn't exist or the it is a null object reply
    // with command not understood.
    if (textMsg.text == null) {
      throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
    }

    ctlv = searchForTag(ComprehensionTlvTag.IMMEDIATE_RESPONSE, ctlvs);
    if (ctlv != null) {
      textMsg.responseNeeded = false;
    }
    // parse icon identifier
    ctlv = searchForTag(ComprehensionTlvTag.ICON_ID, ctlvs);
    if (ctlv != null) {
      iconId = ValueParser.retrieveIconId(ctlv);
      textMsg.iconSelfExplanatory = iconId.selfExplanatory;
    }
    // parse tone duration
    ctlv = searchForTag(ComprehensionTlvTag.DURATION, ctlvs);
    if (ctlv != null) {
      textMsg.duration = ValueParser.retrieveDuration(ctlv);
    }

    // Parse command qualifier parameters.
    textMsg.isHighPriority = (cmdDet.commandQualifier & 0x01) != 0;
    textMsg.userClear = (cmdDet.commandQualifier & 0x80) != 0;

    mCmdParams = new DisplayTextParams(cmdDet, textMsg);

    if (iconId != null) {
      mloadIcon = true;
      mIconLoadState = LOAD_SINGLE_ICON;
      mIconLoader.loadIcon(iconId.recordNumber, this.obtainMessage(MSG_ID_LOAD_ICON_DONE));
      return true;
    }
    return false;
  }
  /**
   * Processes SETUP_CALL proactive command from the SIM card.
   *
   * @param cmdDet Command Details object retrieved from the proactive command object
   * @param ctlvs List of ComprehensionTlv objects following Command Details object and Device
   *     Identities object within the proactive command
   * @return true if the command is processing is pending and additional asynchronous processing is
   *     required.
   */
  private boolean processSetupCall(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs)
      throws ResultException {
    CatLog.d(this, "process SetupCall");

    Iterator<ComprehensionTlv> iter = ctlvs.iterator();
    ComprehensionTlv ctlv = null;
    // User confirmation phase message.
    TextMessage confirmMsg = new TextMessage();
    // Call set up phase message.
    TextMessage callMsg = new TextMessage();
    IconId confirmIconId = null;
    IconId callIconId = null;

    // get confirmation message string.
    ctlv = searchForNextTag(ComprehensionTlvTag.ALPHA_ID, iter);
    confirmMsg.text = ValueParser.retrieveAlphaId(ctlv);

    ctlv = searchForTag(ComprehensionTlvTag.ICON_ID, ctlvs);
    if (ctlv != null) {
      confirmIconId = ValueParser.retrieveIconId(ctlv);
      confirmMsg.iconSelfExplanatory = confirmIconId.selfExplanatory;
    }

    // get call set up message string.
    ctlv = searchForNextTag(ComprehensionTlvTag.ALPHA_ID, iter);
    if (ctlv != null) {
      callMsg.text = ValueParser.retrieveAlphaId(ctlv);
    }

    ctlv = searchForTag(ComprehensionTlvTag.ICON_ID, ctlvs);
    if (ctlv != null) {
      callIconId = ValueParser.retrieveIconId(ctlv);
      callMsg.iconSelfExplanatory = callIconId.selfExplanatory;
    }

    mCmdParams = new CallSetupParams(cmdDet, confirmMsg, callMsg);

    if (confirmIconId != null || callIconId != null) {
      mIconLoadState = LOAD_MULTI_ICONS;
      int[] recordNumbers = new int[2];
      recordNumbers[0] = confirmIconId != null ? confirmIconId.recordNumber : -1;
      recordNumbers[1] = callIconId != null ? callIconId.recordNumber : -1;

      mIconLoader.loadIcons(recordNumbers, this.obtainMessage(MSG_ID_LOAD_ICON_DONE));
      return true;
    }
    return false;
  }
  private CommandDetails processCommandDetails(List<ComprehensionTlv> ctlvs) {
    CommandDetails cmdDet = null;

    if (ctlvs != null) {
      // Search for the Command Details object.
      ComprehensionTlv ctlvCmdDet = searchForTag(ComprehensionTlvTag.COMMAND_DETAILS, ctlvs);
      if (ctlvCmdDet != null) {
        try {
          cmdDet = ValueParser.retrieveCommandDetails(ctlvCmdDet);
        } catch (ResultException e) {
          CatLog.d(this, "processCommandDetails: Failed to procees command details e=" + e);
        }
      }
    }
    return cmdDet;
  }
  /**
   * Processes REFRESH proactive command from the SIM card.
   *
   * @param cmdDet Command Details container object.
   * @param ctlvs List of ComprehensionTlv objects following Command Details object and Device
   *     Identities object within the proactive command
   */
  private boolean processRefresh(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs) {

    CatLog.d(this, "process Refresh");

    // REFRESH proactive command is rerouted by the baseband and handled by
    // the telephony layer. IDLE TEXT should be removed for a REFRESH command
    // with "initialization" or "reset"
    switch (cmdDet.commandQualifier) {
      case REFRESH_NAA_INIT_AND_FULL_FILE_CHANGE:
      case REFRESH_NAA_INIT_AND_FILE_CHANGE:
      case REFRESH_NAA_INIT:
      case REFRESH_UICC_RESET:
        mCmdParams = new DisplayTextParams(cmdDet, null);
        break;
    }
    return false;
  }
  /**
   * Processes GET_INKEY proactive command from the SIM card.
   *
   * @param cmdDet Command Details container object.
   * @param ctlvs List of ComprehensionTlv objects following Command Details object and Device
   *     Identities object within the proactive command
   * @return true if the command is processing is pending and additional asynchronous processing is
   *     required.
   * @throws ResultException
   */
  private boolean processGetInkey(CommandDetails cmdDet, List<ComprehensionTlv> ctlvs)
      throws ResultException {

    CatLog.d(this, "process GetInkey");

    Input input = new Input();
    IconId iconId = null;

    ComprehensionTlv ctlv = searchForTag(ComprehensionTlvTag.TEXT_STRING, ctlvs);
    if (ctlv != null) {
      input.text = ValueParser.retrieveTextString(ctlv);
    } else {
      throw new ResultException(ResultCode.REQUIRED_VALUES_MISSING);
    }
    // parse icon identifier
    ctlv = searchForTag(ComprehensionTlvTag.ICON_ID, ctlvs);
    if (ctlv != null) {
      iconId = ValueParser.retrieveIconId(ctlv);
    }

    // parse duration
    ctlv = searchForTag(ComprehensionTlvTag.DURATION, ctlvs);
    if (ctlv != null) {
      input.duration = ValueParser.retrieveDuration(ctlv);
    }

    input.minLen = 1;
    input.maxLen = 1;

    input.digitOnly = (cmdDet.commandQualifier & 0x01) == 0;
    input.ucs2 = (cmdDet.commandQualifier & 0x02) != 0;
    input.yesNo = (cmdDet.commandQualifier & 0x04) != 0;
    input.helpAvailable = (cmdDet.commandQualifier & 0x80) != 0;
    input.echo = true;

    mCmdParams = new GetInputParams(cmdDet, input);

    if (iconId != null) {
      mloadIcon = true;
      mIconLoadState = LOAD_SINGLE_ICON;
      mIconLoader.loadIcon(iconId.recordNumber, this.obtainMessage(MSG_ID_LOAD_ICON_DONE));
      return true;
    }
    return false;
  }
Пример #30
0
 @Override
 public boolean processMessage(Message msg) {
   if (msg.what == CMD_PARAMS_READY) {
     mCurrentRilMessage.mResCode = ResultCode.fromInt(msg.arg1);
     mCurrentRilMessage.mData = msg.obj;
     sendCmdForExecution(mCurrentRilMessage);
     transitionTo(mStateStart);
   } else {
     CatLog.d(
         this,
         "StateCmdParamsReady expecting CMD_PARAMS_READY="
             + CMD_PARAMS_READY
             + " got "
             + msg.what);
     deferMessage(msg);
   }
   return true;
 }