diff --git a/play-services-base-core/src/main/kotlin/org/microg/gms/profile/Build.kt b/play-services-base-core/src/main/kotlin/org/microg/gms/profile/Build.kt index c3cb8853..c13a4d5a 100644 --- a/play-services-base-core/src/main/kotlin/org/microg/gms/profile/Build.kt +++ b/play-services-base-core/src/main/kotlin/org/microg/gms/profile/Build.kt @@ -90,5 +90,8 @@ object Build { @JvmField var SDK_INT: Int = 0 + + @JvmField + var SECURITY_PATCH: String? = null } } diff --git a/play-services-base-core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt b/play-services-base-core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt index 493f8bd0..89251a9b 100644 --- a/play-services-base-core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt +++ b/play-services-base-core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt @@ -6,12 +6,12 @@ package org.microg.gms.profile import android.annotation.SuppressLint -import android.content.ContentValues import android.content.Context import android.util.Log import org.microg.gms.settings.SettingsContract import org.microg.gms.settings.SettingsContract.Profile import org.xmlpull.v1.XmlPullParser +import java.util.* import kotlin.random.Random object ProfileManager { @@ -24,18 +24,18 @@ object ProfileManager { private fun getProfileFromSettings(context: Context) = SettingsContract.getSettings(context, Profile.getContentUri(context), arrayOf(Profile.PROFILE)) { it.getString(0) } private fun getAutoProfile(context: Context): String { - val profile = "${android.os.Build.DEVICE}_${android.os.Build.VERSION.SDK_INT}" + val profile = "${android.os.Build.PRODUCT}_${android.os.Build.VERSION.SDK_INT}" if (hasProfile(context, profile)) return profile return PROFILE_NATIVE } - private fun getProfileResId(context: Context, profile: String) = context.resources.getIdentifier("${context.packageName}:xml/profile_$profile", null, null) + private fun getProfileResId(context: Context, profile: String) = context.resources.getIdentifier("${context.packageName}:xml/profile_$profile".toLowerCase(Locale.US), null, null) private fun hasProfile(context: Context, profile: String): Boolean = getProfileResId(context, profile) != 0 - private fun getProfileData(context: Context, profile: String, realData: Map): Map? { + private fun getProfileData(context: Context, profile: String, realData: Map): Map { try { - if (profile in listOf(PROFILE_REAL, PROFILE_NATIVE)) return null + if (profile in listOf(PROFILE_REAL, PROFILE_NATIVE)) return realData val profileResId = getProfileResId(context, profile) - if (profileResId == 0) return null + if (profileResId == 0) return realData val resultData = mutableMapOf() resultData.putAll(realData) context.resources.getXml(profileResId).use { @@ -54,13 +54,10 @@ object ProfileManager { next = it.next() } } - for (entry in resultData) { - Log.d(TAG, "") - } return resultData } catch (e: Exception) { Log.w(TAG, e) - return null + return realData } } @@ -88,13 +85,16 @@ object ProfileManager { private fun getProfileSerialTemplate(context: Context, profile: String): String { // Native if (profile in listOf(PROFILE_REAL, PROFILE_NATIVE)) { - return kotlin.runCatching { + var candidate = try { if (android.os.Build.VERSION.SDK_INT >= 26) { android.os.Build.getSerial() } else { - null + android.os.Build.SERIAL } - }.getOrNull()?.takeIf { it != android.os.Build.UNKNOWN } ?: android.os.Build.SERIAL + } catch (e: Exception) { + android.os.Build.SERIAL + } + if (candidate != android.os.Build.UNKNOWN) return candidate } // From profile @@ -160,9 +160,12 @@ object ProfileManager { "Build.VERSION.SDK" to android.os.Build.VERSION.SDK, "Build.VERSION.SDK_INT" to android.os.Build.VERSION.SDK_INT.toString() ).apply { - if (android.os.Build.VERSION.SDK_INT > 21) { + if (android.os.Build.VERSION.SDK_INT >= 21) { put("Build.SUPPORTED_ABIS", android.os.Build.SUPPORTED_ABIS.joinToString(",")) } + if (android.os.Build.VERSION.SDK_INT >= 23) { + put("Build.VERSION.SECURITY_PATCH", android.os.Build.VERSION.SECURITY_PATCH) + } } private fun applyProfileData(profileData: Map) { @@ -195,8 +198,15 @@ object ProfileManager { applyStringField("Build.VERSION.RELEASE") { Build.VERSION.RELEASE = it } applyStringField("Build.VERSION.SDK") { Build.VERSION.SDK = it } applyIntField("Build.VERSION.SDK_INT") { Build.VERSION.SDK_INT = it } - if (android.os.Build.VERSION.SDK_INT > 21) { + if (android.os.Build.VERSION.SDK_INT >= 21) { Build.SUPPORTED_ABIS = profileData["Build.SUPPORTED_ABIS"]?.split(",")?.toTypedArray() ?: emptyArray() + } else { + Build.SUPPORTED_ABIS = emptyArray() + } + if (android.os.Build.VERSION.SDK_INT >= 23) { + Build.VERSION.SECURITY_PATCH = profileData["Build.VERSION.SECURITY_PATCH"] + } else { + Build.VERSION.SECURITY_PATCH = null } } @@ -217,15 +227,15 @@ object ProfileManager { @JvmStatic fun ensureInitialized(context: Context) { - if (initialized) return - try { - val profile = getActiveProfile(context) - applyProfile(context, profile) - initialized = true - } catch (e: Exception) { - Log.w(TAG, e) + synchronized(this) { + if (initialized) return + try { + val profile = getActiveProfile(context) + applyProfile(context, profile) + initialized = true + } catch (e: Exception) { + Log.w(TAG, e) + } } } - - } diff --git a/play-services-core/src/main/res/xml/profile_bullhead_27.xml b/play-services-core/src/main/res/xml/profile_bullhead_27.xml index 66d1a94e..5621421e 100644 --- a/play-services-core/src/main/res/xml/profile_bullhead_27.xml +++ b/play-services-core/src/main/res/xml/profile_bullhead_27.xml @@ -3,7 +3,7 @@ ~ SPDX-FileCopyrightText: 2021, microG Project Team ~ SPDX-License-Identifier: Apache-2.0 --> - +