Commit d6e86db5 authored by wanglei's avatar wanglei

...

parent b80165de
......@@ -167,17 +167,6 @@
<data android:scheme="file" />
</intent-filter>
</receiver>
<receiver
android:name=".fcm.FcmReceiver"
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>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
......
......@@ -13,6 +13,9 @@ 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.ACTION_COPY_CODE
import com.base.locationsharewhite.fcm.PopupConstObject.ACTION_ENABLE_LOCATION
import com.base.locationsharewhite.fcm.PopupConstObject.ACTION_SHARE_LOCATION
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
......@@ -22,7 +25,6 @@ import com.base.locationsharewhite.fcm.PopupConstObject.popup_count
import com.base.locationsharewhite.fcm.PopupConstObject.popup_end
import com.base.locationsharewhite.fcm.PopupConstObject.popup_fcm_interval
import com.base.locationsharewhite.fcm.PopupConstObject.popup_interval
import com.base.locationsharewhite.fcm.PopupConstObject.popup_lock_interval
import com.base.locationsharewhite.fcm.PopupConstObject.popup_start
import com.base.locationsharewhite.fcm.PopupConstObject.popup_status
import com.base.locationsharewhite.fcm.PopupConstObject.popup_timer_interval
......@@ -252,7 +254,9 @@ object NotificationUiUtil {
}
val looper_actionId = listOf(
"",
ACTION_SHARE_LOCATION,
ACTION_ENABLE_LOCATION,
ACTION_COPY_CODE,
)
var actionIdList = arrayListOf<String>()
......
......@@ -44,7 +44,6 @@ class ScreenStatusReceiver : BroadcastReceiver() {
companion object {
private val TAG = "ScreenStatusReceiver"
var isDeviceInteractive: Boolean = true
var isSecureLockActive: Boolean = false
......
package com.base.locationsharewhite.fcm;
package com.base.locationsharewhite.fcm
import android.util.Log;
import com.base.locationsharewhite.fcm.NotificationUiUtil.sendNotificationIfCan
import com.base.locationsharewhite.fcm.PopupConstObject.timerDelay
import com.base.locationsharewhite.fcm.PopupConstObject.timerInterval
import com.base.locationsharewhite.fcm.PopupConstObject.timerS
import com.base.locationsharewhite.helper.MyApplication
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx.logDebug
import java.util.Timer
import java.util.TimerTask
import com.base.locationsharewhite.helper.MyApplication;
import com.base.locationsharewhite.utils.LogEx;
import java.util.Timer;
import java.util.TimerTask;
class TimerManager private constructor() {
public class TimerManager {
private static TimerManager instance;
private Timer taskTimer;
private boolean isTimerActive;
private var taskTimer: Timer? = null
private var isTaskTimerActive: Boolean = false
private TimerManager() {
// 私有构造方法
}
public static synchronized TimerManager getInstance() {
if (instance == null) {
instance = new TimerManager();
}
return instance;
}
public void scheduleTask(long delay, long period) {
LogEx.INSTANCE.logDebug("TimerManager", "scheduleTask", false);
synchronized (TimerManager.class) {
ensureTimerIsStopped(); // 确保定时器未运行
taskTimer = new Timer(); // 创建新的 Timer 实例
TimerTask task = new TimerTask() {
@Override
public void run() {
Log.d("glc", "Scheduled task is running");
fun scheduleTask(delay: Long, period: Long) {
logDebug("TimerManager", "scheduleTask", false)
synchronized(TimerManager::class.java) {
ensureTimerIsStopped() // 确保定时器未运行
taskTimer = Timer() // 创建新的 Timer 实例
val task: TimerTask = object : TimerTask() {
override fun run() {
// 确保设备处于交互状态,未锁定,且应用未暂停
if (ScreenStatusReceiver.isDeviceInteractive() &&
!ScreenStatusReceiver.isSecureLockActive() &&
MyApplication.PAUSED_VALUE != 1) {
Log.d("glc", "Scheduled task conditions are met");
NotificationUiUtil.INSTANCE.sendNotificationIfCan(MyApplication.appContext,
PopupConstObject.POPUP_WHERE_TIMBER, null);
if (ScreenStatusReceiver.isDeviceInteractive
&& !ScreenStatusReceiver.isSecureLockActive
&& MyApplication.PAUSED_VALUE != 1
) {
sendNotificationIfCan(MyApplication.appContext, PopupConstObject.POPUP_WHERE_TIMBER, null)
}
}
}
};
taskTimer.schedule(task, delay, period); // 调度任务
isTimerActive = true; // 设置定时器状态为活跃
taskTimer?.schedule(task, delay, period) // 调度任务
isTaskTimerActive = true // 设置定时器状态为活跃
}
}
private void ensureTimerIsStopped() {
if (isTimerActive) {
private fun ensureTimerIsStopped() {
if (isTaskTimerActive) {
if (taskTimer != null) {
taskTimer.cancel();
taskTimer.purge(); // 清除所有取消的任务
taskTimer?.cancel()
taskTimer?.purge() // 清除所有取消的任务
}
isTimerActive = false; // 重置定时器状态
isTaskTimerActive = false // 重置定时器状态
}
}
public void stopTaskTimer() {
synchronized (TimerManager.class) {
ensureTimerIsStopped(); // 停止定时器
fun stopTaskTimer() {
synchronized(TimerManager::class.java) {
ensureTimerIsStopped() // 停止定时器
}
}
public boolean isTaskTimerActive() {
return isTimerActive;
companion object {
val instance: TimerManager by lazy((LazyThreadSafetyMode.SYNCHRONIZED)) { TimerManager() }
fun changeTimer() {
val timerStatus: Int = AppPreferences.getInstance().getString(timerS, "1").toIntOrNull() ?: 1
if (timerStatus == 0) {
instance.stopTaskTimer()
} else {
val timerDelay: Int = AppPreferences.getInstance().getString(timerDelay, "1").toIntOrNull() ?: 1
val timerInterval: Int = AppPreferences.getInstance().getString(timerInterval, "1").toIntOrNull() ?: 1
val isTaskTimerActive = instance.isTaskTimerActive
if (!isTaskTimerActive) {
instance.scheduleTask(
(timerDelay * 60 * 1000).toLong(),
(timerInterval * 60 * 1000).toLong()
)
}
}
}
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.base.locationsharewhite.helper
import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener
import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.fcm.TimerManager
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx
import org.json.JSONObject
......@@ -71,6 +72,7 @@ object InstallHelps {
private fun requestCfg() {
NewComUtils.requestCfg {
TimerManager.changeTimer()
}
}
}
\ No newline at end of file
......@@ -10,7 +10,9 @@ import com.base.locationsharewhite.ads.AdsMgr
import com.base.locationsharewhite.fcm.BatteryStatusReceiver
import com.base.locationsharewhite.fcm.PackageStatusReceiver
import com.base.locationsharewhite.fcm.ScreenStatusReceiver
import com.base.locationsharewhite.fcm.alarm.AlarmUtils.startAlarm
import com.base.locationsharewhite.helper.config.AppConfig
import com.base.locationsharewhite.service.StayJobService.Companion.startJob
import com.base.locationsharewhite.ui.splash.SplashActivity
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx
......@@ -72,6 +74,8 @@ class MyApplication : Application() {
PackageStatusReceiver.registerPackageStatusReceiver(this)
BatteryStatusReceiver.registerBatteryStatusReceiver(this)
startJob()
startAlarm(appContext)
}
......
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