aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/git
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-05-10 19:21:39 +0530
committerGitHub <noreply@github.com>2020-05-10 19:21:39 +0530
commit041cf00510a75042223d1857660fc7f1dff958ef (patch)
tree1b56e67e2b71afe23ac51b680b62ad778272f162 /app/src/main/java/com/zeapo/pwdstore/git
parent94dc92f8d70870b57a7f8c4fe8adef152c1211ce (diff)
downloadHardenedPass-041cf00510a75042223d1857660fc7f1dff958ef.tar.gz
HardenedPass-041cf00510a75042223d1857660fc7f1dff958ef.zip
Treewide codestyle cleanup (#765)
- Updated gitignore and checked in the IDE's codestyle config - Removed spotless as the underlying ktlint backend has failed to resolve the super frustrating import order bug[1] in nearly a year - Reformat the entire codebase based on the previously committed code style configuration. 1: https://github.com/pinterest/ktlint/issues/527
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/git')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt3
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/BreakOutOfDetached.kt54
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt22
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java19
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt6
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitOperation.kt12
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt22
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt36
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt22
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt16
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt19
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt17
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/config/SshApiSessionFactory.java153
13 files changed, 208 insertions, 193 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt
index 2af6c131..7f14cd7a 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt
@@ -31,6 +31,7 @@ import java.net.URI
* tasks and makes sense to be held here.
*/
abstract class BaseGitActivity : AppCompatActivity() {
+
lateinit var protocol: Protocol
lateinit var connectionMode: ConnectionMode
var url: String? = null
@@ -180,7 +181,7 @@ abstract class BaseGitActivity : AppCompatActivity() {
}
}
op.executeAfterAuthentication(connectionMode, serverUser,
- File("$filesDir/.ssh_key"), identity)
+ File("$filesDir/.ssh_key"), identity)
} catch (e: Exception) {
e.printStackTrace()
MaterialAlertDialogBuilder(this).setMessage(e.message).show()
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/BreakOutOfDetached.kt b/app/src/main/java/com/zeapo/pwdstore/git/BreakOutOfDetached.kt
index 4edd9e38..94ee0845 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/BreakOutOfDetached.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/BreakOutOfDetached.kt
@@ -7,11 +7,11 @@ package com.zeapo.pwdstore.git
import android.app.Activity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
-import java.io.File
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.GitCommand
import org.eclipse.jgit.api.PushCommand
import org.eclipse.jgit.api.RebaseCommand
+import java.io.File
class BreakOutOfDetached(fileDir: File, callingActivity: Activity) : GitOperation(fileDir, callingActivity) {
private lateinit var commands: List<GitCommand<out Any>>
@@ -26,14 +26,14 @@ class BreakOutOfDetached(fileDir: File, callingActivity: Activity) : GitOperatio
val branchName = "conflicting-master-${System.currentTimeMillis()}"
this.commands = listOf(
- // abort the rebase
- git.rebase().setOperation(RebaseCommand.Operation.ABORT),
- // git checkout -b conflict-branch
- git.checkout().setCreateBranch(true).setName(branchName),
- // push the changes
- git.push().setRemote("origin"),
- // switch back to master
- git.checkout().setName("master")
+ // abort the rebase
+ git.rebase().setOperation(RebaseCommand.Operation.ABORT),
+ // git checkout -b conflict-branch
+ git.checkout().setCreateBranch(true).setName(branchName),
+ // push the changes
+ git.push().setRemote("origin"),
+ // switch back to master
+ git.checkout().setName("master")
)
return this
}
@@ -42,11 +42,11 @@ class BreakOutOfDetached(fileDir: File, callingActivity: Activity) : GitOperatio
val git = Git(repository)
if (!git.repository.repositoryState.isRebasing) {
MaterialAlertDialogBuilder(callingActivity)
- .setTitle(callingActivity.resources.getString(R.string.git_abort_and_push_title))
- .setMessage("The repository is not rebasing, no need to push to another branch")
- .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ ->
- callingActivity.finish()
- }.show()
+ .setTitle(callingActivity.resources.getString(R.string.git_abort_and_push_title))
+ .setMessage("The repository is not rebasing, no need to push to another branch")
+ .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ ->
+ callingActivity.finish()
+ }.show()
return
}
@@ -59,26 +59,26 @@ class BreakOutOfDetached(fileDir: File, callingActivity: Activity) : GitOperatio
}
}
GitAsyncTask(callingActivity, true, this, null)
- .execute(*this.commands.toTypedArray())
+ .execute(*this.commands.toTypedArray())
}
override fun onError(errorMessage: String) {
MaterialAlertDialogBuilder(callingActivity)
- .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
- .setMessage("Error occurred when checking out another branch operation $errorMessage")
- .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ ->
- callingActivity.finish()
- }.show()
+ .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
+ .setMessage("Error occurred when checking out another branch operation $errorMessage")
+ .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ ->
+ callingActivity.finish()
+ }.show()
}
override fun onSuccess() {
MaterialAlertDialogBuilder(callingActivity)
- .setTitle(callingActivity.resources.getString(R.string.git_abort_and_push_title))
- .setMessage("There was a conflict when trying to rebase. " +
- "Your local master branch was pushed to another branch named conflicting-master-....\n" +
- "Use this branch to resolve conflict on your computer")
- .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ ->
- callingActivity.finish()
- }.show()
+ .setTitle(callingActivity.resources.getString(R.string.git_abort_and_push_title))
+ .setMessage("There was a conflict when trying to rebase. " +
+ "Your local master branch was pushed to another branch named conflicting-master-....\n" +
+ "Use this branch to resolve conflict on your computer")
+ .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ ->
+ callingActivity.finish()
+ }.show()
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt
index 2bfcd491..a8b9d9ce 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt
@@ -8,9 +8,9 @@ import android.app.Activity
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
-import java.io.File
import org.eclipse.jgit.api.CloneCommand
import org.eclipse.jgit.api.Git
+import java.io.File
/**
* Creates a new clone operation
@@ -28,9 +28,9 @@ class CloneOperation(fileDir: File, callingActivity: Activity) : GitOperation(fi
*/
fun setCommand(uri: String): CloneOperation {
this.command = Git.cloneRepository()
- .setCloneAllBranches(true)
- .setDirectory(repository?.workTree)
- .setURI(uri)
+ .setCloneAllBranches(true)
+ .setDirectory(repository?.workTree)
+ .setURI(uri)
return this
}
@@ -67,12 +67,12 @@ class CloneOperation(fileDir: File, callingActivity: Activity) : GitOperation(fi
override fun onError(errorMessage: String) {
super.onError(errorMessage)
MaterialAlertDialogBuilder(callingActivity)
- .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
- .setMessage("Error occured during the clone operation, " +
- callingActivity.resources.getString(R.string.jgit_error_dialog_text) +
- errorMessage +
- "\nPlease check the FAQ for possible reasons why this error might occur.")
- .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> }
- .show()
+ .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
+ .setMessage("Error occured during the clone operation, " +
+ callingActivity.resources.getString(R.string.jgit_error_dialog_text) +
+ errorMessage +
+ "\nPlease check the FAQ for possible reasons why this error might occur.")
+ .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> }
+ .show()
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java
index d07bd791..33e786a3 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java
@@ -8,9 +8,10 @@ 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;
-import java.lang.ref.WeakReference;
+
import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.GitCommand;
import org.eclipse.jgit.api.PullCommand;
@@ -21,6 +22,8 @@ import org.eclipse.jgit.api.StatusCommand;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RemoteRefUpdate;
+import java.lang.ref.WeakReference;
+
public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
private WeakReference<Activity> activityWeakReference;
private boolean refreshListOnEnd;
@@ -29,10 +32,10 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
private Intent finishWithResultOnEnd;
public GitAsyncTask(
- Activity activity,
- boolean refreshListOnEnd,
- GitOperation operation,
- Intent finishWithResultOnEnd) {
+ Activity activity,
+ boolean refreshListOnEnd,
+ GitOperation operation,
+ Intent finishWithResultOnEnd) {
this.activityWeakReference = new WeakReference<>(activity);
this.refreshListOnEnd = refreshListOnEnd;
this.operation = operation;
@@ -47,7 +50,7 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
protected void onPreExecute() {
this.dialog.setMessage(
- getActivity().getResources().getString(R.string.running_dialog_text));
+ getActivity().getResources().getString(R.string.running_dialog_text));
this.dialog.setCancelable(false);
this.dialog.show();
}
@@ -85,13 +88,13 @@ public class GitAsyncTask extends AsyncTask<GitCommand, Integer, String> {
case NON_EXISTING:
case NOT_ATTEMPTED:
return activity.getString(R.string.git_push_generic_error)
- + rru.getStatus().name();
+ + rru.getStatus().name();
case REJECTED_OTHER_REASON:
if ("non-fast-forward".equals(rru.getMessage())) {
return activity.getString(R.string.git_push_other_error);
} else {
return activity.getString(R.string.git_push_generic_error)
- + rru.getMessage();
+ + rru.getMessage();
}
default:
break;
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt
index dbf67d5f..be1f016b 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt
@@ -53,9 +53,9 @@ class GitConfigActivity : BaseGitActivity() {
val name = binding.gitUserName.text.toString().trim()
if (!email.matches(Patterns.EMAIL_ADDRESS.toRegex())) {
MaterialAlertDialogBuilder(this)
- .setMessage(getString(R.string.invalid_email_dialog_text))
- .setPositiveButton(getString(R.string.dialog_ok), null)
- .show()
+ .setMessage(getString(R.string.invalid_email_dialog_text))
+ .setPositiveButton(getString(R.string.dialog_ok), null)
+ .show()
} else {
settings.edit {
putString("git_config_user_email", email)
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.kt
index 82f3d7f6..712d1bc5 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.kt
@@ -25,11 +25,11 @@ import com.zeapo.pwdstore.git.config.SshConfigSessionFactory
import com.zeapo.pwdstore.utils.PasswordRepository
import com.zeapo.pwdstore.utils.getEncryptedPrefs
import com.zeapo.pwdstore.utils.requestInputFocusOnView
-import java.io.File
import org.eclipse.jgit.api.GitCommand
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.transport.SshSessionFactory
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
+import java.io.File
/**
* Creates a new git operation
@@ -260,14 +260,14 @@ abstract class GitOperation(fileDir: File, internal val callingActivity: Activit
// Clear various auth related fields on failure
if (SshSessionFactory.getInstance() is SshApiSessionFactory) {
PreferenceManager.getDefaultSharedPreferences(callingActivity.applicationContext)
- .edit { putString("ssh_openkeystore_keyid", null) }
+ .edit { putString("ssh_openkeystore_keyid", null) }
callingActivity.applicationContext
- .getEncryptedPrefs("git_operation")
- .edit { remove("ssh_key_local_passphrase") }
+ .getEncryptedPrefs("git_operation")
+ .edit { remove("ssh_key_local_passphrase") }
} else if (SshSessionFactory.getInstance() is GitConfigSessionFactory) {
callingActivity.applicationContext
- .getEncryptedPrefs("git_operation")
- .edit { remove("https_password") }
+ .getEncryptedPrefs("git_operation")
+ .edit { remove("https_password") }
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt
index 37f5e35c..93e861ec 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperationActivity.kt
@@ -56,17 +56,17 @@ open class GitOperationActivity : BaseGitActivity() {
private fun syncRepository(operation: Int) {
if (serverUser.isEmpty() || serverHostname.isEmpty() || url.isNullOrEmpty())
MaterialAlertDialogBuilder(this)
- .setMessage(getString(R.string.set_information_dialog_text))
- .setPositiveButton(getString(R.string.dialog_positive)) { _, _ ->
- val intent = Intent(this, UserPreference::class.java)
- startActivityForResult(intent, REQUEST_PULL)
- }
- .setNegativeButton(getString(R.string.dialog_negative)) { _, _ ->
- // do nothing :(
- setResult(RESULT_OK)
- finish()
- }
- .show()
+ .setMessage(getString(R.string.set_information_dialog_text))
+ .setPositiveButton(getString(R.string.dialog_positive)) { _, _ ->
+ val intent = Intent(this, UserPreference::class.java)
+ startActivityForResult(intent, REQUEST_PULL)
+ }
+ .setNegativeButton(getString(R.string.dialog_negative)) { _, _ ->
+ // do nothing :(
+ setResult(RESULT_OK)
+ finish()
+ }
+ .show()
else {
// check that the remote origin is here, else add it
PasswordRepository.addRemote("origin", url!!, true)
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt
index 14f9bb62..3e5d18e0 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitServerConfigActivity.kt
@@ -144,27 +144,27 @@ class GitServerConfigActivity : BaseGitActivity() {
val localDirFiles = localDir.listFiles() ?: emptyArray()
// Warn if non-empty folder unless it's a just-initialized store that has just a .git folder
if (localDir.exists() && localDirFiles.isNotEmpty() &&
- !(localDirFiles.size == 1 && localDirFiles[0].name == ".git")) {
+ !(localDirFiles.size == 1 && localDirFiles[0].name == ".git")) {
MaterialAlertDialogBuilder(this)
- .setTitle(R.string.dialog_delete_title)
- .setMessage(resources.getString(R.string.dialog_delete_msg) + " " + localDir.toString())
- .setCancelable(false)
- .setPositiveButton(R.string.dialog_delete) { dialog, _ ->
- try {
- localDir.deleteRecursively()
- launchGitOperation(REQUEST_CLONE)
- } catch (e: IOException) {
- // TODO Handle the exception correctly if we are unable to delete the directory...
- e.printStackTrace()
- MaterialAlertDialogBuilder(this).setMessage(e.message).show()
- } finally {
- dialog.cancel()
- }
- }
- .setNegativeButton(R.string.dialog_do_not_delete) { dialog, _ ->
+ .setTitle(R.string.dialog_delete_title)
+ .setMessage(resources.getString(R.string.dialog_delete_msg) + " " + localDir.toString())
+ .setCancelable(false)
+ .setPositiveButton(R.string.dialog_delete) { dialog, _ ->
+ try {
+ localDir.deleteRecursively()
+ launchGitOperation(REQUEST_CLONE)
+ } catch (e: IOException) {
+ // TODO Handle the exception correctly if we are unable to delete the directory...
+ e.printStackTrace()
+ MaterialAlertDialogBuilder(this).setMessage(e.message).show()
+ } finally {
dialog.cancel()
}
- .show()
+ }
+ .setNegativeButton(R.string.dialog_do_not_delete) { dialog, _ ->
+ dialog.cancel()
+ }
+ .show()
} else {
try {
// Silently delete & replace the lone .git folder if it exists
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt
index 554b76af..816b0102 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/PullOperation.kt
@@ -8,9 +8,9 @@ import android.app.Activity
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
-import java.io.File
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.PullCommand
+import java.io.File
/**
* Creates a new git operation
@@ -27,9 +27,9 @@ class PullOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
*/
fun setCommand(): PullOperation {
this.command = Git(repository)
- .pull()
- .setRebase(true)
- .setRemote("origin")
+ .pull()
+ .setRebase(true)
+ .setRemote("origin")
return this
}
@@ -41,12 +41,12 @@ class PullOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
override fun onError(errorMessage: String) {
super.onError(errorMessage)
MaterialAlertDialogBuilder(callingActivity)
- .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
- .setMessage("Error occured during the pull operation, " +
- callingActivity.resources.getString(R.string.jgit_error_dialog_text) +
- errorMessage +
- "\nPlease check the FAQ for possible reasons why this error might occur.")
- .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> callingActivity.finish() }
- .show()
+ .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
+ .setMessage("Error occured during the pull operation, " +
+ callingActivity.resources.getString(R.string.jgit_error_dialog_text) +
+ errorMessage +
+ "\nPlease check the FAQ for possible reasons why this error might occur.")
+ .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> callingActivity.finish() }
+ .show()
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt
index 1f40e615..b2e87322 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/PushOperation.kt
@@ -8,9 +8,9 @@ import android.app.Activity
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
-import java.io.File
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.PushCommand
+import java.io.File
/**
* Creates a new git operation
@@ -27,9 +27,9 @@ class PushOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
*/
fun setCommand(): PushOperation {
this.command = Git(repository)
- .push()
- .setPushAll()
- .setRemote("origin")
+ .push()
+ .setPushAll()
+ .setRemote("origin")
return this
}
@@ -42,9 +42,9 @@ class PushOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
// TODO handle the "Nothing to push" case
super.onError(errorMessage)
MaterialAlertDialogBuilder(callingActivity)
- .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
- .setMessage(callingActivity.getString(R.string.jgit_error_push_dialog_text) + errorMessage)
- .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> callingActivity.finish() }
- .show()
+ .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
+ .setMessage(callingActivity.getString(R.string.jgit_error_push_dialog_text) + errorMessage)
+ .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> callingActivity.finish() }
+ .show()
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt
index 44cd75a0..48997657 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/ResetToRemoteOperation.kt
@@ -8,11 +8,11 @@ import android.app.Activity
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
-import java.io.File
import org.eclipse.jgit.api.AddCommand
import org.eclipse.jgit.api.FetchCommand
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.ResetCommand
+import java.io.File
/**
* Creates a new git operation
@@ -21,6 +21,7 @@ import org.eclipse.jgit.api.ResetCommand
* @param callingActivity the calling activity
*/
class ResetToRemoteOperation(fileDir: File, callingActivity: Activity) : GitOperation(fileDir, callingActivity) {
+
private var addCommand: AddCommand? = null
private var fetchCommand: FetchCommand? = null
private var resetCommand: ResetCommand? = null
@@ -41,18 +42,18 @@ class ResetToRemoteOperation(fileDir: File, callingActivity: Activity) : GitOper
override fun execute() {
this.fetchCommand?.setCredentialsProvider(this.provider)
GitAsyncTask(callingActivity, false, this, Intent())
- .execute(this.addCommand, this.fetchCommand, this.resetCommand)
+ .execute(this.addCommand, this.fetchCommand, this.resetCommand)
}
override fun onError(errorMessage: String) {
super.onError(errorMessage)
MaterialAlertDialogBuilder(callingActivity)
- .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
- .setMessage("Error occured during the sync operation, " +
- "\nPlease check the FAQ for possible reasons why this error might occur." +
- callingActivity.resources.getString(R.string.jgit_error_dialog_text) +
- errorMessage)
- .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> }
- .show()
+ .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
+ .setMessage("Error occured during the sync operation, " +
+ "\nPlease check the FAQ for possible reasons why this error might occur." +
+ callingActivity.resources.getString(R.string.jgit_error_dialog_text) +
+ errorMessage)
+ .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> }
+ .show()
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt b/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt
index 73e2d875..ff07d7f8 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/SyncOperation.kt
@@ -8,13 +8,13 @@ import android.app.Activity
import android.content.Intent
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
-import java.io.File
import org.eclipse.jgit.api.AddCommand
import org.eclipse.jgit.api.CommitCommand
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.PullCommand
import org.eclipse.jgit.api.PushCommand
import org.eclipse.jgit.api.StatusCommand
+import java.io.File
/**
* Creates a new git operation
@@ -23,6 +23,7 @@ import org.eclipse.jgit.api.StatusCommand
* @param callingActivity the calling activity
*/
class SyncOperation(fileDir: File, callingActivity: Activity) : GitOperation(fileDir, callingActivity) {
+
private var addCommand: AddCommand? = null
private var statusCommand: StatusCommand? = null
private var commitCommand: CommitCommand? = null
@@ -55,12 +56,12 @@ class SyncOperation(fileDir: File, callingActivity: Activity) : GitOperation(fil
override fun onError(errorMessage: String) {
super.onError(errorMessage)
MaterialAlertDialogBuilder(callingActivity)
- .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
- .setMessage("Error occured during the sync operation, " +
- "\nPlease check the FAQ for possible reasons why this error might occur." +
- callingActivity.resources.getString(R.string.jgit_error_dialog_text) +
- errorMessage)
- .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> callingActivity.finish() }
- .show()
+ .setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
+ .setMessage("Error occured during the sync operation, " +
+ "\nPlease check the FAQ for possible reasons why this error might occur." +
+ callingActivity.resources.getString(R.string.jgit_error_dialog_text) +
+ errorMessage)
+ .setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> callingActivity.finish() }
+ .show()
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/SshApiSessionFactory.java b/app/src/main/java/com/zeapo/pwdstore/git/config/SshApiSessionFactory.java
index 6b82cac9..c21ec053 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/config/SshApiSessionFactory.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/config/SshApiSessionFactory.java
@@ -9,8 +9,10 @@ import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentSender;
import android.content.SharedPreferences;
+
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
+
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.jcraft.jsch.Identity;
import com.jcraft.jsch.JSch;
@@ -19,8 +21,7 @@ import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;
import com.zeapo.pwdstore.R;
import com.zeapo.pwdstore.git.BaseGitActivity;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
+
import org.eclipse.jgit.errors.UnsupportedCredentialItem;
import org.eclipse.jgit.transport.CredentialItem;
import org.eclipse.jgit.transport.CredentialsProvider;
@@ -39,6 +40,9 @@ import org.openintents.ssh.authentication.request.SigningRequest;
import org.openintents.ssh.authentication.request.SshPublicKeyRequest;
import org.openintents.ssh.authentication.util.SshAuthenticationApiUtils;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+
public class SshApiSessionFactory extends GitConfigSessionFactory {
/**
* Intent request code indicating a completed signature that should be posted to an outstanding
@@ -57,7 +61,7 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
@NonNull
@Override
protected JSch getJSch(@NonNull final OpenSshConfig.Host hc, @NonNull FS fs)
- throws JSchException {
+ throws JSchException {
JSch jsch = super.getJSch(hc, fs);
jsch.removeAllIdentity();
jsch.addIdentity(identity, null);
@@ -70,28 +74,28 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
session.setConfig("PreferredAuthentications", "publickey");
CredentialsProvider provider =
- new CredentialsProvider() {
- @Override
- public boolean isInteractive() {
- return false;
- }
+ new CredentialsProvider() {
+ @Override
+ public boolean isInteractive() {
+ return false;
+ }
- @Override
- public boolean supports(CredentialItem... items) {
- return true;
- }
+ @Override
+ public boolean supports(CredentialItem... items) {
+ return true;
+ }
- @Override
- public boolean get(URIish uri, CredentialItem... items)
- throws UnsupportedCredentialItem {
- for (CredentialItem item : items) {
- if (item instanceof CredentialItem.Username) {
- ((CredentialItem.Username) item).setValue(username);
- }
+ @Override
+ public boolean get(URIish uri, CredentialItem... items)
+ throws UnsupportedCredentialItem {
+ for (CredentialItem item : items) {
+ if (item instanceof CredentialItem.Username) {
+ ((CredentialItem.Username) item).setValue(username);
}
- return true;
}
- };
+ return true;
+ }
+ };
UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
session.setUserInfo(userInfo);
}
@@ -114,14 +118,14 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
* Construct a new IdentityBuilder
*
* @param callingActivity Activity that will be used to launch pending intents and that will
- * receive and handle the results.
+ * receive and handle the results.
*/
public IdentityBuilder(BaseGitActivity callingActivity) {
this.callingActivity = callingActivity;
List<String> providers =
- SshAuthenticationApiUtils.getAuthenticationProviderPackageNames(
- callingActivity);
+ SshAuthenticationApiUtils.getAuthenticationProviderPackageNames(
+ callingActivity);
if (providers.isEmpty())
throw new RuntimeException(callingActivity.getString(R.string.no_ssh_api_provider));
@@ -130,12 +134,14 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
connection = new SshAuthenticationConnection(callingActivity, providers.get(0));
settings =
- PreferenceManager.getDefaultSharedPreferences(
- callingActivity.getApplicationContext());
+ PreferenceManager.getDefaultSharedPreferences(
+ callingActivity.getApplicationContext());
keyId = settings.getString("ssh_openkeystore_keyid", null);
}
- /** Free any resources associated with this IdentityBuilder */
+ /**
+ * Free any resources associated with this IdentityBuilder
+ */
public void close() {
if (connection != null && connection.isConnected()) connection.disconnect();
}
@@ -143,10 +149,10 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
/**
* Helper to invoke an OpenKeyshain SSH API method and correctly interpret the result.
*
- * @param request The request intent to launch
+ * @param request The request intent to launch
* @param requestCode The request code to use if a pending intent needs to be sent
* @return The resulting intent if the request completed immediately, or null if we had to
- * launch a pending intent to interact with the user
+ * launch a pending intent to interact with the user
*/
private Intent executeApi(Request request, int requestCode) {
Intent result = api.executeApi(request.toIntent());
@@ -154,13 +160,13 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
switch (result.getIntExtra(SshAuthenticationApi.EXTRA_RESULT_CODE, -1)) {
case SshAuthenticationApi.RESULT_CODE_ERROR:
SshAuthenticationApiError error =
- result.getParcelableExtra(SshAuthenticationApi.EXTRA_ERROR);
+ result.getParcelableExtra(SshAuthenticationApi.EXTRA_ERROR);
// On an OpenKeychain SSH API error, clear out the stored keyid
settings.edit().putString("ssh_openkeystore_keyid", null).apply();
switch (error.getError()) {
- // If the problem was just a bad keyid, reset to allow them to choose a
- // different one
+ // If the problem was just a bad keyid, reset to allow them to choose a
+ // different one
case (SshAuthenticationApiError.NO_SUCH_KEY):
case (SshAuthenticationApiError.NO_AUTH_KEY):
keyId = null;
@@ -169,7 +175,7 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
alg = null;
return executeApi(new KeySelectionRequest(), requestCode);
- // Other errors are fatal
+ // Other errors are fatal
default:
throw new RuntimeException(error.getMessage());
}
@@ -177,19 +183,19 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
break;
case SshAuthenticationApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
PendingIntent pendingIntent =
- result.getParcelableExtra(SshAuthenticationApi.EXTRA_PENDING_INTENT);
+ result.getParcelableExtra(SshAuthenticationApi.EXTRA_PENDING_INTENT);
try {
callingActivity.startIntentSenderForResult(
- pendingIntent.getIntentSender(), requestCode, null, 0, 0, 0);
+ pendingIntent.getIntentSender(), requestCode, null, 0, 0, 0);
return null;
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
throw new RuntimeException(
- callingActivity.getString(R.string.ssh_api_pending_intent_failed));
+ callingActivity.getString(R.string.ssh_api_pending_intent_failed));
}
default:
throw new RuntimeException(
- callingActivity.getString(R.string.ssh_api_unknown_error));
+ callingActivity.getString(R.string.ssh_api_unknown_error));
}
return result;
@@ -223,32 +229,32 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
*
* @param requestCode The request code to use if a pending intent needs to be sent
* @return The built identity, or null of user interaction is still required (in which case
- * a pending intent will have already been launched)
+ * a pending intent will have already been launched)
*/
public ApiIdentity tryBuild(int requestCode) {
// First gate, need to initiate a connection to the service and wait for it to connect.
if (api == null) {
connection.connect(
- new SshAuthenticationConnection.OnBound() {
- @Override
- public void onBound(ISshAuthenticationService sshAgent) {
- api = new SshAuthenticationApi(callingActivity, sshAgent);
- // We can immediately try the next phase without needing to post
- // back
- // though onActivityResult
- callingActivity.onActivityResult(
- requestCode, Activity.RESULT_OK, null);
- }
-
- @Override
- public void onError() {
- new MaterialAlertDialogBuilder(callingActivity)
- .setMessage(
- callingActivity.getString(
- R.string.openkeychain_ssh_api_connect_fail))
- .show();
- }
- });
+ new SshAuthenticationConnection.OnBound() {
+ @Override
+ public void onBound(ISshAuthenticationService sshAgent) {
+ api = new SshAuthenticationApi(callingActivity, sshAgent);
+ // We can immediately try the next phase without needing to post
+ // back
+ // though onActivityResult
+ callingActivity.onActivityResult(
+ requestCode, Activity.RESULT_OK, null);
+ }
+
+ @Override
+ public void onError() {
+ new MaterialAlertDialogBuilder(callingActivity)
+ .setMessage(
+ callingActivity.getString(
+ R.string.openkeychain_ssh_api_connect_fail))
+ .show();
+ }
+ });
return null;
}
@@ -273,7 +279,9 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
}
}
- /** A Jsch identity that delegates key operations via the OpenKeychain SSH API */
+ /**
+ * A Jsch identity that delegates key operations via the OpenKeychain SSH API
+ */
public static class ApiIdentity implements Identity {
private String keyId, description, alg;
private byte[] publicKey;
@@ -283,12 +291,12 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
private byte[] signature;
ApiIdentity(
- String keyId,
- String description,
- byte[] publicKey,
- String alg,
- Activity callingActivity,
- SshAuthenticationApi api) {
+ String keyId,
+ String description,
+ byte[] publicKey,
+ String alg,
+ Activity callingActivity,
+ SshAuthenticationApi api) {
this.keyId = keyId;
this.description = description;
this.publicKey = publicKey;
@@ -313,35 +321,35 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
*
* @param result The result intent to handle
* @return The signed challenge, or null if it was not immediately available, in which case
- * the latch has been initialized and the pending intent started
+ * the latch has been initialized and the pending intent started
*/
private byte[] handleSignResult(Intent result) {
switch (result.getIntExtra(SshAuthenticationApi.EXTRA_RESULT_CODE, -1)) {
case SshAuthenticationApi.RESULT_CODE_ERROR:
SshAuthenticationApiError error =
- result.getParcelableExtra(SshAuthenticationApi.EXTRA_ERROR);
+ result.getParcelableExtra(SshAuthenticationApi.EXTRA_ERROR);
throw new RuntimeException(error.getMessage());
case SshAuthenticationApi.RESULT_CODE_SUCCESS:
return result.getByteArrayExtra(SshAuthenticationApi.EXTRA_SIGNATURE);
case SshAuthenticationApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
PendingIntent pendingIntent =
- result.getParcelableExtra(SshAuthenticationApi.EXTRA_PENDING_INTENT);
+ result.getParcelableExtra(SshAuthenticationApi.EXTRA_PENDING_INTENT);
try {
latch = new CountDownLatch(1);
callingActivity.startIntentSenderForResult(
- pendingIntent.getIntentSender(), POST_SIGNATURE, null, 0, 0, 0);
+ pendingIntent.getIntentSender(), POST_SIGNATURE, null, 0, 0, 0);
return null;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(
- callingActivity.getString(R.string.ssh_api_pending_intent_failed));
+ callingActivity.getString(R.string.ssh_api_pending_intent_failed));
}
default:
if (result.hasExtra(SshAuthenticationApi.EXTRA_CHALLENGE))
return handleSignResult(api.executeApi(result));
throw new RuntimeException(
- callingActivity.getString(R.string.ssh_api_unknown_error));
+ callingActivity.getString(R.string.ssh_api_unknown_error));
}
}
@@ -399,6 +407,7 @@ public class SshApiSessionFactory extends GitConfigSessionFactory {
}
@Override
- public void clear() {}
+ public void clear() {
+ }
}
}