Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Simple-Sms
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangchengbo
Simple-Sms
Commits
0b271619
Commit
0b271619
authored
Feb 10, 2026
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:1.手机号检测+86并替换 2.针对掩码手机号更改顺丰标识(之前非掩码号也更改了顺丰标识)
parent
20b6b94d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
47 deletions
+31
-47
SmsReceiver.kt
...src/main/kotlin/com/secspace/sms/receivers/SmsReceiver.kt
+31
-47
No files found.
app/src/main/kotlin/com/secspace/sms/receivers/SmsReceiver.kt
View file @
0b271619
...
@@ -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,46 +117,28 @@ class SmsReceiver : BroadcastReceiver() {
...
@@ -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
//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
=
listCallRecent
.
filter
{
it
.
isShunFeng
}.
count
{
if
(
listCallRecent
.
isNotEmpty
())
{
Log
.
d
(
TAG
,
"SmsReceiver findResult isNumber = ${PhoneFromUtil.isNumeric(it.phoneNumber)}"
)
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"
)){
if
(
PhoneFromUtil
.
isNumeric
(
it
.
phoneNumber
))
{
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
)
{
PhoneUtils
.
phoneNumberFormat
(
phoneNumber
)
{
itNumber
->
PhoneUtils
.
phoneNumberFormat
(
phoneNumber
)
{
itNumber
->
lastNumber
=
itNumber
lastNumber
=
itNumber
}
}
}
}
}
}
}
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment