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

相关推荐
zh_xuan3 小时前
Android Looper源码阅读
android
用户02738518402613 小时前
[Android]RecycleView的item用法
android
前行的小黑炭14 小时前
Android :为APK注入“脂肪”,论Android垃圾代码在安全加固中的作用
android·kotlin
帅得不敢出门15 小时前
Docker安装Ubuntu搭建Android SDK编译环境
android·ubuntu·docker
tangweiguo0305198715 小时前
Android Kotlin 动态注册 Broadcast 的完整封装方案
android·kotlin
fatiaozhang952715 小时前
浪潮CD1000-移动云电脑-RK3528芯片-2+32G-安卓9-2种开启ADB ROOT刷机教程方法
android·网络·adb·电脑·电视盒子·刷机固件·机顶盒刷机
前行的小黑炭16 小时前
Android 不同构建模式下使用不同类的例子:如何在debug模式和release模式,让其使用不同的类呢?
android·kotlin·gradle
andyguo17 小时前
AI模型测评平台工程化实战十二讲(第一讲:从手工测试到系统化的觉醒)
android
2501_9159214317 小时前
小团队如何高效完成 uni-app iOS 上架,从分工到工具组合的实战经验
android·ios·小程序·uni-app·cocoa·iphone·webview
幂简集成17 小时前
通义灵码 AI 程序员低代码 API 课程实战教程
android·人工智能·深度学习·神经网络·低代码·rxjava