Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class AutofillSaveActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val repo = PasswordRepository.getRepositoryDirectory()
val saveRoot = AutofillPreferences.saveDirectory(this)
val saveIntent =
Intent(this, PasswordCreationActivity::class.java).apply {
putExtras(
Expand All @@ -136,7 +137,7 @@ class AutofillSaveActivity : AppCompatActivity() {
putString(BasePGPActivity.EXTRA_REPO_PATH, repo.absolutePath)
putString(
BasePGPActivity.EXTRA_FILE_PATH,
repo
saveRoot
.resolve(intent.getStringExtra(EXTRA_FOLDER_NAME) ?: throw NullPointerException())
.absolutePath,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ class AutofillSettings(private val activity: FragmentActivity) : SettingsProvide
summaryProvider = { activity.getString(R.string.preference_custom_public_suffixes_summary) }
textInputHintRes = R.string.preference_custom_public_suffixes_hint
}
editText(PreferenceKeys.AUTOFILL_SAVE_DIRECTORY) {
dependency = PreferenceKeys.AUTOFILL_ENABLE
titleRes = R.string.preference_autofill_save_directory_title
summaryProvider = { value ->
activity.getString(
R.string.preference_autofill_save_directory_summary,
value?.takeUnless { it.isBlank() }
?: activity.getString(R.string.preference_autofill_save_directory_root_placeholder),
)
}
textInputHintRes = R.string.preference_autofill_save_directory_hint
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package app.passwordstore.util.autofill
import android.content.Context
import androidx.core.content.edit
import app.passwordstore.data.passfile.PasswordEntry
import app.passwordstore.data.repo.PasswordRepository
import app.passwordstore.util.extensions.getString
import app.passwordstore.util.extensions.sharedPrefs
import app.passwordstore.util.services.getDefaultUsername
Expand All @@ -22,6 +23,25 @@ object AutofillPreferences {
return DirectoryStructure.fromValue(value)
}

/**
* The directory Autofill-saved credentials should be placed under, relative to the repository
* root. Backed by [PreferenceKeys.AUTOFILL_SAVE_DIRECTORY]; falls back to the repository root
* itself when unset. This only affects saves made through the Autofill framework (the system
* "Save to Password Store?" prompt) — it has no effect on entries created from within the app.
*/
fun saveDirectory(context: Context): File {
val root = PasswordRepository.getRepositoryDirectory()
// Drop empty and ".." segments to prevent escaping the repository root.
val configured =
context.sharedPrefs
.getString(PreferenceKeys.AUTOFILL_SAVE_DIRECTORY)
?.split('/')
?.filter { it.isNotBlank() && it != ".." }
?.joinToString("/")
?.takeUnless { it.isBlank() }
return if (configured == null) root else root.resolve(configured)
}

fun strictDomainSearch(context: Context): Boolean {
return context.sharedPrefs.getBoolean(PreferenceKeys.STRICT_DOMAIN_SEARCH, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ object PreferenceKeys {
const val OREO_AUTOFILL_CUSTOM_PUBLIC_SUFFIXES = "oreo_autofill_custom_public_suffixes"
const val OREO_AUTOFILL_DEFAULT_USERNAME = "oreo_autofill_default_username"
const val DIRECTORY_STRUCTURE = "oreo_autofill_directory_structure"
const val AUTOFILL_SAVE_DIRECTORY = "oreo_autofill_save_directory"
const val STRICT_DOMAIN_SEARCH = "oreo_autofill_strict_domain_search"
const val PREF_KEY_PWGEN_TYPE = "pref_key_pwgen_type"
const val REPOSITORY_INITIALIZED = "repository_initialized"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@
<string name="preference_custom_public_suffixes_title">Custom domains</string>
<string name="preference_custom_public_suffixes_summary">Autofill will distinguish subdomains of these domains.</string>
<string name="preference_custom_public_suffixes_hint">company.com\npersonal.com</string>
<string name="preference_autofill_save_directory_title">Save directory</string>
<string name="preference_autofill_save_directory_summary">Credentials saved via Autofill are placed under this folder instead of the store root. Currently: %1$s</string>
<string name="preference_autofill_save_directory_hint">e.g. www</string>
<string name="preference_autofill_save_directory_root_placeholder">store root</string>

<!-- Password creation/edit -->
<string name="password_creation_edit_file_encryption_success_title">Password item edited</string>
Expand Down