Skip to content

Commit

Permalink
Remove backup service (#4061)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1206314482566716/f

### Description
This PR contains the removal of the Google backup service implementation to persist ATB

### Steps to test this PR

- [x] Go to develop
- [x] Add a file under the Android directory called `test_d2d.sh`
- [x] Copy and paste in this new file the code from https://app.asana.com/0/0/1206310480197408/f
- [x] Install from develop
- [x] Run `./test_cloud_backup.sh com.duckduckgo.mobile.android.debug` to perform a backup
- [x] Check in File Explorer, you have `com.duckduckgo.app.statistics.backup` file with the `atb` key in it
- [x] Install from this branch
- [x] Refresh File Explorer
- [x] Check `com.duckduckgo.app.statistics.backup` has been cleared

### No UI changes
  • Loading branch information
nalcalag authored Jan 11, 2024
1 parent 1b627d0 commit 290ec47
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 526 deletions.
3 changes: 0 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,6 @@ dependencies {
implementation project(':broken-site-impl')
implementation project(':broken-site-store')

implementation project(':backup-agent-api')
implementation project(':backup-agent-impl')

// Deprecated. TODO: Stop using this artifact.
implementation "androidx.legacy:legacy-support-v4:_"
debugImplementation Square.leakCanary.android
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@

<application
android:name="com.duckduckgo.app.global.DuckDuckGoApplication"
android:backupAgent="com.duckduckgo.app.backup.agent.impl.DuckDuckGoBackupAgent"
android:fullBackupOnly="false"
android:allowBackup="false"
android:icon="${appIcon}"
android:label="@string/appName"
android:networkSecurityConfig="@xml/network_security_config"
Expand All @@ -42,8 +41,6 @@
android:theme="@style/Theme.DuckDuckGo.Light"
android:requestLegacyExternalStorage="true"
tools:ignore="GoogleAppIndexingWarning">
<meta-data android:name="com.google.android.backup.api_key"
android:value="unused" />
<meta-data
android:name="android.webkit.WebView.MetricsOptOut"
android:value="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2024 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.reinstalls

import android.content.Context
import android.content.SharedPreferences
import com.duckduckgo.di.scopes.AppScope
import com.squareup.anvil.annotations.ContributesBinding
import javax.inject.Inject

interface BackupServiceDataStore {
fun clearBackupPreferences()
}

@ContributesBinding(AppScope::class)
class BackupServiceSharedPreferences @Inject constructor(
private val context: Context,
) : BackupServiceDataStore {

private val backupServicePreferences: SharedPreferences by lazy { context.getSharedPreferences(FILENAME_BACKUP_SERVICE, Context.MODE_PRIVATE) }
private val backupPixelPreferences: SharedPreferences by lazy { context.getSharedPreferences(FILENAME_BACKUP_PIXEL, Context.MODE_PRIVATE) }

override fun clearBackupPreferences() {
if (backupServicePreferences.contains(KEY_ATB)) {
backupServicePreferences.edit().clear().apply()
}
if (backupPixelPreferences.contains(KEY_PIXEL_SENT)) {
backupPixelPreferences.edit().clear().apply()
}
}

companion object {
private const val FILENAME_BACKUP_SERVICE = "com.duckduckgo.app.statistics.backup"
private const val KEY_ATB = "com.duckduckgo.app.statistics.backup.atb"
private const val FILENAME_BACKUP_PIXEL = "com.duckduckgo.app.statistics.backup.pixel"
private const val KEY_PIXEL_SENT = "com.duckduckgo.app.statistics.backup.pixel.sent"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 DuckDuckGo
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,33 +14,21 @@
* limitations under the License.
*/

package com.duckduckgo.app.backup.agent.impl
package com.duckduckgo.app.reinstalls

import com.duckduckgo.app.backup.agent.impl.BackupAgentManagerImpl.Companion.REINSTALL_VARIANT
import com.duckduckgo.app.backup.agent.impl.store.BackupDataStore
import com.duckduckgo.app.statistics.AtbInitializerListener
import com.duckduckgo.app.statistics.store.StatisticsDataStore
import com.duckduckgo.di.scopes.AppScope
import com.squareup.anvil.annotations.ContributesMultibinding
import dagger.SingleInstanceIn
import javax.inject.Inject
import timber.log.Timber

@SingleInstanceIn(AppScope::class)
@ContributesMultibinding(AppScope::class)
class ReinstallAtbListener @Inject constructor(
private val statisticsDataStore: StatisticsDataStore,
private val backupDataStore: BackupDataStore,
private val backupDataStore: BackupServiceDataStore,
) : AtbInitializerListener {
override suspend fun beforeAtbInit() {
if (statisticsDataStore.hasInstallationStatistics && backupDataStore.atb != statisticsDataStore.atb) {
backupDataStore.atb = statisticsDataStore.atb
}
if (!statisticsDataStore.hasInstallationStatistics && backupDataStore.atb != null) {
backupDataStore.atb = null
statisticsDataStore.variant = REINSTALL_VARIANT
Timber.d("Variant update for returning user")
}
backupDataStore.clearBackupPreferences()
}

override fun beforeAtbInitTimeoutMillis(): Long = MAX_REINSTALL_WAIT_TIME_MS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2024 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.reinstalls

import com.duckduckgo.common.test.CoroutineTestRule
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify

class ReinstallAtbListenerTest {

private lateinit var testee: ReinstallAtbListener

private val mockBackupDataStore: BackupServiceDataStore = mock()

@get:Rule
val coroutineTestRule: CoroutineTestRule = CoroutineTestRule()

@Before
fun before() {
testee = ReinstallAtbListener(mockBackupDataStore)
}

@Test
fun whenBeforeAtbInitIsCalledThenClearBackupServiceSharedPreferences() = runTest {
testee.beforeAtbInit()

verify(mockBackupDataStore).clearBackupPreferences()
}
}
1 change: 0 additions & 1 deletion backup-agent/backup-agent-api/.gitignore

This file was deleted.

37 changes: 0 additions & 37 deletions backup-agent/backup-agent-api/build.gradle

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion backup-agent/backup-agent-impl/.gitignore

This file was deleted.

74 changes: 0 additions & 74 deletions backup-agent/backup-agent-impl/build.gradle

This file was deleted.

This file was deleted.

Loading

0 comments on commit 290ec47

Please sign in to comment.