Android之build.prop属性详解
注:本篇⽂章是基于MSD648项⽬(AndroidTV)的prop进⾏说明。
Android版本:4.4.4
内核版本:3.10.86
1.⽣成build.prop
  build.prop的⽣成是由make系统解析build/core/Makefile完成
  1.1.Makefile⽣成build.prop的主要代码如下
$(INSTALLED_BUILD_PROP_TARGET): $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(system_prop_file)    @echo Target buildinfo: $@
@mkdir -p $(dir $@)
$(hide) TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \
TARGET_DEVICE="$(TARGET_DEVICE)" \
PRODUCT_NAME="$(TARGET_PRODUCT)" \
PRODUCT_BRAND="$(PRODUCT_BRAND)" \
PRODUCT_DEFAULT_LANGUAGE="$(call default-locale-language,$(PRODUCT_LOCALES))" \
PRODUCT_DEFAULT_REGION="$(call default-locale-region,$(PRODUCT_LOCALES))" \
PRODUCT_DEFAULT_WIFI_CHANNELS="$(PRODUCT_DEFAULT_WIFI_CHANNELS)" \
PRODUCT_MODEL="$(PRODUCT_MODEL)" \
PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
PRIVATE_BUILD_DESC="$(PRIVATE_BUILD_DESC)" \
BUILD_ID="$(BUILD_ID)" \
BUILD_DISPLAY_ID="$(BUILD_DISPLAY_ID)" \
BUILD_NUMBER="$(BUILD_NUMBER)" \
PLATFORM_VERSION="$(PLATFORM_VERSION)" \
PLATFORM_SDK_VERSION="$(PLATFORM_SDK_VERSION)" \
PLATFORM_VERSION_CODENAME="$(PLATFORM_VERSION_CODENAME)" \
BUILD_VERSION_TAGS="$(BUILD_VERSION_TAGS)" \
TARGET_BOOTLOADER_BOARD_NAME="$(TARGET_BOOTLOADER_BOARD_NAME)" \
BUILD_FINGERPRINT="$(BUILD_FINGERPRINT)" \
TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \
TARGET_CPU_ABI="$(TARGET_CPU_ABI)" \
TARGET_CPU_ABI2="$(TARGET_CPU_ABI2)" \
TARGET_AAPT_CHARACTERISTICS="$(TARGET_AAPT_CHARACTERISTICS)" \
bash $(BUILDINFO_SH) > $@
$(hide) $(foreach file,$(system_prop_file), \
if [ -f "$(file)" ]; then \
echo"#" >> $@; \
echo Target buildinfo from: "$(file)"; \
echo"# from $(file)" >> $@; \
echo"#" >> $@; \
cat $(file) >> $@; \
fi;)
$(if $(ADDITIONAL_BUILD_PROPERTIES), \
$(hide) echo >> $@; \
echo"#" >> $@; \
echo"# ADDITIONAL_BUILD_PROPERTIES" >> $@; \
echo"#" >> $@; )
$(hide) $(foreach line,$(ADDITIONAL_BUILD_PROPERTIES), \
echo"$(line)" >> $@;)
$(hide) build/tools/post_process_props.py $@
build_desc :=
  1.2.⽬标⽂件为$(INSTALLED_BUILD_PROP_TARGET),其定义为:
android最新版
INSTALLED_BUILD_PROP_TARGET := $(TARGET_OUT)/build.prop
  1.3.⾸先对属性进⾏赋值,如BUILD_ID="$(BUILD_ID)",最后执⾏bash脚本:bash $(BUILDINFO_SH) > $@,其定义为BUILDINFO_SH := build/tools/buildinfo.sh
  1.4.开始执⾏sh脚本中的内容
#!/bin/bash
echo"# begin build properties"
echo"# autogenerated by buildinfo.sh"
echo"ro.build.id=$BUILD_ID"
echo"ro.build.display.id=$BUILD_DISPLAY_ID"
echo"ro.build.version.incremental=$BUILD_NUMBER"
echo"ro.build.version.sdk=$PLATFORM_SDK_VERSION"
echo"ro.dename=$PLATFORM_VERSION_CODENAME"
echo"ro.lease=$PLATFORM_VERSION"
echo"ro.build.date=`date`"
echo"ro.build.date.utc=`date +%s`"
echo"pe=$TARGET_BUILD_TYPE"
echo"ro.build.user=$USER"
echo"ro.build.host=`hostname`"
echo"ro.build.tags=$BUILD_VERSION_TAGS"
echo"del=$PRODUCT_MODEL"
echo"ro.product.brand=$PRODUCT_BRAND"
echo"ro.product.name=$PRODUCT_NAME"
echo"ro.product.device=$TARGET_DEVICE"
echo"ro.product.board=$TARGET_BOOTLOADER_BOARD_NAME"
echo"ro.product.cpu.abi=$TARGET_CPU_ABI"
if [ -n "$TARGET_CPU_ABI2" ] ; then
echo"ro.product.cpu.abi2=$TARGET_CPU_ABI2"
fi
echo"ro.product.manufacturer=$PRODUCT_MANUFACTURER"
if [ -n "$PRODUCT_DEFAULT_LANGUAGE" ] ; then
echo"ro.product.locale.language=$PRODUCT_DEFAULT_LANGUAGE"
fi
if [ -n "$PRODUCT_DEFAULT_REGION" ] ; then
echo"ro.ion=$PRODUCT_DEFAULT_REGION"
fi
echo"ro.wifi.channels=$PRODUCT_DEFAULT_WIFI_CHANNELS"
echo"ro.board.platform=$TARGET_BOARD_PLATFORM"
echo"# ro.build.product is obsolete; use ro.product.device"
echo"ro.build.product=$TARGET_DEVICE"
echo"# Do not try to parse ro.build.description or .fingerprint"
echo"ro.build.description=$PRIVATE_BUILD_DESC"
echo"ro.build.fingerprint=$BUILD_FINGERPRINT"
echo"ro.build.characteristics=$TARGET_AAPT_CHARACTERISTICS"
echo"# end build properties"
  1.5.最后追加余下的属性
$(hide) $(foreach file,$(system_prop_file), \
if [ -f "$(file)" ]; then \
echo"#" >> $@; \
echo Target buildinfo from: "$(file)"; \
echo"# from $(file)" >> $@; \
echo"#" >> $@; \
cat $(file) >> $@; \
fi;)
$(if $(ADDITIONAL_BUILD_PROPERTIES), \
$(hide) echo >> $@; \
echo"#" >> $@; \
echo"# ADDITIONAL_BUILD_PROPERTIES" >> $@; \
echo"#" >> $@; )
$(hide) $(foreach line,$(ADDITIONAL_BUILD_PROPERTIES), \
echo"$(line)" >> $@;)
$(hide) build/tools/post_process_props.py $@
    其中system_prop_file定义:
ifdef TARGET_SYSTEM_PROP
system_prop_file := $(TARGET_SYSTEM_PROP)
else
system_prop_file := $(wildcard $(TARGET_DEVICE_DIR)/system.prop)
endif
    即$(TARGET_DEVICE_DIR)/system.prop⽂件
  到此,prop⽂件⽣成完毕!
2.对⽣成的build.prop的属性进⾏说明:
# begin build properties
# autogenerated by buildinfo.sh
ro.build.id=KTU84P  #版本ID
ro.build.display.id=aosp_almond-userdebug 4.4.4 KTU84P TVOS-04.19.010.02.06.Mooney test-keys  #具体版本号ro.build.version.incremental=TVOS-04.19.010.02.07.Mooney  #版本增量说明
ro.build.version.sdk=19  #SDK版本
ro.dename=REL  #版本代号
ro.lease=4.4.4  #Android系统版本
ro.build.date=2017年 07⽉ 13⽇星期四14:39:47 CST  #编译时间
ro.build.date.utc=1499927987  #编译时间(UTC)
pe=userdebug  #编译类型(eng/user)
ro.build.user=pngcui  #编译者
ro.build.host=Sky-pngcui  #编译机器名
ro.build.tags=test-keys  #系统标记
del=MSD6A648  #设备型号
ro.product.brand=MStar  #设备品牌
ro.product.name=aosp_almond  #产品名
ro.product.device=almond  #采⽤的设备名
ro.product.board=almond  #采⽤的主板名
ro.product.cpu.abi=armeabi-v7a  #CPU版本
ro.product.cpu.abi2=armeabi  #CPU品牌
ro.product.manufacturer=Skyworth-qx, Inc.  #产品制造商
ro.product.locale.language=zh
ro.ion=CN
ro.wifi.channels=  #⽆线局域⽹络的通信信道,空⽩表⽰⾃动识别
ro.board.platform=mooney  #主板平台
# ro.build.product is obsolete; use ro.product.device
ro.build.product=almond  #设备名,已被废弃,使⽤ro.product.device
# Do not try to parse ro.build.description or .fingerprint
ro.build.description=aosp_almond-userdebug 4.4.4 KTU84P TVOS-04.19.010.02.06.Mooney test-keys  #⽤户key
ro.build.fingerprint=MStar/aosp_almond/almond:4.4.4/KTU84P/TVOS-04.19.010.02.06.Mooney:userdebug/test-keys  #机⾝码
ro.build.characteristics=tv
# end build properties
3.修改prop的属性的说明,需要对照build/tools/buildinfo.sh进⾏
  build.id属性(build/core/build_id.mk)
export BUILD_ID=8M648
  build.display.id(build/core/Makefile)
build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER) $(BUILD_VERSION_TAGS) # Display parameters shown under Settings -> About Phone
ifeq ($(TARGET_BUILD_VARIANT),user)
# User builds should show:
# release build number or branch.buld_number non-release builds
# Dev. branches should have DISPLAY_BUILD_NUMBER set
ifeq "true""$(DISPLAY_BUILD_NUMBER)"
BUILD_DISPLAY_ID := $(BUILD_ID).$(BUILD_NUMBER) $(BUILD_KEYS)
else
BUILD_DISPLAY_ID := $(BUILD_ID) $(BUILD_KEYS)
endif
else
# Non-user builds should show detailed build information
BUILD_DISPLAY_ID := $(build_desc)
endif
  build.version.incremental(device/mstar/almond/BoardConfigCommon.mk)
BUILD_NUMBER := TVOS-04.19.010.02.07.Mooney
  del、ro.product.brand、ro.product.name、ro.product.device、
ro.product.manufacturer(device/mstar/almond/aosp_almond.mk)
# Set those variables here to overwrite the inherited values.
PRODUCT_NAME := aosp_almond
PRODUCT_DEVICE := almond
PRODUCT_BRAND := MStar
PRODUCT_MODEL := MSD6A648
PRODUCT_MANUFACTURER := Skyworth-qx, Inc.
  注:PRODUCT_DEVICE会决定device下⽬录的选择,故尽量不要更改
  build.description(build/core/Makefile)
build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER) $(BUILD_VERSION_TAGS) $(INSTALLED_BUILD_PROP_TARGET): PRIVATE_BUILD_DESC := $(build_desc)
  product.board(device/mstar/almond/BoardConfig.mk)
TARGET_BOOTLOADER_BOARD_NAME := almond
4.Android系统中Setting.apk中内核版本
  packages/apps/Settings/src/com/android/settings/DeviceInfoSettings.java  1private static final String FILENAME_PROC_VERSION = "/proc/version";
2private static final String KEY_KERNEL_VERSION = "kernel_version";
3
4 @Override
5public void onCreate(Bundle icicle) {
6  findPreference(KEY_KERNEL_VERSION).setSummary(getFormattedKernelVersion());
7 }
8
9public static String getFormattedKernelVersion() {
10try {
11return formatKernelVersion(readLine(FILENAME_PROC_VERSION));
12
13        } catch (IOException e) {
14            Log.e(LOG_TAG,
15                "IO Exception when getting kernel version for Device Info screen",
16                e);
17
18return "Unavailable";
19        }
20    }
21
22  public static String formatKernelVersion(String rawKernelVersion) {
23// Example (see tests for more):
24// Linux version 3.0.31-g6fb96c9 (x.xxx) \
25//    (gcc version 4.6.x-xxx 20120106 (prerelease) (GCC) ) #1 SMP PREEMPT \
26//    Thu Jun 28 11:02:39 PDT 2012
27
28final String PROC_VERSION_REGEX =
29            "Linux version (\\S+) " + /* group 1: "3.0.31-g6fb96c9" */
30            "\\((\\S+?)\\) " +        /* group 2: "x@y" (kernel builder) */
31            "(?:\\(gcc.+? \\)) " +    /* ignore: GCC version information */
32            "(#\\d+) " +              /* group 3: "#1" */
33            "(?:.*?)?" +              /* ignore: optional SMP, PREEMPT, and any CONFIG_FLAGS */
34            "((Sun|Mon|Tue|Wed|Thu|Fri|Sat).+)"; /* group 4: "Thu Jun 28 11:02:39 PDT 2012" */ 35
36        Matcher m = Patternpile(PROC_VERSION_REGEX).matcher(rawKernelVersion); 37if (!m.matches()) {
38            Log.e(LOG_TAG, "Regex did not match on /proc/version: " + rawKernelVersion);
39return "Unavailable";
40        } else if (m.groupCount() < 4) {
41            Log.e(LOG_TAG, "Regex match on /proc/version only returned " + m.groupCount()
42                    + " groups");
43return "Unavailable";
44        }
up(1) + "\n" +                // 3.0.31-g6fb96c9
46            m.group(2) + " " + m.group(3) + "\n" + // x@y #1
47            m.group(4);                            // Thu Jun 28 11:02:39 PDT 2012
48    }
49
  即从/proc/version⽂件中提取相应信息。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。