Skip to content

Commit 9c593fa

Browse files
committed
Integrate Tellows API
1 parent 7d5e606 commit 9c593fa

File tree

8 files changed

+261
-14
lines changed

8 files changed

+261
-14
lines changed

app/src/main/java/com/addev/listaspam/MainActivity.kt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ import com.addev.listaspam.service.UpdateChecker
2929
import com.addev.listaspam.util.SpamUtils
3030
import com.addev.listaspam.util.getBlockedNumbers
3131
import com.addev.listaspam.util.getCallLogs
32+
import com.addev.listaspam.util.getListaSpamApiLang
33+
import com.addev.listaspam.util.getTellowsApiCountry
3234
import com.addev.listaspam.util.getWhitelistNumbers
3335
import com.addev.listaspam.util.setListaSpamApiLang
36+
import com.addev.listaspam.util.setTellowsApiCountry
3437
import java.util.Locale
3538

3639
class MainActivity : AppCompatActivity(), CallLogAdapter.OnItemChangedListener {
@@ -59,6 +62,7 @@ class MainActivity : AppCompatActivity(), CallLogAdapter.OnItemChangedListener {
5962
recyclerView?.layoutManager = LinearLayoutManager(this)
6063

6164
setLanguage()
65+
setCountry()
6266
checkUpdates()
6367
}
6468

@@ -102,6 +106,8 @@ class MainActivity : AppCompatActivity(), CallLogAdapter.OnItemChangedListener {
102106
}
103107

104108
private fun setLanguage() {
109+
if (getListaSpamApiLang(this) != null) return
110+
105111
val systemLanguage = Locale.getDefault().language.lowercase()
106112
val supportedLanguages = setOf(
107113
"en", "es", "fr", "de", "it", "ru", "sv", "pl", "pt",
@@ -110,10 +116,27 @@ class MainActivity : AppCompatActivity(), CallLogAdapter.OnItemChangedListener {
110116
)
111117

112118
val finalLang = if (supportedLanguages.contains(systemLanguage)) systemLanguage else "en"
113-
114119
setListaSpamApiLang(this, finalLang.uppercase())
115120
}
116121

122+
private fun setCountry() {
123+
if (getTellowsApiCountry(this) != null) return
124+
125+
val systemCountry = Locale.getDefault().country.lowercase()
126+
val supportedCountries = setOf(
127+
"de", "sa", "dz", "ar", "au", "at", "be", "by", "br", "cl",
128+
"cn", "co", "kr", "dk", "eg", "ae", "si", "es", "ph", "fi",
129+
"fr", "gr", "hu", "in", "id", "ir", "ie", "il", "it", "jp",
130+
"mx", "ng", "no", "nz", "nl", "pk", "pe", "pl", "pt", "gb",
131+
"cz", "hk", "ru", "sg", "za", "se", "ch", "tw", "tr", "ua",
132+
"us", "ve"
133+
)
134+
135+
val finalCountry = if (supportedCountries.contains(systemCountry)) systemCountry else "us"
136+
setTellowsApiCountry(this, finalCountry)
137+
}
138+
139+
117140
private fun showNumberInputDialog() {
118141
val builder = AlertDialog.Builder(this)
119142
builder.setTitle(getString(R.string.test_number))

app/src/main/java/com/addev/listaspam/util/ApiUtils.kt

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package com.addev.listaspam.util
22

3+
import android.util.Log
34
import okhttp3.FormBody
5+
import okhttp3.HttpUrl
46
import okhttp3.OkHttpClient
57
import okhttp3.Request
68
import org.json.JSONObject
9+
import javax.xml.parsers.DocumentBuilderFactory
710

811
/**
912
* Utility object for interacting with the UnknownPhone API to check if a phone number is marked as spam.
1013
*/
1114
object ApiUtils {
12-
private const val API_URL = "https://secure.unknownphone.com/api/"
13-
private const val API_KEY = "d58d5bdaba8a80b2311957e9e4af885c"
15+
private const val UNKNOWN_PHONE_API_URL = "https://secure.unknownphone.com/api/"
16+
private const val UNKNOWN_PHONE_API_KEY = "d58d5bdaba8a80b2311957e9e4af885c"
17+
18+
private const val TELLOWS_API_URL = "www.tellows.de"
19+
private const val TELLOWS_API_KEY = "koE5hjkOwbHnmcADqZuqqq2"
20+
1421
private val client = OkHttpClient()
1522

1623
/**
@@ -25,14 +32,14 @@ object ApiUtils {
2532
fun checkListaSpamApi(number: String, lang: String): Boolean {
2633
val formBody = FormBody.Builder()
2734
.add("user_type", "free")
28-
.add("api_key", API_KEY)
35+
.add("api_key", UNKNOWN_PHONE_API_KEY)
2936
.add("phone", number)
3037
.add("_action", "_get_info_for_phone")
3138
.add("lang", lang)
3239
.build()
3340

3441
val request = Request.Builder()
35-
.url(API_URL)
42+
.url(UNKNOWN_PHONE_API_URL)
3643
.post(formBody)
3744
.header("Connection", "Keep-Alive")
3845
.header("Content-Type", "application/x-www-form-urlencoded")
@@ -60,4 +67,48 @@ object ApiUtils {
6067
false
6168
}
6269
}
70+
71+
fun checkTellowsSpamApi(number: String, country: String): Boolean {
72+
val url = HttpUrl.Builder()
73+
.scheme("https")
74+
.host(TELLOWS_API_URL)
75+
.addPathSegments("basic/num/$number")
76+
.addQueryParameter("xml", "1")
77+
.addQueryParameter("partner", "androidapp")
78+
.addQueryParameter("apikey", TELLOWS_API_KEY)
79+
.addQueryParameter("overridecountryfilter", "1")
80+
.addQueryParameter("country", country)
81+
.addQueryParameter("showcomments", "50")
82+
.build()
83+
84+
val request = Request.Builder()
85+
.url(url)
86+
.get()
87+
.header("Connection", "Keep-Alive")
88+
.header("Host", "www.tellows.de")
89+
.header("User-Agent", "Dalvik/2.1.0 (Linux; U; Android 6.0; I14 Pro Max Build/MRA58K)")
90+
.build()
91+
92+
return try {
93+
val response = client.newCall(request).execute()
94+
if (!response.isSuccessful) return false
95+
96+
val bodyString = response.body?.string() ?: return false
97+
98+
val xml = DocumentBuilderFactory.newInstance().newDocumentBuilder()
99+
.parse(bodyString.byteInputStream())
100+
Log.d("com.addev.listaspam", "parsed")
101+
102+
103+
val scoreNode = xml.getElementsByTagName("score").item(0)
104+
val score = scoreNode?.textContent?.toIntOrNull() ?: return false
105+
Log.d("com.addev.listaspam", score.toString())
106+
107+
// Tellows scores: 1 (safe) to 9 (very dangerous)
108+
score >= 7
109+
} catch (e: Exception) {
110+
false
111+
}
112+
}
113+
63114
}

app/src/main/java/com/addev/listaspam/util/SharedPreferencesUtils.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ fun setListaSpamApiLang(context: Context, languageCode: String) {
3737
sharedPreferences.edit().putString("pref_language", languageCode.uppercase()).apply()
3838
}
3939

40+
fun shouldFilterWithTellowsApi(context: Context): Boolean {
41+
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
42+
return sharedPreferences.getBoolean("pref_filter_tellows_api", true)
43+
}
44+
45+
fun getTellowsApiCountry(context: Context): String? {
46+
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
47+
return sharedPreferences.getString("pref_tellows_country", null)?.lowercase()
48+
}
49+
50+
fun setTellowsApiCountry(context: Context, countryCode: String) {
51+
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
52+
sharedPreferences.edit().putString("pref_tellows_country", countryCode.lowercase()).apply()
53+
}
54+
4055
fun shouldFilterWithListaSpamScraper(context: Context): Boolean {
4156
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
4257
return sharedPreferences.getBoolean("pref_filter_lista_spam_scraper", false)

app/src/main/java/com/addev/listaspam/util/SpamUtils.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ class SpamUtils {
120120
ApiUtils.checkListaSpamApi(number, getListaSpamApiLang(context) ?: "EN")
121121
}
122122
}
123+
124+
val tellowsApi = shouldFilterWithTellowsApi(context)
125+
if (tellowsApi) {
126+
spamCheckers.add { number ->
127+
ApiUtils.checkTellowsSpamApi(number, getTellowsApiCountry(context) ?: "us")
128+
}
129+
}
130+
123131
if (shouldFilterWithListaSpamScraper(context) && !listaSpamApi) spamCheckers.add(::checkListaSpam)
124132

125133
if (shouldFilterWithResponderONo(context)) spamCheckers.add(::checkResponderono)

app/src/main/res/values-es/strings.xml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@
4242
<string name="pref_enable_blocking_title">Activar bloqueo</string>
4343
<string name="pref_enable_blocking_summary">Habilitar o deshabilitar la función de bloqueo de llamadas</string>
4444

45-
<!-- Spam Number Filters -->
46-
<string name="pref_filter_lista_spam_title">API unknownphone.com</string>
45+
<!-- API Unknownphone -->
46+
<string name="pref_filter_lista_spam_title">API Unknownphone</string>
4747
<string name="pref_filter_lista_spam_summary">[🌐] (Recomendado) Bloquea llamadas de números spam incluidos en la API unknownphone.com</string>
4848

4949
<string name="pref_filter_lista_spam_api_language_title">Idioma API unknownphone.com</string>
50-
<string name="pref_filter_lista_spam_api_language_summary">Seleccione el idioma para realizar las búsquedas en la API de unknownphone.com (afecta los resultados)</string>
50+
<string name="pref_filter_lista_spam_api_language_summary">Seleccione el idioma para realizar las búsquedas en la API de unknownphone.com (afecta a los resultados)</string>
51+
52+
<!-- API Tellows -->
53+
<string name="pref_filter_tellows_title">API Tellows</string>
54+
<string name="pref_filter_tellows_summary">[🌐] (Recomendado) Bloquea llamadas de números spam listados en la API de Tellows</string>
5155

56+
<string name="pref_filter_tellows_api_country_title">País API Tellows</string>
57+
<string name="pref_filter_tellows_api_country_summary">Seleccione el país para las búsquedas en la API de Tellows (afecta a los resultados)</string>
58+
59+
<!-- Spam Number Filters -->
5260
<string name="pref_filter_lista_spam_scraper_title">Scraper listaspam.com</string>
5361
<string name="pref_filter_lista_spam_scraper_summary">[🇪🇸] (Obsoleto) Bloquea llamadas de números spam incluidos en la web listaspam.es</string>
5462

app/src/main/res/values/arrays.xml

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<item>Slovenčina</item> <!-- sk -->
2727
<item>Românește</item> <!-- ro -->
2828
</string-array>
29-
3029
<string-array name="language_values">
3130
<item>EN</item>
3231
<item>ES</item>
@@ -53,4 +52,112 @@
5352
<item>SK</item>
5453
<item>RO</item>
5554
</string-array>
55+
<string-array name="entryvalues_region_preference">
56+
<item>de</item>
57+
<item>sa</item>
58+
<item>dz</item>
59+
<item>ar</item>
60+
<item>au</item>
61+
<item>at</item>
62+
<item>be</item>
63+
<item>by</item>
64+
<item>br</item>
65+
<item>cl</item>
66+
<item>cn</item>
67+
<item>co</item>
68+
<item>kr</item>
69+
<item>dk</item>
70+
<item>eg</item>
71+
<item>ae</item>
72+
<item>si</item>
73+
<item>es</item>
74+
<item>ph</item>
75+
<item>fi</item>
76+
<item>fr</item>
77+
<item>gr</item>
78+
<item>hu</item>
79+
<item>in</item>
80+
<item>id</item>
81+
<item>ir</item>
82+
<item>ie</item>
83+
<item>il</item>
84+
<item>it</item>
85+
<item>jp</item>
86+
<item>mx</item>
87+
<item>ng</item>
88+
<item>no</item>
89+
<item>nz</item>
90+
<item>nl</item>
91+
<item>pk</item>
92+
<item>pe</item>
93+
<item>pl</item>
94+
<item>pt</item>
95+
<item>gb</item>
96+
<item>cz</item>
97+
<item>hk</item>
98+
<item>ru</item>
99+
<item>sg</item>
100+
<item>za</item>
101+
<item>se</item>
102+
<item>ch</item>
103+
<item>tw</item>
104+
<item>tr</item>
105+
<item>ua</item>
106+
<item>us</item>
107+
<item>ve</item>
108+
</string-array>
109+
<string-array name="entries_region_preference">
110+
<item>Deutschland</item> <!-- Germany -->
111+
<item>المملكة العربية السعودية</item> <!-- Saudi Arabia -->
112+
<item>الجزائر</item> <!-- Algeria -->
113+
<item>Argentina</item> <!-- Argentina (Spanish) -->
114+
<item>Australia</item> <!-- Australia (English) -->
115+
<item>Österreich</item> <!-- Austria -->
116+
<item>België</item> <!-- Belgium (Dutch) -->
117+
<item>Беларусь</item> <!-- Belarus -->
118+
<item>Brasil</item> <!-- Brazil (Portuguese) -->
119+
<item>Chile</item> <!-- Chile (Spanish) -->
120+
<item>中国</item> <!-- China (Simplified Chinese) -->
121+
<item>Colombia</item> <!-- Colombia (Spanish) -->
122+
<item>대한민국</item> <!-- South Korea -->
123+
<item>Danmark</item> <!-- Denmark -->
124+
<item>مصر</item> <!-- Egypt -->
125+
<item>دولة الإمارات العربية المتحدة</item> <!-- United Arab Emirates -->
126+
<item>Slovenija</item> <!-- Slovenia -->
127+
<item>España</item> <!-- Spain (Spanish) -->
128+
<item>Pilipinas</item> <!-- Philippines (Filipino) -->
129+
<item>Suomi</item> <!-- Finland -->
130+
<item>France</item> <!-- France (French) -->
131+
<item>Ελλάδα</item> <!-- Greece -->
132+
<item>Magyarország</item> <!-- Hungary -->
133+
<item>भारत</item> <!-- India (Hindi) -->
134+
<item>Indonesia</item> <!-- Indonesia -->
135+
<item>ایران</item> <!-- Iran -->
136+
<item>Éire</item> <!-- Ireland (Irish) -->
137+
<item>ישראל</item> <!-- Israel (Hebrew) -->
138+
<item>Italia</item> <!-- Italy -->
139+
<item>日本</item> <!-- Japan -->
140+
<item>México</item> <!-- Mexico (Spanish) -->
141+
<item>Nigeria</item> <!-- Nigeria (English) -->
142+
<item>Norge</item> <!-- Norway -->
143+
<item>New Zealand</item> <!-- New Zealand (English) -->
144+
<item>Nederland</item> <!-- Netherlands -->
145+
<item>پاکستان</item> <!-- Pakistan (Urdu) -->
146+
<item>Perú</item> <!-- Peru (Spanish) -->
147+
<item>Polska</item> <!-- Poland -->
148+
<item>Portugal</item> <!-- Portugal -->
149+
<item>United Kingdom</item> <!-- United Kingdom (English) -->
150+
<item>Česká republika</item> <!-- Czech Republic -->
151+
<item>香港</item> <!-- Hong Kong (Chinese) -->
152+
<item>Россия</item> <!-- Russia -->
153+
<item>Singapore</item> <!-- Singapore (English) -->
154+
<item>South Africa</item> <!-- South Africa (English, many official languages) -->
155+
<item>Sverige</item> <!-- Sweden -->
156+
<item>Schweiz</item> <!-- Switzerland (German) -->
157+
<item>臺灣</item> <!-- Taiwan -->
158+
<item>Türkiye</item> <!-- Turkey -->
159+
<item>Україна</item> <!-- Ukraine -->
160+
<item>USA / Canada</item> <!-- USA/Canada (English) -->
161+
<item>Venezuela</item> <!-- Venezuela (Spanish) -->
162+
</string-array>
56163
</resources>

app/src/main/res/values/strings.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@
4242
<string name="pref_enable_blocking_title">Enable Blocking</string>
4343
<string name="pref_enable_blocking_summary">Enable or disable call blocking functionality</string>
4444

45-
<!-- Spam Number Filters -->
46-
<string name="pref_filter_lista_spam_title">API unknownphone.com</string>
45+
<!-- API Unknownphone -->
46+
<string name="pref_filter_lista_spam_title">API Unknownphone</string>
4747
<string name="pref_filter_lista_spam_summary">[🌐] (Recommended) Blocks calls from spam numbers listed in unknownphone.com API</string>
4848

4949
<string name="pref_filter_lista_spam_api_language_title">unknownphone.com API Language</string>
5050
<string name="pref_filter_lista_spam_api_language_summary">Select the language for searches in the unknownphone.com API (affects results)</string>
5151

52+
<!-- API Tellows -->
53+
<string name="pref_filter_tellows_title">Tellows API</string>
54+
<string name="pref_filter_tellows_summary">[🌐] (Recommended) Blocks calls from spam numbers listed in the Tellows API</string>
55+
56+
<string name="pref_filter_tellows_api_country_title">Tellows API Country</string>
57+
<string name="pref_filter_tellows_api_country_summary">Select the country for searches in the Tellows API (affects results)</string>
58+
59+
<!-- Spam Number Filters -->
5260
<string name="pref_filter_lista_spam_scraper_title">listaspam.com Scraper</string>
5361
<string name="pref_filter_lista_spam_scraper_summary">[🇪🇸] (Deprecated) Blocks calls from spam numbers listed on listaspam.es website</string>
5462

0 commit comments

Comments
 (0)