Fix repository corruption by AutofillSaveActivity (#699)
This commit is contained in:
parent
11c7e36986
commit
0d54a687d6
9 changed files with 46 additions and 37 deletions
|
@ -796,12 +796,12 @@ class PasswordStore : AppCompatActivity() {
|
|||
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) {
|
||||
override fun execute() {
|
||||
Timber.tag(TAG).d("Committing with message $message")
|
||||
val git = Git(repository)
|
||||
val tasks = GitAsyncTask(activity, false, true, this)
|
||||
val tasks = GitAsyncTask(activity, true, this, finishWithResultOnEnd)
|
||||
tasks.execute(
|
||||
git.add().addFilepattern("."),
|
||||
git.commit().setAll(true).setMessage(message)
|
||||
|
|
|
@ -120,31 +120,34 @@ class AutofillSaveActivity : Activity() {
|
|||
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")
|
||||
if (password != null) {
|
||||
val clientState =
|
||||
intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE) ?: run {
|
||||
e { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" }
|
||||
finish()
|
||||
return
|
||||
}
|
||||
val credentials = Credentials(username, password)
|
||||
val fillInDataset = FillableForm.makeFillInDataset(
|
||||
this,
|
||||
credentials,
|
||||
clientState,
|
||||
AutofillAction.Generate
|
||||
)
|
||||
setResult(RESULT_OK, Intent().apply {
|
||||
putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, fillInDataset)
|
||||
})
|
||||
val clientState =
|
||||
intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE) ?: run {
|
||||
e { "AutofillDecryptActivity started without EXTRA_CLIENT_STATE" }
|
||||
finish()
|
||||
return
|
||||
}
|
||||
val credentials = Credentials(username, password)
|
||||
val fillInDataset = FillableForm.makeFillInDataset(
|
||||
this,
|
||||
credentials,
|
||||
clientState,
|
||||
AutofillAction.Generate
|
||||
)
|
||||
val result = Intent().apply {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package com.zeapo.pwdstore.git
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.zeapo.pwdstore.R
|
||||
import java.io.File
|
||||
|
@ -60,7 +61,7 @@ class CloneOperation(fileDir: File, callingActivity: Activity) : GitOperation(fi
|
|||
|
||||
override fun execute() {
|
||||
(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) {
|
||||
|
|
|
@ -6,6 +6,7 @@ package com.zeapo.pwdstore.git;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import com.zeapo.pwdstore.PasswordStore;
|
||||
import com.zeapo.pwdstore.R;
|
||||
|
@ -22,20 +23,20 @@ import org.eclipse.jgit.transport.RemoteRefUpdate;
|
|||
|
||||
public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
|
||||
private WeakReference<Activity> activityWeakReference;
|
||||
private boolean finishOnEnd;
|
||||
private boolean refreshListOnEnd;
|
||||
private ProgressDialog dialog;
|
||||
private GitOperation operation;
|
||||
private Intent finishWithResultOnEnd;
|
||||
|
||||
public GitAsyncTask(
|
||||
Activity activity,
|
||||
boolean finishOnEnd,
|
||||
boolean refreshListOnEnd,
|
||||
GitOperation operation) {
|
||||
GitOperation operation,
|
||||
Intent finishWithResultOnEnd) {
|
||||
this.activityWeakReference = new WeakReference<>(activity);
|
||||
this.finishOnEnd = finishOnEnd;
|
||||
this.refreshListOnEnd = refreshListOnEnd;
|
||||
this.operation = operation;
|
||||
this.finishWithResultOnEnd = finishWithResultOnEnd;
|
||||
|
||||
dialog = new ProgressDialog(getActivity());
|
||||
}
|
||||
|
@ -124,8 +125,8 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
|
|||
} else {
|
||||
this.operation.onSuccess();
|
||||
|
||||
if (finishOnEnd) {
|
||||
this.getActivity().setResult(Activity.RESULT_OK);
|
||||
if (finishWithResultOnEnd != null) {
|
||||
this.getActivity().setResult(Activity.RESULT_OK, finishWithResultOnEnd);
|
||||
this.getActivity().finish();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package com.zeapo.pwdstore.git
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.zeapo.pwdstore.R
|
||||
import java.io.File
|
||||
|
@ -34,7 +35,7 @@ class PullOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
|
|||
|
||||
override fun execute() {
|
||||
(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) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package com.zeapo.pwdstore.git
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.zeapo.pwdstore.R
|
||||
import java.io.File
|
||||
|
@ -34,7 +35,7 @@ class PushOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
|
|||
|
||||
override fun execute() {
|
||||
(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) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package com.zeapo.pwdstore.git
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.zeapo.pwdstore.R
|
||||
import java.io.File
|
||||
|
@ -39,7 +40,7 @@ class ResetToRemoteOperation(fileDir: File, callingActivity: Activity) : GitOper
|
|||
|
||||
override fun execute() {
|
||||
this.fetchCommand?.setCredentialsProvider(this.provider)
|
||||
GitAsyncTask(callingActivity, true, false, this)
|
||||
GitAsyncTask(callingActivity, false, this, Intent())
|
||||
.execute(this.addCommand, this.fetchCommand, this.resetCommand)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package com.zeapo.pwdstore.git
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.zeapo.pwdstore.R
|
||||
import java.io.File
|
||||
|
@ -48,7 +49,7 @@ class SyncOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
|
|||
this.pullCommand?.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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue