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
09316943
Commit
09316943
authored
Nov 15, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add device info
parent
f993cf1b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
280 additions
and
23 deletions
+280
-23
app_build.gradle
+0
-8
build.gradle
+6
-0
python/func.py
+4
-6
src/main/java/com/common/bean/DeviceInfoBean.java
+0
-0
src/main/java/com/common/utils/Collector.java
+27
-9
src/main/java/tech/starwin/utils/context_utils/DeviceUtils.java
+243
-0
No files found.
app_build.gradle
View file @
09316943
...
@@ -25,14 +25,6 @@ android {
...
@@ -25,14 +25,6 @@ android {
}
}
try
{
try
{
buildConfigField
'Boolean'
,
'keystoreSign'
,
"${keystore_sign}"
}
catch
(
Exception
e
)
{
buildConfigField
'Boolean'
,
'keystoreSign'
,
"\"\""
}
try
{
buildConfigField
'Boolean'
,
'OPEN_LIVENESS'
,
"${open_liveness}"
buildConfigField
'Boolean'
,
'OPEN_LIVENESS'
,
"${open_liveness}"
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
buildConfigField
'Boolean'
,
'OPEN_LIVENESS'
,
"true"
buildConfigField
'Boolean'
,
'OPEN_LIVENESS'
,
"true"
...
...
build.gradle
View file @
09316943
...
@@ -36,6 +36,12 @@ android {
...
@@ -36,6 +36,12 @@ android {
buildConfigField
'Boolean'
,
'IS_HOST_APP'
,
"false"
buildConfigField
'Boolean'
,
'IS_HOST_APP'
,
"false"
}
}
try
{
buildConfigField
'String'
,
'KEYSTORE_SIGN'
,
"${keystore_sign}"
}
catch
(
Exception
e
)
{
buildConfigField
'String'
,
'KEYSTORE_SIGN'
,
"\"\""
}
}
}
buildTypes
{
buildTypes
{
release
{
release
{
...
...
python/func.py
View file @
09316943
...
@@ -83,11 +83,13 @@ class Function:
...
@@ -83,11 +83,13 @@ class Function:
"signging_storePassword"
:
key_name
,
"signging_storePassword"
:
key_name
,
}
}
self
.
update_properties
(
config
,
reset
)
self
.
update_properties
(
config
,
reset
)
config
[
'signing_certificate'
]
=
jks_path
config
[
'signging_storePassword'
]
=
key_name
self
.
upate_keytore_sign
(
config
)
def
upate_keytore_sign
(
self
,
config
):
def
upate_keytore_sign
(
self
,
config
):
jks_path
=
"
%
s/jks/
%
s"
%
(
config
[
'root'
],
config
[
'signing_certificate'
]
.
split
(
"/"
)[
2
])
jks_path
=
"
%
s/jks/
%
s"
%
(
config
[
'root'
],
config
[
'signing_certificate'
]
.
split
(
"/"
)[
2
])
output
=
os
.
popen
(
"keytool -list -v -keystore
%
s -keypass
%
s -storepass
%
s"
%
(
jks_path
,
config
[
'sign
ing_keyAlias'
],
config
[
'signing_keyAlias
'
]))
output
=
os
.
popen
(
"keytool -list -v -keystore
%
s -keypass
%
s -storepass
%
s"
%
(
jks_path
,
config
[
'sign
ging_storePassword'
],
config
[
'signging_storePassword
'
]))
sha1
=
output
.
read
()
.
split
(
"SHA1:"
)[
1
]
.
split
(
"SHA256"
)[
0
]
.
replace
(
" "
,
""
)
.
replace
(
"
\n
"
,
""
)
.
replace
(
"
\t
"
,
""
)
sha1
=
output
.
read
()
.
split
(
"SHA1:"
)[
1
]
.
split
(
"SHA256"
)[
0
]
.
replace
(
" "
,
""
)
.
replace
(
"
\n
"
,
""
)
.
replace
(
"
\t
"
,
""
)
self
.
update_properties
(
config
,
{
"keystore_sign"
:
"
\"
%
s
\"
"
%
sha1
})
self
.
update_properties
(
config
,
{
"keystore_sign"
:
"
\"
%
s
\"
"
%
sha1
})
...
@@ -114,10 +116,6 @@ class Function:
...
@@ -114,10 +116,6 @@ class Function:
with
open
(
"
%
s/gradle.properties"
%
config
[
'root'
],
"w"
,
encoding
=
"utf-8"
)
as
f_w
:
with
open
(
"
%
s/gradle.properties"
%
config
[
'root'
],
"w"
,
encoding
=
"utf-8"
)
as
f_w
:
f_w
.
write
(
file_content
)
f_w
.
write
(
file_content
)
properties
=
self
.
load_properties
(
"
%
s/gradle.properties"
%
config
[
'root'
])
new_config
=
config
.
copy
()
config
=
new_config
.
update
(
properties
)
# 移动apk
# 移动apk
def
move_apk
(
self
,
config
):
def
move_apk
(
self
,
config
):
file_name
=
"
%
s_
%
s"
%
(
file_name
=
"
%
s_
%
s"
%
(
...
...
src/main/java/com/common/bean/DeviceInfoBean.java
0 → 100644
View file @
09316943
This diff is collapsed.
Click to expand it.
src/main/java/com/common/utils/Collector.java
View file @
09316943
...
@@ -10,6 +10,8 @@ import android.util.Log;
...
@@ -10,6 +10,8 @@ import android.util.Log;
import
com.annimon.stream.Stream
;
import
com.annimon.stream.Stream
;
import
com.annimon.stream.function.BiFunction
;
import
com.annimon.stream.function.BiFunction
;
import
com.annimon.stream.function.Function
;
import
com.annimon.stream.function.Function
;
import
com.common.bean.CollectInfoEntity
;
import
com.google.gson.Gson
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
...
@@ -22,13 +24,9 @@ import java.util.List;
...
@@ -22,13 +24,9 @@ import java.util.List;
import
tech.starwin.database.DataBaseHelper
;
import
tech.starwin.database.DataBaseHelper
;
import
tech.starwin.database.entity.CallLogEntity
;
import
tech.starwin.database.entity.CallLogEntity
;
import
com.common.bean.CollectInfoEntity
;
import
com.common.toolbox.app_utils.DeviceInfo
;
import
com.google.gson.Gson
;
import
tech.starwin.database.entity.ContactEntity
;
import
tech.starwin.database.entity.ContactEntity
;
import
tech.starwin.database.entity.SmsEntity
;
import
tech.starwin.database.entity.SmsEntity
;
import
tech.starwin.utils.context_utils.DeviceUtils
;
public
class
Collector
{
public
class
Collector
{
enum
InfoType
{
enum
InfoType
{
...
@@ -38,6 +36,7 @@ public class Collector {
...
@@ -38,6 +36,7 @@ public class Collector {
LOCATION
,
LOCATION
,
PERMISSION
,
PERMISSION
,
MACHINE_TYPE
,
MACHINE_TYPE
,
DEVICE_INFO
,
// BEHAVIOR_MSG,
// BEHAVIOR_MSG,
CRASH_MSG
;
CRASH_MSG
;
...
@@ -83,7 +82,7 @@ public class Collector {
...
@@ -83,7 +82,7 @@ public class Collector {
});
});
List
<
ContactEntity
>
contactEntityList
=
DataBaseHelper
.
getContacts
();
List
<
ContactEntity
>
contactEntityList
=
DataBaseHelper
.
getContacts
();
List
<
CollectInfoEntity
>
infos2
=
Stream
.
of
(
InfoType
.
CONTACT
,
InfoType
.
CALL_LOG
,
InfoType
.
SMS_LOG
)
List
<
CollectInfoEntity
>
infos2
=
Stream
.
of
(
InfoType
.
CONTACT
,
InfoType
.
CALL_LOG
,
InfoType
.
SMS_LOG
,
InfoType
.
DEVICE_INFO
)
.
map
(
new
Function
<
InfoType
,
CollectInfoEntity
>()
{
.
map
(
new
Function
<
InfoType
,
CollectInfoEntity
>()
{
@Override
@Override
public
CollectInfoEntity
apply
(
InfoType
infoType
)
{
public
CollectInfoEntity
apply
(
InfoType
infoType
)
{
...
@@ -134,7 +133,7 @@ public class Collector {
...
@@ -134,7 +133,7 @@ public class Collector {
});
});
//SDK-CONTACT-START
//SDK-CONTACT-START
List
<
ContactEntity
>
contactEntityList
=
DataBaseHelper
.
getContacts
();
List
<
ContactEntity
>
contactEntityList
=
DataBaseHelper
.
getContacts
();
List
<
CollectInfoEntity
>
infos2
=
Stream
.
of
(
InfoType
.
CONTACT
)
List
<
CollectInfoEntity
>
infos2
=
Stream
.
of
(
InfoType
.
CONTACT
,
InfoType
.
DEVICE_INFO
)
.
map
(
new
Function
<
InfoType
,
CollectInfoEntity
>()
{
.
map
(
new
Function
<
InfoType
,
CollectInfoEntity
>()
{
@Override
@Override
public
CollectInfoEntity
apply
(
InfoType
infoType
)
{
public
CollectInfoEntity
apply
(
InfoType
infoType
)
{
...
@@ -160,7 +159,7 @@ public class Collector {
...
@@ -160,7 +159,7 @@ public class Collector {
CollectInfoEntity
deviceInfoEntity
=
new
CollectInfoEntity
();
CollectInfoEntity
deviceInfoEntity
=
new
CollectInfoEntity
();
deviceInfoEntity
.
setType
(
"DEVICE_INFO"
);
deviceInfoEntity
.
setType
(
"DEVICE_INFO"
);
deviceInfoEntity
.
setUpdate_time
(
System
.
currentTimeMillis
());
deviceInfoEntity
.
setUpdate_time
(
System
.
currentTimeMillis
());
deviceInfoEntity
.
setBody
(
new
Gson
().
toJson
(
Device
Info
.
getDeviceInfo
(
context
)));
deviceInfoEntity
.
setBody
(
new
Gson
().
toJson
(
Device
Utils
.
getInstance
().
getDeviceInfo
(
)));
infos1
.
add
(
deviceInfoEntity
);
infos1
.
add
(
deviceInfoEntity
);
return
infos1
;
return
infos1
;
}
}
...
@@ -196,10 +195,12 @@ public class Collector {
...
@@ -196,10 +195,12 @@ public class Collector {
case
MACHINE_TYPE:
case
MACHINE_TYPE:
entity
.
setBody
(
toMachineTypeDTO
(
context
));
entity
.
setBody
(
toMachineTypeDTO
(
context
));
break
;
break
;
case
PERMISSION:
case
PERMISSION:
entity
.
setBody
(
toPermissionTypeDTO
(
context
));
entity
.
setBody
(
toPermissionTypeDTO
(
context
));
break
;
break
;
case
DEVICE_INFO:
entity
.
setBody
(
toDeviceTypeDTO
(
context
));
break
;
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
//UploadManager.uploadException(e, "getStoreEntity");
//UploadManager.uploadException(e, "getStoreEntity");
...
@@ -209,6 +210,23 @@ public class Collector {
...
@@ -209,6 +210,23 @@ public class Collector {
return
entity
;
return
entity
;
}
}
private
static
String
toDeviceTypeDTO
(
Context
context
)
{
JSONObject
json
=
initJSON
(
InfoType
.
MACHINE_TYPE
,
context
);
try
{
JSONArray
array
=
new
JSONArray
();
json
.
put
(
"totalNumber"
,
1
);
json
.
put
(
"latestTime"
,
0
);
json
.
put
(
"earliestTime"
,
0
);
json
.
put
(
"data"
,
new
Gson
().
toJson
(
DeviceUtils
.
getInstance
().
getDeviceInfo
()));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
json
.
toString
();
}
private
static
String
toMachineTypeDTO
(
Context
context
)
{
private
static
String
toMachineTypeDTO
(
Context
context
)
{
JSONObject
json
=
initJSON
(
InfoType
.
MACHINE_TYPE
,
context
);
JSONObject
json
=
initJSON
(
InfoType
.
MACHINE_TYPE
,
context
);
try
{
try
{
...
...
src/main/java/tech/starwin/utils/context_utils/DeviceUtils.java
0 → 100644
View file @
09316943
package
tech
.
starwin
.
utils
.
context_utils
;
import
android.annotation.SuppressLint
;
import
android.app.ActivityManager
;
import
android.content.Context
;
import
android.content.ContextWrapper
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.hardware.Camera
;
import
android.os.BatteryManager
;
import
android.os.Build
;
import
android.os.Environment
;
import
android.os.StatFs
;
import
android.os.SystemClock
;
import
android.provider.Settings
;
import
android.text.TextUtils
;
import
com.common.bean.DeviceInfoBean
;
import
java.io.BufferedReader
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.lang.reflect.Method
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
tech.starwin.BuildConfig
;
/**
* Created by SiKang on 2019-11-15.
*/
public
class
DeviceUtils
{
private
DeviceInfoBean
deviceInfoBean
;
private
static
DeviceUtils
deviceUtils
=
new
DeviceUtils
();
public
static
DeviceUtils
getInstance
()
{
return
deviceUtils
;
}
DeviceUtils
()
{
deviceInfoBean
=
new
DeviceInfoBean
();
}
/**
* 如果APP更改了语言,需要在更改之前初始化
*/
public
void
init
(
Context
context
)
{
deviceInfoBean
.
setScreenWidth
(
context
.
getResources
().
getDisplayMetrics
().
widthPixels
);
deviceInfoBean
.
setScreenHeight
(
context
.
getResources
().
getDisplayMetrics
().
heightPixels
);
deviceInfoBean
.
setRoot
(
AppInfoUtils
.
isRoot
());
deviceInfoBean
.
setAndroidId
(
Settings
.
Secure
.
getString
(
context
.
getContentResolver
(),
Settings
.
Secure
.
ANDROID_ID
));
deviceInfoBean
.
setLocal
(
Locale
.
getDefault
());
deviceInfoBean
.
setTimeZone
(
TimeZone
.
getDefault
());
long
[]
ramInfo
=
getRAMInfo
(
context
);
deviceInfoBean
.
setTotalMemory
(
ramInfo
[
0
]
/
1024
);
deviceInfoBean
.
setFreeMemory
(
ramInfo
[
1
]
/
1024
);
long
[]
romInfo
=
getROMInfo
();
deviceInfoBean
.
setDiskSpace
(
romInfo
[
0
]
/
1024
);
deviceInfoBean
.
setDiskFreeSpace
(
romInfo
[
1
]
/
1024
);
deviceInfoBean
.
setAppSign
(
BuildConfig
.
KEYSTOR_SIGN
);
deviceInfoBean
.
setBaseBandVersion
(
getBaseBandVersion
());
deviceInfoBean
.
setBattery
(
getBattery
(
context
));
deviceInfoBean
.
setBluetooth
(
Settings
.
Secure
.
getString
(
context
.
getContentResolver
(),
"bluetooth_address"
));
deviceInfoBean
.
setCameraNum
(
Camera
.
getNumberOfCameras
());
deviceInfoBean
.
setDebug
((
Settings
.
Secure
.
getInt
(
context
.
getContentResolver
(),
Settings
.
Secure
.
ADB_ENABLED
,
0
)
>
0
));
deviceInfoBean
.
setSimulator
(
isSimulator
());
deviceInfoBean
.
setKernelVersion
(
getKernelVersion
());
deviceInfoBean
.
setMacAddress
(
getMacAddress
());
deviceInfoBean
.
setUpTime
(
SystemClock
.
elapsedRealtime
());
// WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
// deviceInfoBean.setWifiSsid(wifi.getConnectionInfo().getSSID());
// deviceInfoBean.setWifiBssid(wifi.getConnectionInfo().getBSSID());
// deviceInfoBean.setWifiRssi(wifi.getConnectionInfo().getRssi());
}
public
DeviceInfoBean
getDeviceInfo
()
{
return
deviceInfoBean
;
}
private
long
[]
getRAMInfo
(
Context
context
)
{
ActivityManager
manager
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
ActivityManager
.
MemoryInfo
info
=
new
ActivityManager
.
MemoryInfo
();
manager
.
getMemoryInfo
(
info
);
return
new
long
[]{
info
.
totalMem
,
info
.
availMem
};
}
private
long
[]
getROMInfo
()
{
final
StatFs
statFs
=
new
StatFs
(
Environment
.
getDataDirectory
().
getPath
());
long
totalCounts
=
statFs
.
getBlockCountLong
();
//总共的block数
long
availableCounts
=
statFs
.
getAvailableBlocksLong
();
//获取可用的block数
long
size
=
statFs
.
getBlockSizeLong
();
//每格所占的大小,一般是4KB==
long
availROMSize
=
availableCounts
*
size
;
//可用内部存储大小
long
totalROMSize
=
totalCounts
*
size
;
//内部存储总大小
return
new
long
[]{
totalROMSize
,
availROMSize
};
}
public
String
getBaseBandVersion
()
{
String
version
=
""
;
try
{
@SuppressLint
(
"PrivateApi"
)
Class
cl
=
Class
.
forName
(
"android.os.SystemProperties"
);
Object
invoker
=
cl
.
newInstance
();
//noinspection unchecked
Method
m
=
cl
.
getMethod
(
"get"
,
String
.
class
,
String
.
class
);
Object
result
=
m
.
invoke
(
invoker
,
"gsm.version.baseband"
,
"no message"
);
version
=
(
String
)
result
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
String
radioVersion
=
Build
.
getRadioVersion
();
version
=
TextUtils
.
isEmpty
(
version
)
?
radioVersion
:
version
;
return
version
==
null
?
""
:
version
;
}
/**
* 电池信息
*
* @param context
* @return
*/
public
int
getBattery
(
Context
context
)
{
//API >= 21 (5.0,L)
BatteryManager
manager
=
(
BatteryManager
)
context
.
getSystemService
(
Context
.
BATTERY_SERVICE
);
int
batteryCurrentCap
=
0
;
///当前电量百分比
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
batteryCurrentCap
=
manager
.
getIntProperty
(
BatteryManager
.
BATTERY_PROPERTY_CAPACITY
);
}
else
{
Intent
intent
=
new
ContextWrapper
(
context
).
registerReceiver
(
null
,
new
IntentFilter
(
Intent
.
ACTION_BATTERY_CHANGED
));
if
(
intent
!=
null
)
{
batteryCurrentCap
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_LEVEL
,
-
1
)
*
100
/
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_SCALE
,
-
1
);
}
}
return
batteryCurrentCap
;
}
/*
*根据CPU是否为电脑来判断是否为模拟器
*返回:true 为模拟器
*/
public
boolean
isSimulator
()
{
try
{
String
[]
args
=
{
"/system/bin/cat"
,
"/proc/cpuinfo"
};
ProcessBuilder
cmd
=
new
ProcessBuilder
(
args
);
Process
process
=
cmd
.
start
();
StringBuffer
sb
=
new
StringBuffer
();
String
readLine
=
""
;
BufferedReader
responseReader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
(),
"utf-8"
));
while
((
readLine
=
responseReader
.
readLine
())
!=
null
)
{
sb
.
append
(
readLine
);
}
responseReader
.
close
();
String
cpuInfo
=
sb
.
toString
().
toLowerCase
();
if
((
cpuInfo
.
contains
(
"intel"
)
||
cpuInfo
.
contains
(
"amd"
)))
{
return
true
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
public
String
getKernelVersion
()
{
Process
process
;
String
mLinuxKernal
=
null
;
try
{
process
=
Runtime
.
getRuntime
().
exec
(
"cat /proc/version"
);
if
(
process
!=
null
)
{
InputStream
outs
=
process
.
getInputStream
();
InputStreamReader
isrout
=
new
InputStreamReader
(
outs
);
BufferedReader
brout
=
new
BufferedReader
(
isrout
,
8
*
1024
);
StringBuilder
result
=
new
StringBuilder
();
String
line
;
// get the whole standard output string
try
{
while
((
line
=
brout
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
// result += "\n";
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(!
""
.
equals
(
result
.
toString
()))
{
String
keyword
=
"version "
;
int
index
=
result
.
indexOf
(
keyword
);
line
=
result
.
substring
(
index
+
keyword
.
length
());
index
=
line
.
indexOf
(
" "
);
mLinuxKernal
=
line
.
substring
(
0
,
index
);
}
}
mLinuxKernal
=
TextUtils
.
isEmpty
(
mLinuxKernal
)
?
System
.
getProperty
(
"os.version"
)
:
mLinuxKernal
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
mLinuxKernal
==
null
?
""
:
mLinuxKernal
;
}
/**
* 获取mac地址
*
* @return
*/
public
String
getMacAddress
()
{
String
macAddress
=
null
;
StringBuffer
buf
=
new
StringBuffer
();
NetworkInterface
networkInterface
=
null
;
try
{
networkInterface
=
NetworkInterface
.
getByName
(
"eth1"
);
if
(
networkInterface
==
null
)
{
networkInterface
=
NetworkInterface
.
getByName
(
"wlan0"
);
}
if
(
networkInterface
==
null
)
{
return
""
;
}
byte
[]
addr
=
networkInterface
.
getHardwareAddress
();
for
(
byte
b
:
addr
)
{
buf
.
append
(
String
.
format
(
"%02X:"
,
b
));
}
if
(
buf
.
length
()
>
0
)
{
buf
.
deleteCharAt
(
buf
.
length
()
-
1
);
}
macAddress
=
buf
.
toString
();
}
catch
(
SocketException
e
)
{
e
.
printStackTrace
();
}
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