Fix scanning of fingerprint qr code, whole qr code scanning still broken

This commit is contained in:
Dominik Schürmann 2014-02-01 22:51:07 +01:00
parent 20af0d3b2e
commit 1b0b761352
3 changed files with 34 additions and 28 deletions

View File

@ -121,39 +121,30 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
extras = new Bundle(); extras = new Bundle();
} }
/**
* Android Standard Actions
*/
if (Intent.ACTION_VIEW.equals(action)) { if (Intent.ACTION_VIEW.equals(action)) {
// Android's Action when opening file associated to Keychain (see AndroidManifest.xml) // Android's Action when opening file associated to Keychain (see AndroidManifest.xml)
// override action to delegate it to Keychain's ACTION_IMPORT_KEY // override action to delegate it to Keychain's ACTION_IMPORT_KEY
action = ACTION_IMPORT_KEY; action = ACTION_IMPORT_KEY;
} }
/**
* Scanning a fingerprint directly with Barcode Scanner
*/
if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) { if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) {
/* Scanning a fingerprint directly with Barcode Scanner */
getSupportActionBar().setSelectedNavigationItem(0); getSupportActionBar().setSelectedNavigationItem(0);
loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[0]); loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[0]);
loadFromFingerprintUri(dataUri); loadFromFingerprintUri(dataUri);
} } else if (ACTION_IMPORT_KEY.equals(action)) {
/* Keychain's own Actions */
/**
* Keychain's own Actions
*/
if (ACTION_IMPORT_KEY.equals(action)) {
getSupportActionBar().setSelectedNavigationItem(1); getSupportActionBar().setSelectedNavigationItem(1);
loadFragment(ImportKeysFileFragment.class, null, mNavigationStrings[1]); loadFragment(ImportKeysFileFragment.class, null, mNavigationStrings[1]);
if (dataUri != null) { if (dataUri != null) {
// directly load data // directly load data
startListFragment(savedInstanceState, null, dataUri); startListFragment(savedInstanceState, null, dataUri, null);
} else if (extras.containsKey(EXTRA_KEY_BYTES)) { } else if (extras.containsKey(EXTRA_KEY_BYTES)) {
byte[] importData = intent.getByteArrayExtra(EXTRA_KEY_BYTES); byte[] importData = intent.getByteArrayExtra(EXTRA_KEY_BYTES);
// directly load data // directly load data
startListFragment(savedInstanceState, importData, null); startListFragment(savedInstanceState, importData, null, null);
} }
} else if (ACTION_IMPORT_KEY_FROM_KEYSERVER.equals(action)) { } else if (ACTION_IMPORT_KEY_FROM_KEYSERVER.equals(action)) {
String query = null; String query = null;
@ -179,9 +170,11 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(ImportKeysServerFragment.ARG_QUERY, query); args.putString(ImportKeysServerFragment.ARG_QUERY, query);
loadFragment(ImportKeysServerFragment.class, args, mNavigationStrings[0]); loadFragment(ImportKeysServerFragment.class, args, mNavigationStrings[0]);
startListFragment(savedInstanceState, null, null, query);
} else { } else {
// Other actions // Other actions
startListFragment(savedInstanceState, null, null); startListFragment(savedInstanceState, null, null, null);
if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) { if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) {
getSupportActionBar().setSelectedNavigationItem(1); getSupportActionBar().setSelectedNavigationItem(1);
@ -197,7 +190,7 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
} }
} }
private void startListFragment(Bundle savedInstanceState, byte[] bytes, Uri dataUri) { private void startListFragment(Bundle savedInstanceState, byte[] bytes, Uri dataUri, String serverQuery) {
// Check that the activity is using the layout version with // Check that the activity is using the layout version with
// the fragment_container FrameLayout // the fragment_container FrameLayout
if (findViewById(R.id.import_keys_list_container) != null) { if (findViewById(R.id.import_keys_list_container) != null) {
@ -210,7 +203,7 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
} }
// Create an instance of the fragment // Create an instance of the fragment
mListFragment = ImportKeysListFragment.newInstance(bytes, dataUri, null); mListFragment = ImportKeysListFragment.newInstance(bytes, dataUri, serverQuery);
// Add the fragment to the 'fragment_container' FrameLayout // Add the fragment to the 'fragment_container' FrameLayout
// NOTE: We use commitAllowingStateLoss() to prevent weird crashes! // NOTE: We use commitAllowingStateLoss() to prevent weird crashes!
@ -270,14 +263,19 @@ public class ImportKeysActivity extends DrawerActivity implements OnNavigationLi
return; return;
} }
Intent queryIntent = new Intent(this, ImportKeysActivity.class); String query = "0x" + fingerprint;
queryIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER);
queryIntent.putExtra(ImportKeysActivity.EXTRA_FINGERPRINT, fingerprint); // search directly
startActivity(queryIntent); getSupportActionBar().setSelectedNavigationItem(0);
Bundle args = new Bundle();
args.putString(ImportKeysServerFragment.ARG_QUERY, query);
loadFragment(ImportKeysServerFragment.class, args, mNavigationStrings[0]);
startListFragment(null, null, null, query);
} }
public void loadCallback(byte[] importData, Uri dataUri, String serverQuery, String keyserver) { public void loadCallback(byte[] importData, Uri dataUri, String serverQuery, String keyServer) {
mListFragment.loadNew(importData, dataUri, serverQuery, keyserver); mListFragment.loadNew(importData, dataUri, serverQuery, keyServer);
} }
// private void importAndSignOld(final long keyId, final String expectedFingerprint) { // private void importAndSignOld(final long keyId, final String expectedFingerprint) {

View File

@ -26,6 +26,7 @@ import java.util.List;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader;
@ -122,6 +123,10 @@ public class ImportKeysListFragment extends SherlockListFragment implements
mKeyBytes = getArguments().getByteArray(ARG_BYTES); mKeyBytes = getArguments().getByteArray(ARG_BYTES);
mServerQuery = getArguments().getString(ARG_SERVER_QUERY); mServerQuery = getArguments().getString(ARG_SERVER_QUERY);
// TODO: this is used when scanning QR Code. Currently it simply uses key server nr 0
mKeyServer = Preferences.getPreferences(getActivity())
.getKeyServers()[0];
if (mDataUri != null || mKeyBytes != null) { if (mDataUri != null || mKeyBytes != null) {
// Start out with a progress indicator. // Start out with a progress indicator.
setListShown(false); setListShown(false);
@ -155,8 +160,8 @@ public class ImportKeysListFragment extends SherlockListFragment implements
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
} }
public void loadNew(byte[] importData, Uri dataUri, String serverQuery, String keyServer) { public void loadNew(byte[] keyBytes, Uri dataUri, String serverQuery, String keyServer) {
mKeyBytes = importData; mKeyBytes = keyBytes;
mDataUri = dataUri; mDataUri = dataUri;
mServerQuery = serverQuery; mServerQuery = serverQuery;
mKeyServer = keyServer; mKeyServer = keyServer;

View File

@ -17,8 +17,10 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.util.Log;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
@ -124,10 +126,10 @@ public class ImportKeysServerFragment extends Fragment {
mImportActivity = (ImportKeysActivity) getActivity(); mImportActivity = (ImportKeysActivity) getActivity();
// if query has been set on instantiation, search immediately! // set displayed values
if (getArguments() != null && getArguments().containsKey(ARG_QUERY)) { if (getArguments() != null && getArguments().containsKey(ARG_QUERY)) {
String query = getArguments().getString(ARG_QUERY); String query = getArguments().getString(ARG_QUERY);
mQueryEditText.setText(query); mQueryEditText.setText(query, TextView.BufferType.EDITABLE);
String keyServer = null; String keyServer = null;
if (getArguments().containsKey(ARG_KEY_SERVER)) { if (getArguments().containsKey(ARG_KEY_SERVER)) {
@ -138,7 +140,8 @@ public class ImportKeysServerFragment extends Fragment {
keyServer = (String) mServerSpinner.getSelectedItem(); keyServer = (String) mServerSpinner.getSelectedItem();
} }
search(query, keyServer); Log.d(Constants.TAG, "query: " + query);
Log.d(Constants.TAG, "keyServer: " + keyServer);
} }
} }