aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
diff options
context:
space:
mode:
authorwongma7 <wongma7@users.noreply.github.com>2016-01-05 19:40:44 -0500
committerwongma7 <wongma7@users.noreply.github.com>2016-01-05 19:40:44 -0500
commit2064c2eaac88216e6cfb6819831c3afe39158047 (patch)
tree031d0cb46a2e473bef302642c56cdd684a460cfe /app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
parent9e930ae92351c4044e3efb1c715c99c87fc7edd7 (diff)
parent5cf345eaa3e37cfaca82aa8f7d66328361ca27c3 (diff)
downloadHardenedPass-2064c2eaac88216e6cfb6819831c3afe39158047.tar.gz
HardenedPass-2064c2eaac88216e6cfb6819831c3afe39158047.zip
Merge pull request #146 from zeapo/webview
Autofill: multiple associations per app & WebView/Chrome
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java69
1 files changed, 66 insertions, 3 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
index 6d11936b..d40c5123 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
@@ -1,22 +1,34 @@
package com.zeapo.pwdstore.autofill;
import android.app.PendingIntent;
+import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
+import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
+import com.zeapo.pwdstore.PasswordStore;
+
+import org.eclipse.jgit.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
// blank activity started by service for calling startIntentSenderForResult
public class AutofillActivity extends AppCompatActivity {
public static final int REQUEST_CODE_DECRYPT_AND_VERIFY = 9913;
+ public static final int REQUEST_CODE_PICK = 777;
+ public static final int REQUEST_CODE_PICK_MATCH_WITH = 778;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
- if (extras != null) {
+ if (extras != null && extras.containsKey("pending_intent")) {
try {
PendingIntent pi = extras.getParcelable("pending_intent");
if (pi == null) {
@@ -27,14 +39,65 @@ public class AutofillActivity extends AppCompatActivity {
} catch (IntentSender.SendIntentException e) {
Log.e(AutofillService.Constants.TAG, "SendIntentException", e);
}
+ } else if (extras != null && extras.containsKey("pick")) {
+ Intent intent = new Intent(getApplicationContext(), PasswordStore.class);
+ intent.putExtra("matchWith", true);
+ startActivityForResult(intent, REQUEST_CODE_PICK);
+ } else if (extras != null && extras.containsKey("pickMatchWith")) {
+ Intent intent = new Intent(getApplicationContext(), PasswordStore.class);
+ intent.putExtra("matchWith", true);
+ startActivityForResult(intent, REQUEST_CODE_PICK_MATCH_WITH);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
finish(); // go back to the password field app
- if (resultCode == RESULT_OK) {
- AutofillService.setResultData(data); // report the result to service
+ switch (requestCode) {
+ case REQUEST_CODE_DECRYPT_AND_VERIFY:
+ if (resultCode == RESULT_OK) {
+ AutofillService.getInstance().setResultData(data); // report the result to service
+ }
+ break;
+ case REQUEST_CODE_PICK:
+ if (resultCode == RESULT_OK) {
+ AutofillService.getInstance().setPickedPassword(data.getStringExtra("path"));
+ }
+ break;
+ case REQUEST_CODE_PICK_MATCH_WITH:
+ if (resultCode == RESULT_OK) {
+ // need to not only decrypt the picked password, but also
+ // update the "match with" preference
+ Bundle extras = getIntent().getExtras();
+ String packageName = extras.getString("packageName");
+ boolean isWeb = extras.getBoolean("isWeb");
+
+ String path = data.getStringExtra("path");
+ AutofillService.getInstance().setPickedPassword(data.getStringExtra("path"));
+
+ SharedPreferences prefs;
+ if (!isWeb) {
+ prefs = getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE);
+ } else {
+ prefs = getApplicationContext().getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
+ }
+ SharedPreferences.Editor editor = prefs.edit();
+ String preference = prefs.getString(packageName, "");
+ switch (preference) {
+ case "":
+ case "/first":
+ case "/never":
+ editor.putString(packageName, path);
+ break;
+ default:
+ List<String> matches = new ArrayList<>(Arrays.asList(preference.trim().split("\n")));
+ matches.add(path);
+ String paths = StringUtils.join(matches, "\n");
+ editor.putString(packageName, paths);
+ }
+ editor.apply();
+ }
+ break;
}
}
}