Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea7527ec authored by Wink Saville's avatar Wink Saville
Browse files

Additional logging information for Card Application Toolkit/SIM Toolkit

Add an optional explanation field and toString to ResultException
Add toString to CommandDetails.
Add add a few more log statements on error paths.

Bug: 5852715
Change-Id: I8594178002a67798aa3fb38ce1ee15c1a41f1854
parent 7524a592
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -81,12 +81,18 @@ class BerTlv {
                    temp = data[curIndex++] & 0xff;
                    if (temp < 0x80) {
                        throw new ResultException(
                                ResultCode.CMD_DATA_NOT_UNDERSTOOD);
                                ResultCode.CMD_DATA_NOT_UNDERSTOOD,
                                "length < 0x80 length=" + Integer.toHexString(length) +
                                " curIndex=" + curIndex + " endIndex=" + endIndex);

                    }
                    length = temp;
                } else {
                    throw new ResultException(
                            ResultCode.CMD_DATA_NOT_UNDERSTOOD);
                            ResultCode.CMD_DATA_NOT_UNDERSTOOD,
                            "Expected first byte to be length or a length tag and < 0x81" +
                            " byte= " + Integer.toHexString(temp) + " curIndex=" + curIndex +
                            " endIndex=" + endIndex);
                }
            } else {
                if (ComprehensionTlvTag.COMMAND_DETAILS.value() == (tag & ~0x80)) {
@@ -95,14 +101,18 @@ class BerTlv {
                }
            }
        } catch (IndexOutOfBoundsException e) {
            throw new ResultException(ResultCode.REQUIRED_VALUES_MISSING);
            throw new ResultException(ResultCode.REQUIRED_VALUES_MISSING,
                    "IndexOutOfBoundsException " +
                    " curIndex=" + curIndex + " endIndex=" + endIndex);
        } catch (ResultException e) {
            throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
            throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD, e.explanation());
        }

        /* COMPREHENSION-TLVs */
        if (endIndex - curIndex < length) {
            throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
            throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD,
                    "Command had extra data endIndex=" + endIndex + " curIndex=" + curIndex +
                    " length=" + length);
        }

        List<ComprehensionTlv> ctlvs = ComprehensionTlv.decodeMany(data,
+8 −0
Original line number Diff line number Diff line
@@ -74,6 +74,14 @@ class CommandDetails extends ValueObject implements Parcelable {
    public int describeContents() {
        return 0;
    }

    @Override
    public String toString() {
        return "CmdDetails: compRequired=" + compRequired +
                " commandNumber=" + commandNumber +
                " typeOfCommand=" + typeOfCommand +
                " commandQualifier=" + commandQualifier;
    }
}

class DeviceIdentities extends ValueObject {
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,11 @@ class CommandParams {
    }

    boolean setIcon(Bitmap icon) { return true; }

    @Override
    public String toString() {
        return cmdDet.toString();
    }
}

class DisplayTextParams extends CommandParams {
+3 −1
Original line number Diff line number Diff line
@@ -83,7 +83,8 @@ class CommandParamsFactory extends Handler {
                try {
                    cmdDet = ValueParser.retrieveCommandDetails(ctlvCmdDet);
                } catch (ResultException e) {
                    CatLog.d(this, "Failed to procees command details");
                    CatLog.d(this,
                            "processCommandDetails: Failed to procees command details e=" + e);
                }
            }
        }
@@ -178,6 +179,7 @@ class CommandParamsFactory extends Handler {
                return;
            }
        } catch (ResultException e) {
            CatLog.d(this, "make: caught ResultException e=" + e);
            mCmdParams = new CommandParams(cmdDet);
            sendCmdParams(e.result());
            return;
+30 −11
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony.cat;

import android.util.Log;

import java.util.ArrayList;
import java.util.List;

@@ -112,10 +114,10 @@ class ComprehensionTlv {
     */
    public static ComprehensionTlv decode(byte[] data, int startIndex)
            throws ResultException {
        try {
        int curIndex = startIndex;
        int endIndex = data.length;

        try {
            /* tag */
            int tag;
            boolean cr; // Comprehension required flag
@@ -124,9 +126,11 @@ class ComprehensionTlv {
            case 0:
            case 0xff:
            case 0x80:
                // for error handling
                // these one make exception while decoding the abnormal command.
                // (in case of Ghana MTN simcard , JDI simcard)
                Log.d("CAT     ", "decode: unexpected first tag byte=" + Integer.toHexString(temp) +
                        ", startIndex=" + startIndex + " curIndex=" + curIndex +
                        " endIndex=" + endIndex);
                // Return null which will stop decoding, this has occurred
                // with Ghana MTN simcard and JDI simcard.
                return null;

            case 0x7f: // tag is in three-byte format
@@ -153,7 +157,10 @@ class ComprehensionTlv {
                length = data[curIndex++] & 0xff;
                if (length < 0x80) {
                    throw new ResultException(
                            ResultCode.CMD_DATA_NOT_UNDERSTOOD);
                            ResultCode.CMD_DATA_NOT_UNDERSTOOD,
                            "length < 0x80 length=" + Integer.toHexString(length) +
                            " startIndex=" + startIndex + " curIndex=" + curIndex +
                            " endIndex=" + endIndex);
                }
            } else if (temp == 0x82) {
                length = ((data[curIndex] & 0xff) << 8)
@@ -161,7 +168,10 @@ class ComprehensionTlv {
                curIndex += 2;
                if (length < 0x100) {
                    throw new ResultException(
                            ResultCode.CMD_DATA_NOT_UNDERSTOOD);
                            ResultCode.CMD_DATA_NOT_UNDERSTOOD,
                            "two byte length < 0x100 length=" + Integer.toHexString(length) +
                            " startIndex=" + startIndex + " curIndex=" + curIndex +
                            " endIndex=" + endIndex);
                }
            } else if (temp == 0x83) {
                length = ((data[curIndex] & 0xff) << 16)
@@ -170,16 +180,25 @@ class ComprehensionTlv {
                curIndex += 3;
                if (length < 0x10000) {
                    throw new ResultException(
                            ResultCode.CMD_DATA_NOT_UNDERSTOOD);
                            ResultCode.CMD_DATA_NOT_UNDERSTOOD,
                            "three byte length < 0x10000 length=0x" + Integer.toHexString(length) +
                            " startIndex=" + startIndex + " curIndex=" + curIndex +
                            " endIndex=" + endIndex);
                }
            } else {
                throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
                throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD,
                        "Bad length modifer=" + temp +
                        " startIndex=" + startIndex + " curIndex=" + curIndex +
                        " endIndex=" + endIndex);

            }

            return new ComprehensionTlv(tag, cr, length, data, curIndex);

        } catch (IndexOutOfBoundsException e) {
            throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
            throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD,
                    "IndexOutOfBoundsException" + " startIndex=" + startIndex +
                    " curIndex=" + curIndex + " endIndex=" + endIndex);
        }
    }
}
Loading