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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.duckduckgo.app.global.view

import androidx.test.platform.app.InstrumentationRegistry
import com.duckduckgo.app.browser.WebDataManager
import com.duckduckgo.app.fire.AppCacheClearer
import com.duckduckgo.app.fire.DuckDuckGoCookieManager
import com.duckduckgo.app.fire.UnsentForgetAllPixelStore
import com.duckduckgo.app.settings.db.SettingsDataStore
Expand All @@ -40,6 +41,7 @@ class ClearPersonalDataActionTest {
private val mockTabRepository: TabRepository = mock()
private val mockSettingsDataStore: SettingsDataStore = mock()
private val mockCookieManager: DuckDuckGoCookieManager = mock()
private val mockAppCacheClearer: AppCacheClearer = mock()

@Before
fun setup() {
Expand All @@ -49,7 +51,8 @@ class ClearPersonalDataActionTest {
mockClearingUnsentForgetAllPixelStore,
mockTabRepository,
mockSettingsDataStore,
mockCookieManager
mockCookieManager,
mockAppCacheClearer
)
}

Expand Down Expand Up @@ -83,6 +86,12 @@ class ClearPersonalDataActionTest {
verify(mockDataManager).clearExternalCookies()
}

@Test
fun whenClearCalledThenAppCacheClearerClearsCache() = runBlocking<Unit> {
testee.clearTabsAndAllDataAsync(false, false)
verify(mockAppCacheClearer).clearCache()
}

@Test
fun whenClearCalledThenTabsCleared() = runBlocking<Unit> {
testee.clearTabsAndAllDataAsync(false, false)
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/com/duckduckgo/app/di/PrivacyModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ class PrivacyModule {
clearingStore: UnsentForgetAllPixelStore,
tabRepository: TabRepository,
settingsDataStore: SettingsDataStore,
cookieManager: DuckDuckGoCookieManager
cookieManager: DuckDuckGoCookieManager,
appCacheClearer: AppCacheClearer
): ClearDataAction {
return ClearPersonalDataAction(context, dataManager, clearingStore, tabRepository, settingsDataStore, cookieManager)
return ClearPersonalDataAction(context, dataManager, clearingStore, tabRepository, settingsDataStore, cookieManager, appCacheClearer)
}

@Provides
Expand All @@ -78,4 +79,10 @@ class PrivacyModule {
pixel: Pixel
): HistoricTrackerBlockingObserver =
HistoricTrackerBlockingObserver(appInstallStore, privacySettingsStore, pixel)

@Provides
@Singleton
fun appCacheCleaner(context: Context): AppCacheClearer {
return AndroidAppCacheClearer(context)
}
}
38 changes: 38 additions & 0 deletions app/src/main/java/com/duckduckgo/app/fire/AppCacheClearer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2019 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.
*/

package com.duckduckgo.app.fire

import android.content.Context
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext


interface AppCacheClearer {

suspend fun clearCache()

}

class AndroidAppCacheClearer(private val context: Context) : AppCacheClearer {

override suspend fun clearCache() {
withContext(Dispatchers.IO) {
context.cacheDir.deleteRecursively()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.webkit.WebViewDatabase
import androidx.annotation.UiThread
import androidx.annotation.WorkerThread
import com.duckduckgo.app.browser.WebDataManager
import com.duckduckgo.app.fire.AppCacheClearer
import com.duckduckgo.app.fire.DuckDuckGoCookieManager
import com.duckduckgo.app.fire.FireActivity
import com.duckduckgo.app.fire.UnsentForgetAllPixelStore
Expand Down Expand Up @@ -53,7 +54,8 @@ class ClearPersonalDataAction @Inject constructor(
private val clearingStore: UnsentForgetAllPixelStore,
private val tabRepository: TabRepository,
private val settingsDataStore: SettingsDataStore,
private val cookieManager: DuckDuckGoCookieManager
private val cookieManager: DuckDuckGoCookieManager,
private val appCacheClearer: AppCacheClearer
) : ClearDataAction, CoroutineScope {

private val clearJob: Job = Job()
Expand Down Expand Up @@ -105,6 +107,8 @@ class ClearPersonalDataAction @Inject constructor(
dataManager.clearData(createWebView(), createWebStorage(), WebViewDatabase.getInstance(context))
dataManager.clearExternalCookies()

appCacheClearer.clearCache()

Timber.i("Finished clearing data")
}

Expand Down