Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
odakyuToiletSignage
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kddi
odakyuToiletSignage
Commits
01d52765
Commit
01d52765
authored
Jan 25, 2018
by
leej
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#28062 端末の日付がリセットされる問題対応(ロジック修正、ルート化端末チェック処理削除)
parent
3025b63d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
52 deletions
+31
-52
app/src/main/java/jp/odakyu/toiletsignage/connection/NtpServerConnection.java
+15
-8
app/src/main/java/jp/odakyu/toiletsignage/task/UpdateToiletInfoTask.java
+14
-42
app/src/main/java/jp/odakyu/toiletsignage/util/DateTimeUtil.java
+2
-2
No files found.
app/src/main/java/jp/odakyu/toiletsignage/connection/NtpServerConnection.java
View file @
01d52765
...
...
@@ -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
();
}
...
...
app/src/main/java/jp/odakyu/toiletsignage/task/UpdateToiletInfoTask.java
View file @
01d52765
...
...
@@ -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
);
R
unAsRoot
(
cmd
);
r
unAsRoot
(
cmd
);
}
}
/**
* Root化端末のコマンド実行
*
* @param cmd
s
* @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
;
}
/*
...
...
app/src/main/java/jp/odakyu/toiletsignage/util/DateTimeUtil.java
View file @
01d52765
...
...
@@ -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
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment