feat: complete reverse engineering, standard Maven structure, detailed code annotations and IoT-M platform architecture
This commit is contained in:
1 parent
e8dc09fb3c
commit
cd6a4c70e7
3045 files changed
+566733
-1
No files matched your search
@@ -0,0 +1,173 @@
|
||||
package com.mitac.cell.system;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.mitac.cell.net.McNetUtils;
|
||||
import com.mitac.cell.shell.McRuntime;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Reader;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.UUID;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
public class HwInfo {
|
||||
private String computerName;
|
||||
private int processors;
|
||||
private String serialNo;
|
||||
private UUID systemUuid;
|
||||
private long maxMemory;
|
||||
private long totalMemory;
|
||||
private long freeMemory;
|
||||
private Long physicalTotal;
|
||||
private Long physicalFree;
|
||||
|
||||
public HwInfo(OsInfo.OS_TYPE osType) {
|
||||
this.retreiveDeviceInfo(osType);
|
||||
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
|
||||
|
||||
try {
|
||||
ObjectName osObject = new ObjectName("java.lang", "type", "OperatingSystem");
|
||||
this.physicalTotal = (Long)beanServer.getAttribute(osObject, "TotalPhysicalMemorySize");
|
||||
this.physicalFree = (Long)beanServer.getAttribute(osObject, "FreePhysicalMemorySize");
|
||||
} catch (Exception var4) {
|
||||
}
|
||||
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
this.maxMemory = runtime.maxMemory();
|
||||
this.totalMemory = runtime.totalMemory();
|
||||
this.freeMemory = runtime.freeMemory();
|
||||
this.processors = runtime.availableProcessors();
|
||||
}
|
||||
|
||||
private void retreiveDeviceInfo(OsInfo.OS_TYPE osType) {
|
||||
switch (osType) {
|
||||
case LINUX:
|
||||
this.retrieveDeviceInfoInLinux();
|
||||
break;
|
||||
case WINDOWS:
|
||||
this.retrieveDeviceInfoInWindows();
|
||||
break;
|
||||
case MAC:
|
||||
this.retrieveDeviceInfoInMac();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getComputerName() {
|
||||
return this.computerName;
|
||||
}
|
||||
|
||||
public int getProcessors() {
|
||||
return this.processors;
|
||||
}
|
||||
|
||||
public UUID getSystemUuid() {
|
||||
return this.systemUuid;
|
||||
}
|
||||
|
||||
public String serialNo() {
|
||||
return this.serialNo;
|
||||
}
|
||||
|
||||
public long getMaxMemory() {
|
||||
return this.maxMemory;
|
||||
}
|
||||
|
||||
public long getTotalMemory() {
|
||||
return this.totalMemory;
|
||||
}
|
||||
|
||||
public long getFreeMemory() {
|
||||
return this.freeMemory;
|
||||
}
|
||||
|
||||
public long getPhysicalTotal() {
|
||||
return this.physicalTotal;
|
||||
}
|
||||
|
||||
public long getPhysicalFree() {
|
||||
return this.physicalFree;
|
||||
}
|
||||
|
||||
private void retrieveDeviceInfoInWindows() {
|
||||
this.computerName = McNetUtils.hostName();
|
||||
if (Strings.isNullOrEmpty(this.computerName)) {
|
||||
this.computerName = System.getenv("COMPUTERNAME");
|
||||
}
|
||||
|
||||
try {
|
||||
Reader reader = McRuntime.execReader("wmic", "csproduct", "get", "identifyingnumber, uuid");
|
||||
BufferedReader bufferedReader = new BufferedReader(reader);
|
||||
|
||||
String line;
|
||||
for(line = null; (line = bufferedReader.readLine()) != null && (Strings.isNullOrEmpty(line) || line.startsWith("IdentifyingNumber")); var6 = null) {
|
||||
}
|
||||
|
||||
if (line != null && line.length() >= 19) {
|
||||
this.serialNo = line.substring(0, 19).trim();
|
||||
this.systemUuid = UUID.fromString(line.substring(19).trim());
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void retrieveDeviceInfoInLinux() {
|
||||
this.computerName = McNetUtils.hostName();
|
||||
|
||||
try {
|
||||
Reader reader = McRuntime.execReader("dmidecode", "-t", "system");
|
||||
BufferedReader bufferedReader = new BufferedReader(reader);
|
||||
String line = null;
|
||||
|
||||
while((line = bufferedReader.readLine()) != null) {
|
||||
if (Strings.isNullOrEmpty(line)) {
|
||||
String var6 = null;
|
||||
} else {
|
||||
if (line.contains("Serial")) {
|
||||
this.serialNo = line.substring(16).trim();
|
||||
if (this.serialNo.endsWith("O.E.M")) {
|
||||
this.serialNo = null;
|
||||
}
|
||||
} else if (line.contains("UUID")) {
|
||||
this.systemUuid = UUID.fromString(line.substring(7).trim());
|
||||
}
|
||||
|
||||
if (!Strings.isNullOrEmpty(this.serialNo) && this.systemUuid != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void retrieveDeviceInfoInMac() {
|
||||
this.computerName = McNetUtils.hostName();
|
||||
|
||||
try {
|
||||
Reader reader = McRuntime.execReader("/usr/sbin/system_profiler", "SPHardwareDataType");
|
||||
BufferedReader bufferedReader = new BufferedReader(reader);
|
||||
String line = null;
|
||||
|
||||
while((line = bufferedReader.readLine()) != null) {
|
||||
if (!Strings.isNullOrEmpty(line) && !line.startsWith("IdentifyingNumber")) {
|
||||
if (line.contains("Serial")) {
|
||||
this.serialNo = line.substring(30).trim();
|
||||
} else if (line.contains("Hardware UUID")) {
|
||||
this.systemUuid = UUID.fromString(line.substring(21).trim());
|
||||
}
|
||||
|
||||
if (!Strings.isNullOrEmpty(this.serialNo) && this.systemUuid != null) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
String var6 = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user