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
d2ab1d13
Commit
d2ab1d13
authored
Nov 15, 2024
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:添加通话记录查询是否为顺丰手机号功能
parent
58d4c0a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
14 deletions
+122
-14
SmsReceiver.kt
...src/main/kotlin/com/secspace/sms/receivers/SmsReceiver.kt
+122
-14
No files found.
app/src/main/kotlin/com/secspace/sms/receivers/SmsReceiver.kt
View file @
d2ab1d13
...
@@ -6,19 +6,33 @@ import android.content.Intent
...
@@ -6,19 +6,33 @@ import android.content.Intent
import
android.os.Handler
import
android.os.Handler
import
android.os.Looper
import
android.os.Looper
import
android.provider.Telephony
import
android.provider.Telephony
import
android.util.Log
import
com.secspace.sms.extensions.*
import
com.secspace.sms.extensions.*
import
com.secspace.sms.helpers.RecentsHelper
import
com.secspace.sms.helpers.refreshMessages
import
com.secspace.sms.helpers.refreshMessages
import
com.secspace.sms.models.Conversation
import
com.secspace.sms.models.Message
import
com.secspace.sms.models.Message
import
com.secspace.sms.models.RecentCall
import
com.secspace.sms.util.PhoneUtils
import
com.simplemobiletools.commons.extensions.baseConfig
import
com.simplemobiletools.commons.extensions.baseConfig
import
com.simplemobiletools.commons.extensions.getMyContactsCursor
import
com.simplemobiletools.commons.extensions.getMyContactsCursor
import
com.simplemobiletools.commons.extensions.hasPermission
import
com.simplemobiletools.commons.extensions.isNumberBlocked
import
com.simplemobiletools.commons.extensions.isNumberBlocked
import
com.simplemobiletools.commons.helpers.PERMISSION_READ_CALL_LOG
import
com.simplemobiletools.commons.helpers.SimpleContactsHelper
import
com.simplemobiletools.commons.helpers.SimpleContactsHelper
import
com.simplemobiletools.commons.helpers.ensureBackgroundThread
import
com.simplemobiletools.commons.helpers.ensureBackgroundThread
import
com.simplemobiletools.commons.models.PhoneNumber
import
com.simplemobiletools.commons.models.PhoneNumber
import
com.simplemobiletools.commons.models.SimpleContact
import
com.simplemobiletools.commons.models.SimpleContact
import
com.simplemobiletools.commons.util.GsonUtil
class
SmsReceiver
:
BroadcastReceiver
()
{
class
SmsReceiver
:
BroadcastReceiver
()
{
private
val
TAG
:
String
=
"shuju"
// private var findPhoneNumber = false
private
var
lastNumber
=
""
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
val
messages
=
Telephony
.
Sms
.
Intents
.
getMessagesFromIntent
(
intent
)
val
messages
=
Telephony
.
Sms
.
Intents
.
getMessagesFromIntent
(
intent
)
var
address
=
""
var
address
=
""
var
body
=
""
var
body
=
""
...
@@ -30,7 +44,7 @@ class SmsReceiver : BroadcastReceiver() {
...
@@ -30,7 +44,7 @@ class SmsReceiver : BroadcastReceiver() {
val
read
=
0
val
read
=
0
val
subscriptionId
=
intent
.
getIntExtra
(
"subscription"
,
-
1
)
val
subscriptionId
=
intent
.
getIntExtra
(
"subscription"
,
-
1
)
val
privateCursor
=
context
.
getMyContactsCursor
(
fa
lse
,
true
)
val
privateCursor
=
context
.
getMyContactsCursor
(
fa
voritesOnly
=
false
,
withPhoneNumbersOnly
=
true
)
ensureBackgroundThread
{
ensureBackgroundThread
{
messages
.
forEach
{
messages
.
forEach
{
address
=
it
.
originatingAddress
?:
""
address
=
it
.
originatingAddress
?:
""
...
@@ -41,15 +55,19 @@ class SmsReceiver : BroadcastReceiver() {
...
@@ -41,15 +55,19 @@ class SmsReceiver : BroadcastReceiver() {
threadId
=
context
.
getThreadId
(
address
)
threadId
=
context
.
getThreadId
(
address
)
}
}
if
(
context
.
baseConfig
.
blockUnknownNumbers
)
{
if
(
address
.
isNotEmpty
())
{
val
simpleContactsHelper
=
SimpleContactsHelper
(
context
)
findConversationWithPhoneNumber
(
context
,
address
,
threadId
)
{
simpleContactsHelper
.
exists
(
address
,
privateCursor
)
{
exists
->
if
(
context
.
baseConfig
.
blockUnknownNumbers
)
{
if
(
exists
)
{
val
simpleContactsHelper
=
SimpleContactsHelper
(
context
)
simpleContactsHelper
.
exists
(
address
,
privateCursor
)
{
exists
->
if
(
exists
)
{
handleMessage
(
context
,
address
,
subject
,
body
,
date
,
read
,
threadId
,
type
,
subscriptionId
,
status
)
}
}
}
else
{
handleMessage
(
context
,
address
,
subject
,
body
,
date
,
read
,
threadId
,
type
,
subscriptionId
,
status
)
handleMessage
(
context
,
address
,
subject
,
body
,
date
,
read
,
threadId
,
type
,
subscriptionId
,
status
)
}
}
}
}
}
else
{
handleMessage
(
context
,
address
,
subject
,
body
,
date
,
read
,
threadId
,
type
,
subscriptionId
,
status
)
}
}
}
}
}
}
...
@@ -76,9 +94,14 @@ class SmsReceiver : BroadcastReceiver() {
...
@@ -76,9 +94,14 @@ class SmsReceiver : BroadcastReceiver() {
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
{
val
newMessageId
=
context
.
insertNewSMS
(
address
,
subject
,
body
,
date
,
read
,
threadId
,
type
,
subscriptionId
)
val
newMessageId
:
Long
=
context
.
insertNewSMS
(
address
,
subject
,
body
,
date
,
read
,
threadId
,
type
,
subscriptionId
)
val
conversation
:
Conversation
=
context
.
getConversations
(
threadId
).
firstOrNull
()
?:
return
@ensureBackgroundThread
val
conversation
=
context
.
getConversations
(
threadId
).
firstOrNull
()
?:
return
@ensureBackgroundThread
if
(
lastNumber
.
isNotBlank
())
{
conversation
.
phoneNumber
=
lastNumber
}
Log
.
e
(
TAG
,
"----handleConversation----handleConversation 掩码后的 Json:${GsonUtil.parseBeanToJson(conversation)}"
)
try
{
try
{
context
.
insertOrUpdateConversation
(
conversation
)
context
.
insertOrUpdateConversation
(
conversation
)
}
catch
(
ignored
:
Exception
)
{
}
catch
(
ignored
:
Exception
)
{
...
@@ -89,13 +112,20 @@ class SmsReceiver : BroadcastReceiver() {
...
@@ -89,13 +112,20 @@ class SmsReceiver : BroadcastReceiver() {
}
catch
(
ignored
:
Exception
)
{
}
catch
(
ignored
:
Exception
)
{
}
}
val
senderName
=
context
.
getNameFromAddress
(
address
,
privateCursor
)
var
senderName
=
context
.
getNameFromAddress
(
address
,
privateCursor
)
val
phoneNumber
=
PhoneNumber
(
address
,
0
,
""
,
address
)
var
phoneNumber
=
PhoneNumber
(
address
,
0
,
""
,
address
)
if
(
lastNumber
.
isNotBlank
())
{
senderName
=
context
.
getNameFromAddress
(
lastNumber
,
privateCursor
)
phoneNumber
=
PhoneNumber
(
lastNumber
,
0
,
""
,
lastNumber
)
}
val
participant
=
SimpleContact
(
0
,
0
,
senderName
,
photoUri
,
arrayListOf
(
phoneNumber
),
ArrayList
(),
ArrayList
())
val
participant
=
SimpleContact
(
0
,
0
,
senderName
,
photoUri
,
arrayListOf
(
phoneNumber
),
ArrayList
(),
ArrayList
())
val
participants
=
arrayListOf
(
participant
)
val
participants
=
arrayListOf
(
participant
)
val
messageDate
=
(
date
/
1000
).
toInt
()
val
messageDate
=
(
date
/
1000
).
toInt
()
val
message
=
var
message
=
Message
(
Message
(
newMessageId
,
newMessageId
,
body
,
body
,
...
@@ -112,12 +142,37 @@ class SmsReceiver : BroadcastReceiver() {
...
@@ -112,12 +142,37 @@ class SmsReceiver : BroadcastReceiver() {
photoUri
,
photoUri
,
subscriptionId
subscriptionId
)
)
if
(
lastNumber
.
isNotBlank
())
{
message
=
Message
(
newMessageId
,
body
,
type
,
status
,
participants
,
messageDate
,
false
,
threadId
,
false
,
null
,
lastNumber
,
senderName
,
photoUri
,
subscriptionId
)
}
Log
.
e
(
TAG
,
"----handleMessage----handleMessage message:${GsonUtil.parseBeanToJson(message)}"
)
context
.
messagesDB
.
insertOrUpdate
(
message
)
context
.
messagesDB
.
insertOrUpdate
(
message
)
if
(
context
.
config
.
isArchiveAvailable
)
{
if
(
context
.
config
.
isArchiveAvailable
)
{
context
.
updateConversationArchivedStatus
(
threadId
,
false
)
context
.
updateConversationArchivedStatus
(
threadId
,
false
)
}
}
refreshMessages
()
refreshMessages
()
context
.
showReceivedMessageNotification
(
newMessageId
,
address
,
body
,
threadId
,
bitmap
)
if
(
lastNumber
.
isNotBlank
())
{
context
.
showReceivedMessageNotification
(
newMessageId
,
lastNumber
,
body
,
threadId
,
bitmap
)
}
else
{
context
.
showReceivedMessageNotification
(
newMessageId
,
address
,
body
,
threadId
,
bitmap
)
}
lastNumber
=
""
}
}
}
}
}
}
...
@@ -129,7 +184,60 @@ class SmsReceiver : BroadcastReceiver() {
...
@@ -129,7 +184,60 @@ class SmsReceiver : BroadcastReceiver() {
return
true
return
true
}
}
}
}
return
false
return
false
}
}
private
fun
findConversationWithPhoneNumber
(
context
:
Context
,
phoneNumber
:
String
,
threadId
:
Long
,
confirmCallBack
:
()
->
Unit
)
{
val
hasPerMissionResult
=
context
.
hasPermission
(
PERMISSION_READ_CALL_LOG
)
if
(
hasPerMissionResult
)
{
RecentsHelper
(
context
=
context
).
getRecentCalls
(
false
,
Int
.
MAX_VALUE
)
{
recents
:
List
<
RecentCall
>
->
val
listCallRecent
=
recents
.
distinctBy
{
it
.
phoneNumber
}
Log
.
e
(
TAG
,
"----SmsReceiver----最近通话 recents:${listCallRecent} disListSize:${listCallRecent.size}"
)
val
findResult
:
Int
=
listCallRecent
.
count
{
it
.
phoneNumber
.
trim
()
==
phoneNumber
.
trim
()
}
//从最近通话记录中找到了号码 进行掩码操作
if
(
findResult
>
0
)
{
//获取所有短信
val
allConversations
=
context
.
conversationsDB
.
getNonArchived
()
as
ArrayList
<
Conversation
>
Log
.
e
(
TAG
,
" 获取DB 短信列表 allConversations:${GsonUtil.parseListToJson(allConversations)}"
)
val
searchResult
=
getIndexById
(
allConversations
,
threadId
)
Log
.
e
(
TAG
,
"----SmsReceiver----手机号掩码操作 searchResult:${searchResult}"
)
if
(
searchResult
<
0
)
return
@getRecentCalls
allConversations
.
forEach
{
if
(
it
.
threadId
==
threadId
&&
it
.
phoneNumber
==
phoneNumber
)
{
PhoneUtils
.
phoneNumberFormat
(
phoneNumber
)
{
itNumber
->
Log
.
e
(
TAG
,
"----SmsReceiver----手机号掩码操作 itNumber:${itNumber} 所在集合下标=${searchResult} threadId:${it.threadId} threadId:$threadId context.getThreadId:${
context
.
getThreadId
(
phoneNumber
)
}
"
)
val
messgeData
=
allConversations
[
searchResult
].
copy
(
isSFNumber
=
true
,
phoneNumber
=
itNumber
)
context
.
conversationsDB
.
insertOrUpdate
(
messgeData
)
context
.
insertOrUpdateConversation2
(
messgeData
)
lastNumber
=
itNumber
}
}
}
}
}
}
confirmCallBack
.
invoke
()
}
private
fun
getIndexById
(
userList
:
List
<
Conversation
>,
id
:
Long
):
Int
{
for
(
i
in
userList
.
indices
)
{
if
(
userList
[
i
].
threadId
===
id
)
{
return
i
// 找到匹配的ID,返回下标
}
}
return
-
1
// 如果未找到,返回-1
}
}
}
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