Android Ril Dial

请求流程:

RIL.java中调用 dial()

public void 
dial (String address, int clirMode, Message result) {
        RILRequest rr = RILRequest.obtain(RIL_REQUEST_DIAL, result);
        rr.mp.writeString(address);
        rr.mp.writeInt(clirMode);
        rr.mp.writeInt(0); // UUS information is absent
        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
        send(rr);
    }
private void
    send(RILRequest rr) {
        Message msg;
        msg = mSender.obtainMessage(EVENT_SEND, rr);
        acquireWakeLock();
        msg.sendToTarget();
    }

在handleMessage()中处理发送事件,然后通过

s.getOutputStream().write(dataLength);
s.getOutputStream().write(data);
发送到libril.so,

libril.so在收到socket传过来的消息后,调用ril.cpp中的listenCallback()函数,

 

s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);

 

接收上层的socket请求,并建立起一个record_stream,

p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);

ril_event_set (&s_commands_event, s_fdCommand, 1,processCommandsCallback, p_rs);

调用processCommandsCallback函数去处理请求,processCommandsCallback()函数通过
一个循环,

for (;;) {
  ret = record_stream_get_next(p_rs, &p_record, &recordlen);
        if (ret == 0 && p_record == NULL) {
           
            break;
        } else if (ret < 0) {
            break;
        } else if (ret == 0) {
            processCommandBuffer(p_record, recordlen);
        }
    }

这个循环中是读取完整的数据。
把请求发送到了processCommandBuffer函数中,把请求封装成RequestInfo结构,

    pRI->pCI->dispatchFunction(p, pRI);

通过PCI去读取对应的dispatchFunction,在ril_commands.h中有定义,何以根据事件请求号码去查找,标准的一个请求号码和dispatchFunction的对应关系如下:


{RIL_REQUEST_DIAL, dispatchDial, responseVoid},

 

然后就去执行dispatchFunction,如上的dispatchDial()函数,在dispatchFunction函数中,通过回调函数,去调用

例如:

diapatchDial()函数就会调用 s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI);

发送到qcril.so中去。

qcril.c调用onRequest()函数去处理,在这个函数有,有判断当前传过来的requestNumber然后做处理:

if ( ( request == RIL_REQUEST_DIAL ) || ( request == RIL_REQUEST_SETUP_DATA_CALL ) )
  {
    QCRIL_SNPRINTF( label, sizeof( label ), "%s - Token %d",qcril_lookup_event_name( request ), qcril_get_token_id( t ) );
    QCRIL_LOG_CF_PKT_RIL_REQ2( label );
  }


最后将信息经qcril_dispatch_event( entry_ptr, &params )函数来处理,

 qcril_dispatch_event()函数中有这样一句调用,

(entry_ptr->handler)(params_ptr, &ret);


查找到了在qcril.c中定义的对应函数,

{ QCRIL_REG_ALL_ACTIVE_STATES( RIL_REQUEST_DIAL, qcril_cm_callsvc_request_dial ) },


知道是函数qcril_cm_callsvc_request_dial来处理这个请求,这个函数是在qcril_cm.c中定义的,在qcril_cm_callsvc_request_dial函数内部,会调用
if ( qcril_reqlist_new( params_ptr->event_id, params_ptr->t,QCRIL_REQ_AWAITING_CALLBACK, QCRIL_EVT_CM_CALL_ORIG,0, NULL, 0 ) != E_SUCCESS )
注册AMSS回调函数事件,QCRIL_EVT_CM_CALL_ORIG,然后调
cm_result = cm_mm_call_cmd_orig( qcril_cm_callsvc_command_callback,
                               (void *) params_ptr->t,
                               i_ptr->client_id,
                               call_type,
                               srv_type,
                               &calling_number,
                               &called_number,
                               &alpha_buf,
                               cdma_orig_params_ptr,
                               gw_cs_orig_params_ptr,
                               NULL,
                               &call_id );


函数到AMSS去处理,事件变成了QCRIL_EVT_CM_CALL_ORIG,然后返回到qcril_dispatch_event()函数中,调用qcril_state_transition(),

在qcril_state_transition()函数中去调用函数:qcril_process_event(),这个函数会调用到qcril_dispatch_event(),继续调用

(entry_ptr->handler)(params_ptr, &ret);这句话,由于事件换成了QCRIL_EVT_CM_CALL_ORIG,

 

所以通过查找我们知道,调用的是函数:
{ QCRIL_REG_ALL_STATES( QCRIL_EVT_CM_CALL_ORIG,  

  qcril_cm_callsvc_event_orig ) },qcril_cm_callsvc_event_orig,


调用

qcril_response_success( req_info.t, req_info.request, NULL, 0, TRUE );
qcril_cm_clist_report_call_state_changed();


在函数中调用qcril_unsol_response(RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED,NULL,0)函数,上报callstate状态的改变,调用函数qcril_unsol_response2(),调用函数RIL_onUnsolicitedResponse()函数返回函数给RIL.java来处理cril_response_success()会调用
qcril_response_success2( t, request, response, response_len, remove_entry_from_reqlist, NULL );
RIL_onRequestComplete( t, RIL_E_SUCCESS, response, response_len );

 

RIL_onRequestComplete()函数在ril.cpp中定义,调用sendResponse(p)函数,sendReponse(p)调用函数sendResponseRaw(p.data(), p.dataSize()),

然后调用

ret = blockingWrite(fd, (void *)&header, sizeof(header));

写入到socket中,返回RIL.java中去,在RIL.java中,接受socket传过来的数据,

具体代码是RILReceiver中的run()函数,        

try {
                    InputStream is = mSocket.getInputStream();
                    for (;;) {
                        Parcel p;
                        length = readRilMessage(is, buffer);
                        if (length < 0) {
                            // End-of-stream reached
                            break;
                        }
                        p = Parcel.obtain();
                        p.unmarshall(buffer, 0, length);
                        p.setDataPosition(0);
                        //Log.v(LOG_TAG, "Read packet: " + length + " bytes");
                        processResponse(p);
                        p.recycle();
                    }
                }

调用processResponse(p)函数,然后调用
     if (type == RESPONSE_UNSOLICITED) {
            processUnsolicited (p);
        } else if (type == RESPONSE_SOLICITED) {
            processSolicited (p);
        }
返回中告诉我们dial是主动请求的信息,所以会调用 processSolicited (p)函数,然后做相关的处理,发送事件给对应的handler来处理,在调用Dial()函数中,带下来一个事件,
cm.dial(pendingMO.address, clirMode, obtainCompleteMessage());

 

obtainCompleteMessage(EVENT_OPERATION_COMPLETE);在RIL.java中会发出这个事件,然后上层的handler会去做处理。
case EVENT_OPERATION_COMPLETE:
                ar = (AsyncResult)msg.obj;
                operationComplete();

这样,一个主动请求的流程结束。

如上或为个人和网络的经验总结,如有出入,敬请斧正,谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值