Commit 01d52765 by leej

#28062 端末の日付がリセットされる問題対応(ロジック修正、ルート化端末チェック処理削除)

parent 3025b63d
...@@ -20,6 +20,9 @@ public class NtpServerConnection { ...@@ -20,6 +20,9 @@ public class NtpServerConnection {
public static String connectionNtpServer() throws IOException { public static String connectionNtpServer() throws IOException {
HttpURLConnection conn = null; HttpURLConnection conn = null;
InputStream inputStream = null;
BufferedReader bufferedReader = null;
InputStreamReader inReader =null;
try { try {
URL url = new URL(NTP_SERVER_URL); URL url = new URL(NTP_SERVER_URL);
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
...@@ -32,30 +35,34 @@ public class NtpServerConnection { ...@@ -32,30 +35,34 @@ public class NtpServerConnection {
if (statusCode == HttpURLConnection.HTTP_OK) { if (statusCode == HttpURLConnection.HTTP_OK) {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
//responseの読み込み //responseの読み込み
final InputStream in = conn.getInputStream(); inputStream = conn.getInputStream();
String encoding = conn.getContentEncoding(); String encoding = conn.getContentEncoding();
if (null == encoding) { if (null == encoding) {
encoding = "UTF-8"; encoding = "UTF-8";
} }
final InputStreamReader inReader = new InputStreamReader(in, encoding); inReader = new InputStreamReader(inputStream, encoding);
final BufferedReader 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) { if (line.indexOf("<") == -1 && line.indexOf(">") == -1) {
result.append(line); result.append(line);
} }
} }
bufferedReader.close();
inReader.close();
in.close();
return result.toString(); return result.toString();
} }
return null; return null;
} catch(IOException e) { } catch(IOException e) {
throw e; throw e;
} finally { } finally {
if(bufferedReader != null) {
bufferedReader.close();
}
if(inReader != null) {
inReader.close();
}
if(inputStream != null) {
inputStream.close();
}
if(conn != null) { if(conn != null) {
conn.disconnect(); conn.disconnect();
} }
......
...@@ -5,6 +5,7 @@ import android.content.Intent; ...@@ -5,6 +5,7 @@ import android.content.Intent;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.DataOutputStream; import java.io.DataOutputStream;
...@@ -128,68 +129,39 @@ public class UpdateToiletInfoTask extends TimerTask { ...@@ -128,68 +129,39 @@ public class UpdateToiletInfoTask extends TimerTask {
* @throws IOException * @throws IOException
*/ */
private void synchronizingNtpServerDate() throws IOException { private void synchronizingNtpServerDate() throws IOException {
if(isAbnormalYear() && rootCheck()) { if(isAbnormalYear()) {
Logger.i(TAG, "Synchronizing NTP Server Time"); Logger.i(TAG, "Synchronizing NTP Server Time");
String result = NtpServerConnection.connectionNtpServer(); String result = NtpServerConnection.connectionNtpServer();
Logger.i(TAG, "NTP Server Time : " + result); Logger.i(TAG, "NTP Server Time : " + result);
//ntpサーバから取得時間の結果が秒(xxxxxxxxxx.xxx)なのでミリ秒に変換のため、小数点を削除 //ntpサーバから取得時間の結果が秒(xxxxxxxxxx.xxx)なのでミリ秒に変換のため、小数点を削除
String ntpTimeMillis = result.replace(".", ""); String ntpTimeMillis = result.replace(".", "");
String cmd = "date " + DateTimeUtil.convertNtpTimeToStringTime(Long.parseLong(ntpTimeMillis), DateTimeFormat.MMDDHHmmyyyyss__colon); String cmd = "date " + DateTimeUtil.convertNtpTimeToStringTime(Long.parseLong(ntpTimeMillis), DateTimeFormat.MMDDHHmmyyyyss__colon);
Logger.i(TAG, "Command : " + cmd); Logger.i(TAG, "Command : " + cmd);
RunAsRoot(cmd); runAsRoot(cmd);
} }
} }
/** /**
* Root化端末のコマンド実行 * Root化端末のコマンド実行
* *
* @param cmds * @param cmd
* @throws IOException * @throws IOException
*/ */
private void RunAsRoot(String cmds) throws IOException { private void runAsRoot(String cmd) {
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes(cmds+"\n");
os.writeBytes("exit\n");
os.flush();
}
//Root化端末チェック
private boolean rootCheck() {
boolean isRoot = false;
if (suCommandCheck() || superUserCheck()) {
isRoot = true;
}
Logger.i(TAG, "isRoot : " + isRoot);
return isRoot;
}
//suコマンドチェック
private boolean suCommandCheck() {
boolean suCommand = true;
try { try {
Process process = Runtime.getRuntime().exec("su"); Process process = Runtime.getRuntime().exec("su");
process.destroy();
} catch (IOException e) { DataOutputStream dataOutputStream = new DataOutputStream(process.getOutputStream());
//suコマンドが実行されない場合 dataOutputStream.writeBytes(cmd+"\n");
suCommand = false;
}
return suCommand;
}
//superUserアプリチェック
private boolean superUserCheck() {
boolean superUser = true;
try { dataOutputStream.writeBytes("exit\n");
applicationContext.getPackageManager().getApplicationInfo("com.noshufou.android.su", 0); dataOutputStream.flush();
} catch (IOException e) {
} catch (NameNotFoundException e) { Logger.e(TAG, "runAsRoot error.");
superUser = false; //何も処理しない
} }
return superUser;
} }
/* /*
......
...@@ -540,8 +540,8 @@ public class DateTimeUtil { ...@@ -540,8 +540,8 @@ public class DateTimeUtil {
} }
public static String convertNtpTimeToStringTime (long ntpTime, String format) { public static String convertNtpTimeToStringTime (long ntpTime, String format) {
//NTP時刻とPOSIX時刻のオフセット(ミリ秒) //NTP時刻(基準年度:1900年)とUTC時刻(基準年度:1970年)のオフセット(ミリ秒)
long offset = 2208988800L * 1000; long offset = (long) 25567 * 24 * 60 * 60 * 1000;
long result = ntpTime - offset; long result = ntpTime - offset;
return new SimpleDateFormat(format).format(new Timestamp(result)); 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