Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ ext {
}

android {
compileSdkVersion 29
compileSdkVersion compile_sdk
ndkVersion '21.0.6113669'
defaultConfig {
applicationId "com.duckduckgo.mobile.android"
minSdkVersion 21
targetSdkVersion 29
minSdkVersion min_sdk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

targetSdkVersion target_sdk
versionCode buildVersionCode()
versionName buildVersionName()
testInstrumentationRunner "com.duckduckgo.app.TestRunner"
Expand Down Expand Up @@ -96,6 +96,9 @@ android {
}

dependencies {
implementation project(path: ':statistics')
implementation project(path: ':common')

implementation AndroidX.legacy.supportV4
debugImplementation Square.leakCanary.android

Expand Down Expand Up @@ -174,9 +177,6 @@ dependencies {
// Lottie
implementation "com.airbnb.android:lottie:_"

// Apache commons
implementation "org.apache.commons:commons-math3:_"

// Play Store referrer library
implementation("com.android.installreferrer:installreferrer:_")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package com.duckduckgo.app.di
import android.content.Context
import com.duckduckgo.app.global.device.ContextDeviceInfo
import com.duckduckgo.app.global.device.DeviceInfo
import com.duckduckgo.app.referral.AppInstallationReferrerStateListener
import com.duckduckgo.app.statistics.AtbInitializer
import com.duckduckgo.app.statistics.AtbInitializerListener
import com.duckduckgo.app.statistics.api.PixelSender
import com.duckduckgo.app.statistics.api.StatisticsService
import com.duckduckgo.app.statistics.api.StatisticsUpdater
Expand Down Expand Up @@ -84,9 +84,9 @@ class StubStatisticsModule {
fun atbInitializer(
statisticsDataStore: StatisticsDataStore,
statisticsUpdater: StatisticsUpdater,
appReferrerStateListener: AppInstallationReferrerStateListener
listeners: Set<@JvmSuppressWildcards AtbInitializerListener>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

): AtbInitializer {
return AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
return AtbInitializer(statisticsDataStore, statisticsUpdater, listeners)
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class UncaughtExceptionDaoTest {

@Test
fun whenSeveralExceptionExistAndOneDeletedThenCorrectEntryIsRemoved() {
val exception1 = UncaughtExceptionEntity(id = 1, exceptionSource = GLOBAL, message = "foo1")
val exception2 = UncaughtExceptionEntity(id = 2, exceptionSource = ON_PROGRESS_CHANGED, message = "foo2")
val exception3 = UncaughtExceptionEntity(id = 3, exceptionSource = ON_PAGE_STARTED, message = "foo3")
val exception1 = UncaughtExceptionEntity(id = 1, exceptionSource = GLOBAL, message = "foo1", "version")
val exception2 = UncaughtExceptionEntity(id = 2, exceptionSource = ON_PROGRESS_CHANGED, message = "foo2", "version")
val exception3 = UncaughtExceptionEntity(id = 3, exceptionSource = ON_PAGE_STARTED, message = "foo3", "version")
dao.add(exception1)
dao.add(exception2)
dao.add(exception3)
Expand All @@ -102,7 +102,7 @@ class UncaughtExceptionDaoTest {

@Test
fun whenExceptionRetrievedFromDatabaseThenAllDetailsRestored() {
val exception = UncaughtExceptionEntity(id = 1, exceptionSource = GLOBAL, message = "foo")
val exception = UncaughtExceptionEntity(id = 1, exceptionSource = GLOBAL, message = "foo", "version")
dao.add(exception)
val list = dao.all()
assertEquals(1, list.size)
Expand All @@ -116,5 +116,5 @@ class UncaughtExceptionDaoTest {
}

private fun anUncaughtExceptionEntity(id: Long? = null) =
UncaughtExceptionEntity(id = id ?: 0, exceptionSource = GLOBAL, message = "foo")
UncaughtExceptionEntity(id = id ?: 0, exceptionSource = GLOBAL, message = "foo", "version")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package com.duckduckgo.app.referral

import com.duckduckgo.app.statistics.AtbInitializerListener
import kotlinx.coroutines.delay

class StubAppReferrerFoundStateListener(private val referrer: String, private val mockDelayMs: Long = 0) : AppInstallationReferrerStateListener {
class StubAppReferrerFoundStateListener(
private val referrer: String,
private val mockDelayMs: Long = 0
) : AppInstallationReferrerStateListener, AtbInitializerListener {
override suspend fun waitForReferrerCode(): ParsedReferrerResult {
if (mockDelayMs > 0) delay(mockDelayMs)

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

override fun initialiseReferralRetrieval() {
}

override suspend fun beforeAtbInit() {
waitForReferrerCode()
}

override fun beforeAtbInitTimeoutMillis(): Long {
return mockDelayMs
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.duckduckgo.app.statistics

import com.duckduckgo.app.referral.AppInstallationReferrerStateListener
import com.duckduckgo.app.referral.StubAppReferrerFoundStateListener
import com.duckduckgo.app.statistics.api.StatisticsUpdater
import com.duckduckgo.app.statistics.store.StatisticsDataStore
Expand All @@ -34,15 +33,15 @@ class AtbInitializerTest {

private val statisticsDataStore: StatisticsDataStore = mock()
private val statisticsUpdater: StatisticsUpdater = mock()
private lateinit var appReferrerStateListener: AppInstallationReferrerStateListener
private lateinit var appReferrerStateListener: AtbInitializerListener

@Test
fun whenReferrerInformationInstantlyAvailableThenAtbInitialized() = runBlockingTest {
whenever(statisticsDataStore.hasInstallationStatistics).thenReturn(false)
appReferrerStateListener = StubAppReferrerFoundStateListener(referrer = "xx")
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, setOf(appReferrerStateListener))

testee.initializeAfterReferrerAvailable()
testee.initialize()

verify(statisticsUpdater).initializeAtb()
}
Expand All @@ -51,9 +50,9 @@ class AtbInitializerTest {
fun whenReferrerInformationQuicklyAvailableThenAtbInitialized() = runBlockingTest {
whenever(statisticsDataStore.hasInstallationStatistics).thenReturn(false)
appReferrerStateListener = StubAppReferrerFoundStateListener(referrer = "xx", mockDelayMs = 1000L)
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, setOf(appReferrerStateListener))

testee.initializeAfterReferrerAvailable()
testee.initialize()

verify(statisticsUpdater).initializeAtb()
}
Expand All @@ -62,19 +61,19 @@ class AtbInitializerTest {
fun whenReferrerInformationTimesOutThenAtbInitialized() = runBlockingTest {
whenever(statisticsDataStore.hasInstallationStatistics).thenReturn(false)
appReferrerStateListener = StubAppReferrerFoundStateListener(referrer = "xx", mockDelayMs = Long.MAX_VALUE)
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, setOf(appReferrerStateListener))

testee.initializeAfterReferrerAvailable()
testee.initialize()

verify(statisticsUpdater).initializeAtb()
}

@Test
fun whenAlreadyInitializedThenRefreshCalled() = runBlockingTest {
configureAlreadyInitialized()
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
testee = AtbInitializer(statisticsDataStore, statisticsUpdater, setOf(appReferrerStateListener))

testee.initializeAfterReferrerAvailable()
testee.initialize()
verify(statisticsUpdater).refreshAppRetentionAtb()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class OfflinePixelSenderTest {

@Before
fun before() {
val exceptionEntity = UncaughtExceptionEntity(1, UncaughtExceptionSource.GLOBAL, "test", 1588167165000, "version")
val exceptionEntity = UncaughtExceptionEntity(1, UncaughtExceptionSource.GLOBAL, "test", "version", 1588167165000)

runBlocking<Unit> {
whenever(mockPixel.sendPixel(any(), any(), any())).thenReturn(Completable.complete())
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/com/duckduckgo/app/di/PlayStoreReferralModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package com.duckduckgo.app.di

import android.content.Context
import android.content.pm.PackageManager
import com.duckduckgo.app.referral.*
import com.duckduckgo.app.statistics.VariantManager
import com.duckduckgo.app.statistics.AtbInitializerListener
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoSet
import javax.inject.Singleton

@Module
Expand All @@ -35,14 +35,14 @@ class PlayStoreReferralModule {
@Provides
@Singleton
fun appInstallationReferrerStateListener(
context: Context,
packageManager: PackageManager,
appInstallationReferrerParser: AppInstallationReferrerParser,
appReferrerDataStore: AppReferrerDataStore,
variantManager: VariantManager
): AppInstallationReferrerStateListener {
return PlayStoreAppReferrerStateListener(context, packageManager, appInstallationReferrerParser, appReferrerDataStore, variantManager)
}
playStoreAppReferrerStateListener: PlayStoreAppReferrerStateListener
): AppInstallationReferrerStateListener = playStoreAppReferrerStateListener

@Provides
@IntoSet
fun providedReferrerAtbInitializerListener(
playStoreAppReferrerStateListener: PlayStoreAppReferrerStateListener
): AtbInitializerListener = playStoreAppReferrerStateListener

@Provides
@Singleton
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/duckduckgo/app/di/StatisticsModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import com.duckduckgo.app.global.db.AppDatabase
import com.duckduckgo.app.global.device.ContextDeviceInfo
import com.duckduckgo.app.global.device.DeviceInfo
import com.duckduckgo.app.global.exception.UncaughtExceptionRepository
import com.duckduckgo.app.referral.AppInstallationReferrerStateListener
import com.duckduckgo.app.statistics.AtbInitializer
import com.duckduckgo.app.statistics.AtbInitializerListener
import com.duckduckgo.app.statistics.VariantManager
import com.duckduckgo.app.statistics.api.*
import com.duckduckgo.app.statistics.pixels.RxBasedPixel
Expand Down Expand Up @@ -86,9 +86,9 @@ class StatisticsModule {
fun atbInitializer(
statisticsDataStore: StatisticsDataStore,
statisticsUpdater: StatisticsUpdater,
appReferrerStateListener: AppInstallationReferrerStateListener
listeners: Set<@JvmSuppressWildcards AtbInitializerListener>
): AtbInitializer {
return AtbInitializer(statisticsDataStore, statisticsUpdater, appReferrerStateListener)
return AtbInitializer(statisticsDataStore, statisticsUpdater, listeners)
}

@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ open class DuckDuckGoApplication : HasAndroidInjector, Application(), LifecycleO
notificationRegistrar.updateStatus()
GlobalScope.launch {
workScheduler.scheduleWork()
atbInitializer.initializeAfterReferrerAvailable()
atbInitializer.initialize()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.duckduckgo.app.global.exception

import com.duckduckgo.app.global.AlertingUncaughtExceptionHandler
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.app.global.device.DeviceInfo
import com.duckduckgo.app.statistics.store.OfflinePixelCountDataStore
import dagger.Module
import dagger.Provides
Expand All @@ -30,9 +31,10 @@ class UncaughtExceptionModule {
@Singleton
fun uncaughtWebViewExceptionRepository(
uncaughtExceptionDao: UncaughtExceptionDao,
rootExceptionFinder: RootExceptionFinder
rootExceptionFinder: RootExceptionFinder,
deviceInfo: DeviceInfo
): UncaughtExceptionRepository {
return UncaughtExceptionRepositoryDb(uncaughtExceptionDao, rootExceptionFinder)
return UncaughtExceptionRepositoryDb(uncaughtExceptionDao, rootExceptionFinder, deviceInfo)
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ import com.android.installreferrer.api.InstallReferrerClient.InstallReferrerResp
import com.android.installreferrer.api.InstallReferrerStateListener
import com.duckduckgo.app.playstore.PlayStoreAndroidUtils.Companion.PLAY_STORE_PACKAGE
import com.duckduckgo.app.playstore.PlayStoreAndroidUtils.Companion.PLAY_STORE_REFERRAL_SERVICE
import com.duckduckgo.app.referral.AppInstallationReferrerStateListener.Companion.MAX_REFERRER_WAIT_TIME_MS
import com.duckduckgo.app.referral.ParseFailureReason.*
import com.duckduckgo.app.referral.ParsedReferrerResult.*
import com.duckduckgo.app.statistics.AtbInitializerListener
import com.duckduckgo.app.statistics.VariantManager
import kotlinx.coroutines.delay
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton

interface AppInstallationReferrerStateListener {

Expand All @@ -43,13 +46,14 @@ interface AppInstallationReferrerStateListener {

}

@Singleton
class PlayStoreAppReferrerStateListener @Inject constructor(
val context: Context,
private val packageManager: PackageManager,
private val appInstallationReferrerParser: AppInstallationReferrerParser,
private val appReferrerDataStore: AppReferrerDataStore,
private val variantManager: VariantManager
) : InstallReferrerStateListener, AppInstallationReferrerStateListener {
) : InstallReferrerStateListener, AppInstallationReferrerStateListener, AtbInitializerListener {

private val referralClient = InstallReferrerClient.newBuilder(context).build()
private var initialisationStartTime: Long = 0
Expand Down Expand Up @@ -182,4 +186,10 @@ class PlayStoreAppReferrerStateListener @Inject constructor(
override fun onInstallReferrerServiceDisconnected() {
Timber.i("Referrer: ServiceDisconnected")
}

override suspend fun beforeAtbInit() {
waitForReferrerCode()
}

override fun beforeAtbInitTimeoutMillis(): Long = MAX_REFERRER_WAIT_TIME_MS
}
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ buildscript {
ext.kotlin_version = '1.4.10'
ext.spotless = "5.7.0"

ext.min_sdk = 21
ext.target_sdk = 29
ext.compile_sdk = 29
ext.tools_build_version = "30.0.3"

repositories {
google()
jcenter()
Expand Down
1 change: 1 addition & 0 deletions common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
46 changes: 46 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2021 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-kapt'
}

apply from: "$rootProject.projectDir/gradle/android-library.gradle"

dependencies {
implementation Kotlin.stdlib.jdk7
implementation KotlinX.coroutines.core
implementation KotlinX.coroutines.android

implementation AndroidX.work.runtimeKtx

implementation Google.dagger

implementation JakeWharton.timber

// Room
implementation AndroidX.room.runtime
implementation AndroidX.room.rxJava2
kapt AndroidX.room.compiler
testImplementation AndroidX.room.testing
androidTestImplementation AndroidX.room.testing

testImplementation Testing.junit4
androidTestImplementation AndroidX.test.runner
androidTestImplementation AndroidX.test.rules
}
Empty file added common/consumer-rules.pro
Empty file.
Loading