/sys/power/wake_lock targetTime="4" targetTime2="16" ">

magisk模块 实现app 保活

magisk模块 实现app 保活

#!/system/bin/sh

MODDIR=${0%/*}

while [ "$(getprop sys.boot_completed)" != "1" ]; do

sleep 1

done

echo "PowerManagerService.noSuspend" > /sys/power/wake_lock

targetTime="4"

targetTime2="16"

executedToday=false

appPackage="com.idormy.sms.forwarder"

appActivity="com.idormy.sms.forwarder/com.idormy.sms.forwarder.MainActivity"

log() {

echo "$(date '+%Y-%m-%d %H:%M:%S') $1"

}

while true; do

# 每30分钟执行一次

log "定时唤醒"

am start -n "$appActivity"

sleep 1800 # 30分钟

ctime=$(date +"%H")

currentDate=$(date +"%Y-%m-%d")

log "Current hour: $ctime"

log "Target times: $targetTime, $targetTime2"

if [ "$ctime" = "$targetTime" ] || [ "$ctime" = "$targetTime2" ]; then

if [ "$executedToday" = false ]; then

log "每天4点杀死app重新启动"

am force-stop "$appPackage"

sleep 2

am start -n "$appActivity"

executedToday=true

log "Executed restart at $currentDate $ctime:00"

else

log "Already executed restart today."

fi

else

# 重置标志变量,每天0点之后允许再次执行

if [ "$ctime" = "00" ]; then

executedToday=false

log "Reset executedToday flag"

fi

log "It is not the target time, skipping force-stop and restart"

fi

done

每30分钟自动唤醒一次, 每天4点杀app重启一次

相关推荐

《CSGO》国际服加速器哪个好?好用的加速器推荐
极品飞车集结平民赛车推荐 极品飞车集结平民赛车有哪些
新网云主机搭建,新网云主机如何快速搭建?
365bet备用网

新网云主机搭建,新网云主机如何快速搭建?

📅 09-07 👁️ 7176
苹果7的VR体验如何?(探索苹果7的VR功能,揭秘其影响因素)
伊奥思 X6 金属 入耳式耳机 8.5元包邮
mobileBET365

伊奥思 X6 金属 入耳式耳机 8.5元包邮

📅 07-25 👁️ 2082
粉蒸鲢鱼的做法与步骤
mobileBET365

粉蒸鲢鱼的做法与步骤

📅 08-20 👁️ 9275