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

5

6

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?

Hodess answered 2/3, 2019 at 7:49 Comment(13)
Probably from Google's places database. Similar question here: #16463899Lyndy
did you checked the content provider data corresponding to the number?Jinajingle
@ChristosThemelis How do you know? Have you checked it? Does it return the same information?Hodess
@SarthakMittal What do you mean? Which content provider? How to check it?Hodess
@androiddeveloper I notice at my phone that the dialer's that some results that I cross check, matches with the name that appears at Google places. I did'nt cross check all resultsLyndy
@ChristosThemelis But for all results that you've checked, it's the same? Also, does using this API cost money? Or is it available for all, for free? Can you please share your project on Github (except for the API key, of course) ?Hodess
No, it's not free to request places API, I know that because I am using it for another project. What code to share? I am talking about the default Android dailer at Android 8 (phone with MTK chipset)Lyndy
@ChristosThemelis Maybe you are using the API that requires money, and there is one that is more basic that doesn't (see here: developers.google.com/places/web-service/usage-and-billing ) ? About code, I mean the code of how you tested it, when you wrote "I cross check, matches with the name that appears at Google places"Hodess
@androiddeveloper The test is simple. Phone is ringing, number is not at your contact list but a name displayed. Check the dislpayed name if is equal at Google places. 5 checks, 5 exactly same namesLyndy
@ChristosThemelis But what is the code you used for checking on Google Places on the Android app you've made?Hodess
@androiddeveloper The other project is irrelevant. It is searching for places by category near to you, like Google "maps" application. When you getting info from a place, you getting also the phone (if exists)Lyndy
Is this app same as truecaller?Ashur
@ManojPerumarath TrueCaller doesn't currently replace the UI of the dialer, last time I checked.Hodess
M
3

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!

Mylan answered 6/3, 2019 at 16:1 Comment(14)
Have you tested it? If I search for the phone number I've shown on the screenshot (wrote the phone number above it) , will it show the same information? I've noticed it's available for both server and client side, and that it might cost money, but it seems that for basic usage, it costs nothing: developers.google.com/places/web-service/usage-and-billing . Not sure if that's the correct website. Can you please explain about it (it doesn't say the difference on the website, and doesn't show how much it costs, maybe different for client vs server...)...Hodess
And what are "callDetails" and "statusHints" used for?Hodess
@androiddeveloper yes, I was able to get the same info you have on the screen. You just have to make a new project in the Google cloud console and enable billing in order to use the API, You get 300$ for trial so you can test freely for a while then after that billing applies which is really complicated based on which data you need from the API. You can find more info in the same link you shared developers.google.com/places/web-service/usage-and-billingMylan
I don't know what are "callDetails" and "statusHints" variables are used for!Mylan
About the prices, if I look at "SKU: Basic Data" , it seems for free, and the data there seems to me more than enough for what's shown on the Phone app, no? Can you please share the code you've used to test it (without the real API key of course) ?Hodess
I think you're right about billing, but just in case I had set up a project and will monitor it and update the answer once I'm sure! About the code example, what do you have in your mind exactly? as this is a simple get request and some query params! If you just clicked the request in a browser providing a valid API key it's gonna work! I don't want to write HTTP library specific code tbhMylan
I see, so this could be fine for this: developer.android.com/training/volley/simple , right? I didn't know it's a simple HTTP GET request... I thought there is more into it...Hodess
yeah, it is a simple HTTP GET request, will emphasize this more in the answer! I advise not to put the API directly in the app in production code though for security reasons!Mylan
Wait I see you've updated your answer : "Such an API is not available at the current moment in Google places SDK for Android, but you can make an API in the backend as a proxy" . What do you mean? I need to have a proxy?! Why ? Why can't I use it directly on the app? And what do you mean it's not available for the SDK ?Hodess
I mean that there is already some methods implemented in the SDK like autocomplete and get a place by id developers.google.com/places/android-sdk/intro but this method is not implemented inside the SDK, so you have to handle it yourself(make the request yourself and manage the security concerns)!Mylan
I see. I grant you the bounty. You deserve it. I will give you +1 if you find out what are the functions I wrote about. :)Hodess
About the security part of the API key, since this is about accessing via a simple GET, I don't think it's possible to protect using the methods you wrote if the usage is directly in the app ("package name and your keystore SHA-1 signature or the API address") . But what if a hacker took it? What could they do with it, if it's free anyway? They could use the ones that trigger pricing? Isn't it possible to lock on the free package?Hodess
yeah, you're right I guess it was not clear that this was in case of using the Android library which doesn't belong to this question anyways. I edited the answer to be more clear! About the API key, It's attached to your credit card and nobody knows how the billing would change in the future, also you have quotas that you don't want to exceed even in the free tier!Mylan
Let us continue this discussion in chat.Mylan
R
1

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/
Rejoice answered 7/3, 2019 at 7:2 Comment(2)
So what you are saying is that this is hidden from developers, and that those who made their own dialer use a different set of services to figure out who is behind the phone number? Given that "lineage os" is quite free, does it mean those services are also free?Hodess
And what are "callDetails" and "statusHints" used for?Hodess
E
0

I believe Google has its own database of spam callers, and the Phone app sends the number to its server, and if there is a match, it shows the name.

Maybe, if your app can read notifications, there is a possibility to retrieve that name. Try this example out and modify it according to your needs

Ergocalciferol answered 7/3, 2019 at 6:38 Comment(4)
I'm not interested in such workarounds. Besides, I want to know how to do it when the current app is the default dialer, so this won't work anyway...Hodess
And what are "callDetails" and "statusHints" used for?Hodess
If its the default dialer and your app can read the notifications then it should be possible to get the text from that notification. I have no idea about the second part you're asking forErgocalciferol
If the app is the default dialer and shows its own UI, it is the one that is responsible for showing the notification, so there is no need to read the notification as I'm the one who will create it. There is also no data to read, because I'm the one that should put the text into it.Hodess
R
0

You could check the working of apps like Truecaller for this. Truecaller acts on a give and take scenario... You want those unknown numbers then you have to part with your phone book contacts.. Now apparently everyone who has installed the app has surrendered his phone book. The data is crowd-sourced from the millions of users who have downloaded the truecaller app on their smart phones. As part of the end user agreement, the truecaller app asks the user to allow access to the user's address book/contacts on the smart phone. This data is then uploaded by the app to the company's servers. After going through several data matching/refining algorithms, this data is made available to all truecaller users to search upon.

Rafaelle answered 11/3, 2019 at 11:48 Comment(1)
I'm aware of this. I asked about the dialer app of Google.Hodess
S
-1

Google Phone app is provided a feature of Use caller ID & spam protection by default. Some of these steps work only on Android 6.0 and up.

When you make or get a call with caller ID and spam protection on, you can see information about callers or businesses not in your contacts or warnings about potential spam callers.

To use caller ID and spam protection, your phone may need to send information about your calls to Google.

Turn caller ID & spam protection off or back on

Caller ID and spam protection is on by default. You can choose to turn it off.

To use caller ID and spam protection, your phone may need to send information about your calls to Google. It doesn’t control whether your number shows when you make calls.

Caller ID by Google shows the names of companies and services with a Google My Business listing. It also looks for matches in any directory that shows caller information for work or school accounts.

As per your solution, Google does not provide this kind of support as you want. you need to create your own function and save spam and other contact detail at your side.

Shovelhead answered 11/3, 2019 at 11:37 Comment(2)
You wrote it as if I ask as a user how to use it. I asked how to use the API to get this information, not how to enable it on the smartphone... I already know how to turn on a setting...Hodess
as i said Google does not provide API to get this informationShovelhead

© 2022 - 2024 — McMap. All rights reserved.