From 57771c4dfee862c8eb87777c59ad1b1dced04de3 Mon Sep 17 00:00:00 2001 From: Fabian Henneke Date: Thu, 26 Mar 2020 19:49:28 +0100 Subject: Fix: Commit file after Autofill generate/save (#669) Currently, password files generated via the Autofill generate or save flow are not committed to the Git repository and therefore also not synchronized to the remote. The root cause is that it was missed that PgpActivity relies on PasswordStore to commit the changes when it returns an appropriate result code. The fix is to extract the commit code into the companion object of PasswordStore and call it from AutofillSaveActivity's onActivityResult. --- .../main/java/com/zeapo/pwdstore/PasswordStore.kt | 23 ++++++++++++++-------- .../autofill/oreo/ui/AutofillSaveActivity.kt | 14 ++++++++----- 2 files changed, 24 insertions(+), 13 deletions(-) (limited to 'app') diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt index 9ee28f09..72fbee8d 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.kt @@ -548,14 +548,7 @@ class PasswordStore : AppCompatActivity() { get() = plist?.currentDir ?: getRepositoryDirectory(applicationContext) private fun commitChange(message: String) { - object : GitOperation(getRepositoryDirectory(activity), activity) { - override fun execute() { - Timber.tag(TAG).d("Committing with message $message") - val git = Git(repository) - val tasks = GitAsyncTask(activity, false, true, this) - tasks.execute(git.add().addFilepattern("."), git.commit().setAll(true).setMessage(message)) - } - }.execute() + Companion.commitChange(activity, message) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { @@ -772,5 +765,19 @@ class PasswordStore : AppCompatActivity() { return (!Character.isISOControl(c) && block != null && block !== UnicodeBlock.SPECIALS) } + + fun commitChange(activity: Activity, message: String) { + object : GitOperation(getRepositoryDirectory(activity), activity) { + override fun execute() { + Timber.tag(TAG).d("Committing with message $message") + val git = Git(repository) + val tasks = GitAsyncTask(activity, false, true, this) + tasks.execute( + git.add().addFilepattern("."), + git.commit().setAll(true).setMessage(message) + ) + } + }.execute() + } } } diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt index e5def0fb..3a4831d6 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt @@ -16,6 +16,7 @@ import androidx.annotation.RequiresApi import androidx.core.os.bundleOf import com.github.ajalt.timberkt.e import com.zeapo.pwdstore.PasswordStore +import com.zeapo.pwdstore.R import com.zeapo.pwdstore.autofill.oreo.AutofillAction import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences @@ -114,12 +115,15 @@ class AutofillSaveActivity : Activity() { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == PasswordStore.REQUEST_CODE_ENCRYPT && resultCode == RESULT_OK && data != null) { - val createdPath = data.getStringExtra("CREATED_FILE") - if (createdPath != null) { - formOrigin?.let { - AutofillMatcher.addMatchFor(this, it, File(createdPath)) - } + val createdPath = data.getStringExtra("CREATED_FILE")!! + formOrigin?.let { + AutofillMatcher.addMatchFor(this, it, File(createdPath)) } + val longName = data.getStringExtra("LONG_NAME")!! + // PgpActivity delegates committing the added file to PasswordStore. Since PasswordStore + // is not involved in an AutofillScenario, we have to commit the file ourself. + PasswordStore.commitChange(this, getString(R.string.git_commit_add_text, longName)) + val password = data.getStringExtra("PASSWORD") val username = data.getStringExtra("USERNAME") if (password != null) { -- cgit v1.2.3