Skip to content

Conversation

@aitorvs
Copy link
Collaborator

@aitorvs aitorvs commented Feb 15, 2021

Task/Issue URL: https://app.asana.com/0/414730916066338/1199931182139284/f
Tech Design URL:
CC:

Description:
This PR moves the statistics package, that contains the ATB and Pixel APIs to its own gradle lib module. The PR:

  • 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

I have left the corresponding test in the app gradle module for now to be sure the are executed in CI (I was not sured whether CI was prepared to execute tests in other gradle lib modules).
Once that's done, we can move the tests as well

Steps to test this PR:

  1. install/upgrade from this branch
  2. open the app test basic features work, bookmarks, settings, fire proofing sites, tabs, etc.
  3. verify pixels are sent normally

Internal references:

Software Engineering Expectations
Technical Design Template

Comment on lines 46 to 56
@Database(
entities = [PixelEntity::class],
version = 1
)
@TypeConverters(
QueryParamsTypeConverter::class
)
abstract class TestDatabase : RoomDatabase() {
abstract fun pixelDao(): PendingPixelDao
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created the TestDatabase to break the circular dependency with the main app module. Also, we don't need the full DB, just the DAO to perform the test

Copy link
Contributor

Choose a reason for hiding this comment

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

as discussed, we can get rid of this

Comment on lines +23 to 41
interface AtbInitializerListener {

/**
* This method will be called before initializing the ATB
*/
suspend fun beforeAtbInit()

/**
* @return the timeout in milliseconds after which [beforeAtbInit]
* will be stopped
*/
fun beforeAtbInitTimeoutMillis(): Long
}

class AtbInitializer(
private val statisticsDataStore: StatisticsDataStore,
private val statisticsUpdater: StatisticsUpdater,
private val appReferrerStateListener: AppInstallationReferrerStateListener
private val listeners: Set<AtbInitializerListener>
) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Creater AtbInitializerListener to break circular dependency with the main app module.
Also, the fact that the AtbInitializer depended on the AppInstallationReferrerStateListener was leaking the referrer logic into the AtbInitializer, which preferably should not happen.

The AtbInitializer now provides a listener that can be implemented by any other class in the app that is interested in executing some code before the AtbInitializer is initialized.
This way, the AtbInitializer does not need to know anything about these classes

Comment on lines +44 to +47
override val appVersion by lazy {
val info = context.packageManager.getPackageInfo(context.packageName, 0)
info.versionName.orEmpty()
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BuildConfig.VERSION_NAME cannot be access from a lib gradle module. So we get the version name programatically

Comment on lines +29 to +30
val version: String,
val timestamp: Long = System.currentTimeMillis()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BuildConfig.VERSION_NAME cannot be access from a lib gradle module, so I made version required so that the caller side can provide the proper version

val exceptionEntity = UncaughtExceptionEntity(
message = rootCause.extractExceptionCause(),
exceptionSource = exceptionSource,
version = deviceInfo.appVersion)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

version is now required param, so get it from the DeviceInfo

version.google.dagger=2.27
version.io.reactivex.rxjava2..rxandroid=2.0.2
version.io.reactivex.rxjava2..rxjava=2.1.10
version.io.reactivex.rxjava2..rxjava=2.2.9
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bumped this dependency bc I realised that it was overriden by the AndroidX.work.rxJava2, which was bringing version 2.2.9 along, so we effectively had two rxjava versions in the APK, but we were using 2.2.9

@aitorvs aitorvs force-pushed the feature/aitor/pixel_module branch from 66a853e to a80752d Compare February 16, 2021 10:46
@aitorvs aitorvs requested a review from malmstein February 16, 2021 13:44
@aitorvs aitorvs force-pushed the feature/aitor/pixel_module branch from 70451b8 to 26709d0 Compare February 16, 2021 14:00
@malmstein malmstein self-assigned this Feb 16, 2021
Copy link
Contributor

@malmstein malmstein left a comment

Choose a reason for hiding this comment

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

couple of changes on sdk versions and removing the unnecessary TestDatabase

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.

👍

Comment on lines 46 to 56
@Database(
entities = [PixelEntity::class],
version = 1
)
@TypeConverters(
QueryParamsTypeConverter::class
)
abstract class TestDatabase : RoomDatabase() {
abstract fun pixelDao(): PendingPixelDao
}

Copy link
Contributor

Choose a reason for hiding this comment

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

as discussed, we can get rid of this


defaultConfig {
minSdkVersion 21
targetSdkVersion 30
Copy link
Contributor

Choose a reason for hiding this comment

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

project's targetSdkVersion is 29, probably we should export it for everyone's to use.

}

android {
compileSdkVersion 30
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, this is 29

testImplementation AndroidX.room.testing
androidTestImplementation AndroidX.room.testing

testImplementation 'junit:junit:4.+'
Copy link
Contributor

Choose a reason for hiding this comment

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

can you call ./gradleW refreshVersions so this is extracted?

import org.junit.Assert.assertTrue
import org.junit.Test

class DummyTestForCI {
Copy link
Contributor

Choose a reason for hiding this comment

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

💥

}

android {
compileSdkVersion 30
Copy link
Contributor

Choose a reason for hiding this comment

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

same here regarding version 29


defaultConfig {
minSdkVersion 21
targetSdkVersion 30
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

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

testImplementation 'junit:junit:4.+'
Copy link
Contributor

Choose a reason for hiding this comment

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

same here for refreshVersions

@aitorvs aitorvs requested a review from malmstein February 17, 2021 10:04
Copy link
Contributor

@malmstein malmstein left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @aitorvs , this looks great!

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.

👍

@aitorvs aitorvs merged commit 088dd73 into develop Feb 17, 2021
@aitorvs aitorvs deleted the feature/aitor/pixel_module branch February 17, 2021 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants