Skip to content

Commit a2ceb1b

Browse files
committed
Merge branch 'hotfix/5.32.1'
2 parents 4b08643 + 1b8cf78 commit a2ceb1b

File tree

11 files changed

+42
-25
lines changed

11 files changed

+42
-25
lines changed

app/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ android {
3131
androidTest.resources.srcDirs += files("$projectDir/../submodules/".toString())
3232
}
3333
}
34+
kotlinOptions {
35+
jvmTarget = "1.8"
36+
}
3437
signingConfigs {
3538
release
3639
}
@@ -88,7 +91,7 @@ ext {
8891
constraintLayout = "2.0.0-beta1"
8992
lifecycle = "2.1.0-alpha04"
9093
room = "2.1.0"
91-
workManager = "2.0.0"
94+
workManager = "2.2.0"
9295
legacySupport = "1.0.0"
9396
espressoCore = "3.1.1"
9497
coreTesting = "2.0.0"

app/src/androidTest/java/com/duckduckgo/app/fire/AutomaticDataClearerTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package com.duckduckgo.app.fire
2020

2121
import androidx.test.annotation.UiThreadTest
22+
import androidx.work.WorkManager
2223
import com.duckduckgo.app.global.view.ClearDataAction
2324
import com.duckduckgo.app.settings.clear.ClearWhatOption
2425
import com.duckduckgo.app.settings.clear.ClearWhenOption
@@ -37,12 +38,13 @@ class AutomaticDataClearerTest {
3738
private val mockSettingsDataStore: SettingsDataStore = mock()
3839
private val mockClearAction: ClearDataAction = mock()
3940
private val mockTimeKeeper: BackgroundTimeKeeper = mock()
41+
private val mockWorkManager: WorkManager = mock()
4042

4143
@UiThreadTest
4244
@Before
4345
fun setup() {
4446
whenever(mockSettingsDataStore.hasBackgroundTimestampRecorded()).thenReturn(true)
45-
testee = AutomaticDataClearer(mockSettingsDataStore, mockClearAction, mockTimeKeeper)
47+
testee = AutomaticDataClearer(mockWorkManager, mockSettingsDataStore, mockClearAction, mockTimeKeeper)
4648
}
4749

4850
private suspend fun simulateLifecycle(isFreshAppLaunch: Boolean) {

app/src/androidTest/java/com/duckduckgo/app/notification/NotificationSchedulerTest.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package com.duckduckgo.app.notification
2121

22+
import androidx.test.platform.app.InstrumentationRegistry
23+
import androidx.work.Configuration
2224
import androidx.work.WorkInfo
2325
import androidx.work.WorkManager
2426
import com.duckduckgo.app.notification.NotificationScheduler.ClearDataNotificationWorker
@@ -41,12 +43,15 @@ class NotificationSchedulerTest {
4143
private val clearNotification: SchedulableNotification = mock()
4244
private val privacyNotification: SchedulableNotification = mock()
4345

46+
private val context = InstrumentationRegistry.getInstrumentation().targetContext
47+
private var workManager = WorkManager.getInstance(context)
4448
private lateinit var testee: NotificationScheduler
4549

4650
@Before
4751
fun before() {
4852
whenever(variantManager.getVariant(any())).thenReturn(DEFAULT_VARIANT)
4953
testee = NotificationScheduler(
54+
workManager,
5055
clearNotification,
5156
privacyNotification
5257
)
@@ -93,8 +98,7 @@ class NotificationSchedulerTest {
9398
}
9499

95100
private fun getScheduledWorkers(): List<WorkInfo> {
96-
return WorkManager
97-
.getInstance()
101+
return workManager
98102
.getWorkInfosByTag(NotificationScheduler.WORK_REQUEST_TAG)
99103
.get()
100104
.filter { it.state == WorkInfo.State.ENQUEUED }

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import android.app.NotificationManager
2020
import android.content.Context
2121
import androidx.core.app.NotificationManagerCompat
2222
import androidx.localbroadcastmanager.content.LocalBroadcastManager
23+
import androidx.work.WorkManager
2324
import com.duckduckgo.app.notification.NotificationFactory
2425
import com.duckduckgo.app.notification.NotificationScheduler
2526
import com.duckduckgo.app.notification.db.NotificationDao
@@ -73,10 +74,12 @@ class NotificationModule {
7374
@Provides
7475
@Singleton
7576
fun providesNotificationScheduler(
77+
workManager: WorkManager,
7678
clearDataNotification: ClearDataNotification,
7779
privacyProtectionNotification: PrivacyProtectionNotification
7880
): NotificationScheduler {
7981
return NotificationScheduler(
82+
workManager,
8083
clearDataNotification,
8184
privacyProtectionNotification
8285
)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.duckduckgo.app.di
1818

1919
import android.content.Context
20+
import androidx.work.WorkManager
2021
import com.duckduckgo.app.browser.WebDataManager
2122
import com.duckduckgo.app.entities.EntityMapping
2223
import com.duckduckgo.app.fire.*
@@ -65,11 +66,12 @@ class PrivacyModule {
6566
@Provides
6667
@Singleton
6768
fun automaticDataClearer(
69+
workManager: WorkManager,
6870
settingsDataStore: SettingsDataStore,
6971
clearDataAction: ClearDataAction,
7072
dataClearerTimeKeeper: BackgroundTimeKeeper
7173
): DataClearer {
72-
return AutomaticDataClearer(settingsDataStore, clearDataAction, dataClearerTimeKeeper)
74+
return AutomaticDataClearer(workManager, settingsDataStore, clearDataAction, dataClearerTimeKeeper)
7375
}
7476

7577
@Provides

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

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

1717
package com.duckduckgo.app.di
1818

19+
import android.content.Context
1920
import androidx.core.app.NotificationManagerCompat
21+
import androidx.work.Configuration
22+
import androidx.work.WorkManager
2023
import androidx.work.WorkerFactory
2124
import com.duckduckgo.app.global.view.ClearDataAction
2225
import com.duckduckgo.app.notification.NotificationFactory
@@ -33,6 +36,16 @@ import javax.inject.Singleton
3336
@Module
3437
class WorkerModule {
3538

39+
@Provides
40+
@Singleton
41+
fun workManager(context: Context, workerFactory: WorkerFactory): WorkManager {
42+
val config = Configuration.Builder()
43+
.setWorkerFactory(workerFactory)
44+
.build()
45+
WorkManager.initialize(context, config)
46+
return WorkManager.getInstance(context)
47+
}
48+
3649
@Provides
3750
@Singleton
3851
fun workerFactory(

app/src/main/java/com/duckduckgo/app/fire/AutomaticDataClearer.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ interface DataClearer : LifecycleObserver {
4040
}
4141

4242
class AutomaticDataClearer(
43+
private val workManager: WorkManager,
4344
private val settingsDataStore: SettingsDataStore,
4445
private val clearDataAction: ClearDataAction,
4546
private val dataClearerTimeKeeper: BackgroundTimeKeeper
4647
) : DataClearer, LifecycleObserver, CoroutineScope {
4748

4849
private val clearJob: Job = Job()
50+
4951
override val coroutineContext: CoroutineContext
5052
get() = Dispatchers.Main + clearJob
5153

@@ -70,7 +72,7 @@ class AutomaticDataClearer(
7072

7173
Timber.i("onAppForegrounded; is from fresh app launch? $isFreshAppLaunch")
7274

73-
WorkManager.getInstance().cancelAllWorkByTag(DataClearingWorker.WORK_REQUEST_TAG)
75+
workManager.cancelAllWorkByTag(DataClearingWorker.WORK_REQUEST_TAG)
7476

7577
val appUsedSinceLastClear = settingsDataStore.appUsedSinceLastClear
7678
settingsDataStore.appUsedSinceLastClear = true
@@ -116,7 +118,7 @@ class AutomaticDataClearer(
116118
}
117119

118120
private fun scheduleBackgroundTimerToTriggerClear(durationMillis: Long) {
119-
WorkManager.getInstance().also {
121+
workManager.also {
120122
val workRequest = OneTimeWorkRequestBuilder<DataClearingWorker>()
121123
.setInitialDelay(durationMillis, TimeUnit.MILLISECONDS)
122124
.addTag(DataClearingWorker.WORK_REQUEST_TAG)

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import androidx.lifecycle.Lifecycle
2525
import androidx.lifecycle.LifecycleObserver
2626
import androidx.lifecycle.OnLifecycleEvent
2727
import androidx.lifecycle.ProcessLifecycleOwner
28-
import androidx.work.Configuration
29-
import androidx.work.WorkManager
3028
import androidx.work.WorkerFactory
3129
import com.duckduckgo.app.browser.BuildConfig
3230
import com.duckduckgo.app.browser.defaultbrowsing.DefaultBrowserObserver
@@ -47,7 +45,6 @@ import com.duckduckgo.app.notification.NotificationScheduler
4745
import com.duckduckgo.app.privacy.HistoricTrackerBlockingObserver
4846
import com.duckduckgo.app.settings.db.SettingsDataStore
4947
import com.duckduckgo.app.statistics.api.OfflinePixelScheduler
50-
import com.duckduckgo.app.statistics.api.OfflinePixelSender
5148
import com.duckduckgo.app.statistics.api.StatisticsUpdater
5249
import com.duckduckgo.app.statistics.pixels.Pixel
5350
import com.duckduckgo.app.statistics.pixels.Pixel.PixelName.APP_LAUNCH
@@ -164,8 +161,6 @@ open class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, HasS
164161

165162
if (appIsRestarting()) return
166163

167-
configureWorkManager()
168-
169164
ProcessLifecycleOwner.get().lifecycle.also {
170165
it.addObserver(this)
171166
it.addObserver(dataClearer)
@@ -198,14 +193,6 @@ open class DuckDuckGoApplication : HasActivityInjector, HasServiceInjector, HasS
198193
Thread.setDefaultUncaughtExceptionHandler(AlertingUncaughtExceptionHandler(originalHandler, offlinePixelDataStore))
199194
}
200195

201-
private fun configureWorkManager() {
202-
val config = Configuration.Builder()
203-
.setWorkerFactory(workerFactory)
204-
.build()
205-
206-
WorkManager.initialize(this, config)
207-
}
208-
209196
private fun recordInstallationTimestamp() {
210197
if (!appInstallStore.hasInstallTimestampRecorded()) {
211198
appInstallStore.installTimestamp = System.currentTimeMillis()

app/src/main/java/com/duckduckgo/app/notification/NotificationScheduler.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ import java.util.concurrent.TimeUnit
3535
import javax.inject.Inject
3636

3737
class NotificationScheduler @Inject constructor(
38+
private val workManager: WorkManager,
3839
private val clearDataNotification: SchedulableNotification,
3940
private val privacyNotification: SchedulableNotification
4041
) {
42+
4143
suspend fun scheduleNextNotification() {
4244

43-
WorkManager.getInstance().cancelAllWorkByTag(WORK_REQUEST_TAG)
45+
workManager.cancelAllWorkByTag(WORK_REQUEST_TAG)
4446

4547
when {
4648
privacyNotification.canShow() -> {
@@ -60,7 +62,7 @@ class NotificationScheduler @Inject constructor(
6062
.setInitialDelay(duration, unit)
6163
.build()
6264

63-
WorkManager.getInstance().enqueue(request)
65+
workManager.enqueue(request)
6466
}
6567

6668
// Legacy code. Unused class required for users who already have this notification scheduled from previous version. We will

app/src/main/java/com/duckduckgo/app/statistics/api/OfflinePixelScheduler.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ import timber.log.Timber
2222
import java.util.concurrent.TimeUnit
2323
import javax.inject.Inject
2424

25-
class OfflinePixelScheduler @Inject constructor() {
25+
class OfflinePixelScheduler @Inject constructor(private val workManager: WorkManager) {
2626

2727
fun scheduleOfflinePixels() {
2828

2929
Timber.v("Scheduling offline pixels to be sent")
30-
val workManager = WorkManager.getInstance()
3130
workManager.cancelAllWorkByTag(WORK_REQUEST_TAG)
3231

3332
val constraints = Constraints.Builder()

0 commit comments

Comments
 (0)