diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/ExpertSettingsFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/ExpertSettingsFragment.kt index 94243f06..72c701df 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/ExpertSettingsFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/ExpertSettingsFragment.kt @@ -5,11 +5,15 @@ package com.stevesoltys.seedvault.settings +import android.app.backup.IBackupManager import android.os.Bundle import androidx.activity.result.contract.ActivityResultContracts.CreateDocument import androidx.preference.Preference +import androidx.preference.Preference.OnPreferenceChangeListener import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreferenceCompat +import androidx.preference.TwoStatePreference +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.mms.ContentType.TEXT_PLAIN import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.permitDiskReads @@ -21,6 +25,9 @@ class ExpertSettingsFragment : PreferenceFragmentCompat() { private val viewModel: SettingsViewModel by sharedViewModel() private val packageService: PackageService by inject() + private val backupManager: IBackupManager by inject() + + private lateinit var apkBackup: TwoStatePreference private val createFileLauncher = registerForActivityResult(CreateDocument(TEXT_PLAIN)) { uri -> @@ -32,6 +39,25 @@ class ExpertSettingsFragment : PreferenceFragmentCompat() { setPreferencesFromResource(R.xml.settings_expert, rootKey) } + apkBackup = findPreference(PREF_KEY_BACKUP_APK)!! + apkBackup.onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue -> + val enable = newValue as Boolean + if (enable) return@OnPreferenceChangeListener true + MaterialAlertDialogBuilder(requireContext()) + .setIcon(R.drawable.ic_warning) + .setTitle(R.string.settings_backup_apk_dialog_title) + .setMessage(R.string.settings_backup_apk_dialog_message) + .setPositiveButton(R.string.settings_backup_apk_dialog_cancel) { dialog, _ -> + dialog.dismiss() + } + .setNegativeButton(R.string.settings_backup_apk_dialog_disable) { dialog, _ -> + apkBackup.isChecked = false + dialog.dismiss() + } + .show() + return@OnPreferenceChangeListener false + } + findPreference("logcat")?.setOnPreferenceClickListener { val versionName = packageService.getVersionName(requireContext().packageName) ?: "ver" val timestamp = System.currentTimeMillis() @@ -51,5 +77,6 @@ class ExpertSettingsFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() activity?.setTitle(R.string.settings_expert_title) + apkBackup.isEnabled = backupManager.isBackupEnabled } } diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt index 04aad46f..3d85f58e 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt @@ -47,7 +47,6 @@ class SettingsFragment : PreferenceFragmentCompat() { private lateinit var backup: TwoStatePreference private lateinit var autoRestore: TwoStatePreference - private lateinit var apkBackup: TwoStatePreference private lateinit var backupLocation: Preference private lateinit var backupStatus: Preference private lateinit var backupScheduling: Preference @@ -121,24 +120,6 @@ class SettingsFragment : PreferenceFragmentCompat() { } } - apkBackup = findPreference(PREF_KEY_BACKUP_APK)!! - apkBackup.onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue -> - val enable = newValue as Boolean - if (enable) return@OnPreferenceChangeListener true - MaterialAlertDialogBuilder(requireContext()) - .setIcon(R.drawable.ic_warning) - .setTitle(R.string.settings_backup_apk_dialog_title) - .setMessage(R.string.settings_backup_apk_dialog_message) - .setPositiveButton(R.string.settings_backup_apk_dialog_cancel) { dialog, _ -> - dialog.dismiss() - } - .setNegativeButton(R.string.settings_backup_apk_dialog_disable) { dialog, _ -> - apkBackup.isChecked = false - dialog.dismiss() - } - .show() - return@OnPreferenceChangeListener false - } backupStatus = findPreference("backup_status")!! backupScheduling = findPreference("backup_scheduling")!! diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/RequireProvisioningViewModel.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/RequireProvisioningViewModel.kt index a7858eeb..e64ef397 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/RequireProvisioningViewModel.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/RequireProvisioningViewModel.kt @@ -7,8 +7,9 @@ package com.stevesoltys.seedvault.ui import android.app.Application import androidx.lifecycle.AndroidViewModel -import com.stevesoltys.seedvault.crypto.KeyManager import com.stevesoltys.seedvault.backend.BackendManager +import com.stevesoltys.seedvault.crypto.KeyManager +import com.stevesoltys.seedvault.permitDiskReads import com.stevesoltys.seedvault.settings.SettingsManager abstract class RequireProvisioningViewModel( @@ -26,7 +27,7 @@ abstract class RequireProvisioningViewModel( internal fun validLocationIsSet() = backendManager.isValidAppPluginSet() - internal fun recoveryCodeIsSet() = keyManager.hasBackupKey() + internal fun recoveryCodeIsSet() = permitDiskReads { keyManager.hasBackupKey() } open fun onStorageLocationChanged() { // noop can be overwritten by sub-classes diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 17e54794..3cf42ea8 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -43,13 +43,6 @@ app:title="@string/settings_auto_restore_title" tools:defaultValue="true" /> - - - @@ -9,6 +8,14 @@ android:key="unlimited_quota" android:summary="@string/settings_expert_quota_summary" android:title="@string/settings_expert_quota_title" /> + + +