Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does "Phone" app show information of contacts that are not on the address book?

Background

In the "Phone" app of Google, there is an option "Caller ID & spam" :

enter image description here

So, if you get a call from someone or some organization that isn't on the address book, yet it is identified somehow, you get a name for it, as such (called "+972-035283487") :

enter image description here

Ever since Android M (6.0 - API 23) , apps can replace the default phone app, and then also providing alternative UI when you call someone or get a phone call, by extending InCallService class, as demonstrated here which is based on here.

The problem

I want to try to show the same information as on the Phone app, meaning the name of the person/company in case it identified it (and it's not on the address book).

What I've tried

I tried to dig over the various things that I get via the API of the dialer, but failed:

  1. Various fields and functions of: android.telecom.Call class

  2. There is getDetails inside of the Call class, so I tried to get what's inside there, and there is also statusHints and "label" inside the "statusHints" . None of those had any information (returned null). The reason I tried to look at "statusHints" is because that's what I see on the docs :

Contains status label and icon displayed in the in-call UI.

  1. On the "Phone" app, pressing "Learn more" goes to a website (here) full of links that I think might be sources of the data, but I don't think the app itself uses this. Instead I think it uses something of Google.

The questions

  1. Is it possible to get this CallerId information? If so, how?

  2. How does the Phone app do it? It's supposed to be open sourced, so there has to be something that gives it this information, right? Would cloning it somehow get this information? Maybe Google has its own service for CallerID?

  3. What are the "callDetails" and "statusHints" used for? What do they provide?

like image 946
android developer Avatar asked Mar 02 '19 07:03

android developer


2 Answers

I believe Android's native phone app is using Google's place search API. As you can easily search for a place by its phone number and get place details like name, place id, formatted_address and many other fields that you can find in the documentation

Request URL: https://maps.googleapis.com/maps/api/place/findplacefromtext/json

Request method: GET

Request query parameters:

  • key: Your application's API key.
  • input: The text input specifying which place to search for (for example a name or phone number).
  • inputtype: The type of input. This can be one of either textquery or phonenumber. Phone numbers must be in international format (prefixed by a plus sign ("+"), followed by the country code, then the phone number itself).

Example request: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=%2B972035283487&inputtype=phonenumber&fields=place_id,name&key=API_KEY_HERE

Example response:

{
   "candidates" : [
      {
         "name" : "מלך העופות",
         "place_id" : "ChIJ78ko1zBKHRURpwbgUdWc4nU"
      },
      {
         "name" : "Of Yaakov",
         "place_id" : "ChIJv3myn4FMHRURUGffcXgxKuw"
      }
   ],
   "status" : "OK"
}

Note: Such an API is not available at the current moment in Google places SDK for Android, but you can use the HTTP API directly in your app or you can make an API in the backend as a proxy to the places API. I prefer the later version as in the first solution the API key is deployed in the application code and hackers could decompile the APK and use it for malicious reasons. For security reasons you have to restrict the usage of the API key to the IP address of the server in case you are using the backend solution!

like image 54
Ahmed Hegazy Avatar answered Oct 13 '22 21:10

Ahmed Hegazy


I tried to decompile the Dialer app, couldn't find the specific info about how the app is doing it.

But this info could be useful. Please check it.

In Dialer app, there are classes SpamCallDatabase_Impl.smali SpamCallDatabase.smali and there is service running in package com.google.android.gms app, which provides spam lists

com.google.android.gms/.telephonyspam.sync.SpamListSyncTaskService 

and for caller id check this commit

https://gitlab.e.foundation/e/os/android_packages_apps_Dialer/commit/420eb901ed1d64fdaf055cde4cc46d7a5c0b42fc

This looks dialer app of lineage os and it uses different services for phone num lookup like

https://auskunft.at/

https://www.dastelefonbuch.de/
like image 44
nkalra0123 Avatar answered Oct 13 '22 20:10

nkalra0123