12

Android API level 24 introduces a new Service called the CallScreeningService. The documentation says that the service can by implemented by the default dialer to screen incoming calls. I would like to implement this service in my own app, preferably without creating an entire dialer app, but a simple naive implementation seems to be ignored by the OS when an incoming call happens.

AndroidManifest.xml snippet:

<service android:name="com.example.callbouncer.CallService" android:permission="android.permission.BIND_SCREENING_SERVICE">
    <intent-filter>
        <action android:name="android.telecom.CallScreeningService"/>
    </intent-filter>
</service>

CallService.java:

// imports...
public class CallService extends CallScreeningService {
    @Override
    public void onScreenCall(Call.Details callDetails) {
        CallResponse.Builder response = new CallResponse.Builder();
        Log.e("CallBouncer", "Call screening service triggered");
        respondToCall(callDetails, response.build() );
    }
}

There are no errors while building or installing this program, but the screening doesn't seem to be taking place. Have I done something wrong (like the manifest or missing implementations/overrides in the service) or is it just not possible? If it's not possible in a small app like this, will it be possible if I implement an entire dialing app and set it as the default dialer? Finally, if that's the case, is there anything preventing me from just forking the dialer out of the AOSP and adding my features to it?

Segfault
  • 8,036
  • 3
  • 35
  • 54

2 Answers2

14

As of Android 10 (API 29+), you can have a CallScreeningService without the requirement of also implementing an entire dialer app. Until Android 10, only the default dialer app's call CallScreeningService would be invoked.

https://developer.android.com/about/versions/10/features#call-screening

Don't get too excited though, because it's very buggy and does not work as the documentation says it does:

My workaround for getting called for known contacts was to ask the user for contact access and check if the incoming caller was in the user's contacts. There is no workaround for the other issues at the moment.

I made a very basic screening app that declines all calls from numbers not in the user's contacts you can use an an example if you like: https://github.com/joshfriend/gofccyourself

Josh
  • 1,306
  • 2
  • 17
  • 28
  • 1
    Thanks @Josh! I would use your gofccyourself as an example, but that's exactly the functionality I wanted to implement! – Segfault Nov 11 '19 at 20:11
  • 1
    @Josh is it crucial to obtain the role of call screening service to make it working? What do you do if you don't get this role granted? – BWappsAndmore Aug 03 '20 at 14:45
  • @BWappsandmore you do nothing because it is required for anything to work as stated in the documentation. – Josh Aug 03 '20 at 18:18
  • I can't find where doc show "only the default dialer app's call CallScreeningService would be invoked." – Kiwi Lin Feb 01 '21 at 09:36
  • @HvSimon Right at the top of the CallScreeningService docs "This service can be implemented by the default dialer or a third party app" – Josh Feb 01 '21 at 16:05
  • There is "or a third party app", so not only work for default dialer? – Kiwi Lin Feb 02 '21 at 08:09
  • 2
    As of android 10, yes, but before that it was _only the default dialer app_ as clearly stated in my answer – Josh Feb 02 '21 at 14:04
1

Looking at the docs you linked to:

This service can be implemented by the default dialer (see getDefaultDialerPackage()) to allow or disallow incoming calls before they are shown to a user.

Don't think you can do this in a separate app (at least with the current interface: I'd expect in the not too distant feature it will be exposed).

Femi
  • 64,273
  • 8
  • 118
  • 148
  • I have the same suspicion, which is why I didn't invest a lot of time in this test app but I still worry I haven't implemented something correctly, since I don't have a lot of experience with Android Services and hope someone can answer definitively. – Segfault Apr 25 '17 at 18:10
  • 4
    As of Android Q, a non-default-dialer app can request to obtain the role of call screening service: https://developer.android.com/reference/android/telecom/CallScreeningService.html#becoming-thecallscreeningservice – Josh Apr 07 '19 at 22:59
  • What if it is a system app? – Dhinakaran Thennarasu Jul 26 '19 at 03:19
  • @Josh want to rework that into an answer so I can accept it? – Segfault Nov 09 '19 at 17:06
  • 1
    @Femi , they have updated the docs and also included the word 3rd party, what do you think, are they allowing non default dialer apps to access call screening service below android 10 ? – humble_wolf Mar 10 '20 at 15:09