android 添加ro属性字段并初始化

硬件平台:QCS6125

软件平台:Android11

需求:硬件需通过硬件电路区分为多款型号,需要初始化到相应的系统属性字段展示。

这种型号属性适合做成ro类型,类似于原生系统的ro.product.model,由于android层面拿到这个具体的型号值是内核通过传递cmdline而获取的,内核层面拿到硬件型号的区别从而在cmdline添加了一个board-id字段,Android层面在init进程解析并设置属性即可。

修改分两部分,init一部分,settings展示代码一部分;

1、init部分改动:

cpp 复制代码
diff --git a/init/property_service.cpp b/init/property_service.cpp
index 94c6e466d..17e1c59b6 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -100,6 +100,8 @@ static bool accept_messages = false;
 static std::mutex accept_messages_lock;
 static std::thread property_service_thread;
 
+const std::string& model_prop = "ro.product.yfdsubmodel";
+
 static PropertyInfoAreaFile property_info_area;
 
 struct PropertyAuditData {
@@ -1150,6 +1152,23 @@ static void ProcessKernelCmdline() {
             for_emulator = true;
         } else if (StartsWith(key, "androidboot.")) {
             InitPropertySet("ro.boot." + key.substr(12), value);
+        } else if (StartsWith(key, "board_id")) {
+            const char *val = value.c_str();
+            if (strcmp(val, "1") == 0) {
+                InitPropertySet(model_prop, "S2(T1000)");
+            } else if (strcmp(val, "2") == 0) {
+                InitPropertySet(model_prop, "S2N(T2001)");
+            } else if (strcmp(val, "3") == 0) {
+                InitPropertySet(model_prop, "S2N(TC358767)");
+            } else if (strcmp(val, "4") == 0) {
+                InitPropertySet(model_prop, "S3(TC358767)");
+            } else if (strcmp(val, "5") == 0) {
+                InitPropertySet(model_prop, "E1(T2001)");
+            } else if (strcmp(val, "6") == 0) {
+                InitPropertySet(model_prop, "E1(TC358767)");
+            } else {
+                LOG(ERROR) << "Unknown board id.";
+            }
         }
     });

2、Settings页面展示部分修改:

java 复制代码
diff --git a/src/com/android/settings/development/AdbDeviceNamePreferenceController.java b/src/com/android/settings/development/AdbDeviceNamePreferenceController.java
index 7706c3cdbb..546de8819e 100644
--- a/src/com/android/settings/development/AdbDeviceNamePreferenceController.java
+++ b/src/com/android/settings/development/AdbDeviceNamePreferenceController.java
@@ -25,6 +25,8 @@ import android.os.Build;
 import android.provider.Settings;
 import android.widget.Toast;
 
+import android.os.SystemProperties;
+
 import androidx.preference.PreferenceScreen;
 
 import com.android.settings.R;
@@ -51,7 +53,8 @@ public class AdbDeviceNamePreferenceController extends BasePreferenceController
         mDeviceName = Settings.Global.getString(mContext.getContentResolver(),
                 Settings.Global.DEVICE_NAME);
         if (mDeviceName == null) {
-            mDeviceName = Build.MODEL;
+            //mDeviceName = Build.MODEL;
+            mDeviceName = SystemProperties.get("ro.product.yfdsubmodel");
         }
     }
 
diff --git a/src/com/android/settings/development/WirelessDebuggingFragment.java b/src/com/android/settings/development/WirelessDebuggingFragment.java
index 68d25e18cf..2414fb6041 100644
--- a/src/com/android/settings/development/WirelessDebuggingFragment.java
+++ b/src/com/android/settings/development/WirelessDebuggingFragment.java
@@ -29,6 +29,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.SystemProperties;
 import android.provider.Settings;
 import android.util.Log;
 
@@ -461,7 +462,8 @@ public class WirelessDebuggingFragment extends DashboardFragment
         String deviceName = Settings.Global.getString(getContext().getContentResolver(),
                 Settings.Global.DEVICE_NAME);
         if (deviceName == null) {
-            deviceName = Build.MODEL;
+            //deviceName = Build.MODEL;
+            deviceName = SystemProperties.get("ro.product.yfdsubmodel");;
         }
         return deviceName;
     }
diff --git a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
index 42aeede939..369aef408c 100644
--- a/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/DeviceNamePreferenceController.java
@@ -22,6 +22,7 @@ import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiManager;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.SystemProperties;
 import android.provider.Settings;
 import android.text.SpannedString;
 
@@ -80,7 +81,8 @@ public class DeviceNamePreferenceController extends BasePreferenceController
             mDeviceName = Utils.getString(mContext, Utils.KEY_DEVICE_NAME);
         }
         if (mDeviceName == null) {
-            mDeviceName = Build.MODEL;
+            //mDeviceName = Build.MODEL;
+            mDeviceName = SystemProperties.get("ro.product.yfdsubmodel");;
         }
     }
 
diff --git a/src/com/android/settings/deviceinfo/HardwareInfoPreferenceController.java b/src/com/android/settings/deviceinfo/HardwareInfoPreferenceController.java
index 38fc8baf1b..c8af4f8838 100644
--- a/src/com/android/settings/deviceinfo/HardwareInfoPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/HardwareInfoPreferenceController.java
@@ -17,6 +17,7 @@ package com.android.settings.deviceinfo;
 
 import android.content.Context;
 import android.os.Build;
+import android.os.SystemProperties;
 import android.util.Log;
 
 import androidx.preference.PreferenceScreen;
@@ -69,11 +70,14 @@ public class HardwareInfoPreferenceController extends BasePreferenceController {
     public static String getDeviceModel() {
         FutureTask<String> msvSuffixTask = new FutureTask<>(() -> DeviceInfoUtils.getMsvSuffix());
 
+        String model = SystemProperties.get("ro.product.yfdsubmodel");
+
         msvSuffixTask.run();
         try {
             // Wait for msv suffix value.
             final String msvSuffix = msvSuffixTask.get();
-            return Build.MODEL + msvSuffix;
+            //return Build.MODEL + msvSuffix;
+            return model + msvSuffix;
         } catch (ExecutionException e) {
             Log.e(TAG, "Execution error, so we only show model name");
         } catch (InterruptedException e) {
@@ -81,6 +85,7 @@ public class HardwareInfoPreferenceController extends BasePreferenceController {
         }
         // If we can't get an msv suffix value successfully,
         // it's better to return model name.
-        return Build.MODEL;
+        //return Build.MODEL;
+        return model;
     }
 }

Mark。。。

相关推荐
HahaGiver6663 分钟前
Unity与Android原生交互开发入门篇 - 打开Unity游戏的设置
android·unity·交互
2501_9159090630 分钟前
WebView 调试工具全解析,解决“看不见的移动端问题”
android·ios·小程序·https·uni-app·iphone·webview
IT乐手2 小时前
android 下载管理工具类
android
2501_915106323 小时前
App 怎么上架 iOS?从准备资料到开心上架(Appuploader)免 Mac 上传的完整实战流程指南
android·macos·ios·小程序·uni-app·iphone·webview
科技峰行者4 小时前
安卓16提前发布能否改写移动生态格局
android
蒲公英少年带我飞4 小时前
Android NDK 编译 protobuf
android
沐怡旸4 小时前
【底层机制】ART虚拟机深度解析:Android运行时的架构革命
android·面试
小禾青青5 小时前
uniapp安卓打包遇到报错:Uncaught SyntaxError: Invalid regular expression: /[\p{L}\p{N}]/
android·uni-app
studyForMokey5 小时前
【Kotlin内联函数】
android·开发语言·kotlin
2501_915921437 小时前
iOS 抓不到包怎么办?工程化排查与替代抓包方案(抓包/HTTPS/Charles代理/tcpdump)
android·ios·小程序·https·uni-app·iphone·tcpdump