一、设备名称修改
1、 Setings源码
packages/apps/Settings/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
private void initializeDeviceName() { mDeviceName = Settings.Global.getString(mContext.getContentResolver(), Settings.Global.DEVICE_NAME); if (mDeviceName == null) { mDeviceName = Build.MODEL; } }
可以修改数据库中Settings.Global.DEVICE_NAME
字段或者修改Build.MODEL
2.DEVICE_NAME具体值如下:
frameworks/base/core/java/android/provider/Settings.java
/** * The name of the device */ public static final String DEVICE_NAME = "device_name";
初始化的地方在SettingsProvider:
frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
private void loadGlobalSettings(SQLiteDatabase db) { ...... loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName()); ........ } private String getDefaultDeviceName() { return mContext.getResources().getString(R.string.def_device_name_simple, Build.MODEL); }
res/values/defaults.xml <string name="def_device_name_simple">%1$s</string>
3.Build.MODEL如下:
frameworks/base/core/java/android/os/Build.java
/** The end-user-visible name for the end product. */ public static final String MODEL = getString("ro.product.model");
4.本项目中实际修改Build.MODEL,即ro.product.model
属性值
sl8541e_1h10_32b/sl8541e_1h10_32b_Natv.mk -PRODUCT_MODEL := sl8541e_1h10_32b_Natv +PRODUCT_MODEL := FT11
二、设备型号修改
1、Settings源码
packages/apps/Settings/src/com/android/settings/deviceinfo/HardwareInfoPreferenceController.java
public static String getDeviceModel() { FutureTask<String> msvSuffixTask = new FutureTask<>(() -> DeviceInfoUtils.getMsvSuffix()); msvSuffixTask.run(); try { // Wait for msv suffix value. final String msvSuffix = msvSuffixTask.get(); return Build.MODEL + msvSuffix; } catch (ExecutionException e) { Log.e(TAG, "Execution error, so we only show model name"); } catch (InterruptedException e) { Log.e(TAG, "Interruption error, so we only show model name"); } // If we can't get an msv suffix value successfully, // it's better to return model name. return Build.MODEL; }
型号读取的也跟Build.MODEL有关,但是它可以还带后缀msvSuffix
- 后缀msvSuffix 的读取
``
private static final String FILENAME_MSV = "/sys/board_properties/soc/msv"; public static String getMsvSuffix() { // Production devices should have a non-zero value. If we can't read it, assume it's a // production device so that we don't accidentally show that it's an ENGINEERING device. try { String msv = readLine(FILENAME_MSV); // Parse as a hex number. If it evaluates to a zero, then it's an engineering build. if (Long.parseLong(msv, 16) == 0) { return " (ENGINEERING)"; } } catch (IOException|NumberFormatException e) { // Fail quietly, as the file may not exist on some devices, or may be unreadable } return ""; } private static String readLine(String filename) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(filename), 256); try { return reader.readLine(); } finally { reader.close(); } }
实际就是读取文件 "/sys/board_properties/soc/msv"的内容,而我们机器中不包含该文件,所以型号实际上还是Build.MODEL。
三、修改版本号显示
1.Settings源码
/packages/apps/Settings/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
public CharSequence getSummary() { return BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY); }
frameworks/base/core/java/android/os/Build.java
/** A build ID string meant for displaying to the user */ public static final String DISPLAY = getString("ro.build.display.id");
实际上修改属性值ro.build.display.id