Commit 1ab3e0a0 by 霍志良

feat:ydl-platform mac地址获取方式修改,且不将“:”-替换>“”。

parent 2325843e
......@@ -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
*/
private static String getLocalIpAddress() {
public static String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements(); ) {
......
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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment