Commit 0b271619 by zhangchengbo

fix:1.手机号检测+86并替换 2.针对掩码手机号更改顺丰标识(之前非掩码号也更改了顺丰标识)

parent 20b6b94d
...@@ -56,7 +56,7 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -56,7 +56,7 @@ class SmsReceiver : BroadcastReceiver() {
val blockedNumberList = context.getBlockedNumbers().map { it.number } val blockedNumberList = context.getBlockedNumbers().map { it.number }
Log.d(TAG, "onReceive: 黑名单列表 = ${Gson().toJson(blockedNumberList)}") Log.d(TAG, "onReceive: 黑名单列表 = ${Gson().toJson(blockedNumberList)}")
if(blockedNumberList.contains(address)){ if (blockedNumberList.contains(address)) {
return return
} }
val privateCursor: Cursor? = context.getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true) val privateCursor: Cursor? = context.getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
...@@ -72,7 +72,11 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -72,7 +72,11 @@ class SmsReceiver : BroadcastReceiver() {
} }
if (address.isNotEmpty()) { if (address.isNotEmpty()) {
findConversationWithPhoneNumber(context, address,body,threadId) {phoneNumberResult-> if (address.contains("+86")) {
address = address.replace("+86", "")
}
findConversationWithPhoneNumber(context, address, body, threadId) { phoneNumberResult ->
Log.d(TAG, "onReceive: phoneNumberResult = $phoneNumberResult")
if (context.baseConfig.blockUnknownNumbers) { if (context.baseConfig.blockUnknownNumbers) {
val simpleContactsHelper = SimpleContactsHelper(context) val simpleContactsHelper = SimpleContactsHelper(context)
simpleContactsHelper.exists(address, privateCursor) { exists -> simpleContactsHelper.exists(address, privateCursor) { exists ->
...@@ -97,7 +101,7 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -97,7 +101,7 @@ class SmsReceiver : BroadcastReceiver() {
* 1.先从短信DB库查找 * 1.先从短信DB库查找
* 2.未找到再从 通话记录中查找 * 2.未找到再从 通话记录中查找
*/ */
private fun findConversationWithPhoneNumber(context: Context, phoneNumber: String,body :String,threadId: Long,confirmCallBack: (String) -> Unit) { private fun findConversationWithPhoneNumber(context: Context, phoneNumber: String, body: String, threadId: Long, confirmCallBack: (String) -> Unit) {
var lastNumber = "" var lastNumber = ""
Log.d(TAG, "SmsReceiver phoneNumber:${phoneNumber} body = $body threadId = $threadId") Log.d(TAG, "SmsReceiver phoneNumber:${phoneNumber} body = $body threadId = $threadId")
val hasPerMissionResult = context.hasPermission(PERMISSION_READ_CALL_LOG) val hasPerMissionResult = context.hasPermission(PERMISSION_READ_CALL_LOG)
...@@ -113,41 +117,22 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -113,41 +117,22 @@ class SmsReceiver : BroadcastReceiver() {
} }
} }
} }
/* val allConversations = context.conversationsDB.getNonArchived() as ArrayList<Conversation>
Log.d(TAG, "SmsReceiver handleMessage allConversations:${GsonUtil.parseListToJson(allConversations)}")
if(allConversations.isNotEmpty()){
val listConversation: List<Conversation> = allConversations.filter {
Log.d(TAG, "SmsReceiver 短信内容相等 = ${it.threadId == threadId && it.isSFNumber }")
it.threadId == threadId && it.isSFNumber
}
Log.d(TAG, "findConversationWithPhoneNumber listConversation = $listConversation")
if (listConversation.isNotEmpty()) {
lastNumber = listConversation.first().title
}
}*/
//2 //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)}")
if (listCallRecent.isNotEmpty()) {
val findResult = listCallRecent.filter { it.isShunFeng }.count { val findResult = listCallRecent.filter { it.isShunFeng }.count {
Log.d(TAG, "SmsReceiver findResult isNumber = ${PhoneFromUtil.isNumeric(it.phoneNumber)}") Log.d(TAG, "SmsReceiver findResult isNumber = ${PhoneFromUtil.isNumeric(it.phoneNumber)}")
if (PhoneFromUtil.isNumeric(it.phoneNumber)) { if (PhoneFromUtil.isNumeric(it.phoneNumber)) {
if(phoneNumber.contains("+86")){
it.phoneNumber == phoneNumber.replace("+86","")
}else{
it.phoneNumber == phoneNumber it.phoneNumber == phoneNumber
}
} else { } else {
if(phoneNumber.contains("+86")) {
AES.decrypt(it.phoneNumber) == phoneNumber.replace("+86","")
}else{
AES.decrypt(it.phoneNumber) == phoneNumber AES.decrypt(it.phoneNumber) == phoneNumber
} }
} }
}
Log.d(TAG, "SmsReceiverfindResult:${findResult} phoneNumber = ${phoneNumber.trim()}") Log.d(TAG, "SmsReceiverfindResult:${findResult} phoneNumber = ${phoneNumber.trim()}")
//从最近通话记录中找到了号码 进行掩码操作 //从最近通话记录中找到了号码 进行掩码操作
if (findResult > 0) { if (findResult > 0) {
...@@ -157,6 +142,7 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -157,6 +142,7 @@ class SmsReceiver : BroadcastReceiver() {
} }
} }
} }
}
Log.d(TAG, "SmsReceiver lastNumber = $lastNumber") Log.d(TAG, "SmsReceiver lastNumber = $lastNumber")
} }
if (lastNumber == "") { if (lastNumber == "") {
...@@ -190,8 +176,6 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -190,8 +176,6 @@ class SmsReceiver : BroadcastReceiver() {
var notificationUserName = ""//通讯录如果有备注则优先展示备注,其次手机号 var notificationUserName = ""//通讯录如果有备注则优先展示备注,其次手机号
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
if (!context.isNumberBlocked(address)) { if (!context.isNumberBlocked(address)) {
val privateCursor = context.getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true) val privateCursor = context.getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
ensureBackgroundThread { ensureBackgroundThread {
...@@ -199,10 +183,10 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -199,10 +183,10 @@ class SmsReceiver : BroadcastReceiver() {
//最新消息会话 必须在insertNewSMS 后获取,否则读取的read状态不生效 //最新消息会话 必须在insertNewSMS 后获取,否则读取的read状态不生效
val conversation: Conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread val conversation: Conversation = context.getConversations(threadId).firstOrNull() ?: return@ensureBackgroundThread
Log.d(TAG, "handleMessage: conversation toJson = ${Gson().toJson(conversation)} ") Log.d(TAG, "handleMessage: conversation toJson = ${Gson().toJson(conversation)} ")
if(!PhoneFromUtil.isNumeric(conversation.userName)){ if (!PhoneFromUtil.isNumeric(conversation.userName)) {
notificationUserName = conversation.userName notificationUserName = conversation.userName
} }
if (aesPhoneNumber.isNotBlank() || body.contains("\u200B")) { if (!aesPhoneNumber.isPhoneNumber() || aesPhoneNumber.contains("*") || body.contains("\u200B") ) {
conversation.title = aesPhoneNumber conversation.title = aesPhoneNumber
conversation.isSFNumber = true conversation.isSFNumber = true
} }
...@@ -243,10 +227,13 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -243,10 +227,13 @@ class SmsReceiver : BroadcastReceiver() {
context.updateConversationArchivedStatus(threadId, false) context.updateConversationArchivedStatus(threadId, false)
} }
refreshMessages() refreshMessages()
Log.d(TAG, "handleMessage: notificationUserName = $notificationUserName aesPhoneNumber = $aesPhoneNumber address = $address") Log.d(
if(notificationUserName.isNotEmpty()){ TAG,
"handleMessage: notificationUserName = $notificationUserName aesPhoneNumber = $aesPhoneNumber address = $address threadId = $threadId"
)
if (notificationUserName.isNotEmpty()) {
context.showReceivedMessageNotification(newMessageId, notificationUserName, body, threadId, bitmap) context.showReceivedMessageNotification(newMessageId, notificationUserName, body, threadId, bitmap)
}else if (aesPhoneNumber.isNotBlank()) { } else if (!aesPhoneNumber.isPhoneNumber() || aesPhoneNumber.contains("*")) {
context.showReceivedMessageNotification(newMessageId, aesPhoneNumber, 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)
...@@ -256,18 +243,15 @@ class SmsReceiver : BroadcastReceiver() { ...@@ -256,18 +243,15 @@ class SmsReceiver : BroadcastReceiver() {
Log.d(TAG, "SmsReceiver aesPhoneNumber 手机号是否加密 :${aesPhoneNumber}") Log.d(TAG, "SmsReceiver aesPhoneNumber 手机号是否加密 :${aesPhoneNumber}")
Log.d(TAG, "SmsReceiver: notificationUserName = $notificationUserName aesPhoneNumber = $aesPhoneNumber address = $address") Log.d(TAG, "SmsReceiver: notificationUserName = $notificationUserName aesPhoneNumber = $aesPhoneNumber address = $address")
if(notificationUserName.isNotEmpty()){ if (notificationUserName.isNotEmpty()) {
val tipPopup = MyPushWindow(context, notificationUserName, body) val tipPopup = MyPushWindow(context, notificationUserName, body)
tipPopup.show() tipPopup.show()
}else if (aesPhoneNumber.isNotBlank()) { } else if (aesPhoneNumber.isNotBlank()) {
val tipPopup = MyPushWindow(context, aesPhoneNumber, body) val tipPopup = MyPushWindow(context, aesPhoneNumber, body)
tipPopup.show() tipPopup.show()
} else { } else {
Log.d(TAG, "SmsReceiver 短信内容 = ${body} address = $address ") Log.d(TAG, "SmsReceiver 短信内容 = $body address = $address ")
if (body.contains("\u200B")) { if (body.contains("\u200B")) {
if (address.contains("+86")) {
address.replace("+86", "")
}
PhoneUtils.phoneNumberFormat(address) { itNumber -> PhoneUtils.phoneNumberFormat(address) { itNumber ->
val tipPopup = MyPushWindow(context, itNumber, body) val tipPopup = MyPushWindow(context, itNumber, body)
tipPopup.show() tipPopup.show()
......
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