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。。。

相关推荐
DogDaoDao3 小时前
Android 硬件编码器参数完全指南:MediaCodec 深度解析
android·音视频·视频编解码·h264·硬编码·视频直播·mediacodec
JohnnyDeng943 小时前
Android 自定义 View:Canvas 绘图与事件分发深度解析
android
Android小码家7 小时前
Framework之Launcher小窗开发
android·framework·虚拟屏·小窗
赏金术士7 小时前
第七章:状态管理实战与架构总结
android·ui·kotlin·compose
颂love8 小时前
MySQL的执行流程
android·数据库·mysql
云起SAAS12 小时前
抖音小游戏源码 - 消消乐 | 含激励广告+成就系统 | 开箱即用商业级消除游戏模板
android·游戏·广告联盟·看激励广告联盟流量主·抖音小游戏源码 - 消消乐
大貔貅喝啤酒14 小时前
基于Windows下载安装Android Studio 3.3.2版本教程(2026详细图文版)
android·java·windows·android studio
程序员码歌14 小时前
OpenSpec 到 Superpowers:AI 编码从说清到做对
android·前端·人工智能
2501_9151063214 小时前
深入解析无源码iOS加固原理与方案,保护应用安全
android·安全·ios·小程序·uni-app·cocoa·iphone
黄林晴18 小时前
重磅官宣:Android UI 开发正式进入 Compose-first 时代
android·google io