在Android系统中有几个版本号经常遇到,有时还要做特殊处理。下面整理一下,这些都保留在文件系统的/system/build.prop文件里,build.prop相当于Windows下的注册表,这个文件内定义了系统初始(或永久)的一些参数属性、功能的开放等。

下面的代码均是基于Android8.1分析。

系统设置--关于手机--版本号

1、在系统设置代码中搜索“版本号”,AndroidStudio中全局搜索快捷键“Ctrl+Shift+f”。

<string name="build_number" msgid="3075795840572241758">"版本号"</string>

全局搜索“build_number”,找到com.android.settings.deviceinfo.BuildNumberPreferenceController类。

private static final String KEY_BUILD_NUMBER = "build_number";
    public void displayPreference(PreferenceScreen screen) {super.displayPreference(screen);final Preference preference = screen.findPreference(KEY_BUILD_NUMBER);if (preference != null) {try {preference.setSummary(BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY));preference.setEnabled(true);} catch (Exception e) {preference.setSummary(R.string.device_info_default);}}}

此时关键就是找到Build.DISPLAY。

这里是定义在android.os.Build类中,该类位于frameworks/base/core/java目录下,如下:

    /** A build ID string meant for displaying to the user */public static final String DISPLAY = getString("ro.build.display.id");
    private static String getString(String property) {return SystemProperties.get(property, UNKNOWN);}

我们看到了DISPLAY是Build类中的静态变量,表示“ro.build.display.id”的属性值。

2、此时我们就需要知道“ro.build.display.id”属性值是在哪里定义的。

这里我们在Android源码环境下全局搜索“ro.build.display.id”,命令:grep -r "ro.build.display.id" ./

其实只在build目录下搜索即可,build存放系统编译规则。

在build/make/tools/buildinfo.sh文件中搜索出:

echo "ro.build.display.id=$BUILD_DISPLAY_ID"

我们继续在build目录下,搜索“BUILD_DISPLAY_ID”,命令:grep -r "BUILD_DISPLAY_ID"。在文件build/make/core/MakeFile中搜索出:

# 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 setifeq (true,$(DISPLAY_BUILD_NUMBER))BUILD_DISPLAY_ID := $(BUILD_ID).$(BUILD_NUMBER_FROM_FILE) $(BUILD_KEYS)elseBUILD_DISPLAY_ID := $(BUILD_ID) $(BUILD_KEYS)endif
else# Non-user builds should show detailed build informationBUILD_DISPLAY_ID := $(build_desc)
endif

BUILD_ID定义在build/make/core/build_id.mk中,如下:

# BUILD_ID is usually used to specify the branch name
# (like "MAIN") or a branch name and a release candidate
# (like "CRB01").  It must be a single word, and is
# capitalized by convention.export BUILD_ID=OPM1.171019.011

BUILD_NUMBER_FROM_FILE定义在build/make/core/main.mk中,如下:

BUILD_NUMBER_FROM_FILE := $$(cat $(OUT_DIR)/build_number.txt)

这里OUT_DIR就是out目录,build_number.txt就是在out目录下生成的一个文件,内容如下:

eng.sgf.20180421.152052

这里是eng版本。

BUILD_KEYS定义在build/make/core/MakeFile中,表示系统签名,test-keys只适用于开发阶段。如下:

# The "test-keys" tag marks builds signed with the old test keys,
# which are available in the SDK.  "dev-keys" marks builds signed with
# non-default dev keys (usually private keys from a vendor directory).
# Both of these tags will be removed and replaced with "release-keys"
# when the target-files is signed in a post-build step.
ifeq ($(DEFAULT_SYSTEM_DEV_CERTIFICATE),build/target/product/security/testkey)
BUILD_KEYS := test-keys
else
BUILD_KEYS := dev-keys
endif

如果不是user版本,BUILD_DISPLAY_ID的取值就是$(build_desc)

# A human-readable string that descibes this build in detail.
build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER_FROM_FILE) $(BUILD_VERSION_TAGS)

BUILD_NUMBER定义在build/make/core/version_default.mk文件中,如下:

ifndef BUILD_NUMBER# BUILD_NUMBER should be set to the source control value that# represents the current state of the source code.  E.g., a# perforce changelist number or a git hash.  Can be an arbitrary string# (to allow for source control that uses something other than numbers),# but must be a single word and a valid file name.## 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 $${USER:0:6}).$(shell $(DATE) +%Y%m%d.%H%M%S)
endif

总结:想要修改版本号,可以通过两个部分修改。

1、修改Java文件,直接写死;

2、修改编译系统,在device中修改。

https://blog.csdn.net/codingnotes/article/details/62222656

系统设置--蓝牙--手机名称

1、手机名称的修改,定位到LocalDeviceNameDialogFragment中,如下:

    @Overrideprotected String getDeviceName() {if (mLocalAdapter != null && mLocalAdapter.isEnabled()) {return mLocalAdapter.getName();}return null;}@Overrideprotected void setDeviceName(String deviceName) {mLocalAdapter.setName(deviceName);}
    private LocalBluetoothAdapter mLocalAdapter;

frameworks/base/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothAdapter.java

    public String getName() {return mAdapter.getName();}
    /** This class does not allow direct access to the BluetoothAdapter. */private final BluetoothAdapter mAdapter;

frameworks/base/core/java/android/bluetooth/BluetoothAdapter.java

    public String getName() {try {return mManagerService.getName();} catch (RemoteException e) {Log.e(TAG, "", e);}return null;}

BluetoothManagerService.java

    public String getName() {mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,"Need BLUETOOTH permission");if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&(!checkIfCallerIsForegroundUser())) {Slog.w(TAG,"getName(): not allowed for non-active and non system user");return null;}try {mBluetoothLock.readLock().lock();if (mBluetooth != null) return mBluetooth.getName();} catch (RemoteException e) {Slog.e(TAG, "getName(): Unable to retrieve name remotely. Returning cached name", e);} finally {mBluetoothLock.readLock().unlock();}// mName is accessed from outside.// It alright without a lock. Here, bluetooth is off, no other thread is// changing mNamereturn mName;}
mName = Settings.Secure.getString(mContentResolver, SECURE_SETTINGS_BLUETOOTH_NAME);

这里的bluetooth_name保存在/data/system/users/0/settings_secure.xml文件中。

在 Android6.0版本时,SettingsProvider被重构,Android 从性能、安全等方面考虑,把SettingsProvider 中原本保存在settings.db中的数据,目前全部保存在 XML 文件中。

具体修改地方:

device/qcom/common/bdroid_buildcfg.h

#define BTM_DEF_LOCAL_NAME   "Acuteag-P6"

MTK平台,修改device目录下custom.conf文件中的bluetooth.HostName的值。

热点--设置WLAN热点--修改名称

在Settings的WifiTetherSSIDPreferenceController类中,获取WiFiConfiguration的SSID。

    @Overridepublic void displayPreference(PreferenceScreen screen) {super.displayPreference(screen);final WifiConfiguration config = mWifiManager.getWifiApConfiguration();if (config != null) {mSSID = config.SSID;} else {mSSID = DEFAULT_SSID;}((ValidatedEditTextPreference) mPreference).setValidator(this);updateSsidDisplay((EditTextPreference) mPreference);}

在WiFiManager类中的getWifiApConfiguration()方法如下:

    public WifiConfiguration getWifiApConfiguration() {try {return mService.getWifiApConfiguration();} catch (RemoteException e) {throw e.rethrowFromSystemServer();}}
    IWifiManager mService;

如果不知道是哪个类继承IWiFiManager.Stub,可以搜索该字符串。

frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiServiceImpl.java

    @Overridepublic WifiConfiguration getWifiApConfiguration() {enforceAccessPermission();int uid = Binder.getCallingUid();// only allow Settings UI to get the saved SoftApConfigif (!mWifiPermissionsUtil.checkConfigOverridePermission(uid)) {// random apps should not be allowed to read the user specified configthrow new SecurityException("App not allowed to read or update stored WiFi Ap config "+ "(uid = " + uid + ")");}mLog.info("getWifiApConfiguration uid=%").c(uid).flush();return mWifiStateMachine.syncGetWifiApConfiguration();}

frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java

    public WifiConfiguration syncGetWifiApConfiguration() {return mWifiApConfigStore.getApConfiguration();}

frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiApConfigStore.java

    private WifiConfiguration getDefaultApConfiguration() {WifiConfiguration config = new WifiConfiguration();config.SSID = mContext.getResources().getString(R.string.wifi_tether_configure_ssid_default) + "_" + getRandomIntForDefaultSsid();config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);String randomUUID = UUID.randomUUID().toString();//first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxxconfig.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13);return config;}

最后全局搜索字符串wifi_tether_configure_ssid_default,定位到frameworks/base/core/res/res/values/strings.xml,如下:

    <!-- Do not translate. Default access point SSID used for tethering --><string name="wifi_tether_configure_ssid_default" translatable="false">AndroidAP</string>

正好匹配起来,修改上面strings.xml文件中的字符串值即可。

最后,上一篇好文章:

Android系统默认参数的修改

修改Android系统的软件版本号等相关推荐

  1. android代码图片编辑,怎样修改android系统apk软件里面的代码和图片?

    你好,你的问题我算是看明白了,从你的问题可以设计三个方面,apk反编译.apk回编译以及apk签名,看来,我得从头说起了. 首先,我在这里提供下反编译Android所需的软件,当然是全套,刚刚收集整理 ...

  2. 修改Android系统默认时间

    一 : 修改Android系统默认时间 源码路径:frameworks/base/services/java/com/android/server/SystemServer.java 主要变量EARL ...

  3. 修改android系统开机动画

    本文转载自:http://blog.csdn.net/u012301841/article/details/51598115 修改android系统开机动画 转载于:https://www.cnblo ...

  4. 修改android系统 字体

    Android系统的字体文件路径为手机存储\system\font 其中三个字体文件分别对应的字体如下: 1.DroidSans.ttf 系统默认英文字体 2.DroidSans-Bold.ttf 系 ...

  5. android系统 修改优化,修改Android系统源代码,优化开机速度。

    通常情况下,Android系统开机保持在20s~25s应该算是合格比较好的状态. 最近几天在看关于Android系统开机启动过程的相关内容.做个笔记. 关于有话Android系统开机时间有话,采取三个 ...

  6. android 系统清理软件,Android软件大比拼:系统清理选择谁?

    [IT168厂商动态]近日,IDC在报告中指出,谷歌Android系统市场份额已接近80%.特别是在中国市场,大量千元以内Android手机的推出,加速了智能手机的快速普及.Android手机也成为用 ...

  7. 把android系统装到sd卡,在Android系统中将软件安装在SD卡的方法

    这样就可以装上更多自己喜欢的软件了. 在Android手机刚面世的时候,系统版本1.5至后来的2.1都不支持把程序装到SD卡上,由于系统内置的空间较小,装不了太多软件,于是人们 想出App2SD的概念 ...

  8. Android系统的软件OpenGL介绍以及移植

    一. 简介 Android从很早之前就给出了软件OpenGL的实现,主要应用场景还真不在于代替GPU来实现UI的绘制,它主要目的是让芯片厂商在GPU驱动还没集成之前带起系统. 先讲下软件OpenGL为 ...

  9. android默认安装位置,修改Android手机的软件默认安装位置

    如无意外,一般来说,android 手机的默认安装位置应该是手机内存,因为考虑到如输入法的软件需要常驻使用. 但对于手机 Room 较小的手机,自然是把如游戏等非关键程序安装在 SD 卡好,留出更多的 ...

最新文章

  1. 自定义msi安装包的执行过程
  2. java学习笔记:使用dom4j解析xml
  3. php 语句,php的控制语句
  4. python mysql autocommit_MySQLdb autocommit的坑
  5. Windows下最轻量级Git克隆工具源码分享
  6. 06 - 雷达发射机 概述
  7. 【源码分享】-c++界面源代码分享
  8. 关于开会了一点点想法
  9. 中文的括号和英文的括号区别_如何在word里快捷键入六角括号
  10. win10删除软件注册表
  11. Android 中编写一个简易购物车,商品包括商品名称,单价,数量,可以对商品进行增删改查功能。(ArrayList,SQLite)
  12. eval()函数是什么?有什么作用?
  13. 联想T430 安装msata接口的SSD固态硬盘
  14. 数字经济是如何崛起的?
  15. 1javascript语法
  16. 深度强化学习落地方法论(6)——回报函数篇
  17. Red Herring2010年亚洲区创新实用产品排名
  18. 【Sublinux】Station P1在Andriod上使用AriaNg远程下载
  19. win7c盘空间越来越小_系统盘可用空间越来越少,如何扩展C盘可用空间?
  20. 矩阵的负二分之一次方

热门文章

  1. 第十四届蓝桥杯集训——练习解题阶段(无序阶段)-基础练习 01字串
  2. 互联网日报 | 7月20日 星期二 | 华为P50系列7月29日发布;盒马NB事业部成立;FF91量产版开启预订...
  3. 如何用python画一束花_武汉早樱开了!却没有赏樱人群,那就用python画一束最美的樱花...
  4. 微信小应用-小程序-demo-仿芒果TV
  5. 实现js动态创建img并使用canvas画线连接
  6. React实现H5在线音乐播放器
  7. 深入剖析Kubernetes笔记:Kubernetes常见问题
  8. SAP AA固定资产上线后录入以前年度固定资产的处理方式
  9. centos 配置DNS服务器地址
  10. phpstudy_pro在wnmp环境下404、403错误