Commit 962721e4 by zhangchengbo

fix:只对会话Conversation-title显示进行脱敏操作,优化代码

parent 8af9c605
...@@ -17,6 +17,8 @@ import com.secspace.sms.models.Conversation ...@@ -17,6 +17,8 @@ import com.secspace.sms.models.Conversation
import com.secspace.sms.models.Message import com.secspace.sms.models.Message
import com.secspace.sms.models.RecentCall import com.secspace.sms.models.RecentCall
import com.secspace.sms.popup.MyPushWindow import com.secspace.sms.popup.MyPushWindow
import com.secspace.sms.util.AES
import com.secspace.sms.util.PhoneFromUtil
import com.secspace.sms.util.PhoneUtils import com.secspace.sms.util.PhoneUtils
import com.secspace.sms.util.SmsCountUtil import com.secspace.sms.util.SmsCountUtil
import com.simplemobiletools.commons.extensions.baseConfig import com.simplemobiletools.commons.extensions.baseConfig
...@@ -28,11 +30,10 @@ import com.simplemobiletools.commons.helpers.SimpleContactsHelper ...@@ -28,11 +30,10 @@ import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.PhoneNumber import com.simplemobiletools.commons.models.PhoneNumber
import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.commons.models.SimpleContact
import com.simplemobiletools.commons.util.GsonUtil
class SmsReceiver : BroadcastReceiver() { class SmsReceiver : BroadcastReceiver() {
private val TAG: String = "shuju" private val TAG: String = "SmsReceiver"
private var lastNumber = ""
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
...@@ -64,13 +65,13 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -64,13 +65,13 @@ class SmsReceiver : BroadcastReceiver() {
val simpleContactsHelper = SimpleContactsHelper(context) val simpleContactsHelper = SimpleContactsHelper(context)
simpleContactsHelper.exists(address, privateCursor) { exists -> simpleContactsHelper.exists(address, privateCursor) { exists ->
if (exists) { if (exists) {
handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status) { handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status, it) {
badgeTotalNumber(context) badgeTotalNumber(context)
} }
} }
} }
} else { } else {
handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status) { handleMessage(context, address, subject, body, date, read, threadId, type, subscriptionId, status, it) {
badgeTotalNumber(context) badgeTotalNumber(context)
} }
} }
...@@ -84,47 +85,47 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -84,47 +85,47 @@ class SmsReceiver : BroadcastReceiver() {
* 1.先从短信DB库查找 * 1.先从短信DB库查找
* 2.未找到再从 通话记录中查找 * 2.未找到再从 通话记录中查找
*/ */
private fun findConversationWithPhoneNumber(context: Context, phoneNumber: String, threadId: Long, confirmCallBack: () -> Unit) { private fun findConversationWithPhoneNumber(context: Context, phoneNumber: String, threadId: Long, confirmCallBack: (String) -> Unit) {
var lastNumber = ""
Log.d(TAG, "----SmsReceiver---- phoneNumber:${phoneNumber} threadId:$threadId") // Log.d(TAG, "----SmsReceiver---- phoneNumber:${phoneNumber} threadId:$threadId")
val hasPerMissionResult = context.hasPermission(PERMISSION_READ_CALL_LOG) val hasPerMissionResult = context.hasPermission(PERMISSION_READ_CALL_LOG)
if (hasPerMissionResult) { if (hasPerMissionResult) {
val allConversations = context.conversationsDB.getNonArchived() as ArrayList<Conversation> val allConversations = context.conversationsDB.getNonArchived() as ArrayList<Conversation>
// Log.d(TAG, "----SmsReceiver----handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}") // Log.d(TAG, "----SmsReceiver----handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}")
//1
allConversations.forEach { allConversations.forEach {
if (it.title.trim() == phoneNumber && it.isSFNumber) { if (it.title.trim() == phoneNumber && it.isSFNumber) {
lastNumber = it.phoneNumber lastNumber = it.phoneNumber
Log.d(TAG, "----SmsReceiver--conversationsDB数据库--lastNumber :$lastNumber")
return@forEach return@forEach
} }
} }
//2
if (lastNumber.isEmpty()) { if (lastNumber.isEmpty()) {
RecentsHelper(context = context).getRecentCalls(false, Int.MAX_VALUE) { recents: List<RecentCall> -> RecentsHelper(context = context).getRecentCalls(false, Int.MAX_VALUE) { recents: List<RecentCall> ->
val listCallRecent: List<RecentCall> = recents.distinctBy { it.phoneNumber } val listCallRecent: List<RecentCall> = recents.distinctBy { it.phoneNumber }
// Log.d(TAG, "----SmsReceiver----最近通话 recents:${GsonUtil.parseListToJson(listCallRecent)}") // Log.d(TAG, "----SmsReceiver----最近通话 recents:${GsonUtil.parseListToJson(listCallRecent)}")
val findResult: Int = listCallRecent.count { it.phoneNumber.trim() == phoneNumber.trim() && it.isShunFeng } val findResult = listCallRecent.filter { it.isShunFeng }.count {
Log.d(TAG, "----SmsReceiver----findResult:${findResult}") // Log.d(TAG, "----SmsReceiver----findResult isNumber = ${PhoneFromUtil.isNumeric(it.phoneNumber)}")
if (PhoneFromUtil.isNumeric(it.phoneNumber)) {
it.phoneNumber == phoneNumber
} else {
AES.decrypt(it.phoneNumber) == phoneNumber
}
}
// Log.d(TAG, "----SmsReceiver----findResult:${findResult} phoneNumber = ${phoneNumber.trim()}")
//从最近通话记录中找到了号码 进行掩码操作 //从最近通话记录中找到了号码 进行掩码操作
if (findResult > 0) { if (findResult > 0) {
PhoneUtils.phoneNumberFormat(phoneNumber) { itNumber -> PhoneUtils.phoneNumberFormat(phoneNumber) { itNumber ->
/* Log.d(
TAG,
"----SmsReceiver----手机号掩码操作 itNumber:${itNumber} threadId:$threadId context.getThreadId:${
context.getThreadId(
phoneNumber
)
}"
)*/
lastNumber = itNumber lastNumber = itNumber
} }
} }
} }
} }
} }
confirmCallBack.invoke() confirmCallBack.invoke(lastNumber)
} }
...@@ -140,6 +141,7 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -140,6 +141,7 @@ class SmsReceiver : BroadcastReceiver() {
type: Int, type: Int,
subscriptionId: Int, subscriptionId: Int,
status: Int, status: Int,
aesPhoneNumber: String,
confirmCallBack: () -> Unit confirmCallBack: () -> Unit
) { ) {
if (isMessageFilteredOut(context, body)) { if (isMessageFilteredOut(context, body)) {
...@@ -155,8 +157,8 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -155,8 +157,8 @@ class SmsReceiver : BroadcastReceiver() {
val conversation: Conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread val conversation: Conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread
if (lastNumber.isNotBlank()) { if (aesPhoneNumber.isNotBlank()) {
conversation.phoneNumber = lastNumber conversation.title = aesPhoneNumber
conversation.isSFNumber = true conversation.isSFNumber = true
} }
// Log.d(TAG, "----SmsReceiver----handleConversation 掩码后的 Json:${GsonUtil.parseBeanToJson(conversation)}") // Log.d(TAG, "----SmsReceiver----handleConversation 掩码后的 Json:${GsonUtil.parseBeanToJson(conversation)}")
...@@ -165,25 +167,20 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -165,25 +167,20 @@ class SmsReceiver : BroadcastReceiver() {
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }
try { val senderName = context.getNameFromAddress(address, privateCursor)
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations()) val phoneNumber = PhoneNumber(address, 0, "", address)
} catch (ignored: Exception) {
}
var senderName = context.getNameFromAddress(address, privateCursor) /*if (aesPhoneNumber.isNotBlank()) {
var phoneNumber = PhoneNumber(address, 0, "", address) senderName = context.getNameFromAddress(aesPhoneNumber, privateCursor)
phoneNumber = PhoneNumber(aesPhoneNumber, 0, "", aesPhoneNumber)
if (lastNumber.isNotBlank()) { }*/
senderName = context.getNameFromAddress(lastNumber, privateCursor)
phoneNumber = PhoneNumber(lastNumber, 0, "", lastNumber)
}
val participant = SimpleContact(0, 0, senderName, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList()) val participant = SimpleContact(0, 0, senderName, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList())
val participants = arrayListOf(participant) val participants = arrayListOf(participant)
val messageDate = (date / 1000).toInt() val messageDate = (date / 1000).toInt()
var message = val message =
Message( Message(
newMessageId, newMessageId,
body, body,
...@@ -200,7 +197,7 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -200,7 +197,7 @@ class SmsReceiver : BroadcastReceiver() {
photoUri, photoUri,
subscriptionId subscriptionId
) )
if (lastNumber.isNotBlank()) { /*if (aesPhoneNumber.isNotBlank()) {
message = message =
Message( Message(
newMessageId, newMessageId,
...@@ -213,20 +210,20 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -213,20 +210,20 @@ class SmsReceiver : BroadcastReceiver() {
threadId, threadId,
false, false,
null, null,
lastNumber, aesPhoneNumber,
senderName, senderName,
photoUri, photoUri,
subscriptionId subscriptionId
) )
} }*/
// Log.d(TAG, "----SmsReceiver----handleMessage message:${GsonUtil.parseBeanToJson(message)}") // Log.d(TAG, "----SmsReceiver----handleMessage message:${GsonUtil.parseBeanToJson(message)}")
context.messagesDB.insertOrUpdate(message) context.messagesDB.insertOrUpdate(message)
if (context.config.isArchiveAvailable) { if (context.config.isArchiveAvailable) {
context.updateConversationArchivedStatus(threadId, false) context.updateConversationArchivedStatus(threadId, false)
} }
refreshMessages() refreshMessages()
if (lastNumber.isNotBlank()) { if (aesPhoneNumber.isNotBlank()) {
context.showReceivedMessageNotification(newMessageId, lastNumber, body, threadId, bitmap) context.showReceivedMessageNotification(newMessageId, aesPhoneNumber, body, threadId, bitmap)
} else { } else {
context.showReceivedMessageNotification(newMessageId, address, body, threadId, bitmap) context.showReceivedMessageNotification(newMessageId, address, body, threadId, bitmap)
...@@ -234,15 +231,14 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -234,15 +231,14 @@ class SmsReceiver : BroadcastReceiver() {
} }
} }
if (lastNumber.isNotBlank()) { if (aesPhoneNumber.isNotBlank()) {
val tipPopup = MyPushWindow(context, lastNumber, body) val tipPopup = MyPushWindow(context, aesPhoneNumber, body)
tipPopup.show() tipPopup.show()
} else { } else {
val tipPopup = MyPushWindow(context, address, body) val tipPopup = MyPushWindow(context, address, body)
tipPopup.show() tipPopup.show()
} }
} }
lastNumber = ""
confirmCallBack.invoke() confirmCallBack.invoke()
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment