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;
  }
  /**
   * Handles RIL_UNSOL_STK_EVENT_NOTIFY or RIL_UNSOL_STK_PROACTIVE_COMMAND command from RIL. Sends
   * valid proactive command data to the application using intents.
   * RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE will be send back if the command is from
   * RIL_UNSOL_STK_PROACTIVE_COMMAND.
   */
  private void handleCommand(CommandParams cmdParams, boolean isProactiveCmd) {
    CatLog.d(this, cmdParams.getCommandType().name());

    // Log all proactive commands.
    if (isProactiveCmd) {
      if (mUiccController != null) {
        mUiccController.addCardLog(
            "ProactiveCommand mSlotId=" + mSlotId + " cmdParams=" + cmdParams);
      }
    }

    CharSequence message;
    ResultCode resultCode;
    CatCmdMessage cmdMsg = new CatCmdMessage(cmdParams);
    switch (cmdParams.getCommandType()) {
      case SET_UP_MENU:
        if (removeMenu(cmdMsg.getMenu())) {
          mMenuCmd = null;
        } else {
          mMenuCmd = cmdMsg;
        }
        resultCode =
            cmdParams.mLoadIconFailed ? ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK;
        if (isProactiveCmd) {
          sendTerminalResponse(cmdParams.mCmdDet, resultCode, false, 0, null);
        }
        break;
      case DISPLAY_TEXT:
        break;
      case REFRESH:
        // Stk app service displays alpha id to user if it is present, nothing to do here
        CatLog.d(this, "Pass Refresh to Stk app");
        break;
      case SET_UP_IDLE_MODE_TEXT:
        resultCode =
            cmdParams.mLoadIconFailed ? ResultCode.PRFRMD_ICON_NOT_DISPLAYED : ResultCode.OK;
        if (isProactiveCmd) {
          sendTerminalResponse(cmdParams.mCmdDet, resultCode, false, 0, null);
        }
        break;
      case SET_UP_EVENT_LIST:
        if (isProactiveCmd) {
          if (isSupportedSetupEventCommand(cmdMsg)) {
            sendTerminalResponse(cmdParams.mCmdDet, ResultCode.OK, false, 0, null);
          } else {
            sendTerminalResponse(
                cmdParams.mCmdDet, ResultCode.BEYOND_TERMINAL_CAPABILITY, false, 0, null);
          }
        }
        break;
      case PROVIDE_LOCAL_INFORMATION:
        ResponseData resp;
        switch (cmdParams.mCmdDet.commandQualifier) {
          case CommandParamsFactory.DTTZ_SETTING:
            resp = new DTTZResponseData(null);
            sendTerminalResponse(cmdParams.mCmdDet, ResultCode.OK, false, 0, resp);
            break;
          case CommandParamsFactory.LANGUAGE_SETTING:
            resp = new LanguageResponseData(Locale.getDefault().getLanguage());
            sendTerminalResponse(cmdParams.mCmdDet, ResultCode.OK, false, 0, resp);
            break;
          default:
            sendTerminalResponse(cmdParams.mCmdDet, ResultCode.OK, false, 0, null);
        }
        // No need to start STK app here.
        return;
      case LAUNCH_BROWSER:
        if ((((LaunchBrowserParams) cmdParams).mConfirmMsg.text != null)
            && (((LaunchBrowserParams) cmdParams).mConfirmMsg.text.equals(STK_DEFAULT))) {
          message = mContext.getText(com.android.internal.R.string.launchBrowserDefault);
          ((LaunchBrowserParams) cmdParams).mConfirmMsg.text = message.toString();
        }
        break;
      case SELECT_ITEM:
      case GET_INPUT:
      case GET_INKEY:
        break;
      case SEND_DTMF:
      case SEND_SMS:
        // Samsung STK
        if (cmdParams instanceof SendSMSParams) {
          handleProactiveCommandSendSMS((SendSMSParams) cmdParams);
        }
        // Fall through
      case SEND_SS:
      case SEND_USSD:
        // Samsung STK
        if (cmdParams instanceof SendUSSDParams) {
          handleProactiveCommandSendUSSD((SendUSSDParams) cmdParams);
        }
        if ((((DisplayTextParams) cmdParams).mTextMsg.text != null)
            && (((DisplayTextParams) cmdParams).mTextMsg.text.equals(STK_DEFAULT))) {
          message = mContext.getText(com.android.internal.R.string.sending);
          ((DisplayTextParams) cmdParams).mTextMsg.text = message.toString();
        }
        break;
      case PLAY_TONE:
        break;
      case SET_UP_CALL:
        if ((((CallSetupParams) cmdParams).mConfirmMsg.text != null)
            && (((CallSetupParams) cmdParams).mConfirmMsg.text.equals(STK_DEFAULT))) {
          message = mContext.getText(com.android.internal.R.string.SetupCallDefault);
          ((CallSetupParams) cmdParams).mConfirmMsg.text = message.toString();
        }
        break;
      case OPEN_CHANNEL:
      case CLOSE_CHANNEL:
      case RECEIVE_DATA:
      case SEND_DATA:
        BIPClientParams cmd = (BIPClientParams) cmdParams;
        /* Per 3GPP specification 102.223,
         * if the alpha identifier is not provided by the UICC,
         * the terminal MAY give information to the user
         * noAlphaUsrCnf defines if you need to show user confirmation or not
         */
        boolean noAlphaUsrCnf = false;
        try {
          noAlphaUsrCnf =
              mContext
                  .getResources()
                  .getBoolean(com.android.internal.R.bool.config_stkNoAlphaUsrCnf);
        } catch (NotFoundException e) {
          noAlphaUsrCnf = false;
        }
        if ((cmd.mTextMsg.text == null) && (cmd.mHasAlphaId || noAlphaUsrCnf)) {
          CatLog.d(this, "cmd " + cmdParams.getCommandType() + " with null alpha id");
          // If alpha length is zero, we just respond with OK.
          if (isProactiveCmd) {
            sendTerminalResponse(cmdParams.mCmdDet, ResultCode.OK, false, 0, null);
          } else if (cmdParams.getCommandType() == CommandType.OPEN_CHANNEL) {
            mCmdIf.handleCallSetupRequestFromSim(true, null);
          }
          return;
        }
        // Respond with permanent failure to avoid retry if STK app is not present.
        if (!mStkAppInstalled) {
          CatLog.d(this, "No STK application found.");
          if (isProactiveCmd) {
            sendTerminalResponse(
                cmdParams.mCmdDet, ResultCode.BEYOND_TERMINAL_CAPABILITY, false, 0, null);
            return;
          }
        }
        /*
         * CLOSE_CHANNEL, RECEIVE_DATA and SEND_DATA can be delivered by
         * either PROACTIVE_COMMAND or EVENT_NOTIFY.
         * If PROACTIVE_COMMAND is used for those commands, send terminal
         * response here.
         */
        if (isProactiveCmd
            && ((cmdParams.getCommandType() == CommandType.CLOSE_CHANNEL)
                || (cmdParams.getCommandType() == CommandType.RECEIVE_DATA)
                || (cmdParams.getCommandType() == CommandType.SEND_DATA))) {
          sendTerminalResponse(cmdParams.mCmdDet, ResultCode.OK, false, 0, null);
        }
        break;
      case ACTIVATE:
        // TO DO: Retrieve the target of the ACTIVATE cmd from the cmd.
        // Target : '01' = UICC-CFL interface according to TS 102 613 [39];
        //          '00' and '02' to 'FF' = RFU (Reserved for Future Use).
        resultCode = ResultCode.OK;
        sendTerminalResponse(cmdParams.mCmdDet, resultCode, false, 0, null);
        break;
      default:
        CatLog.d(this, "Unsupported command");
        return;
    }
    mCurrntCmd = cmdMsg;
    broadcastCatCmdIntent(cmdMsg);
  }
  /**
   * Handles RIL_UNSOL_STK_EVENT_NOTIFY or RIL_UNSOL_STK_PROACTIVE_COMMAND command from RIL. Sends
   * valid proactive command data to the application using intents.
   * RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE will be send back if the command is from
   * RIL_UNSOL_STK_PROACTIVE_COMMAND.
   */
  private void handleCommand(CommandParams cmdParams, boolean isProactiveCmd) {
    CatLog.d(this, cmdParams.getCommandType().name());

    CharSequence message;
    CatCmdMessage cmdMsg = new CatCmdMessage(cmdParams);
    switch (cmdParams.getCommandType()) {
      case SET_UP_MENU:
        if (removeMenu(cmdMsg.getMenu())) {
          mMenuCmd = null;
        } else {
          mMenuCmd = cmdMsg;
        }
        sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, null);
        break;
      case DISPLAY_TEXT:
        // when application is not required to respond, send an immediate response.
        if (!cmdMsg.geTextMessage().responseNeeded) {
          sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, null);
        }
        break;
      case REFRESH:
        // ME side only handles refresh commands which meant to remove IDLE
        // MODE TEXT.
        cmdParams.cmdDet.typeOfCommand = CommandType.SET_UP_IDLE_MODE_TEXT.value();
        break;
      case SET_UP_IDLE_MODE_TEXT:
        sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, null);
        break;
      case PROVIDE_LOCAL_INFORMATION:
        ResponseData resp;
        switch (cmdParams.cmdDet.commandQualifier) {
          case CommandParamsFactory.DTTZ_SETTING:
            resp = new DTTZResponseData(null);
            sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, resp);
            break;
          case CommandParamsFactory.LANGUAGE_SETTING:
            resp = new LanguageResponseData(Locale.getDefault().getLanguage());
            sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, resp);
            break;
          default:
            sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, null);
        }
        // No need to start STK app here.
        return;
      case LAUNCH_BROWSER:
        if ((((LaunchBrowserParams) cmdParams).confirmMsg.text != null)
            && (((LaunchBrowserParams) cmdParams).confirmMsg.text.equals(STK_DEFAULT))) {
          message = mContext.getText(com.android.internal.R.string.launchBrowserDefault);
          ((LaunchBrowserParams) cmdParams).confirmMsg.text = message.toString();
        }
        break;
      case SELECT_ITEM:
      case GET_INPUT:
      case GET_INKEY:
        break;
      case SEND_DTMF:
      case SEND_SMS:
      case SEND_SS:
      case SEND_USSD:
        if ((((DisplayTextParams) cmdParams).textMsg.text != null)
            && (((DisplayTextParams) cmdParams).textMsg.text.equals(STK_DEFAULT))) {
          message = mContext.getText(com.android.internal.R.string.sending);
          ((DisplayTextParams) cmdParams).textMsg.text = message.toString();
        }
        break;
      case PLAY_TONE:
        break;
      case SET_UP_CALL:
        if ((((CallSetupParams) cmdParams).confirmMsg.text != null)
            && (((CallSetupParams) cmdParams).confirmMsg.text.equals(STK_DEFAULT))) {
          message = mContext.getText(com.android.internal.R.string.SetupCallDefault);
          ((CallSetupParams) cmdParams).confirmMsg.text = message.toString();
        }
        break;
      case OPEN_CHANNEL:
      case CLOSE_CHANNEL:
      case RECEIVE_DATA:
      case SEND_DATA:
        BIPClientParams cmd = (BIPClientParams) cmdParams;
        /*
         * If the text mesg is null, need to send the response
         * back to the card in the following scenarios
         * - It has alpha ID tag with no Text Msg (or)
         * - If alphaUsrCnf is not set. In the above cases
         *   there should be no UI indication given to the user.
         */
        boolean alphaUsrCnf =
            SystemProperties.getBoolean(TelephonyProperties.PROPERTY_ALPHA_USRCNF, false);
        CatLog.d(this, "alphaUsrCnf: " + alphaUsrCnf + ", bHasAlphaId: " + cmd.bHasAlphaId);

        if ((cmd.textMsg.text == null) && (cmd.bHasAlphaId || !alphaUsrCnf)) {
          CatLog.d(this, "cmd " + cmdParams.getCommandType() + " with null alpha id");
          // If alpha length is zero, we just respond with OK.
          if (isProactiveCmd) {
            sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, null);
          } else if (cmdParams.getCommandType() == CommandType.OPEN_CHANNEL) {
            mCmdIf.handleCallSetupRequestFromSim(true, null);
          }
          return;
        }
        // Respond with permanent failure to avoid retry if STK app is not present.
        if (!mStkAppInstalled) {
          CatLog.d(this, "No STK application found.");
          if (isProactiveCmd) {
            sendTerminalResponse(
                cmdParams.cmdDet, ResultCode.BEYOND_TERMINAL_CAPABILITY, false, 0, null);
            return;
          }
        }
        /*
         * CLOSE_CHANNEL, RECEIVE_DATA and SEND_DATA can be delivered by
         * either PROACTIVE_COMMAND or EVENT_NOTIFY.
         * If PROACTIVE_COMMAND is used for those commands, send terminal
         * response here.
         */
        if (isProactiveCmd
            && ((cmdParams.getCommandType() == CommandType.CLOSE_CHANNEL)
                || (cmdParams.getCommandType() == CommandType.RECEIVE_DATA)
                || (cmdParams.getCommandType() == CommandType.SEND_DATA))) {
          sendTerminalResponse(cmdParams.cmdDet, ResultCode.OK, false, 0, null);
        }
        break;
      default:
        CatLog.d(this, "Unsupported command");
        return;
    }
    mCurrntCmd = cmdMsg;
    Intent intent = new Intent(AppInterface.CAT_CMD_ACTION);
    intent.putExtra("STK CMD", cmdMsg);
    mContext.sendBroadcast(intent);
  }