Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove backup service #4061

Merged
merged 4 commits into from
Jan 11, 2024
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
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"
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept this class because the new approach will be also added here so we can assign ru variant before initialisation.
I thought it was a good place to also add the preferences removal for the moment.

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
Loading