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
c5491608
Commit
c5491608
authored
Apr 18, 2019
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
934b29df
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
320 additions
and
218 deletions
+320
-218
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+14
-5
Constant.java
app/src/main/java/com/virjar/g4proxy/Constant.java
+7
-0
HttpProxyService.java
app/src/main/java/com/virjar/g4proxy/HttpProxyService.java
+0
-8
MainActivity.java
app/src/main/java/com/virjar/g4proxy/MainActivity.java
+22
-24
SelfStartReceiver.java
app/src/main/java/com/virjar/g4proxy/SelfStartReceiver.java
+10
-8
StartOnBootBroadcastReceiver.java
...java/com/virjar/g4proxy/StartOnBootBroadcastReceiver.java
+3
-1
App.java
app/src/main/java/com/virjar/g4proxy/bean/App.java
+1
-1
SchedulerTaskService.java
...java/com/virjar/g4proxy/service/SchedulerTaskService.java
+55
-38
DeviceInfoHolder.java
.../main/java/com/virjar/g4proxy/utils/DeviceInfoHolder.java
+118
-0
DeviceMessageUtil.java
...main/java/com/virjar/g4proxy/utils/DeviceMessageUtil.java
+81
-108
MyApplication.java
...src/main/java/com/virjar/g4proxy/utils/MyApplication.java
+0
-24
AutoInstaller.java
...ain/java/top/wuhaojie/installerlibrary/AutoInstaller.java
+9
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
c5491608
...
...
@@ -36,7 +36,6 @@
<uses-permission
android:name=
"android.permission.REQUEST_INSTALL_PACKAGES"
/>
<application
android:name=
"com.virjar.g4proxy.utils.MyApplication"
android:allowBackup=
"true"
android:icon=
"@mipmap/ic_launcher"
android:label=
"@string/app_name"
...
...
@@ -64,6 +63,16 @@
</intent-filter>
</service>
<service
android:name=
"com.virjar.g4proxy.service.SchedulerTaskService"
tools:ignore=
"ExportedService"
>
<intent-filter
android:priority=
"1000"
>
<action
android:name=
"com.virjar.g4proxy.service.scheuler"
/>
<category
android:name=
"android.intent.category.DEFAULT"
/>
</intent-filter>
</service>
<!--开机自启服务-->
<receiver
android:name=
"com.virjar.g4proxy.StartOnBootBroadcastReceiver"
...
...
@@ -83,11 +92,11 @@
<!--<!–覆盖安装后唤醒service–>-->
<!--<receiver android:name="com.virjar.g4proxy.SelfStartReceiver">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.PACKAGE_REPLACED" />-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.PACKAGE_REPLACED" />-->
<!--<data android:scheme="package" />-->
<!--</intent-filter>-->
<!--<data android:scheme="package" />-->
<!--</intent-filter>-->
<!--</receiver>-->
<service
...
...
app/src/main/java/com/virjar/g4proxy/Constant.java
0 → 100644
View file @
c5491608
package
com
.
virjar
.
g4proxy
;
public
class
Constant
{
public
static
final
String
TAG
=
"G4ProxyAgent"
;
public
static
final
String
sharedPreferenceFile
=
"config"
;
}
app/src/main/java/com/virjar/g4proxy/HttpProxyService.java
View file @
c5491608
...
...
@@ -109,14 +109,6 @@ public class HttpProxyService extends Service {
String
clientKey
=
Settings
.
System
.
getString
(
getContentResolver
(),
Settings
.
Secure
.
ANDROID_ID
);
Log
.
i
(
"weijia"
,
"start G4Proxy front service"
);
Launcher
.
startHttpProxyService
(
3128
);
// Log.i("weijia", "start private network forward task");
//
// ProxyClient.start(Constants.g4ProxyServerHost_1, Constants.g4ProxyServerPort, clientKey);
//
// ProxyClient.start(Constants.g4ProxyServerHost_2, Constants.g4ProxyServerPort, clientKey);
//新的代理服务器实现
LogbackConfig
.
config
();
...
...
app/src/main/java/com/virjar/g4proxy/MainActivity.java
View file @
c5491608
package
com
.
virjar
.
g4proxy
;
import
android.app.ActivityManager
;
import
android.app.Application
;
import
android.app.ProgressDialog
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.location.LocationManager
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.provider.Settings
;
import
android.support.annotation.NonNull
;
import
android.support.v7.app.AppCompatActivity
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.tencent.mm.R
;
import
com.virjar.g4proxy.service.SchedulerTaskService
;
import
com.virjar.g4proxy.utils.AccessAuthority
;
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.util.List
;
import
top.wuhaojie.installerlibrary.AutoInstaller
;
public
class
MainActivity
extends
AppCompatActivity
{
public
LocationManager
locationManager
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -44,20 +28,34 @@ public class MainActivity extends AppCompatActivity {
TextView
textView
=
findViewById
(
R
.
id
.
text
);
locationManager
=
(
LocationManager
)
getSystemService
(
Context
.
LOCATION_SERVICE
);
String
clientKey
=
Settings
.
System
.
getString
(
getContentResolver
(),
Settings
.
Secure
.
ANDROID_ID
);
textView
.
setText
(
"device: "
+
clientKey
+
"\n"
);
textView
.
setText
(
"device: "
+
clientKey
+
"\n
\n
"
);
//待上传的设备信息:devicesMsg
JSONObject
deviceMsg
=
DeviceMessageUtil
.
getDeviceMessage
(
locationManager
,
this
,
this
);
JSONObject
deviceMsg
=
DeviceMessageUtil
.
getDeviceMessage
(
this
);
textView
.
append
(
deviceMsg
.
toString
());
startService
(
new
Intent
(
this
,
AppUpdateService
.
class
));
startService
(
new
Intent
(
this
,
SchedulerTaskService
.
class
));
startService
(
new
Intent
(
this
,
HttpProxyService
.
class
));
AutoInstaller
.
getDefault
(
this
).
autoConfigAccessibilitySetting
(
this
);
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
DeviceInfoHolder
.
initDeviceInfo
(
this
);
}
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
@NonNull
String
[]
permissions
,
@NonNull
int
[]
grantResults
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
);
//不给权限的话,循环申请
DeviceInfoHolder
.
initDeviceInfo
(
this
);
}
}
app/src/main/java/com/virjar/g4proxy/SelfStartReceiver.java
View file @
c5491608
...
...
@@ -5,15 +5,17 @@ import android.content.Context;
import
android.content.Intent
;
import
android.net.Uri
;
import
com.virjar.g4proxy.service.SchedulerTaskService
;
/**
* Created by liuzhaoce on 2019/4/14.
*/
public
class
SelfStartReceiver
extends
BroadcastReceiver
{
// 这里我们先依靠slave进行守护保活
public
class
SelfStartReceiver
extends
BroadcastReceiver
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
){
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
...
...
@@ -22,19 +24,19 @@ public class SelfStartReceiver extends BroadcastReceiver{
Uri
data
=
intent
.
getData
();
if
(
data
==
null
){
if
(
data
==
null
)
{
return
;
}
//取得安装的Apk的包名,只在该app覆盖安装后自启动
String
installedPkgName
=
data
.
getSchemeSpecificPart
();
if
(
action
==
null
){
if
(
action
==
null
)
{
return
;
}
if
((
action
.
equals
(
Intent
.
ACTION_PACKAGE_ADDED
)
||
action
.
equals
(
Intent
.
ACTION_PACKAGE_REPLACED
))
&&
installedPkgName
.
equals
(
localPkgName
)){
if
((
action
.
equals
(
Intent
.
ACTION_PACKAGE_ADDED
)
||
action
.
equals
(
Intent
.
ACTION_PACKAGE_REPLACED
))
&&
installedPkgName
.
equals
(
localPkgName
))
{
Intent
launchAppUpdateService
=
new
Intent
(
context
,
AppUpdate
Service
.
class
);
Intent
launchAppUpdateService
=
new
Intent
(
context
,
SchedulerTask
Service
.
class
);
launchAppUpdateService
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
Intent
launchHttpProxyService
=
new
Intent
(
context
,
HttpProxyService
.
class
);
...
...
app/src/main/java/com/virjar/g4proxy/StartOnBootBroadcastReceiver.java
View file @
c5491608
...
...
@@ -6,6 +6,8 @@ import android.content.Context;
import
android.content.Intent
;
import
android.util.Log
;
import
com.virjar.g4proxy.service.SchedulerTaskService
;
/**
* Created by virjar on 2018/8/23.
*/
...
...
@@ -16,7 +18,7 @@ public class StartOnBootBroadcastReceiver extends BroadcastReceiver {
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
Log
.
i
(
"weijia"
,
"receive start service broadcast"
);
context
.
startService
(
new
Intent
(
context
,
AppUpdate
Service
.
class
));
context
.
startService
(
new
Intent
(
context
,
SchedulerTask
Service
.
class
));
context
.
startService
(
new
Intent
(
context
,
HttpProxyService
.
class
));
...
...
app/src/main/java/com/virjar/g4proxy/App.java
→
app/src/main/java/com/virjar/g4proxy/
bean/
App.java
View file @
c5491608
package
com
.
virjar
.
g4proxy
;
package
com
.
virjar
.
g4proxy
.
bean
;
/**
* Created by liuzhaoce on 2019/4/11.
...
...
app/src/main/java/com/virjar/g4proxy/
AppUpdate
Service.java
→
app/src/main/java/com/virjar/g4proxy/
service/SchedulerTask
Service.java
View file @
c5491608
package
com
.
virjar
.
g4proxy
;
package
com
.
virjar
.
g4proxy
.
service
;
import
android.app.AlarmManager
;
import
android.app.PendingIntent
;
import
android.app.ProgressDialog
;
import
android.app.Service
;
import
android.content.Context
;
import
android.content.Intent
;
...
...
@@ -11,11 +10,13 @@ import android.content.pm.PackageManager;
import
android.os.Handler
;
import
android.os.IBinder
;
import
android.os.Looper
;
import
android.os.Message
;
import
android.os.SystemClock
;
import
android.support.annotation.Nullable
;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.virjar.g4proxy.Constant
;
import
com.virjar.g4proxy.utils.DeviceMessageUtil
;
import
com.virjar.g4proxy.utils.HttpClientUtils
;
import
org.json.JSONException
;
...
...
@@ -23,61 +24,76 @@ import org.json.JSONObject;
import
java.io.IOException
;
import
javax.annotation.Nullable
;
import
okhttp3.Call
;
import
okhttp3.Callback
;
import
okhttp3.Request
;
import
okhttp3.Response
;
import
top.wuhaojie.installerlibrary.AutoInstaller
;
public
class
AppUpdate
Service
extends
Service
{
public
class
SchedulerTask
Service
extends
Service
{
//查询更新的间隔 (单位:分钟)
public
static
final
int
updateInterval
=
10
;
public
static
final
String
TAG
=
"AppUpdateService"
;
public
static
final
String
getNewestModifiedApkUrl
=
"http://www.scumall.com:5597/hermes/ModifiedApp/getNewestModifiedApk?appPackageName="
;
private
long
lastCheckUpdateTimestamp
=
0
;
@Nullable
@Override
public
IBinder
onBind
(
Intent
intent
)
{
startService
();
checkAndRunTask
();
return
null
;
}
@Override
public
void
onCreate
()
{
registerAlarm
();
checkAndRunTask
();
super
.
onCreate
();
startService
();
}
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
startService
();
checkAndRunTask
();
return
START_STICKY
;
}
private
void
startService
()
{
private
void
checkAndRunTask
()
{
if
(
System
.
currentTimeMillis
()
-
lastCheckUpdateTimestamp
<
(
updateInterval
*
1000
*
60
)
/
3
)
{
return
;
}
lastCheckUpdateTimestamp
=
System
.
currentTimeMillis
();
runAppInstallTask
();
runUploadMessageTask
();
}
private
void
runUploadMessageTask
()
{
JSONObject
deviceMessage
=
DeviceMessageUtil
.
getDeviceMessage
(
this
);
}
private
void
runAppInstallTask
()
{
final
String
packageName
=
getApplicationInfo
().
packageName
;
Request
request
=
HttpClientUtils
.
getRequest
(
getNewestModifiedApkUrl
+
packageName
);
HttpClientUtils
.
getClient
().
newCall
(
request
).
enqueue
(
new
Callback
()
{
@Override
public
void
onFailure
(
@
Nullable
Call
call
,
@
Nullable
IOException
e
)
{
Log
.
e
(
"get request"
,
"get downloadUrl failed"
,
e
);
public
void
onFailure
(
@
javax
.
annotation
.
Nullable
Call
call
,
@javax
.
annotation
.
Nullable
IOException
e
)
{
Log
.
e
(
Constant
.
TAG
,
"get downloadUrl failed"
,
e
);
}
@Override
public
void
onResponse
(
@
Nullable
Call
call
,
@
Nullable
Response
response
)
{
public
void
onResponse
(
@
javax
.
annotation
.
Nullable
Call
call
,
@javax
.
annotation
.
Nullable
Response
response
)
{
try
{
handleResponse
(
response
,
packageName
);
}
catch
(
JSONException
|
PackageManager
.
NameNotFoundException
|
IOException
e
)
{
...
...
@@ -85,25 +101,14 @@ public class AppUpdateService extends Service {
}
}
});
AlarmManager
alarmManager
=
(
AlarmManager
)
getSystemService
(
Context
.
ALARM_SERVICE
);
int
time
=
1000
*
60
*
updateInterval
;
//获取系统开机至今所经历的毫秒
long
startTime
=
SystemClock
.
elapsedRealtime
()
+
time
;
Intent
intent
=
new
Intent
(
this
,
AppUpdateService
.
class
);
PendingIntent
pendingIntent
=
PendingIntent
.
getService
(
this
,
0
,
intent
,
0
);
if
(
alarmManager
==
null
){
return
;
}
alarmManager
.
set
(
AlarmManager
.
ELAPSED_REALTIME_WAKEUP
,
startTime
,
pendingIntent
);
}
private
void
doInstall
(
final
String
url
)
{
new
Handler
(
Looper
.
getMainLooper
()).
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
Log
.
e
(
TAG
,
"installing"
);
AutoInstaller
installer
=
AutoInstaller
.
getDefault
(
AppUpdate
Service
.
this
);
Log
.
e
(
Constant
.
TAG
,
"installing"
);
AutoInstaller
installer
=
AutoInstaller
.
getDefault
(
SchedulerTask
Service
.
this
);
installer
.
installFromUrl
(
url
);
installer
.
setOnStateChangedListener
(
new
AutoInstaller
.
OnStateChangedListener
()
{
@Override
...
...
@@ -118,12 +123,12 @@ public class AppUpdateService extends Service {
@Override
public
void
onNeed2OpenService
()
{
Toast
.
makeText
(
AppUpdate
Service
.
this
,
"请打开辅助功能服务"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
SchedulerTask
Service
.
this
,
"请打开辅助功能服务"
,
Toast
.
LENGTH_SHORT
).
show
();
}
@Override
public
void
needPermission
()
{
Toast
.
makeText
(
AppUpdate
Service
.
this
,
"需要申请存储空间权限"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
SchedulerTask
Service
.
this
,
"需要申请存储空间权限"
,
Toast
.
LENGTH_SHORT
).
show
();
}
});
}
...
...
@@ -132,25 +137,37 @@ public class AppUpdateService extends Service {
public
void
handleResponse
(
Response
response
,
String
packageName
)
throws
JSONException
,
PackageManager
.
NameNotFoundException
,
IOException
{
if
(
response
.
body
()
==
null
){
if
(
response
.
body
()
==
null
)
{
return
;
}
String
responseJson
=
response
.
body
().
string
();
Log
.
i
(
Constant
.
TAG
,
"app update config service response: "
+
responseJson
);
JSONObject
jsonObject
=
new
JSONObject
(
responseJson
);
jsonObject
=
jsonObject
.
optJSONObject
(
"data"
);
String
downloadUrl
=
jsonObject
.
optString
(
"downloadUrl"
);
long
versionCode
=
jsonObject
.
optLong
(
"versionCode"
);
Log
.
i
(
"app_update"
,
"downloadUrl: "
+
downloadUrl
);
Log
.
i
(
"app_update"
,
"up-to-date versionCode: "
+
versionCode
);
Log
.
i
(
Constant
.
TAG
,
"downloadUrl: "
+
downloadUrl
);
Log
.
i
(
Constant
.
TAG
,
"up-to-date versionCode: "
+
versionCode
);
PackageInfo
packageInfo
=
getPackageManager
().
getPackageInfo
(
packageName
,
PackageManager
.
GET_META_DATA
);
if
(
packageInfo
.
versionCode
<
versionCode
)
{
Log
.
i
(
Constant
.
TAG
,
"the app need update,with download url: "
+
downloadUrl
);
doInstall
(
downloadUrl
);
}
}
@Override
public
void
onDestroy
()
{
super
.
onDestroy
();
private
void
registerAlarm
()
{
AlarmManager
alarmManager
=
(
AlarmManager
)
getSystemService
(
Context
.
ALARM_SERVICE
);
int
time
=
1000
*
60
*
updateInterval
;
//获取系统开机至今所经历的毫秒
long
startTime
=
SystemClock
.
elapsedRealtime
()
+
time
;
Intent
intent
=
new
Intent
(
this
,
SchedulerTaskService
.
class
);
PendingIntent
pendingIntent
=
PendingIntent
.
getService
(
this
,
0
,
intent
,
0
);
if
(
alarmManager
==
null
)
{
return
;
}
alarmManager
.
set
(
AlarmManager
.
ELAPSED_REALTIME_WAKEUP
,
startTime
,
pendingIntent
);
}
}
app/src/main/java/com/virjar/g4proxy/utils/DeviceInfoHolder.java
0 → 100644
View file @
c5491608
package
com
.
virjar
.
g4proxy
.
utils
;
import
android.Manifest
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.content.pm.PackageManager
;
import
android.provider.Settings
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.telephony.TelephonyManager
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.virjar.g4proxy.Constant
;
import
com.virjar.g4proxy.MainActivity
;
public
class
DeviceInfoHolder
{
private
static
String
imei
;
private
static
String
androidId
;
public
static
void
initDeviceInfo
(
MainActivity
activity
)
{
if
(
ActivityCompat
.
checkSelfPermission
(
activity
,
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
ActivityCompat
.
shouldShowRequestPermissionRationale
(
activity
,
Manifest
.
permission
.
ACCESS_FINE_LOCATION
))
{
Log
.
e
(
Constant
.
TAG
,
"checkSelfPermission ACCESS_FINE_LOCATION did not show."
);
}
else
{
ActivityCompat
.
requestPermissions
(
activity
,
new
String
[]{
Manifest
.
permission
.
ACCESS_FINE_LOCATION
},
AccessAuthority
.
ACCESS_FINE_LOCATION_REQUEST_CODE
.
getRequestCode
());
}
return
;
}
if
(
ContextCompat
.
checkSelfPermission
(
activity
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
ActivityCompat
.
shouldShowRequestPermissionRationale
(
activity
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
))
{
Log
.
e
(
Constant
.
TAG
,
"checkSelfPermission WRITE_EXTERNAL_STORAGE did not show."
);
}
else
{
ActivityCompat
.
requestPermissions
(
activity
,
new
String
[]{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
AccessAuthority
.
WRITE_EXTERNAL_STORAGE_REQUEST_CODE
.
getRequestCode
());
}
return
;
}
if
(
restoreInfo
(
activity
))
{
return
;
}
if
(
ContextCompat
.
checkSelfPermission
(
activity
,
Manifest
.
permission
.
READ_PHONE_STATE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
ActivityCompat
.
shouldShowRequestPermissionRationale
(
activity
,
Manifest
.
permission
.
READ_PHONE_STATE
))
{
Log
.
e
(
Constant
.
TAG
,
"checkSelfPermission READ_PHONE_STATE did not show."
);
}
else
{
ActivityCompat
.
requestPermissions
(
activity
,
new
String
[]{
Manifest
.
permission
.
READ_PHONE_STATE
},
AccessAuthority
.
READ_PHONE_STATE_REQUEST_CODE
.
getRequestCode
());
}
return
;
}
try
{
TelephonyManager
telephonyManager
=
(
TelephonyManager
)
activity
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
if
(
telephonyManager
==
null
)
{
Log
.
e
(
Constant
.
TAG
,
"can not get telephonyManager instance"
);
return
;
}
@SuppressLint
(
"HardwareIds"
)
String
imeiCopy
=
telephonyManager
.
getDeviceId
();
if
(!
TextUtils
.
isEmpty
(
imeiCopy
))
{
imei
=
imeiCopy
;
}
androidId
=
Settings
.
System
.
getString
(
activity
.
getContentResolver
(),
Settings
.
Secure
.
ANDROID_ID
);
save
(
activity
);
}
catch
(
Exception
e
)
{
Log
.
e
(
Constant
.
TAG
,
"getIMEI failed!"
,
e
);
}
}
private
static
boolean
restoreInfo
(
Context
context
)
{
if
(
imei
!=
null
&&
androidId
!=
null
)
{
return
true
;
}
SharedPreferences
sharedPreferences
=
context
.
getSharedPreferences
(
Constant
.
sharedPreferenceFile
,
Context
.
MODE_PRIVATE
);
String
imei
=
sharedPreferences
.
getString
(
"imei"
,
null
);
if
(
imei
==
null
)
{
return
false
;
}
DeviceInfoHolder
.
imei
=
imei
;
String
androidId
=
sharedPreferences
.
getString
(
"androidId"
,
null
);
if
(
androidId
==
null
)
{
return
false
;
}
DeviceInfoHolder
.
androidId
=
androidId
;
return
true
;
}
private
static
void
save
(
Context
context
)
{
SharedPreferences
sharedPreferences
=
context
.
getSharedPreferences
(
Constant
.
sharedPreferenceFile
,
Context
.
MODE_PRIVATE
);
SharedPreferences
.
Editor
edit
=
sharedPreferences
.
edit
();
edit
.
putString
(
"imei"
,
imei
);
edit
.
putString
(
"androidId"
,
androidId
);
edit
.
apply
();
}
public
static
String
getCachedImei
(
Context
context
)
{
restoreInfo
(
context
);
return
imei
;
}
public
static
String
getCachedAndroidId
(
Context
context
)
{
restoreInfo
(
context
);
return
androidId
;
}
}
app/src/main/java/com/virjar/g4proxy/utils/DeviceMessageUtil.java
View file @
c5491608
package
com
.
virjar
.
g4proxy
.
utils
;
import
android.Manifest
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.app.ActivityManager
;
import
android.content.Context
;
...
...
@@ -12,18 +13,15 @@ import android.location.Criteria;
import
android.location.Location
;
import
android.location.LocationListener
;
import
android.location.LocationManager
;
import
android.net.wifi.WifiInfo
;
import
android.net.wifi.WifiManager
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.telephony.TelephonyManager
;
import
android.util.Log
;
import
com.google.common.collect.Lists
;
import
com.virjar.g4proxy.App
;
import
com.virjar.g4proxy.
bean.
App
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -31,8 +29,11 @@ import org.json.JSONObject;
import
java.io.BufferedReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.net.Inet4Address
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.util.Collections
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Locale
;
...
...
@@ -77,19 +78,19 @@ public class DeviceMessageUtil {
};
public
static
JSONObject
getDeviceMessage
(
LocationManager
locationManager
,
Context
context
,
Activity
activity
)
{
public
static
JSONObject
getDeviceMessage
(
Context
context
)
{
JSONObject
devicesMsg
=
new
JSONObject
();
Map
<
String
,
String
>
latAndLon
=
DeviceMessageUtil
.
getLatAndLon
(
locationManager
,
context
,
activity
);
Map
<
String
,
String
>
latAndLon
=
DeviceMessageUtil
.
getLatAndLon
(
context
);
try
{
devicesMsg
.
put
(
"IMEI"
,
getIMEI
(
context
,
activity
));
devicesMsg
.
put
(
"IMEI"
,
DeviceInfoHolder
.
getCachedImei
(
context
));
devicesMsg
.
put
(
"os"
,
Build
.
VERSION
.
RELEASE
);
devicesMsg
.
put
(
"mac"
,
getNewMac
());
devicesMsg
.
put
(
"ip"
,
getIPAddress
(
context
));
devicesMsg
.
put
(
"cpuUsage"
,
getCPURateDesc
());
devicesMsg
.
put
(
"memoryTotal"
,
getMemoryTotal
());
devicesMsg
.
put
(
"memoryUsage"
,
getMemUsage
(
context
));
devicesMsg
.
put
(
"slaveInfo"
,
getSlaveInfo
(
context
,
activity
));
devicesMsg
.
put
(
"slaveInfo"
,
getSlaveInfo
(
context
));
devicesMsg
.
put
(
"latitude"
,
latAndLon
.
get
(
latitude
));
devicesMsg
.
put
(
"longitude"
,
latAndLon
.
get
(
longitude
));
devicesMsg
.
put
(
"appList"
,
getAPPList
(
context
));
...
...
@@ -101,63 +102,25 @@ public class DeviceMessageUtil {
/**
* 获取手机IMEI
*
*/
private
static
String
getIMEI
(
Context
context
,
Activity
activity
)
{
try
{
TelephonyManager
telephonyManager
=
(
TelephonyManager
)
context
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
if
(
ContextCompat
.
checkSelfPermission
(
context
,
Manifest
.
permission
.
READ_PHONE_STATE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
ActivityCompat
.
shouldShowRequestPermissionRationale
(
activity
,
Manifest
.
permission
.
READ_PHONE_STATE
))
{
Log
.
e
(
DeviceMsg
,
"checkSelfPermission READ_PHONE_STATE did not show."
);
}
else
{
ActivityCompat
.
requestPermissions
(
activity
,
new
String
[]{
Manifest
.
permission
.
READ_PHONE_STATE
},
AccessAuthority
.
READ_PHONE_STATE_REQUEST_CODE
.
getRequestCode
());
}
}
String
imei
=
telephonyManager
.
getDeviceId
();
if
(
imei
==
null
)
{
imei
=
""
;
}
return
imei
;
}
catch
(
Exception
e
)
{
Log
.
e
(
DeviceMsg
,
"getIMEI failed!"
);
e
.
printStackTrace
();
return
""
;
}
}
/**
* 获取手机经纬度
*
*/
private
static
Map
<
String
,
String
>
getLatAndLon
(
LocationManager
locationManager
,
Context
context
,
Activity
activity
)
{
private
static
Map
<
String
,
String
>
getLatAndLon
(
Context
context
)
{
LocationManager
locationManager
=
(
LocationManager
)
context
.
getSystemService
(
Context
.
LOCATION_SERVICE
);
Map
<
String
,
String
>
latAndLon
=
new
HashMap
<>();
if
(
locationManager
==
null
)
{
return
latAndLon
;
}
String
bestProvider
=
locationManager
.
getBestProvider
(
getCriteria
(),
true
);
Log
.
e
(
DeviceMsg
,
"bestProvider :"
+
bestProvider
);
if
(
ActivityCompat
.
checkSelfPermission
(
context
,
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
ActivityCompat
.
shouldShowRequestPermissionRationale
(
activity
,
Manifest
.
permission
.
ACCESS_FINE_LOCATION
))
{
Log
.
e
(
DeviceMsg
,
"checkSelfPermission ACCESS_FINE_LOCATION did not show."
);
}
else
{
ActivityCompat
.
requestPermissions
(
activity
,
new
String
[]{
Manifest
.
permission
.
ACCESS_FINE_LOCATION
},
AccessAuthority
.
ACCESS_FINE_LOCATION_REQUEST_CODE
.
getRequestCode
());
}
}
if
(
ActivityCompat
.
checkSelfPermission
(
context
,
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
ActivityCompat
.
shouldShowRequestPermissionRationale
(
activity
,
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
))
{
Log
.
e
(
DeviceMsg
,
"checkSelfPermission ACCESS_COARSE_LOCATION did not show."
);
}
else
{
ActivityCompat
.
requestPermissions
(
activity
,
new
String
[]{
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
},
AccessAuthority
.
ACCESS_COARSE_LOCATION_REQUEST_CODE
.
getRequestCode
());
}
return
latAndLon
;
}
locationManager
.
requestLocationUpdates
(
bestProvider
,
3000
,
1
,
locationListener
);
Location
location
=
locationManager
.
getLastKnownLocation
(
bestProvider
);
if
(
location
==
null
)
{
if
(
location
==
null
)
{
List
<
String
>
providers
=
locationManager
.
getProviders
(
true
);
for
(
String
provider
:
providers
)
{
...
...
@@ -184,7 +147,6 @@ public class DeviceMessageUtil {
/**
* 通过网络接口取mac地址
*
*/
private
static
String
getNewMac
()
{
try
{
...
...
@@ -218,16 +180,36 @@ public class DeviceMessageUtil {
* 通过WiFiManager获取ip地址
*/
private
static
String
getIPAddress
(
Context
context
)
{
WifiManager
wifiManager
=
(
WifiManager
)
context
.
getApplicationContext
().
getSystemService
(
Context
.
WIFI_SERVICE
);
if
(
wifiManager
==
null
){
return
null
;
String
ipV6Ip
=
null
;
String
lookUpIP
=
null
;
try
{
for
(
Enumeration
<
NetworkInterface
>
en
=
NetworkInterface
.
getNetworkInterfaces
();
en
.
hasMoreElements
();
)
{
NetworkInterface
intf
=
en
.
nextElement
();
if
(
intf
.
getName
()
!=
null
&&
intf
.
getName
().
toLowerCase
().
contains
(
"usbnet"
))
{
continue
;
}
for
(
Enumeration
<
InetAddress
>
ipAddr
=
intf
.
getInetAddresses
();
ipAddr
.
hasMoreElements
();
)
{
InetAddress
inetAddress
=
ipAddr
.
nextElement
();
if
(
inetAddress
.
isLoopbackAddress
())
{
lookUpIP
=
inetAddress
.
getHostAddress
();
continue
;
}
if
(
inetAddress
instanceof
Inet4Address
)
{
return
inetAddress
.
getHostAddress
();
}
else
{
ipV6Ip
=
inetAddress
.
getHostAddress
();
}
}
}
}
catch
(
Exception
e
)
{
Log
.
e
(
"TAG"
,
"query local ip failed"
,
e
);
}
if
(!
wifiManager
.
isWifiEnabled
())
{
wifiManager
.
setWifiEnabled
(
true
);
if
(
lookUpIP
!=
null
)
{
return
lookUpIP
;
}
WifiInfo
wifiInfo
=
wifiManager
.
getConnectionInfo
();
int
ipAddress
=
wifiInfo
.
getIpAddress
();
return
intToIp
(
ipAddress
);
return
ipV6Ip
;
}
...
...
@@ -235,23 +217,23 @@ public class DeviceMessageUtil {
* 获取当前CPU占比
* 在实际测试中发现,有的手机会隐藏CPU状态,不会完全显示所有CPU信息
*/
private
static
String
getCPURateDesc
(){
private
static
String
getCPURateDesc
()
{
String
path
=
"/proc/stat"
;
// 系统CPU信息文件
long
totalJiffies
[]
=
new
long
[
2
];
long
totalIdle
[]
=
new
long
[
2
];
int
firstCPUNum
=
0
;
//设置这个参数,这要是防止两次读取文件获知的CPU数量不同,导致不能计算。这里统一以第一次的CPU数量为基准
long
totalJiffies
[]
=
new
long
[
2
];
long
totalIdle
[]
=
new
long
[
2
];
int
firstCPUNum
=
0
;
//设置这个参数,这要是防止两次读取文件获知的CPU数量不同,导致不能计算。这里统一以第一次的CPU数量为基准
FileReader
fileReader
;
BufferedReader
bufferedReader
=
null
;
Pattern
pattern
=
Pattern
.
compile
(
" [0-9]+"
);
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
totalJiffies
[
i
]
=
0
;
totalIdle
[
i
]
=
0
;
Pattern
pattern
=
Pattern
.
compile
(
" [0-9]+"
);
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
totalJiffies
[
i
]
=
0
;
totalIdle
[
i
]
=
0
;
try
{
fileReader
=
new
FileReader
(
path
);
bufferedReader
=
new
BufferedReader
(
fileReader
,
8192
);
int
currentCPUNum
=
0
;
int
currentCPUNum
=
0
;
String
str
;
while
((
str
=
bufferedReader
.
readLine
())
!=
null
&&(
i
==
0
||
currentCPUNum
<
firstCPUNum
))
{
while
((
str
=
bufferedReader
.
readLine
())
!=
null
&&
(
i
==
0
||
currentCPUNum
<
firstCPUNum
))
{
if
(
str
.
toLowerCase
().
startsWith
(
"cpu"
))
{
currentCPUNum
++;
int
index
=
0
;
...
...
@@ -269,8 +251,8 @@ public class DeviceMessageUtil {
}
}
}
if
(
i
==
0
)
{
firstCPUNum
=
currentCPUNum
;
if
(
i
==
0
)
{
firstCPUNum
=
currentCPUNum
;
try
{
//暂停50毫秒,等待系统更新信息。
Thread
.
sleep
(
50
);
}
catch
(
InterruptedException
e
)
{
...
...
@@ -290,32 +272,31 @@ public class DeviceMessageUtil {
}
}
}
double
rate
=
-
1
;
if
(
totalJiffies
[
0
]
>
0
&&
totalJiffies
[
1
]>
0
&&
totalJiffies
[
0
]!=
totalJiffies
[
1
])
{
rate
=
1.0
*((
totalJiffies
[
1
]-
totalIdle
[
1
])-(
totalJiffies
[
0
]-
totalIdle
[
0
]))/(
totalJiffies
[
1
]-
totalJiffies
[
0
]);
double
rate
=
-
1
;
if
(
totalJiffies
[
0
]
>
0
&&
totalJiffies
[
1
]
>
0
&&
totalJiffies
[
0
]
!=
totalJiffies
[
1
])
{
rate
=
1.0
*
((
totalJiffies
[
1
]
-
totalIdle
[
1
])
-
(
totalJiffies
[
0
]
-
totalIdle
[
0
]))
/
(
totalJiffies
[
1
]
-
totalJiffies
[
0
]);
}
return
String
.
format
(
Locale
.
CHINA
,
"%.2f"
,
rate
*
100
);
return
String
.
format
(
Locale
.
CHINA
,
"%.2f"
,
rate
*
100
);
}
/**
* 获取总内存大小(MB)
*
*/
private
static
String
getMemoryTotal
(){
private
static
String
getMemoryTotal
()
{
String
path
=
"/proc/meminfo"
;
String
firstLine
=
null
;
int
totalRam
=
0
;
try
{
int
totalRam
=
0
;
try
{
FileReader
fileReader
=
new
FileReader
(
path
);
BufferedReader
br
=
new
BufferedReader
(
fileReader
,
8192
);
BufferedReader
br
=
new
BufferedReader
(
fileReader
,
8192
);
firstLine
=
br
.
readLine
().
split
(
"\\s+"
)[
1
];
br
.
close
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
firstLine
!=
null
)
{
totalRam
=
(
int
)
Math
.
ceil
((
Float
.
valueOf
(
Float
.
valueOf
(
firstLine
)
/
(
1024
)).
doubleValue
()));
if
(
firstLine
!=
null
)
{
totalRam
=
(
int
)
Math
.
ceil
((
Float
.
valueOf
(
Float
.
valueOf
(
firstLine
)
/
(
1024
)).
doubleValue
()));
}
return
String
.
valueOf
(
totalRam
);
...
...
@@ -323,26 +304,22 @@ public class DeviceMessageUtil {
/**
* 获取SlaveInfo
*
*/
private
static
String
getSlaveInfo
(
Context
context
,
Activity
activity
)
{
private
static
String
getSlaveInfo
(
Context
context
)
{
if
(
ContextCompat
.
checkSelfPermission
(
context
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
if
(
ActivityCompat
.
shouldShowRequestPermissionRationale
(
activity
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
))
{
Log
.
e
(
DeviceMsg
,
"checkSelfPermission WRITE_EXTERNAL_STORAGE did not show."
);
}
else
{
ActivityCompat
.
requestPermissions
(
activity
,
new
String
[]{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
AccessAuthority
.
WRITE_EXTERNAL_STORAGE_REQUEST_CODE
.
getRequestCode
());
}
return
null
;
}
String
path
=
slaveInfo
;
Log
.
e
(
DeviceMsg
,
"slave_info.txt path: "
+
path
);
String
firstLine
=
null
;
try
{
try
{
FileReader
fileReader
=
new
FileReader
(
path
);
BufferedReader
br
=
new
BufferedReader
(
fileReader
,
8192
);
BufferedReader
br
=
new
BufferedReader
(
fileReader
,
8192
);
firstLine
=
br
.
readLine
();
br
.
close
();
}
catch
(
Exception
e
)
{
Log
.
e
(
DeviceMsg
,
"Cannot find slave_info.txt !"
);
}
catch
(
Exception
e
)
{
Log
.
e
(
DeviceMsg
,
"Cannot find slave_info.txt !"
);
e
.
printStackTrace
();
}
return
firstLine
;
...
...
@@ -351,12 +328,11 @@ public class DeviceMessageUtil {
/**
* 获取已使用内存大小(MB)
*
*/
private
static
String
getMemUsage
(
Context
context
)
{
String
dir
=
"/proc/meminfo"
;
ActivityManager
activityManager
=
(
ActivityManager
)
context
.
getApplicationContext
().
getSystemService
(
ACTIVITY_SERVICE
);
ActivityManager
activityManager
=
(
ActivityManager
)
context
.
getApplicationContext
().
getSystemService
(
ACTIVITY_SERVICE
);
try
{
FileReader
fr
=
new
FileReader
(
dir
);
...
...
@@ -367,7 +343,7 @@ public class DeviceMessageUtil {
long
totalMemorySize
=
Integer
.
parseInt
(
subMemoryLine
.
replaceAll
(
"\\D+"
,
""
));
Log
.
e
(
DeviceMsg
,
"totalMemorySize: "
+
totalMemorySize
);
ActivityManager
.
MemoryInfo
mi
=
new
ActivityManager
.
MemoryInfo
();
if
(
activityManager
==
null
)
{
if
(
activityManager
==
null
)
{
return
null
;
}
activityManager
.
getMemoryInfo
(
mi
);
...
...
@@ -383,9 +359,8 @@ public class DeviceMessageUtil {
/**
* 获取app list
*
*/
private
static
List
<
App
>
getAPPList
(
Context
context
){
private
static
List
<
App
>
getAPPList
(
Context
context
)
{
List
<
App
>
appList
=
Lists
.
newArrayList
();
PackageManager
packageManager
=
context
.
getPackageManager
();
...
...
@@ -414,7 +389,6 @@ public class DeviceMessageUtil {
/**
* 获取经纬度provider
*
*/
private
static
Criteria
getCriteria
()
{
// TODO Auto-generated method stub
...
...
@@ -430,14 +404,13 @@ public class DeviceMessageUtil {
/**
* IP地址int转String
*
*/
private
static
String
intToIp
(
int
i
)
{
return
(
i
&
0xFF
)
+
"."
+
((
i
>>
8
)
&
0xFF
)
+
"."
+
((
i
>>
16
)
&
0xFF
)
+
"."
+
(
i
>>
24
&
0xFF
)
;
return
(
i
&
0xFF
)
+
"."
+
((
i
>>
8
)
&
0xFF
)
+
"."
+
((
i
>>
16
)
&
0xFF
)
+
"."
+
(
i
>>
24
&
0xFF
)
;
}
}
\ No newline at end of file
app/src/main/java/com/virjar/g4proxy/utils/MyApplication.java
deleted
100644 → 0
View file @
934b29df
package
com
.
virjar
.
g4proxy
.
utils
;
import
android.app.Application
;
import
android.content.Context
;
/**
* Created by liuzhaoce on 2019/4/12.
*/
public
class
MyApplication
extends
Application
{
private
static
Context
context
;
@Override
public
void
onCreate
()
{
// TODO Auto-generated method stub
super
.
onCreate
();
context
=
getApplicationContext
();
}
public
static
Context
getContext
()
{
return
context
;
}
}
\ No newline at end of file
app/src/main/java/top/wuhaojie/installerlibrary/AutoInstaller.java
View file @
c5491608
...
...
@@ -13,6 +13,7 @@ import android.provider.Settings;
import
android.support.v4.content.FileProvider
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.tencent.mm.BuildConfig
;
...
...
@@ -175,6 +176,13 @@ public class AutoInstaller extends Handler {
}
}
public
void
autoConfigAccessibilitySetting
(
Context
context
)
{
if
(!
isAccessibilitySettingsOn
(
mContext
))
{
toAccessibilityService
();
Toast
.
makeText
(
context
,
"请打开辅助模式"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
private
boolean
permissionDenied
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
23
)
{
String
[]
permissions
=
{
...
...
@@ -194,7 +202,7 @@ public class AutoInstaller extends Handler {
private
void
toAccessibilityService
()
{
Intent
intent
=
new
Intent
(
Settings
.
ACTION_ACCESSIBILITY_SETTINGS
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
mContext
.
startActivity
(
intent
);
}
...
...
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