From 1ee443a3d8693ca74fb65588499f2c4addf74b56 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 1 Aug 2019 10:34:31 +0200 Subject: [PATCH] Add a unique ID to the device folder name to avoid collisions when using several devices of the same model with the same account --- Android.mk | 8 +++++ app/src/main/AndroidManifest.xml | 6 ++-- .../java/com/stevesoltys/backup/Backup.kt | 34 +++++++++++++++++++ .../com/stevesoltys/backup/Base64Utils.kt | 18 ++++++++++ .../com/stevesoltys/backup/header/Header.kt | 4 --- .../stevesoltys/backup/header/HeaderReader.kt | 1 + .../stevesoltys/backup/header/HeaderWriter.kt | 1 + .../backup/settings/SettingsManager.kt | 15 +++++++- .../backup/transport/PluginManager.kt | 10 ++---- .../transport/backup/FullBackupPlugin.kt | 1 + .../backup/transport/backup/KVBackup.kt | 5 ++- .../backup/transport/backup/KVBackupPlugin.kt | 1 + .../plugins/DocumentsProviderBackupPlugin.kt | 5 --- .../backup/plugins/DocumentsStorage.kt | 6 +++- .../backup/transport/restore/KVRestore.kt | 4 +-- .../backup/header/HeaderReaderTest.kt | 1 + .../transport/CoordinatorIntegrationTest.kt | 9 +++-- .../backup/transport/backup/KVBackupTest.kt | 2 +- .../backup/transport/restore/KVRestoreTest.kt | 7 ++-- ...ult-permissions_com.stevesoltys.backup.xml | 6 ++++ 20 files changed, 108 insertions(+), 36 deletions(-) create mode 100644 app/src/main/java/com/stevesoltys/backup/Base64Utils.kt create mode 100644 default-permissions_com.stevesoltys.backup.xml diff --git a/Android.mk b/Android.mk index f3c3d59b..ed863870 100644 --- a/Android.mk +++ b/Android.mk @@ -1,5 +1,13 @@ LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) +LOCAL_MODULE := default-permissions_com.stevesoltys.backup.xml +LOCAL_MODULE_CLASS := ETC +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/default-permissions +LOCAL_SRC_FILES := $(LOCAL_MODULE) +include $(BUILD_PREBUILT) + include $(CLEAR_VARS) LOCAL_MODULE := permissions_com.stevesoltys.backup.xml LOCAL_MODULE_CLASS := ETC diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6a987969..adcf91b4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,7 +14,9 @@ android:name="android.permission.BACKUP" tools:ignore="ProtectedPermissions" /> - + + + android:label="@string/app_name" /> { - internal val key = String(getUrlDecoder().decode(base64Key)) + internal val key = base64Key.decodeBase64() override fun compareTo(other: DecodedKey) = key.compareTo(other.key) } diff --git a/app/src/test/java/com/stevesoltys/backup/header/HeaderReaderTest.kt b/app/src/test/java/com/stevesoltys/backup/header/HeaderReaderTest.kt index 94b85b6f..1cbc864c 100644 --- a/app/src/test/java/com/stevesoltys/backup/header/HeaderReaderTest.kt +++ b/app/src/test/java/com/stevesoltys/backup/header/HeaderReaderTest.kt @@ -1,5 +1,6 @@ package com.stevesoltys.backup.header +import com.stevesoltys.backup.Utf8 import com.stevesoltys.backup.assertContains import com.stevesoltys.backup.getRandomString import org.junit.jupiter.api.Assertions.* diff --git a/app/src/test/java/com/stevesoltys/backup/transport/CoordinatorIntegrationTest.kt b/app/src/test/java/com/stevesoltys/backup/transport/CoordinatorIntegrationTest.kt index 9622568c..7875db5e 100644 --- a/app/src/test/java/com/stevesoltys/backup/transport/CoordinatorIntegrationTest.kt +++ b/app/src/test/java/com/stevesoltys/backup/transport/CoordinatorIntegrationTest.kt @@ -10,17 +10,16 @@ import android.os.ParcelFileDescriptor import com.stevesoltys.backup.crypto.CipherFactoryImpl import com.stevesoltys.backup.crypto.CryptoImpl import com.stevesoltys.backup.crypto.KeyManagerTestImpl -import com.stevesoltys.backup.transport.backup.* +import com.stevesoltys.backup.encodeBase64 import com.stevesoltys.backup.header.HeaderReaderImpl import com.stevesoltys.backup.header.HeaderWriterImpl -import com.stevesoltys.backup.header.Utf8 +import com.stevesoltys.backup.transport.backup.* import com.stevesoltys.backup.transport.restore.* import io.mockk.* import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream -import java.util.* import kotlin.random.Random internal class CoordinatorIntegrationTest : TransportTest() { @@ -53,9 +52,9 @@ internal class CoordinatorIntegrationTest : TransportTest() { private val appData = ByteArray(42).apply { Random.nextBytes(this) } private val appData2 = ByteArray(1337).apply { Random.nextBytes(this) } private val key = "RestoreKey" - private val key64 = Base64.getUrlEncoder().withoutPadding().encodeToString(key.toByteArray(Utf8)) + private val key64 = key.encodeBase64() private val key2 = "RestoreKey2" - private val key264 = Base64.getUrlEncoder().withoutPadding().encodeToString(key2.toByteArray(Utf8)) + private val key264 = key2.encodeBase64() init { every { backupPlugin.kvBackupPlugin } returns kvBackupPlugin diff --git a/app/src/test/java/com/stevesoltys/backup/transport/backup/KVBackupTest.kt b/app/src/test/java/com/stevesoltys/backup/transport/backup/KVBackupTest.kt index 5362415b..422c3aab 100644 --- a/app/src/test/java/com/stevesoltys/backup/transport/backup/KVBackupTest.kt +++ b/app/src/test/java/com/stevesoltys/backup/transport/backup/KVBackupTest.kt @@ -2,9 +2,9 @@ package com.stevesoltys.backup.transport.backup import android.app.backup.BackupDataInput import android.app.backup.BackupTransport.* +import com.stevesoltys.backup.Utf8 import com.stevesoltys.backup.getRandomString import com.stevesoltys.backup.header.MAX_KEY_LENGTH_SIZE -import com.stevesoltys.backup.header.Utf8 import com.stevesoltys.backup.header.VersionHeader import io.mockk.Runs import io.mockk.every diff --git a/app/src/test/java/com/stevesoltys/backup/transport/restore/KVRestoreTest.kt b/app/src/test/java/com/stevesoltys/backup/transport/restore/KVRestoreTest.kt index f0237ce8..2d345d2f 100644 --- a/app/src/test/java/com/stevesoltys/backup/transport/restore/KVRestoreTest.kt +++ b/app/src/test/java/com/stevesoltys/backup/transport/restore/KVRestoreTest.kt @@ -3,9 +3,9 @@ package com.stevesoltys.backup.transport.restore import android.app.backup.BackupDataOutput import android.app.backup.BackupTransport.TRANSPORT_ERROR import android.app.backup.BackupTransport.TRANSPORT_OK +import com.stevesoltys.backup.encodeBase64 import com.stevesoltys.backup.getRandomByteArray import com.stevesoltys.backup.header.UnsupportedVersionException -import com.stevesoltys.backup.header.Utf8 import com.stevesoltys.backup.header.VERSION import com.stevesoltys.backup.header.VersionHeader import io.mockk.* @@ -14,7 +14,6 @@ import org.junit.jupiter.api.Assertions.assertThrows import org.junit.jupiter.api.Test import java.io.IOException import java.io.InputStream -import java.util.Base64.getUrlEncoder import kotlin.random.Random internal class KVRestoreTest : RestoreTest() { @@ -24,10 +23,10 @@ internal class KVRestoreTest : RestoreTest() { private val restore = KVRestore(plugin, outputFactory, headerReader, crypto) private val key = "Restore Key" - private val key64 = getUrlEncoder().withoutPadding().encodeToString(key.toByteArray(Utf8)) + private val key64 = key.encodeBase64() private val versionHeader = VersionHeader(VERSION, packageInfo.packageName, key) private val key2 = "Restore Key2" - private val key264 = getUrlEncoder().withoutPadding().encodeToString(key2.toByteArray(Utf8)) + private val key264 = key2.encodeBase64() private val versionHeader2 = VersionHeader(VERSION, packageInfo.packageName, key2) @Test diff --git a/default-permissions_com.stevesoltys.backup.xml b/default-permissions_com.stevesoltys.backup.xml new file mode 100644 index 00000000..825c0049 --- /dev/null +++ b/default-permissions_com.stevesoltys.backup.xml @@ -0,0 +1,6 @@ + + + + + +