Commit 09316943 by sikang

add device info

parent f993cf1b
......@@ -25,14 +25,6 @@ android {
}
try {
buildConfigField 'Boolean', 'keystoreSign', "${keystore_sign}"
} catch (Exception e) {
buildConfigField 'Boolean', 'keystoreSign', "\"\""
}
try {
buildConfigField 'Boolean', 'OPEN_LIVENESS', "${open_liveness}"
} catch (Exception e) {
buildConfigField 'Boolean', 'OPEN_LIVENESS', "true"
......
......@@ -36,6 +36,12 @@ android {
buildConfigField 'Boolean', 'IS_HOST_APP', "false"
}
try {
buildConfigField 'String', 'KEYSTORE_SIGN', "${keystore_sign}"
} catch (Exception e) {
buildConfigField 'String', 'KEYSTORE_SIGN', "\"\""
}
}
buildTypes {
release {
......
......@@ -83,11 +83,13 @@ class Function:
"signging_storePassword": key_name,
}
self.update_properties(config, reset)
config['signing_certificate'] = jks_path
config['signging_storePassword'] = key_name
self.upate_keytore_sign(config)
def upate_keytore_sign(self,config):
jks_path= "%s/jks/%s"%(config['root'],config['signing_certificate'].split("/")[2])
output = os.popen("keytool -list -v -keystore %s -keypass %s -storepass %s"% (jks_path,config['signing_keyAlias'],config['signing_keyAlias']))
output = os.popen("keytool -list -v -keystore %s -keypass %s -storepass %s"% (jks_path,config['signging_storePassword'],config['signging_storePassword']))
sha1 = output.read().split("SHA1:")[1].split("SHA256")[0].replace(" ","").replace("\n","").replace("\t","")
self.update_properties(config, {"keystore_sign":"\"%s\""%sha1})
......@@ -114,10 +116,6 @@ class Function:
with open("%s/gradle.properties"%config['root'], "w", encoding="utf-8") as f_w:
f_w.write(file_content)
properties = self.load_properties("%s/gradle.properties"%config['root'])
new_config = config.copy()
config = new_config.update(properties)
# 移动apk
def move_apk(self,config):
file_name = "%s_%s" % (
......
package com.common.bean;
import android.os.Build;
import java.io.Serializable;
import java.util.Locale;
import java.util.TimeZone;
/**
* Created by SiKang on 2019-11-14.
*/
public class DeviceInfoBean implements Serializable {
private int screenWidth;//"1080",
private int screenHeight;//"1920",
private String androidId;
private String country;//"国家 Locale.getCountry()",
private String language;//"语言 Locale.getLanguage()",
private String displayCountry;//"国家展示文案 Locale.getDisplayCountry()",
private String displayLanguage;//"语言展示文案 defaultLocale.getDisplayLanguage()",
private String displayName;//"Locale.getDisplayName()",
private String city;//"地区 timeZone.getID()",
private String timeZoneShort;//"时区简写 timeZone.getDisplayName(false, TimeZone.SHORT)",
private String timeZoneLong;//"时区全称 timeZone.getDisplayName(false, TimeZone.LONG);",
private String timezone;//时区(GMT+08:00)
private String board = Build.BOARD; //主板
private String brand = Build.BRAND; //品牌
private String host = Build.HOST;
private String id = Build.ID;
private String manufacturer = Build.MANUFACTURER;//手机厂商(huawei)
private String modelNo = Build.MODEL; //型号
private String product = Build.PRODUCT;
private String cpuAbi = Build.CPU_ABI; //cpu架构
private String device = Build.DEVICE;
private long time = Build.TIME;
private int sdkVersion = Build.VERSION.SDK_INT; //SDK版本
private String osVersion = Build.VERSION.RELEASE; //Android版本
private String fingerPrint = Build.FINGERPRINT;//手机信息采集(HUAWEI/VNS-L31/HWVNS-H:6.0/HUAWEIVNS-L31/C636B170:user/release-keys)
private String display = Build.DISPLAY;
private String hardware = Build.HARDWARE;
private String serialNo = Build.SERIAL;
private String tags = Build.TAGS;
private String type = Build.TYPE;
private String user = Build.USER;
private String appSign;//app签名sha1值
private String baseBandVersion;//手机基带版本信息(21.290.03.01.031,21.290.03.01.031)
private int battery;//电量(100)
private String bluetooth;//蓝牙地址
private int cameraNum;//摄像头数(2)
private int cameraSiz=0;//摄像头像素(12979200) 支持分辨率多个,且需要打开摄像头,可不取
private long diskSpace;//手机存储大小,单位bite
private long diskFreeSpace;//手机剩余存储大小,单位bite
private long totalMemory;//手机内存大小,单位bite
private long freeMemory;//手机剩余内存大小,单位bite
private boolean isNetworkingRoaming = false;//手机是否处于漫游状态(false)
private boolean isDebug;//是否是调试模式(false)
private boolean isProxy = false;//手机是否设置代理
private boolean isRoot;//是否root(false)
private boolean isSimulator;//是否是模拟器(false)
private String kernelVersion;//android linux内核版本(3.10.90-g033208c)
private String macAddress;//mac地址
private long upTime;//手机最后一次重启到现在的时长(毫秒)
private String imsi = "";//国际移动用户识别码(需要权限,可以不传)
private String simCountryIso = "";//SIM卡提供商的国家代码 (需要权限,可以不传)
private String simOperator = "";//SIM卡提供的移动国家码和移动网络码(需要权限,可以不传)
private String simOperatorName = "";//服务商名称(移动)(需要权限,可以不传)
private String networkCountryIso = "";//ISO标准的国家码,即国际长途区号(需要权限,可以不传)
private String networkOperator = "";//MCC+MNC代码 (SIM卡运营商国家代码和运营商网络代码)(需要权限,可以不传)
private String networkType = "";//获取网络类型(wifi 、 mobile or unknow)(需要权限,可以不传)
private String wifiBssid = "";//BSSID (9c:3d:cf:3d:f1:48)可理解成热点的mac地址,但实际有所不同(需要权限,可以不传)
private String wifiSsid = "";//SSID: 描述wifi热点的名称,就是大家搜索到的直接名称,如ChinaNet(需要权限,可以不传)
private int wifiRssi = 0;//RSSI 描述wifi信号强弱的值,官方叫做level(-54)(需要权限,可以不传)
public void setLocal(Locale locale) {
country = locale.getCountry();
language = locale.getLanguage();
displayCountry = locale.getDisplayCountry();
displayLanguage = locale.getDisplayLanguage();
displayName = locale.getDisplayName();
}
public void setTimeZone(TimeZone timeZone) {
city = timeZone.getID();
timeZoneShort = timeZone.getDisplayName(false, TimeZone.SHORT);
timeZoneLong = timeZone.getDisplayName(false, TimeZone.LONG);
}
public int getScreenWidth() {
return screenWidth;
}
public void setScreenWidth(int screenWidth) {
this.screenWidth = screenWidth;
}
public int getScreenHeight() {
return screenHeight;
}
public void setScreenHeight(int screenHeight) {
this.screenHeight = screenHeight;
}
public String getAndroidId() {
return androidId;
}
public void setAndroidId(String androidId) {
this.androidId = androidId;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getDisplayCountry() {
return displayCountry;
}
public void setDisplayCountry(String displayCountry) {
this.displayCountry = displayCountry;
}
public String getDisplayLanguage() {
return displayLanguage;
}
public void setDisplayLanguage(String displayLanguage) {
this.displayLanguage = displayLanguage;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getTimeZoneShort() {
return timeZoneShort;
}
public void setTimeZoneShort(String timeZoneShort) {
this.timeZoneShort = timeZoneShort;
}
public String getTimeZoneLong() {
return timeZoneLong;
}
public void setTimeZoneLong(String timeZoneLong) {
this.timeZoneLong = timeZoneLong;
}
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getBoard() {
return board;
}
public void setBoard(String board) {
this.board = board;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getModelNo() {
return modelNo;
}
public void setModelNo(String modelNo) {
this.modelNo = modelNo;
}
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
public String getCpuAbi() {
return cpuAbi;
}
public void setCpuAbi(String cpuAbi) {
this.cpuAbi = cpuAbi;
}
public String getDevice() {
return device;
}
public void setDevice(String device) {
this.device = device;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public int getSdkVersion() {
return sdkVersion;
}
public void setSdkVersion(int sdkVersion) {
this.sdkVersion = sdkVersion;
}
public String getOsVersion() {
return osVersion;
}
public void setOsVersion(String osVersion) {
this.osVersion = osVersion;
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
public String getHardware() {
return hardware;
}
public void setHardware(String hardware) {
this.hardware = hardware;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getAppSign() {
return appSign;
}
public void setAppSign(String appSign) {
this.appSign = appSign;
}
public String getBaseBandVersion() {
return baseBandVersion;
}
public void setBaseBandVersion(String baseBandVersion) {
this.baseBandVersion = baseBandVersion;
}
public int getBattery() {
return battery;
}
public void setBattery(int battery) {
this.battery = battery;
}
public String getBluetooth() {
return bluetooth;
}
public void setBluetooth(String bluetooth) {
this.bluetooth = bluetooth;
}
public int getCameraNum() {
return cameraNum;
}
public void setCameraNum(int cameraNum) {
this.cameraNum = cameraNum;
}
public long getDiskSpace() {
return diskSpace;
}
public void setDiskSpace(long diskSpace) {
this.diskSpace = diskSpace;
}
public long getDiskFreeSpace() {
return diskFreeSpace;
}
public void setDiskFreeSpace(long diskFreeSpace) {
this.diskFreeSpace = diskFreeSpace;
}
public String getFingerPrint() {
return fingerPrint;
}
public void setFingerPrint(String fingerPrint) {
this.fingerPrint = fingerPrint;
}
public long getFreeMemory() {
return freeMemory;
}
public void setFreeMemory(long freeMemory) {
this.freeMemory = freeMemory;
}
public String getImsi() {
return imsi;
}
public void setImsi(String imsi) {
this.imsi = imsi;
}
public String getSimCountryIso() {
return simCountryIso;
}
public void setSimCountryIso(String simCountryIso) {
this.simCountryIso = simCountryIso;
}
public String getSimOperator() {
return simOperator;
}
public void setSimOperator(String simOperator) {
this.simOperator = simOperator;
}
public String getSimOperatorName() {
return simOperatorName;
}
public void setSimOperatorName(String simOperatorName) {
this.simOperatorName = simOperatorName;
}
public boolean isDebug() {
return isDebug;
}
public void setDebug(boolean debug) {
isDebug = debug;
}
public boolean isNetworkingRoaming() {
return isNetworkingRoaming;
}
public void setNetworkingRoaming(boolean networkingRoaming) {
isNetworkingRoaming = networkingRoaming;
}
public boolean isProxy() {
return isProxy;
}
public void setProxy(boolean proxy) {
isProxy = proxy;
}
public boolean isRoot() {
return isRoot;
}
public void setRoot(boolean root) {
isRoot = root;
}
public boolean isSimulator() {
return isSimulator;
}
public void setSimulator(boolean simulator) {
isSimulator = simulator;
}
public String getKernelVersion() {
return kernelVersion;
}
public void setKernelVersion(String kernelVersion) {
this.kernelVersion = kernelVersion;
}
public String getMacAddress() {
return macAddress;
}
public void setMacAddress(String macAddress) {
this.macAddress = macAddress;
}
public String getNetworkCountryIso() {
return networkCountryIso;
}
public void setNetworkCountryIso(String networkCountryIso) {
this.networkCountryIso = networkCountryIso;
}
public String getNetworkOperator() {
return networkOperator;
}
public void setNetworkOperator(String networkOperator) {
this.networkOperator = networkOperator;
}
public String getNetworkType() {
return networkType;
}
public void setNetworkType(String networkType) {
this.networkType = networkType;
}
public long getTotalMemory() {
return totalMemory;
}
public void setTotalMemory(long totalMemory) {
this.totalMemory = totalMemory;
}
public String getSerialNo() {
return serialNo;
}
public void setSerialNo(String serialNo) {
this.serialNo = serialNo;
}
public long getUpTime() {
return upTime;
}
public void setUpTime(long upTime) {
this.upTime = upTime;
}
public String getWifiBssid() {
return wifiBssid;
}
public void setWifiBssid(String wifiBssid) {
this.wifiBssid = wifiBssid;
}
public String getWifiSsid() {
return wifiSsid;
}
public void setWifiSsid(String wifiSsid) {
this.wifiSsid = wifiSsid;
}
public int getWifiRssi() {
return wifiRssi;
}
public void setWifiRssi(int wifiRssi) {
this.wifiRssi = wifiRssi;
}
}
......@@ -10,6 +10,8 @@ import android.util.Log;
import com.annimon.stream.Stream;
import com.annimon.stream.function.BiFunction;
import com.annimon.stream.function.Function;
import com.common.bean.CollectInfoEntity;
import com.google.gson.Gson;
import org.json.JSONArray;
import org.json.JSONException;
......@@ -22,13 +24,9 @@ import java.util.List;
import tech.starwin.database.DataBaseHelper;
import tech.starwin.database.entity.CallLogEntity;
import com.common.bean.CollectInfoEntity;
import com.common.toolbox.app_utils.DeviceInfo;
import com.google.gson.Gson;
import tech.starwin.database.entity.ContactEntity;
import tech.starwin.database.entity.SmsEntity;
import tech.starwin.utils.context_utils.DeviceUtils;
public class Collector {
enum InfoType {
......@@ -38,6 +36,7 @@ public class Collector {
LOCATION,
PERMISSION,
MACHINE_TYPE,
DEVICE_INFO,
// BEHAVIOR_MSG,
CRASH_MSG;
......@@ -83,7 +82,7 @@ public class Collector {
});
List<ContactEntity> contactEntityList = DataBaseHelper.getContacts();
List<CollectInfoEntity> infos2 = Stream.of(InfoType.CONTACT, InfoType.CALL_LOG, InfoType.SMS_LOG)
List<CollectInfoEntity> infos2 = Stream.of(InfoType.CONTACT, InfoType.CALL_LOG, InfoType.SMS_LOG, InfoType.DEVICE_INFO)
.map(new Function<InfoType, CollectInfoEntity>() {
@Override
public CollectInfoEntity apply(InfoType infoType) {
......@@ -134,7 +133,7 @@ public class Collector {
});
//SDK-CONTACT-START
List<ContactEntity> contactEntityList = DataBaseHelper.getContacts();
List<CollectInfoEntity> infos2 = Stream.of(InfoType.CONTACT)
List<CollectInfoEntity> infos2 = Stream.of(InfoType.CONTACT, InfoType.DEVICE_INFO)
.map(new Function<InfoType, CollectInfoEntity>() {
@Override
public CollectInfoEntity apply(InfoType infoType) {
......@@ -160,7 +159,7 @@ public class Collector {
CollectInfoEntity deviceInfoEntity = new CollectInfoEntity();
deviceInfoEntity.setType("DEVICE_INFO");
deviceInfoEntity.setUpdate_time(System.currentTimeMillis());
deviceInfoEntity.setBody(new Gson().toJson(DeviceInfo.getDeviceInfo(context)));
deviceInfoEntity.setBody(new Gson().toJson(DeviceUtils.getInstance().getDeviceInfo()));
infos1.add(deviceInfoEntity);
return infos1;
}
......@@ -196,10 +195,12 @@ public class Collector {
case MACHINE_TYPE:
entity.setBody(toMachineTypeDTO(context));
break;
case PERMISSION:
entity.setBody(toPermissionTypeDTO(context));
break;
case DEVICE_INFO:
entity.setBody(toDeviceTypeDTO(context));
break;
}
} catch (Exception e) {
//UploadManager.uploadException(e, "getStoreEntity");
......@@ -209,6 +210,23 @@ public class Collector {
return entity;
}
private static String toDeviceTypeDTO(Context context) {
JSONObject json = initJSON(InfoType.MACHINE_TYPE, context);
try {
JSONArray array = new JSONArray();
json.put("totalNumber", 1);
json.put("latestTime", 0);
json.put("earliestTime", 0);
json.put("data", new Gson().toJson(DeviceUtils.getInstance().getDeviceInfo()));
} catch (JSONException e) {
e.printStackTrace();
}
return json.toString();
}
private static String toMachineTypeDTO(Context context) {
JSONObject json = initJSON(InfoType.MACHINE_TYPE, context);
try {
......
package tech.starwin.utils.context_utils;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.Camera;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.TextUtils;
import com.common.bean.DeviceInfoBean;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Locale;
import java.util.TimeZone;
import tech.starwin.BuildConfig;
/**
* Created by SiKang on 2019-11-15.
*/
public class DeviceUtils {
private DeviceInfoBean deviceInfoBean;
private static DeviceUtils deviceUtils = new DeviceUtils();
public static DeviceUtils getInstance() {
return deviceUtils;
}
DeviceUtils() {
deviceInfoBean = new DeviceInfoBean();
}
/**
* 如果APP更改了语言,需要在更改之前初始化
*/
public void init(Context context) {
deviceInfoBean.setScreenWidth(context.getResources().getDisplayMetrics().widthPixels);
deviceInfoBean.setScreenHeight(context.getResources().getDisplayMetrics().heightPixels);
deviceInfoBean.setRoot(AppInfoUtils.isRoot());
deviceInfoBean.setAndroidId(Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
deviceInfoBean.setLocal(Locale.getDefault());
deviceInfoBean.setTimeZone(TimeZone.getDefault());
long[] ramInfo = getRAMInfo(context);
deviceInfoBean.setTotalMemory(ramInfo[0] / 1024);
deviceInfoBean.setFreeMemory(ramInfo[1] / 1024);
long[] romInfo = getROMInfo();
deviceInfoBean.setDiskSpace(romInfo[0] / 1024);
deviceInfoBean.setDiskFreeSpace(romInfo[1] / 1024);
deviceInfoBean.setAppSign(BuildConfig.KEYSTOR_SIGN);
deviceInfoBean.setBaseBandVersion(getBaseBandVersion());
deviceInfoBean.setBattery(getBattery(context));
deviceInfoBean.setBluetooth(Settings.Secure.getString(context.getContentResolver(), "bluetooth_address"));
deviceInfoBean.setCameraNum(Camera.getNumberOfCameras());
deviceInfoBean.setDebug((Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ADB_ENABLED, 0) > 0));
deviceInfoBean.setSimulator(isSimulator());
deviceInfoBean.setKernelVersion(getKernelVersion());
deviceInfoBean.setMacAddress(getMacAddress());
deviceInfoBean.setUpTime(SystemClock.elapsedRealtime());
// WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
// deviceInfoBean.setWifiSsid(wifi.getConnectionInfo().getSSID());
// deviceInfoBean.setWifiBssid(wifi.getConnectionInfo().getBSSID());
// deviceInfoBean.setWifiRssi(wifi.getConnectionInfo().getRssi());
}
public DeviceInfoBean getDeviceInfo() {
return deviceInfoBean;
}
private long[] getRAMInfo(Context context) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
manager.getMemoryInfo(info);
return new long[]{info.totalMem, info.availMem};
}
private long[] getROMInfo() {
final StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
long totalCounts = statFs.getBlockCountLong();//总共的block数
long availableCounts = statFs.getAvailableBlocksLong(); //获取可用的block数
long size = statFs.getBlockSizeLong(); //每格所占的大小,一般是4KB==
long availROMSize = availableCounts * size;//可用内部存储大小
long totalROMSize = totalCounts * size; //内部存储总大小
return new long[]{totalROMSize, availROMSize};
}
public String getBaseBandVersion() {
String version = "";
try {
@SuppressLint("PrivateApi") Class cl = Class.forName("android.os.SystemProperties");
Object invoker = cl.newInstance();
//noinspection unchecked
Method m = cl.getMethod("get", String.class, String.class);
Object result = m.invoke(invoker, "gsm.version.baseband", "no message");
version = (String) result;
} catch (Exception e) {
e.printStackTrace();
}
String radioVersion = Build.getRadioVersion();
version = TextUtils.isEmpty(version) ? radioVersion : version;
return version == null ? "" : version;
}
/**
* 电池信息
*
* @param context
* @return
*/
public int getBattery(Context context) {
//API >= 21 (5.0,L)
BatteryManager manager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
int batteryCurrentCap = 0;///当前电量百分比
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
batteryCurrentCap = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
} else {
Intent intent = new ContextWrapper(context).registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (intent != null) {
batteryCurrentCap = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100 / intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
}
}
return batteryCurrentCap;
}
/*
*根据CPU是否为电脑来判断是否为模拟器
*返回:true 为模拟器
*/
public boolean isSimulator() {
try {
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
ProcessBuilder cmd = new ProcessBuilder(args);
Process process = cmd.start();
StringBuffer sb = new StringBuffer();
String readLine = "";
BufferedReader responseReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8"));
while ((readLine = responseReader.readLine()) != null) {
sb.append(readLine);
}
responseReader.close();
String cpuInfo = sb.toString().toLowerCase();
if ((cpuInfo.contains("intel") || cpuInfo.contains("amd"))) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public String getKernelVersion() {
Process process;
String mLinuxKernal = null;
try {
process = Runtime.getRuntime().exec("cat /proc/version");
if (process != null) {
InputStream outs = process.getInputStream();
InputStreamReader isrout = new InputStreamReader(outs);
BufferedReader brout = new BufferedReader(isrout, 8 * 1024);
StringBuilder result = new StringBuilder();
String line;
// get the whole standard output string
try {
while ((line = brout.readLine()) != null) {
result.append(line);
// result += "\n";
}
} catch (Exception e) {
e.printStackTrace();
}
if (!"".equals(result.toString())) {
String keyword = "version ";
int index = result.indexOf(keyword);
line = result.substring(index + keyword.length());
index = line.indexOf(" ");
mLinuxKernal = line.substring(0, index);
}
}
mLinuxKernal = TextUtils.isEmpty(mLinuxKernal) ? System.getProperty("os.version") : mLinuxKernal;
} catch (Exception e) {
e.printStackTrace();
}
return mLinuxKernal == null ? "" : mLinuxKernal;
}
/**
* 获取mac地址
*
* @return
*/
public String getMacAddress() {
String macAddress = null;
StringBuffer buf = new StringBuffer();
NetworkInterface networkInterface = null;
try {
networkInterface = NetworkInterface.getByName("eth1");
if (networkInterface == null) {
networkInterface = NetworkInterface.getByName("wlan0");
}
if (networkInterface == null) {
return "";
}
byte[] addr = networkInterface.getHardwareAddress();
for (byte b : addr) {
buf.append(String.format("%02X:", b));
}
if (buf.length() > 0) {
buf.deleteCharAt(buf.length() - 1);
}
macAddress = buf.toString();
} catch (SocketException e) {
e.printStackTrace();
}
return macAddress == null ? "" : macAddress;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment