MessageBoxActivity.java
private void startQuery{
if(SIMCARD.equals(boxType)){
if(phoneId == 1){
mQueryHandler.startQuery(9, null, uri_icc1, null, null, null, null);
}
}
}
private AsyncQueryHandler mQueryHandler = null;
onCreate() mQueryHandler = new QueryHandler(mContentResolver, this);
private class QueryHandler extends AsyncQueryHandler{
protected void onQueryComplete(int token, Object cookie, Cursor cursor){
}
}
查看startQuery函数
AsyncQueryHandler.java
public void startQuery(int token, Object cookie, Uri uri, String[] projection, String selection, String[] selectionArgs, String orderBy){
Message msg = mWorkerThreadHandler.obtainMessage(token);
msg.arg1 = EVENT_ARG_QUERY;
WorkerArgs args = new WorkerArgs();
args.handler = this; //这里的handler是当前类中的
args.uri = uri;
...
msg.obj = args;
mWorkerThreadHandler.sendMessage(msg);
}
mWorkerThreadHandler = createHandler(sLooper); -> new WorkerHandler(looper);
protected class WorkerHandler extends Handler{
public void handleMessage(Message msg){
WorkerArs args = (WorkerArgs)msg.obj;
int event = msg.arg1;
switch(event){
case EVENT_ARG_QUERY:
Cursor cursor;
curosr = resolver.query(args.uri, args.projection, args.selection, args.selectionArgs, args.orderBy);
args.result = cursor;
break;
}
Message reply = args.handler.obtaionMessage(token);
reply.obj = args;
reply.arg1 = msg.arg1;
reply.sendToTarget();
}
}
public void handleMessage(Message msg){
WorkerArgs args = (WorkerArgs)msg.obj;
int token = msg.what;
int event = msg.arg1;
switch(event){
case EVENT_ARG_QUERY:
onQueryComplete(token, args.cookie, (Cursor)args.result);
break;
}
}
MessageBoxActivity.java 重写onQueryComplete
protected void onQueryComplete(int token, Object cookie, Cursor cursor){
if(cursor != null) {
mListAdapter = new MessageSimListAdapter(mParent, cursor);
mMsgList.setAdapter(mListAdapter);
mMsgList.setOnCreateContextMenuListener(mSimMsgListOnCreateContextMenuListener);
mMsgList.setOnItemClickListener(mOnItemClickListener);
updateState(SHOW_LIST);
}
}
总结一下:
在MessageBoxActivity中,创建继承自AsyncQueryHandler的类QueryHandler,重写方法onQueryComplete
新建类QueryHandler对象,调用AsyncQueryHandler中的方法startQuery,参数为Uri等,
在方法startQuery中,利用内部类WorkerHandler的对象mWorkerThreadHandler,处理查询消息,这是一个继承自Handler的类。
查询完成后,让AsyncQueryHandler的handleMessage来处理查询完成后的事情。
调用的是onQueryComplete,而QueryHandler已经重写了,因此实际调用的是MessageBoxActivity中的QueryHandler的onQueryComplete
mQueryHandler.startQuery(9, null, uri_icc1, null, null, null, null);
由于我们是查看UIM卡中的短信,需要继续查看SmsProvider.java中的细节
从LOG来看
public Cursor query(Uri url, ...){
Log.i("SmsProvider","query SMS_INBOX"+match);
}
I/SmsProvider( 341): query SMS_INBOX86
default:
if(match == SMS_ALL_ICC+MAX_MATCH_TYPE){
return getAllMessagesFromIcc(getPhoneId(match));
}
private Cursor getAllMessagesFromIcc(int phoneId){
SmsManager smsManager = SmsManager.getDefault(phoneId);
ArrayList<SmsMessage> messages = smsManager.getAllMessagesFromIcc();
}
查看SmsManager.java
public ArrayList<SmsMessage> getAllMessageFromIcc(){
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService(PhoneFactory.getServiceName("isms",mPhoneId)));
if(iccIsms != null)
records = iccISms.getAllMessagesFromIccEf();
return createMessageListFromRawRecords(records);
}
RuimSmsInterfaceManager.java
public List<SmsRawData> getAllMessagesFromIccEf(){
mPhone.getIccFileHandler().loadEFLinearFexedAll(IccConstants.EF_SMS, response);
}
IccFileHandler.java
public void loadEFLinearFixedAll(int fileid, Message onLoaded){
Message response = obtainMessage(EVENT_GET_RECORD_SIZE_DONE, new LoadLinearFexedContext(fileid, onLoaded));
phone.mCM.iccIO(COMMAND_GET_RESPONSE, fileid, getEFPath(fileid), 0, 0, GET_RESPONSE_EF_SIZE_BYTES, null, null, response);
}
RIL.java
public void iccIO(int command, int fileid, String path, int p1, int p2, int p3, String data, Stirng pin2, Message result){
RILRequest rr = RILRequest.obtain(RIL_REQUEST_SIM_IO, result);
rr.mp.writeInt(command);
rr.mp.writeInt(fileid);
...
send(rr);
}