Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
G
g4proxy
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
g4proxy
Commits
3d717eeb
Commit
3d717eeb
authored
Apr 28, 2019
by
liuzhaoce
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scheduler msg report task
parent
78081c3c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
28 deletions
+81
-28
Constant.java
app/src/main/java/com/virjar/g4proxy/Constant.java
+2
-0
MainActivity.java
app/src/main/java/com/virjar/g4proxy/MainActivity.java
+3
-5
SchedulerTaskService.java
...java/com/virjar/g4proxy/service/SchedulerTaskService.java
+39
-11
DeviceMessageUtil.java
...main/java/com/virjar/g4proxy/utils/DeviceMessageUtil.java
+37
-12
No files found.
app/src/main/java/com/virjar/g4proxy/Constant.java
View file @
3d717eeb
...
...
@@ -4,4 +4,6 @@ public class Constant {
public
static
final
String
TAG
=
"G4ProxyAgent"
;
public
static
final
String
sharedPreferenceFile
=
"config"
;
public
static
final
String
schedulerTAG
=
"SchedulerTask"
;
}
app/src/main/java/com/virjar/g4proxy/MainActivity.java
View file @
3d717eeb
package
com
.
virjar
.
g4proxy
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.os.Bundle
;
import
android.provider.Settings
;
import
android.support.annotation.NonNull
;
...
...
@@ -12,15 +11,12 @@ import android.widget.Button;
import
android.widget.TextView
;
import
com.tencent.mm.R
;
import
com.virjar.g4proxy.bean.Const
;
import
com.virjar.g4proxy.service.SchedulerTaskService
;
import
com.virjar.g4proxy.utils.AccessAuthority
;
import
com.virjar.g4proxy.utils.BDLocationUtils
;
import
com.virjar.g4proxy.utils.DeviceInfoHolder
;
import
com.virjar.g4proxy.utils.DeviceMessageUtil
;
import
com.virjar.g4proxy.utils.HttpClientUtils
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.io.IOException
;
...
...
@@ -95,7 +91,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
@Override
public
void
onResponse
(
@javax
.
annotation
.
Nullable
Call
call
,
@javax
.
annotation
.
Nullable
Response
response
)
{
try
{
Log
.
e
(
"report response"
,
response
.
body
().
string
());
if
(
response
!=
null
)
{
Log
.
e
(
"report response"
,
response
.
body
().
string
());
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
...
...
app/src/main/java/com/virjar/g4proxy/service/SchedulerTaskService.java
View file @
3d717eeb
...
...
@@ -11,7 +11,6 @@ import android.os.Handler;
import
android.os.IBinder
;
import
android.os.Looper
;
import
android.os.SystemClock
;
import
android.provider.Settings
;
import
android.support.annotation.Nullable
;
import
android.util.Log
;
import
android.widget.Toast
;
...
...
@@ -31,15 +30,20 @@ import okhttp3.Request;
import
okhttp3.Response
;
import
top.wuhaojie.installerlibrary.AutoInstaller
;
import
static
com
.
virjar
.
g4proxy
.
Constant
.
schedulerTAG
;
public
class
SchedulerTaskService
extends
Service
{
//查询更新的间隔 (单位:分钟)
public
static
final
int
updateInterval
=
10
;
//上传设备信息的间隔 (单位: 分钟)
public
static
final
int
reportInterval
=
5
;
public
static
final
String
getNewestModifiedApkUrl
=
"http://www.scumall.com:5597/hermes/ModifiedApp/getNewestModifiedApk?appPackageName="
;
public
static
final
String
msgReportlUrl
=
"http://taskcenter.beta.qunar.com/api/phone/report"
;
private
long
lastCheckUpdateTimestamp
=
0
;
private
long
lastCheckReportTimestamp
=
0
;
@Nullable
...
...
@@ -59,27 +63,51 @@ public class SchedulerTaskService extends Service {
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
registerAlarm
();
checkAndRunTask
();
return
START_STICKY
;
}
private
void
checkAndRunTask
()
{
if
(
System
.
currentTimeMillis
()
-
lastCheckUpdateTimestamp
<
(
updateInterval
*
1000
*
60
)
/
3
)
{
return
;
Log
.
e
(
schedulerTAG
,
"checkAndRunTask"
);
if
(
System
.
currentTimeMillis
()
-
lastCheckUpdateTimestamp
>
(
updateInterval
*
1000
*
60
)
/
3
)
{
runAppInstallTask
();
}
else
{
lastCheckUpdateTimestamp
=
System
.
currentTimeMillis
();
}
if
(
System
.
currentTimeMillis
()
-
lastCheckReportTimestamp
>
(
reportInterval
*
1000
*
60
)
/
3
){
runReportMessageTask
();
}
else
{
lastCheckReportTimestamp
=
System
.
currentTimeMillis
();
}
lastCheckUpdateTimestamp
=
System
.
currentTimeMillis
();
}
runAppInstallTask
();
private
void
runReportMessageTask
()
{
Log
.
e
(
schedulerTAG
,
"runUploadMessageTask"
);
JSONObject
deviceMessage
=
DeviceMessageUtil
.
getDeviceMessage
(
this
);
runUploadMessageTask
();
}
Request
request
=
HttpClientUtils
.
postRequest
(
msgReportlUrl
,
deviceMessage
);
HttpClientUtils
.
getClient
().
newCall
(
request
).
enqueue
(
new
Callback
()
{
@Override
public
void
onFailure
(
@javax
.
annotation
.
Nullable
Call
call
,
@javax
.
annotation
.
Nullable
IOException
e
)
{
Log
.
e
(
Constant
.
TAG
,
"report device msg failed"
,
e
);
}
private
void
runUploadMessageTask
()
{
JSONObject
deviceMessage
=
DeviceMessageUtil
.
getDeviceMessage
(
this
);
@Override
public
void
onResponse
(
@javax
.
annotation
.
Nullable
Call
call
,
@javax
.
annotation
.
Nullable
Response
response
)
{
try
{
if
(
response
!=
null
)
{
Log
.
e
(
"report response"
,
response
.
body
().
string
());
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
});
}
...
...
@@ -160,7 +188,7 @@ public class SchedulerTaskService extends Service {
private
void
registerAlarm
()
{
AlarmManager
alarmManager
=
(
AlarmManager
)
getSystemService
(
Context
.
ALARM_SERVICE
);
int
time
=
1000
*
60
*
updateInterval
;
int
time
=
1000
*
60
*
Math
.
min
(
reportInterval
,
updateInterval
)
;
//获取系统开机至今所经历的毫秒
long
startTime
=
SystemClock
.
elapsedRealtime
()
+
time
;
Intent
intent
=
new
Intent
(
this
,
SchedulerTaskService
.
class
);
...
...
app/src/main/java/com/virjar/g4proxy/utils/DeviceMessageUtil.java
View file @
3d717eeb
...
...
@@ -2,7 +2,6 @@ package com.virjar.g4proxy.utils;
import
android.Manifest
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.app.ActivityManager
;
import
android.content.Context
;
import
android.content.Intent
;
...
...
@@ -18,11 +17,8 @@ import android.os.Bundle;
import
android.provider.Settings
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.telephony.TelephonyManager
;
import
android.util.Log
;
import
com.baidu.location.BDAbstractLocationListener
;
import
com.baidu.location.BDLocation
;
import
com.google.common.collect.Lists
;
import
com.virjar.g4proxy.bean.App
;
import
com.virjar.g4proxy.bean.Const
;
...
...
@@ -45,7 +41,6 @@ import java.util.Map;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
static
android
.
content
.
Context
.
ACTIVITY_SERVICE
;
...
...
@@ -59,7 +54,8 @@ public class DeviceMessageUtil {
private
static
String
longitude
=
"longitude"
;
private
static
String
DeviceMsg
=
"DeviceMsg"
;
public
static
String
slaveInfo
=
"/sdcard/slave_info.txt"
;
//0:UI 1:沙盒
private
static
int
channel
;
private
static
LocationListener
locationListener
=
new
LocationListener
()
{
...
...
@@ -88,8 +84,25 @@ public class DeviceMessageUtil {
JSONObject
devicesMsg
=
new
JSONObject
();
Map
<
String
,
String
>
latAndLon
=
DeviceMessageUtil
.
getLatAndLon
(
context
);
String
slaveInfo
=
getSlaveInfo
(
context
);
String
deviceId
;
switch
(
channel
){
case
0
:
deviceId
=
getSerialNumber
();
Log
.
e
(
DeviceMsg
,
"channel: "
+
channel
);
break
;
case
1
:
deviceId
=
getSerialNumber
()
+
"_"
+
getAndroidID
(
context
);
Log
.
e
(
DeviceMsg
,
"channel: "
+
channel
);
break
;
default
:
deviceId
=
null
;
Log
.
e
(
DeviceMsg
,
"channel error!"
);
}
try
{
devicesMsg
.
put
(
"deviceId"
,
getSerialNumber
()
+
"_"
+
getAndroidID
(
context
)
);
devicesMsg
.
put
(
"deviceId"
,
deviceId
);
devicesMsg
.
put
(
"brand"
,
android
.
os
.
Build
.
BRAND
);
devicesMsg
.
put
(
"os"
,
Build
.
VERSION
.
RELEASE
);
devicesMsg
.
put
(
"mac"
,
getNewMac
());
...
...
@@ -97,7 +110,7 @@ public class DeviceMessageUtil {
devicesMsg
.
put
(
"cpuUsage"
,
getCPURateDesc
());
devicesMsg
.
put
(
"memoryTotal"
,
getMemoryTotal
());
devicesMsg
.
put
(
"memoryUsage"
,
getMemUsage
(
context
));
devicesMsg
.
put
(
"slaveInfo"
,
getSlaveInfo
(
context
)
);
devicesMsg
.
put
(
"slaveInfo"
,
slaveInfo
);
devicesMsg
.
put
(
"latitude"
,
latAndLon
.
get
(
latitude
));
devicesMsg
.
put
(
"longitude"
,
latAndLon
.
get
(
longitude
));
devicesMsg
.
put
(
"osType"
,
2
);
...
...
@@ -321,15 +334,18 @@ public class DeviceMessageUtil {
* 获取SlaveInfo
*/
private
static
String
getSlaveInfo
(
Context
context
)
{
if
(
ContextCompat
.
checkSelfPermission
(
context
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
return
null
;
}
String
path
=
slaveInfo
;
Log
.
e
(
DeviceMsg
,
"slave_info.txt path: "
+
path
);
String
slaveInfoPath
=
"/sdcard/slave_info.txt"
;
Log
.
e
(
DeviceMsg
,
"slave_info.txt path: "
+
slaveInfoPath
);
String
firstLine
=
null
;
try
{
FileReader
fileReader
=
new
FileReader
(
p
ath
);
FileReader
fileReader
=
new
FileReader
(
slaveInfoP
ath
);
BufferedReader
br
=
new
BufferedReader
(
fileReader
,
8192
);
firstLine
=
br
.
readLine
();
br
.
close
();
...
...
@@ -337,7 +353,15 @@ public class DeviceMessageUtil {
Log
.
e
(
DeviceMsg
,
"Cannot find slave_info.txt !"
);
e
.
printStackTrace
();
}
return
firstLine
;
String
slaveInfo
=
null
;
if
(
firstLine
!=
null
)
{
slaveInfo
=
firstLine
.
split
(
","
)[
0
];
channel
=
Integer
.
valueOf
(
firstLine
.
split
(
","
)[
1
]);
}
else
{
Log
.
e
(
DeviceMsg
,
"slave_info.txt can not be parsed!"
);
}
return
slaveInfo
;
}
...
...
@@ -376,6 +400,7 @@ public class DeviceMessageUtil {
/**
* 获取手机序列号
*/
@SuppressLint
(
"HardwareIds"
)
private
static
String
getSerialNumber
()
{
return
android
.
os
.
Build
.
SERIAL
;
...
...
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