Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
A
appzxhy
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
appzxhy
Commits
86177a80
Commit
86177a80
authored
Dec 27, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...通知部分
parent
c3391b64
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
821 additions
and
40 deletions
+821
-40
README.md
README.md
+10
-0
MyApplication.kt
app/src/main/java/com/base/appzxhy/MyApplication.kt
+33
-24
AdsMgr.kt
app/src/main/java/com/base/appzxhy/ads/AdsMgr.kt
+1
-6
LimitUtils.kt
app/src/main/java/com/base/appzxhy/ads/LimitUtils.kt
+8
-7
AdBannerMgr.kt
app/src/main/java/com/base/appzxhy/ads/admob/AdBannerMgr.kt
+2
-1
NotificationSendBean.kt
...c/main/java/com/base/appzxhy/bean/NotificationSendBean.kt
+25
-0
AdConfigBean.kt
...rc/main/java/com/base/appzxhy/bean/config/AdConfigBean.kt
+11
-1
PopupConfigBean.kt
...main/java/com/base/appzxhy/bean/config/PopupConfigBean.kt
+6
-1
TimerManager.kt
app/src/main/java/com/base/appzxhy/fcm/TimerManager.kt
+79
-0
NotificationHoverUtils.kt
...m/base/appzxhy/fcm/notification/NotificationHoverUtils.kt
+64
-0
NotificationManager.kt
.../com/base/appzxhy/fcm/notification/NotificationManager.kt
+162
-0
NotificationUiUtil.kt
...a/com/base/appzxhy/fcm/notification/NotificationUiUtil.kt
+13
-0
BatteryStatusReceiver.kt
...va/com/base/appzxhy/fcm/receiver/BatteryStatusReceiver.kt
+147
-0
FileJobReceiver.kt
...ain/java/com/base/appzxhy/fcm/receiver/FileJobReceiver.kt
+15
-0
PackageStatusReceiver.kt
...va/com/base/appzxhy/fcm/receiver/PackageStatusReceiver.kt
+117
-0
ScreenStatusReceiver.kt
...ava/com/base/appzxhy/fcm/receiver/ScreenStatusReceiver.kt
+128
-0
No files found.
README.md
View file @
86177a80
...
...
@@ -10,3 +10,13 @@
2.
初始化广告
3.
初始化Facebook
4.
FCM上报topic和token
5.
初始化上次sp配置
6.
请求InstallReferrerUrl,再次请求配置接口跟新配置
7.
根据配置执行(上报配置类型;更新运行时广告配置;更新运行时通知配置;按配置启动定时器)
8.
SolarEngineUtils归因上报
9.
注册各种触发推送的广播(解锁广播,卸载安装广播,电量广播)
10.
StayJobService启动常驻通知栏
11.
设置闹钟(24h,48h,72h)
12.
注册生命周期回调,app从后台回来走启动页
app/src/main/java/com/base/appzxhy/MyApplication.kt
View file @
86177a80
...
...
@@ -9,14 +9,21 @@ import android.util.Log
import
com.base.appzxhy.ads.AdsMgr
import
com.base.appzxhy.bean.ConstObject.appLanguageCountrySp
import
com.base.appzxhy.bean.ConstObject.appLanguageSp
import
com.base.appzxhy.bean.config.AdConfigBean
import
com.base.appzxhy.bean.config.ConfigBean
import
com.base.appzxhy.bean.config.PopupConfigBean
import
com.base.appzxhy.fcm.FCMManager
import
com.base.appzxhy.fcm.TimerManager.Companion.changeTimer
import
com.base.appzxhy.helper.EventUtils
import
com.base.appzxhy.utils.ActivityManagerUtils
import
com.base.appzxhy.utils.AppPreferences
import
com.base.appzxhy.utils.LogEx
import
com.facebook.FacebookSdk
import
com.google.android.gms.ads.identifier.AdvertisingIdClient
import
com.google.gson.Gson
import
com.hjq.language.MultiLanguages
import
com.hjq.language.OnLanguageListener
import
org.json.JSONObject
import
java.util.Locale
import
java.util.UUID
...
...
@@ -104,7 +111,7 @@ class MyApplication : Application() {
FCMManager
.
initFirebase
(
this
)
FCMManager
.
subscribeToTopic
(
topic
)
//
initConfig()
initConfig
()
//
// Thread {
// InstallHelps.init {
...
...
@@ -116,9 +123,9 @@ class MyApplication : Application() {
initLifeListener
()
// ScreenStatusReceiver.registerScreenStatusReceiver(this)
// PackageStatusReceiver.registerPackageStatusReceiver(this)
// BatteryStatusReceiver.registerBatteryStatusReceiver(this)
//
com.base.appzxhy.fcm.receiver.
ScreenStatusReceiver.registerScreenStatusReceiver(this)
//
com.base.appzxhy.fcm.receiver.
PackageStatusReceiver.registerPackageStatusReceiver(this)
//
com.base.appzxhy.fcm.receiver.
BatteryStatusReceiver.registerBatteryStatusReceiver(this)
// startJob()
// startAlarm(appContext, 24)
...
...
@@ -210,26 +217,28 @@ class MyApplication : Application() {
private
fun
initConfig
(
config
:
String
?
=
AppPreferences
.
getInstance
().
getString
(
"config"
,
""
))
{
// kotlin.runCatching {
// val configBean = Gson().fromJson(config, com.base.appzxhy.bean.config.ConfigBean::class.java)
//
// val jsonObject = JSONObject()
// jsonObject.put("ut", configBean.ut)
// EventUtils.event("user_type", ext = jsonObject)
//
// //配置
// com.base.appzxhy.bean.config.ConfigBean.configBean = configBean
//
// //广告
// com.base.appzxhy.ads.AdsMgr.adsConfigBean = configBean.adConfigBean
// com.base.localweatherwhite.utils.LogEx.logDebug("initConfig", "com.base.appzxhy.ads.AdsMgr.adsConfigBean=${configBean.adConfigBean.functionInShowAd}")
//
// //通知
// PopupConstObject.popupConfigBean = configBean.popupConfigBean
//
// //启动定时器
// changeTimer()
// }
kotlin
.
runCatching
{
val
configBean
=
Gson
().
fromJson
(
config
,
ConfigBean
::
class
.
java
)
val
jsonObject
=
JSONObject
()
jsonObject
.
put
(
"ut"
,
configBean
.
ut
)
EventUtils
.
event
(
"user_type"
,
ext
=
jsonObject
)
//配置
ConfigBean
.
configBean
=
configBean
//广告
AdConfigBean
.
adsConfigBean
=
configBean
.
adConfigBean
LogEx
.
logDebug
(
"initConfig"
,
"adsConfigBean=${configBean.adConfigBean.functionInShowAd}"
)
//通知配置
PopupConfigBean
.
popupConfigBean
=
configBean
.
popupConfigBean
LogEx
.
logDebug
(
"initConfig"
,
"popupConfigBean=${configBean.popupConfigBean.popupCount}"
)
//启动定时器
changeTimer
()
}
}
...
...
app/src/main/java/com/base/appzxhy/ads/AdsMgr.kt
View file @
86177a80
...
...
@@ -18,7 +18,7 @@ import com.base.appzxhy.ads.applovin.AdMaxEvent
import
com.base.appzxhy.ads.applovin.MaxInsertMgr
import
com.base.appzxhy.ads.applovin.MaxNativeMgr
import
com.base.appzxhy.ads.applovin.MaxOpenMgr
import
com.base.appzxhy.bean.config.AdConfigBean
import
com.base.appzxhy.bean.config.AdConfigBean
.Companion.adsConfigBean
import
com.base.appzxhy.bean.config.ConfigBean.Companion.configBean
import
com.base.appzxhy.helper.EventUtils
import
com.base.appzxhy.utils.AppPreferences
...
...
@@ -73,11 +73,6 @@ object AdsMgr {
var
isMaxInit
=
false
private
set
/**
* 广告配置项目
*/
var
adsConfigBean
:
AdConfigBean
=
AdConfigBean
()
/**
* Init 初始化
...
...
app/src/main/java/com/base/appzxhy/ads/LimitUtils.kt
View file @
86177a80
package
com.base.appzxhy.ads
import
com.base.appzxhy.bean.config.AdConfigBean
import
com.base.appzxhy.utils.AppPreferences
import
com.base.appzxhy.utils.KotlinExt.toFormatTime4
...
...
@@ -31,7 +32,7 @@ object LimitUtils {
*/
private
inline
val
isRequestLimited
:
Boolean
get
()
{
val
maxCount
=
Ad
sMgr
.
adsConfigBean
.
numRequestLimit
val
maxCount
=
Ad
ConfigBean
.
adsConfigBean
.
numRequestLimit
return
maxCount
>
-
1
&&
AppPreferences
.
getInstance
()
.
getInt
(
NUM_REQUEST
,
0
)
>=
maxCount
}
...
...
@@ -41,7 +42,7 @@ object LimitUtils {
*/
private
inline
val
isDisplayLimited
:
Boolean
get
()
{
val
maxCount
=
Ad
sMgr
.
adsConfigBean
.
numDisplayLimit
val
maxCount
=
Ad
ConfigBean
.
adsConfigBean
.
numDisplayLimit
return
maxCount
>
-
1
&&
AppPreferences
.
getInstance
()
.
getInt
(
NUM_DISPLAY
,
0
)
>=
maxCount
}
...
...
@@ -51,7 +52,7 @@ object LimitUtils {
*/
private
inline
val
isClickLimited
:
Boolean
get
()
{
val
maxCount
=
Ad
sMgr
.
adsConfigBean
.
numClickLimit
val
maxCount
=
Ad
ConfigBean
.
adsConfigBean
.
numClickLimit
return
maxCount
>
-
1
&&
AppPreferences
.
getInstance
()
.
getInt
(
NUM_CLICK
,
0
)
>=
maxCount
}
...
...
@@ -84,21 +85,21 @@ object LimitUtils {
val
value
=
"current${getAdEventMsg(adsType)} "
+
"show=${AppPreferences.getInstance().getInt(NUM_DISPLAY, 0)} "
+
"${getAdEventMsg(adsType).lowercase()}_"
+
"max_show=${Ad
sMgr
.adsConfigBean.numDisplayLimit}"
"${getAdEventMsg(adsType).lowercase()}_"
+
"max_show=${Ad
ConfigBean
.adsConfigBean.numDisplayLimit}"
adEvent
?.
adLimited
(
value
)
}
if
(
isClickLimited
)
{
val
value
=
"current${getAdEventMsg(adsType)}Click=${AppPreferences.getInstance().getInt(NUM_CLICK, 0)} "
"${getAdEventMsg(adsType).lowercase()}_max_click=${Ad
sMgr
.adsConfigBean.numClickLimit}"
"${getAdEventMsg(adsType).lowercase()}_max_click=${Ad
ConfigBean
.adsConfigBean.numClickLimit}"
adEvent
?.
adLimited
(
value
)
}
if
(
isRequestLimited
)
{
val
value
=
"current${getAdEventMsg(adsType)}Request=${AppPreferences.getInstance().getInt(NUM_REQUEST, 0)} "
+
"${getAdEventMsg(adsType).lowercase()}_max_request=${Ad
sMgr
.adsConfigBean.numRequestLimit}"
"${getAdEventMsg(adsType).lowercase()}_max_request=${Ad
ConfigBean
.adsConfigBean.numRequestLimit}"
adEvent
?.
adLimited
(
value
)
}
...
...
@@ -137,7 +138,7 @@ object LimitUtils {
* @param lastTime 上一次显示的时间
*/
fun
isIntervalLimited
(
lastTime
:
Long
,
adEvent
:
AdEvent
):
Boolean
{
val
flag
=
((
System
.
currentTimeMillis
()
-
lastTime
)
/
1000
).
toInt
()
<
(
Ad
sMgr
.
adsConfigBean
.
timeInterval
)
val
flag
=
((
System
.
currentTimeMillis
()
-
lastTime
)
/
1000
).
toInt
()
<
(
Ad
ConfigBean
.
adsConfigBean
.
timeInterval
)
if
(
flag
)
{
adEvent
.
adShowError
(
"ad in timeInterval"
)
}
...
...
app/src/main/java/com/base/appzxhy/ads/admob/AdBannerMgr.kt
View file @
86177a80
...
...
@@ -7,6 +7,7 @@ import com.base.appzxhy.GlobalConfig
import
com.base.appzxhy.ads.AdsMgr
import
com.base.appzxhy.ads.AdsType
import
com.base.appzxhy.ads.LimitUtils
import
com.base.appzxhy.bean.config.AdConfigBean
import
com.google.ads.mediation.admob.AdMobAdapter
import
com.google.android.gms.ads.AdListener
import
com.google.android.gms.ads.AdRequest
...
...
@@ -25,7 +26,7 @@ class AdBannerMgr {
fun
show
(
parent
:
ViewGroup
,
collapsible
:
Boolean
,
adClose
:
(()
->
Unit
)?
=
null
)
{
if
(!
Ad
sMgr
.
adsConfigBean
.
adSwitch
)
{
if
(!
Ad
ConfigBean
.
adsConfigBean
.
adSwitch
)
{
return
}
val
admobEvent
=
AdmobEvent
(
"banner"
,
"banner"
)
...
...
app/src/main/java/com/base/appzxhy/bean/NotificationSendBean.kt
0 → 100644
View file @
86177a80
package
com.base.appzxhy.bean
import
android.content.Context
class
NotificationSendBean
(
val
context
:
Context
,
val
actionId
:
String
=
""
,
val
where
:
String
=
""
,
val
canSend
:
()
->
Boolean
=
{
true
},
//是否可以发送
var
sendSuccess
:
(()
->
Unit
)?
=
null
,
//发送成功回调
var
valueMap
:
HashMap
<
String
,
Any
>
=
hashMapOf
()
//发送通知可能携带的参数
)
{
companion
object
{
const
val
POPUP_WHERE_TIMBER
=
"Timer"
const
val
POPUP_WHERE_LOCK
=
"Lock"
const
val
POPUP_WHERE_FCM
=
"fcm"
const
val
POPUP_WHERE_ALARM
=
"Alarm"
const
val
POPUP_WHERE_BATTERY
=
"battery"
const
val
POPUP_WHERE_PACKAGE
=
"package"
const
val
POPUP_WHERE_WORK_MANAGER
=
"workmanager"
const
val
POPUP_WHERE_FILE_JOB
=
"FileJob"
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/bean/config/AdConfigBean.kt
View file @
86177a80
...
...
@@ -9,4 +9,14 @@ class AdConfigBean(
var
openAdLoading
:
Int
=
15
,
var
functionBackShowAd
:
Boolean
=
true
,
var
functionInShowAd
:
Boolean
=
true
,
)
\ No newline at end of file
){
companion
object
{
/**
* 广告配置项目
*/
var
adsConfigBean
:
AdConfigBean
=
AdConfigBean
()
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/bean/config/PopupConfigBean.kt
View file @
86177a80
...
...
@@ -33,4 +33,9 @@ class PopupConfigBean(
var
packageS
:
Boolean
=
true
,
var
popupPackageCount
:
Int
=
20
,
var
popupPackageInterval
:
Int
=
1
)
\ No newline at end of file
)
{
companion
object
{
var
popupConfigBean
:
PopupConfigBean
=
PopupConfigBean
()
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/fcm/TimerManager.kt
0 → 100644
View file @
86177a80
package
com.base.appzxhy.fcm
import
com.base.appzxhy.MyApplication
import
com.base.appzxhy.bean.config.PopupConfigBean.Companion.popupConfigBean
import
com.base.appzxhy.fcm.receiver.ScreenStatusReceiver
import
com.base.appzxhy.utils.LogEx.logDebug
import
java.util.Timer
import
java.util.TimerTask
class
TimerManager
private
constructor
()
{
private
val
TAG
=
"TimerManager"
private
var
taskTimer
:
Timer
?
=
null
private
var
isTaskTimerActive
:
Boolean
=
false
fun
scheduleTask
(
delay
:
Long
,
period
:
Long
)
{
logDebug
(
TAG
,
"scheduleTask"
)
synchronized
(
TimerManager
::
class
.
java
)
{
ensureTimerIsStopped
()
// 确保定时器未运行
taskTimer
=
Timer
()
// 创建新的 Timer 实例
val
task
:
TimerTask
=
object
:
TimerTask
()
{
override
fun
run
()
{
logDebug
(
TAG
,
"scheduleTask run"
)
// 确保设备处于交互状态,未锁定,且应用未暂停
if
(
ScreenStatusReceiver
.
isDeviceInteractive
&&
!
ScreenStatusReceiver
.
isSecureLockActive
&&
MyApplication
.
PAUSED_VALUE
!=
1
)
{
logDebug
(
TAG
,
"scheduleTask send"
)
// sendNotificationIfCan(MyApplication.appContext, PopupConstObject.POPUP_WHERE_TIMBER, null)
}
}
}
taskTimer
?.
schedule
(
task
,
delay
,
period
)
// 调度任务
isTaskTimerActive
=
true
// 设置定时器状态为活跃
}
}
private
fun
ensureTimerIsStopped
()
{
if
(
isTaskTimerActive
)
{
if
(
taskTimer
!=
null
)
{
taskTimer
?.
cancel
()
taskTimer
?.
purge
()
// 清除所有取消的任务
}
isTaskTimerActive
=
false
// 重置定时器状态
}
}
fun
stopTaskTimer
()
{
synchronized
(
TimerManager
::
class
.
java
)
{
ensureTimerIsStopped
()
// 停止定时器
}
}
companion
object
{
private
val
instance
:
TimerManager
by
lazy
((
LazyThreadSafetyMode
.
SYNCHRONIZED
))
{
TimerManager
()
}
fun
changeTimer
()
{
if
(!
popupConfigBean
.
timerS
)
{
instance
.
stopTaskTimer
()
}
else
{
val
timerDelay
:
Int
=
popupConfigBean
.
timerDelay
val
timerInterval
:
Int
=
popupConfigBean
.
timerInterval
val
isTaskTimerActive
=
instance
.
isTaskTimerActive
if
(!
isTaskTimerActive
)
{
instance
.
scheduleTask
(
(
timerDelay
*
60
*
1000
).
toLong
(),
(
timerInterval
*
60
*
1000
).
toLong
()
)
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/fcm/notification/NotificationHoverUtils.kt
0 → 100644
View file @
86177a80
package
com.base.appzxhy.fcm.notification
import
android.os.Handler
import
android.os.HandlerThread
import
com.base.appzxhy.MyApplication
import
com.base.appzxhy.bean.NotificationSendBean
import
com.base.appzxhy.bean.config.PopupConfigBean.Companion.popupConfigBean
/**
* 悬停
*/
object
NotificationHoverUtils
{
private
val
TAG
=
"NotificationHoverUtils"
private
var
handlerThread
:
HandlerThread
?
=
null
private
var
handler
:
Handler
?
=
null
/**
* 发送悬停通知
*/
fun
sendHoverNotification
(
sendBean
:
NotificationSendBean
)
{
val
hoverStatus
=
popupConfigBean
.
popupHoverStatus
val
hoverCount
=
popupConfigBean
.
popupHoverCount
val
hoverDelay
=
popupConfigBean
.
popupHoverDelay
.
toLong
()
if
(!
hoverStatus
)
return
if
(
handlerThread
==
null
)
{
handlerThread
=
HandlerThread
(
"NotificationHandlerThread"
)
handlerThread
?.
start
()
}
// 创建 Handler
if
(
handler
==
null
)
{
handlerThread
?.
let
{
handler
=
Handler
(
it
.
getLooper
())
}
}
for
(
i
in
1
..
hoverCount
)
{
val
time
=
i
*
hoverDelay
handler
?.
postDelayed
(
Runnable
{
// LogEx.logDebug(TAG, "handler ${MyApplication.PAUSED_VALUE}")
if
(
MyApplication
.
PAUSED_VALUE
==
1
)
{
handler
?.
removeCallbacksAndMessages
(
null
)
}
else
{
NotificationUiUtil
.
setNotification
(
sendBean
)
}
},
time
)
}
}
fun
stopNotificationHandler
()
{
// 停止 HandlerThread
if
(
handler
!=
null
)
{
handler
?.
removeCallbacksAndMessages
(
null
)
}
if
(
handlerThread
!=
null
)
{
handlerThread
?.
quit
()
handlerThread
=
null
}
handler
=
null
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/fcm/notification/NotificationManager.kt
0 → 100644
View file @
86177a80
package
com.base.appzxhy.fcm.notification
import
android.content.Context
import
com.base.appzxhy.BuildConfig
import
com.base.appzxhy.bean.NotificationSendBean
import
com.base.appzxhy.bean.NotificationSendBean.Companion.POPUP_WHERE_TIMBER
import
com.base.appzxhy.bean.config.PopupConfigBean.Companion.popupConfigBean
import
com.base.appzxhy.helper.EventUtils
import
com.base.appzxhy.utils.AppPreferences
import
com.base.appzxhy.utils.KotlinExt.currentDate
import
com.base.appzxhy.utils.LogEx
import
com.base.appzxhy.utils.ToastUtils.toast
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.MainScope
import
kotlinx.coroutines.async
import
kotlinx.coroutines.isActive
import
kotlinx.coroutines.launch
import
java.util.Calendar
import
java.util.concurrent.ArrayBlockingQueue
import
java.util.concurrent.atomic.AtomicBoolean
/**
* 发送通知的管理类,方便测试限制条件
*/
object
NotificationManager
{
private
val
TAG
=
"NotificationManager"
private
var
sendBeanBlockingQueue
=
ArrayBlockingQueue
<
NotificationSendBean
>(
10
)
fun
submitSendBean
(
bean
:
NotificationSendBean
)
{
try
{
sendBeanBlockingQueue
.
put
(
bean
)
}
catch
(
e
:
Exception
)
{
EventUtils
.
event
(
"Notification_Error"
,
"submitSendBean Exception"
)
LogEx
.
logDebug
(
"canSendNotification"
,
"submitSendBean Exception"
)
}
}
private
var
isStartSendQueue
=
AtomicBoolean
(
false
)
private
var
isUnLimit
:
Boolean
=
if
(
BuildConfig
.
DEBUG
)
false
else
false
fun
startNotificationQueue
()
{
if
(
isStartSendQueue
.
get
())
return
isStartSendQueue
.
set
(
true
)
MainScope
().
launch
(
Dispatchers
.
IO
)
{
while
(
isActive
)
{
val
bean
=
sendBeanBlockingQueue
.
take
()
//测试哪些位置触发
if
(
BuildConfig
.
DEBUG
)
{
if
(!
testWhere
.
contains
(
bean
.
where
))
continue
}
LogEx
.
logDebug
(
TAG
,
"sendNotificationIfCan where=${bean.where}"
)
EventUtils
.
event
(
"Notification_Popup_Start"
,
"where=${bean.where}"
)
if
(!
isUnLimit
)
{
//总的限制条件
if
(!
canSendNotification
(
bean
.
context
))
continue
//当条推送是否可以推送
if
(!
bean
.
canSend
.
invoke
())
continue
}
async
(
Dispatchers
.
Main
)
{
NotificationUiUtil
.
setNotification
(
bean
)
}.
await
()
//上报通知
EventUtils
.
event
(
"Notification_Popup"
,
"where=${bean.where} actionId=${bean.actionId}"
)
//当天次数加一
dayPopupCount
+=
1
//推送时间
lastPopupTime
=
System
.
currentTimeMillis
()
//这条推送回调
bean
.
sendSuccess
?.
invoke
()
async
(
Dispatchers
.
Main
)
{
//发送悬停
NotificationHoverUtils
.
sendHoverNotification
(
bean
)
}.
await
()
}
isStartSendQueue
.
set
(
false
)
}
}
//当天推送次数
private
var
dayPopupCount
=
0
get
()
{
return
AppPreferences
.
getInstance
().
getInt
(
"dayPopupCount_${currentDate()}"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"dayPopupCount_${currentDate()}"
,
value
,
true
)
}
//上次推送时间
private
var
lastPopupTime
=
0L
get
()
{
return
AppPreferences
.
getInstance
().
getLong
(
"lastPopupTime"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"lastPopupTime"
,
value
,
true
)
}
/**
* 总的限制条件
*/
private
fun
canSendNotification
(
context
:
Context
):
Boolean
{
//是否开启推送
if
(!
popupConfigBean
.
popupStatus
)
{
EventUtils
.
event
(
"Notification_Error"
,
"status=${popupConfigBean.popupStatus}"
)
LogEx
.
logDebug
(
"canSendNotification"
,
"status"
)
if
(
BuildConfig
.
DEBUG
)
{
MainScope
().
launch
(
Dispatchers
.
Main
)
{
context
.
toast
(
"配置关闭推送"
)
}
}
return
false
}
//当天推送次数
val
count
=
popupConfigBean
.
popupCount
if
(
dayPopupCount
>
count
)
{
LogEx
.
logDebug
(
"canSendNotification"
,
"count"
)
EventUtils
.
event
(
"Notification_Error"
,
"dayPopupCount=$dayPopupCount count=$count "
)
return
false
}
//判断是否在时间区域
val
start
=
popupConfigBean
.
popupStart
val
end
=
popupConfigBean
.
popupEnd
val
calendar
=
Calendar
.
getInstance
()
val
currentHour
=
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
)
if
(
currentHour
!
in
start
until
end
)
{
LogEx
.
logDebug
(
"canSendNotification"
,
"start-end currentHour=$currentHour start=$start end=$end"
)
EventUtils
.
event
(
"Notification_Error"
,
"start=$start end=$end currentHour=$currentHour"
)
return
false
}
//总时间间隔,单位分钟
val
interval
=
popupConfigBean
.
popupInterval
val
passedTime
=
System
.
currentTimeMillis
()
-
lastPopupTime
if
(
passedTime
<
interval
*
60
*
1000L
)
{
EventUtils
.
event
(
"Notification_Error"
,
"interval=$interval passedTime=$passedTime"
)
LogEx
.
logDebug
(
"canSendNotification"
,
"interval=$interval passedTime=$passedTime"
)
return
false
}
return
true
}
/**
* 值测某些类型
*/
private
var
testWhere
=
listOf
(
POPUP_WHERE_TIMBER
)
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/fcm/notification/NotificationUiUtil.kt
0 → 100644
View file @
86177a80
package
com.base.appzxhy.fcm.notification
import
com.base.appzxhy.bean.NotificationSendBean
/**
* 发送通知UI部分
*/
object
NotificationUiUtil
{
fun
setNotification
(
sendBean
:
NotificationSendBean
)
{
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/fcm/receiver/BatteryStatusReceiver.kt
0 → 100644
View file @
86177a80
package
com.base.appzxhy.fcm.receiver
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
import
android.content.IntentFilter
import
android.os.BatteryManager
import
android.os.Build
import
com.base.appzxhy.bean.NotificationSendBean.Companion.POPUP_WHERE_BATTERY
import
com.base.appzxhy.bean.config.PopupConfigBean.Companion.popupConfigBean
import
com.base.appzxhy.helper.EventUtils
import
com.base.appzxhy.utils.AppPreferences
import
com.base.appzxhy.utils.KotlinExt.currentDate
import
com.base.appzxhy.utils.LogEx
import
kotlin.math.absoluteValue
/**
*电量监听
*/
class
BatteryStatusReceiver
()
:
BroadcastReceiver
()
{
companion
object
{
private
val
TAG
=
"BatteryStatusReceiver"
fun
registerBatteryStatusReceiver
(
context
:
Context
)
{
val
intentFilter
=
IntentFilter
().
apply
{
addAction
(
Intent
.
ACTION_BATTERY_CHANGED
)
addAction
(
Intent
.
ACTION_POWER_CONNECTED
)
addAction
(
Intent
.
ACTION_POWER_DISCONNECTED
)
}
val
applicationContext
=
context
.
applicationContext
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
applicationContext
.
registerReceiver
(
BatteryStatusReceiver
(),
intentFilter
,
Context
.
RECEIVER_EXPORTED
)
}
else
{
applicationContext
.
registerReceiver
(
BatteryStatusReceiver
(),
intentFilter
)
}
}
/**
* 当前天推送数量
*/
private
var
todayBatteryPush
=
0
get
()
{
return
AppPreferences
.
getInstance
().
getInt
(
"todayBatteryPush_${currentDate()}"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"todayBatteryPush_${currentDate()}"
,
value
,
true
)
}
/**
* 上次成功推送
*/
private
var
batteryLastPushTime
=
0L
get
()
{
return
AppPreferences
.
getInstance
().
getLong
(
"batteryLastPushTime"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"batteryLastPushTime"
,
value
,
true
)
}
/**
* 电池电量是否可推送
* 总的限制条件判断后才判断
*/
fun
canBatteryStatusReceiverPush
():
Boolean
{
if
(!
popupConfigBean
.
batteryS
)
return
false
val
popupBatteryCount
=
popupConfigBean
.
popupBatteryValue
val
flag1
=
todayBatteryPush
<=
popupBatteryCount
val
minute
=
60
*
1000L
val
interval
=
popupConfigBean
.
popupBatteryInterval
val
passTime
=
System
.
currentTimeMillis
()
-
batteryLastPushTime
val
flag2
=
batteryLastPushTime
==
0L
||
passTime
>
interval
*
minute
val
flag
=
flag1
&&
flag2
if
(!
flag
)
{
EventUtils
.
event
(
"Notification_Error"
,
"todayBatteryPush=$todayBatteryPush "
+
"popupBatteryCount=$popupBatteryCount where=$POPUP_WHERE_BATTERY"
)
LogEx
.
logDebug
(
"canSendNotification"
,
"Notification_Error todayBatteryPush=$todayBatteryPush "
+
"popupBatteryCount=$popupBatteryCount where=$POPUP_WHERE_BATTERY"
)
}
return
flag
}
/**
* 推送成功后保存值
*/
fun
saveBatteryPushedData
(
where
:
String
,
actionId
:
String
)
{
if
(
where
==
POPUP_WHERE_BATTERY
)
{
todayBatteryPush
+=
1
batteryLastPushTime
=
System
.
currentTimeMillis
()
}
}
}
private
var
currentBatteryPercentage
=
0f
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
?)
{
val
action
=
intent
?.
action
when
(
action
)
{
Intent
.
ACTION_BATTERY_CHANGED
->
{
val
batteryLevel
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_LEVEL
,
-
1
)
val
batteryScale
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_SCALE
,
-
1
)
val
batteryPercentage
=
(
batteryLevel
/
batteryScale
.
toFloat
())
*
100
//避免频繁触发
val
changeValue
=
currentBatteryPercentage
-
batteryPercentage
if
(
batteryPercentage
<
21
&&
changeValue
.
absoluteValue
>=
1f
)
{
//推送次数没有达到限制并且展示的最小时间间隔大于配置时间(分钟)
// sendNotificationIfCan(context, POPUP_WHERE_BATTERY, null)
}
currentBatteryPercentage
=
batteryPercentage
}
Intent
.
ACTION_POWER_CONNECTED
->
{
// sendNotificationIfCan(context, POPUP_WHERE_BATTERY, null)
}
}
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/fcm/receiver/FileJobReceiver.kt
0 → 100644
View file @
86177a80
package
com.base.appzxhy.fcm.receiver
import
android.annotation.SuppressLint
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
class
FileJobReceiver
:
BroadcastReceiver
()
{
@SuppressLint
(
"UnsafeProtectedBroadcastReceiver"
)
override
fun
onReceive
(
context
:
Context
?,
intent
:
Intent
?)
{
// context?.startJob()
context
?.
let
{
// sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_FILE_JOB)
}
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/fcm/receiver/PackageStatusReceiver.kt
0 → 100644
View file @
86177a80
package
com.base.appzxhy.fcm.receiver
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
import
android.content.IntentFilter
import
android.os.Build
import
com.base.appzxhy.bean.config.PopupConfigBean.Companion.POPUP_WHERE_PACKAGE
import
com.base.appzxhy.bean.config.PopupConfigBean.Companion.popupConfigBean
import
com.base.appzxhy.helper.EventUtils
import
com.base.appzxhy.utils.AppPreferences
import
com.base.appzxhy.utils.KotlinExt.currentDate
import
com.base.appzxhy.utils.LogEx
class
PackageStatusReceiver
()
:
BroadcastReceiver
()
{
companion
object
{
private
val
TAG
=
"PackageStatusReceiver"
fun
registerPackageStatusReceiver
(
context
:
Context
)
{
LogEx
.
logDebug
(
TAG
,
"registerPackageStatusReceiver"
)
val
intentFilter
=
IntentFilter
().
apply
{
addAction
(
Intent
.
ACTION_PACKAGE_ADDED
)
addAction
(
Intent
.
ACTION_PACKAGE_REMOVED
)
addDataScheme
(
"package"
)
}
val
applicationContext
=
context
.
applicationContext
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
applicationContext
.
registerReceiver
(
PackageStatusReceiver
(),
intentFilter
,
Context
.
RECEIVER_EXPORTED
)
}
else
{
applicationContext
.
registerReceiver
(
PackageStatusReceiver
(),
intentFilter
)
}
}
/**
* 当前天推送数量
*/
private
var
todayPackagePush
=
0
get
()
{
return
AppPreferences
.
getInstance
().
getInt
(
"todayPackagePush_${currentDate()}"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"todayPackagePush_${currentDate()}"
,
value
,
true
)
}
/**
* 上次成功推送
*/
private
var
packageLastPushTime
=
0L
get
()
{
return
AppPreferences
.
getInstance
().
getLong
(
"packageLastPushTime"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"packageLastPushTime"
,
value
,
true
)
}
/**
* 安装卸载是否可推送
* 总的限制条件判断后才判断
*/
fun
canPackageStatusReceiverPush
():
Boolean
{
if
(!
popupConfigBean
.
packageS
)
return
false
val
popupPackageCount
=
popupConfigBean
.
popupPackageCount
val
flag1
=
todayPackagePush
<=
popupPackageCount
val
minute
=
60
*
1000L
val
interval
=
popupConfigBean
.
popupPackageInterval
val
passTime
=
System
.
currentTimeMillis
()
-
packageLastPushTime
val
flag2
=
packageLastPushTime
==
0L
||
passTime
>
interval
*
minute
val
flag
=
flag1
&&
flag2
if
(!
flag
)
{
EventUtils
.
event
(
"Notification_Error"
,
"todayPackagePush=$todayPackagePush "
+
"popupPackageCount=$popupPackageCount where=$POPUP_WHERE_PACKAGE"
)
LogEx
.
logDebug
(
"canSendNotification"
,
"Notification_Error todayPackagePush=$todayPackagePush "
+
"popupPackageCount=$popupPackageCount where=$POPUP_WHERE_PACKAGE"
)
}
return
flag
}
/**
* 推送成功后保存值
*/
fun
savePackagePushedData
(
where
:
String
,
actionId
:
String
)
{
if
(
where
==
POPUP_WHERE_PACKAGE
)
{
todayPackagePush
+=
1
packageLastPushTime
=
System
.
currentTimeMillis
()
}
}
}
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
?)
{
val
action
=
intent
?.
action
LogEx
.
logDebug
(
TAG
,
"onReceive action=$action"
)
if
(
action
==
Intent
.
ACTION_PACKAGE_ADDED
||
action
==
Intent
.
ACTION_PACKAGE_REMOVED
)
{
// NotificationUiUtil.sendNotificationIfCan(context, POPUP_WHERE_PACKAGE)
}
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/fcm/receiver/ScreenStatusReceiver.kt
0 → 100644
View file @
86177a80
package
com.base.appzxhy.fcm.receiver
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
import
android.content.IntentFilter
import
android.os.Build
import
com.base.appzxhy.bean.config.PopupConfigBean.Companion.POPUP_WHERE_LOCK
import
com.base.appzxhy.bean.config.PopupConfigBean.Companion.popupConfigBean
import
com.base.appzxhy.helper.EventUtils
import
com.base.appzxhy.utils.AppPreferences
import
com.base.appzxhy.utils.KotlinExt.currentDate
import
com.base.appzxhy.utils.LogEx
import
java.util.Objects
class
ScreenStatusReceiver
:
BroadcastReceiver
()
{
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
val
action
=
intent
.
action
when
(
Objects
.
requireNonNull
<
String
?>(
action
))
{
Intent
.
ACTION_SCREEN_ON
->
isDeviceInteractive
=
true
Intent
.
ACTION_SCREEN_OFF
->
{
isDeviceInteractive
=
false
isSecureLockActive
=
true
}
Intent
.
ACTION_USER_PRESENT
->
{
isSecureLockActive
=
false
if
(
isDeviceInteractive
&&
!
isSecureLockActive
)
{
if
(
popupConfigBean
.
screenS
)
{
// sendNotificationIfCan(context, POPUP_WHERE_LOCK, null)
}
}
}
}
}
companion
object
{
private
val
TAG
=
"com.base.appzxhy.fcm.receiver.ScreenStatusReceiver"
var
isDeviceInteractive
:
Boolean
=
true
var
isSecureLockActive
:
Boolean
=
false
fun
registerScreenStatusReceiver
(
context
:
Context
)
{
val
intentFilter
=
IntentFilter
()
intentFilter
.
addAction
(
Intent
.
ACTION_SCREEN_OFF
)
intentFilter
.
addAction
(
Intent
.
ACTION_SCREEN_ON
)
intentFilter
.
addAction
(
Intent
.
ACTION_USER_PRESENT
)
val
applicationContext
=
context
.
applicationContext
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
applicationContext
.
registerReceiver
(
ScreenStatusReceiver
(),
intentFilter
,
Context
.
RECEIVER_EXPORTED
)
}
else
{
applicationContext
.
registerReceiver
(
ScreenStatusReceiver
(),
intentFilter
)
}
}
/**
* 当前天推送数量
*/
private
var
todayScreenPush
=
0
get
()
{
return
AppPreferences
.
getInstance
().
getInt
(
"todayScreenPush_${currentDate()}"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"todayScreenPush_${currentDate()}"
,
value
,
true
)
}
/**
* 上次成功推送
*/
private
var
screenLastPushTime
=
0L
get
()
{
return
AppPreferences
.
getInstance
().
getLong
(
"screenLastPushTime"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"screenLastPushTime"
,
value
,
true
)
}
/**
* 解锁是否可推送
* 总的限制条件判断后才判断
*/
fun
canScreenStatusReceiverPush
():
Boolean
{
if
(!
popupConfigBean
.
popupStatus
)
return
false
val
popupScreenCount
=
popupConfigBean
.
popupScreenCount
val
flag1
=
todayScreenPush
<=
popupScreenCount
val
minute
=
60
*
1000L
val
interval
=
popupConfigBean
.
popupScreenInterval
val
passTime
=
System
.
currentTimeMillis
()
-
screenLastPushTime
val
flag2
=
screenLastPushTime
==
0L
||
passTime
>
interval
*
minute
val
flag
=
flag1
&&
flag2
if
(!
flag
)
{
EventUtils
.
event
(
"Notification_Error"
,
"todayScreenPush=$todayScreenPush "
+
"popupScreenCount=$popupScreenCount where=$POPUP_WHERE_LOCK"
)
LogEx
.
logDebug
(
"canSendNotification"
,
"Notification_Error todayScreenPush=$todayScreenPush "
+
"popupScreenCount=$popupScreenCount where=$POPUP_WHERE_LOCK"
)
}
return
flag
}
/**
* 推送成功后保存值
*/
fun
saveScreenPushedData
(
where
:
String
,
actionId
:
String
)
{
if
(
where
==
POPUP_WHERE_LOCK
)
{
todayScreenPush
+=
1
screenLastPushTime
=
System
.
currentTimeMillis
()
}
}
}
}
\ 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