go to directly to certify screen after nfc import

This commit is contained in:
Vincent Breitmoser 2015-02-27 18:05:36 +01:00
parent ea4ca9e686
commit 2cd7be6373
5 changed files with 79 additions and 94 deletions

View File

@ -451,7 +451,7 @@
android:value=".ui.MainActivity" />
</activity>
<activity
android:name=".ui.QrCodeScanActivity"
android:name=".ui.ImportKeysProxyActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoDisplay"
@ -478,6 +478,14 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- NFC: Handle NFC tags detected from outside our application -->
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<!-- MIME type as defined in http://tools.ietf.org/html/rfc3156 -->
<data android:mimeType="application/pgp-keys" />
</intent-filter>
</activity>
<activity
@ -502,14 +510,6 @@
-->
<data android:mimeType="text/plain" />
</intent-filter>
<!-- NFC: Handle NFC tags detected from outside our application -->
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<!-- MIME type as defined in http://tools.ietf.org/html/rfc3156 -->
<data android:mimeType="application/pgp-keys" />
</intent-filter>
<!-- VIEW with file endings: *.gpg (e.g. to import from OI File Manager) -->
<intent-filter android:label="@string/intent_import_key">
<action android:name="android.intent.action.VIEW" />

View File

@ -17,17 +17,12 @@
package org.sufficientlysecure.keychain.ui;
import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.View.OnClickListener;
@ -63,9 +58,6 @@ public class ImportKeysActivity extends BaseActivity {
// Actions for internal use only:
public static final String ACTION_IMPORT_KEY_FROM_FILE = Constants.INTENT_PREFIX
+ "IMPORT_KEY_FROM_FILE";
public static final String ACTION_IMPORT_KEY_FROM_NFC = Constants.INTENT_PREFIX
+ "IMPORT_KEY_FROM_NFC";
public static final String EXTRA_RESULT = "result";
// only used by ACTION_IMPORT_KEY
@ -215,15 +207,6 @@ public class ImportKeysActivity extends BaseActivity {
startListFragment(savedInstanceState, null, null, null);
break;
}
case ACTION_IMPORT_KEY_FROM_NFC: {
// NOTE: this only displays the appropriate fragment, no actions are taken
startFileFragment(savedInstanceState);
// TODO!!!!!
// no immediate actions!
startListFragment(savedInstanceState, null, null, null);
break;
}
default: {
startCloudFragment(savedInstanceState, null, false);
startListFragment(savedInstanceState, null, null, null);
@ -433,50 +416,4 @@ public class ImportKeysActivity extends BaseActivity {
}
}
/**
* NFC
*/
@Override
public void onResume() {
super.onResume();
// Check to see if the Activity started due to an Android Beam
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
handleActionNdefDiscovered(getIntent());
} else {
Log.d(Constants.TAG, "NFC: No NDEF discovered!");
}
} else {
Log.e(Constants.TAG, "Android Beam not supported by Android < 4.1");
}
}
/**
* NFC
*/
@Override
public void onNewIntent(Intent intent) {
// onResume gets called after this to handle the intent
setIntent(intent);
}
/**
* NFC: Parses the NDEF Message from the intent and prints to the TextView
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
void handleActionNdefDiscovered(Intent intent) {
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
// only one message sent during the beam
NdefMessage msg = (NdefMessage) rawMsgs[0];
// record 0 contains the MIME type, record 1 is the AAR, if present
byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload();
Intent importIntent = new Intent(this, ImportKeysActivity.class);
importIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY);
importIntent.putExtra(ImportKeysActivity.EXTRA_KEY_BYTES, receivedKeyringBytes);
handleActions(null, importIntent);
}
}

View File

@ -17,12 +17,17 @@
package org.sufficientlysecure.keychain.ui;
import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
import android.os.Parcelable;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
@ -48,7 +53,7 @@ import java.util.Locale;
/**
* Proxy activity (just a transparent content view) to scan QR Codes using the Barcode Scanner app
*/
public class QrCodeScanActivity 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_SCAN_WITH_RESULT = Constants.INTENT_PREFIX + "SCAN_QR_CODE_WITH_RESULT";
@ -88,6 +93,15 @@ public class QrCodeScanActivity extends FragmentActivity {
returnResult = false;
new IntentIntegrator(this).initiateScan();
} else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
// Check to see if the Activity started due to an Android Beam
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
returnResult = false;
handleActionNdefDiscovered(getIntent());
} else {
Log.e(Constants.TAG, "Android Beam not supported by Android < 4.1");
finish();
}
} else {
Log.e(Constants.TAG, "No valid scheme or action given!");
finish();
@ -116,6 +130,7 @@ public class QrCodeScanActivity extends FragmentActivity {
returnResult(data);
} else {
super.onActivityResult(requestCode, resultCode, data);
finish();
}
}
@ -146,7 +161,28 @@ public class QrCodeScanActivity extends FragmentActivity {
}
}
public void importKeys(byte[] keyringData) {
ParcelableKeyRing keyEntry = new ParcelableKeyRing(keyringData);
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
selectedEntries.add(keyEntry);
startImportService(selectedEntries);
}
public void importKeys(String fingerprint) {
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null);
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
selectedEntries.add(keyEntry);
startImportService(selectedEntries);
}
private void startImportService (ArrayList<ParcelableKeyRing> keyRings) {
// Message is received after importing is done in KeychainIntentService
KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(
this,
@ -180,34 +216,32 @@ public class QrCodeScanActivity extends FragmentActivity {
return;
}
Intent certifyIntent = new Intent(QrCodeScanActivity.this, CertifyKeyActivity.class);
Intent certifyIntent = new Intent(ImportKeysProxyActivity.this,
CertifyKeyActivity.class);
certifyIntent.putExtra(CertifyKeyActivity.EXTRA_RESULT, result);
certifyIntent.putExtra(CertifyKeyActivity.EXTRA_KEY_IDS, result.getImportedMasterKeyIds());
certifyIntent.putExtra(CertifyKeyActivity.EXTRA_KEY_IDS,
result.getImportedMasterKeyIds());
startActivityForResult(certifyIntent, 0);
}
}
};
// search config
Preferences prefs = Preferences.getPreferences(this);
Preferences.CloudSearchPrefs cloudPrefs = new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver());
// Send all information needed to service to query keys in other thread
Intent intent = new Intent(this, KeychainIntentService.class);
intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);
// fill values for this action
Bundle data = new Bundle();
data.putString(KeychainIntentService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);
// search config
{
Preferences prefs = Preferences.getPreferences(this);
Preferences.CloudSearchPrefs cloudPrefs =
new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver());
data.putString(KeychainIntentService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);
}
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null);
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
selectedEntries.add(keyEntry);
data.putParcelableArrayList(KeychainIntentService.IMPORT_KEY_LIST, selectedEntries);
data.putParcelableArrayList(KeychainIntentService.IMPORT_KEY_LIST, keyRings);
// Send all information needed to service to query keys in other thread
Intent intent = new Intent(this, KeychainIntentService.class);
intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
// Create a new Messenger for the communication back
@ -219,6 +253,20 @@ public class QrCodeScanActivity extends FragmentActivity {
// start service with intent
startService(intent);
}
/**
* NFC: Parses the NDEF Message from the intent and prints to the TextView
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
void handleActionNdefDiscovered(Intent intent) {
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
// only one message sent during the beam
NdefMessage msg = (NdefMessage) rawMsgs[0];
// record 0 contains the MIME type, record 1 is the AAR, if present
byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload();
importKeys(receivedKeyringBytes);
}
}

View File

@ -602,8 +602,8 @@ public class KeyListFragment extends LoaderFragment
}
private void scanQrCode() {
Intent scanQrCode = new Intent(getActivity(), QrCodeScanActivity.class);
scanQrCode.setAction(QrCodeScanActivity.ACTION_SCAN_WITH_RESULT);
Intent scanQrCode = new Intent(getActivity(), ImportKeysProxyActivity.class);
scanQrCode.setAction(ImportKeysProxyActivity.ACTION_SCAN_WITH_RESULT);
startActivityForResult(scanQrCode, 0);
}

View File

@ -316,8 +316,8 @@ public class ViewKeyActivity extends BaseActivity implements
}
private void scanQrCode() {
Intent scanQrCode = new Intent(this, QrCodeScanActivity.class);
scanQrCode.setAction(QrCodeScanActivity.ACTION_SCAN_WITH_RESULT);
Intent scanQrCode = new Intent(this, ImportKeysProxyActivity.class);
scanQrCode.setAction(ImportKeysProxyActivity.ACTION_SCAN_WITH_RESULT);
startActivityForResult(scanQrCode, 0);
}