Commit f0f279c4 by zhangchengbo

fix:解决荣耀云备份后恢复,手机号未脱敏的情况

parent 08d0d5c2
...@@ -21,12 +21,10 @@ import com.secspace.sms.adapters.ConversationsAdapter ...@@ -21,12 +21,10 @@ import com.secspace.sms.adapters.ConversationsAdapter
import com.secspace.sms.adapters.SearchResultsAdapter import com.secspace.sms.adapters.SearchResultsAdapter
import com.secspace.sms.databinding.ActivityMainBinding import com.secspace.sms.databinding.ActivityMainBinding
import com.secspace.sms.extensions.* import com.secspace.sms.extensions.*
import com.secspace.sms.helpers.RecentsHelper import com.secspace.sms.helpers.*
import com.secspace.sms.helpers.SEARCHED_MESSAGE_ID
import com.secspace.sms.helpers.THREAD_ID
import com.secspace.sms.helpers.THREAD_TITLE
import com.secspace.sms.models.* import com.secspace.sms.models.*
import com.secspace.sms.receivers.SmsSendObserver import com.secspace.sms.receivers.SmsSendObserver
import com.secspace.sms.util.AES
import com.secspace.sms.util.PhoneFromUtil 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
...@@ -398,18 +396,16 @@ class MainActivity : SimpleActivity() { ...@@ -398,18 +396,16 @@ class MainActivity : SimpleActivity() {
insertOrUpdateConversation(conversation) insertOrUpdateConversation(conversation)
} }
} }
val allConversations = conversationsDB.getNonArchived() as ArrayList<Conversation> val allConversations = conversationsDB.getNonArchived() as ArrayList<Conversation>
// Log.e(TAG, "----MainActivity----handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}") // Log.d(TAG, "getNewConversations allConversations = ${GsonUtil.parseListToJson(allConversations)} ")
setupConversations(allConversations) setupConversations(allConversations)
//未读消息 桌面Icon提示
val listMessage = messagesDB.getAll() val listMessage = messagesDB.getAll()
val readResult = listMessage.count { !it.read } val readResult = listMessage.count { !it.read }
// lifecycleScope.launch(Dispatchers.Main) {
SmsCountUtil.setBadgeNum(this@MainActivity, readResult) SmsCountUtil.setBadgeNum(this@MainActivity, readResult)
config.badgeTotalNumber = readResult config.badgeTotalNumber = readResult
// }
if (config.appRunCount == 1) { if (config.appRunCount == 1) {
conversations.map { it.threadId }.forEach { threadId -> conversations.map { it.threadId }.forEach { threadId ->
...@@ -441,34 +437,15 @@ class MainActivity : SimpleActivity() { ...@@ -441,34 +437,15 @@ class MainActivity : SimpleActivity() {
} }
/** /**
* 1.获取最新短信 与通话记录中对比数据进行掩码操作 * 1.获取最新短信 先于自身message列表查找,检测对话列表(message)是否包含[零宽度字符]
* 2.更新列表最新一条的数据 * 2.message列表找不到的情况下,通话记录中对比数据进行掩码操作
* 3.落库生成记录
*/ */
private fun setFirstConversationAndUpdateData(sortedConversations: ArrayList<Conversation>) { private fun setFirstConversationAndUpdateData(sortedConversations: ArrayList<Conversation>) {
val hasPerMissionResult = this@MainActivity.hasPermission(PERMISSION_READ_CALL_LOG) val hasPerMissionResult = this@MainActivity.hasPermission(PERMISSION_READ_CALL_LOG)
if (hasPerMissionResult && sortedConversations.isNotEmpty()) { if (hasPerMissionResult && sortedConversations.isNotEmpty()) {
val firstConversation = sortedConversations.firstOrNull() ?: return//获取第一条未掩码会话 val firstConversation: Conversation = sortedConversations.firstOrNull() ?: return//获取第一条未掩码会话
Log.d(TAG, " MainActivity firstConversation() 获取第一条会话 =: ${GsonUtil.parseBeanToJson(firstConversation)}") // Log.d(TAG, " MainActivity firstConversation() 获取第一条会话 =: ${GsonUtil.parseBeanToJson(firstConversation)}")
val phoneNumber = firstConversation.title.replace(" ", "")
//只针对手机号
if (phoneNumber.length < 11) return
if (!firstConversation.isSFNumber) {
// Log.d(TAG, "----MainActivity----获取第一条会话手机号 phoneNumber:$phoneNumber")
RecentsHelper(context = this@MainActivity).getRecentCalls(false, Int.MAX_VALUE) { recents: List<RecentCall> ->
val listCallRecent: List<RecentCall> = recents.distinctBy { it.phoneNumber }
// Log.d(TAG, "----MainActivity----最近通话记录列表 :${GsonUtil.parseListToJson(listCallRecent)}")
val findResult: RecentCall? = listCallRecent.firstOrNull { it.phoneNumber.replace(" ", "") == phoneNumber && it.isShunFeng }
// Log.d(TAG, "----MainActivity----是否从通话记录中查找到电话号Result:${findResult != null}")
//从最近通话记录中找到了号码 进行掩码操作
if (findResult != null) {
PhoneUtils.phoneNumberFormat(phoneNumber) { itNumber ->
firstConversation.phoneNumber = itNumber
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,8 +461,8 @@ class MainActivity : SimpleActivity() { ...@@ -484,8 +461,8 @@ class MainActivity : SimpleActivity() {
firstConversation.isSFNumber = true firstConversation.isSFNumber = true
if (lastMsg.senderPhoneNumber.isNotEmpty() && PhoneFromUtil.isNumeric(lastMsg.senderPhoneNumber)) if (lastMsg.senderPhoneNumber.isNotEmpty() && PhoneFromUtil.isNumeric(lastMsg.senderPhoneNumber))
PhoneUtils.phoneNumberFormat(lastMsg.senderPhoneNumber) { PhoneUtils.phoneNumberFormat(lastMsg.senderPhoneNumber) {
firstConversation.phoneNumber = it firstConversation.phoneNumber = AES.encrypt(it)
firstConversation.title = it // firstConversation.title = it
} }
val listMsg = messagesDB.getThreadMessages(lastMsg.threadId) val listMsg = messagesDB.getThreadMessages(lastMsg.threadId)
...@@ -496,8 +473,27 @@ class MainActivity : SimpleActivity() { ...@@ -496,8 +473,27 @@ class MainActivity : SimpleActivity() {
messagesDB.insertOrUpdate(itemBean) messagesDB.insertOrUpdate(itemBean)
} }
// Log.d(TAG, " MainActivity getMessages() lastMsg 数据库 threadId = ${lastMsg.threadId} =:${GsonUtil.parseListToJson(listMsg)} ") // Log.d(TAG, " MainActivity getMessages() lastMsg 数据库 threadId = ${lastMsg.threadId} =:${GsonUtil.parseListToJson(listMsg)} ")
} else {
val phoneNumber = firstConversation.title.replace(" ", "")
//只针对手机号
if (phoneNumber.length < 11) return
if (!firstConversation.isSFNumber) {
// Log.d(TAG, "----MainActivity----获取第一条会话手机号 phoneNumber:$phoneNumber")
RecentsHelper(context = this@MainActivity).getRecentCalls(false, Int.MAX_VALUE) { recents: List<RecentCall> ->
val listCallRecent: List<RecentCall> = recents.distinctBy { it.phoneNumber }
// Log.d(TAG, "----MainActivity----最近通话记录列表 :${GsonUtil.parseListToJson(listCallRecent)}")
val findResult: RecentCall? = listCallRecent.firstOrNull { it.phoneNumber.replace(" ", "") == phoneNumber && it.isShunFeng }
// Log.d(TAG, "----MainActivity----是否从通话记录中查找到电话号Result:${findResult != null}")
//从最近通话记录中找到了号码 进行掩码操作
if (findResult != null) {
PhoneUtils.phoneNumberFormat(phoneNumber) { itNumber ->
firstConversation.phoneNumber = AES.encrypt(itNumber)
firstConversation.isSFNumber = true
}
}
}
}
} }
// Log.d(TAG, " MainActivity getMessages() firstConversation 数据库 =:${GsonUtil.parseBeanToJson(firstConversation)} ")
conversationsDB.insertOrUpdate(firstConversation) conversationsDB.insertOrUpdate(firstConversation)
// Log.d(TAG, " MainActivity getMessages() lastMsg 数据库 =:${GsonUtil.parseBeanToJson(lastMsg)} ") // Log.d(TAG, " MainActivity getMessages() lastMsg 数据库 =:${GsonUtil.parseBeanToJson(lastMsg)} ")
} }
...@@ -512,10 +508,19 @@ class MainActivity : SimpleActivity() { ...@@ -512,10 +508,19 @@ class MainActivity : SimpleActivity() {
setFirstConversationAndUpdateData(sortedConversations) setFirstConversationAndUpdateData(sortedConversations)
//根据记录被删除的会话手机号,从会话列表中判断手机号是否一致,满足就脱敏手机号(为了解决荣耀云备份后恢复,手机号未脱敏的情况)
// Log.d(TAG, "setupConversations listThreadData = ${Constant.listThreadData}")
if (Constant.listThreadData.isNotEmpty()) {
val listConversationData: List<Conversation> = conversations.filter { Constant.listThreadData.contains(it.phoneNumber) }
// Log.d(TAG, "setupConversations 找到被删除的 ListConversation 会话 = ${Gson().toJson(listConversationData)}")
listConversationData.forEach {conversation->
Constant.listThreadData.remove(conversation.phoneNumber)
conversation.isSFNumber = true
conversationsDB.insertOrUpdate(conversation)
}
}
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
// delay(1_000)
// Log.d(TAG, " MainActivity setupConversations() 修改后显示短信列表数据 =: ${GsonUtil.parseListToJson(sortedConversations)}")
// runOnUiThread {
if (cached && config.appRunCount == 1) { if (cached && config.appRunCount == 1) {
// there are no cached conversations on the first run so we show the loading placeholder and progress until we are done loading from telephony // there are no cached conversations on the first run so we show the loading placeholder and progress until we are done loading from telephony
showOrHideProgress(conversations.isEmpty()) showOrHideProgress(conversations.isEmpty())
......
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