FileDocCategorySizeDatePackage
RilMessageDecoder.javaAPI DocAndroid 5.1 API7067Thu Mar 12 22:22:54 GMT 2015com.android.internal.telephony.cat

RilMessageDecoder

public class RilMessageDecoder extends com.android.internal.util.StateMachine
Class used for queuing raw ril messages, decoding them into CommanParams objects and sending the result back to the CAT Service.

Fields Summary
private static final int
CMD_START
private static final int
CMD_PARAMS_READY
private CommandParamsFactory
mCmdParamsFactory
private RilMessage
mCurrentRilMessage
private android.os.Handler
mCaller
private static int
mSimCount
private static RilMessageDecoder[]
mInstance
private StateStart
mStateStart
private StateCmdParamsReady
mStateCmdParamsReady
Constructors Summary
private RilMessageDecoder(android.os.Handler caller, com.android.internal.telephony.uicc.IccFileHandler fh)

        super("RilMessageDecoder");

        addState(mStateStart);
        addState(mStateCmdParamsReady);
        setInitialState(mStateStart);

        mCaller = caller;
        mCmdParamsFactory = CommandParamsFactory.getInstance(this, fh);
    
private RilMessageDecoder()

        super("RilMessageDecoder");
    
Methods Summary
private booleandecodeMessageParams(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;
    
public voiddispose()

        mStateStart = null;
        mStateCmdParamsReady = null;
        mCmdParamsFactory.dispose();
        mCmdParamsFactory = null;
        mCurrentRilMessage = null;
        mCaller = null;
        mInstance = null;
    
public static synchronized com.android.internal.telephony.cat.RilMessageDecodergetInstance(android.os.Handler caller, com.android.internal.telephony.uicc.IccFileHandler fh, int slotId)
Get the singleton instance, constructing if necessary.

param
caller
param
fh
return
RilMesssageDecoder


                      
           
              
        if (null == mInstance) {
            mSimCount = TelephonyManager.getDefault().getSimCount();
            mInstance = new RilMessageDecoder[mSimCount];
            for (int i = 0; i < mSimCount; i++) {
                mInstance[i] = null;
            }
        }

        if (slotId != SubscriptionManager.INVALID_SIM_SLOT_INDEX && slotId < mSimCount) {
            if (null == mInstance[slotId]) {
                mInstance[slotId] = new RilMessageDecoder(caller, fh);
            }
        } else {
            CatLog.d("RilMessageDecoder", "invaild slot id: " + slotId);
            return null;
        }

        return mInstance[slotId];
    
private voidsendCmdForExecution(RilMessage rilMsg)

        Message msg = mCaller.obtainMessage(CatService.MSG_ID_RIL_MSG_DECODED,
                new RilMessage(rilMsg));
        msg.sendToTarget();
    
public voidsendMsgParamsDecoded(ResultCode resCode, CommandParams cmdParams)
The command parameters have been decoded.

param
resCode
param
cmdParams

        Message msg = obtainMessage(RilMessageDecoder.CMD_PARAMS_READY);
        msg.arg1 = resCode.value();
        msg.obj = cmdParams;
        sendMessage(msg);
    
public voidsendStartDecodingMessageParams(RilMessage rilMsg)
Start decoding the message parameters, when complete MSG_ID_RIL_MSG_DECODED will be returned to caller.

param
rilMsg

        Message msg = obtainMessage(CMD_START);
        msg.obj = rilMsg;
        sendMessage(msg);