Commit 9c3b683b authored by brizental's avatar brizental Committed by Pier Angelo Vendrame
Browse files

BB 45085: [android] Confine GooglePlayIntegrityClient to Components.kt

parent 590bfd6c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -595,7 +595,7 @@ open class FenixApplication : Application(), Provider, ThemeProvider {
        }
        runOnVisualCompleteness(queue) {
            GlobalScope.launch(IO) {
                components.integrityClient.warmUp()
                components.warmUpIntegrityClient()
            }
        }
    }
+8 −3
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ package org.mozilla.fenix.components
import android.content.Context
import android.content.SharedPreferences
import androidx.core.content.edit
import mozilla.components.lib.integrity.googleplay.RequestHashProvider
import mozilla.components.lib.llm.mlpa.UserIdProvider
import mozilla.components.lib.llm.mlpa.service.UserId
import mozilla.components.support.ktx.kotlin.toHexString
@@ -39,9 +38,15 @@ fun interface Hasher {

/**
 * Generates and persists a stable per-install UUID, used to identify this client
 * consistently across [UserIdProvider] and [RequestHashProvider] consumers.
 * consistently across [UserIdProvider] consumers and other callers that need a
 * stable per-request hash derived from that UUID.
 */
interface ClientUUID : UserIdProvider, RequestHashProvider {
interface ClientUUID : UserIdProvider {
    /**
     * Generates a hash derived from the client's stable UUID.
     */
    fun generateHash(): String

    companion object {
        /**
         * Convenience initializer that creates a [SharedPreferences] to be used by [ClientUUID].
+16 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import kotlinx.coroutines.MainScope
import kotlinx.coroutines.SupervisorJob
import mozilla.components.concept.ai.controls.AIFeatureBlock
import mozilla.components.concept.ai.controls.AIFeatureRegistry
import mozilla.components.concept.integrity.IntegrityClient
import mozilla.components.feature.addons.AddonManager
import mozilla.components.feature.addons.amo.AMOAddonsProvider
import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker
@@ -32,6 +33,8 @@ import mozilla.components.lib.ai.controls.default
import mozilla.components.lib.crash.store.CrashAction
import mozilla.components.lib.crash.store.CrashMiddleware
import mozilla.components.lib.integrity.googleplay.GooglePlayIntegrityClient
import mozilla.components.lib.integrity.googleplay.IntegrityConsumer
import mozilla.components.lib.integrity.googleplay.RequestHashProvider
import mozilla.components.lib.llm.mlpa.MlpaTokenStorage
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
import mozilla.components.service.fxrelay.eligibility.RelayEligibilityStore
@@ -432,14 +435,25 @@ class Components(private val context: Context) {
        )
    }

    val integrityClient by lazyMonitored {
    private val googlePlayIntegrityClient by lazyMonitored {
        GooglePlayIntegrityClient.create(
            context = context,
            projectNumberToken = BuildConfig.GPS_INTEGRITY_TOKEN,
            requestHashProvider = clientUUID,
            requestHashProvider = RequestHashProvider { clientUUID.generateHash() },
        )
    }

    val integrityClient: IntegrityClient by lazyMonitored {
        googlePlayIntegrityClient.forConsumer(IntegrityConsumer.Summarize)
    }

    /**
     * Eagerly initializes the underlying Play Integrity token provider. This is exposed
     * separately from [integrityClient] because warm-up is specific to the Google
     * Play-backed implementation and isn't part of the [IntegrityClient] concept.
     */
    suspend fun warmUpIntegrityClient(): Boolean = googlePlayIntegrityClient.warmUp()

    val termsOfUsePromptRepository by lazyMonitored {
        DefaultTermsOfUsePromptRepository(settings)
    }
+3 −4
Original line number Diff line number Diff line
@@ -5,8 +5,7 @@
package org.mozilla.fenix.components.llm

import mozilla.components.concept.fetch.Client
import mozilla.components.lib.integrity.googleplay.GooglePlayIntegrityClient
import mozilla.components.lib.integrity.googleplay.IntegrityConsumer
import mozilla.components.concept.integrity.IntegrityClient
import mozilla.components.lib.llm.mlpa.MlpaLlmProvider
import mozilla.components.lib.llm.mlpa.MlpaTokenProvider
import mozilla.components.lib.llm.mlpa.MlpaTokenStorage
@@ -25,7 +24,7 @@ class Llm(
    private val client: Client,
    private val storage: MlpaTokenStorage,
    private val fxaTokenProvider: FxaAccessTokenProvider,
    private val integrityClient: GooglePlayIntegrityClient,
    private val integrityClient: IntegrityClient,
    private val userIdProvider: UserIdProvider,
) {

@@ -36,7 +35,7 @@ class Llm(
            MlpaTokenProvider.choose(
                MlpaTokenProvider.fxaTokenProvider(fxaTokenProvider),
                MlpaTokenProvider.mlpaIntegrityHandshake(
                    integrityClient = integrityClient.forConsumer(IntegrityConsumer.Summarize),
                    integrityClient = integrityClient,
                    authenticationService = fenixMlpaService,
                    userIdProvider = userIdProvider,
                    storage = storage,