Platform: RK3568
OS: Android 12
Kernel: v4.19.206
SDK Version:android-12.0-mid-rkr1
之所以用这篇来作为博客文章的开端,是因为本人最初入行的时候就开始做这些了,如今老方法在新系统上有些不太适用了,就稍微再理了一遍,也算是提醒自己“不忘初心”吧。以下是正文:
需求:
修改系统Settings显示的产品型号,版本号和默认时区等
实现方法:
在build/make/目录下修改
型号(Model)
diff --git a/core/sysprop.mk b/core/sysprop.mk
index 636c8b439a..98e221f7dd 100644
--- a/core/sysprop.mk
+++ b/core/sysprop.mk
@@ -38,13 +38,13 @@ define generate-common-build-props
echo "ro.product.$(1).brand=$(PRODUCT_SYSTEM_BRAND)" >> $(2);\
echo "ro.product.$(1).device=$(PRODUCT_SYSTEM_DEVICE)" >> $(2);\
echo "ro.product.$(1).manufacturer=$(PRODUCT_SYSTEM_MANUFACTURER)" >> $(2);\
- echo "ro.product.$(1).model=$(PRODUCT_SYSTEM_MODEL)" >> $(2);\
+ echo "ro.product.$(1).model=MY_MODEL" >> $(2);\
echo "ro.product.$(1).name=$(PRODUCT_SYSTEM_NAME)" >> $(2);\
,\
echo "ro.product.$(1).brand=$(PRODUCT_BRAND)" >> $(2);\
echo "ro.product.$(1).device=$(TARGET_DEVICE)" >> $(2);\
echo "ro.product.$(1).manufacturer=$(PRODUCT_MANUFACTURER)" >> $(2);\
- echo "ro.product.$(1).model=$(PRODUCT_MODEL)" >> $(2);\
+ echo "ro.product.$(1).model=MY_MODEL" >> $(2);\
echo "ro.product.$(1).name=$(TARGET_PRODUCT)" >> $(2);\
)\
$(if $(filter system vendor odm,$(1)),\
版本号(Build number)
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index 3f95e3cad3..e693304f21 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -297,7 +297,7 @@ ifndef BUILD_NUMBER
# If no BUILD_NUMBER is set, create a useful "I am an engineering build
# from this date/time" value. Make it start with a non-digit so that
# anyone trying to parse it as an integer will probably get "0".
- BUILD_NUMBER := eng.$(shell echo $${BUILD_USERNAME:0:6}).$(shell $(DATE) +%Y%m%d.%H%M%S)
+ BUILD_NUMBER := eng.MY_BuildNumber.$(shell $(DATE) +%Y%m%d.%H%M%S)
HAS_BUILD_NUMBER := false
endif
.KATI_READONLY := BUILD_NUMBER HAS_BUILD_NUMBER
时区(Timezone)
diff --git a/tools/buildinfo.sh b/tools/buildinfo.sh
index a349cba0f0..04490f3d4a 100755
--- a/tools/buildinfo.sh
+++ b/tools/buildinfo.sh
@@ -54,5 +54,6 @@ echo "ro.build.description=$PRIVATE_BUILD_DESC"
if [ -n "$BUILD_THUMBPRINT" ] ; then
echo "ro.build.thumbprint=$BUILD_THUMBPRINT"
fi
-
+# set timezone as US EST
+echo "persist.sys.timezone=America/New_York"
echo "# end build properties"
简单分析:
Android12的代码和之前版本的SDK有一定差别
之前可以直接在buildinfo.sh里面修改,如今可能不太适用了,重新跟了一遍,以下是简单分析过程:
下列源码均在build/make/ 目录下
型号(Model)
型号相对简单,Settings中是通过Build.MODEL获取的,实际是读取ro.product.model 属性
core/sysprop.mk
brand,device,model等属性都在这部分设置,之后是自动生成到build.prop文件中去
# Emits a set of sysprops common to all partitions to a file.
# $(1): Partition name
# $(2): Output file name
define generate-common-build-props
echo "####################################" >> $(2);\
echo "# from generate-common-build-props" >> $(2);\
echo "# These properties identify this partition image." >> $(2);\
echo "####################################" >> $(2);\
$(if $(filter system,$(1)),\
echo "ro.product.$(1).brand=$(PRODUCT_SYSTEM_BRAND)" >> $(2);\
echo "ro.product.$(1).device=$(PRODUCT_SYSTEM_DEVICE)" >> $(2);\
echo "ro.product.$(1).manufacturer=$(PRODUCT_SYSTEM_MANUFACTURER)" >> $(2);\
echo "ro.product.$(1).model=$(PRODUCT_MODEL)" >> $(2);\
echo "ro.product.$(1).name=$(PRODUCT_SYSTEM_NAME)" >> $(2);\
,\
echo "ro.product.$(1).brand=$(PRODUCT_BRAND)" >> $(2);\
echo "ro.product.$(1).device=$(TARGET_DEVICE)" >> $(2);\
echo "ro.product.$(1).manufacturer=$(PRODUCT_MANUFACTURER)" >> $(2);\
echo "ro.product.$(1).model=$(PRODUCT_MODEL)" >> $(2);\
echo "ro.product.$(1).name=$(TARGET_PRODUCT)" >> $(2);\
)\
版本号(Build number)
Settings中版本号是用Build.DISPLAY 获取的
在Build.java中可以看到是读取ro.build.display.id 属性
而该属性是由BUILD_DISPLAY_ID 来定义的:
tools/buildinfo.sh:12:echo "ro.build.display.id=$BUILD_DISPLAY_ID"
如果想要全部自定义版本号,可直接重写ro.build.display.id 属性,我这边的需求是部分自定义,因此继续跟下去
core/sysprop.mk
我们一般编译的是userdebug版本,因此最终是读取BUILD_DESC的值
# -----------------------------------------------------------------
# Define human readable strings that describe this build
#
# BUILD_ID: detail info; has the same info as the build fingerprint
BUILD_DESC := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER_FROM_FILE) $(BUILD_VERSION_TAGS)
# BUILD_DISPLAY_ID is 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_FROM_FILE) $(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_NUMBER_FROM_FILE 为例继续追踪,可以看到它是从一个txt文件中去取值
core/config.mk:757:BUILD_NUMBER_FROM_FILE := $$(cat $(SOONG_OUT_DIR)/build_number.txt)
core/main.mk
这里是写入txt的过程
$(shell mkdir -p $(SOONG_OUT_DIR) && \
echo -n $(BUILD_NUMBER) > $(SOONG_OUT_DIR)/build_number.tmp; \
if ! cmp -s $(SOONG_OUT_DIR)/build_number.tmp $(SOONG_OUT_DIR)/build_number.txt; then \
mv $(SOONG_OUT_DIR)/build_number.tmp $(SOONG_OUT_DIR)/build_number.txt; \
else \
rm $(SOONG_OUT_DIR)/build_number.tmp; \
fi)
endif
BUILD_NUMBER_FILE := $(SOONG_OUT_DIR)/build_number.txt
.KATI_READONLY := BUILD_NUMBER_FILE
最终找到了BUILD_NUMBER
core/version_defaults.mk:300: BUILD_NUMBER := eng.$(shell echo $${BUILD_USERNAME:0:6}).$(shell $(DATE) +%Y%m%d.%H%M%S)
时区(Timezone)
之前一般是在device/目录下对应产品的system.prop 中设置persist.sys.timezone 属性,但是在Android12中已经没有了该文件,因此要换个方法
据我所知,源码中设置属性大概有几种方法:
- 在buildinfo.sh 中用echo方法来设置
- 在device.mk中用PRODUCT_PROPERTY_OVERRIDES 来设置
- 在main.mk 中用ADDITIONAL_BUILD_PROPERTIES 来设置
我这边还是选择比较简单的在buildinfo.sh 中设置,具体的Android时区表网上有很多资源就不赘述了
参考文章
https://www.cnblogs.com/wmc245376374/p/13663206.html
欢迎留言讨论,感谢阅读~