The Catservice of UICC

Source: Internet
Author: User
Tags constructor
Catservice is primarily responsible for the Stk menu, and we'll analyze the object in this section.


first, the creation process of Catservice


As we analyzed in the second section above, the Catservice object is initialized during the Uicccard update process:[Java] View plain copy @UiccCard .java   public void update (context c, commandsinterface  ci, icccardstatus ics)  {       synchronized  (MLock)  {           if  (muiccapplications.length >  0 && muiccapplications[0] != null)  {                //Creating catservice                mcatservice = catservice.getinstance (MCi, mContext,  this);           } else {                if  (Mcatservice != null)  {                    mcatservice.disPose ();               }                mCatService = null;           }       }  }            then look at the specific initialization process: [Java] View plain copy @CatService .java   public static catservice getinstance (commandsinterface  ci, context context, uicccard ic)  {        uicccardapplication ca = null;       iccfilehandler fh =  null;       IccRecords ir = null;        if  (ic != null)  {           / /Get objects such as Uicccardapplication, Iccfilehandler, Iccrecords             ca = ic.getapplicationindex (0);           if   (ca != null)  {                fh = ca.geticcfilehandler ();              &nbsP; ir = ca.geticcrecords ();           }        }       synchronized  (sinstancelock)  {            if  (sinstance == null)  {                if  (ci == null  | |  ca == null | |  ir == null | |  context == null | |  fh == null | |  ic == null)  {                    return null;                }                //creating Catservice Message processing Threads                handlerthread thread = new handlerthread ("Cat Telephony  Service ");               thread.start ();                //Creating Catservice instance objects                 sInstance = new  Catservice (ci, ca, ir, context, fh, ic);            } else if  (ir != null)  &&  (miccrecords !=  ir))  {               // Catservice has been created, just need to update its listener                 if  (miccrecords != null)  {                     miccrecords.unregisterforrecordsloaded (sinstance);                }                if  (muiccapplication != null)  {                     Muiccapplication.unregisterforready (sinstance);                }                miccrecords = ir;                mUiccApplication = ca;                miccrecords.registerforrecordsloaded (sinstance, msg_id_icc_records_loaded, null);           &Nbsp;    muiccapplication.registerforready (Sinstance, msg_id_sim_ready, null);            } else {                CATLOG.D (sinstance,  "Return current  Sinstance ");           }            return sInstance;       }  }           Look at his constructor: [Java] View Plain copy 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 Rilmessagedecoder Objects        mmsgdecoder = rilmessagedecoder.getinstance (THIS, FH);      //to RIL Register listener        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);          mIccRecords = ir;       mUiccApplication = ca;       // Register Sim ready Listener        //with the Uicccardapplication object to register the Iccrecords object Icc record  loaded's listeners        muiccapplication.registerforready (this, msg_id_sim_ Ready, null);       miccrecords.registerforrecordsloaded (this, MSG_ID_ Icc_records_loaded, nulL);          mstkappinstalled = isstkappinstalled ();   }           We've seen a major three tasks in the Catservice initialization process:
1, obtain Rilmessagedecoder object Mmsgdecoder;
2, to the RIL registration related notification monitoring;

3, to Uicccardapplication, Iccrecords registered SIM card and record monitoring;


Second, the message mechanism of Catservice


In the Catservice constructor above we see that Catservice registered six main listeners:
1, Msg_id_session_end
2, Msg_id_proactive_command
3, msg_id_ril_msg_decoded
4, Msg_id_event_notify
5, Msg_id_call_setup
6, Msg_id_sim_ready
7, msg_id_icc_records_loaded

Of these six message events, four are more important, according to the order received is:
Msg_id_sim_ready----Inform Catservice,sim card is ready, need catservice feedback is ready
Msg_id_proactive_command----Catservice Get the STK information from the SIM card
msg_id_ril_msg_decodedSend notification to catservice----Rilmessagedecoder after parsing STK data
Msg_id_session_end----RIL upload the current message has been transferred.

Below we mainly introduce the above four message processing flow.


2.1, Msg_id_sim_ready


This is the first message received by Catservice, which indicates that the SIM card is already in the ready state, and Catservice reports to the RIL that Catservice is already running and preparing to accept the message. Here's a detailed procedure:[Java] View Plain copy public void handlemessage (message msg)  {        switch  (msg.what)  {           case msg_id_sim_ ready:               //Send message to Ril                 mcmdif.reportstkserviceisrunning (null);               break;           default:                throw new assertionerror ("unrecognized cat command: "  + msg.what);       }  }  

At this point the RIL will send ril_request_report_stk_service_is_running message to the modem, which tells Modem,catservice is ready to accept STK data.


2.2, Msg_id_proactive_command


When the modem receives a message that the Catservice has started, it will escalate the Msg_id_proactive_command message, which contains the STK information stored in the SIM card.Catservice need to parse and save this information to build the Stk menu
Please note thatIf the SIM card does not support STK business, the message will not be received[Java] View Plain copy public void handlemessage (message msg)  {        switch  (msg.what)  {           case msg_id_ session_end:           case msg_id_proactive_command:            case MSG_ID_EVENT_NOTIFY:            case MSG_ID_REFRESH:                String data = null;                if  (msg.obj != null)  {                   asyncresult  ar =  (AsyncResult)  msg.obj;                    if  (Ar != null && ar.result != null)  {                        try {                            data =  ( String)  ar.result;                        } catch  (classcastexception e)  {                             break;                        }                    }                }               / /through Rilmessagedecoder to parse data                 Mmsgdecoder.sendstartdecodingmessageparams (New rilmessage (msg.what, data));                break;            default:                Throw new assertionerror ("unrecognized cat command: "  + msg.what);        }  }           We see that the data we get is parsed by Mmsgdecoder. , which is the object of Rilmessagedecoder, which is created in the Catservice constructor. Let's look at the specific process of parsing the data:[Java]View plain copy @RilMessageDecoder. Java public void Sendstartdecodingmessageparams (Rilmessage rilmsg) {Message ms       g = Obtainmessage (Cmd_start);       Msg.obj = rilmsg;   SendMessage (msg); The message is then encapsulated in Rilmessagedecoder and sent to itself and processed in Statestart:[Java] View Plain Copy private class statestart extends state {         @Override        public boolean processmessage (message msg)  {           if  (Msg.what == cmd_start)  {               if  ( Decodemessageparams ((rilmessage) msg.obj)  {                    transitionto (mstatecmdparamsready);                }            } else {                CATLOG.D (this,  "statestart unexpected expecting start="  + CMD_START +   " got " + msg.what);           }            return true;       }  }            is then parsed in the Decodemessageparams () method: [Java] View Plain copy private boolean decodemessageparams (rilmessage rilmsg)  {        boolean decodingStarted;       mcurrentrilmessage =  rilMsg;       switch (rilmsg.mid)  {            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)  {               }          &n

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.