jimu-decompiled/sources/com/ubtrobot/analytics/device/DeviceInfoUtils.java
2025-05-13 19:24:51 +02:00

237 lines
7.7 KiB
Java

package com.ubtrobot.analytics.device;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import com.ijm.dataencryption.de.DataDecryptTool;
import com.ubt.jimu.diy.model.CategoryModel;
import com.ubt.jimu.diy.view.fragment.BuildStepFragment;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.Enumeration;
import java.util.Locale;
import java.util.TimeZone;
import java.util.UUID;
/* loaded from: classes2.dex */
public class DeviceInfoUtils {
private static final byte[] a = new byte[0];
private static volatile String b;
public static String a() {
return Locale.getDefault().getLanguage();
}
public static String b() {
return Build.MODEL;
}
public static String c() {
return Build.VERSION.RELEASE;
}
public static String d(Context context) {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException unused) {
Log.w("Analytics", "Get app version fail.");
return "";
}
}
public static String e() {
try {
return TimeZone.getDefault().getDisplayName(false, 0);
} catch (AssertionError unused) {
Log.w("Analytics", "Fail get time zone.");
String date = new Date(119, 5, 9).toString();
return date.substring(20, date.length() - 5);
}
}
@SuppressLint({"MissingPermission"})
private static String f(Context context) {
String imei;
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
if (telephonyManager != null) {
try {
imei = Build.VERSION.SDK_INT >= 26 ? telephonyManager.getImei() : telephonyManager.getDeviceId();
} catch (SecurityException unused) {
}
return (imei != null || "000000000000000".equals(imei)) ? "" : imei;
}
imei = null;
if (imei != null) {
}
}
private static String g(Context context) {
String macAddress;
if (Build.VERSION.SDK_INT >= 23) {
macAddress = g();
if (TextUtils.isEmpty(macAddress)) {
macAddress = f();
}
} else {
macAddress = ((WifiManager) context.getSystemService("wifi")).getConnectionInfo().getMacAddress();
}
return (macAddress == null || "02:00:00:00:00:00".equals(macAddress)) ? "" : macAddress;
}
public static String h(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
return telephonyManager != null ? telephonyManager.getSimOperator() : "";
}
private static String i(Context context) {
if (b != null) {
return b;
}
synchronized (a) {
if (b != null) {
return b;
}
String j = j(context);
if (j.length() == 0) {
j = a(context);
}
b = j;
return b;
}
}
private static String j(Context context) {
return context.getApplicationContext().getSharedPreferences("deviceId", 0).getString(BuildStepFragment.UUID, "");
}
private static String a(Context context) {
String b2 = b(b(context));
a(context, b2);
return b2;
}
private static String b(String str) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(str.getBytes());
return new BigInteger(1, messageDigest.digest()).toString(16);
} catch (NoSuchAlgorithmException unused) {
throw new IllegalStateException("MessageDigest md5 fail.");
}
}
private static String c(Context context) {
String string = Settings.Secure.getString(context.getContentResolver(), "android_id");
return (string == null || "9774d56d682e549c".equals(string)) ? "" : string;
}
private static void a(Context context, String str) {
SharedPreferences.Editor edit = context.getApplicationContext().getSharedPreferences("deviceId", 0).edit();
edit.putString(BuildStepFragment.UUID, str);
edit.apply();
}
@SuppressLint({"MissingPermission"})
private static String d() {
try {
String serial = Build.VERSION.SDK_INT >= 26 ? Build.getSerial() : Build.SERIAL;
return CategoryModel.unknown.equals(serial.toLowerCase()) ? "" : serial;
} catch (SecurityException unused) {
Log.i("Analytics", "Get sn is not permission.");
return "";
}
}
private static String f() {
for (String str : new String[]{"/sys/class/net/wlan0/address", "/sys/class/net/eth0/address", "/sys/devices/virtual/net/wlan0/address"}) {
String a2 = a(str);
if (a2.length() > 0) {
return a2;
}
}
return "";
}
private static String b(Context context) {
String g = g(context);
String c = c(context);
String f = f(context);
String d = d();
StringBuffer stringBuffer = new StringBuffer();
if (g.length() != 0) {
stringBuffer.append(g);
}
if (c.length() != 0) {
stringBuffer.append(c);
}
if (f.length() != 0) {
stringBuffer.append(f);
}
if (d.length() != 0) {
stringBuffer.append(d);
}
if (stringBuffer.length() == 0) {
stringBuffer.append(UUID.randomUUID().toString().replace("-", ""));
}
return stringBuffer.toString();
}
public static String e(Context context) {
return i(context);
}
private static String g() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
if (!networkInterfaces.hasMoreElements()) {
return "";
}
NetworkInterface nextElement = networkInterfaces.nextElement();
String name = nextElement.getName();
if (!"wlan0".equals(name) && !"eth0".equals(name)) {
return "";
}
try {
byte[] hardwareAddress = nextElement.getHardwareAddress();
StringBuilder sb = new StringBuilder();
for (byte b2 : hardwareAddress) {
sb.append(String.format("%02X:", Byte.valueOf(b2)));
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString().toLowerCase(Locale.getDefault());
} catch (SocketException unused) {
return "";
}
} catch (SocketException unused2) {
Log.w("Analytics", "Get Enumeration fail.");
return "";
}
}
private static String a(String str) {
String str2 = "";
try {
FileReader fileReader = new FileReader(str);
str2 = new BufferedReader(fileReader, DataDecryptTool.DECRYPT_SP_FILE).readLine();
fileReader.close();
} catch (FileNotFoundException | IOException unused) {
}
return str2;
}
}