Improve NativeDeviceInfoProvider
-- Export unstripped configs -- Simplify code
This commit is contained in:
committed by
Aayush Gupta
parent
33b398cb3b
commit
c6e7166618
@@ -20,16 +20,15 @@ package com.aurora.store.data.providers
|
|||||||
|
|
||||||
import android.app.ActivityManager
|
import android.app.ActivityManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.ContextWrapper
|
import android.content.Context.ACTIVITY_SERVICE
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.text.TextUtils
|
|
||||||
import com.aurora.extensions.isHuawei
|
import com.aurora.extensions.isHuawei
|
||||||
import java.util.Properties
|
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 {
|
val properties = Properties().apply {
|
||||||
//Build Props
|
//Build Props
|
||||||
setProperty("UserReadableName", "${Build.DEVICE}-default")
|
setProperty("UserReadableName", "${Build.DEVICE}-default")
|
||||||
@@ -52,7 +51,7 @@ class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
|
|||||||
setProperty("Build.ID", Build.ID)
|
setProperty("Build.ID", Build.ID)
|
||||||
setProperty("Build.BOOTLOADER", Build.BOOTLOADER)
|
setProperty("Build.BOOTLOADER", Build.BOOTLOADER)
|
||||||
|
|
||||||
val config = applicationContext.resources.configuration
|
val config = context.resources.configuration
|
||||||
setProperty("TouchScreen", "${config.touchscreen}")
|
setProperty("TouchScreen", "${config.touchscreen}")
|
||||||
setProperty("Keyboard", "${config.keyboard}")
|
setProperty("Keyboard", "${config.keyboard}")
|
||||||
setProperty("Navigation", "${config.navigation}")
|
setProperty("Navigation", "${config.navigation}")
|
||||||
@@ -64,12 +63,11 @@ class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
//Display Metrics
|
//Display Metrics
|
||||||
val metrics = applicationContext.resources.displayMetrics
|
val metrics = context.resources.displayMetrics
|
||||||
setProperty("Screen.Density", "${metrics.densityDpi}")
|
setProperty("Screen.Density", "${metrics.densityDpi}")
|
||||||
setProperty("Screen.Width", "${metrics.widthPixels}")
|
setProperty("Screen.Width", "${metrics.widthPixels}")
|
||||||
setProperty("Screen.Height", "${metrics.heightPixels}")
|
setProperty("Screen.Height", "${metrics.heightPixels}")
|
||||||
|
|
||||||
|
|
||||||
//Supported Platforms
|
//Supported Platforms
|
||||||
setProperty("Platforms", Build.SUPPORTED_ABIS.joinToString(separator = ","))
|
setProperty("Platforms", Build.SUPPORTED_ABIS.joinToString(separator = ","))
|
||||||
//Supported Features
|
//Supported Features
|
||||||
@@ -80,7 +78,7 @@ class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
|
|||||||
setProperty("SharedLibraries", getSharedLibraries().joinToString(separator = ","))
|
setProperty("SharedLibraries", getSharedLibraries().joinToString(separator = ","))
|
||||||
//GL Extensions
|
//GL Extensions
|
||||||
val activityManager =
|
val activityManager =
|
||||||
applicationContext.getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
context.getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
||||||
setProperty(
|
setProperty(
|
||||||
"GL.Version",
|
"GL.Version",
|
||||||
activityManager.deviceConfigurationInfo.reqGlEsVersion.toString()
|
activityManager.deviceConfigurationInfo.reqGlEsVersion.toString()
|
||||||
@@ -92,9 +90,11 @@ class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
|
|||||||
|
|
||||||
//Google Related Props
|
//Google Related Props
|
||||||
setProperty("Client", "android-google")
|
setProperty("Client", "android-google")
|
||||||
setProperty("GSF.version", "203615037")
|
|
||||||
setProperty("Vending.version", "82201710")
|
val gsfVersionProvider = NativeGsfVersionProvider(context, isExport)
|
||||||
setProperty("Vending.versionString", "22.0.17-21 [0] [PR] 332555730")
|
setProperty("GSF.version", gsfVersionProvider.gsfVersionCode.toString())
|
||||||
|
setProperty("Vending.version", gsfVersionProvider.vendingVersionCode.toString())
|
||||||
|
setProperty("Vending.versionString", gsfVersionProvider.vendingVersionString)
|
||||||
|
|
||||||
//MISC
|
//MISC
|
||||||
setProperty("Roaming", "mobile-notroaming")
|
setProperty("Roaming", "mobile-notroaming")
|
||||||
@@ -105,51 +105,31 @@ class NativeDeviceInfoProvider(context: Context) : ContextWrapper(context) {
|
|||||||
setProperty("SimOperator", "38")
|
setProperty("SimOperator", "38")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isHuawei())
|
if (isHuawei() && !isExport)
|
||||||
stripHuaweiProperties(properties)
|
stripHuaweiProperties(properties)
|
||||||
|
|
||||||
return properties
|
return properties
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFeatures(): List<String> {
|
private fun getFeatures(): List<String> {
|
||||||
val featureStringList: MutableList<String> = ArrayList()
|
return context
|
||||||
try {
|
.packageManager
|
||||||
val availableFeatures = applicationContext.packageManager.systemAvailableFeatures
|
.systemAvailableFeatures
|
||||||
for (feature in availableFeatures) {
|
?.mapNotNull { it.name } ?: emptyList()
|
||||||
if (feature.name.isNotEmpty()) {
|
|
||||||
featureStringList.add(feature.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return featureStringList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getLocales(): List<String> {
|
private fun getLocales(): List<String> {
|
||||||
val localeList: MutableList<String> = ArrayList()
|
return context
|
||||||
localeList.addAll(listOf(*applicationContext.assets.locales))
|
.assets
|
||||||
val locales: MutableList<String> = ArrayList()
|
.locales
|
||||||
for (locale in localeList) {
|
.mapNotNull { it.replace("-", "_") }
|
||||||
if (TextUtils.isEmpty(locale)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
locales.add(locale.replace("-", "_"))
|
|
||||||
}
|
|
||||||
return locales
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSharedLibraries(): List<String> {
|
private fun getSharedLibraries(): List<String> {
|
||||||
val systemSharedLibraryNames = applicationContext.packageManager.systemSharedLibraryNames
|
return context
|
||||||
val libraries: MutableList<String> = ArrayList()
|
.packageManager
|
||||||
try {
|
.systemSharedLibraryNames
|
||||||
if (systemSharedLibraryNames != null) {
|
?.toList() ?: emptyList()
|
||||||
libraries.addAll(listOf(*systemSharedLibraryNames))
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return libraries
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stripHuaweiProperties(properties: Properties): Properties {
|
private fun stripHuaweiProperties(properties: Properties): Properties {
|
||||||
|
|||||||
@@ -24,53 +24,28 @@ import android.content.pm.PackageManager
|
|||||||
import androidx.core.content.pm.PackageInfoCompat
|
import androidx.core.content.pm.PackageInfoCompat
|
||||||
import com.aurora.store.util.PackageUtil.getPackageInfo
|
import com.aurora.store.util.PackageUtil.getPackageInfo
|
||||||
|
|
||||||
class NativeGsfVersionProvider(context: Context) {
|
class NativeGsfVersionProvider(context: Context, isExport: Boolean = false) {
|
||||||
private var gsfVersionCode = 0L
|
private val GOOGLE_SERVICES_PACKAGE_ID = "com.google.android.gms"
|
||||||
private var vendingVersionCode = 0L
|
private val GOOGLE_VENDING_PACKAGE_ID = "com.android.vending"
|
||||||
private var vendingVersionString = ""
|
|
||||||
|
// 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 {
|
init {
|
||||||
try {
|
try {
|
||||||
val gsfPackageInfo = getPackageInfo(context, GOOGLE_SERVICES_PACKAGE_ID)
|
if (isExport) {
|
||||||
gsfVersionCode = PackageInfoCompat.getLongVersionCode(gsfPackageInfo)
|
getPackageInfo(context, GOOGLE_SERVICES_PACKAGE_ID).let {
|
||||||
} catch (e: PackageManager.NameNotFoundException) {
|
gsfVersionCode = PackageInfoCompat.getLongVersionCode(it)
|
||||||
// com.google.android.gms not found
|
}
|
||||||
|
|
||||||
|
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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class SpoofFragment : BaseFragment<FragmentGenericWithPagerBinding>() {
|
|||||||
|
|
||||||
private fun importDeviceConfig(uri: Uri) {
|
private fun importDeviceConfig(uri: Uri) {
|
||||||
try {
|
try {
|
||||||
context?.contentResolver?.openInputStream(uri)?.use { input ->
|
requireContext().contentResolver?.openInputStream(uri)?.use { input ->
|
||||||
PathUtil.getNewEmptySpoofConfig(requireContext()).outputStream().use {
|
PathUtil.getNewEmptySpoofConfig(requireContext()).outputStream().use {
|
||||||
input.copyTo(it)
|
input.copyTo(it)
|
||||||
}
|
}
|
||||||
@@ -124,8 +124,8 @@ class SpoofFragment : BaseFragment<FragmentGenericWithPagerBinding>() {
|
|||||||
private fun exportDeviceConfig(uri: Uri) {
|
private fun exportDeviceConfig(uri: Uri) {
|
||||||
try {
|
try {
|
||||||
NativeDeviceInfoProvider(requireContext())
|
NativeDeviceInfoProvider(requireContext())
|
||||||
.getNativeDeviceProperties()
|
.getNativeDeviceProperties(true)
|
||||||
.store(context?.contentResolver?.openOutputStream(uri), "DEVICE_CONFIG")
|
.store(requireContext().contentResolver?.openOutputStream(uri), "DEVICE_CONFIG")
|
||||||
toast(R.string.toast_export_success)
|
toast(R.string.toast_export_success)
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
Log.e(TAG, "Failed to export device config", exception)
|
Log.e(TAG, "Failed to export device config", exception)
|
||||||
|
|||||||
Reference in New Issue
Block a user