Skip to content

Commit 55c1e42

Browse files
CDRussellsubsymbolic
authored andcommitted
Delete app cache when clearing data using fire button (#508)
1 parent bf7e5d0 commit 55c1e42

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

app/src/androidTest/java/com/duckduckgo/app/global/view/ClearPersonalDataActionTest.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.duckduckgo.app.global.view
1818

1919
import androidx.test.platform.app.InstrumentationRegistry
2020
import com.duckduckgo.app.browser.WebDataManager
21+
import com.duckduckgo.app.fire.AppCacheClearer
2122
import com.duckduckgo.app.fire.DuckDuckGoCookieManager
2223
import com.duckduckgo.app.fire.UnsentForgetAllPixelStore
2324
import com.duckduckgo.app.settings.db.SettingsDataStore
@@ -40,6 +41,7 @@ class ClearPersonalDataActionTest {
4041
private val mockTabRepository: TabRepository = mock()
4142
private val mockSettingsDataStore: SettingsDataStore = mock()
4243
private val mockCookieManager: DuckDuckGoCookieManager = mock()
44+
private val mockAppCacheClearer: AppCacheClearer = mock()
4345

4446
@Before
4547
fun setup() {
@@ -49,7 +51,8 @@ class ClearPersonalDataActionTest {
4951
mockClearingUnsentForgetAllPixelStore,
5052
mockTabRepository,
5153
mockSettingsDataStore,
52-
mockCookieManager
54+
mockCookieManager,
55+
mockAppCacheClearer
5356
)
5457
}
5558

@@ -83,6 +86,12 @@ class ClearPersonalDataActionTest {
8386
verify(mockDataManager).clearExternalCookies()
8487
}
8588

89+
@Test
90+
fun whenClearCalledThenAppCacheClearerClearsCache() = runBlocking<Unit> {
91+
testee.clearTabsAndAllDataAsync(false, false)
92+
verify(mockAppCacheClearer).clearCache()
93+
}
94+
8695
@Test
8796
fun whenClearCalledThenTabsCleared() = runBlocking<Unit> {
8897
testee.clearTabsAndAllDataAsync(false, false)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ class PrivacyModule {
5050
clearingStore: UnsentForgetAllPixelStore,
5151
tabRepository: TabRepository,
5252
settingsDataStore: SettingsDataStore,
53-
cookieManager: DuckDuckGoCookieManager
53+
cookieManager: DuckDuckGoCookieManager,
54+
appCacheClearer: AppCacheClearer
5455
): ClearDataAction {
55-
return ClearPersonalDataAction(context, dataManager, clearingStore, tabRepository, settingsDataStore, cookieManager)
56+
return ClearPersonalDataAction(context, dataManager, clearingStore, tabRepository, settingsDataStore, cookieManager, appCacheClearer)
5657
}
5758

5859
@Provides
@@ -78,4 +79,10 @@ class PrivacyModule {
7879
pixel: Pixel
7980
): HistoricTrackerBlockingObserver =
8081
HistoricTrackerBlockingObserver(appInstallStore, privacySettingsStore, pixel)
82+
83+
@Provides
84+
@Singleton
85+
fun appCacheCleaner(context: Context): AppCacheClearer {
86+
return AndroidAppCacheClearer(context)
87+
}
8188
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2019 DuckDuckGo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.duckduckgo.app.fire
18+
19+
import android.content.Context
20+
import kotlinx.coroutines.Dispatchers
21+
import kotlinx.coroutines.withContext
22+
23+
24+
interface AppCacheClearer {
25+
26+
suspend fun clearCache()
27+
28+
}
29+
30+
class AndroidAppCacheClearer(private val context: Context) : AppCacheClearer {
31+
32+
override suspend fun clearCache() {
33+
withContext(Dispatchers.IO) {
34+
context.cacheDir.deleteRecursively()
35+
}
36+
}
37+
38+
}

app/src/main/java/com/duckduckgo/app/global/view/ClearPersonalDataAction.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import android.webkit.WebViewDatabase
2323
import androidx.annotation.UiThread
2424
import androidx.annotation.WorkerThread
2525
import com.duckduckgo.app.browser.WebDataManager
26+
import com.duckduckgo.app.fire.AppCacheClearer
2627
import com.duckduckgo.app.fire.DuckDuckGoCookieManager
2728
import com.duckduckgo.app.fire.FireActivity
2829
import com.duckduckgo.app.fire.UnsentForgetAllPixelStore
@@ -53,7 +54,8 @@ class ClearPersonalDataAction @Inject constructor(
5354
private val clearingStore: UnsentForgetAllPixelStore,
5455
private val tabRepository: TabRepository,
5556
private val settingsDataStore: SettingsDataStore,
56-
private val cookieManager: DuckDuckGoCookieManager
57+
private val cookieManager: DuckDuckGoCookieManager,
58+
private val appCacheClearer: AppCacheClearer
5759
) : ClearDataAction, CoroutineScope {
5860

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

110+
appCacheClearer.clearCache()
111+
108112
Timber.i("Finished clearing data")
109113
}
110114

0 commit comments

Comments
 (0)