Store anonymized call numbers in shared preferences
This commit is contained in:
parent
fc3f6c58ce
commit
079bbb20f5
1 changed files with 29 additions and 7 deletions
|
@ -61,7 +61,9 @@ class CallRedirectionService : CallRedirectionService() {
|
|||
initialPhoneAccount: PhoneAccountHandle,
|
||||
allowInteractiveResponse: Boolean,
|
||||
) {
|
||||
Log.d("Redirection", "onPlaceCall triggered: uri=$handle, interactive=$allowInteractiveResponse")
|
||||
val phoneNumber = handle.schemeSpecificPart
|
||||
val numberAlias = getAnonymizedAlias(phoneNumber)
|
||||
Log.d("Redirection", "onPlaceCall triggered: alias=$numberAlias, interactive=$allowInteractiveResponse")
|
||||
|
||||
val capabilities = connectivityManager
|
||||
?.getNetworkCapabilities(connectivityManager?.activeNetwork)
|
||||
|
@ -100,10 +102,6 @@ class CallRedirectionService : CallRedirectionService() {
|
|||
return
|
||||
}
|
||||
|
||||
val phoneNumber = handle.schemeSpecificPart
|
||||
val numberAlias = getAnonymizedNumberAlias(phoneNumber)
|
||||
Log.d("Redirection", "Processing call to: $numberAlias")
|
||||
|
||||
if (prefs.redirectInternationalOnly && !isInternationalNumber(phoneNumber)) {
|
||||
Log.d("Redirection", "Aborting: number $numberAlias is not international and pref requires it")
|
||||
placeCallUnmodified()
|
||||
|
@ -115,6 +113,8 @@ class CallRedirectionService : CallRedirectionService() {
|
|||
placeCallUnmodified()
|
||||
return
|
||||
}
|
||||
|
||||
Log.d("Redirection", "Number $numberAlias is not in filters, processing redirection...")
|
||||
|
||||
val records: Array<Record>
|
||||
try {
|
||||
|
@ -201,8 +201,30 @@ class CallRedirectionService : CallRedirectionService() {
|
|||
}
|
||||
|
||||
private fun getAnonymizedAlias(number: String): String {
|
||||
val contactId = getContactIdByPhoneNumber(number)
|
||||
return if (contactId != null) "#$contactId" else "#???"
|
||||
val prefs = getSharedPreferences("anonymized_numbers", MODE_PRIVATE)
|
||||
|
||||
// Return existing alias if already mapped
|
||||
val existing = prefs.getString(number, null)
|
||||
if (existing != null) return existing
|
||||
|
||||
// Start from current counter
|
||||
var counter = prefs.getInt("counter", 1)
|
||||
var alias: String
|
||||
|
||||
// Find the first unused alias (safety check)
|
||||
while (true) {
|
||||
alias = "#$counter"
|
||||
if (!prefs.all.containsValue(alias)) break
|
||||
counter++
|
||||
}
|
||||
|
||||
// Store new alias and increment counter
|
||||
prefs.edit()
|
||||
.putString(number, alias)
|
||||
.putInt("counter", counter + 1)
|
||||
.apply()
|
||||
|
||||
return alias
|
||||
}
|
||||
|
||||
private fun isInternationalNumber(phoneNumber: String): Boolean {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue