CallLogFragment 数据显示的fragment
CallLogQueryHandler查询calllog.db{calls}
CallLogAdapter显示结果
>>CallLog加载或显示:
CallLogFragment.java
-onResume
--refreshData()
---startCallsQuery();
----mCallLogQueryHandler.fetchCalls(mCallTypeFilter);
|
CallLogQueryHandler.java
-fetchCalls()
--fetchCalls(QUERY_CALLLOG_TOKEN, requestId, callType, false /* newOnly */, newerThan, sub);
--- startQuery(token, requestId, uri,
CallLogQuery._PROJECTION, selection, selectionArgs.toArray(EMPTY_STRING_ARRAY), Calls.DEFAULT_SORT_ORDER);
接下来NoNullCursorAsyncQueryHandlerextends AsyncQueryHandler,所以会调用AsyncQueryHandler中的startQuery\startInsert\startUpdate\startDelete方法. 发送给后台,也就是ContentProvider.这里提供了操作数据库基本方法{query\insert\update\delete}
执行完毕会触发onQueryComplete\onInsertComplete\onUpdateComplete\onDeleteComplete.层层返回
UI显示是通过如下:
CallLogAdapter中的newChildView加载布局文件:
View view = inflater.inflate(R.layout.call_log_list_item, parent, false);
之后,会对每一条通话记录进行复制操作,接口bindView{
final String number = c.getString(CallLogQuery.NUMBER);
final int numberPresentation = c.getInt(CallLogQuery.NUMBER_PRESENTATION);
final long date = c.getLong(CallLogQuery.DATE);
final long duration = c.getLong(CallLogQuery.DURATION);
final int callType = c.getInt(CallLogQuery.CALL_TYPE);
final String countryIso = c.getString(CallLogQuery.COUNTRY_ISO);
final int subscription = c.getInt(CallLogQuery.SUBSCRIPTION);
final int durationType = c.getInt(CallLogQuery.DURATION_TYPE);
final String videocallDuration = c.getString(CallLogQuery.VIDEO_CALL_DURATION);
final ContactInfo cachedContactInfo = getContactInfoFromCallLog(c);
final boolean isVoicemailNumber =
PhoneNumberUtilsWrapper.INSTANCE.isVoicemailNumber(number);
// Primary action is always to call, if possible.
if (PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)) {
// Sets the primary action to call the number.
views.primaryActionView.setTag(IntentProvider.getReturnCallIntentProvider(number,
subscription));
} else {
views.primaryActionView.setTag(null);
}
>>CallLog添加:
CallsManager的setCallState函数
->listener.onCallStateChanged(call, oldState, newState);
跳转CallLogManager.java->onCallStateChanged
->logCall
->logCallAsync(args);
->return new LogCallAsyncTask().execute(args);
->addCall
跳转CallLog.java->addCall
->addEntryAndRemoveExpiredEntries
->resolver.insert
跳转CallLogProvider.java->insert (插入到:CONTENT_URI = Uri.parse("content://call_log/calls"))
->getDatabaseModifier(mCallsInserter).insert(copiedValues)//insert方法插入到Tables.CALLS
->DbModifierWithNotification(Tables.CALLS, insertHelper, getContext());
跳转DbModifierWithNotification
private void notifyCallLogChange() {
mContext.getContentResolver().notifyChange(Calls.CONTENT_URI, null, false);
Intent intent = new Intent("com.android.internal.action.CALL_LOG_CHANGE");
intent.setComponent(new ComponentName("com.android.calllogbackup",
"com.android.calllogbackup.CallLogChangeReceiver"));
if (!mContext.getPackageManager().queryBroadcastReceivers(intent, 0).isEmpty()) {
mContext.sendBroadcast(intent);
}
}
跳转CallLogChangeReceiver中处理ACTION_CALL_LOG_CHANGE.equals(intent.getAction()
补充:CallsManager添加MISSED\Reject call 记录到calls数据库中
mCallLogManager.logCall(incomingCall, Calls.MISSED_TYPE, result.shouldShowNotification);
mCallLogManager.logCall(incomingCall, Calls.MISSED_TYPE, true /*showNotificationForMissedCall*