private void onUpdateIccAvailability() {
    if (mUiccController == null) {
      return;
    }

    UiccCardApplication newUiccApplication = getUiccCardApplication();

    UiccCardApplication app = mUiccApplication.get();
    if (app != newUiccApplication) {
      if (app != null) {
        Rlog.d(TAG, "Removing stale icc objects.");
        if (mIccRecords.get() != null) {
          mIccRecords.get().unregisterForNewSms(this);
        }
        mIccRecords.set(null);
        mUiccApplication.set(null);
      }
      if (newUiccApplication != null) {
        Rlog.d(TAG, "New Uicc application found");
        mUiccApplication.set(newUiccApplication);
        mIccRecords.set(newUiccApplication.getIccRecords());
        if (mIccRecords.get() != null) {
          mIccRecords.get().registerForNewSms(this, EVENT_NEW_ICC_SMS, null);
        }
      }
    }
  }
  @Override
  protected void onUpdateIccAvailability() {
    if (mUiccController == null) {
      return;
    }

    // Update IsimRecords
    UiccCardApplication newUiccApplication =
        mUiccController.getUiccCardApplication(UiccController.APP_FAM_IMS);
    IsimUiccRecords newIsimUiccRecords = null;

    if (newUiccApplication != null) {
      newIsimUiccRecords = (IsimUiccRecords) newUiccApplication.getIccRecords();
    }
    mIsimUiccRecords = newIsimUiccRecords;

    // Update UsimRecords
    newUiccApplication = mUiccController.getUiccCardApplication(UiccController.APP_FAM_3GPP);
    SIMRecords newSimRecords = null;
    if (newUiccApplication != null) {
      newSimRecords = (SIMRecords) newUiccApplication.getIccRecords();
    }
    if (mSimRecords != newSimRecords) {
      if (mSimRecords != null) {
        log("Removing stale SIMRecords object.");
        mSimRecords = null;
      }
      if (newSimRecords != null) {
        log("New SIMRecords found");
        mSimRecords = newSimRecords;
      }
    }

    super.onUpdateIccAvailability();
  }
Beispiel #3
0
  /** Process a MMI PUK code */
  void processCode() {
    try {
      if (isPinPukCommand()) {
        // TODO: This is the same as the code in GsmMmiCode.java,
        // MmiCode should be an abstract or base class and this and
        // other common variables and code should be promoted.

        // sia = old PIN or PUK
        // sib = new PIN
        // sic = new PIN
        String oldPinOrPuk = mSia;
        String newPinOrPuk = mSib;
        int pinLen = newPinOrPuk.length();
        if (isRegister()) {
          if (!newPinOrPuk.equals(mSic)) {
            // password mismatch; return error
            handlePasswordError(com.android.internal.R.string.mismatchPin);
          } else if (pinLen < 4 || pinLen > 8) {
            // invalid length
            handlePasswordError(com.android.internal.R.string.invalidPin);
          } else if (mSc.equals(SC_PIN)
              && mUiccApplication != null
              && mUiccApplication.getState() == AppState.APPSTATE_PUK) {
            // Sim is puk-locked
            handlePasswordError(com.android.internal.R.string.needPuk);
          } else if (mUiccApplication != null) {
            Rlog.d(LOG_TAG, "process mmi service code using UiccApp sc=" + mSc);

            // We have an app and the pre-checks are OK
            if (mSc.equals(SC_PIN)) {
              mUiccApplication.changeIccLockPassword(
                  oldPinOrPuk, newPinOrPuk, obtainMessage(EVENT_SET_COMPLETE, this));
            } else if (mSc.equals(SC_PIN2)) {
              mUiccApplication.changeIccFdnPassword(
                  oldPinOrPuk, newPinOrPuk, obtainMessage(EVENT_SET_COMPLETE, this));
            } else if (mSc.equals(SC_PUK)) {
              mUiccApplication.supplyPuk(
                  oldPinOrPuk, newPinOrPuk, obtainMessage(EVENT_SET_COMPLETE, this));
            } else if (mSc.equals(SC_PUK2)) {
              mUiccApplication.supplyPuk2(
                  oldPinOrPuk, newPinOrPuk, obtainMessage(EVENT_SET_COMPLETE, this));
            } else {
              throw new RuntimeException("Unsupported service code=" + mSc);
            }
          } else {
            throw new RuntimeException("No application mUiccApplicaiton is null");
          }
        } else {
          throw new RuntimeException("Ivalid register/action=" + mAction);
        }
      }
    } catch (RuntimeException exc) {
      mState = State.FAILED;
      mMessage = mContext.getText(com.android.internal.R.string.mmiError);
      mPhone.onMMIDone(this);
    }
  }
  /* 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);
  }
  /**
   * Return true if time zone needs fixing.
   *
   * @param phoneBase
   * @param operatorNumeric
   * @param prevOperatorNumeric
   * @param needToFixTimeZone
   * @return true if time zone needs to be fixed
   */
  protected boolean shouldFixTimeZoneNow(
      PhoneBase phoneBase,
      String operatorNumeric,
      String prevOperatorNumeric,
      boolean needToFixTimeZone) {
    // Return false if the mcc isn't valid as we don't know where we are.
    // Return true if we have an IccCard and the mcc changed or we
    // need to fix it because when the NITZ time came in we didn't
    // know the country code.

    // If mcc is invalid then we'll return false
    int mcc;
    try {
      mcc = Integer.parseInt(operatorNumeric.substring(0, 3));
    } catch (Exception e) {
      if (DBG) {
        log("shouldFixTimeZoneNow: no mcc, operatorNumeric=" + operatorNumeric + " retVal=false");
      }
      return false;
    }

    // If prevMcc is invalid will make it different from mcc
    // so we'll return true if the card exists.
    int prevMcc;
    try {
      prevMcc = Integer.parseInt(prevOperatorNumeric.substring(0, 3));
    } catch (Exception e) {
      prevMcc = mcc + 1;
    }

    // Determine if the Icc card exists
    boolean iccCardExist = false;
    if (mUiccApplcation != null) {
      iccCardExist = mUiccApplcation.getState() != AppState.APPSTATE_UNKNOWN;
    }

    // Determine retVal
    boolean retVal = ((iccCardExist && (mcc != prevMcc)) || needToFixTimeZone);
    if (DBG) {
      long ctm = System.currentTimeMillis();
      log(
          "shouldFixTimeZoneNow: retVal="
              + retVal
              + " iccCardExist="
              + iccCardExist
              + " operatorNumeric="
              + operatorNumeric
              + " mcc="
              + mcc
              + " prevOperatorNumeric="
              + prevOperatorNumeric
              + " prevMcc="
              + prevMcc
              + " needToFixTimeZone="
              + needToFixTimeZone
              + " ltod="
              + TimeUtils.logTimeOfDay(ctm));
    }
    return retVal;
  }
  /**
   * 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;
    }
  }