manager: Refactoring the get device name logic (#152)

* manager: Import `getDeviceInfo()` from bmax/APatch

Co-authored-by: GarfieldHan <2652609017@qq.com>
Signed-off-by: WenHao2130 <wenhao2130@outlook.com>

* manager: Use `getDeviceInfo()` instead `Build.DEVICE`

Signed-off-by: WenHao2130 <wenhao2130@outlook.com>

---------

Signed-off-by: WenHao2130 <wenhao2130@outlook.com>
Co-authored-by: GarfieldHan <2652609017@qq.com>
This commit is contained in:
WenHao2130
2025-06-08 15:47:48 +08:00
committed by GitHub
parent 9c7ba5b998
commit fa060dca58

View File

@@ -236,6 +236,16 @@ class HomeViewModel : ViewModel() {
} }
} }
private fun getDeviceInfo(): String {
var manufacturer =
Build.MANUFACTURER[0].uppercaseChar().toString() + Build.MANUFACTURER.substring(1)
if (Build.BRAND != Build.MANUFACTURER) {
manufacturer += " " + Build.BRAND[0].uppercaseChar() + Build.BRAND.substring(1)
}
manufacturer += " " + Build.MODEL + " "
return manufacturer
}
@SuppressLint("PrivateApi") @SuppressLint("PrivateApi")
private fun getDeviceModel(): String { private fun getDeviceModel(): String {
return try { return try {
@@ -247,7 +257,7 @@ class HomeViewModel : ViewModel() {
"ro.vivo.market.name", // Vivo "ro.vivo.market.name", // Vivo
"ro.config.marketing_name" // Huawei "ro.config.marketing_name" // Huawei
) )
var result = Build.DEVICE var result = getDeviceInfo()
for (key in marketNameKeys) { for (key in marketNameKeys) {
val marketName = getMethod.invoke(null, key, "") as String val marketName = getMethod.invoke(null, key, "") as String
if (marketName.isNotEmpty()) { if (marketName.isNotEmpty()) {
@@ -258,7 +268,7 @@ class HomeViewModel : ViewModel() {
result result
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "Error getting device model", e) Log.e(TAG, "Error getting device model", e)
Build.DEVICE getDeviceInfo()
} }
} }