Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matthew Finkel
fenix
Commits
3b791f39
Commit
3b791f39
authored
Aug 06, 2020
by
Matthew Finkel
Browse files
Bug 40014: Neuter Google Advertising ID
parent
40b142ea
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/build.gradle
View file @
3b791f39
...
...
@@ -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
...
...
app/src/main/java/org/mozilla/fenix/components/metrics/MetricsUtils.kt
View file @
3b791f39
...
...
@@ -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.
...
...
app/src/test/java/org/mozilla/fenix/components/metrics/MetricsUtilsTest.kt
View file @
3b791f39
...
...
@@ -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"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment