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.
This commit is contained in:
Fabian Henneke 2020-03-26 19:49:28 +01:00 committed by GitHub
parent de4cc63860
commit 57771c4dfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 13 deletions

View file

@ -548,14 +548,7 @@ class PasswordStore : AppCompatActivity() {
get() = plist?.currentDir ?: getRepositoryDirectory(applicationContext) get() = plist?.currentDir ?: getRepositoryDirectory(applicationContext)
private fun commitChange(message: String) { private fun commitChange(message: String) {
object : GitOperation(getRepositoryDirectory(activity), activity) { Companion.commitChange(activity, message)
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()
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@ -772,5 +765,19 @@ class PasswordStore : AppCompatActivity() {
return (!Character.isISOControl(c) && return (!Character.isISOControl(c) &&
block != null && block !== UnicodeBlock.SPECIALS) 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()
}
} }
} }

View file

@ -16,6 +16,7 @@ import androidx.annotation.RequiresApi
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import com.github.ajalt.timberkt.e import com.github.ajalt.timberkt.e
import com.zeapo.pwdstore.PasswordStore import com.zeapo.pwdstore.PasswordStore
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.autofill.oreo.AutofillAction import com.zeapo.pwdstore.autofill.oreo.AutofillAction
import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher
import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences
@ -114,12 +115,15 @@ class AutofillSaveActivity : Activity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
if (requestCode == PasswordStore.REQUEST_CODE_ENCRYPT && resultCode == RESULT_OK && data != null) { if (requestCode == PasswordStore.REQUEST_CODE_ENCRYPT && resultCode == RESULT_OK && data != null) {
val createdPath = data.getStringExtra("CREATED_FILE") val createdPath = data.getStringExtra("CREATED_FILE")!!
if (createdPath != null) { formOrigin?.let {
formOrigin?.let { AutofillMatcher.addMatchFor(this, it, File(createdPath))
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 password = data.getStringExtra("PASSWORD")
val username = data.getStringExtra("USERNAME") val username = data.getStringExtra("USERNAME")
if (password != null) { if (password != null) {