Search in sources :

Example 1 with CommandException

use of com.android.internal.telephony.CommandException in project XobotOS by xamarin.

the class SimulatedCommands method supplyIccPin2.

public void supplyIccPin2(String pin2, Message result) {
    if (mSimFdnEnabledState != SimFdnState.REQUIRE_PIN2) {
        Log.i(LOG_TAG, "[SimCmd] supplyIccPin2: wrong state, state=" + mSimFdnEnabledState);
        CommandException ex = new CommandException(CommandException.Error.PASSWORD_INCORRECT);
        AsyncResult.forMessage(result, null, ex);
        result.sendToTarget();
        return;
    }
    if (pin2 != null && pin2.equals(mPin2Code)) {
        Log.i(LOG_TAG, "[SimCmd] supplyIccPin2: success!");
        mPin2UnlockAttempts = 0;
        mSimFdnEnabledState = SimFdnState.NONE;
        if (result != null) {
            AsyncResult.forMessage(result, null, null);
            result.sendToTarget();
        }
        return;
    }
    if (result != null) {
        mPin2UnlockAttempts++;
        Log.i(LOG_TAG, "[SimCmd] supplyIccPin2: failed! attempt=" + mPin2UnlockAttempts);
        if (mPin2UnlockAttempts >= 3) {
            Log.i(LOG_TAG, "[SimCmd] supplyIccPin2: set state to REQUIRE_PUK2");
            mSimFdnEnabledState = SimFdnState.REQUIRE_PUK2;
        }
        CommandException ex = new CommandException(CommandException.Error.PASSWORD_INCORRECT);
        AsyncResult.forMessage(result, null, ex);
        result.sendToTarget();
    }
}
Also used : CommandException(com.android.internal.telephony.CommandException)

Example 2 with CommandException

use of com.android.internal.telephony.CommandException in project XobotOS by xamarin.

the class SimulatedCommands method supplyIccPuk.

public void supplyIccPuk(String puk, String newPin, Message result) {
    if (mSimLockedState != SimLockState.REQUIRE_PUK) {
        Log.i(LOG_TAG, "[SimCmd] supplyIccPuk: wrong state, state=" + mSimLockedState);
        CommandException ex = new CommandException(CommandException.Error.PASSWORD_INCORRECT);
        AsyncResult.forMessage(result, null, ex);
        result.sendToTarget();
        return;
    }
    if (puk != null && puk.equals(SIM_PUK_CODE)) {
        Log.i(LOG_TAG, "[SimCmd] supplyIccPuk: success!");
        setRadioState(RadioState.SIM_READY);
        mSimLockedState = SimLockState.NONE;
        mPukUnlockAttempts = 0;
        if (result != null) {
            AsyncResult.forMessage(result, null, null);
            result.sendToTarget();
        }
        return;
    }
    if (result != null) {
        mPukUnlockAttempts++;
        Log.i(LOG_TAG, "[SimCmd] supplyIccPuk: failed! attempt=" + mPukUnlockAttempts);
        if (mPukUnlockAttempts >= 10) {
            Log.i(LOG_TAG, "[SimCmd] supplyIccPuk: set state to SIM_PERM_LOCKED");
            mSimLockedState = SimLockState.SIM_PERM_LOCKED;
        }
        CommandException ex = new CommandException(CommandException.Error.PASSWORD_INCORRECT);
        AsyncResult.forMessage(result, null, ex);
        result.sendToTarget();
    }
}
Also used : CommandException(com.android.internal.telephony.CommandException)

Example 3 with CommandException

use of com.android.internal.telephony.CommandException in project XobotOS by xamarin.

the class SimulatedCommands method supplyIccPuk2.

public void supplyIccPuk2(String puk2, String newPin2, Message result) {
    if (mSimFdnEnabledState != SimFdnState.REQUIRE_PUK2) {
        Log.i(LOG_TAG, "[SimCmd] supplyIccPuk2: wrong state, state=" + mSimLockedState);
        CommandException ex = new CommandException(CommandException.Error.PASSWORD_INCORRECT);
        AsyncResult.forMessage(result, null, ex);
        result.sendToTarget();
        return;
    }
    if (puk2 != null && puk2.equals(SIM_PUK2_CODE)) {
        Log.i(LOG_TAG, "[SimCmd] supplyIccPuk2: success!");
        mSimFdnEnabledState = SimFdnState.NONE;
        mPuk2UnlockAttempts = 0;
        if (result != null) {
            AsyncResult.forMessage(result, null, null);
            result.sendToTarget();
        }
        return;
    }
    if (result != null) {
        mPuk2UnlockAttempts++;
        Log.i(LOG_TAG, "[SimCmd] supplyIccPuk2: failed! attempt=" + mPuk2UnlockAttempts);
        if (mPuk2UnlockAttempts >= 10) {
            Log.i(LOG_TAG, "[SimCmd] supplyIccPuk2: set state to SIM_PERM_LOCKED");
            mSimFdnEnabledState = SimFdnState.SIM_PERM_LOCKED;
        }
        CommandException ex = new CommandException(CommandException.Error.PASSWORD_INCORRECT);
        AsyncResult.forMessage(result, null, ex);
        result.sendToTarget();
    }
}
Also used : CommandException(com.android.internal.telephony.CommandException)

Example 4 with CommandException

use of com.android.internal.telephony.CommandException in project android_frameworks_opt_telephony by LineageOS.

the class ImsPhoneMmiCode method onSetComplete.

private void onSetComplete(Message msg, AsyncResult ar) {
    StringBuilder sb = new StringBuilder(getScString());
    sb.append("\n");
    if (ar.exception != null) {
        mState = State.FAILED;
        if (ar.exception instanceof CommandException) {
            CommandException err = (CommandException) ar.exception;
            if (err.getCommandError() == CommandException.Error.PASSWORD_INCORRECT) {
                sb.append(mContext.getText(com.android.internal.R.string.passwordIncorrect));
            } else if (err.getMessage() != null) {
                sb.append(err.getMessage());
            } else {
                sb.append(mContext.getText(com.android.internal.R.string.mmiError));
            }
        } else {
            ImsException error = (ImsException) ar.exception;
            if (error.getMessage() != null) {
                sb.append(error.getMessage());
            } else {
                sb.append(getErrorMessage(ar));
            }
        }
    } else if (isActivate()) {
        mState = State.COMPLETE;
        if (mIsCallFwdReg) {
            sb.append(mContext.getText(com.android.internal.R.string.serviceRegistered));
        } else {
            sb.append(mContext.getText(com.android.internal.R.string.serviceEnabled));
        }
    } else if (isDeactivate()) {
        mState = State.COMPLETE;
        sb.append(mContext.getText(com.android.internal.R.string.serviceDisabled));
    } else if (isRegister()) {
        mState = State.COMPLETE;
        sb.append(mContext.getText(com.android.internal.R.string.serviceRegistered));
    } else if (isErasure()) {
        mState = State.COMPLETE;
        sb.append(mContext.getText(com.android.internal.R.string.serviceErased));
    } else {
        mState = State.FAILED;
        sb.append(mContext.getText(com.android.internal.R.string.mmiError));
    }
    mMessage = sb;
    Rlog.d(LOG_TAG, "onSetComplete: mmi=" + this);
    mPhone.onMMIDone(this);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ImsException(com.android.ims.ImsException) CommandException(com.android.internal.telephony.CommandException)

Example 5 with CommandException

use of com.android.internal.telephony.CommandException in project android_frameworks_opt_telephony by LineageOS.

the class UiccCarrierPrivilegeRules method handleMessage.

@Override
public void handleMessage(Message msg) {
    AsyncResult ar;
    switch(msg.what) {
        case EVENT_OPEN_LOGICAL_CHANNEL_DONE:
            log("EVENT_OPEN_LOGICAL_CHANNEL_DONE");
            ar = (AsyncResult) msg.obj;
            if (ar.exception == null && ar.result != null) {
                mChannelId = ((int[]) ar.result)[0];
                mUiccCard.iccTransmitApduLogicalChannel(mChannelId, CLA, COMMAND, P1, P2, P3, DATA, obtainMessage(EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE, mChannelId));
            } else {
                // so we retry up to MAX_RETRY times, with an interval of RETRY_INTERVAL_MS.
                if (ar.exception instanceof CommandException && mRetryCount < MAX_RETRY && ((CommandException) (ar.exception)).getCommandError() == CommandException.Error.MISSING_RESOURCE) {
                    mRetryCount++;
                    removeCallbacks(mRetryRunnable);
                    postDelayed(mRetryRunnable, RETRY_INTERVAL_MS);
                } else {
                    // if rules cannot be read from ARA applet,
                    // fallback to PKCS15-based ARF.
                    log("No ARA, try ARF next.");
                    mUiccPkcs15 = new UiccPkcs15(mUiccCard, obtainMessage(EVENT_PKCS15_READ_DONE));
                }
            }
            break;
        case EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE:
            log("EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE");
            ar = (AsyncResult) msg.obj;
            if (ar.exception == null && ar.result != null) {
                IccIoResult response = (IccIoResult) ar.result;
                if (response.sw1 == 0x90 && response.sw2 == 0x00 && response.payload != null && response.payload.length > 0) {
                    try {
                        mRules += IccUtils.bytesToHexString(response.payload).toUpperCase(Locale.US);
                        if (isDataComplete()) {
                            mAccessRules = parseRules(mRules);
                            updateState(STATE_LOADED, "Success!");
                        } else {
                            mUiccCard.iccTransmitApduLogicalChannel(mChannelId, CLA, COMMAND, P1, P2_EXTENDED_DATA, P3, DATA, obtainMessage(EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE, mChannelId));
                            break;
                        }
                    } catch (IllegalArgumentException | IndexOutOfBoundsException ex) {
                        updateState(STATE_ERROR, "Error parsing rules: " + ex);
                    }
                } else {
                    String errorMsg = "Invalid response: payload=" + response.payload + " sw1=" + response.sw1 + " sw2=" + response.sw2;
                    updateState(STATE_ERROR, errorMsg);
                }
            } else {
                updateState(STATE_ERROR, "Error reading value from SIM.");
            }
            mUiccCard.iccCloseLogicalChannel(mChannelId, obtainMessage(EVENT_CLOSE_LOGICAL_CHANNEL_DONE));
            mChannelId = -1;
            break;
        case EVENT_CLOSE_LOGICAL_CHANNEL_DONE:
            log("EVENT_CLOSE_LOGICAL_CHANNEL_DONE");
            break;
        case EVENT_PKCS15_READ_DONE:
            log("EVENT_PKCS15_READ_DONE");
            if (mUiccPkcs15 == null || mUiccPkcs15.getRules() == null) {
                updateState(STATE_ERROR, "No ARA or ARF.");
            } else {
                for (String cert : mUiccPkcs15.getRules()) {
                    UiccAccessRule accessRule = new UiccAccessRule(IccUtils.hexStringToBytes(cert), "", 0x00);
                    mAccessRules.add(accessRule);
                }
                updateState(STATE_LOADED, "Success!");
            }
            break;
        default:
            Rlog.e(LOG_TAG, "Unknown event " + msg.what);
    }
}
Also used : UiccAccessRule(android.telephony.UiccAccessRule) CommandException(com.android.internal.telephony.CommandException) AsyncResult(android.os.AsyncResult)

Aggregations

CommandException (com.android.internal.telephony.CommandException)23 AsyncResult (android.os.AsyncResult)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 ImsException (com.android.ims.ImsException)2 UiccAccessRule (android.telephony.UiccAccessRule)1