Commit 329d1be0 by zhangchengbo

fix:根据对话内容检测,对号码进行脱敏操作

parent 5529f9d4
...@@ -99,17 +99,17 @@ class MainActivity : SimpleActivity() { ...@@ -99,17 +99,17 @@ class MainActivity : SimpleActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
/* ensureBackgroundThread { /* ensureBackgroundThread {
val allConversations = conversationsDB.getNonArchived() val allConversations = conversationsDB.getNonArchived()
if(allConversations.isEmpty()) return@ensureBackgroundThread if(allConversations.isEmpty()) return@ensureBackgroundThread
com.secspace.log.Log.d(TAG, "获取所有 是否是顺丰号码 = ${allConversations[0].isSFNumber} 是否包含 isContains = ${allConversations[0].snippet.contains("\u200B")}") com.secspace.log.Log.d(TAG, "获取所有 是否是顺丰号码 = ${allConversations[0].isSFNumber} 是否包含 isContains = ${allConversations[0].snippet.contains("\u200B")}")
val results: Conversation = allConversations.last() val results: Conversation = allConversations.last()
com.secspace.log.Log.d(TAG, "获取最后一条body = ${GsonUtil.parseBeanToJson(results)}") com.secspace.log.Log.d(TAG, "获取最后一条body = ${GsonUtil.parseBeanToJson(results)}")
}*/ }*/
//是否拥有通知使用权 //是否拥有通知使用权
val result = isNotificationAccessEnabled() val result = isNotificationAccessEnabled()
if(!result){ if (!result) {
val intent = Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS") val intent = Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS")
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent) startActivity(intent)
...@@ -462,20 +462,20 @@ class MainActivity : SimpleActivity() { ...@@ -462,20 +462,20 @@ class MainActivity : SimpleActivity() {
if (phoneNumber.length < 11) return if (phoneNumber.length < 11) return
if (!firstConversation.isSFNumber) { if (!firstConversation.isSFNumber) {
// Log.d(TAG, "----MainActivity----获取第一条会话手机号 phoneNumber:$phoneNumber") // Log.d(TAG, "----MainActivity----获取第一条会话手机号 phoneNumber:$phoneNumber")
RecentsHelper(context = this@MainActivity).getRecentCalls(false, Int.MAX_VALUE) { recents: List<RecentCall> -> RecentsHelper(context = this@MainActivity).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, "----MainActivity----最近通话记录列表 :${GsonUtil.parseListToJson(listCallRecent)}") Log.d(TAG, "----MainActivity----最近通话记录列表 :${GsonUtil.parseListToJson(listCallRecent)}")
val findResult: RecentCall? = listCallRecent.firstOrNull { it.phoneNumber.replace(" ", "") == phoneNumber && it.isShunFeng } val findResult: RecentCall? = listCallRecent.firstOrNull { it.phoneNumber.replace(" ", "") == phoneNumber && it.isShunFeng }
Log.d(TAG, "----MainActivity----是否从通话记录中查找到电话号Result:${findResult != null}") Log.d(TAG, "----MainActivity----是否从通话记录中查找到电话号Result:${findResult != null}")
//从最近通话记录中找到了号码 进行掩码操作 //从最近通话记录中找到了号码 进行掩码操作
if (findResult != null) { if (findResult != null) {
PhoneUtils.phoneNumberFormat(phoneNumber) { itNumber -> PhoneUtils.phoneNumberFormat(phoneNumber) { itNumber ->
firstConversation.phoneNumber = itNumber firstConversation.phoneNumber = itNumber
firstConversation.isSFNumber = true firstConversation.isSFNumber = true
}
} }
} }
} }
}
//根据最新的短信threadId 获取所有短信列表 取最新一条记录 //根据最新的短信threadId 获取所有短信列表 取最新一条记录
val messages: java.util.ArrayList<Message> = getMessages(firstConversation.threadId, true) val messages: java.util.ArrayList<Message> = getMessages(firstConversation.threadId, true)
...@@ -484,6 +484,13 @@ class MainActivity : SimpleActivity() { ...@@ -484,6 +484,13 @@ class MainActivity : SimpleActivity() {
val lastMsg = messages.last() val lastMsg = messages.last()
firstConversation.snippet = lastMsg.body firstConversation.snippet = lastMsg.body
firstConversation.date = lastMsg.date firstConversation.date = lastMsg.date
val listContains: List<String> = messages.map { it.body }.filter { it.contains("\u200B") }
Log.d(TAG, "sendNormalMessage: 该对话是否有包含零宽字符 = ${listContains.isNotEmpty()}")
if (listContains.isNotEmpty()) {
firstConversation.isSFNumber = true
Log.d(TAG, "sendNormalMessage: last body = ${GsonUtil.parseBeanToJson(conversationsDB.getNonArchived().last())}")
}
// Log.d(TAG, " MainActivity getMessages() firstConversation 数据库 =:${GsonUtil.parseBeanToJson(firstConversation)} ") // Log.d(TAG, " MainActivity getMessages() firstConversation 数据库 =:${GsonUtil.parseBeanToJson(firstConversation)} ")
conversationsDB.insertOrUpdate(firstConversation) conversationsDB.insertOrUpdate(firstConversation)
......
...@@ -1367,53 +1367,19 @@ class ThreadActivity : SimpleActivity() { ...@@ -1367,53 +1367,19 @@ class ThreadActivity : SimpleActivity() {
private fun sendNormalMessage(text: String, subscriptionId: Int) { private fun sendNormalMessage(text: String, subscriptionId: Int) {
val addresses = participants.getAddresses() val addresses = participants.getAddresses()
// android.util.Log.d(TAG, "sendNormalMessage: addresses = $addresses")
val attachments = buildMessageAttachments() val attachments = buildMessageAttachments()
try { try {
refreshedSinceSent = false refreshedSinceSent = false
sendMessageCompat(text, addresses, subscriptionId, attachments, messageToResend) sendMessageCompat(text, addresses, subscriptionId, attachments, messageToResend)
ensureBackgroundThread { ensureBackgroundThread {
val messageIds = messages.map { it.id } val messageIds = messages.map { it.id }
// android.util.Log.d(TAG, "sendNormalMessage: messageIds = $messageIds threadId = $threadId ")
val messages: List<Message> = getMessages(threadId, getImageResolutions = true, limit = maxOf(1, attachments.size)) val messages: List<Message> = getMessages(threadId, getImageResolutions = true, limit = maxOf(1, attachments.size))
.filter { it.id !in messageIds } .filter { it.id !in messageIds }
// android.util.Log.d(TAG, "sendNormalMessage: body = ${GsonUtil.parseListToJson(messages)}")
for (message in messages) { for (message in messages) {
// message.body = "${message.body} \u200B"
// android.util.Log.d(TAG, "sendNormalMessage: body = ${message.body} isContains = ${message.body.contains("\u200B")}")
insertOrUpdateMessage(message) insertOrUpdateMessage(message)
val listContains: List<String> = this.messages.map { it.body }.filter { it.contains("\u200B") }
// android.util.Log.d(TAG, "sendNormalMessage: 该对话是否有包含零宽字符 = ${listContains.isNotEmpty()}")
if (listContains.isNotEmpty()) {
val allConversation = conversationsDB.getNonArchived()
val lastConversation = allConversation.last()
lastConversation.snippet = "${message.body} \u200B \u200C \u200D "
lastConversation.isSFNumber = true
lastConversation.threadId = message.threadId
val id = conversationsDB.insertOrUpdate(lastConversation)
android.util.Log.d(TAG, "sendNormalMessage: message.threadId = ${message.threadId} id = $id")
// android.util.Log.d(TAG, "sendNormalMessage: last body = ${GsonUtil.parseBeanToJson(conversationsDB.getNonArchived().last())}")
}
} }
val allConversation = conversationsDB.getNonArchived()
val lastConversation = allConversation.last()
lastConversation.snippet = "测试内容 body \u200B \u200C \u200D"
lastConversation.isSFNumber = true
// lastConversation.threadId = message.threadId
val id = conversationsDB.insertOrUpdate(lastConversation)
android.util.Log.d(TAG, "sendNormalMessage: id = $id")
android.util.Log.d(TAG, "sendNormalMessage: last body = ${GsonUtil.parseBeanToJson(conversationsDB.getNonArchived().last())}")
} }
clearCurrentMessage() clearCurrentMessage()
} catch (e: Exception) { } catch (e: Exception) {
showErrorToast(e) showErrorToast(e)
} catch (e: Error) { } catch (e: Error) {
......
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