骚扰号码存放的URI
BlockedNumberContract.BlockedNumbers.CONTENT_URI
存放号码的列
BlockedNumberContract.BlockedNumbers.COLUMN_ORIGINAL_NUMBER
ContentResolver contentResolver = getContext().getContentResolver();
ContentValues newValues = newContentValues();
newValues.put(BlockedNumberContract.BlockedNumbers.COLUMN_ORIGINAL_NUMBER,
mNumber);
contentResolver.insert(BlockedNumberContract.BlockedNumbers.CONTENT_URI,
newValues);
号码是否存在
BlockedNumberContract.isBlocked(getContext(),mNumber)
https://developer.android.com/reference/android/provider/BlockedNumberContract.html
拦截原理
Telcomm(packages/services/Telecomm)
CallsManager onSuccessfulIncomingCall
@Override
public void onSuccessfulIncomingCall(Call incomingCall) {
Log.d(this, "onSuccessfulIncomingCall");
List
filters.add(new DirectToVoicemailCallFilter(mCallerInfoLookupHelper));
filters.add(new AsyncBlockCheckFilter(mContext,new BlockCheckerAdapter()));
filters.add(new CallScreeningServiceFilter(mContext, this,mPhoneAccountRegistrar,
mDefaultDialerManagerAdapter,
newParcelableCallUtils.Converter(), mLock));
new IncomingCallFilter(mContext, this,incomingCall, mLock,
mTimeoutsAdapter,filters).performFiltering();
}
public void performFiltering() {
Log.event(mCall, Log.Events.FILTERING_INITIATED);
Log.d(this, "[performFiltering], timeout = "
+mTimeoutsAdapter.getCallScreeningTimeoutMillis(mContext.getContentResolver()));
for (CallFilter filter : mFilters) {
filter.startFilterLookup(mCall,this);
}
mHandler.postDelayed(new Runnable("ICF.pFTO") { //performFiltering time-out
@Override
public void loggedRun() {
// synchronized to prevent arace on mResult and to enter into Telecom.
synchronized (mTelecomLock) {
if (mIsPending) {
Log.i(IncomingCallFilter.this, "Call filtering has timed out.");
Log.event(mCall,Log.Events.FILTERING_TIMED_OUT);
mListener.onCallFilteringComplete(mCall, mResult);
mIsPending = false;
}
}
}
}.prepare(),mTimeoutsAdapter.getCallScreeningTimeoutMillis(mContext.getContentResolver()));
}
AsyncBlockCheckFilter
protected void onPostExecute(Boolean isBlocked) {
CallFilteringResult result;
if (isBlocked) {
result = new CallFilteringResult(
false, // shouldAllowCall
true, //shouldReject
false, //shouldAddToCallLog
false //shouldShowNotification
);
} else {
result = new CallFilteringResult(
true, // shouldAllowCall
false, // shouldReject
true, // shouldAddToCallLog
true //shouldShowNotification
);
}