Add 'pick password' option that shows only when no other items are available (+travis)

This commit is contained in:
Matthew Wong 2015-12-31 05:14:37 -05:00
parent 1d9e3b50a5
commit a782c3f83e
3 changed files with 64 additions and 27 deletions

View file

@ -3,8 +3,9 @@ language: android
android: android:
components: components:
- android-23 - android-23
- build-tools-23.0.1 - build-tools-23.0.2
- platform-tools - platform-tools
- tools
- extra-google-m2repository - extra-google-m2repository
- extra-android-m2repository - extra-android-m2repository

View file

@ -7,16 +7,19 @@ import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import com.zeapo.pwdstore.PasswordStore;
// blank activity started by service for calling startIntentSenderForResult // blank activity started by service for calling startIntentSenderForResult
public class AutofillActivity extends AppCompatActivity { public class AutofillActivity extends AppCompatActivity {
public static final int REQUEST_CODE_DECRYPT_AND_VERIFY = 9913; public static final int REQUEST_CODE_DECRYPT_AND_VERIFY = 9913;
public static final int REQUEST_CODE_MATCH_WITH = 777;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null) { if (extras != null && extras.containsKey("pending_intent")) {
try { try {
PendingIntent pi = extras.getParcelable("pending_intent"); PendingIntent pi = extras.getParcelable("pending_intent");
if (pi == null) { if (pi == null) {
@ -27,14 +30,26 @@ public class AutofillActivity extends AppCompatActivity {
} catch (IntentSender.SendIntentException e) { } catch (IntentSender.SendIntentException e) {
Log.e(AutofillService.Constants.TAG, "SendIntentException", e); Log.e(AutofillService.Constants.TAG, "SendIntentException", e);
} }
} else if (extras != null && extras.containsKey("matchWith")) {
Intent intent = new Intent(getApplicationContext(), PasswordStore.class);
intent.putExtra("matchWith", true);
startActivityForResult(intent, REQUEST_CODE_MATCH_WITH);
} }
} }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
finish(); // go back to the password field app finish(); // go back to the password field app
if (resultCode == RESULT_OK) { switch (requestCode) {
AutofillService.setResultData(data); // report the result to service case REQUEST_CODE_DECRYPT_AND_VERIFY:
if (resultCode == RESULT_OK) {
AutofillService.getInstance().setResultData(data); // report the result to service
}
break;
case REQUEST_CODE_MATCH_WITH:
if (resultCode == RESULT_OK) {
AutofillService.getInstance().setPickedPassword(data.getStringExtra("path"));
}
} }
} }
} }

View file

@ -44,6 +44,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class AutofillService extends AccessibilityService { public class AutofillService extends AccessibilityService {
private static AutofillService instance;
private OpenPgpServiceConnection serviceConnection; private OpenPgpServiceConnection serviceConnection;
private SharedPreferences settings; private SharedPreferences settings;
private AccessibilityNodeInfo info; // the original source of the event (the edittext field) private AccessibilityNodeInfo info; // the original source of the event (the edittext field)
@ -51,7 +52,7 @@ public class AutofillService extends AccessibilityService {
private int lastWhichItem; private int lastWhichItem;
private AlertDialog dialog; private AlertDialog dialog;
private AccessibilityWindowInfo window; private AccessibilityWindowInfo window;
private static Intent resultData = null; // need the intent which contains results from user interaction private Intent resultData = null; // need the intent which contains results from user interaction
private CharSequence packageName; private CharSequence packageName;
private boolean ignoreActionFocus = false; private boolean ignoreActionFocus = false;
private String webViewTitle = null; private String webViewTitle = null;
@ -61,7 +62,22 @@ public class AutofillService extends AccessibilityService {
public static final String TAG = "Keychain"; public static final String TAG = "Keychain";
} }
public static void setResultData(Intent data) { resultData = data; } public static AutofillService getInstance() {
return instance;
}
public void setResultData(Intent data) { resultData = data; }
public void setPickedPassword(String path) {
items.add(new File(PasswordRepository.getWorkTree() + "/" + path + ".gpg"));
bindDecryptAndVerify();
}
@Override
public void onCreate() {
super.onCreate();
instance = this;
}
@Override @Override
protected void onServiceConnected() { protected void onServiceConnected() {
@ -88,7 +104,7 @@ public class AutofillService extends AccessibilityService {
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
webViewTitle = searchWebView(getRootInActiveWindow()); webViewTitle = searchWebView(getRootInActiveWindow());
webViewURL = null; webViewURL = null;
if (webViewTitle != null) { if (webViewTitle != null && getRootInActiveWindow() != null) {
List<AccessibilityNodeInfo> nodes = getRootInActiveWindow() List<AccessibilityNodeInfo> nodes = getRootInActiveWindow()
.findAccessibilityNodeInfosByViewId("com.android.chrome:id/url_bar"); .findAccessibilityNodeInfosByViewId("com.android.chrome:id/url_bar");
for (AccessibilityNodeInfo node : nodes) for (AccessibilityNodeInfo node : nodes)
@ -105,10 +121,6 @@ public class AutofillService extends AccessibilityService {
} }
} }
} }
if (webViewTitle != null)
Log.d("Title", webViewTitle);
if (webViewURL != null)
Log.d("URL", webViewURL);
} }
// nothing to do if not password field focus, android version, or field is keychain app // nothing to do if not password field focus, android version, or field is keychain app
@ -335,28 +347,37 @@ public class AutofillService extends AccessibilityService {
} }
}); });
CharSequence itemNames[] = new CharSequence[items.size()]; if (!items.isEmpty()) {
for (int i = 0; i < items.size(); i++) { CharSequence itemNames[] = new CharSequence[items.size()];
itemNames[i] = items.get(i).getName().replace(".gpg", ""); for (int i = 0; i < items.size(); i++) {
} itemNames[i] = items.get(i).getName().replace(".gpg", "");
builder.setItems(itemNames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
lastWhichItem = which;
bindDecryptAndVerify();
} }
}); builder.setItems(itemNames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
lastWhichItem = which;
bindDecryptAndVerify();
}
});
} else {
builder.setItems(new CharSequence[]{"Pick a password..."}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
lastWhichItem = which; // always 0
// TODO option to remember a pick for the future when possible? or option to have this always visible?
Intent intent = new Intent(AutofillService.this, AutofillActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra("matchWith", true);
startActivity(intent);
}
});
}
dialog = builder.create(); dialog = builder.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
// arbitrary non-annoying size // arbitrary non-annoying size
int height = 88; int height = 154;
if (items.size() > 0) {
height += 66;
}
if (items.size() > 1) { if (items.size() > 1) {
height += 33; height += 33;
} }