Skip to content

Commit 088dd73

Browse files
aitorvsmalmstein
andauthored
Move pixel API to its own gradle lib module (#1103)
* Moved statistics package to its own module * Added dagger as implementation to use Inject annotations * Added common gradle module and moved WorkerInjectorPlugin to it * Moved AppUrl to common module and fix pixel service and entity * Moved Device.kt to common module and fix VERSION_NAME access * Moved exception package to common module * Removed default Build.VERSION_NAME from UncaughtExceptionEntity * Fixed the AppInstallationReferrerStateListener<>AtbInitializer dependency * Fixed tests * Added test runner to common and statistics manifest * Added dummy tests for CI * added jUnit to refreshVersions * Reverted change in RxPixelSenderTest as it stayed in the :app module * Changed compileSdkVersion and targetSdkVersion to 29 in :common and :statistics and extracted common lib gradle config Co-authored-by: David Gonzalez <[email protected]>
1 parent 2f55588 commit 088dd73

File tree

53 files changed

+430
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+430
-68
lines changed

app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ ext {
1111
}
1212

1313
android {
14-
compileSdkVersion 29
14+
compileSdkVersion compile_sdk
1515
ndkVersion '21.0.6113669'
1616
defaultConfig {
1717
applicationId "com.duckduckgo.mobile.android"
18-
minSdkVersion 21
19-
targetSdkVersion 29
18+
minSdkVersion min_sdk
19+
targetSdkVersion target_sdk
2020
versionCode buildVersionCode()
2121
versionName buildVersionName()
2222
testInstrumentationRunner "com.duckduckgo.app.TestRunner"
@@ -96,6 +96,9 @@ android {
9696
}
9797

9898
dependencies {
99+
implementation project(path: ':statistics')
100+
implementation project(path: ':common')
101+
99102
implementation AndroidX.legacy.supportV4
100103
debugImplementation Square.leakCanary.android
101104

@@ -174,9 +177,6 @@ dependencies {
174177
// Lottie
175178
implementation "com.airbnb.android:lottie:_"
176179

177-
// Apache commons
178-
implementation "org.apache.commons:commons-math3:_"
179-
180180
// Play Store referrer library
181181
implementation("com.android.installreferrer:installreferrer:_")
182182

app/src/androidTest/java/com/duckduckgo/app/di/StubStatisticsModule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package com.duckduckgo.app.di
1919
import android.content.Context
2020
import com.duckduckgo.app.global.device.ContextDeviceInfo
2121
import com.duckduckgo.app.global.device.DeviceInfo
22-
import com.duckduckgo.app.referral.AppInstallationReferrerStateListener
2322
import com.duckduckgo.app.statistics.AtbInitializer
23+
import com.duckduckgo.app.statistics.AtbInitializerListener
2424
import com.duckduckgo.app.statistics.api.PixelSender
2525
import com.duckduckgo.app.statistics.api.StatisticsService
2626
import com.duckduckgo.app.statistics.api.StatisticsUpdater
@@ -84,9 +84,9 @@ class StubStatisticsModule {
8484
fun atbInitializer(
8585
statisticsDataStore: StatisticsDataStore,
8686
statisticsUpdater: StatisticsUpdater,
87-
appReferrerStateListener: AppInstallationReferrerStateListener
87+
listeners: Set<@JvmSuppressWildcards AtbInitializerListener>
8888
): AtbInitializer {
89-
return AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
89+
return AtbInitializer(statisticsDataStore, statisticsUpdater, listeners)
9090
}
9191

9292
@Provides

app/src/androidTest/java/com/duckduckgo/app/global/exception/UncaughtExceptionDaoTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class UncaughtExceptionDaoTest {
7777

7878
@Test
7979
fun whenSeveralExceptionExistAndOneDeletedThenCorrectEntryIsRemoved() {
80-
val exception1 = UncaughtExceptionEntity(id = 1, exceptionSource = GLOBAL, message = "foo1")
81-
val exception2 = UncaughtExceptionEntity(id = 2, exceptionSource = ON_PROGRESS_CHANGED, message = "foo2")
82-
val exception3 = UncaughtExceptionEntity(id = 3, exceptionSource = ON_PAGE_STARTED, message = "foo3")
80+
val exception1 = UncaughtExceptionEntity(id = 1, exceptionSource = GLOBAL, message = "foo1", "version")
81+
val exception2 = UncaughtExceptionEntity(id = 2, exceptionSource = ON_PROGRESS_CHANGED, message = "foo2", "version")
82+
val exception3 = UncaughtExceptionEntity(id = 3, exceptionSource = ON_PAGE_STARTED, message = "foo3", "version")
8383
dao.add(exception1)
8484
dao.add(exception2)
8585
dao.add(exception3)
@@ -102,7 +102,7 @@ class UncaughtExceptionDaoTest {
102102

103103
@Test
104104
fun whenExceptionRetrievedFromDatabaseThenAllDetailsRestored() {
105-
val exception = UncaughtExceptionEntity(id = 1, exceptionSource = GLOBAL, message = "foo")
105+
val exception = UncaughtExceptionEntity(id = 1, exceptionSource = GLOBAL, message = "foo", "version")
106106
dao.add(exception)
107107
val list = dao.all()
108108
assertEquals(1, list.size)
@@ -116,5 +116,5 @@ class UncaughtExceptionDaoTest {
116116
}
117117

118118
private fun anUncaughtExceptionEntity(id: Long? = null) =
119-
UncaughtExceptionEntity(id = id ?: 0, exceptionSource = GLOBAL, message = "foo")
119+
UncaughtExceptionEntity(id = id ?: 0, exceptionSource = GLOBAL, message = "foo", "version")
120120
}

app/src/androidTest/java/com/duckduckgo/app/referral/StubAppReferrerFoundStateListener.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
package com.duckduckgo.app.referral
1818

19+
import com.duckduckgo.app.statistics.AtbInitializerListener
1920
import kotlinx.coroutines.delay
2021

21-
class StubAppReferrerFoundStateListener(private val referrer: String, private val mockDelayMs: Long = 0) : AppInstallationReferrerStateListener {
22+
class StubAppReferrerFoundStateListener(
23+
private val referrer: String,
24+
private val mockDelayMs: Long = 0
25+
) : AppInstallationReferrerStateListener, AtbInitializerListener {
2226
override suspend fun waitForReferrerCode(): ParsedReferrerResult {
2327
if (mockDelayMs > 0) delay(mockDelayMs)
2428

@@ -27,4 +31,12 @@ class StubAppReferrerFoundStateListener(private val referrer: String, private va
2731

2832
override fun initialiseReferralRetrieval() {
2933
}
34+
35+
override suspend fun beforeAtbInit() {
36+
waitForReferrerCode()
37+
}
38+
39+
override fun beforeAtbInitTimeoutMillis(): Long {
40+
return mockDelayMs
41+
}
3042
}

app/src/androidTest/java/com/duckduckgo/app/statistics/AtbInitializerTest.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.duckduckgo.app.statistics
1818

19-
import com.duckduckgo.app.referral.AppInstallationReferrerStateListener
2019
import com.duckduckgo.app.referral.StubAppReferrerFoundStateListener
2120
import com.duckduckgo.app.statistics.api.StatisticsUpdater
2221
import com.duckduckgo.app.statistics.store.StatisticsDataStore
@@ -34,15 +33,15 @@ class AtbInitializerTest {
3433

3534
private val statisticsDataStore: StatisticsDataStore = mock()
3635
private val statisticsUpdater: StatisticsUpdater = mock()
37-
private lateinit var appReferrerStateListener: AppInstallationReferrerStateListener
36+
private lateinit var appReferrerStateListener: AtbInitializerListener
3837

3938
@Test
4039
fun whenReferrerInformationInstantlyAvailableThenAtbInitialized() = runBlockingTest {
4140
whenever(statisticsDataStore.hasInstallationStatistics).thenReturn(false)
4241
appReferrerStateListener = StubAppReferrerFoundStateListener(referrer = "xx")
43-
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
42+
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, setOf(appReferrerStateListener))
4443

45-
testee.initializeAfterReferrerAvailable()
44+
testee.initialize()
4645

4746
verify(statisticsUpdater).initializeAtb()
4847
}
@@ -51,9 +50,9 @@ class AtbInitializerTest {
5150
fun whenReferrerInformationQuicklyAvailableThenAtbInitialized() = runBlockingTest {
5251
whenever(statisticsDataStore.hasInstallationStatistics).thenReturn(false)
5352
appReferrerStateListener = StubAppReferrerFoundStateListener(referrer = "xx", mockDelayMs = 1000L)
54-
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
53+
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, setOf(appReferrerStateListener))
5554

56-
testee.initializeAfterReferrerAvailable()
55+
testee.initialize()
5756

5857
verify(statisticsUpdater).initializeAtb()
5958
}
@@ -62,19 +61,19 @@ class AtbInitializerTest {
6261
fun whenReferrerInformationTimesOutThenAtbInitialized() = runBlockingTest {
6362
whenever(statisticsDataStore.hasInstallationStatistics).thenReturn(false)
6463
appReferrerStateListener = StubAppReferrerFoundStateListener(referrer = "xx", mockDelayMs = Long.MAX_VALUE)
65-
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
64+
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, setOf(appReferrerStateListener))
6665

67-
testee.initializeAfterReferrerAvailable()
66+
testee.initialize()
6867

6968
verify(statisticsUpdater).initializeAtb()
7069
}
7170

7271
@Test
7372
fun whenAlreadyInitializedThenRefreshCalled() = runBlockingTest {
7473
configureAlreadyInitialized()
75-
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
74+
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, setOf(appReferrerStateListener))
7675

77-
testee.initializeAfterReferrerAvailable()
76+
testee.initialize()
7877
verify(statisticsUpdater).refreshAppRetentionAtb()
7978
}
8079

app/src/androidTest/java/com/duckduckgo/app/statistics/api/OfflinePixelSenderTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class OfflinePixelSenderTest {
5252

5353
@Before
5454
fun before() {
55-
val exceptionEntity = UncaughtExceptionEntity(1, UncaughtExceptionSource.GLOBAL, "test", 1588167165000, "version")
55+
val exceptionEntity = UncaughtExceptionEntity(1, UncaughtExceptionSource.GLOBAL, "test", "version", 1588167165000)
5656

5757
runBlocking<Unit> {
5858
whenever(mockPixel.sendPixel(any(), any(), any())).thenReturn(Completable.complete())

app/src/main/java/com/duckduckgo/app/di/PlayStoreReferralModule.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
package com.duckduckgo.app.di
1818

1919
import android.content.Context
20-
import android.content.pm.PackageManager
2120
import com.duckduckgo.app.referral.*
22-
import com.duckduckgo.app.statistics.VariantManager
21+
import com.duckduckgo.app.statistics.AtbInitializerListener
2322
import dagger.Module
2423
import dagger.Provides
24+
import dagger.multibindings.IntoSet
2525
import javax.inject.Singleton
2626

2727
@Module
@@ -35,14 +35,14 @@ class PlayStoreReferralModule {
3535
@Provides
3636
@Singleton
3737
fun appInstallationReferrerStateListener(
38-
context: Context,
39-
packageManager: PackageManager,
40-
appInstallationReferrerParser: AppInstallationReferrerParser,
41-
appReferrerDataStore: AppReferrerDataStore,
42-
variantManager: VariantManager
43-
): AppInstallationReferrerStateListener {
44-
return PlayStoreAppReferrerStateListener(context, packageManager, appInstallationReferrerParser, appReferrerDataStore, variantManager)
45-
}
38+
playStoreAppReferrerStateListener: PlayStoreAppReferrerStateListener
39+
): AppInstallationReferrerStateListener = playStoreAppReferrerStateListener
40+
41+
@Provides
42+
@IntoSet
43+
fun providedReferrerAtbInitializerListener(
44+
playStoreAppReferrerStateListener: PlayStoreAppReferrerStateListener
45+
): AtbInitializerListener = playStoreAppReferrerStateListener
4646

4747
@Provides
4848
@Singleton

app/src/main/java/com/duckduckgo/app/di/StatisticsModule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import com.duckduckgo.app.global.db.AppDatabase
2121
import com.duckduckgo.app.global.device.ContextDeviceInfo
2222
import com.duckduckgo.app.global.device.DeviceInfo
2323
import com.duckduckgo.app.global.exception.UncaughtExceptionRepository
24-
import com.duckduckgo.app.referral.AppInstallationReferrerStateListener
2524
import com.duckduckgo.app.statistics.AtbInitializer
25+
import com.duckduckgo.app.statistics.AtbInitializerListener
2626
import com.duckduckgo.app.statistics.VariantManager
2727
import com.duckduckgo.app.statistics.api.*
2828
import com.duckduckgo.app.statistics.pixels.RxBasedPixel
@@ -86,9 +86,9 @@ class StatisticsModule {
8686
fun atbInitializer(
8787
statisticsDataStore: StatisticsDataStore,
8888
statisticsUpdater: StatisticsUpdater,
89-
appReferrerStateListener: AppInstallationReferrerStateListener
89+
listeners: Set<@JvmSuppressWildcards AtbInitializerListener>
9090
): AtbInitializer {
91-
return AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
91+
return AtbInitializer(statisticsDataStore, statisticsUpdater, listeners)
9292
}
9393

9494
@Singleton

app/src/main/java/com/duckduckgo/app/global/DuckDuckGoApplication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ open class DuckDuckGoApplication : HasAndroidInjector, Application(), LifecycleO
329329
notificationRegistrar.updateStatus()
330330
GlobalScope.launch {
331331
workScheduler.scheduleWork()
332-
atbInitializer.initializeAfterReferrerAvailable()
332+
atbInitializer.initialize()
333333
}
334334
}
335335

app/src/main/java/com/duckduckgo/app/global/exception/UncaughtExceptionModule.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.duckduckgo.app.global.exception
1818

1919
import com.duckduckgo.app.global.AlertingUncaughtExceptionHandler
2020
import com.duckduckgo.app.global.DispatcherProvider
21+
import com.duckduckgo.app.global.device.DeviceInfo
2122
import com.duckduckgo.app.statistics.store.OfflinePixelCountDataStore
2223
import dagger.Module
2324
import dagger.Provides
@@ -30,9 +31,10 @@ class UncaughtExceptionModule {
3031
@Singleton
3132
fun uncaughtWebViewExceptionRepository(
3233
uncaughtExceptionDao: UncaughtExceptionDao,
33-
rootExceptionFinder: RootExceptionFinder
34+
rootExceptionFinder: RootExceptionFinder,
35+
deviceInfo: DeviceInfo
3436
): UncaughtExceptionRepository {
35-
return UncaughtExceptionRepositoryDb(uncaughtExceptionDao, rootExceptionFinder)
37+
return UncaughtExceptionRepositoryDb(uncaughtExceptionDao, rootExceptionFinder, deviceInfo)
3638
}
3739

3840
@Provides

0 commit comments

Comments
 (0)