Commit 35a6c1c4 by leej

#28062 NTPサーバのタイムスタンプJSON型のURLに変更

parent 4073ea50
...@@ -14,7 +14,7 @@ import java.net.URL; ...@@ -14,7 +14,7 @@ import java.net.URL;
*/ */
public class NtpServerConnection { public class NtpServerConnection {
private static final String NTP_SERVER_URL = "http://ntp-a1.nict.go.jp/cgi-bin/ntp"; private static final String NTP_SERVER_URL = "http://ntp-a1.nict.go.jp/cgi-bin/json";
private static final int CONNECTION_TIMEOUT = 5 * 1000; private static final int CONNECTION_TIMEOUT = 5 * 1000;
private static final int READ_TIMEOUT = 5 * 1000; private static final int READ_TIMEOUT = 5 * 1000;
...@@ -44,10 +44,8 @@ public class NtpServerConnection { ...@@ -44,10 +44,8 @@ public class NtpServerConnection {
bufferedReader = new BufferedReader(inReader); bufferedReader = new BufferedReader(inReader);
String line; String line;
while ((line = bufferedReader.readLine()) != null) { while ((line = bufferedReader.readLine()) != null) {
if (line.indexOf("<") == -1 && line.indexOf(">") == -1) {
result.append(line); result.append(line);
} }
}
return result.toString(); return result.toString();
} }
return null; return null;
......
...@@ -12,6 +12,8 @@ import java.io.DataOutputStream; ...@@ -12,6 +12,8 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.TimerTask; import java.util.TimerTask;
...@@ -128,14 +130,14 @@ public class UpdateToiletInfoTask extends TimerTask { ...@@ -128,14 +130,14 @@ public class UpdateToiletInfoTask extends TimerTask {
* NTPサーバーの時刻を取得し、端末時刻にセット * NTPサーバーの時刻を取得し、端末時刻にセット
* @throws IOException * @throws IOException
*/ */
private void synchronizingNtpServerDate() throws IOException { private void synchronizingNtpServerDate() throws IOException, JSONException {
if(isAbnormalYear()) { if(isAbnormalYear()) {
String result = NtpServerConnection.connectionNtpServer(); String jsonString = NtpServerConnection.connectionNtpServer();
JSONObject jsonObject = new JSONObject(jsonString);
Logger.d(TAG, "NTP Server Time : " + result); Long ntpTimeMillis = (long) ((Double) jsonObject.get("st") * 1000);
Logger.d(TAG, "NTP Server ntpTimeMillis : " + ntpTimeMillis);
//ntpサーバから取得時間の結果が秒(xxxxxxxxxx.xxx)なのでミリ秒に変換のため、小数点を削除 //ntpサーバから取得時間の結果が秒(xxxxxxxxxx.xxx)なのでミリ秒に変換のため、小数点を削除
String ntpTimeMillis = result.replace(".", ""); String cmd = "date " + DateTimeUtil.toString(new Timestamp(ntpTimeMillis), DateTimeFormat.MMDDHHmmyyyyss__colon);
String cmd = "date " + DateTimeUtil.convertNtpTimeToStringTime(Long.parseLong(ntpTimeMillis), DateTimeFormat.MMDDHHmmyyyyss__colon);
Logger.d(TAG, "Command : " + cmd); Logger.d(TAG, "Command : " + cmd);
runAsRoot(cmd); runAsRoot(cmd);
} }
......
...@@ -538,12 +538,4 @@ public class DateTimeUtil { ...@@ -538,12 +538,4 @@ public class DateTimeUtil {
df.setTimeZone(TimeZone.getTimeZone("GMT")); df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.format(date)+ " GMT"; return df.format(date)+ " GMT";
} }
public static String convertNtpTimeToStringTime (long ntpTime, String format) {
//NTP時刻(基準年度:1900年)とUTC時刻(基準年度:1970年)のオフセット(ミリ秒)
long offset = (long) 25567 * 24 * 60 * 60 * 1000;
long result = ntpTime - offset;
return new SimpleDateFormat(format).format(new Timestamp(result));
}
} }
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