Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
1ab3e0a0
Commit
1ab3e0a0
authored
Dec 02, 2020
by
霍志良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:ydl-platform mac地址获取方式修改,且不将“:”-替换>“”。
parent
2325843e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
177 additions
and
12 deletions
+177
-12
DeviceTool.java
ydl-platform/src/main/java/com/ydl/ydlcommon/utils/DeviceTool.java
+154
-2
ActionCountUtils.kt
ydl-platform/src/main/java/com/ydl/ydlcommon/utils/actionutil/ActionCountUtils.kt
+23
-10
No files found.
ydl-platform/src/main/java/com/ydl/ydlcommon/utils/DeviceTool.java
View file @
1ab3e0a0
...
...
@@ -28,10 +28,13 @@ import java.io.FileReader;
import
java.io.InputStreamReader
;
import
java.io.LineNumberReader
;
import
java.io.Reader
;
import
java.net.Inet6Address
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.util.Collections
;
import
java.util.Enumeration
;
import
java.util.List
;
import
static
com
.
umeng
.
socialize
.
utils
.
ContextUtil
.
getPackageName
;
...
...
@@ -146,6 +149,17 @@ public class DeviceTool {
}
public
static
String
getEncryptionAndroidID
()
{
try
{
@SuppressLint
(
"HardwareIds"
)
String
id
=
Settings
.
Secure
.
getString
(
RxTool
.
getContext
().
getContentResolver
(),
Settings
.
Secure
.
ANDROID_ID
);
return
TextUtils
.
isEmpty
(
id
)
?
""
:
id
;
}
catch
(
Exception
e
)
{
return
""
;
}
}
public
static
String
getAndroidID
()
{
try
{
@SuppressLint
(
"HardwareIds"
)
String
id
=
Settings
.
Secure
.
getString
(
...
...
@@ -158,7 +172,6 @@ public class DeviceTool {
}
}
//没有网络连接
public
static
final
int
NETWORN_NONE
=
0
;
//wifi连接
...
...
@@ -263,7 +276,119 @@ public class DeviceTool {
return
"02:00:00:00:00:00"
;
}
/*
* 获取MAC地址
*GPRS链接和WIFI链接返回同一个MAC地址
* */
public
static
String
getMacFromHardware
()
{
try
{
List
<
NetworkInterface
>
all
=
Collections
.
list
(
NetworkInterface
.
getNetworkInterfaces
());
for
(
NetworkInterface
nif
:
all
)
{
if
(!
nif
.
getName
().
equalsIgnoreCase
(
"wlan0"
))
continue
;
byte
[]
macBytes
=
nif
.
getHardwareAddress
();
if
(
macBytes
==
null
)
{
return
""
;
}
StringBuilder
res1
=
new
StringBuilder
();
for
(
byte
b
:
macBytes
)
{
res1
.
append
(
String
.
format
(
"%02X:"
,
b
));
}
if
(
res1
.
length
()
>
0
)
{
res1
.
deleteCharAt
(
res1
.
length
()
-
1
);
}
return
res1
.
toString
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
"02:00:00:00:00:00"
;
}
/**
*
* 将ip的整数形式转换成ip形式
*
* @param ipInt
* @return
*/
public
static
String
int2ip
(
int
ipInt
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
ipInt
&
0xFF
).
append
(
"."
);
sb
.
append
((
ipInt
>>
8
)
&
0xFF
).
append
(
"."
);
sb
.
append
((
ipInt
>>
16
)
&
0xFF
).
append
(
"."
);
sb
.
append
((
ipInt
>>
24
)
&
0xFF
);
return
sb
.
toString
();
}
/**
* 获取WIFI当前ip地址
*
* @param context
* @return
*/
public
static
String
getLocalWifiIpAddress
(
Context
context
)
{
try
{
WifiManager
wifiManager
=
(
WifiManager
)
context
.
getSystemService
(
Context
.
WIFI_SERVICE
);
WifiInfo
wifiInfo
=
wifiManager
.
getConnectionInfo
();
int
i
=
wifiInfo
.
getIpAddress
();
return
int2ip
(
i
);
}
catch
(
Exception
ex
)
{
return
" 获取IP出错鸟!!!!请保证是WIFI,或者请重新打开网络!\n"
+
ex
.
getMessage
();
}
// return null;
}
//GPRS连接下的ip
public
static
String
getLocalGPRSIpAddress
()
{
try
{
for
(
Enumeration
<
NetworkInterface
>
en
=
NetworkInterface
.
getNetworkInterfaces
();
en
.
hasMoreElements
();
)
{
NetworkInterface
intf
=
en
.
nextElement
();
for
(
Enumeration
<
InetAddress
>
enumIpAddr
=
intf
.
getInetAddresses
();
enumIpAddr
.
hasMoreElements
();
)
{
InetAddress
inetAddress
=
enumIpAddr
.
nextElement
();
if
(!
inetAddress
.
isLoopbackAddress
())
{
return
inetAddress
.
getHostAddress
().
toString
();
}
}
}
}
catch
(
SocketException
ex
)
{
Log
.
e
(
"WifiPreferenceIpAddress"
,
ex
.
toString
());
}
return
null
;
}
/**
* 通过网络接口取MAC地址
* @return
*/
public
static
String
getNewMac
()
{
try
{
List
<
NetworkInterface
>
all
=
Collections
.
list
(
NetworkInterface
.
getNetworkInterfaces
());
for
(
NetworkInterface
nif
:
all
)
{
if
(!
nif
.
getName
().
equalsIgnoreCase
(
"wlan0"
))
continue
;
byte
[]
macBytes
=
nif
.
getHardwareAddress
();
if
(
macBytes
==
null
)
{
return
null
;
}
StringBuilder
res1
=
new
StringBuilder
();
for
(
byte
b
:
macBytes
)
{
res1
.
append
(
String
.
format
(
"%02X:"
,
b
));
}
if
(
res1
.
length
()
>
0
)
{
res1
.
deleteCharAt
(
res1
.
length
()
-
1
);
}
return
res1
.
toString
();
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
return
null
;
}
public
static
String
getLocalMacAddressFromWifiInfo
(
Context
context
)
{
WifiManager
wifi
=
(
WifiManager
)
context
.
getSystemService
(
Context
.
WIFI_SERVICE
);
WifiInfo
winfo
=
wifi
.
getConnectionInfo
();
...
...
@@ -271,7 +396,34 @@ public class DeviceTool {
return
mac
;
}
/*
* 获取IPV6地址
* */
public
static
String
getLocalIpV6
()
{
try
{
for
(
Enumeration
<
NetworkInterface
>
en
=
NetworkInterface
.
getNetworkInterfaces
();
en
.
hasMoreElements
();
)
{
NetworkInterface
intf
=
en
.
nextElement
();
for
(
Enumeration
<
InetAddress
>
enumIpAddr
=
intf
.
getInetAddresses
();
enumIpAddr
.
hasMoreElements
();
)
{
InetAddress
inetAddress
=
enumIpAddr
.
nextElement
();
// logger.error("ip1 " + inetAddress);
/* logger.error("getHostName " + inetAddress.getHostName());
logger.error("getCanonicalHostName " + inetAddress.getCanonicalHostName());
logger.error("getAddress " + Arrays.toString(inetAddress.getAddress()));
logger.error("getHostAddress " + inetAddress.getHostAddress());*/
if
(!
inetAddress
.
isLoopbackAddress
()
&&
inetAddress
instanceof
Inet6Address
)
{
return
inetAddress
.
getHostAddress
();
}
}
}
}
catch
(
Exception
ex
)
{
Log
.
e
(
"IP Address"
,
ex
.
toString
());
}
return
null
;
}
public
static
String
getMacAddress
(
Context
context
)
{
// 如果是6.0以下,直接通过wifimanager获取
...
...
@@ -429,7 +581,7 @@ public class DeviceTool {
*
* @return
*/
p
rivate
static
String
getLocalIpAddress
()
{
p
ublic
static
String
getLocalIpAddress
()
{
try
{
for
(
Enumeration
<
NetworkInterface
>
en
=
NetworkInterface
.
getNetworkInterfaces
();
en
.
hasMoreElements
();
)
{
...
...
ydl-platform/src/main/java/com/ydl/ydlcommon/utils/actionutil/ActionCountUtils.kt
View file @
1ab3e0a0
package
com.ydl.ydlcommon.utils.actionutil
import
android.annotation.SuppressLint
import
android.content.Context
import
android.net.ConnectivityManager
import
android.net.NetworkInfo
import
android.net.wifi.WifiManager
import
android.os.Build
import
android.provider.Settings
import
android.text.TextUtils
import
android.util.Log
//import com.bun.miitmdid.content.ContextKeeper
import
com.google.gson.Gson
import
com.ydl.burypointlib.MD5Util
//import com.ydl.devicesidlib.DemoHelper
import
com.ydl.devicesidlib.DeviceIDHelper
import
com.ydl.devicesidlib.Utils
...
...
@@ -105,7 +108,10 @@ class ActionCountUtils {
)
{
count
(
uid
,
partId
,
position
,
url
,
api
,
signs
=
*
arrayOf
(
sign1
))
}
/*
*
* 测试用埋点,现在服务端统一用百度埋点
* */
fun
count
(
uid
:
String
?,
partId
:
String
,
...
...
@@ -175,9 +181,8 @@ class ActionCountUtils {
}
actionDataParams
.
screenWidth
(
RxDeviceTool
.
getScreenWidth
(
RxTool
.
getContext
()
!!
))
actionDataParams
.
screenHeight
(
RxDeviceTool
.
getScreenHeight
(
RxTool
.
getContext
()
!!
))
//剩余额外参数根据需求定义
LogUtil
.
e
(
"androididgetMacFromHardwareMAC地址:${DeviceTool.getMacFromHardware()}"
)
//请求
request
(
actionDataParams
.
build
())
...
...
@@ -243,20 +248,28 @@ class ActionCountUtils {
baiduActionDataParams
.
convertTime
(
System
.
currentTimeMillis
()
/
1000
)
baiduActionDataParams
.
appid
(
0
.
toLong
())
baiduActionDataParams
.
appName
(
appName
)
baiduActionDataParams
.
androidId
(
DeviceTool
.
getAndroidID
())
try
{
@SuppressLint
(
"HardwareIds"
)
val
id
=
Settings
.
Secure
.
getString
(
RxTool
.
getContext
().
contentResolver
,
Settings
.
Secure
.
ANDROID_ID
)
LogUtil
.
e
(
"androidid未加密:${id}"
)
}
catch
(
e
:
java
.
lang
.
Exception
)
{
}
baiduActionDataParams
.
androidId
(
DeviceTool
.
getAndroidID
())
//MD5加密的androidId
baiduActionDataParams
.
ip
(
""
)
baiduActionDataParams
.
ipv6
(
""
)
baiduActionDataParams
.
ipv6
(
""
)
//给服务端传IPV6地址DeviceTool.getLocalIpV6()
baiduActionDataParams
.
tp
(
android
.
os
.
Build
.
MODEL
)
baiduActionDataParams
.
network
(
DeviceTool
.
getNetworkState
(
RxTool
.
getContext
()))
baiduActionDataParams
.
convertParam
(
""
)
baiduActionDataParams
.
uid
(
uid
)
Log
.
e
(
"baiduActionDataParams"
,
"---------${baiduActionDataParams}"
)
try
{
var
mac
=
DeviceTool
.
getMac
(
BaseApp
.
getApp
())
if
(!
TextUtils
.
isEmpty
(
mac
))
{
mac
=
mac
.
replace
(
":"
,
""
)
}
com
.
ydl
.
ydlcommon
.
utils
.
LogUtil
.
d
(
"MAC=${mac}"
)
var
mac
=
DeviceTool
.
getMacFromHardware
()
//获得mac地址,gprs和wifi返回同一个mac地址
LogUtil
.
e
(
"androidid:mac:${mac}"
)
baiduActionDataParams
.
mac
(
mac
)
}
catch
(
e
:
Exception
)
{
...
...
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