#!/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重启一次
标签:-%,executedToday,false,ctime,app,保活,magisk,log From: https://www.cnblogs.com/linuxxx/p/18337043