Commit 0b271619 by zhangchengbo

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

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