之前在看Android官方文档系统的时候看到Android N 一系列新增和改变的特性,因为工作中负责的部分和通话有关,就尤其注意到了这个Call Screening。
下面来简单介绍一下Call Screening是什么,以及它在通话流程中起了哪些作用。
PS:一下代码全部来自Mokee mkn-mr1,
来自android官方的解释
Call Screening
Android 7.0 allows the default phone app to screen incoming calls. The phone app does this by implementing the new CallScreeningService, which allows the phone app to perform a number of actions based on an incoming call's
Reject the incoming call
Do not allow the call to the call log
Do not show the user a notification for the call
For more information, see the reference documentation for
来电过滤(Call Screening)
Android 7.0 允许默认的手机应用过滤来电。手机应用执行此操作的方式是实现新的 CallScreeningService,该方法允许手机应用基于来电的
拒绝来电
不允许来电到达通话记录
不向用户显示来电通知
如需了解详细信息,请参阅可下载的 API 参考中的 android.telecom.CallScreeningService。
读者可能会奇怪 Call Screening翻译成“
呼叫筛选
”可能更合适些,来电过滤 或许应该是IncomingCall filter的翻译啊(其实这也是有道理的,看了代码就知晓了)。
上面的文字有两个重点 based on an incoming call's Call.Details和 CallScreeningService。
应该是从
Call.Details来判断需不需要过滤,先不看去判断哪些具体的条件,我们先看看CallScreeningService
在代码中是什么样子的。
CallScreeningService
public abstract class CallScreeningService
extends Service
This service can be implemented by the default dialer (see
Below is an example manifest registration for a CallScreeningService.
首先它是一个services,需要在拨号软件中实现,在AndroidManifest中的声明如上。
分析在源码中的使用
下面到源码中看这个是怎么使用的。
但是得到的第一个就是失望的消息,,
目前只有测试相关的代码
cts/tests/tests/telecom/src/android/telecom/cts/MockCallScreeningService.java 注册了CallScreeningService,也就是说我们在Android N中并看不到这个功能的实际使用。
但是我们依然可以窥探一下CallScreeningService的功能以及在现有代码中的作用
PS:所有代码来自Mokee mkn-mr1
publicstaticclassBuilder{privatebooleanmShouldDisallowCall;privatebooleanmShouldRejectCall;privatebooleanmShouldSkipCallLog;privatebooleanmShouldSkipNotification;/** Sets whether the incoming call should be blocked.*/publicBuildersetDisallowCall(booleanshouldDisallowCall){mShouldDisallowCall=shouldDisallowCall;returnthis;}/** Sets whether the incoming call should be disconnected as if the user had manually* rejected it. This property should only be set to true if the call is disallowed.*/publicBuildersetRejectCall(booleanshouldRejectCall){mShouldRejectCall=shouldRejectCall;returnthis;}/** Sets whether the incoming call should not be displayed in the call log. This property* should only be set to true if the call is disallowed.*/publicBuildersetSkipCallLog(booleanshouldSkipCallLog){mShouldSkipCallLog=shouldSkipCallLog;returnthis;}/** Sets whether a missed call notification should not be shown for the incoming call.* This property should only be set to true if the call is disallowed.*/publicBuildersetSkipNotification(booleanshouldSkipNotification){mShouldSkipNotification=shouldSkipNotification;returnthis;}publicCallResponsebuild(){returnnewCallResponse(mShouldDisallowCall,mShouldRejectCall,mShouldSkipCallLog,mShouldSkipNotification);}}
四个重要的方法:setDisallowCall(), setRejectCall(), setSkipCallLog(), setSkipNotification(), 从这4个方法也可以大概知道,这个“
来电过滤
”能做的具体的事情是什么:1. 完全阻止来电(类似黑名单),2. 是否拒接来电, 3. 是否在CallLog中显示, 4. 是否要显示未接通知(这跟前面不就是一样的嘛),也就是说 可以通过这4个方法设置来电的提醒方式。
在cts代码中使用
再看一下在cts代码中的使用的
privateCallScreeningServiceCallbackscreateCallbacks(){returnnewCallScreeningServiceCallbacks(){@OverridepublicvoidonScreenCall(Call.DetailscallDetails){mCallFound=true;CallScreening