Fix repository corruption by AutofillSaveActivity (#699)

This commit is contained in:
Fabian Henneke 2020-04-14 00:21:59 +02:00 committed by GitHub
parent 11c7e36986
commit 0d54a687d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 37 deletions

View file

@ -796,12 +796,12 @@ class PasswordStore : AppCompatActivity() {
block != null && block !== UnicodeBlock.SPECIALS) block != null && block !== UnicodeBlock.SPECIALS)
} }
fun commitChange(activity: Activity, message: String) { fun commitChange(activity: Activity, message: String, finishWithResultOnEnd: Intent? = null) {
object : GitOperation(getRepositoryDirectory(activity), activity) { object : GitOperation(getRepositoryDirectory(activity), activity) {
override fun execute() { override fun execute() {
Timber.tag(TAG).d("Committing with message $message") Timber.tag(TAG).d("Committing with message $message")
val git = Git(repository) val git = Git(repository)
val tasks = GitAsyncTask(activity, false, true, this) val tasks = GitAsyncTask(activity, true, this, finishWithResultOnEnd)
tasks.execute( tasks.execute(
git.add().addFilepattern("."), git.add().addFilepattern("."),
git.commit().setAll(true).setMessage(message) git.commit().setAll(true).setMessage(message)

View file

@ -120,13 +120,8 @@ class AutofillSaveActivity : Activity() {
AutofillMatcher.addMatchFor(this, it, File(createdPath)) AutofillMatcher.addMatchFor(this, it, File(createdPath))
} }
val longName = data.getStringExtra("LONG_NAME")!! val longName = data.getStringExtra("LONG_NAME")!!
// PgpActivity delegates committing the added file to PasswordStore. Since PasswordStore val password = data.getStringExtra("PASSWORD")!!
// 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") val username = data.getStringExtra("USERNAME")
if (password != null) {
val clientState = val clientState =
intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE) ?: run { intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE) ?: run {
e { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" } e { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" }
@ -140,11 +135,19 @@ class AutofillSaveActivity : Activity() {
clientState, clientState,
AutofillAction.Generate AutofillAction.Generate
) )
setResult(RESULT_OK, Intent().apply { val result = Intent().apply {
putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, fillInDataset) putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, fillInDataset)
})
}
} }
// PgpActivity delegates committing the added file to PasswordStore. Since PasswordStore
// is not involved in an AutofillScenario, we have to commit the file ourselves.
PasswordStore.commitChange(
this,
getString(R.string.git_commit_add_text, longName),
finishWithResultOnEnd = result
)
// GitAsyncTask will finish the activity for us.
} else {
finish() finish()
} }
} }
}

View file

@ -58,7 +58,7 @@ class BreakOutOfDetached(fileDir: File, callingActivity: Activity) : GitOperatio
} }
} }
} }
GitAsyncTask(callingActivity, false, true, this) GitAsyncTask(callingActivity, true, this, null)
.execute(*this.commands.toTypedArray()) .execute(*this.commands.toTypedArray())
} }

View file

@ -5,6 +5,7 @@
package com.zeapo.pwdstore.git package com.zeapo.pwdstore.git
import android.app.Activity import android.app.Activity
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R import com.zeapo.pwdstore.R
import java.io.File import java.io.File
@ -60,7 +61,7 @@ class CloneOperation(fileDir: File, callingActivity: Activity) : GitOperation(fi
override fun execute() { override fun execute() {
(this.command as? CloneCommand)?.setCredentialsProvider(this.provider) (this.command as? CloneCommand)?.setCredentialsProvider(this.provider)
GitAsyncTask(callingActivity, true, false, this).execute(this.command) GitAsyncTask(callingActivity, false, this, Intent()).execute(this.command)
} }
override fun onError(errorMessage: String) { override fun onError(errorMessage: String) {

View file

@ -6,6 +6,7 @@ package com.zeapo.pwdstore.git;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import com.zeapo.pwdstore.PasswordStore; import com.zeapo.pwdstore.PasswordStore;
import com.zeapo.pwdstore.R; import com.zeapo.pwdstore.R;
@ -22,20 +23,20 @@ import org.eclipse.jgit.transport.RemoteRefUpdate;
public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> { public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
private WeakReference<Activity> activityWeakReference; private WeakReference<Activity> activityWeakReference;
private boolean finishOnEnd;
private boolean refreshListOnEnd; private boolean refreshListOnEnd;
private ProgressDialog dialog; private ProgressDialog dialog;
private GitOperation operation; private GitOperation operation;
private Intent finishWithResultOnEnd;
public GitAsyncTask( public GitAsyncTask(
Activity activity, Activity activity,
boolean finishOnEnd,
boolean refreshListOnEnd, boolean refreshListOnEnd,
GitOperation operation) { GitOperation operation,
Intent finishWithResultOnEnd) {
this.activityWeakReference = new WeakReference<>(activity); this.activityWeakReference = new WeakReference<>(activity);
this.finishOnEnd = finishOnEnd;
this.refreshListOnEnd = refreshListOnEnd; this.refreshListOnEnd = refreshListOnEnd;
this.operation = operation; this.operation = operation;
this.finishWithResultOnEnd = finishWithResultOnEnd;
dialog = new ProgressDialog(getActivity()); dialog = new ProgressDialog(getActivity());
} }
@ -124,8 +125,8 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
} else { } else {
this.operation.onSuccess(); this.operation.onSuccess();
if (finishOnEnd) { if (finishWithResultOnEnd != null) {
this.getActivity().setResult(Activity.RESULT_OK); this.getActivity().setResult(Activity.RESULT_OK, finishWithResultOnEnd);
this.getActivity().finish(); this.getActivity().finish();
} }

View file

@ -5,6 +5,7 @@
package com.zeapo.pwdstore.git package com.zeapo.pwdstore.git
import android.app.Activity import android.app.Activity
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R import com.zeapo.pwdstore.R
import java.io.File import java.io.File
@ -34,7 +35,7 @@ class PullOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
override fun execute() { override fun execute() {
(this.command as? PullCommand)?.setCredentialsProvider(this.provider) (this.command as? PullCommand)?.setCredentialsProvider(this.provider)
GitAsyncTask(callingActivity, true, false, this).execute(this.command) GitAsyncTask(callingActivity, false, this, Intent()).execute(this.command)
} }
override fun onError(errorMessage: String) { override fun onError(errorMessage: String) {

View file

@ -5,6 +5,7 @@
package com.zeapo.pwdstore.git package com.zeapo.pwdstore.git
import android.app.Activity import android.app.Activity
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R import com.zeapo.pwdstore.R
import java.io.File import java.io.File
@ -34,7 +35,7 @@ class PushOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
override fun execute() { override fun execute() {
(this.command as? PushCommand)?.setCredentialsProvider(this.provider) (this.command as? PushCommand)?.setCredentialsProvider(this.provider)
GitAsyncTask(callingActivity, true, false, this).execute(this.command) GitAsyncTask(callingActivity, false, this, Intent()).execute(this.command)
} }
override fun onError(errorMessage: String) { override fun onError(errorMessage: String) {

View file

@ -5,6 +5,7 @@
package com.zeapo.pwdstore.git package com.zeapo.pwdstore.git
import android.app.Activity import android.app.Activity
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R import com.zeapo.pwdstore.R
import java.io.File import java.io.File
@ -39,7 +40,7 @@ class ResetToRemoteOperation(fileDir: File, callingActivity: Activity) : GitOper
override fun execute() { override fun execute() {
this.fetchCommand?.setCredentialsProvider(this.provider) this.fetchCommand?.setCredentialsProvider(this.provider)
GitAsyncTask(callingActivity, true, false, this) GitAsyncTask(callingActivity, false, this, Intent())
.execute(this.addCommand, this.fetchCommand, this.resetCommand) .execute(this.addCommand, this.fetchCommand, this.resetCommand)
} }

View file

@ -5,6 +5,7 @@
package com.zeapo.pwdstore.git package com.zeapo.pwdstore.git
import android.app.Activity import android.app.Activity
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R import com.zeapo.pwdstore.R
import java.io.File import java.io.File
@ -48,7 +49,7 @@ class SyncOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
this.pullCommand?.setCredentialsProvider(this.provider) this.pullCommand?.setCredentialsProvider(this.provider)
this.pushCommand?.setCredentialsProvider(this.provider) this.pushCommand?.setCredentialsProvider(this.provider)
} }
GitAsyncTask(callingActivity, true, false, this).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand) GitAsyncTask(callingActivity, false, this, Intent()).execute(this.addCommand, this.statusCommand, this.commitCommand, this.pullCommand, this.pushCommand)
} }
override fun onError(errorMessage: String) { override fun onError(errorMessage: String) {