硬件平台:QCS6125
软件平台:Android11
需求:硬件需通过硬件电路区分为多款型号,需要初始化到相应的系统属性字段展示。
这种型号属性适合做成ro类型,类似于原生系统的ro.product.model,由于android层面拿到这个具体的型号值是内核通过传递cmdline而获取的,内核层面拿到硬件型号的区别从而在cmdline添加了一个board-id字段,Android层面在init进程解析并设置属性即可。
修改分两部分,init一部分,settings展示代码一部分;
1、init部分改动:
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页面展示部分修改:
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 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。。。