Improve NativeDeviceInfoProvider

-- Export unstripped configs
  -- Simplify code
This commit is contained in:
Rahul Patel
2024-08-11 03:41:49 +05:30
committed by Aayush Gupta
parent 33b398cb3b
commit c6e7166618
3 changed files with 46 additions and 91 deletions

View File

@@ -20,16 +20,15 @@ package com.aurora.store.data.providers
import android.app.ActivityManager
import android.content.Context
import android.content.ContextWrapper
import android.content.Context.ACTIVITY_SERVICE
import android.content.res.Configuration
import android.os.Build
import android.text.TextUtils
import com.aurora.extensions.isHuawei
import java.util.Properties
class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
class NativeDeviceInfoProvider(val context: Context) {
fun getNativeDeviceProperties(): Properties {
fun getNativeDeviceProperties(isExport: Boolean = false): Properties {
val properties = Properties().apply {
//Build Props
setProperty("UserReadableName", "${Build.DEVICE}-default")
@@ -52,7 +51,7 @@ class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
setProperty("Build.ID", Build.ID)
setProperty("Build.BOOTLOADER", Build.BOOTLOADER)
val config = applicationContext.resources.configuration
val config = context.resources.configuration
setProperty("TouchScreen", "${config.touchscreen}")
setProperty("Keyboard", "${config.keyboard}")
setProperty("Navigation", "${config.navigation}")
@@ -64,12 +63,11 @@ class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
)
//Display Metrics
val metrics = applicationContext.resources.displayMetrics
val metrics = context.resources.displayMetrics
setProperty("Screen.Density", "${metrics.densityDpi}")
setProperty("Screen.Width", "${metrics.widthPixels}")
setProperty("Screen.Height", "${metrics.heightPixels}")
//Supported Platforms
setProperty("Platforms", Build.SUPPORTED_ABIS.joinToString(separator = ","))
//Supported Features
@@ -80,7 +78,7 @@ class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
setProperty("SharedLibraries", getSharedLibraries().joinToString(separator = ","))
//GL Extensions
val activityManager =
applicationContext.getSystemService(ACTIVITY_SERVICE) as ActivityManager
context.getSystemService(ACTIVITY_SERVICE) as ActivityManager
setProperty(
"GL.Version",
activityManager.deviceConfigurationInfo.reqGlEsVersion.toString()
@@ -92,9 +90,11 @@ class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
//Google Related Props
setProperty("Client", "android-google")
setProperty("GSF.version", "203615037")
setProperty("Vending.version", "82201710")
setProperty("Vending.versionString", "22.0.17-21 [0] [PR] 332555730")
val gsfVersionProvider = NativeGsfVersionProvider(context, isExport)
setProperty("GSF.version", gsfVersionProvider.gsfVersionCode.toString())
setProperty("Vending.version", gsfVersionProvider.vendingVersionCode.toString())
setProperty("Vending.versionString", gsfVersionProvider.vendingVersionString)
//MISC
setProperty("Roaming", "mobile-notroaming")
@@ -105,51 +105,31 @@ class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
setProperty("SimOperator", "38")
}
if (isHuawei())
if (isHuawei() && !isExport)
stripHuaweiProperties(properties)
return properties
}
private fun getFeatures(): List<String> {
val featureStringList: MutableList<String> = ArrayList()
try {
val availableFeatures = applicationContext.packageManager.systemAvailableFeatures
for (feature in availableFeatures) {
if (feature.name.isNotEmpty()) {
featureStringList.add(feature.name)
}
}
} catch (e: Exception) {
}
return featureStringList
return context
.packageManager
.systemAvailableFeatures
?.mapNotNull { it.name } ?: emptyList()
}
private fun getLocales(): List<String> {
val localeList: MutableList<String> = ArrayList()
localeList.addAll(listOf(*applicationContext.assets.locales))
val locales: MutableList<String> = ArrayList()
for (locale in localeList) {
if (TextUtils.isEmpty(locale)) {
continue
}
locales.add(locale.replace("-", "_"))
}
return locales
return context
.assets
.locales
.mapNotNull { it.replace("-", "_") }
}
private fun getSharedLibraries(): List<String> {
val systemSharedLibraryNames = applicationContext.packageManager.systemSharedLibraryNames
val libraries: MutableList<String> = ArrayList()
try {
if (systemSharedLibraryNames != null) {
libraries.addAll(listOf(*systemSharedLibraryNames))
}
} catch (e: Exception) {
}
return libraries
return context
.packageManager
.systemSharedLibraryNames
?.toList() ?: emptyList()
}
private fun stripHuaweiProperties(properties: Properties): Properties {

View File

@@ -24,53 +24,28 @@ import android.content.pm.PackageManager
import androidx.core.content.pm.PackageInfoCompat
import com.aurora.store.util.PackageUtil.getPackageInfo
class NativeGsfVersionProvider(context: Context) {
private var gsfVersionCode = 0L
private var vendingVersionCode = 0L
private var vendingVersionString = ""
class NativeGsfVersionProvider(context: Context, isExport: Boolean = false) {
private val GOOGLE_SERVICES_PACKAGE_ID = "com.google.android.gms"
private val GOOGLE_VENDING_PACKAGE_ID = "com.android.vending"
// Preferred defaults, not any specific reason they just work fine.
var gsfVersionCode = 203019037L
var vendingVersionCode = 82151710L
var vendingVersionString = "21.5.17-21 [0] [PR] 326734551"
init {
try {
val gsfPackageInfo = getPackageInfo(context, GOOGLE_SERVICES_PACKAGE_ID)
gsfVersionCode = PackageInfoCompat.getLongVersionCode(gsfPackageInfo)
} catch (e: PackageManager.NameNotFoundException) {
// com.google.android.gms not found
if (isExport) {
getPackageInfo(context, GOOGLE_SERVICES_PACKAGE_ID).let {
gsfVersionCode = PackageInfoCompat.getLongVersionCode(it)
}
getPackageInfo(context, GOOGLE_VENDING_PACKAGE_ID).let {
vendingVersionCode = PackageInfoCompat.getLongVersionCode(it)
vendingVersionString = it.versionName ?: vendingVersionString
}
}
} catch (_: PackageManager.NameNotFoundException) {
}
try {
val packageInfo = getPackageInfo(context, GOOGLE_VENDING_PACKAGE_ID)
vendingVersionCode = PackageInfoCompat.getLongVersionCode(packageInfo)
vendingVersionString = packageInfo.versionName!!
} catch (e: PackageManager.NameNotFoundException) {
// com.android.vending not found
}
}
fun getGsfVersionCode(defaultIfNotFound: Boolean): Long {
return if (defaultIfNotFound && gsfVersionCode < GOOGLE_SERVICES_VERSION_CODE)
GOOGLE_SERVICES_VERSION_CODE
else
gsfVersionCode
}
fun getVendingVersionCode(defaultIfNotFound: Boolean): Long {
return if (defaultIfNotFound && vendingVersionCode < GOOGLE_VENDING_VERSION_CODE)
GOOGLE_VENDING_VERSION_CODE
else
vendingVersionCode
}
fun getVendingVersionString(defaultIfNotFound: Boolean): String {
return if (defaultIfNotFound && vendingVersionCode < GOOGLE_VENDING_VERSION_CODE)
GOOGLE_VENDING_VERSION_STRING
else
vendingVersionString
}
companion object {
private const val GOOGLE_SERVICES_PACKAGE_ID = "com.google.android.gms"
private const val GOOGLE_VENDING_PACKAGE_ID = "com.android.vending"
private const val GOOGLE_SERVICES_VERSION_CODE = 203019037L
private const val GOOGLE_VENDING_VERSION_CODE = 82151710L
private const val GOOGLE_VENDING_VERSION_STRING = "21.5.17-21 [0] [PR] 326734551"
}
}

View File

@@ -108,7 +108,7 @@ class SpoofFragment : BaseFragment<FragmentGenericWithPagerBinding>() {
private fun importDeviceConfig(uri: Uri) {
try {
context?.contentResolver?.openInputStream(uri)?.use { input ->
requireContext().contentResolver?.openInputStream(uri)?.use { input ->
PathUtil.getNewEmptySpoofConfig(requireContext()).outputStream().use {
input.copyTo(it)
}
@@ -124,8 +124,8 @@ class SpoofFragment : BaseFragment<FragmentGenericWithPagerBinding>() {
private fun exportDeviceConfig(uri: Uri) {
try {
NativeDeviceInfoProvider(requireContext())
.getNativeDeviceProperties()
.store(context?.contentResolver?.openOutputStream(uri), "DEVICE_CONFIG")
.getNativeDeviceProperties(true)
.store(requireContext().contentResolver?.openOutputStream(uri), "DEVICE_CONFIG")
toast(R.string.toast_export_success)
} catch (exception: Exception) {
Log.e(TAG, "Failed to export device config", exception)