在Android系统中有几个版本号经常遇到,有时还要做特殊处理。下面整理一下,这些都保留在文件系统的/system/build.prop文件里,build.prop相当于Windows下的注册表,这个文件内定义了系统初始(或永久)的一些参数属性、功能的开放等。
下面的代码均是基于Android8.1分析。
1、在系统设置代码中搜索“版本号”,AndroidStudio中全局搜索快捷键“Ctrl+Shift+f”。
"版本号"
全局搜索“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 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_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中,如下:
@Override
protected String getDeviceName() {
if (mLocalAdapter != null && mLocalAdapter.isEnabled()) {
return mLocalAdapter.getName();
}
return null;
}
@Override
protected 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 mName
return 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的值。
在Settings的WifiTetherSSIDPreferenceController类中,获取WiFiConfiguration的SSID。
@Override
public 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
@Override
public WifiConfiguration getWifiApConfiguration() {
enforceAccessPermission();
int uid = Binder.getCallingUid();
// only allow Settings UI to get the saved SoftApConfig
if (!mWifiPermissionsUtil.checkConfigOverridePermission(uid)) {
// random apps should not be allowed to read the user specified config
throw 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-xxxxxxxxxxxx
config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
return config;
}
最后全局搜索字符串wifi_tether_configure_ssid_default,定位到frameworks/base/core/res/res/values/strings.xml,如下:
AndroidAP
正好匹配起来,修改上面strings.xml文件中的字符串值即可。
最后,上一篇好文章:
Android系统默认参数的修改