package com.basic.security.manager.impl.cblite;
|
|
import com.basic.security.base.BaseApplication;
|
import com.basic.security.manager.impl.sqlite.SlDeviceManager;
|
import com.basic.security.utils.Constants;
|
import com.basic.security.utils.IpUtils;
|
|
import org.apache.commons.io.IOUtils;
|
|
import java.io.File;
|
import java.io.FileReader;
|
import java.io.FileWriter;
|
import java.io.IOException;
|
import java.util.List;
|
|
public class DeviceManager {
|
|
public static String company_id = "";
|
// public static String couchbase_server_ip = "";
|
// public static String port = "";
|
public static String device_id = "";
|
|
public static String getDeviceId() {
|
if (Constants.useCouchbase) {
|
File deviceIdFile = new File("/sdcard/device_id.txt");
|
if (deviceIdFile.exists()) {
|
try {
|
List<String> lines = IOUtils.readLines(new FileReader(deviceIdFile));
|
if (lines.size() > 0) {
|
device_id = lines.get(0);
|
}
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
return device_id;
|
} else {
|
return SlDeviceManager.getDeviceId();
|
}
|
}
|
|
public static String getCompareId() {
|
if (Constants.useCouchbase) {
|
return company_id;
|
} else {
|
return SlDeviceManager.getCompareId();
|
}
|
}
|
|
public static void writeDeviceId(String newDeviceId) {
|
if (Constants.useCouchbase) {
|
File deviceIdFile = new File("/sdcard/device_id.txt");
|
try {
|
FileWriter fileWriter = new FileWriter(deviceIdFile);
|
IOUtils.write(newDeviceId.getBytes(), fileWriter);
|
fileWriter.flush();
|
fileWriter.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
} else {
|
SlDeviceManager.writeDeviceId(newDeviceId);
|
}
|
}
|
|
public static String getDeviceIp() {
|
if (Constants.useCouchbase) {
|
return IpUtils.getIpAddress(BaseApplication.getApplication());
|
} else {
|
return SlDeviceManager.getDeviceIp();
|
}
|
}
|
}
|