Anonymized phone number logging

This commit is contained in:
partisan 2025-06-05 09:11:05 +02:00
parent 09de3785b9
commit fc3f6c58ce

View file

@ -101,16 +101,17 @@ class CallRedirectionService : CallRedirectionService() {
} }
val phoneNumber = handle.schemeSpecificPart val phoneNumber = handle.schemeSpecificPart
Log.d("Redirection", "Resolved phone number: $phoneNumber") val numberAlias = getAnonymizedNumberAlias(phoneNumber)
Log.d("Redirection", "Processing call to: $numberAlias")
if (prefs.redirectInternationalOnly && !isInternationalNumber(phoneNumber)) { if (prefs.redirectInternationalOnly && !isInternationalNumber(phoneNumber)) {
Log.d("Redirection", "Aborting: number is not international and pref requires it") Log.d("Redirection", "Aborting: number $numberAlias is not international and pref requires it")
placeCallUnmodified() placeCallUnmodified()
return return
} }
if (prefs.isBlacklistEnabled && !prefs.isContactWhitelisted(phoneNumber)) { if (prefs.isBlacklistEnabled && !prefs.isContactWhitelisted(phoneNumber)) {
Log.d("Redirection", "Aborting: number is not in whitelist while blacklist is enabled") Log.d("Redirection", "Aborting: number $numberAlias is not in whitelist while blacklist is enabled")
placeCallUnmodified() placeCallUnmodified()
return return
} }
@ -118,7 +119,7 @@ class CallRedirectionService : CallRedirectionService() {
val records: Array<Record> val records: Array<Record>
try { try {
records = getRecordsFromPhoneNumber(phoneNumber) records = getRecordsFromPhoneNumber(phoneNumber)
Log.d("Redirection", "Found ${records.size} raw records for contact") Log.d("Redirection", "Found ${records.size} raw redirect apps for number $numberAlias")
} catch (exc: SecurityException) { } catch (exc: SecurityException) {
Log.w("Redirection", "SecurityException during record fetch", exc) Log.w("Redirection", "SecurityException during record fetch", exc)
placeCallUnmodified() placeCallUnmodified()
@ -129,11 +130,11 @@ class CallRedirectionService : CallRedirectionService() {
.filter { prefs.isServiceEnabled(it.mimetype) } .filter { prefs.isServiceEnabled(it.mimetype) }
.sortedBy { prefs.getServicePriority(it.mimetype) } .sortedBy { prefs.getServicePriority(it.mimetype) }
Log.d("Redirection", "Filtered to ${enabledRecords.size} enabled records") Log.d("Redirection", "Filtered to ${enabledRecords.size} enabled redirect apps")
val record = enabledRecords.firstOrNull() val record = enabledRecords.firstOrNull()
if (record == null) { if (record == null) {
Log.d("Redirection", "Aborting: no suitable record found for redirection") Log.d("Redirection", "Aborting: no suitable redirect apps found for number $numberAlias")
placeCallUnmodified() placeCallUnmodified()
return return
} }
@ -199,6 +200,11 @@ class CallRedirectionService : CallRedirectionService() {
return results.toTypedArray() return results.toTypedArray()
} }
private fun getAnonymizedAlias(number: String): String {
val contactId = getContactIdByPhoneNumber(number)
return if (contactId != null) "#$contactId" else "#???"
}
private fun isInternationalNumber(phoneNumber: String): Boolean { private fun isInternationalNumber(phoneNumber: String): Boolean {
val telephony = getSystemService(TelephonyManager::class.java) ?: return true val telephony = getSystemService(TelephonyManager::class.java) ?: return true
val simCountryIso = telephony.simCountryIso?.lowercase() ?: return true val simCountryIso = telephony.simCountryIso?.lowercase() ?: return true