diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-02-28 15:58:26 +0100 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-02-28 15:58:26 +0100 |
commit | 0557e0680e3cdedc32f8ebe35105b772c7b3935b (patch) | |
tree | e957e9d06e11e5956f958fab08136d6aa8a9b76c /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java | |
parent | 2ae4d6ce05e6ca1585239b779b1dd6f39f58050a (diff) | |
download | open-keychain-0557e0680e3cdedc32f8ebe35105b772c7b3935b.tar.gz open-keychain-0557e0680e3cdedc32f8ebe35105b772c7b3935b.tar.bz2 open-keychain-0557e0680e3cdedc32f8ebe35105b772c7b3935b.zip |
some changes to qr scan logic
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java | 73 |
1 files changed, 51 insertions, 22 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java index 4cb6c69e0..94eaa8171 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java @@ -57,6 +57,9 @@ public class ImportKeysProxyActivity extends FragmentActivity { public static final String ACTION_QR_CODE_API = OpenKeychainIntents.IMPORT_KEY_FROM_QR_CODE; public static final String ACTION_SCAN_WITH_RESULT = Constants.INTENT_PREFIX + "SCAN_QR_CODE_WITH_RESULT"; + public static final String ACTION_SCAN_IMPORT = Constants.INTENT_PREFIX + "SCAN_QR_CODE_IMPORT"; + + public static final String EXTRA_FINGERPRINT = "fingerprint"; boolean returnResult; @@ -78,10 +81,15 @@ public class ImportKeysProxyActivity extends FragmentActivity { // Scanning a fingerprint directly with Barcode Scanner, thus we already have scanned returnResult = false; - startCertify(dataUri); + processScannedContent(dataUri); + } else if (ACTION_SCAN_IMPORT.equals(action)) { + returnResult = false; + IntentIntegrator integrator = new IntentIntegrator(this); + integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES) + .setPrompt(getString(R.string.import_qr_code_text)) + .setResultDisplayDuration(0) + .initiateScan(); } else if (ACTION_SCAN_WITH_RESULT.equals(action)) { - // scan using xzing's Barcode Scanner and return result parcel in OpenKeychain - returnResult = true; IntentIntegrator integrator = new IntentIntegrator(this); integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES) @@ -113,16 +121,16 @@ public class ImportKeysProxyActivity extends FragmentActivity { if (requestCode == IntentIntegratorSupportV4.REQUEST_CODE) { IntentResult scanResult = IntentIntegratorSupportV4.parseActivityResult(requestCode, resultCode, data); - if (scanResult != null && scanResult.getFormatName() != null) { - String scannedContent = scanResult.getContents(); - Log.d(Constants.TAG, "scannedContent: " + scannedContent); - startCertify(Uri.parse(scanResult.getContents())); - } else { + if (scanResult == null || scanResult.getFormatName() == null) { Log.e(Constants.TAG, "scanResult or formatName null! Should not happen!"); finish(); + return; } + String scannedContent = scanResult.getContents(); + processScannedContent(scannedContent); + return; } // if a result has been returned, return it down to other activity @@ -134,6 +142,41 @@ public class ImportKeysProxyActivity extends FragmentActivity { } } + private void processScannedContent(String content) { + Uri uri = Uri.parse(content); + processScannedContent(uri); + } + + private void processScannedContent(Uri uri) { + + Log.d(Constants.TAG, "scanned: " + uri.toString()); + + String fingerprint = null; + + // example: openpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282 + if (uri.getScheme().toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) { + fingerprint = uri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH); + } + + if (fingerprint == null) { + SingletonResult result = new SingletonResult( + SingletonResult.RESULT_ERROR, OperationResult.LogType.MSG_WRONG_QR_CODE); + Intent intent = new Intent(); + intent.putExtra(SingletonResult.EXTRA_RESULT, result); + returnResult(intent); + return; + } + + if (returnResult) { + Intent result = new Intent(); + result.putExtra(EXTRA_FINGERPRINT, fingerprint); + setResult(RESULT_OK, result); + finish(); + } else { + importKeys(fingerprint); + } + } + public void returnResult(Intent data) { if (returnResult) { setResult(RESULT_OK, data); @@ -147,20 +190,6 @@ public class ImportKeysProxyActivity extends FragmentActivity { } } - public void startCertify(Uri dataUri) { - // example: openpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282 - if (dataUri.getScheme().equals(Constants.FINGERPRINT_SCHEME)) { - String fingerprint = dataUri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH); - importKeys(fingerprint); - } else { - SingletonResult result = new SingletonResult( - SingletonResult.RESULT_ERROR, OperationResult.LogType.MSG_WRONG_QR_CODE); - Intent intent = new Intent(); - intent.putExtra(SingletonResult.EXTRA_RESULT, result); - returnResult(intent); - } - } - public void importKeys(byte[] keyringData) { ParcelableKeyRing keyEntry = new ParcelableKeyRing(keyringData); |