Skip to content

Commit

Permalink
SMS Retriever: Handle SMS without sender number (#2325)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaVinci9196 committed Apr 29, 2024
1 parent 4b96074 commit 85571d9
Showing 1 changed file with 5 additions and 3 deletions.
Expand Up @@ -16,6 +16,7 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.database.Cursor
import android.os.*
import android.os.Build.VERSION.SDK_INT
import android.provider.ContactsContract
Expand Down Expand Up @@ -296,19 +297,20 @@ class SmsRetrieverCore(private val context: Context, override val lifecycle: Lif
}

val normalizePhoneNumber = normalizePhoneNumber(phoneNumber)
val cursor = context.contentResolver.query(Phone.CONTENT_URI, arrayOf(Phone.NUMBER), null, null, null) ?: return false
var cursor: Cursor? = null
try {
cursor = context.contentResolver.query(Phone.CONTENT_URI, arrayOf(Phone.NUMBER), null, null, null) ?: return false
while (cursor.moveToNext()) {
val addressIndex = cursor.getColumnIndex(Phone.NUMBER)
val contactPhoneNumber = normalizePhoneNumber(cursor.getString(addressIndex))
if (normalizePhoneNumber == contactPhoneNumber) {
if (!TextUtils.isEmpty(normalizePhoneNumber) && !TextUtils.isEmpty(contactPhoneNumber) && normalizePhoneNumber == contactPhoneNumber) {
return true
}
}
} catch (e: Exception) {
Log.w(TAG, e)
} finally {
cursor.close()
cursor?.close()
}
return false
}
Expand Down

0 comments on commit 85571d9

Please sign in to comment.