Commit 4fbef966 authored by wanglei's avatar wanglei

...

parent 3f40efe6
......@@ -113,11 +113,6 @@
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<service
android:name=".service.StayNotificationService"
android:foregroundServiceType="dataSync" />
<service
android:name=".fcm.MessagingService"
android:exported="false">
......@@ -125,7 +120,53 @@
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".service.StayJobService"
android:exported="false"
android:foregroundServiceType="dataSync"
android:permission="android.permission.BIND_JOB_SERVICE" />
<receiver
android:name=".fcm.FcmReceiver"
android:directBootAware="true"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="confine.scream" />
</intent-filter>
</receiver>
<receiver
android:name=".fcm.alarm.AlarmJobReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
<intent-filter>
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_EJECT" />
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<data android:scheme="file" />
</intent-filter>
</receiver>
<receiver
android:name=".fcm.FcmReceiver"
android:exported="true"
......
package com.base.locationsharewhite.fcm
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.locationsharewhite.fcm.PopupConstObject.POPUP_WHERE_BATTERY
import com.base.locationsharewhite.fcm.PopupConstObject.popup_battery_count
import com.base.locationsharewhite.fcm.PopupConstObject.popup_battery_interval
import com.base.locationsharewhite.helper.EventUtils
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.KotlinExt.currentDate
/**
*电量监听
*/
class BatteryStatusReceiver() : BroadcastReceiver() {
companion object {
fun registerBatteryReceiver(context: Context) {
val intentFilter = IntentFilter().apply {
addAction(Intent.ACTION_BATTERY_CHANGED)
}
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 {
val popupBatteryCount = AppPreferences.getInstance().getString(popup_battery_count, "20").toInt()
val flag1 = todayBatteryPush <= popupBatteryCount
val default = 60 * 60 * 1000L
val interval = AppPreferences.getInstance().getString(popup_battery_interval, default.toString()).toLong()
val passTime = System.currentTimeMillis() - batteryLastPushTime
val flag2 = batteryLastPushTime == 0L || passTime > interval
EventUtils.event(
"Notification_Error",
"todayBatteryPush=$todayBatteryPush popupBatteryCount=$popupBatteryCount where=$POPUP_WHERE_BATTERY"
)
return flag1 && flag2
}
/**
* 推送成功后保存值
*/
fun saveBatteryPushedData(where: String, actionId: String) {
if (where == POPUP_WHERE_BATTERY) {
todayBatteryPush += 1
batteryLastPushTime = System.currentTimeMillis()
}
}
}
override fun onReceive(context: Context, intent: Intent?) {
val action = intent?.action
if (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
if (batteryPercentage < 21) {
//推送次数没有达到限制并且展示的最小时间间隔大于配置时间(分钟)
NotificationUiUtil.sendNotificationIfCan(context, where = POPUP_WHERE_BATTERY)
}
}
}
}
\ No newline at end of file
......@@ -13,8 +13,10 @@ import androidx.core.app.NotificationCompat
import androidx.core.graphics.drawable.IconCompat
import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.R
import com.base.locationsharewhite.fcm.PopupConstObject.POPUP_WHERE_BATTERY
import com.base.locationsharewhite.fcm.PopupConstObject.POPUP_WHERE_FCM
import com.base.locationsharewhite.fcm.PopupConstObject.POPUP_WHERE_LOCK
import com.base.locationsharewhite.fcm.PopupConstObject.POPUP_WHERE_PACKAGE
import com.base.locationsharewhite.fcm.PopupConstObject.POPUP_WHERE_TIMBER
import com.base.locationsharewhite.fcm.PopupConstObject.popup_count
import com.base.locationsharewhite.fcm.PopupConstObject.popup_end
......@@ -26,7 +28,6 @@ import com.base.locationsharewhite.fcm.PopupConstObject.popup_status
import com.base.locationsharewhite.fcm.PopupConstObject.popup_timer_interval
import com.base.locationsharewhite.helper.EventUtils
import com.base.locationsharewhite.helper.MyApplication
import com.base.locationsharewhite.helper.config.ConstConfig.ACTION_APP_PROCESS
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx
import java.text.SimpleDateFormat
......@@ -70,7 +71,7 @@ object NotificationUiUtil {
AppPreferences.getInstance().put("lastPopupTime", value, true)
}
fun canSendNotification(where: String, actionId: String): Boolean {
private fun canSendNotification(where: String, actionId: String): Boolean {
//是否开启推送
val status = AppPreferences.getInstance().getString(popup_status, "1").toInt()
if (status == 0) {
......@@ -124,8 +125,12 @@ object NotificationUiUtil {
val actionId = id ?: getNextActionId()
//总的限制条件
if (!canSendNotification(where, actionId)) return
//特定类限制条件
if (!canOtherSend(where, actionId)) return
if (MyApplication.PAUSED_VALUE == 1) {
LogEx.logDebug(TAG, "APP Resumed")
return
......@@ -142,11 +147,37 @@ object NotificationUiUtil {
//推送时间
lastPopupTime = System.currentTimeMillis()
//保存其他特定场景的推送判断条件
saveOtherPopupData(actionId, where)
//悬停通知
hoverActionId = actionId
NotificationHoverUtils.sendHoverNotification(context)
}
/**
* 特定类型的是否可以推送
*/
private fun canOtherSend(where: String, actionId: String): Boolean {
var canPush = true
if (where == POPUP_WHERE_BATTERY) {
canPush = BatteryStatusReceiver.canBatteryStatusReceiverPush()
}
if (where == POPUP_WHERE_PACKAGE) {
canPush = PackageStatusReceiver.canPackageStatusReceiverPush()
}
return canPush
}
private fun saveOtherPopupData(where: String, actionId: String) {
BatteryStatusReceiver.saveBatteryPushedData(actionId, where)
PackageStatusReceiver.savePackagePushedData(actionId, where)
}
fun setActionNotification(context: Context, actionId: String) {
// val bigRemoteViews = RemoteViews(MyApplication.appContext.packageName, R.layout.notification_message)
// val smallRemoteViews = RemoteViews(MyApplication.appContext.packageName, R.layout.notification_message)
......@@ -221,7 +252,7 @@ object NotificationUiUtil {
}
val looper_actionId = listOf(
ACTION_APP_PROCESS,
"",
)
var actionIdList = arrayListOf<String>()
......
package com.base.locationsharewhite.fcm
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import com.base.locationsharewhite.fcm.PopupConstObject.POPUP_WHERE_PACKAGE
import com.base.locationsharewhite.fcm.PopupConstObject.popup_package_count
import com.base.locationsharewhite.fcm.PopupConstObject.popup_package_interval
import com.base.locationsharewhite.helper.EventUtils
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.KotlinExt.currentDate
class PackageStatusReceiver() : BroadcastReceiver() {
companion object {
fun registerBatteryReceiver(context: Context) {
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 {
val popupPackageCount = AppPreferences.getInstance().getString(popup_package_count, "20").toInt()
val flag1 = todayPackagePush <= popupPackageCount
val default = 60 * 1000L
val interval = AppPreferences.getInstance().getString(popup_package_interval, default.toString()).toLong()
val passTime = System.currentTimeMillis() - packageLastPushTime
val flag2 = packageLastPushTime == 0L || passTime > interval
EventUtils.event(
"Notification_Error",
"todayPackagePush=$todayPackagePush popupPackageCount=$popupPackageCount where=$POPUP_WHERE_PACKAGE"
)
return flag1 && flag2
}
/**
* 推送成功后保存值
*/
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
if (action == Intent.ACTION_PACKAGE_ADDED || action == Intent.ACTION_PACKAGE_REMOVED) {
NotificationUiUtil.sendNotificationIfCan(context, POPUP_WHERE_PACKAGE)
}
}
}
\ No newline at end of file
package com.base.locationsharewhite.fcm
import com.base.locationsharewhite.utils.AppPreferences
object PopupConstObject {
//推送触发位置
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_HOVER_HANDLE = "hover_handle"//悬停调用
......@@ -34,14 +35,14 @@ object PopupConstObject {
const val timerDelay = "timerDelay"
const val timerInterval = "timerInterval"
var topic_number = ""
get() {
return AppPreferences.getInstance().getString("topic_number", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("topic_number", value, true)
}
//电量可配置值
const val popup_battery_count = "popup_battery_count"
const val popup_battery_interval = "popup_battery_interval"
//安装卸载可配置值
const val popup_package_count = "popup_package_count"
const val popup_package_interval = "popup_package_interval"
const val ACTION_STAY_HOME = "action_stay_home"
const val ACTION_STAY_MY_CODE = "action_stay_my_code"
......@@ -49,7 +50,7 @@ object PopupConstObject {
const val ACTION_STAY_SETTING = "action_stay_setting"
const val ACTION_SHARE_LOCATION = "action_share_location"
const val ACTION_ENABLE_LOCATION = "action_enable_location"
const val ACTION_COPY_CODE="action_copy_code"
const val ACTION_COPY_CODE = "action_copy_code"
}
\ No newline at end of file
......@@ -45,7 +45,6 @@ public class ScreenStatusReceiver extends BroadcastReceiver {
setSecureLockActive(true);
break;
case Intent.ACTION_USER_PRESENT:
LogEx.INSTANCE.logDebug("ScreenStatusReceiver", "ACTION_USER_PRESENT", false);
setSecureLockActive(false);
if (isDeviceInteractive() && !isSecureLockActive()) {
int secureSetting = Integer.parseInt(AppPreferences.getInstance().getString(lockS, "1"));
......
package com.base.pdfreaderallpdfreader.fcm.alarm
package com.base.locationsharewhite.fcm.alarm
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.fcm.NotificationUiUtil.sendNotificationIfCan
import com.base.locationsharewhite.fcm.PopupConstObject
import com.base.locationsharewhite.helper.EventUtils
......@@ -19,17 +18,12 @@ class AlarmJobReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) {
LogEx.logDebug(TAG, "AlarmJobReceiver onReceive")
EventUtils.event("alarm_push")
var firstAlemtime = AppPreferences.getInstance().getLong("firstAlemtime", 0L)
if (BuildConfig.DEBUG) {
firstAlemtime = 1
val lastAlarmTime = AppPreferences.getInstance().getLong("lastAlarmTime", 0L)
val currentTime = System.currentTimeMillis()
if (lastAlarmTime == 0L || currentTime - lastAlarmTime >= 1000 * 30 * 60) {
sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_ALARM)
AppPreferences.getInstance().put("lastAlarmTime", System.currentTimeMillis())
}
if (firstAlemtime > 0) {
val leatTime = System.currentTimeMillis()
if (leatTime - firstAlemtime >= 1000 * 30 * 60) {
sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_ALARM)
}
}
AppPreferences.getInstance().put("firstAlemtime", System.currentTimeMillis())
return
}
}
\ No newline at end of file
......@@ -8,7 +8,6 @@ import android.content.Intent
import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.fcm.work.RepeatingWorker.Companion.schedulePeriodicWork
import com.base.locationsharewhite.service.StayJobService.Companion.startJob
import com.base.pdfreaderallpdfreader.fcm.alarm.AlarmJobReceiver
import java.util.Calendar
object AlarmUtils {
......@@ -25,7 +24,7 @@ object AlarmUtils {
calendar.set(Calendar.HOUR_OF_DAY, 6)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
var delay = 1800000L
var delay = 30 * 60 * 1000L
if (BuildConfig.DEBUG) {
delay = 1 * 60 * 1000L
}
......
......@@ -8,6 +8,7 @@ import android.text.TextUtils
import com.base.locationsharewhite.ads.AdsConfigBean
import com.base.locationsharewhite.ads.AdsMgr
import com.base.locationsharewhite.bean.ConstObject.topic_number
import com.base.locationsharewhite.fcm.ScreenStatusReceiver
import com.base.locationsharewhite.helper.config.AppConfig
import com.base.locationsharewhite.ui.splash.SplashActivity
import com.base.locationsharewhite.utils.AppPreferences
......@@ -59,21 +60,14 @@ class MyApplication : Application() {
fun initApp() {
// FacebookSdk.sdkInitialize(applicationContext)
var topicNumber = System.currentTimeMillis().toFormatMinute()
LogEx.logDebug(TAG, "topicNumber=$topicNumber")
if (topic_number.isNotEmpty()) {
topicNumber = topic_number
} else {
topic_number = topicNumber
}
val topic = AppConfig.packageName + "_push_$topicNumber"
val topic = AppConfig.packageName + "_push"
LogEx.logDebug(TAG, "topic=${topic}")
// FCMManager.initFirebase(this)
// FCMManager.subscribeToTopic(topic)
FCMManager.initFirebase(this)
FCMManager.subscribeToTopic(topic)
InstallHelps.init()
initAdSdk()
initLifeListener()
// ScreenStatusReceiver.setupScreenStatusListener(this)
ScreenStatusReceiver.setupScreenStatusListener(this)
}
......
package com.base.locationsharewhite.utils
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
......@@ -57,4 +58,10 @@ object KotlinExt {
return stringBuilder.toString()
}
fun currentDate(): String {
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
val currentDate = Calendar.getInstance().time
return dateFormat.format(currentDate)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment