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.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.isEmpty()) { // system_config_uuid = DeviceUtils.getUniqueDeviceId(); configUtils.addOrUpdateText(system_uuid_key, system_config_uuid); } return system_config_uuid; } /** * 系统参数 * * @return */ public static Map getSystemParams() { Map headers = new HashMap<>(); headers.put("deviceId", SystemUtils.getShortClientID(CommonAppContext.getInstance())); headers.put("appId", CommonAppContext.getInstance().appId); headers.put("versionName", CommonAppContext.getInstance().appVersionName); headers.put("versionCode", CommonAppContext.getInstance().appVersionCode); 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(); } public static int getWidth(int value) { // 获取屏幕宽度 int screenWidth = com.blankj.utilcode.util.ScreenUtils.getScreenWidth(); // 按照公式计算:value / 375 * screenWidth return (int) ((value / 375.0) * screenWidth); } }