mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
Fix NFC
This commit is contained in:
parent
a0a51c9f92
commit
19b62d67b3
@ -93,6 +93,11 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
ImportKeysClipboardFragment.class,
|
||||
ImportKeysNFCFragment.class
|
||||
};
|
||||
private static final int NAV_SERVER = 0;
|
||||
private static final int NAV_FILE = 1;
|
||||
private static final int NAV_QR_CODE = 2;
|
||||
private static final int NAV_CLIPBOARD = 3;
|
||||
private static final int NAV_NFC = 4;
|
||||
|
||||
private int mCurrentNavPosition = -1;
|
||||
|
||||
@ -152,7 +157,7 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
/* Keychain's own Actions */
|
||||
|
||||
// display file fragment
|
||||
loadNavFragment(1, null);
|
||||
loadNavFragment(NAV_FILE, null);
|
||||
|
||||
if (dataUri != null) {
|
||||
// action: directly load data
|
||||
@ -187,7 +192,7 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
// display keyserver fragment with query
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
||||
loadNavFragment(0, args);
|
||||
loadNavFragment(NAV_SERVER, args);
|
||||
|
||||
// action: search immediately
|
||||
startListFragment(savedInstanceState, null, null, query);
|
||||
@ -212,7 +217,7 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
} else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) {
|
||||
|
||||
// NOTE: this only displays the appropriate fragment, no actions are taken
|
||||
loadNavFragment(1, null);
|
||||
loadNavFragment(NAV_FILE, null);
|
||||
|
||||
// no immediate actions!
|
||||
startListFragment(savedInstanceState, null, null, null);
|
||||
@ -220,14 +225,14 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
// also exposed in AndroidManifest
|
||||
|
||||
// NOTE: this only displays the appropriate fragment, no actions are taken
|
||||
loadNavFragment(2, null);
|
||||
loadNavFragment(NAV_QR_CODE, null);
|
||||
|
||||
// no immediate actions!
|
||||
startListFragment(savedInstanceState, null, null, null);
|
||||
} else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) {
|
||||
|
||||
// NOTE: this only displays the appropriate fragment, no actions are taken
|
||||
loadNavFragment(3, null);
|
||||
loadNavFragment(NAV_NFC, null);
|
||||
|
||||
// no immediate actions!
|
||||
startListFragment(savedInstanceState, null, null, null);
|
||||
@ -327,7 +332,7 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
||||
args.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true);
|
||||
loadNavFragment(0, args);
|
||||
loadNavFragment(NAV_SERVER, args);
|
||||
|
||||
// action: search directly
|
||||
startListFragment(savedInstanceState, null, null, query);
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.net.Uri;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefRecord;
|
||||
import android.nfc.NfcAdapter;
|
||||
@ -29,12 +30,12 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.devspark.appmsg.AppMsg;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
@ -63,29 +64,40 @@ public class ViewKeyActivityJB extends ViewKeyActivity implements CreateNdefMess
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
// Check for available NFC Adapter
|
||||
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
|
||||
if (mNfcAdapter != null) {
|
||||
/*
|
||||
* Retrieve mSharedKeyringBytes here asynchronously (to not block the UI)
|
||||
* and init nfc adapter afterwards.
|
||||
* mSharedKeyringBytes can not be retrieved in createNdefMessage, because this process
|
||||
* has no permissions to query the Uri.
|
||||
*/
|
||||
AsyncTask<NfcAdapter, Void, Void> initTask =
|
||||
new AsyncTask<NfcAdapter, Void, Void>() {
|
||||
protected Void doInBackground(NfcAdapter... adapter) {
|
||||
try {
|
||||
Uri dataUri = KeychainContract.KeyRingData.buildPublicKeyRingUri(mDataUri);
|
||||
mSharedKeyringBytes = ProviderHelper.getPGPKeyRing(
|
||||
ViewKeyActivityJB.this, dataUri).getEncoded();
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "Error parsing keyring", e);
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG, "key not found!", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// AsyncTask<NfcAdapter, Void, Void> registerTask =
|
||||
// new AsyncTask<NfcAdapter, Void, Void>() {
|
||||
// protected Void doInBackground(NfcAdapter... adapter) {
|
||||
// if (adapter != null) {
|
||||
// // init nfc
|
||||
// // Register callback to set NDEF message
|
||||
// adapter.setNdefPushMessageCallback(ViewKeyActivityJB.this, ViewKeyActivityJB.this);
|
||||
// // Register callback to listen for message-sent success
|
||||
// adapter.setOnNdefPushCompleteCallback(this, this);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// protected void onProgressUpdate() {
|
||||
// }
|
||||
//
|
||||
// protected void onPostExecute(Void result) {
|
||||
//
|
||||
// }
|
||||
// };
|
||||
|
||||
protected void onPostExecute(Void result) {
|
||||
// Register callback to set NDEF message
|
||||
mNfcAdapter.setNdefPushMessageCallback(ViewKeyActivityJB.this
|
||||
, ViewKeyActivityJB.this);
|
||||
// Register callback to listen for message-sent success
|
||||
mNfcAdapter.setOnNdefPushCompleteCallback(ViewKeyActivityJB.this,
|
||||
ViewKeyActivityJB.this);
|
||||
}
|
||||
};
|
||||
|
||||
initTask.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,21 +112,9 @@ public class ViewKeyActivityJB extends ViewKeyActivity implements CreateNdefMess
|
||||
* guarantee that this activity starts when receiving a beamed message. For now, this code
|
||||
* uses the tag dispatch system.
|
||||
*/
|
||||
// try {
|
||||
// get public keyring as byte array
|
||||
// event.nfcAdapter.
|
||||
// mSharedKeyringBytes = ProviderHelper.getPGPKeyRing(this, mDataUri).getEncoded();
|
||||
//
|
||||
// NdefMessage msg = new NdefMessage(NdefRecord.createMime(Constants.NFC_MIME,
|
||||
// mSharedKeyringBytes), NdefRecord.createApplicationRecord(Constants.PACKAGE_NAME));
|
||||
// return msg;
|
||||
// } catch(IOException e) {
|
||||
// Log.e(Constants.TAG, "Error parsing keyring", e);
|
||||
// return null;
|
||||
// } catch (ProviderHelper.NotFoundException e) {
|
||||
// Log.e(Constants.TAG, "key not found!", e);
|
||||
return null;
|
||||
// }
|
||||
NdefMessage msg = new NdefMessage(NdefRecord.createMime(Constants.NFC_MIME,
|
||||
mSharedKeyringBytes), NdefRecord.createApplicationRecord(Constants.PACKAGE_NAME));
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user