public class DeviceInfo {
/**
* MAC address of the device which will be used while communicating with the
* server
*/
private static String _localId = null;
/**
* Method to get the local Id as the MAC address of the phone.
*/
public static void initLocalId() {
WifiManager wifiManager = (WifiManager) CppApplication.getAppContext()
.getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
_localId = wInfo.getMacAddress();
VCLog.info(Category.CAT_GENERAL, "DeviceInfo: initLocalId: wifiSsid->"
+ _localId);
}
/***
* Get MAC address of device
*
* @return MAC address
*/
public static String getLocalID() {
if (_localId == null) {
initLocalId();
}
return _localId;
}
/**
* Method to get the device model. e.g. Droid 3
*
* @return The model name of the device.
*/
public String getDeviceModel() {
String model = Build.MODEL;
return model;
}
/**
* This method is used to get the manufacturer.
*
* @return the manufacturer.
*/
public String getDeviceManufacturer() {
String manufacturer = Build.MANUFACTURER;
return manufacturer;
}
public static String getDataShaHashed(String str) {
MessageDigest digest = null;
byte[] input = null;
try {
digest = MessageDigest.getInstance("SHA-1");
digest.reset();
input = digest.digest(str.getBytes("UTF-8"));
} catch (Exception e) {
VCLog.error(
Category.CAT_GENERAL,
"DeviceInfo: getDataShaHashed: Exception->"
+ e.getMessage());
}
return _convertToHex(input);
}
private static String _convertToHex(byte[] data) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++) {
int halfbyte = (data[i] >>> 4) & 0x0F;
int two_halfs = 0;
do {
if ((0 <= halfbyte) && (halfbyte <= 9))
buf.append((char) ('0' + halfbyte));
else
buf.append((char) ('a' + (halfbyte - 10)));
halfbyte = data[i] & 0x0F;
} while (two_halfs++ < 1);
}
return buf.toString();
}
public static String getCurrentTimeStamp() {
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now = new Date();
String strDate = sdfDate.format(now);
strDate = strDate.replace(" ", "T");
return strDate;
}
/**
* This function returns unique device id i.e. IMEI number for current
* device returns null if not able to find device id
*
* @return String containing Device id, null if not able to find
* */
public static String getDeviceId() {
TelephonyManager telephonyManager = (TelephonyManager) CppApplication
.getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
String deviceId = null;
if (telephonyManager != null) {
deviceId = telephonyManager.getDeviceId();
telephonyManager = null;
}
return deviceId;
}
/**
* This function checks whether SD card is present or not and whether space
* is available or not.
*
* @return true if SD card is available, false otherwise.
*/
public static boolean isSdCardPresent() {
String sdCardStatus = android.os.Environment.getExternalStorageState();
boolean isSdCardAvailable = sdCardStatus
.equals(android.os.Environment.MEDIA_MOUNTED);
return isSdCardAvailable;
}
public static String getSdCardPath() {
File externalStorage = Environment.getExternalStorageDirectory();
String sdcardPath = externalStorage.getAbsolutePath();
return sdcardPath;
}
/**
* This method is used to get the OS version.
*
* @return the OS version.
*/
public static int getDeviceOsVersion() {
int ver = Build.VERSION.SDK_INT;
return ver;
}
public static String getLocale() {
return CppApplication.getAppContext().getResources().getConfiguration().locale
.getDisplayCountry(Locale.getDefault());
}
}