GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 64e242e1 authored by Matthew Finkel's avatar Matthew Finkel Committed by Alex Catarineu
Browse files

Bug 40014: Neuter Google Advertising ID

parent 6c6502db
...@@ -440,8 +440,6 @@ dependencies { ...@@ -440,8 +440,6 @@ dependencies {
implementation Deps.adjust implementation Deps.adjust
implementation Deps.installreferrer // Required by 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 implementation Deps.google_play_store // Required for in-app reviews
androidTestImplementation Deps.uiautomator androidTestImplementation Deps.uiautomator
......
...@@ -7,9 +7,6 @@ package org.mozilla.fenix.components.metrics ...@@ -7,9 +7,6 @@ package org.mozilla.fenix.components.metrics
import android.content.Context import android.content.Context
import android.util.Base64 import android.util.Base64
import androidx.annotation.VisibleForTesting 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.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import mozilla.components.browser.search.SearchEngine import mozilla.components.browser.search.SearchEngine
...@@ -82,14 +79,8 @@ object MetricsUtils { ...@@ -82,14 +79,8 @@ object MetricsUtils {
*/ */
@Suppress("TooGenericExceptionCaught") @Suppress("TooGenericExceptionCaught")
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal fun getAdvertisingID(context: Context): String? { internal fun getAdvertisingID(@Suppress("UNUSED_PARAMETER") context: Context): String? {
return try { 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 null
} catch (e: IllegalStateException) { } catch (e: IllegalStateException) {
// This is unlikely to happen, as this should be running off the main thread. // This is unlikely to happen, as this should be running off the main thread.
......
...@@ -2,67 +2,25 @@ package org.mozilla.fenix.components.metrics ...@@ -2,67 +2,25 @@ package org.mozilla.fenix.components.metrics
import android.content.Context import android.content.Context
import android.util.Base64 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.every
import io.mockk.mockk import io.mockk.mockk
import io.mockk.mockkObject import io.mockk.mockkObject
import io.mockk.mockkStatic import io.mockk.mockkStatic
import io.mockk.slot import io.mockk.slot
import io.mockk.unmockkStatic
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Test import org.junit.Test
import java.io.IOException
class MetricsUtilsTest { class MetricsUtilsTest {
private val context: Context = mockk(relaxed = true) 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 @Test
fun `getAdvertisingID() returns null if the API returns null info`() { fun `getAdvertisingID() returns null if the API returns null info`() {
mockkStatic(AdvertisingIdClient::class)
every { AdvertisingIdClient.getAdvertisingIdInfo(any()) } returns null
assertNull(MetricsUtils.getAdvertisingID(context)) 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 @Test
fun `getHashedIdentifier() returns a hashed identifier`() { fun `getHashedIdentifier() returns a hashed identifier`() {
val testId = "test-value-id" val testId = "test-value-id"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment