diff options
author | Torsten Grote <t@grobox.de> | 2022-11-01 15:36:17 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2022-11-01 15:36:17 -0300 |
commit | 55624eb33bae14380efe8ca085dc420390b23702 (patch) | |
tree | 3188915ef630ba9a170e2c54d4e475158aca4c15 | |
parent | 3a6662437dd0a017d6d75ea59eda8524e6fb58e9 (diff) | |
download | taler-android-55624eb33bae14380efe8ca085dc420390b23702.tar.gz taler-android-55624eb33bae14380efe8ca085dc420390b23702.tar.bz2 taler-android-55624eb33bae14380efe8ca085dc420390b23702.zip |
[wallet] Allow exporting the entire DB
6 files changed, 79 insertions, 2 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt index f99f38d..06e0627 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt @@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap import kotlin.system.exitProcess private const val TAG = "taler-wallet-backend" +const val WALLET_DB = "talerwalletdb-v30.json" class RequestData(val clientRequestId: Int, val messenger: Messenger) @@ -83,7 +84,7 @@ class WalletBackendService : Service() { msg.put("operation", "init") val args = JSONObject() msg.put("args", args) - args.put("persistentStoragePath", "${application.filesDir}/talerwalletdb-v30.json") + args.put("persistentStoragePath", "${application.filesDir}/$WALLET_DB") akono.sendMessage(msg.toString()) } diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt b/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt index ecf45a6..3d31dc5 100644 --- a/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt @@ -48,6 +48,7 @@ class SettingsFragment : PreferenceFragmentCompat() { private lateinit var prefDevMode: SwitchPreferenceCompat private lateinit var prefWithdrawTest: Preference private lateinit var prefLogcat: Preference + private lateinit var prefExportDb: Preference private lateinit var prefVersionApp: Preference private lateinit var prefVersionCore: Preference private lateinit var prefVersionExchange: Preference @@ -58,6 +59,7 @@ class SettingsFragment : PreferenceFragmentCompat() { prefBackup, prefWithdrawTest, prefLogcat, + prefExportDb, prefVersionApp, prefVersionCore, prefVersionExchange, @@ -69,6 +71,9 @@ class SettingsFragment : PreferenceFragmentCompat() { private val logLauncher = registerForActivityResult(CreateDocument("text/plain")) { uri -> settingsManager.exportLogcat(uri) } + private val dbExportLauncher = registerForActivityResult(CreateDocument("application/json")) { uri -> + settingsManager.exportDb(uri) + } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.settings_main, rootKey) @@ -76,6 +81,7 @@ class SettingsFragment : PreferenceFragmentCompat() { prefDevMode = findPreference("pref_dev_mode")!! prefWithdrawTest = findPreference("pref_testkudos")!! prefLogcat = findPreference("pref_logcat")!! + prefExportDb = findPreference("pref_export_db")!! prefVersionApp = findPreference("pref_version_app")!! prefVersionCore = findPreference("pref_version_core")!! prefVersionExchange = findPreference("pref_version_protocol_exchange")!! @@ -125,6 +131,10 @@ class SettingsFragment : PreferenceFragmentCompat() { logLauncher.launch("taler-wallet-log-${currentTimeMillis()}.txt") true } + prefExportDb.setOnPreferenceClickListener { + dbExportLauncher.launch("taler-wallet-db-${currentTimeMillis()}.json") + true + } prefReset.setOnPreferenceClickListener { showResetDialog() diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsManager.kt b/wallet/src/main/java/net/taler/wallet/settings/SettingsManager.kt index 6bf1673..349c7b1 100644 --- a/wallet/src/main/java/net/taler/wallet/settings/SettingsManager.kt +++ b/wallet/src/main/java/net/taler/wallet/settings/SettingsManager.kt @@ -26,6 +26,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import net.taler.wallet.R +import net.taler.wallet.backend.WALLET_DB class SettingsManager( private val context: Context, @@ -59,4 +60,31 @@ class SettingsManager( Toast.makeText(context, R.string.settings_logcat_error, LENGTH_LONG).show() } + fun exportDb(uri: Uri?) { + if (uri == null) { + onDbExportError() + return + } + scope.launch(Dispatchers.IO) { + try { + context.contentResolver.openOutputStream(uri, "wt")?.use { outputStream -> + context.openFileInput(WALLET_DB).use { inputStream -> + inputStream.copyTo(outputStream) + } + } ?: onDbExportError() + } catch (e: Exception) { + Log.e(SettingsManager::class.simpleName, "Error exporting db: ", e) + onDbExportError() + return@launch + } + withContext(Dispatchers.Main) { + Toast.makeText(context, R.string.settings_db_export_success, LENGTH_LONG).show() + } + } + } + + private fun onDbExportError() { + Toast.makeText(context, R.string.settings_db_export_error, LENGTH_LONG).show() + } + } diff --git a/wallet/src/main/res/drawable/ic_unarchive.xml b/wallet/src/main/res/drawable/ic_unarchive.xml new file mode 100644 index 0000000..e6faf51 --- /dev/null +++ b/wallet/src/main/res/drawable/ic_unarchive.xml @@ -0,0 +1,26 @@ +<!-- + ~ This file is part of GNU Taler + ~ (C) 2022 Taler Systems S.A. + ~ + ~ GNU Taler is free software; you can redistribute it and/or modify it under the + ~ terms of the GNU General Public License as published by the Free Software + ~ Foundation; either version 3, or (at your option) any later version. + ~ + ~ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + ~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + ~ A PARTICULAR PURPOSE. See the GNU General Public License for more details. + ~ + ~ You should have received a copy of the GNU General Public License along with + ~ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + --> + +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:tint="#000000" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="?attr/colorControlNormal" + android:pathData="M20.55,5.22l-1.39,-1.68C18.88,3.21 18.47,3 18,3H6C5.53,3 5.12,3.21 4.85,3.55L3.46,5.22C3.17,5.57 3,6.01 3,6.5V19c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V6.5C21,6.01 20.83,5.57 20.55,5.22zM12,9.5l5.5,5.5H14v2h-4v-2H6.5L12,9.5zM5.12,5l0.82,-1h12l0.93,1H5.12z" /> +</vector> diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml index 2b81894..5fba9f1 100644 --- a/wallet/src/main/res/values/strings.xml +++ b/wallet/src/main/res/values/strings.xml @@ -214,9 +214,13 @@ GNU Taler is immune against many types of fraud, such as phishing of credit card <string name="settings_withdraw_testkudos">Withdraw TESTKUDOS</string> <string name="settings_withdraw_testkudos_summary">Get money for testing</string> <string name="settings_logcat">Debug log</string> - <string name="settings_logcat_summary">View/send internal log</string> + <string name="settings_logcat_summary">Save internal log</string> <string name="settings_logcat_error">Error exporting log</string> <string name="settings_logcat_success">Log exported to file</string> + <string name="settings_db_export">Database</string> + <string name="settings_db_export_summary">Save internal database</string> + <string name="settings_db_export_error">Error exporting database</string> + <string name="settings_db_export_success">Database exported to file</string> <string name="settings_version_app">App Version</string> <string name="settings_version_core">Wallet Core Version</string> <string name="settings_version_protocol_exchange">Supported Exchange Versions</string> diff --git a/wallet/src/main/res/xml/settings_main.xml b/wallet/src/main/res/xml/settings_main.xml index a713838..101aa37 100644 --- a/wallet/src/main/res/xml/settings_main.xml +++ b/wallet/src/main/res/xml/settings_main.xml @@ -55,6 +55,14 @@ tools:isPreferenceVisible="true" /> <Preference + app:icon="@drawable/ic_unarchive" + app:isPreferenceVisible="false" + app:key="pref_export_db" + app:summary="@string/settings_db_export_summary" + app:title="@string/settings_db_export" + tools:isPreferenceVisible="true" /> + + <Preference app:icon="@drawable/ic_account_balance_wallet" app:isPreferenceVisible="false" app:key="pref_version_app" |