运维增加校时功能

master
Matthew 11 months ago
parent 2d493b0edc
commit 3cd4bdff3d

@ -68,6 +68,7 @@ public class MicroPhotoContext {
public int separateNetwork = 1; // Default is 1 public int separateNetwork = 1; // Default is 1
public int mpappMonitorTimeout = 30 * 60000; // 30 minutes public int mpappMonitorTimeout = 30 * 60000; // 30 minutes
public int timeForKeepingLogs = 15; // Unit day public int timeForKeepingLogs = 15; // Unit day
public boolean syncTime = false;
public String getUrl() { public String getUrl() {
if (TextUtils.isEmpty(server)) { if (TextUtils.isEmpty(server)) {
@ -276,6 +277,7 @@ public class MicroPhotoContext {
masterConfig.usingAbsHbTime = jsonObject.optInt("usingAbsHbTime", 0); masterConfig.usingAbsHbTime = jsonObject.optInt("usingAbsHbTime", 0);
masterConfig.separateNetwork = jsonObject.optInt("separateNetwork", 1); masterConfig.separateNetwork = jsonObject.optInt("separateNetwork", 1);
masterConfig.timeForKeepingLogs = jsonObject.optInt("timeForKeepingLogs", 15); masterConfig.timeForKeepingLogs = jsonObject.optInt("timeForKeepingLogs", 15);
masterConfig.syncTime = jsonObject.optInt("syncTime", 0) != 0;
// masterConfig.mpappMonitorTimeout = jsonObject.optInt("mpappMonitorTimeout", 30 * 60000); // masterConfig.mpappMonitorTimeout = jsonObject.optInt("mpappMonitorTimeout", 30 * 60000);
int mpappMonitorTimeout = jsonObject.optInt("mpappMonitorTimeout", 30 * 60000); int mpappMonitorTimeout = jsonObject.optInt("mpappMonitorTimeout", 30 * 60000);

@ -281,6 +281,11 @@ public class AppMaster {
httpURLConnection.setDoOutput(true); httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestProperty("Accept-Cmds", "Multiple"); httpURLConnection.setRequestProperty("Accept-Cmds", "Multiple");
final boolean shouldSyncTime = mService.shouldSyncTime();
final long requestSyncTime = System.currentTimeMillis();
if (shouldSyncTime) {
httpURLConnection.setRequestProperty("ReqSyncTime", Long.toString(requestSyncTime));
}
// postParams(httpURLConnection.getOutputStream(), postParams); // postParams(httpURLConnection.getOutputStream(), postParams);
buildParams(httpURLConnection.getOutputStream(), postParams); buildParams(httpURLConnection.getOutputStream(), postParams);
@ -292,6 +297,24 @@ public class AppMaster {
if (responseCode == HttpURLConnection.HTTP_OK) { if (responseCode == HttpURLConnection.HTTP_OK) {
//在子线程中不能操作UI线程通过handler在UI线程中进行操作 //在子线程中不能操作UI线程通过handler在UI线程中进行操作
// handler.sendEmptyMessage(0x00); // handler.sendEmptyMessage(0x00);
// httpURLConnection.get
try {
if (shouldSyncTime) {
long localResponseTime = System.currentTimeMillis();
Map<String, List<String>> responseHeaders = httpURLConnection.getHeaderFields();
if (responseHeaders != null && responseHeaders.containsKey("ResSyncTime")) {
List<String> resSyncTimes = responseHeaders.get("ResSyncTime");
if (resSyncTimes != null && !resSyncTimes.isEmpty()) {
long serverSyncTime = Long.parseLong(resSyncTimes.get(0));
mService.updateTime(serverSyncTime + (localResponseTime - requestSyncTime) / 2);
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
String response = convertStreamToString(inputStream); String response = convertStreamToString(inputStream);
process(response); process(response);
} }

@ -99,6 +99,7 @@ public class MpMasterService extends Service {
private int mHeartbeatDuration = 600; // Unit: second 10m = 10 * 60s private int mHeartbeatDuration = 600; // Unit: second 10m = 10 * 60s
private long mTimeForKeepingLogs = 86400000 * 15; // 15 days private long mTimeForKeepingLogs = 86400000 * 15; // 15 days
private boolean mSyncTime = false;
private AlarmReceiver mAlarmReceiver = null; private AlarmReceiver mAlarmReceiver = null;
private ScreenActionReceiver mScreenaAtionReceiver = null; private ScreenActionReceiver mScreenaAtionReceiver = null;
@ -310,6 +311,7 @@ public class MpMasterService extends Service {
if (masterConfig.timeForKeepingLogs > 0) { if (masterConfig.timeForKeepingLogs > 0) {
mTimeForKeepingLogs = masterConfig.timeForKeepingLogs * 86400000; mTimeForKeepingLogs = masterConfig.timeForKeepingLogs * 86400000;
} }
mSyncTime = masterConfig.syncTime;
} }
private void loadIccid() { private void loadIccid() {
@ -349,6 +351,8 @@ public class MpMasterService extends Service {
return mMntnMode; return mMntnMode;
} }
public boolean shouldSyncTime() { return mSyncTime; }
public void startMpApp() { public void startMpApp() {
try { try {
final Context context = getApplicationContext(); final Context context = getApplicationContext();
@ -853,14 +857,6 @@ public class MpMasterService extends Service {
return JSONUtils.saveJson(path, jsonObject); return JSONUtils.saveJson(path, jsonObject);
} }
public boolean updateTime(long timeInMillis) {
try {
SysApi.setSystemTime(getApplicationContext(), timeInMillis);
} catch (Exception ex) {
}
return true;
}
public static int getSignalLevel(int num) { public static int getSignalLevel(int num) {
String result = getSystemProperty("vendor.ril.nw.signalstrength.lte." + Integer.toString(num)); String result = getSystemProperty("vendor.ril.nw.signalstrength.lte." + Integer.toString(num));
if (TextUtils.isEmpty(result)) { if (TextUtils.isEmpty(result)) {
@ -1023,6 +1019,16 @@ public class MpMasterService extends Service {
System.exit(0); System.exit(0);
} }
public void updateTime(long ms) {
Intent intent = new Intent("com.xy.xsetting.action");
intent.putExtra("cmd", "settime");
intent.putExtra("timemills", ms);
intent.setPackage("com.android.systemui");
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
sendBroadcast(intent);
}
public native static int getInt(int cmd); public native static int getInt(int cmd);
public native static int setInt(int cmd, int val); public native static int setInt(int cmd, int val);
public native static int[] getStats(long ts); public native static int[] getStats(long ts);

Loading…
Cancel
Save