Commit 01d52765 by leej

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

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