Files
midi-android/moduleUtil/src/main/java/com/xscm/moduleutil/utils/SystemUtils.java
2025-08-26 19:34:44 +08:00

137 lines
4.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.xscm.moduleutil.utils;
import android.content.Context;
import android.os.Build;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.MetaDataUtils;
import com.chad.library.BuildConfig;
import com.xscm.moduleutil.base.CommonAppContext;
import com.xscm.moduleutil.utils.config.ConfigUtils;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class SystemUtils {
/**
* 获取当前手机系统语言。
*
* @return 返回当前系统语言。例如:当前设置的是“中文-中国”则返回“zh-CN”
*/
public static String getSystemLanguage() {
return Locale.getDefault().getLanguage();
}
/**
* 获取当前手机系统版本号
*
* @return 系统版本号
*/
public static String getSystemVersion() {
return Build.VERSION.RELEASE;
}
/**
* 获取手机型号
*
* @return 手机型号
*/
public static String getSystemModel() {
return Build.MODEL;
}
/**
* 获取手机厂商
*
* @return 手机厂商
*/
public static String getDeviceBrand() {
return Build.BRAND;
}
public static String getClientID(String channel) {
StringBuffer sb = new StringBuffer();
sb.append(channel);
sb.append(Build.SERIAL);
sb.append(Build.BOARD.length() % 10);
sb.append(Build.BRAND.length() % 10);
sb.append(Build.CPU_ABI.length() % 10);
sb.append(Build.DEVICE.length() % 10);
sb.append(Build.DISPLAY.length() % 10);
sb.append(Build.HOST.length() % 10);
sb.append(Build.ID.length() % 10);
sb.append(Build.MANUFACTURER.length() % 10);
sb.append(Build.MODEL.length() % 10);
sb.append(Build.PRODUCT.length() % 10);
sb.append(Build.TAGS.length() % 10);
sb.append(Build.TYPE.length() % 10);
sb.append(Build.USER.length() % 10);
return Md5Utils.get(sb.toString());
}
public static String getShortClientID(Context context, String channel) {
String cid = getClientID(channel);
return Md5Utils.get(cid + getUUID(context));
}
public static String getShortClientID(Context context) {
String cid = getClientID("xqipaoandroid");
return Md5Utils.get(cid + getUUID(context));
}
/**
* 得到全局唯一UUID
*/
public static String getUUID(Context context) {
String system_uuid_key = "system_uuid";
ConfigUtils configUtils = ConfigUtils.getInstance(context);
configUtils.setConfigName(system_uuid_key);
String system_config_uuid = configUtils.findStringByKey(system_uuid_key);
if (system_config_uuid == null) {
// system_config_uuid = DeviceUtils.getUniqueDeviceId();
configUtils.addOrUpdateText(system_uuid_key, system_config_uuid);
}
return system_config_uuid;
}
/**
* 系统参数
*
* @return
*/
public static Map<String, String> getSystemParams() {
Map<String, String> headers = new HashMap<>();
headers.put("deviceId", SystemUtils.getShortClientID(CommonAppContext.getInstance()));
headers.put("appVersion", BuildConfig.VERSION_NAME + "." + BuildConfig.VERSION_CODE);
headers.put("versionName", BuildConfig.VERSION_NAME);
headers.put("versionCode", String.valueOf(BuildConfig.VERSION_CODE));
headers.put("system", "android");
headers.put("emulator", CommonAppContext.getInstance().emulator);
headers.put("deviceName", SystemUtils.getDeviceBrand() + SystemUtils.getSystemModel() + SystemUtils.getSystemVersion());
try {
String channelId = MetaDataUtils.getMetaDataInApp("TD_CHANNEL_ID");
headers.put("CHANNELID", channelId);
headers.put("appName", encodeHeadInfo(AppUtils.getAppName()));
} catch (Exception e) {
e.printStackTrace();
}
return headers;
}
private static String encodeHeadInfo( String headInfo ) {
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0, length = headInfo.length(); i < length; i++) {
char c = headInfo.charAt(i);
if (c <= '\u001f' || c >= '\u007f') {
stringBuffer.append( String.format ("\\u%04x", (int)c) );
} else {
stringBuffer.append(c);
}
}
return stringBuffer.toString();
}
}