DeteMin
2020-03-31 77c62e023d2dc31200fc696158df84b3aee90ee7
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
package com.basic.security.manager;
 
import com.basic.security.base.BaseApplication;
import com.basic.security.manager.impl.sqlite.SlDeviceManager;
import com.basic.security.utils.IpUtils;
 
import org.apache.commons.io.IOUtils;
 
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
 
public class DeviceManager extends BaseManager {
    // bufferReader和bufferWriter比fileWriter和fileReader 效率高,
    public static String company_id = "";
    //    public static String couchbase_server_ip = "";
//    public static String port = "";
    public static String device_id = "security";
 
    public static String getDeviceId() {
        return SlDeviceManager.getDeviceId();
//        if (device_id != null && device_id.length() > 0) {
//            return device_id;
//        }
//        File deviceIdFile = new File("/sdcard/device_id.txt");
//        FileReader fileReader = null;
//        if (deviceIdFile.exists()) {
//            try {
//                fileReader = new FileReader(deviceIdFile);
//                List<String> lines = IOUtils.readLines(fileReader);
//                if (lines.size() > 0) {
//                    device_id = lines.get(0);
//                }
//            } catch (IOException e) {
//                e.printStackTrace();
//            } finally {
//                try {
//                    if (fileReader != null) {
//                        fileReader.close();
//                    }
//                } catch (Exception e) {
//
//                }
//            }
//        }
//        return device_id;
    }
 
    public static String getCompareId() {
        return company_id;
    }
 
    public static void writeDeviceId(String newDeviceId) {
        File deviceIdFile = new File("/sdcard/device_id.txt");
        if (!deviceIdFile.exists()) {
            try {
                deviceIdFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            FileWriter fileWriter = new FileWriter(deviceIdFile);
            IOUtils.write(newDeviceId.getBytes(), fileWriter);
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
 
        }
    }
 
    public static String getDeviceIp() {
        return IpUtils.getIpAddress(BaseApplication.getApplication());
    }
}