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
b1349720
Commit
b1349720
authored
Nov 19, 2024
by
zhangchengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:优化顺丰手机号掩码操作
parent
56d44481
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
36 deletions
+34
-36
SmsReceiver.kt
...src/main/kotlin/com/secspace/sms/receivers/SmsReceiver.kt
+34
-36
No files found.
app/src/main/kotlin/com/secspace/sms/receivers/SmsReceiver.kt
View file @
b1349720
...
...
@@ -6,6 +6,7 @@ import android.content.Intent
import
android.os.Handler
import
android.os.Looper
import
android.provider.Telephony
import
android.util.Log
import
com.secspace.sms.extensions.*
import
com.secspace.sms.helpers.RecentsHelper
import
com.secspace.sms.helpers.refreshMessages
...
...
@@ -22,6 +23,7 @@ import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import
com.simplemobiletools.commons.helpers.ensureBackgroundThread
import
com.simplemobiletools.commons.models.PhoneNumber
import
com.simplemobiletools.commons.models.SimpleContact
import
com.simplemobiletools.commons.util.GsonUtil
class
SmsReceiver
:
BroadcastReceiver
()
{
private
val
TAG
:
String
=
"shuju"
...
...
@@ -70,6 +72,36 @@ class SmsReceiver : BroadcastReceiver() {
}
}
/**
* 根据短信手机号查找
*/
private
fun
findConversationWithPhoneNumber
(
context
:
Context
,
phoneNumber
:
String
,
threadId
:
Long
,
confirmCallBack
:
()
->
Unit
)
{
Log
.
e
(
TAG
,
"----SmsReceiver---- phoneNumber:${phoneNumber} threadId:$threadId"
)
val
hasPerMissionResult
=
context
.
hasPermission
(
PERMISSION_READ_CALL_LOG
)
if
(
hasPerMissionResult
)
{
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
:
Int
=
listCallRecent
.
count
{
it
.
phoneNumber
.
trim
()
==
phoneNumber
.
trim
()
&&
it
.
isShunFeng
}
Log
.
d
(
TAG
,
"----SmsReceiver----findResult:${findResult}"
)
//从最近通话记录中找到了号码 进行掩码操作
if
(
findResult
>
0
)
{
PhoneUtils
.
phoneNumberFormat
(
phoneNumber
)
{
itNumber
->
Log
.
d
(
TAG
,
"----SmsReceiver----手机号掩码操作 itNumber:${itNumber} threadId:$threadId context.getThreadId:${context.getThreadId(phoneNumber)}"
)
lastNumber
=
itNumber
}
}
}
}
confirmCallBack
.
invoke
()
}
private
fun
handleMessage
(
context
:
Context
,
address
:
String
,
...
...
@@ -100,7 +132,7 @@ class SmsReceiver : BroadcastReceiver() {
conversation
.
phoneNumber
=
lastNumber
conversation
.
isSFNumber
=
true
}
//
Log.e(TAG, "----SmsReceiver----handleConversation 掩码后的 Json:${GsonUtil.parseBeanToJson(conversation)}")
Log
.
e
(
TAG
,
"----SmsReceiver----handleConversation 掩码后的 Json:${GsonUtil.parseBeanToJson(conversation)}"
)
try
{
context
.
insertOrUpdateConversation
(
conversation
)
}
catch
(
ignored
:
Exception
)
{
...
...
@@ -160,7 +192,7 @@ class SmsReceiver : BroadcastReceiver() {
subscriptionId
)
}
//
Log.e(TAG, "----SmsReceiver----handleMessage message:${GsonUtil.parseBeanToJson(message)}")
Log
.
e
(
TAG
,
"----SmsReceiver----handleMessage message:${GsonUtil.parseBeanToJson(message)}"
)
context
.
messagesDB
.
insertOrUpdate
(
message
)
if
(
context
.
config
.
isArchiveAvailable
)
{
context
.
updateConversationArchivedStatus
(
threadId
,
false
)
...
...
@@ -186,40 +218,6 @@ class SmsReceiver : BroadcastReceiver() {
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
>
val
searchResult
=
getIndexById
(
allConversations
,
threadId
)
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)
}"
)*/
lastNumber
=
itNumber
}
}
}
}
}
}
confirmCallBack
.
invoke
()
}
private
fun
getIndexById
(
userList
:
List
<
Conversation
>,
id
:
Long
):
Int
{
for
(
i
in
userList
.
indices
)
{
...
...
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