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

相关推荐
长亭外的少年3 小时前
Kotlin 编译失败问题及解决方案:从守护进程到 Gradle 配置
android·开发语言·kotlin
建群新人小猿6 小时前
会员等级经验问题
android·开发语言·前端·javascript·php
1024小神7 小时前
tauri2.0版本开发苹果ios和安卓android应用,环境搭建和最后编译为apk
android·ios·tauri
兰琛7 小时前
20241121 android中树结构列表(使用recyclerView实现)
android·gitee
Y多了个想法8 小时前
RK3568 android11 适配敦泰触摸屏 FocalTech-ft5526
android·rk3568·触摸屏·tp·敦泰·focaltech·ft5526
NotesChapter9 小时前
Android吸顶效果,并有着ViewPager左右切换
android
_祝你今天愉快10 小时前
分析android :The binary version of its metadata is 1.8.0, expected version is 1.5.
android
暮志未晚Webgl10 小时前
109. UE5 GAS RPG 实现检查点的存档功能
android·java·ue5
麦田里的守望者江11 小时前
KMP 中的 expect 和 actual 声明
android·ios·kotlin
Dnelic-11 小时前
解决 Android 单元测试 No tests found for given includes:
android·junit·单元测试·问题记录·自学笔记