0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 03:52:15 +02:00

Scoped Storage: Enforce Media Sync Before Migration

We need to move the user's data to /Android/ to handle scoped storage
changes. Before we perform this migration, we should ensure that users
data is safe. To do this, we enforce a sync.

A user should have completed a full media sync before the migration
occurs.

This ensures that their data is up to date and can be restored if
anything goes awry with the migration

Dialog wording as discussed on the Figma, with the exception of
changing 'sync' to 'media sync'

Issue 5304
This commit is contained in:
David Allison 2023-03-06 22:47:51 +00:00 committed by Mike Hardy
parent 60fa3261c9
commit 3b3e1fcdc7
2 changed files with 18 additions and 15 deletions

View File

@ -116,7 +116,6 @@ import com.ichi2.widget.WidgetStatus
import kotlinx.coroutines.*
import net.ankiweb.rsdroid.BackendFactory
import net.ankiweb.rsdroid.RustCleanup
import org.intellij.lang.annotations.Language
import org.json.JSONException
import timber.log.Timber
import java.io.File
@ -2528,15 +2527,7 @@ open class DeckPicker :
return
}
val ifYouUninstallMessageId = when {
isLoggedIn() -> R.string.migration_warning_risk_of_data_loss_if_no_update
else -> R.string.migration_update_request_dialog_download_warning
}
@Language("HTML")
val message = """${getString(R.string.migration_update_request)}
<br>
<br>${getString(ifYouUninstallMessageId)}"""
val message = getString(R.string.migration_update_request_requires_media_sync)
fun onPostponeOnce() {
if (shownAutomatically) {
@ -2565,7 +2556,12 @@ open class DeckPicker :
.setPositiveButton(
getString(R.string.scoped_storage_migrate)
) { _, _ ->
migrate()
if (!BuildConfig.ALLOW_UNSAFE_MIGRATION) {
performMediaSyncBeforeStorageMigration()
} else {
Timber.i("Performing unsafe storage migration")
migrate()
}
}
.setNegativeButton(
getString(R.string.scoped_storage_postpone)
@ -2586,6 +2582,12 @@ open class DeckPicker :
dialog.addScopedStorageLearnMoreLinkAndShow(message)
}
private fun performMediaSyncBeforeStorageMigration() {
Timber.i("Syncing before storage migration")
migrateStorageAfterMediaSyncCompleted = true
sync()
}
// Scoped Storage migration
private fun setMigrationWasLastPostponedAtToNow() {
migrationWasLastPostponedAt = TimeManager.time.intTime()

View File

@ -402,10 +402,7 @@
<string name="sync_impossible_during_migration">Sync is disabled until the migration is done.\n
%1$d media files left to migrate.</string>
<string name="migration_warning_risk_of_data_loss_if_no_update">If you reinstall AnkiDroid, it will not be able to open your collection.</string>
<string name="migration_update_request_dialog_download_warning">If you uninstall AnkiDroid, you will need to download your full collection again.</string>
<string name="migration_update_request">Android storage access policy requires us to change where we store your collection. When your data is migrated AnkiDroid will be faster and your data will be more secure.
You will not be able to sync during the storage migration.</string>
<string name="migration_update_request_requires_media_sync" commnet="use HTML linebreaks in this string">AnkiDroid needs to migrate its storage to comply with Android 10 security policy.\n\nThis will improve media sync performance.&lt;br&gt;&lt;br&gt;During the migration you will be unable to sync and some settings will be disabled. A media sync will occur before the migration starts to keep your data safe.&lt;br&gt;&lt;br&gt;It is safe to use or close AnkiDroid during this process.</string>
<string name="start_migration_progress_message">Starting storage migration. You may resume using AnkiDroid shortly.</string>
<string name="migration_part_1_done_resume">You may resume using AnkiDroid.
\nStorage migration will continue in the background.</string>
@ -456,4 +453,8 @@
comment="Appears on a notification after the user has opted into a storage migration and provided consent to sync
and AnkiDroid was minimised when the sync completed"
>Tap to start storage migration</string>
<string name="media_sync_required_title">Media Sync Required</string>
<string name="media_sync_required_message">You must sync before performing a storage migration</string>
</resources>