admin
2022-08-09 399ac289f80b7a40aa4210341db6b447cacdcf14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.tejia.lijin.app.util;
 
import android.content.Context;
import android.content.SharedPreferences;
 
import com.google.gson.Gson;
import com.tejia.lijin.app.entity.common.ExpireValue;
import com.wpc.library.DeviceUuidFactory;
import com.wpc.library.util.MobileUtil;
import com.wpc.library.util.common.StringUtils;
 
import static android.content.Context.MODE_PRIVATE;
 
public class DeviceInfoUtil {
    enum DeviceInfoType {
        deviceId("device_id_"), imei("imei_"), androidId("android_id_"), mac("mac_"), utdid("utdid_"), systemModel("system_model_"), systemVersion("system_version_");
        private String key;
 
        public String getKey() {
            return key;
        }
 
        private DeviceInfoType(String key) {
            this.key = key;
        }
    }
 
 
    private static String getDeviceInfo(Context context, DeviceInfoType deviceInfoType) {
        SharedPreferences deviceInfo = context.getSharedPreferences("deviceInfo", MODE_PRIVATE);
        String data = deviceInfo.getString(deviceInfoType.getKey(), "");
        ExpireValue value = null;
        if (!StringUtils.isEmpty(data)) {
            value = new Gson().fromJson(data, ExpireValue.class);
            if (value.getExpireTime() < System.currentTimeMillis()) {
                value = null;
            }
        }
 
        if (value == null) {
            String v = "";
            if (deviceInfoType == DeviceInfoType.imei) {
                v = MobileUtil.getIMEI(context);
            } else if (deviceInfoType == DeviceInfoType.utdid) {
                v = com.ta.utdid2.device.UTDevice.getUtdid(context);
            } else if (deviceInfoType == DeviceInfoType.systemModel) {
                v = MobileUtil.getSystemModel();
            } else if (deviceInfoType == DeviceInfoType.systemVersion) {
                v = MobileUtil.getSystemVersion();
            } else if (deviceInfoType == DeviceInfoType.deviceId) {
                v = new DeviceUuidFactory(context).getDeviceUuid() + "";
            }
            value = new ExpireValue(v, System.currentTimeMillis() + 1000 * 60 * 10);
            SharedPreferences.Editor editor = deviceInfo.edit();
            editor.putString(deviceInfoType.getKey(), new Gson().toJson(value));
            editor.commit();
        }
        if (value == null)
            return "";
        else
            return value.getValue();
    }
 
    public static String getIMEI(Context context) {
        return getDeviceInfo(context, DeviceInfoType.imei);
    }
 
    public static String getAndroidId(Context context) {
        return getDeviceInfo(context, DeviceInfoType.androidId);
    }
 
    public static String getUtdid(Context context) {
        return getDeviceInfo(context, DeviceInfoType.utdid);
    }
 
    public static String getSystemModel(Context context) {
        return getDeviceInfo(context, DeviceInfoType.systemModel);
    }
 
    public static String getSystemVersion(Context context) {
        return getDeviceInfo(context, DeviceInfoType.systemVersion);
    }
 
    public static String getDeviceId(Context context) {
        return getDeviceInfo(context, DeviceInfoType.deviceId);
    }
 
 
}