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,
|
ImportKeysClipboardFragment.class,
|
||||||
ImportKeysNFCFragment.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;
|
private int mCurrentNavPosition = -1;
|
||||||
|
|
||||||
@ -152,7 +157,7 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
|||||||
/* Keychain's own Actions */
|
/* Keychain's own Actions */
|
||||||
|
|
||||||
// display file fragment
|
// display file fragment
|
||||||
loadNavFragment(1, null);
|
loadNavFragment(NAV_FILE, null);
|
||||||
|
|
||||||
if (dataUri != null) {
|
if (dataUri != null) {
|
||||||
// action: directly load data
|
// action: directly load data
|
||||||
@ -187,7 +192,7 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
|||||||
// display keyserver fragment with query
|
// display keyserver fragment with query
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
args.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
||||||
loadNavFragment(0, args);
|
loadNavFragment(NAV_SERVER, args);
|
||||||
|
|
||||||
// action: search immediately
|
// action: search immediately
|
||||||
startListFragment(savedInstanceState, null, null, query);
|
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)) {
|
} else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) {
|
||||||
|
|
||||||
// NOTE: this only displays the appropriate fragment, no actions are taken
|
// NOTE: this only displays the appropriate fragment, no actions are taken
|
||||||
loadNavFragment(1, null);
|
loadNavFragment(NAV_FILE, null);
|
||||||
|
|
||||||
// no immediate actions!
|
// no immediate actions!
|
||||||
startListFragment(savedInstanceState, null, null, null);
|
startListFragment(savedInstanceState, null, null, null);
|
||||||
@ -220,14 +225,14 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
|||||||
// also exposed in AndroidManifest
|
// also exposed in AndroidManifest
|
||||||
|
|
||||||
// NOTE: this only displays the appropriate fragment, no actions are taken
|
// NOTE: this only displays the appropriate fragment, no actions are taken
|
||||||
loadNavFragment(2, null);
|
loadNavFragment(NAV_QR_CODE, null);
|
||||||
|
|
||||||
// no immediate actions!
|
// no immediate actions!
|
||||||
startListFragment(savedInstanceState, null, null, null);
|
startListFragment(savedInstanceState, null, null, null);
|
||||||
} else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) {
|
} else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) {
|
||||||
|
|
||||||
// NOTE: this only displays the appropriate fragment, no actions are taken
|
// NOTE: this only displays the appropriate fragment, no actions are taken
|
||||||
loadNavFragment(3, null);
|
loadNavFragment(NAV_NFC, null);
|
||||||
|
|
||||||
// no immediate actions!
|
// no immediate actions!
|
||||||
startListFragment(savedInstanceState, null, null, null);
|
startListFragment(savedInstanceState, null, null, null);
|
||||||
@ -327,7 +332,7 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
|
|||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
args.putString(ImportKeysServerFragment.ARG_QUERY, query);
|
||||||
args.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true);
|
args.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true);
|
||||||
loadNavFragment(0, args);
|
loadNavFragment(NAV_SERVER, args);
|
||||||
|
|
||||||
// action: search directly
|
// action: search directly
|
||||||
startListFragment(savedInstanceState, null, null, query);
|
startListFragment(savedInstanceState, null, null, query);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.net.Uri;
|
||||||
import android.nfc.NdefMessage;
|
import android.nfc.NdefMessage;
|
||||||
import android.nfc.NdefRecord;
|
import android.nfc.NdefRecord;
|
||||||
import android.nfc.NfcAdapter;
|
import android.nfc.NfcAdapter;
|
||||||
@ -29,12 +30,12 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.devspark.appmsg.AppMsg;
|
import com.devspark.appmsg.AppMsg;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
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) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
// Check for available NFC Adapter
|
// Check for available NFC Adapter
|
||||||
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
|
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 =
|
protected void onPostExecute(Void result) {
|
||||||
// new AsyncTask<NfcAdapter, Void, Void>() {
|
// Register callback to set NDEF message
|
||||||
// protected Void doInBackground(NfcAdapter... adapter) {
|
mNfcAdapter.setNdefPushMessageCallback(ViewKeyActivityJB.this
|
||||||
// if (adapter != null) {
|
, ViewKeyActivityJB.this);
|
||||||
// // init nfc
|
// Register callback to listen for message-sent success
|
||||||
// // Register callback to set NDEF message
|
mNfcAdapter.setOnNdefPushCompleteCallback(ViewKeyActivityJB.this,
|
||||||
// adapter.setNdefPushMessageCallback(ViewKeyActivityJB.this, 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) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
* guarantee that this activity starts when receiving a beamed message. For now, this code
|
||||||
* uses the tag dispatch system.
|
* uses the tag dispatch system.
|
||||||
*/
|
*/
|
||||||
// try {
|
NdefMessage msg = new NdefMessage(NdefRecord.createMime(Constants.NFC_MIME,
|
||||||
// get public keyring as byte array
|
mSharedKeyringBytes), NdefRecord.createApplicationRecord(Constants.PACKAGE_NAME));
|
||||||
// event.nfcAdapter.
|
return msg;
|
||||||
// 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;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user