Commit 3b791f39 authored by Matthew Finkel's avatar Matthew Finkel
Browse files

Bug 40014: Neuter Google Advertising ID

parent 40b142ea
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -465,8 +465,6 @@ dependencies {
    implementation Deps.adjust
    implementation Deps.installreferrer // Required by Adjust

    implementation Deps.google_ads_id // Required for the Google Advertising ID

    implementation Deps.google_play_store // Required for in-app reviews

    androidTestImplementation Deps.uiautomator
+1 −10
Original line number Diff line number Diff line
@@ -7,9 +7,6 @@ package org.mozilla.fenix.components.metrics
import android.content.Context
import android.util.Base64
import androidx.annotation.VisibleForTesting
import com.google.android.gms.ads.identifier.AdvertisingIdClient
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
import com.google.android.gms.common.GooglePlayServicesRepairableException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import mozilla.components.browser.search.SearchEngine
@@ -82,14 +79,8 @@ object MetricsUtils {
     */
    @Suppress("TooGenericExceptionCaught")
    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
    internal fun getAdvertisingID(context: Context): String? {
    internal fun getAdvertisingID(@Suppress("UNUSED_PARAMETER") context: Context): String? {
        return try {
            AdvertisingIdClient.getAdvertisingIdInfo(context).id
        } catch (e: GooglePlayServicesNotAvailableException) {
            Logger.debug("ActivationPing - Google Play not installed on the device")
            null
        } catch (e: GooglePlayServicesRepairableException) {
            Logger.debug("ActivationPing - recoverable error connecting to Google Play Services")
            null
        } catch (e: IllegalStateException) {
            // This is unlikely to happen, as this should be running off the main thread.
+0 −42
Original line number Diff line number Diff line
@@ -2,67 +2,25 @@ package org.mozilla.fenix.components.metrics

import android.content.Context
import android.util.Base64
import com.google.android.gms.ads.identifier.AdvertisingIdClient
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
import com.google.android.gms.common.GooglePlayServicesRepairableException
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.slot
import io.mockk.unmockkStatic
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import java.io.IOException

class MetricsUtilsTest {

    private val context: Context = mockk(relaxed = true)

    @Test
    fun `getAdvertisingID() returns null if the API throws`() {
        mockkStatic("com.google.android.gms.ads.identifier.AdvertisingIdClient")

        val exceptions = listOf(
            GooglePlayServicesNotAvailableException(1),
            GooglePlayServicesRepairableException(0, "", mockk()),
            IllegalStateException(),
            IOException()
        )

        exceptions.forEach {
            every {
                AdvertisingIdClient.getAdvertisingIdInfo(any())
            } throws it

            assertNull(MetricsUtils.getAdvertisingID(context))
        }

        unmockkStatic("com.google.android.gms.ads.identifier.AdvertisingIdClient")
    }

    @Test
    fun `getAdvertisingID() returns null if the API returns null info`() {
        mockkStatic(AdvertisingIdClient::class)
        every { AdvertisingIdClient.getAdvertisingIdInfo(any()) } returns null

        assertNull(MetricsUtils.getAdvertisingID(context))
    }

    @Test
    fun `getAdvertisingID() returns a valid string if the API returns a valid ID`() {
        val testId = "test-value-id"

        mockkStatic(AdvertisingIdClient::class)
        every {
            AdvertisingIdClient.getAdvertisingIdInfo(any())
        } returns AdvertisingIdClient.Info(testId, false)

        assertEquals(testId, MetricsUtils.getAdvertisingID(context))
    }

    @Test
    fun `getHashedIdentifier() returns a hashed identifier`() {
        val testId = "test-value-id"