|
|
|
@ -141,6 +141,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
|
|
|
|
|
loadConfig();
|
|
|
|
|
loadIccid();
|
|
|
|
|
|
|
|
|
|
logger = Logger.getLogger("com.xypower.mpmaster.logger");
|
|
|
|
|
logger.setLevel(Level.ALL);
|
|
|
|
|
// LogFormatter.installFormatter(logger);
|
|
|
|
@ -161,9 +162,12 @@ public class MpMasterService extends Service {
|
|
|
|
|
fi.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File logFile = new File(fi, "log.txt");
|
|
|
|
|
File logFile = new File(fi, "log.%g.txt");
|
|
|
|
|
int logFileLimit = BuildConfig.DEBUG ? (16 * 1024) : (2 * 1024 * 1024);
|
|
|
|
|
int logFileCount = BuildConfig.DEBUG ? 4 : 128;
|
|
|
|
|
|
|
|
|
|
fileHandler = new FileHandler(logFile.getAbsolutePath(), logFileLimit, logFileCount, true);
|
|
|
|
|
|
|
|
|
|
fileHandler = new FileHandler(logFile.getAbsolutePath(), true);//true表示日志内容在文件中追加
|
|
|
|
|
fileHandler.setLevel(Level.ALL);//级别为ALL,记录所有消息
|
|
|
|
|
// fileHandler.
|
|
|
|
|
|
|
|
|
@ -171,7 +175,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
logger.addHandler(fileHandler);
|
|
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
System.out.println("创建文件失败!" + e.getMessage());
|
|
|
|
|
System.out.println("Failed to create directory:" + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -215,9 +219,8 @@ public class MpMasterService extends Service {
|
|
|
|
|
intentFilter.addAction(ACTION_UPD_OTA);
|
|
|
|
|
intentFilter.addAction(ACTION_INSTALL_RESULT);
|
|
|
|
|
intentFilter.addAction(ACTION_UNINSTALL_RESULT);
|
|
|
|
|
if (!mSeparateNetwork) {
|
|
|
|
|
intentFilter.addAction(MicroPhotoContext.ACTION_HEARTBEAT_MP);
|
|
|
|
|
}
|
|
|
|
|
intentFilter.addAction(MicroPhotoContext.ACTION_HEARTBEAT_MP);
|
|
|
|
|
|
|
|
|
|
registerReceiver(mAlarmReceiver, intentFilter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -479,7 +482,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
mService.startMpApp();
|
|
|
|
|
|
|
|
|
|
} else if (TextUtils.equals(MicroPhotoContext.ACTION_HEARTBEAT_MP, action)) {
|
|
|
|
|
if (!mService.mSeparateNetwork && !mService.mMntnMode && !mService.mQuickHbMode) {
|
|
|
|
|
if (!mService.mSeparateNetwork || (mService.mMntnMode || mService.mQuickHbMode)) {
|
|
|
|
|
mService.logger.info("Heartbeat Timer Fired By MpAPP ACTION=" + action);
|
|
|
|
|
|
|
|
|
|
mService.registerHeartbeatTimer(mService.mPreviousHeartbeatTime + mService.mHeartbeatDuration * 1000);
|
|
|
|
@ -554,24 +557,21 @@ public class MpMasterService extends Service {
|
|
|
|
|
if (mAbsHeartbeatTimes != null && mAbsHeartbeatTimes.length > 0) {
|
|
|
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
long heartTimeMills = currentTimeMillis + timeout * 1000;
|
|
|
|
|
Arrays.sort(mAbsHeartbeatTimes);
|
|
|
|
|
|
|
|
|
|
Date dt = new Date();
|
|
|
|
|
for (int i = 0; i < mAbsHeartbeatTimes.length; i++) {
|
|
|
|
|
int mAbsHeartbeatTime = mAbsHeartbeatTimes[i];
|
|
|
|
|
int hour = mAbsHeartbeatTime / 60;
|
|
|
|
|
int minute = mAbsHeartbeatTime % 60;
|
|
|
|
|
if (hour >= 24) {
|
|
|
|
|
return;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//设置提醒时间
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
//这里时区需要设置一下,不然会有8个小时的时间差
|
|
|
|
|
calendar.setTimeZone(TimeZone.getTimeZone("GMT+8"));
|
|
|
|
|
//设置每天为13:50点提醒
|
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
|
|
|
|
calendar.set(Calendar.MINUTE, minute);
|
|
|
|
|
calendar.set(Calendar.SECOND, 0);
|
|
|
|
|
calendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
|
long selecttime = calendar.getTimeInMillis();
|
|
|
|
|
|
|
|
|
|
dt.setHours(hour);
|
|
|
|
|
dt.setMinutes(minute);
|
|
|
|
|
dt.setSeconds(0);
|
|
|
|
|
|
|
|
|
|
long selecttime = dt.getTime();
|
|
|
|
|
if (selecttime > currentTimeMillis && selecttime < heartTimeMills) {
|
|
|
|
|
closestTime = selecttime;
|
|
|
|
|
break;
|
|
|
|
@ -581,9 +581,12 @@ public class MpMasterService extends Service {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (closestTime > 0) {
|
|
|
|
|
registerAbsHeartbeatTimer(closestTime);
|
|
|
|
|
|
|
|
|
|
if (closestTime > 0) {
|
|
|
|
|
registerAbsHeartbeatTimer(closestTime);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
registerHeartbeatTimer(SystemClock.elapsedRealtime() + timeout * 1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|