Commit 85a1d00d authored by wanglei's avatar wanglei

...

parent 0d63c5ec
......@@ -102,9 +102,6 @@ object NotificationUiUtil {
if (where == POPUP_WHERE_TIMBER) {
interval = AppPreferences.getInstance().getString(popup_timer_interval, "7").toInt()
}
if (where == POPUP_WHERE_LOCK) {
interval = AppPreferences.getInstance().getString(popup_lock_interval, "1").toInt()
}
if (where == POPUP_WHERE_FCM) {
interval = AppPreferences.getInstance().getString(popup_fcm_interval, "1").toInt()
}
......@@ -168,14 +165,17 @@ object NotificationUiUtil {
if (where == POPUP_WHERE_PACKAGE) {
canPush = PackageStatusReceiver.canPackageStatusReceiverPush()
}
if (where == POPUP_WHERE_LOCK) {
canPush = ScreenStatusReceiver.canScreenStatusReceiverPush()
}
return canPush
}
private fun saveOtherPopupData(where: String, actionId: String) {
BatteryStatusReceiver.saveBatteryPushedData(actionId, where)
PackageStatusReceiver.savePackagePushedData(actionId, where)
BatteryStatusReceiver.saveBatteryPushedData(where, actionId)
PackageStatusReceiver.savePackagePushedData(where, actionId)
ScreenStatusReceiver.saveScreenPushedData(where, actionId)
}
fun setActionNotification(context: Context, actionId: String) {
......
......@@ -88,6 +88,7 @@ class PackageStatusReceiver() : BroadcastReceiver() {
}
}
}
override fun onReceive(context: Context, intent: Intent?) {
......
......@@ -43,6 +43,10 @@ object PopupConstObject {
const val popup_package_count = "popup_package_count"
const val popup_package_interval = "popup_package_interval"
//解锁可配置值
const val popup_screen_count = "popup_screen_count"
const val popup_screen_interval = "popup_screen_interval"
const val ACTION_STAY_HOME = "action_stay_home"
const val ACTION_STAY_MY_CODE = "action_stay_my_code"
......
package com.base.locationsharewhite.fcm;
package com.base.locationsharewhite.fcm
import static com.base.locationsharewhite.fcm.PopupConstObject.lockS;
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.NotificationUiUtil.sendNotificationIfCan
import com.base.locationsharewhite.fcm.PopupConstObject.POPUP_WHERE_LOCK
import com.base.locationsharewhite.fcm.PopupConstObject.lockS
import com.base.locationsharewhite.fcm.PopupConstObject.popup_screen_count
import com.base.locationsharewhite.fcm.PopupConstObject.popup_screen_interval
import com.base.locationsharewhite.helper.EventUtils
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.KotlinExt.currentDate
import java.util.Objects
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
class ScreenStatusReceiver : BroadcastReceiver() {
import com.base.locationsharewhite.utils.AppPreferences;
import com.base.locationsharewhite.utils.LogEx;
import java.util.Objects;
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) {
val secureSetting = AppPreferences.getInstance().getString(lockS, "1").toInt()
if (secureSetting == 1) {
sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_LOCK, null)
}
}
}
}
}
public class ScreenStatusReceiver extends BroadcastReceiver {
private static boolean isDeviceInteractive = true;
private static boolean isSecureLockActive = false;
companion object {
var isDeviceInteractive: Boolean = true
var isSecureLockActive: Boolean = false
public static void setupScreenStatusListener(Context context) {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_USER_PRESENT);
fun setupScreenStatusListener(context: Context) {
val intentFilter = IntentFilter()
intentFilter.addAction(Intent.ACTION_SCREEN_OFF)
intentFilter.addAction(Intent.ACTION_SCREEN_ON)
intentFilter.addAction(Intent.ACTION_USER_PRESENT)
final Context applicationContext = context.getApplicationContext();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
applicationContext.registerReceiver(new ScreenStatusReceiver(), intentFilter, Context.RECEIVER_EXPORTED);
} else {
applicationContext.registerReceiver(new ScreenStatusReceiver(), intentFilter);
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)
}
}
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (Objects.requireNonNull(action)) {
case Intent.ACTION_SCREEN_ON:
setDeviceInteractive(true);
break;
case Intent.ACTION_SCREEN_OFF:
setDeviceInteractive(false);
setSecureLockActive(true);
break;
case Intent.ACTION_USER_PRESENT:
setSecureLockActive(false);
if (isDeviceInteractive() && !isSecureLockActive()) {
int secureSetting = Integer.parseInt(AppPreferences.getInstance().getString(lockS, "1"));
if (secureSetting == 1) {
NotificationUiUtil.INSTANCE.sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_LOCK, null);
}
}
break;
}
}
private void setDeviceInteractive(boolean interactive) {
isDeviceInteractive = interactive;
}
/**
* 当前天推送数量
*/
private var todayScreenPush = 0
get() {
return AppPreferences.getInstance().getInt("todayScreenPush_${currentDate()}", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("todayScreenPush_${currentDate()}", value, true)
}
public static boolean isDeviceInteractive() {
return isDeviceInteractive;
}
/**
* 上次成功推送
*/
private var screenLastPushTime = 0L
get() {
return AppPreferences.getInstance().getLong("screenLastPushTime", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("screenLastPushTime", value, true)
}
private void setSecureLockActive(boolean active) {
isSecureLockActive = active;
}
public static boolean isSecureLockActive() {
return isSecureLockActive;
/**
* 解锁是否可推送
* 总的限制条件判断后才判断
*/
fun canScreenStatusReceiverPush(): Boolean {
val popupScreenCount = AppPreferences.getInstance().getString(popup_screen_count, "20").toInt()
val flag1 = todayScreenPush <= popupScreenCount
val default = 60 * 1000L
val interval = AppPreferences.getInstance().getString(popup_screen_interval, default.toString()).toLong()
val passTime = System.currentTimeMillis() - screenLastPushTime
val flag2 = screenLastPushTime == 0L || passTime > interval
EventUtils.event(
"Notification_Error",
"todayScreenPush=$todayScreenPush popupScreenCount=$popupScreenCount where=$POPUP_WHERE_LOCK"
)
return flag1 && flag2
}
/**
* 推送成功后保存值
*/
fun saveScreenPushedData(where: String, actionId: String) {
if (where == POPUP_WHERE_LOCK) {
todayScreenPush += 1
screenLastPushTime = System.currentTimeMillis()
}
}
}
}
\ 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