Skip to content

Commit

Permalink
Merge branch 'microg:master' into patch-split-install-service
Browse files Browse the repository at this point in the history
  • Loading branch information
ale5000-git authored Mar 21, 2024
2 parents 74c193c + 5a398aa commit 1a8b108
Show file tree
Hide file tree
Showing 130 changed files with 8,117 additions and 363 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ jobs:
echo "Matcher configured: ${NAME:?}"
fi
done
- name: "Execute Gradle build"
run: "./gradlew --no-daemon build"
- name: "Execute Gradle assemble"
run: "./gradlew --no-daemon assemble"
- name: "Execute Gradle check"
run: "./gradlew --no-daemon check"
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def execResult(...args) {
return stdout.toString()
}

def gmsVersion = "23.35.15"
def gmsVersion = "24.09.13"
def gmsVersionCode = Integer.parseInt(gmsVersion.replaceAll('\\.', ''))
def vendingVersion = "37.5.24"
def vendingVersionCode = Integer.parseInt(vendingVersion.replaceAll('\\.', ''))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AppListDatabaseOpenHelper extends SQLiteOpenHelper {
public static final String TABLE_APPLIST = "applist";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_FAKE = "fake";
private static final int DATABASE_VERSION = 2;
private static final int DATABASE_VERSION = 3;
private static final String DROP_APP_LIST_TABLE = "DROP TABLE IF EXISTS " + TABLE_APPLIST;
private static final String CREATE_APP_LIST_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_APPLIST + "(" +
COLUMN_NAME + " VARCHAR(255) PRIMARY KEY, " +
Expand Down
4 changes: 4 additions & 0 deletions fake-signature/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<item>com.mobisoft.morhipo</item>
<item>com.zzkko</item>
<item>com.didilabs.kaavefali</item>
<item>com.airbnb.android</item>
<item>com.mobillium.papara</item>
<item>co.com.fincaraiz.app</item>
<item>com.frisby.frisby</item>
</string-array>
<string-array name="signature_never_fake">
<item>com.truecaller</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ class IdentityToolkitClient(context: Context, private val apiKey: String, privat

suspend fun getTokenByRefreshToken(refreshToken: String): JSONObject = suspendCoroutine { continuation ->
queue.add(object : JsonRequest<JSONObject>(POST, buildStsUrl("token"), "grant_type=refresh_token&refresh_token=$refreshToken", { continuation.resume(it) }, { continuation.resumeWithException(RuntimeException(it)) }) {
override fun parseNetworkResponse(response: NetworkResponse?): Response<JSONObject> {
override fun parseNetworkResponse(response: NetworkResponse): Response<JSONObject> {
return try {
val jsonString = String(response!!.data, Charset.forName(HttpHeaderParser.parseCharset(response!!.headers, PROTOCOL_CHARSET)))
Response.success(JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response))
val jsonString = String(response.data, Charset.forName(HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET)))
Response.success(JSONObject(jsonString), null)
} catch (e: UnsupportedEncodingException) {
Response.error(ParseError(e))
} catch (je: JSONException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.telephony.SmsMessage
import android.text.TextUtils
import android.util.Base64
import android.util.Log
import androidx.core.app.PendingIntentCompat
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.lifecycle.DefaultLifecycleObserver
Expand Down Expand Up @@ -160,7 +161,7 @@ class SmsRetrieverCore(private val context: Context, override val lifecycle: Lif
private fun getTimeoutPendingIntent(context: Context, packageName: String): PendingIntent {
val intent = Intent(ACTION_SMS_RETRIEVE_TIMEOUT)
intent.setPackage(packageName)
return PendingIntent.getBroadcast(context, ++requestCode, intent, PendingIntent.FLAG_IMMUTABLE)
return PendingIntentCompat.getBroadcast(context, ++requestCode, intent, 0, false)!!
}

private fun tryHandleIncomingMessageAsRetrieverMessage(message: SmsMessage): Boolean {
Expand Down
1 change: 1 addition & 0 deletions play-services-base/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {

implementation "androidx.annotation:annotation:$annotationVersion"
implementation "androidx.appcompat:appcompat:$appcompatVersion"
implementation "androidx.core:core-ktx:$coreVersion"
implementation "androidx.lifecycle:lifecycle-service:$lifecycleVersion"
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ package org.microg.gms.profile

import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.XmlResourceParser
import android.net.Uri
import android.os.Bundle
import android.util.Log
import org.microg.gms.settings.SettingsContract
import org.microg.gms.settings.SettingsContract.Profile
Expand All @@ -19,11 +22,13 @@ import kotlin.random.Random

object ProfileManager {
private const val TAG = "ProfileManager"
const val META_DATA_KEY_SOURCE_PACKAGE = "org.microg.gms.profile:source-package"
const val PROFILE_REAL = "real"
const val PROFILE_AUTO = "auto"
const val PROFILE_NATIVE = "native"
const val PROFILE_USER = "user"
const val PROFILE_SYSTEM = "system"
const val PROFILE_REMOTE = "remote"

private var activeProfile: String? = null

Expand Down Expand Up @@ -130,6 +135,17 @@ object ProfileManager {
}
}

private fun getRemoteProfileData(context: Context, packageName: String): Map<String, String> {
val data = mutableMapOf<String, String>()
val cursor = context.contentResolver.query(Uri.parse("content://${packageName}.microg.profile"), null, null, null, null)
cursor?.use {
while (cursor.moveToNext()) {
data[cursor.getString(0)] = cursor.getString(1)
}
}
return data
}

private fun getProfile(context: Context) = getConfiguredProfile(context).let { if (it != PROFILE_AUTO) it else getAutoProfile(context) }
private fun getSerialFromSettings(context: Context): String? = SettingsContract.getSettings(context, Profile.getContentUri(context), arrayOf(Profile.SERIAL)) { it.getString(0) }
private fun saveSerial(context: Context, serial: String) = SettingsContract.setSettings(context, Profile.getContentUri(context)) { put(Profile.SERIAL, serial) }
Expand Down Expand Up @@ -302,6 +318,17 @@ object ProfileManager {
activeProfile = profile
}

private fun applyRemoteProfile(context: Context, packageName: String) {
val profileData = getRemoteProfileData(context, packageName)
if (Log.isLoggable(TAG, Log.VERBOSE)) {
for ((key, value) in profileData) {
Log.v(TAG, "<data key=\"$key\" value=\"$value\" />")
}
}
applyProfileData(profileData)
activeProfile = PROFILE_REMOTE
}

fun getProfileName(context: Context, profile: String): String? = getProfileName { getProfileXml(context, profile) }

private fun getProfileName(parserCreator: () -> XmlResourceParser?): String? {
Expand Down Expand Up @@ -352,14 +379,23 @@ object ProfileManager {

@JvmStatic
fun ensureInitialized(context: Context) {
val metaData = runCatching { context.packageManager.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA).metaData }.getOrNull() ?: Bundle.EMPTY
synchronized(this) {
try {
val profile = getProfile(context)
if (activeProfile == profile) return
applyProfile(context, profile)
if (metaData.containsKey(META_DATA_KEY_SOURCE_PACKAGE)) {
if (activeProfile != PROFILE_REMOTE) {
val packageName = metaData.getString(META_DATA_KEY_SOURCE_PACKAGE)!!
applyRemoteProfile(context, packageName)
}
} else {
val profile = getProfile(context)
if (activeProfile == profile) return
applyProfile(context, profile)
}
} catch (e: Exception) {
Log.w(TAG, e)
}
Unit
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ package org.microg.gms.settings

import android.content.ContentValues
import android.content.Context
import android.content.pm.PackageManager
import android.database.Cursor
import android.net.Uri
import android.os.Binder
import android.os.Bundle

object SettingsContract {
fun getAuthority(context: Context) = "${context.packageName}.microg.settings"
const val META_DATA_KEY_SOURCE_PACKAGE = "org.microg.gms.settings:source-package"
fun getAuthority(context: Context): String {
val metaData = runCatching { context.packageManager.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA).metaData }.getOrNull() ?: Bundle.EMPTY
val sourcePackage = metaData.getString(META_DATA_KEY_SOURCE_PACKAGE, context.packageName)
return "${sourcePackage}.microg.settings"
}
fun getAuthorityUri(context: Context): Uri = Uri.parse("content://${getAuthority(context)}")

object CheckIn {
Expand Down Expand Up @@ -179,9 +186,11 @@ object SettingsContract {
fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"

const val LICENSING = "vending_licensing"
const val BILLING = "vending_billing"

val PROJECTION = arrayOf(
LICENSING
LICENSING,
BILLING,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ class SettingsProvider : ContentProvider() {
private fun queryVending(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key ->
when (key) {
Vending.LICENSING -> getSettingsBoolean(key, false)
Vending.BILLING -> getSettingsBoolean(key, false)
else -> throw IllegalArgumentException("Unknown key: $key")
}
}
Expand All @@ -353,6 +354,7 @@ class SettingsProvider : ContentProvider() {
values.valueSet().forEach { (key, value) ->
when (key) {
Vending.LICENSING -> editor.putBoolean(key, value as Boolean)
Vending.BILLING -> editor.putBoolean(key, value as Boolean)
else -> throw IllegalArgumentException("Unknown key: $key")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ package org.microg.gms.utils

import android.app.AlarmManager
import android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP
import android.app.PendingIntent
import android.app.PendingIntent.FLAG_NO_CREATE
import android.app.PendingIntent.FLAG_MUTABLE
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
import android.app.Service
import android.content.Context
Expand All @@ -18,6 +16,7 @@ import android.os.Build.VERSION.SDK_INT
import android.os.Parcelable
import android.os.SystemClock
import android.util.Log
import androidx.core.app.PendingIntentCompat
import androidx.core.content.getSystemService
import java.util.UUID

Expand All @@ -29,7 +28,7 @@ class IntentCacheManager<S : Service, T : Parcelable>(private val context: Conte
private val pendingActions: MutableList<() -> Unit> = arrayListOf()

init {
val pendingIntent = PendingIntent.getService(context, type, getIntent(), if (SDK_INT >= 31) FLAG_MUTABLE else 0)
val pendingIntent = PendingIntentCompat.getService(context, type, getIntent(), 0, true)!!
val alarmManager = context.getSystemService<AlarmManager>()
if (SDK_INT >= 19) {
alarmManager?.setWindow(ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + TEN_YEARS, -1, pendingIntent)
Expand Down Expand Up @@ -116,7 +115,7 @@ class IntentCacheManager<S : Service, T : Parcelable>(private val context: Conte
putExtra(EXTRA_ID, id)
putParcelableArrayListExtra(EXTRA_DATA, content)
}
val pendingIntent = PendingIntent.getService(context, type, intent, FLAG_NO_CREATE or FLAG_UPDATE_CURRENT or if (SDK_INT >= 31) FLAG_MUTABLE else 0)
val pendingIntent = PendingIntentCompat.getService(context, type, intent, FLAG_NO_CREATE or FLAG_UPDATE_CURRENT, true)
if (pendingIntent == null) {
Log.w(TAG, "Failed to update existing pending intent, will likely have a loss of information")
}
Expand Down
6 changes: 6 additions & 0 deletions play-services-core/src/huawei/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@
<meta-data
android:name="org.microg.gms.settings.safetynet_enabled"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.vending_billing"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.vending_licensing"
android:value="true" />
</application>
</manifest>
6 changes: 6 additions & 0 deletions play-services-core/src/huaweilh/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<meta-data
android:name="org.microg.gms.settings.safetynet_enabled"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.vending_billing"
android:value="true" />
<meta-data
android:name="org.microg.gms.settings.vending_licensing"
android:value="true" />

<activity-alias
android:name="org.microg.gms.ui.SettingsActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.microg.gms.ui

import android.accounts.AccountManager
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.view.View
import androidx.core.content.ContextCompat
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import com.google.android.gms.R
import org.microg.gms.auth.AuthConstants

class AccountsFragment : PreferenceFragmentCompat() {

private val TAG = AccountsFragment::class.java.simpleName

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preferences_accounts)

val accountManager = AccountManager.get(requireContext())
val accounts = accountManager.getAccountsByType(AuthConstants.DEFAULT_ACCOUNT_TYPE)

findPreference<Preference>("pref_current_accounts_none")?.isVisible = accounts.isEmpty()
val preferenceCategory = findPreference<PreferenceCategory>("prefcat_current_accounts")
accounts.forEach {
Preference(requireContext()).apply {
title = it.name
icon = ContextCompat.getDrawable(
requireContext(),
R.drawable.proprietary_auth_gls_ic_google_minitab_selected
)
preferenceCategory?.addPreference(this)
}
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

findPreference<Preference>("pref_manage_accounts")?.setOnPreferenceClickListener {
try {
startActivity(Intent(Settings.ACTION_SYNC_SETTINGS))
} catch (activityNotFoundException: ActivityNotFoundException) {
Log.e(TAG, "Failed to launch sync settings", activityNotFoundException)
}
true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.content.Context
import android.content.Intent
import android.os.Parcel
import android.util.Log
import androidx.core.app.PendingIntentCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -51,10 +52,10 @@ class GamesConnectServiceImpl(val context: Context, override val lifecycle: Life
override fun signIn(callback: IGamesConnectCallbacks?, request: GamesSignInRequest?) {
Log.d(TAG, "signIn($request)")
fun sendSignInRequired() {
val resolution = PendingIntent.getActivity(context, packageName.hashCode(), Intent(context, GamesSignInActivity::class.java).apply {
val resolution = PendingIntentCompat.getActivity(context, packageName.hashCode(), Intent(context, GamesSignInActivity::class.java).apply {
putExtra(EXTRA_GAME_PACKAGE_NAME, packageName)
putExtra(EXTRA_SCOPES, arrayOf(Scopes.GAMES_LITE))
}, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
}, PendingIntent.FLAG_UPDATE_CURRENT, false)
when (request?.signInType) {
0 -> { // Manual sign in, provide resolution
callback?.onSignIn(Status(CommonStatusCodes.SIGN_IN_REQUIRED, null, resolution), null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.os.Bundle
import android.os.IBinder
import android.os.Parcel
import android.util.Log
import androidx.core.app.PendingIntentCompat
import androidx.core.os.bundleOf
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
Expand Down Expand Up @@ -55,15 +56,16 @@ class GamesService : BaseService(TAG, GmsService.GAMES) {
Log.d(TAG, "Sending SIGN_IN_REQUIRED to $packageName")
callback.onPostInitCompleteWithConnectionInfo(ConnectionResult.SIGN_IN_REQUIRED, null, ConnectionInfo().apply {
params = bundleOf(
"pendingIntent" to PendingIntent.getActivity(
"pendingIntent" to PendingIntentCompat.getActivity(
this@GamesService,
packageName.hashCode(),
Intent(this@GamesService, GamesSignInActivity::class.java).apply {
putExtra(EXTRA_GAME_PACKAGE_NAME, request.packageName)
putExtra(EXTRA_ACCOUNT, request.account)
putExtra(EXTRA_SCOPES, request.scopes)
},
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
PendingIntent.FLAG_UPDATE_CURRENT,
false
)
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PhenotypeService : BaseService(TAG, GmsService.PHENOTYPE) {
class PhenotypeServiceImpl(val packageName: String?) : IPhenotypeService.Stub() {
override fun register(callbacks: IPhenotypeCallbacks, packageName: String?, version: Int, p3: Array<out String>?, p4: ByteArray?) {
Log.d(TAG, "register($packageName, $version, $p3, $p4)")
callbacks.onRegistered(Status.SUCCESS)
callbacks.onRegistered(if (version != 0) Status.SUCCESS else Status.CANCELED)
}

override fun weakRegister(callbacks: IPhenotypeCallbacks, packageName: String?, version: Int, p3: Array<out String>?, p4: IntArray?, p5: ByteArray?) {
Expand Down
Loading

0 comments on commit 1a8b108

Please sign in to comment.