added log to QR code scan/import fail

This commit is contained in:
Adithya Abraham Philip 2015-04-21 23:16:33 +05:30
parent a658d3c1e1
commit 5a4a8f2b6a

View File

@ -58,13 +58,12 @@ import java.util.Locale;
public class ImportKeysProxyActivity extends FragmentActivity { public class ImportKeysProxyActivity extends FragmentActivity {
public static final String ACTION_QR_CODE_API = OpenKeychainIntents.IMPORT_KEY_FROM_QR_CODE; public static final String ACTION_QR_CODE_API = OpenKeychainIntents.IMPORT_KEY_FROM_QR_CODE;
// implies activity returns scanned fingerprint as extra and does not import
public static final String ACTION_SCAN_WITH_RESULT = Constants.INTENT_PREFIX + "SCAN_QR_CODE_WITH_RESULT"; 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 ACTION_SCAN_IMPORT = Constants.INTENT_PREFIX + "SCAN_QR_CODE_IMPORT";
public static final String EXTRA_FINGERPRINT = "fingerprint"; public static final String EXTRA_FINGERPRINT = "fingerprint";
boolean returnResult;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -82,10 +81,8 @@ public class ImportKeysProxyActivity extends FragmentActivity {
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, thus we already have scanned // Scanning a fingerprint directly with Barcode Scanner, thus we already have scanned
returnResult = false;
processScannedContent(dataUri); processScannedContent(dataUri);
} else if (ACTION_SCAN_IMPORT.equals(action) || ACTION_QR_CODE_API.equals(action)) { } else if (ACTION_SCAN_IMPORT.equals(action) || ACTION_QR_CODE_API.equals(action)) {
returnResult = false;
IntentIntegrator integrator = new IntentIntegrator(this); IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES) integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES)
.setPrompt(getString(R.string.import_qr_code_text)) .setPrompt(getString(R.string.import_qr_code_text))
@ -93,7 +90,6 @@ public class ImportKeysProxyActivity extends FragmentActivity {
integrator.setOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); integrator.setOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
integrator.initiateScan(); integrator.initiateScan();
} else if (ACTION_SCAN_WITH_RESULT.equals(action)) { } else if (ACTION_SCAN_WITH_RESULT.equals(action)) {
returnResult = true;
IntentIntegrator integrator = new IntentIntegrator(this); IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES) integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES)
.setPrompt(getString(R.string.import_qr_code_text)) .setPrompt(getString(R.string.import_qr_code_text))
@ -103,7 +99,6 @@ public class ImportKeysProxyActivity extends FragmentActivity {
} else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { } else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
// Check to see if the Activity started due to an Android Beam // Check to see if the Activity started due to an Android Beam
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
returnResult = false;
handleActionNdefDiscovered(getIntent()); handleActionNdefDiscovered(getIntent());
} else { } else {
Log.e(Constants.TAG, "Android Beam not supported by Android < 4.1"); Log.e(Constants.TAG, "Android Beam not supported by Android < 4.1");
@ -148,6 +143,8 @@ public class ImportKeysProxyActivity extends FragmentActivity {
private void processScannedContent(Uri uri) { private void processScannedContent(Uri uri) {
String action = getIntent().getAction();
Log.d(Constants.TAG, "scanned: " + uri); Log.d(Constants.TAG, "scanned: " + uri);
String fingerprint = null; String fingerprint = null;
@ -166,7 +163,7 @@ public class ImportKeysProxyActivity extends FragmentActivity {
return; return;
} }
if (returnResult) { if (ACTION_SCAN_WITH_RESULT.equals(action)) {
Intent result = new Intent(); Intent result = new Intent();
result.putExtra(EXTRA_FINGERPRINT, fingerprint); result.putExtra(EXTRA_FINGERPRINT, fingerprint);
setResult(RESULT_OK, result); setResult(RESULT_OK, result);
@ -177,15 +174,17 @@ public class ImportKeysProxyActivity extends FragmentActivity {
} }
public void returnResult(Intent data) { public void returnResult(Intent data) {
if (returnResult) { String action = getIntent().getAction();
setResult(RESULT_OK, data);
finish(); if (ACTION_QR_CODE_API.equals(action)) {
} else {
// display last log message but as Toast for calls from outside OpenKeychain // display last log message but as Toast for calls from outside OpenKeychain
OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT); OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT);
String str = getString(result.getLog().getLast().mType.getMsgId()); String str = getString(result.getLog().getLast().mType.getMsgId());
Toast.makeText(this, str, Toast.LENGTH_LONG).show(); Toast.makeText(this, str, Toast.LENGTH_LONG).show();
finish(); finish();
} else {
setResult(RESULT_OK, data);
finish();
} }
} }
@ -209,7 +208,7 @@ public class ImportKeysProxyActivity extends FragmentActivity {
} }
private void startImportService (ArrayList<ParcelableKeyRing> keyRings) { private void startImportService(ArrayList<ParcelableKeyRing> keyRings) {
// Message is received after importing is done in KeychainIntentService // Message is received after importing is done in KeychainIntentService
ServiceProgressHandler serviceHandler = new ServiceProgressHandler( ServiceProgressHandler serviceHandler = new ServiceProgressHandler(