Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
O
One Clean Master
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
One Clean Master
Commits
10ca7fbd
Commit
10ca7fbd
authored
May 28, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
同步SmartClean通知部分的修改
parent
3921e2f4
Pipeline
#1127
canceled with stages
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
26 deletions
+95
-26
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+7
-1
NotificationHelper.kt
...om/test/basd/onecleanmaster/display/NotificationHelper.kt
+2
-2
NotificationTimerTask.kt
...test/basd/onecleanmaster/display/NotificationTimerTask.kt
+2
-2
NotificationUtils.kt
...com/test/basd/onecleanmaster/display/NotificationUtils.kt
+7
-7
MyFirebaseMessagingService.kt
.../onecleanmaster/display/fcm/MyFirebaseMessagingService.kt
+19
-14
NotificationJobService.kt
...basd/onecleanmaster/display/fcm/NotificationJobService.kt
+58
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
10ca7fbd
...
@@ -166,7 +166,13 @@
...
@@ -166,7 +166,13 @@
</intent-filter>
</intent-filter>
</receiver>
</receiver>
<service
android:name=
".display.NotificationService"
/>
<service
android:name=
".display.NotificationService"
android:permission=
"android.permission.FOREGROUND_SERVICE"
/>
<service
android:name=
".display.fcm.NotificationJobService"
android:permission=
"android.permission.BIND_JOB_SERVICE"
/>
<service
<service
android:name=
".notificationclean.AppNotificationListenerService"
android:name=
".notificationclean.AppNotificationListenerService"
...
...
app/src/main/java/com/test/basd/onecleanmaster/display/NotificationHelper.kt
View file @
10ca7fbd
...
@@ -131,7 +131,7 @@ object NotificationHelper {
...
@@ -131,7 +131,7 @@ object NotificationHelper {
* @param extra 额外参数
* @param extra 额外参数
*/
*/
@SuppressLint
(
"RemoteViewLayout"
)
@SuppressLint
(
"RemoteViewLayout"
)
fun
Context
.
postActionNotification
(
actionId
:
Int
,
extra
:
Int
?
=
null
,
s
:
Long
?
=
null
)
{
fun
Context
.
postActionNotification
(
actionId
:
Int
,
extra
:
Int
?
=
null
,
pushStayTime
:
Long
?
=
null
)
{
val
remoteViews
=
RemoteViews
(
packageName
,
R
.
layout
.
notification_common_notify
)
val
remoteViews
=
RemoteViews
(
packageName
,
R
.
layout
.
notification_common_notify
)
when
(
actionId
)
{
when
(
actionId
)
{
ID_JUNK_CLEAN_PUSH
->
{
ID_JUNK_CLEAN_PUSH
->
{
...
@@ -281,7 +281,7 @@ object NotificationHelper {
...
@@ -281,7 +281,7 @@ object NotificationHelper {
val
requestCode
=
Random
.
nextInt
(
0
,
1000
)
val
requestCode
=
Random
.
nextInt
(
0
,
1000
)
val
pendingIntent
=
PendingIntent
.
getActivity
(
applicationContext
,
requestCode
,
intent
,
FLAG_UPDATE_CURRENT
or
FLAG_MUTABLE
)
val
pendingIntent
=
PendingIntent
.
getActivity
(
applicationContext
,
requestCode
,
intent
,
FLAG_UPDATE_CURRENT
or
FLAG_MUTABLE
)
NotificationUtils
.
showNotification
(
applicationContext
,
notificationId
,
remoteViews
,
R
.
id
.
fl_cancel
,
pendingIntent
,
s
?:
0
)
NotificationUtils
.
showNotification
(
applicationContext
,
notificationId
,
remoteViews
,
R
.
id
.
fl_cancel
,
pendingIntent
,
pushStayTime
?:
0
)
}
}
...
...
app/src/main/java/com/test/basd/onecleanmaster/display/NotificationTimerTask.kt
View file @
10ca7fbd
...
@@ -31,10 +31,10 @@ class NotificationTimerTask() : TimerTask() {
...
@@ -31,10 +31,10 @@ class NotificationTimerTask() : TimerTask() {
var
extra
:
Int
?
=
null
var
extra
:
Int
?
=
null
if
(
id
==
ID_PHONE_ACCELERATE
)
{
if
(
id
==
ID_PHONE_ACCELERATE
)
{
extra
=
RamMemoryEx
.
getMemoryUsage
(
BaseApplication
.
context
).
toInt
()
extra
=
RamMemoryEx
.
getMemoryUsage
(
BaseApplication
.
context
).
toInt
()
Log
.
d
(
"My
service"
,
"ram: "
+
extra
)
Log
.
d
(
"My
Service"
,
"ram: $extra"
)
}
}
BaseApplication
.
context
.
postActionNotification
(
id
,
extra
)
BaseApplication
.
context
.
postActionNotification
(
id
,
extra
,
200000
)
}
}
}
}
...
...
app/src/main/java/com/test/basd/onecleanmaster/display/NotificationUtils.kt
View file @
10ca7fbd
...
@@ -40,7 +40,7 @@ object NotificationUtils {
...
@@ -40,7 +40,7 @@ object NotificationUtils {
remoteViews
:
RemoteViews
,
remoteViews
:
RemoteViews
,
closeViewId
:
Int
,
closeViewId
:
Int
,
pendingIntent
:
PendingIntent
,
pendingIntent
:
PendingIntent
,
delay
:
Long
pushStayTime
:
Long
)
{
)
{
if
(
closeViewId
!=
0
)
{
if
(
closeViewId
!=
0
)
{
val
closeIntent
=
Intent
(
context
,
CloseNotificationReceiver
::
class
.
java
).
apply
{
val
closeIntent
=
Intent
(
context
,
CloseNotificationReceiver
::
class
.
java
).
apply
{
...
@@ -50,7 +50,7 @@ object NotificationUtils {
...
@@ -50,7 +50,7 @@ object NotificationUtils {
PendingIntent
.
getBroadcast
(
context
,
0
,
closeIntent
,
PendingIntent
.
FLAG_MUTABLE
)
PendingIntent
.
getBroadcast
(
context
,
0
,
closeIntent
,
PendingIntent
.
FLAG_MUTABLE
)
remoteViews
.
setOnClickPendingIntent
(
closeViewId
,
closePendingIntent
)
remoteViews
.
setOnClickPendingIntent
(
closeViewId
,
closePendingIntent
)
}
}
val
builder
=
createNotificationBuilder
(
context
,
remoteViews
,
pendingIntent
,
delay
)
val
builder
=
createNotificationBuilder
(
context
,
remoteViews
,
pendingIntent
,
pushStayTime
)
sendNotification
(
context
,
notificationId
,
builder
)
sendNotification
(
context
,
notificationId
,
builder
)
}
}
...
@@ -58,7 +58,7 @@ object NotificationUtils {
...
@@ -58,7 +58,7 @@ object NotificationUtils {
context
:
Context
,
context
:
Context
,
remoteViews
:
RemoteViews
,
remoteViews
:
RemoteViews
,
pendingIntent
:
PendingIntent
,
pendingIntent
:
PendingIntent
,
delay
:
Long
pushStayTime
:
Long
):
NotificationCompat
.
Builder
{
):
NotificationCompat
.
Builder
{
val
notificationManager
=
val
notificationManager
=
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
...
@@ -90,7 +90,7 @@ object NotificationUtils {
...
@@ -90,7 +90,7 @@ object NotificationUtils {
.
setStyle
(
NotificationCompat
.
BigTextStyle
())
.
setStyle
(
NotificationCompat
.
BigTextStyle
())
.
setFullScreenIntent
(
pendingIntent
,
true
)
.
setFullScreenIntent
(
pendingIntent
,
true
)
.
setVisibility
(
NotificationCompat
.
VISIBILITY_PUBLIC
)
.
setVisibility
(
NotificationCompat
.
VISIBILITY_PUBLIC
)
.
setTimeoutAfter
(
delay
)
.
setTimeoutAfter
(
pushStayTime
)
.
setSound
(
null
)
.
setSound
(
null
)
.
setLights
(
0
,
0
,
0
)
.
setLights
(
0
,
0
,
0
)
.
setVibrate
(
null
)
.
setVibrate
(
null
)
...
@@ -187,7 +187,7 @@ object NotificationUtils {
...
@@ -187,7 +187,7 @@ object NotificationUtils {
return
notification
return
notification
}
}
fun
sendTimerPush
(
s
:
Long
)
{
fun
sendTimerPush
(
pushStayTime
:
Long
)
{
Log
.
d
(
TAG
,
"sendTimerPush"
)
Log
.
d
(
TAG
,
"sendTimerPush"
)
val
id
=
NotificationHelper
.
getPresentPushId
()
val
id
=
NotificationHelper
.
getPresentPushId
()
val
isPush
=
PushStrategy
.
isPush
(
id
)
val
isPush
=
PushStrategy
.
isPush
(
id
)
...
@@ -199,13 +199,13 @@ object NotificationUtils {
...
@@ -199,13 +199,13 @@ object NotificationUtils {
if
(
id
==
ID_PHONE_ACCELERATE
)
{
if
(
id
==
ID_PHONE_ACCELERATE
)
{
extra
=
RamMemoryEx
.
getMemoryUsage
(
BaseApplication
.
context
).
toInt
()
extra
=
RamMemoryEx
.
getMemoryUsage
(
BaseApplication
.
context
).
toInt
()
}
}
BaseApplication
.
context
.
postActionNotification
(
id
,
extra
,
s
)
BaseApplication
.
context
.
postActionNotification
(
id
,
extra
,
pushStayTime
)
}
}
}
}
fun
isNotificationExist
(
context
:
Context
,
notificationId
:
Int
):
Boolean
{
fun
isNotificationExist
(
context
:
Context
,
notificationId
:
Int
):
Boolean
{
// 获取 NotificationManagerCompat 实例
// 获取 NotificationManagerCompat 实例
val
notificationManager
=
NotificationManagerCompat
.
from
(
context
!!
)
val
notificationManager
=
NotificationManagerCompat
.
from
(
context
)
// 获取当前活动的通知列表
// 获取当前活动的通知列表
val
notifications
:
MutableList
<
StatusBarNotification
>
=
notificationManager
.
activeNotifications
val
notifications
:
MutableList
<
StatusBarNotification
>
=
notificationManager
.
activeNotifications
...
...
app/src/main/java/com/test/basd/onecleanmaster/display/fcm/MyFirebaseMessagingService.kt
View file @
10ca7fbd
package
com.test.basd.onecleanmaster.display.fcm
package
com.test.basd.onecleanmaster.display.fcm
import
android.app.job.JobInfo
import
android.app.job.JobScheduler
import
android.content.ComponentName
import
android.content.Context
import
android.content.Intent
import
android.content.Intent
import
android.os.Build
import
android.os.Build
import
android.util.Log
import
android.util.Log
...
@@ -13,20 +17,20 @@ import com.test.basd.onecleanmaster.helps.EventHelper
...
@@ -13,20 +17,20 @@ import com.test.basd.onecleanmaster.helps.EventHelper
class
MyFirebaseMessagingService
:
FirebaseMessagingService
()
{
class
MyFirebaseMessagingService
:
FirebaseMessagingService
()
{
override
fun
onMessageReceived
(
remoteMessage
:
RemoteMessage
)
{
override
fun
onMessageReceived
(
remoteMessage
:
RemoteMessage
)
{
Log
.
d
(
TAG
,
"onMessageReceived: "
+
remoteMessage
.
from
)
Log
.
d
(
TAG
,
"onMessageReceived: "
+
remoteMessage
.
from
)
val
isBoolean
=
NotificationUtils
.
isNotificationExist
(
this
,
1
)
val
pushStayTime
=
remoteMessage
.
data
[
"push_stay_time"
]
?.
toLongOrNull
()
?:
0
val
s
=
remoteMessage
?.
data
?.
get
(
"push_stay_time"
)
?.
toLongOrNull
()
?:
0
EventHelper
.
event
(
"fcm_message_received"
,
pushStayTime
.
toString
())
EventHelper
.
event
(
"fcm_message_received"
,
s
.
toString
()
)
NotificationUtils
.
sendTimerPush
(
pushStayTime
)
NotificationUtils
.
sendTimerPush
(
s
)
initJob
(
)
if
(
isBoolean
)
{
}
Log
.
d
(
TAG
,
"常驻通知栏存在"
);
return
private
fun
initJob
()
{
}
val
jobScheduler
=
getSystemService
(
Context
.
JOB_SCHEDULER_SERVICE
)
as
JobScheduler
val
intent
=
Intent
(
this
,
NotificationService
::
class
.
java
)
val
job
=
JobInfo
.
Builder
(
0
,
ComponentName
(
this
,
NotificationJobService
::
class
.
java
)
)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
.
setMinimumLatency
(
0L
)
startForegroundService
(
intent
)
.
setOverrideDeadline
(
0L
)
}
else
{
.
setPersisted
(
true
)
startService
(
intent
)
.
build
(
)
}
jobScheduler
.
schedule
(
job
)
}
}
override
fun
onNewToken
(
token
:
String
)
{
override
fun
onNewToken
(
token
:
String
)
{
...
@@ -38,3 +42,4 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
...
@@ -38,3 +42,4 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
private
const
val
TAG
=
"MyFirebaseMsgService"
private
const
val
TAG
=
"MyFirebaseMsgService"
}
}
}
}
app/src/main/java/com/test/basd/onecleanmaster/display/fcm/NotificationJobService.kt
0 → 100644
View file @
10ca7fbd
package
com.test.basd.onecleanmaster.display.fcm
import
android.annotation.SuppressLint
import
android.app.ActivityManager
import
android.app.job.JobParameters
import
android.app.job.JobService
import
android.content.Intent
import
android.os.Build
import
com.test.basd.onecleanmaster.display.NotificationService
@SuppressLint
(
"SpecifyJobSchedulerIdRange"
)
class
NotificationJobService
:
JobService
()
{
private
var
isServiceRunning
=
false
override
fun
onStartJob
(
params
:
JobParameters
):
Boolean
{
if
(!
isServiceRunning
)
{
// 创建一个启动服务的Intent
val
intent
=
Intent
(
this
,
NotificationService
::
class
.
java
)
// 检查服务是否已经运行
isServiceRunning
=
if
(
isServiceRunning
(
intent
))
{
true
}
else
{
// 启动服务
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
startForegroundService
(
intent
)
}
else
{
startService
(
intent
)
}
// 标记服务已经运行
true
}
}
// 告诉系统任务已完成
jobFinished
(
params
,
false
)
return
false
}
override
fun
onStopJob
(
params
:
JobParameters
):
Boolean
{
return
false
}
private
fun
isServiceRunning
(
intent
:
Intent
):
Boolean
{
val
manager
:
ActivityManager
=
getSystemService
(
ACTIVITY_SERVICE
)
as
ActivityManager
val
infos
:
List
<
ActivityManager
.
RunningServiceInfo
>
=
manager
.
getRunningServices
(
Int
.
MAX_VALUE
)
for
(
info
in
infos
)
{
if
(
info
.
service
.
className
==
intent
.
component
?.
className
)
{
return
true
}
}
return
false
}
companion
object
{
private
const
val
JOB_ID
=
123
}
}
\ No newline at end of file
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