Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d5aa622 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Merge remote-tracking branch 'upstream/master'

parents 6968294b 28ca3245
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ class FirebaseAuthService : BaseService(TAG, GmsService.FIREBASE_AUTH) {
}

class FirebaseAuthServiceImpl(private val context: Context, private val lifecycle: Lifecycle, private val packageName: String, private val libraryVersion: String?, private val apiKey: String) : IFirebaseAuthService.Stub(), LifecycleOwner {
    private val client = IdentityToolkitClient(context, apiKey)
    private val client by lazy { IdentityToolkitClient(context, apiKey, packageName, PackageUtils.firstSignatureDigestBytes(context, packageName)) }
    private var authorizedDomain: String? = null

    private suspend fun getAuthorizedDomain(): String {
+30 −22
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import com.android.volley.toolbox.Volley
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import org.microg.gms.utils.toHexString
import java.io.UnsupportedEncodingException
import java.lang.RuntimeException
import java.nio.charset.Charset
@@ -29,19 +30,26 @@ import kotlin.coroutines.suspendCoroutine

private const val TAG = "GmsFirebaseAuthClient"

class IdentityToolkitClient(context: Context, private val apiKey: String) {
class IdentityToolkitClient(context: Context, private val apiKey: String, private val packageName: String? = null, private val certSha1Hash: ByteArray? = null) {
    private val queue = Volley.newRequestQueue(context)

    private fun buildRelyingPartyUrl(method: String) = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/$method?key=$apiKey"
    private fun buildStsUrl(method: String) = "https://securetoken.googleapis.com/v1/$method?key=$apiKey"

    private fun getRequestHeaders(): Map<String, String> = hashMapOf<String, String>().apply {
        if (packageName != null) put("X-Android-Package", packageName)
        if (certSha1Hash != null) put("X-Android-Cert", certSha1Hash.toHexString().uppercase())
    }

    private suspend fun request(method: String, data: JSONObject): JSONObject = suspendCoroutine { continuation ->
        queue.add(JsonObjectRequest(POST, buildRelyingPartyUrl(method), data, {
        queue.add(object : JsonObjectRequest(POST, buildRelyingPartyUrl(method), data, {
            continuation.resume(it)
        }, {
            Log.d(TAG, "Error: ${it.networkResponse?.data?.decodeToString() ?: it.message}")
            continuation.resumeWithException(RuntimeException(it))
        }))
        }) {
            override fun getHeaders(): Map<String, String> = getRequestHeaders()
        })
    }

    suspend fun createAuthUri(identifier: String? = null, tenantId: String? = null, continueUri: String? = "http://localhost"): JSONObject =
@@ -117,11 +125,7 @@ class IdentityToolkitClient(context: Context, private val apiKey: String) {
                    .put("sessionInfo", sessionInfo))

    suspend fun getTokenByRefreshToken(refreshToken: String): JSONObject = suspendCoroutine { continuation ->
        queue.add(StsRequest(POST, buildStsUrl("token"), "grant_type=refresh_token&refresh_token=$refreshToken", { continuation.resume(it) }, { continuation.resumeWithException(RuntimeException(it)) }))
    }
}

private class StsRequest(method: Int, url: String, request: String?, listener: (JSONObject) -> Unit, errorListener: (VolleyError) -> Unit) : JsonRequest<JSONObject>(method, url, request, listener, errorListener) {
        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> {
                return try {
                    val jsonString = String(response!!.data, Charset.forName(HttpHeaderParser.parseCharset(response!!.headers, PROTOCOL_CHARSET)))
@@ -136,4 +140,8 @@ private class StsRequest(method: Int, url: String, request: String?, listener: (
            override fun getBodyContentType(): String {
                return "application/x-www-form-urlencoded"
            }

            override fun getHeaders(): Map<String, String> = getRequestHeaders()
        })
    }
}
 No newline at end of file
+32 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2023 microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'signing'

android {
    compileSdkVersion androidCompileSdk
    buildToolsVersion "$androidBuildVersionTools"

    defaultConfig {
        versionName version
        minSdkVersion androidMinSdk
        targetSdkVersion androidTargetSdk
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

apply from: '../gradle/publish-android.gradle'

description = 'microG implementation of play-services-ads-base'

dependencies {
    api project(':play-services-basement')
}
+7 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ SPDX-FileCopyrightText: 2023 microG Project Team
  ~ SPDX-License-Identifier: Apache-2.0
  -->

<manifest package="com.google.android.gms.ads_base"/>
+32 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2023 microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'signing'

android {
    compileSdkVersion androidCompileSdk
    buildToolsVersion "$androidBuildVersionTools"

    defaultConfig {
        versionName version
        minSdkVersion androidMinSdk
        targetSdkVersion androidTargetSdk
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

apply from: '../gradle/publish-android.gradle'

description = 'microG implementation of play-services-ads-identifier'

dependencies {
    api project(':play-services-basement')
}
Loading