獲取手機品牌資訊的Build類
一、需求
Build類獲取手機制造商,系統定製商,型號,Android 系統版本,CPU 指令集,可以檢視是否支援64位等
二、原始碼
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package android.os;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Slog;
import com.mediatek.cta.CtaUtils;
import dalvik.system.VMRuntime;
import java.util.Objects;
public class Build {
private static final String TAG = "Build";
// 當一個版本屬性不知道時所設定的值。其字串值為 "unknown" .
public static final String UNKNOWN = "unknown";
// 修訂版本列表:Either a changelist number, or a label like "M4-rc20".
public static final String ID = getString("ro.build.id");
// DISPLAY 顯示屏引數
public static final String DISPLAY = getString("ro.build.display.id");
// PRODUCT 整個產品的名稱:The name of the overall product.
public static final String PRODUCT = getString("ro.product.name");
// 裝置引數:The name of the industrial design.
public static final String DEVICE = getString("ro.product.device");
// 主機板:The name of the underlying board, like "goldfish".
public static final String BOARD = getString("ro.product.board");
// cpu指令集:The name of the instruction set (CPU type + ABI convention) of native code.
/** @deprecated */
@Deprecated
public static final String CPU_ABI;
// cpu指令集2:The name of the second instruction set (CPU type + ABI convention) of native code.
/** @deprecated */
@Deprecated
public static final String CPU_ABI2;
// MANUFACTURER 硬體製造商:The manufacturer of the product/hardware.
public static final String MANUFACTURER = getString("ro.product.manufacturer");
// 系統定製商:The consumer-visible brand with which the product/hardware will be associated, if any.
// 版本即終端使用者可見的名稱:The end-user-visible name for the end product.
public static final String BRAND = getString("ro.product.brand");
public static final String MODEL = getString("ro.product.model");
// BOOTLOADER 系統啟動程式版本號:The system bootloader version number.
public static final String BOOTLOADER = getString("ro.bootloader");
// 無線電韌體版本:The radio firmware version number. 在API14後已過時。使用 getRadioVersion()代替
/** @deprecated */
@Deprecated
public static final String RADIO = getString("gsm.version.baseband");
public static final String HARDWARE = getString("ro.hardware");
public static final boolean IS_EMULATOR = getString("ro.kernel.qemu").equals("1");
// 硬體序列號:A hardware serial number, if available. Alphanumeric only, case-insensitive.
public static final String SERIAL = getString("ro.serialno");
public static final String[] SUPPORTED_ABIS = getStringList("ro.product.cpu.abilist", ",");
public static final String[] SUPPORTED_32_BIT_ABIS = getStringList("ro.product.cpu.abilist32", ",");
public static final String[] SUPPORTED_64_BIT_ABIS = getStringList("ro.product.cpu.abilist64", ",");
public static final String TYPE;
// 描述build的標籤,如未簽名,debug等等。:Comma-separated tags describing the build, like "unsigned,debug".
public static final String TAGS;
// 唯一識別碼:A string that uniquely identifies this build. Do not attempt to parse this value.
public static final String FINGERPRINT;
public static final long TIME;
public static final String USER;
public static final String HOST;
public static final boolean IS_DEBUGGABLE;
public static final boolean PERMISSIONS_REVIEW_REQUIRED;
public Build() {
}
private static String deriveFingerprint() {
String finger = SystemProperties.get("ro.build.fingerprint");
if(TextUtils.isEmpty(finger)) {
finger = getString("ro.product.brand") + '/' + getString("ro.product.name") + '/' + getString("ro.product.device") + ':' + getString("ro.build.version.release") + '/' + getString("ro.build.id") + '/' + getString("ro.build.version.incremental") + ':' + getString("ro.build.type") + '/' + getString("ro.build.tags");
}
return finger;
}
public static void ensureFingerprintProperty() {
if(TextUtils.isEmpty(SystemProperties.get("ro.build.fingerprint"))) {
try {
SystemProperties.set("ro.build.fingerprint", FINGERPRINT);
} catch (IllegalArgumentException var1) {
Slog.e("Build", "Failed to set fingerprint property", var1);
}
}
}
public static boolean isBuildConsistent() {
if("eng".equals(TYPE)) {
return true;
} else {
String system = SystemProperties.get("ro.build.fingerprint");
String vendor = SystemProperties.get("ro.vendor.build.fingerprint");
String bootimage = SystemProperties.get("ro.bootimage.build.fingerprint");
String requiredBootloader = SystemProperties.get("ro.build.expect.bootloader");
String currentBootloader = SystemProperties.get("ro.bootloader");
String requiredRadio = SystemProperties.get("ro.build.expect.baseband");
String currentRadio = SystemProperties.get("gsm.version.baseband");
if(TextUtils.isEmpty(system)) {
Slog.e("Build", "Required ro.build.fingerprint is empty!");
return false;
} else if(!TextUtils.isEmpty(vendor) && !Objects.equals(system, vendor)) {
Slog.e("Build", "Mismatched fingerprints; system reported " + system + " but vendor reported " + vendor);
return false;
} else {
return true;
}
}
}
public static String getRadioVersion() {
return SystemProperties.get("gsm.version.baseband", (String)null);
}
private static String getString(String property) {
return SystemProperties.get(property, "unknown");
}
private static String[] getStringList(String property, String separator) {
String value = SystemProperties.get(property);
return value.isEmpty()?new String[0]:value.split(separator);
}
private static long getLong(String property) {
try {
return Long.parseLong(SystemProperties.get(property));
} catch (NumberFormatException var2) {
return -1L;
}
}
public static boolean isPermissionReviewRequired() {
return PERMISSIONS_REVIEW_REQUIRED || CtaUtils.isCtaSupported();
}
static {
String[] abiList;
if(VMRuntime.getRuntime().is64Bit()) {
abiList = SUPPORTED_64_BIT_ABIS;
} else {
abiList = SUPPORTED_32_BIT_ABIS;
}
CPU_ABI = abiList[0];
if(abiList.length > 1) {
CPU_ABI2 = abiList[1];
} else {
CPU_ABI2 = "";
}
TYPE = getString("ro.build.type");
TAGS = getString("ro.build.tags");
FINGERPRINT = deriveFingerprint();
TIME = getLong("ro.build.date.utc") * 1000L;
USER = getString("ro.build.user");
HOST = getString("ro.build.host");
IS_DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0) == 1;
PERMISSIONS_REVIEW_REQUIRED = SystemProperties.getInt("ro.permission_review_required", 0) == 1;
}
public static class VERSION_CODES {
public static final int CUR_DEVELOPMENT = 10000;
public static final int BASE = 1;
public static final int BASE_1_1 = 2;
public static final int CUPCAKE = 3;
public static final int DONUT = 4;
public static final int ECLAIR = 5;
public static final int ECLAIR_0_1 = 6;
public static final int ECLAIR_MR1 = 7;
public static final int FROYO = 8;
public static final int GINGERBREAD = 9;
public static final int GINGERBREAD_MR1 = 10;
public static final int HONEYCOMB = 11;
public static final int HONEYCOMB_MR1 = 12;
public static final int HONEYCOMB_MR2 = 13;
public static final int ICE_CREAM_SANDWICH = 14;
public static final int ICE_CREAM_SANDWICH_MR1 = 15;
public static final int JELLY_BEAN = 16;
public static final int JELLY_BEAN_MR1 = 17;
public static final int JELLY_BEAN_MR2 = 18;
public static final int KITKAT = 19;
public static final int KITKAT_WATCH = 20;
public static final int L = 21;
public static final int LOLLIPOP = 21;
public static final int LOLLIPOP_MR1 = 22;
public static final int M = 23;
public static final int N = 24;
public VERSION_CODES() {
}
}
public static class VERSION {
public static final String INCREMENTAL = Build.getString("ro.build.version.incremental");
public static final String RELEASE = Build.getString("ro.build.version.release");
public static final String BASE_OS = SystemProperties.get("ro.build.version.base_os", "");
public static final String SECURITY_PATCH = SystemProperties.get("ro.build.version.security_patch", "");
/** @deprecated */
@Deprecated
public static final String SDK = Build.getString("ro.build.version.sdk");
public static final int SDK_INT = SystemProperties.getInt("ro.build.version.sdk", 0);
public static final int PREVIEW_SDK_INT = SystemProperties.getInt("ro.build.version.preview_sdk", 0);
public static final String CODENAME = Build.getString("ro.build.version.codename");
private static final String[] ALL_CODENAMES = Build.getStringList("ro.build.version.all_codenames", ",");
public static final String[] ACTIVE_CODENAMES;
public static final int RESOURCES_SDK_INT;
public VERSION() {
}
static {
ACTIVE_CODENAMES = "REL".equals(ALL_CODENAMES[0])?new String[0]:ALL_CODENAMES;
RESOURCES_SDK_INT = SDK_INT + ACTIVE_CODENAMES.length;
}
}
}
三、運用
package com.fadisu.cpurun.util;
import java.lang.reflect.Field;
import android.os.Build;
import android.util.Log;
public class BuildHelper {
private static final String TAG = BuildHelper.class.getSimpleName();
/**
* Build class所有的欄位屬性
* Build.BOARD : Z91
* Build.BOOTLOADER : unknown
* Build.BRAND : FaDi
* Build.CPU_ABI : arm64-v8a
* Build.CPU_ABI2 :
* Build.DEVICE : Z91
* Build.DISPLAY : TEST_FaDi_Z91_S100_20180108
* Build.FINGERPRINT : FaDi/Z91/Z91:7.1.1/N6F26Q/1515397384:user/release-keys
* Build.HARDWARE : mt6739
* Build.HOST : 69959bbb90c6
* Build.ID : N6F26Q
* Build.IS_DEBUGGABLE : true
* Build.IS_EMULATOR : false
* Build.MANUFACTURER : FaDi
* Build.MODEL : Z91
* Build.PERMISSIONS_REVIEW_REQUIRED : false
* Build.PRODUCT : Z91
* Build.RADIO : unknown
* Build.SERIAL : 0123456789ABCDEF
* Build.SUPPORTED_32_BIT_ABIS : [Ljava.lang.String;@305cf5e
* Build.SUPPORTED_64_BIT_ABIS : [Ljava.lang.String;@f5c1f3f
* Build.SUPPORTED_ABIS : [Ljava.lang.String;@578b00c
* Build.TAG : Build
* Build.TAGS : release-keys
* Build.TIME : 1515397382000
* Build.TYPE : user
* Build.UNKNOWN : unknown
* Build.USER : FaDi
* Build.VERSION.ACTIVE_CODENAMES : [Ljava.lang.String;@f4ecd55
* Build.VERSION.ALL_CODENAMES : [Ljava.lang.String;@bdb836a
* Build.VERSION.BASE_OS :
* Build.VERSION.CODENAME : REL
* Build.VERSION.INCREMENTAL : 1515397384
* Build.VERSION.PREVIEW_SDK_INT : 0
* Build.VERSION.RELEASE : 7.1.1
* Build.VERSION.RESOURCES_SDK_INT : 25
* Build.VERSION.SDK : 25
* Build.VERSION.SDK_INT : 25
* Build.VERSION.SECURITY_PATCH : 2017-11-05
*/
public static void getAllBuildInformation() {
Field[] fields = Build.class.getDeclaredFields();
for (Field field : fields) {
try {
field.setAccessible(true);
Log.w(TAG, "Build." + field.getName() + " : " + field.get(null));
} catch (Exception e) {
Log.e(TAG, "an error occured when collect crash info", e);
}
}
Field[] fieldsVersion = Build.VERSION.class.getDeclaredFields();
for (Field field : fieldsVersion) {
try {
field.setAccessible(true);
Log.w(TAG, "Build.VERSION." + field.getName() + " : " + field.get(null));
} catch (Exception e) {
Log.e(TAG, "an error occured when collect crash info", e);
}
}
}
// 手機制造商
public static String getProduct() {
return Build.PRODUCT;
}
// 系統定製商
public static String getBrand() {
return Build.BRAND;
}
// 硬體製造商
public static String getManufacturer() {
return Build.MANUFACTURER;
}
// 硬體名稱
public static String getHardWare() {
return Build.HARDWARE;
}
// 型號
public static String getMode() {
return Build.MODEL;
}
// Android 系統版本
public static String getAndroidVersion() {
return Build.VERSION.RELEASE;
}
// CPU 指令集,可以檢視是否支援64位
public static String getCpuAbi() {
return Build.CPU_ABI;
}
}
相關推薦
獲取手機品牌資訊的Build類
一、需求 Build類獲取手機制造商,系統定製商,型號,Android 系統版本,CPU 指令集,可以檢視是否支援64位等 二、原始碼 // // Source code recreated from a .class file by Intell
android 獲取手機信息工具類
telephony == 系統 設備 android pack devices 信息 context package com.yqy.yqy_listviewheadview; import android.content.Context; import androi
Android 獲取手機儲存資訊詳解(記憶體,外存等)
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); //系統記憶體資訊 ActivityManager.MemoryInfo memInfo = new ActivityManager
iOS開發-Object-C獲取手機裝置資訊(UIDevice)
一、獲取UiDevice裝置資訊 // 獲取裝置名稱 NSString *name = [[UIDevice currentDevice] name]; // 獲取裝置系統名稱 NSString *systemName = [[UIDevice currentDevice] systemName
android-獲取手機小區資訊介面設計
1. manifests <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package
Android程式碼獲取手機品牌、手機型號、手機唯一序列號
獲取手機品牌:phone_brand = (TextView) findViewById(R.id.mobile_phone_brand); String brand = android.os.Build.BRAND; phone_brand.setText(brand);獲
Android如何獲取手機各項資訊
1、使用Build獲取架構屬性 下面我們來根據原始碼看看通過Build這個類可以得到哪些配置資訊,具體就不解釋了,從命名基本可以理解其代表的屬性。 public class Build { //當一個版本屬性不知道時所設定的值。 publ
ABPeoplePickerNavigationController 獲取手機通訊錄資訊
最近專案用到獲取使用者手機通訊錄的功能,但發現有兩個代理方法在iOS 9.0 廢棄了,用新的代理方法代替,所以整理下供以後參考。。 #pragma mark - 點選聯絡人 連結到使用者手機通訊錄 - (void)accessPhoneBook: (UIButton *)
原生js獲取手機定位資訊
<script type="text/javascript"> function Location() {}; Location.prototype.getLocation = function (callback) { var options = {
獲取手機聯絡人資訊 很簡單的方法
String a; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.la
Android獲取手機基站資訊並進行基站定位(基站定位原理)
http://blog.csdn.net/mad1989/article/details/9970431 一,首先普及一下手機基站資訊中相關的專業詞彙: 通過TelephonyManager 獲取lac:mcc:mnc:cell-id(基站資訊)的解釋: MCC,M
Android 獲取手機儲存資訊詳解(記憶體,外存等)
android 獲取手機儲存資訊詳解(記憶體,外存等) android不像ios,android可以外接Sd卡,並且也會有內接的儲存卡,此次專門研究下如何獲取android的儲存資訊。 一、RAM記憶體 RAM,也就是我們常說的手機記憶體。最早的記憶體大小
Android ContentResolver ContactsContract 獲取手機聯絡人資訊
獲取手機聯絡人資訊步驟: 1、獲取 ContentResolver ContentResolver resolver = getContentResolver(); 2、resolver.query(*)查詢資訊 查詢手機聯絡人的URI:Cont
Unity&Android之二:獲取手機電量資訊、網路狀況
Unity&Android之二:獲取手機電量資訊、網路狀況 遊戲中經常會在UI顯示電量以及網路狀況 手機電量包括: 1、當前正在充電還是放電 2、當前電量值 網路包括: 1、如果是WIFI,WIFI訊號強度 2、如果是流量,訊號強度等資料
Android 獲取手機聯絡人資訊
<span style="font-size:18px;"> // 訪問聯絡人的姓名+電話 private Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; private Strin
android手機獲取手機裝置資訊
在有的專案中需要根據特定的手機資訊來進行處理,這時就需要我們來獲取手機的裝置資訊了,那首先看看我的測試機的一些基本資訊: 那麼這些資訊怎麼獲得呢??其實都封裝在了TelephonyManager中,我們從裡面可以拿到,但是注意的是有的手機手機號是拿不到的(
android -------- 獲取手機裝置資訊
最近在開發中,需要用到一些系統資訊,總結了一下 /** * Created
Android獲取手機版本號、品牌等 相關資訊工具類
主要有,獲取手機系統版本,獲取手機品牌、獲取軟體版本資訊、獲取螢幕尺寸寬高(包含和不包含虛擬鍵)以及獲取手機ip地址 public class DeviceUtils { /** * 品牌 */ public static String getDevic
Android筆記: 獲取手機的品牌、型號、Android系統版本號、IMEI、當前系統語言等工具類
最近在開發中,需要用到一些系統資訊,這裡我把這些方法寫成一個工具類方便以後複用,該工具類有以下6個功能: 1、獲取手機制造廠商 2、獲取手機型號 3、獲取手機系統當前使用的語言 4、獲取Andr
編寫一個手機類(Mobile),包括手機品牌(brand)、手機型號(type), 方法包括顯示手機資訊,並編寫測試類進行物件的建立
/*編寫一個手機類(Mobile),包括手機品牌(brand)、手機型號(type), * 方法包括顯示手機資訊,並編寫測試類進行物件的建立*/package cyff;public class Mobile {// 定義Mobile類String brand, type