Android 版本信息

Model

Build.MODEL + getMsvSuffix()

/**
 * Returns " (ENGINEERING)" if the msv file has a zero value, else returns "".
 * @return a string to append to the model number description.
 */
public static String getMsvSuffix() {
    // Production devices should have a non-zero value. If we can't read it, assume it's a
    // production device so that we don't accidentally show that it's an ENGINEERING device.
    try {
        String msv = readLine(FILENAME_MSV);
        // Parse as a hex number. If it evaluates to a zero, then it's an engineering build.
        if (Long.parseLong(msv, 16) == 0) {
            return " (ENGINEERING)";
        }
    } catch (IOException|NumberFormatException e) {
        // Fail quietly, as the file may not exist on some devices, or may be unreadable
    }
    return "";
}

Android Version

"Android"+Build.VERSION.RELEASE

Android security patch level

    public static String getSecurityPatch() {
        String patch = Build.VERSION.SECURITY_PATCH;
        if (!"".equals(patch)) {
            try {
                SimpleDateFormat template = new SimpleDateFormat("yyyy-MM-dd");
                Date patchDate = template.parse(patch);
                String format = DateFormat.getBestDateTimePattern(Locale.getDefault(), "dMMMMyyyy");
                patch = DateFormat.format(format, patchDate).toString();
            } catch (ParseException e) {
                // broken parse; fall through and use the raw string
            }
            return patch;
        } else {
            return null;
        }
    }

Kernel version

public static String getFormattedKernelVersion(Context context) {
            return formatKernelVersion(context, Os.uname());
    }

    @VisibleForTesting
    static String formatKernelVersion(Context context, StructUtsname uname) {
        if (uname == null) {
            return context.getString(R.string.status_unavailable);
        }
        // Example:
        // 4.9.29-g958411d
        // #1 SMP PREEMPT Wed Jun 7 00:06:03 CST 2017
        final String VERSION_REGEX =
                "(#\\d+) " +              /* group 1: "#1" */
                "(?:.*?)?" +              /* ignore: optional SMP, PREEMPT, and any CONFIG_FLAGS */
                "((Sun|Mon|Tue|Wed|Thu|Fri|Sat).+)"; /* group 2: "Thu Jun 28 11:02:39 PDT 2012" */
        Matcher m = Pattern.compile(VERSION_REGEX).matcher(uname.version);
        if (!m.matches()) {
            Log.e(TAG, "Regex did not match on uname version " + uname.version);
            return context.getString(R.string.status_unavailable);
        }

        // Example output:
        // 4.9.29-g958411d
        // #1 Wed Jun 7 00:06:03 CST 2017
        return new StringBuilder().append(uname.release)
                .append("\n")
                .append(m.group(1))
                .append(" ")
                .append(m.group(2)).toString();
    }

Build number

Build.DISPLAY

硬件版本

android.os.SystemProperties.get("ro.boot.hardware.revision")

Bluetooth Address

    public static String getBtMac(Context ctx){
        try {
            BluetoothManager bluetoothManager = (BluetoothManager) ctx.getSystemService(Service.BLUETOOTH_SERVICE);
            BluetoothAdapter adapter = bluetoothManager.getAdapter();
            return adapter.getAddress();
        }catch (Exception e){
            return "";
        }
    }

Wifi Address

    public static String getWifiMac(Context ctx){
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
                NetworkInterface nif = en.nextElement();
                if (!nif.getName().equalsIgnoreCase("wlan0")){
                    continue;
                }
                byte[] macBytes = nif.getHardwareAddress();
                //nif.getInetAddresses();
                if (macBytes == null) {
                    return "";
                }
                StringBuilder res1 = new StringBuilder();
                for (byte b : macBytes) {
                    res1.append(String.format("%02X:",b));
                }

                if (res1.length() > 0) {
                    res1.deleteCharAt(res1.length() - 1);
                }
                return res1.toString();
            }
        } catch (Exception ex) {
        }
        return "02:00:00:00:00:00";
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章