Merge pull request #2145 from open-keychain/ditch-android-beam
Ditch Android Beam feature
This commit is contained in:
@@ -27,7 +27,6 @@ import android.app.Activity;
|
|||||||
import android.app.ActivityOptions;
|
import android.app.ActivityOptions;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
@@ -68,7 +67,6 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
|
|||||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||||
import org.sufficientlysecure.keychain.ui.util.QrCodeUtils;
|
import org.sufficientlysecure.keychain.ui.util.QrCodeUtils;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.NfcHelper;
|
|
||||||
|
|
||||||
public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
||||||
LoaderManager.LoaderCallbacks<Cursor> {
|
LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
@@ -79,8 +77,6 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
|||||||
private CardView mQrCodeLayout;
|
private CardView mQrCodeLayout;
|
||||||
private TextView mFingerprintView;
|
private TextView mFingerprintView;
|
||||||
|
|
||||||
NfcHelper mNfcHelper;
|
|
||||||
|
|
||||||
private static final int LOADER_ID_UNIFIED = 0;
|
private static final int LOADER_ID_UNIFIED = 0;
|
||||||
|
|
||||||
private Uri mDataUri;
|
private Uri mDataUri;
|
||||||
@@ -94,10 +90,6 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
|||||||
View root = super.onCreateView(inflater, superContainer, savedInstanceState);
|
View root = super.onCreateView(inflater, superContainer, savedInstanceState);
|
||||||
View view = inflater.inflate(R.layout.view_key_adv_share_fragment, getContainer());
|
View view = inflater.inflate(R.layout.view_key_adv_share_fragment, getContainer());
|
||||||
|
|
||||||
ContentResolver contentResolver = ViewKeyAdvShareFragment.this.getActivity().getContentResolver();
|
|
||||||
KeyRepository keyRepository = KeyRepository.createDatabaseInteractor(getContext());
|
|
||||||
mNfcHelper = new NfcHelper(getActivity(), keyRepository);
|
|
||||||
|
|
||||||
mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint);
|
mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint);
|
||||||
mQrCode = (ImageView) view.findViewById(R.id.view_key_qr_code);
|
mQrCode = (ImageView) view.findViewById(R.id.view_key_qr_code);
|
||||||
|
|
||||||
@@ -139,7 +131,6 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
|||||||
View vFingerprintShareButton = view.findViewById(R.id.view_key_action_fingerprint_share);
|
View vFingerprintShareButton = view.findViewById(R.id.view_key_action_fingerprint_share);
|
||||||
View vFingerprintClipboardButton = view.findViewById(R.id.view_key_action_fingerprint_clipboard);
|
View vFingerprintClipboardButton = view.findViewById(R.id.view_key_action_fingerprint_clipboard);
|
||||||
View vKeyShareButton = view.findViewById(R.id.view_key_action_key_share);
|
View vKeyShareButton = view.findViewById(R.id.view_key_action_key_share);
|
||||||
View vKeyNfcButton = view.findViewById(R.id.view_key_action_key_nfc);
|
|
||||||
View vKeyClipboardButton = view.findViewById(R.id.view_key_action_key_clipboard);
|
View vKeyClipboardButton = view.findViewById(R.id.view_key_action_key_clipboard);
|
||||||
ImageButton vKeySafeSlingerButton = (ImageButton) view.findViewById(R.id.view_key_action_key_safeslinger);
|
ImageButton vKeySafeSlingerButton = (ImageButton) view.findViewById(R.id.view_key_action_key_safeslinger);
|
||||||
View vKeyUploadButton = view.findViewById(R.id.view_key_action_upload);
|
View vKeyUploadButton = view.findViewById(R.id.view_key_action_upload);
|
||||||
@@ -171,18 +162,6 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
vKeyNfcButton.setVisibility(View.VISIBLE);
|
|
||||||
vKeyNfcButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
mNfcHelper.invokeNfcBeam();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
vKeyNfcButton.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
vKeySafeSlingerButton.setOnClickListener(new View.OnClickListener() {
|
vKeySafeSlingerButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@@ -357,9 +336,6 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
|
|||||||
// Prepare the loaders. Either re-connect with an existing ones,
|
// Prepare the loaders. Either re-connect with an existing ones,
|
||||||
// or start new ones.
|
// or start new ones.
|
||||||
getLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
|
getLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
|
||||||
|
|
||||||
// Prepare the NfcHelper
|
|
||||||
mNfcHelper.initNfc(mDataUri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static final String[] UNIFIED_PROJECTION = new String[]{
|
static final String[] UNIFIED_PROJECTION = new String[]{
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import android.database.Cursor;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.nfc.NfcAdapter;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -112,7 +111,6 @@ import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
|||||||
import org.sufficientlysecure.keychain.ui.util.QrCodeUtils;
|
import org.sufficientlysecure.keychain.ui.util.QrCodeUtils;
|
||||||
import org.sufficientlysecure.keychain.util.ContactHelper;
|
import org.sufficientlysecure.keychain.util.ContactHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.NfcHelper;
|
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
@@ -157,7 +155,6 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
|
|
||||||
private ImageButton mActionEncryptFile;
|
private ImageButton mActionEncryptFile;
|
||||||
private ImageButton mActionEncryptText;
|
private ImageButton mActionEncryptText;
|
||||||
private ImageButton mActionNfc;
|
|
||||||
private FloatingActionButton mFab;
|
private FloatingActionButton mFab;
|
||||||
private ImageView mPhoto;
|
private ImageView mPhoto;
|
||||||
private FrameLayout mPhotoLayout;
|
private FrameLayout mPhotoLayout;
|
||||||
@@ -166,9 +163,6 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
|
|
||||||
private String mQrCodeLoaded;
|
private String mQrCodeLoaded;
|
||||||
|
|
||||||
// NFC
|
|
||||||
private NfcHelper mNfcHelper;
|
|
||||||
|
|
||||||
private static final int LOADER_ID_UNIFIED = 0;
|
private static final int LOADER_ID_UNIFIED = 0;
|
||||||
|
|
||||||
private boolean mIsSecret = false;
|
private boolean mIsSecret = false;
|
||||||
@@ -211,7 +205,6 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
|
|
||||||
mActionEncryptFile = (ImageButton) findViewById(R.id.view_key_action_encrypt_files);
|
mActionEncryptFile = (ImageButton) findViewById(R.id.view_key_action_encrypt_files);
|
||||||
mActionEncryptText = (ImageButton) findViewById(R.id.view_key_action_encrypt_text);
|
mActionEncryptText = (ImageButton) findViewById(R.id.view_key_action_encrypt_text);
|
||||||
mActionNfc = (ImageButton) findViewById(R.id.view_key_action_nfc);
|
|
||||||
mFab = (FloatingActionButton) findViewById(R.id.fab);
|
mFab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
mPhoto = (ImageView) findViewById(R.id.view_key_photo);
|
mPhoto = (ImageView) findViewById(R.id.view_key_photo);
|
||||||
mPhotoLayout = (FrameLayout) findViewById(R.id.view_key_photo_layout);
|
mPhotoLayout = (FrameLayout) findViewById(R.id.view_key_photo_layout);
|
||||||
@@ -224,7 +217,6 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
|
|
||||||
ContentDescriptionHint.setup(mActionEncryptFile);
|
ContentDescriptionHint.setup(mActionEncryptFile);
|
||||||
ContentDescriptionHint.setup(mActionEncryptText);
|
ContentDescriptionHint.setup(mActionEncryptText);
|
||||||
ContentDescriptionHint.setup(mActionNfc);
|
|
||||||
ContentDescriptionHint.setup(mFab);
|
ContentDescriptionHint.setup(mFab);
|
||||||
|
|
||||||
|
|
||||||
@@ -321,20 +313,10 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mActionNfc.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
mNfcHelper.invokeNfcBeam();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Prepare the loaders. Either re-connect with an existing ones,
|
// Prepare the loaders. Either re-connect with an existing ones,
|
||||||
// or start new ones.
|
// or start new ones.
|
||||||
getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
|
getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
|
||||||
|
|
||||||
mNfcHelper = new NfcHelper(this, mKeyRepository);
|
|
||||||
mNfcHelper.initNfc(mDataUri);
|
|
||||||
|
|
||||||
if (savedInstanceState == null && getIntent().hasExtra(EXTRA_DISPLAY_RESULT)) {
|
if (savedInstanceState == null && getIntent().hasExtra(EXTRA_DISPLAY_RESULT)) {
|
||||||
OperationResult result = getIntent().getParcelableExtra(EXTRA_DISPLAY_RESULT);
|
OperationResult result = getIntent().getParcelableExtra(EXTRA_DISPLAY_RESULT);
|
||||||
result.createNotify(this).show();
|
result.createNotify(this).show();
|
||||||
@@ -998,7 +980,6 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
|
|
||||||
mActionEncryptFile.setVisibility(View.INVISIBLE);
|
mActionEncryptFile.setVisibility(View.INVISIBLE);
|
||||||
mActionEncryptText.setVisibility(View.INVISIBLE);
|
mActionEncryptText.setVisibility(View.INVISIBLE);
|
||||||
mActionNfc.setVisibility(View.INVISIBLE);
|
|
||||||
hideFab();
|
hideFab();
|
||||||
mQrCodeLayout.setVisibility(View.GONE);
|
mQrCodeLayout.setVisibility(View.GONE);
|
||||||
} else if (!mIsSecure) {
|
} else if (!mIsSecure) {
|
||||||
@@ -1010,7 +991,6 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
|
|
||||||
mActionEncryptFile.setVisibility(View.INVISIBLE);
|
mActionEncryptFile.setVisibility(View.INVISIBLE);
|
||||||
mActionEncryptText.setVisibility(View.INVISIBLE);
|
mActionEncryptText.setVisibility(View.INVISIBLE);
|
||||||
mActionNfc.setVisibility(View.INVISIBLE);
|
|
||||||
hideFab();
|
hideFab();
|
||||||
mQrCodeLayout.setVisibility(View.GONE);
|
mQrCodeLayout.setVisibility(View.GONE);
|
||||||
} else if (mIsExpired) {
|
} else if (mIsExpired) {
|
||||||
@@ -1022,7 +1002,6 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
|
|
||||||
mActionEncryptFile.setVisibility(View.INVISIBLE);
|
mActionEncryptFile.setVisibility(View.INVISIBLE);
|
||||||
mActionEncryptText.setVisibility(View.INVISIBLE);
|
mActionEncryptText.setVisibility(View.INVISIBLE);
|
||||||
mActionNfc.setVisibility(View.INVISIBLE);
|
|
||||||
hideFab();
|
hideFab();
|
||||||
mQrCodeLayout.setVisibility(View.GONE);
|
mQrCodeLayout.setVisibility(View.GONE);
|
||||||
} else if (mIsSecret) {
|
} else if (mIsSecret) {
|
||||||
@@ -1059,13 +1038,6 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
mActionEncryptFile.setVisibility(View.VISIBLE);
|
mActionEncryptFile.setVisibility(View.VISIBLE);
|
||||||
mActionEncryptText.setVisibility(View.VISIBLE);
|
mActionEncryptText.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
// invokeBeam is available from API 21
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
|
||||||
&& NfcAdapter.getDefaultAdapter(this) != null) {
|
|
||||||
mActionNfc.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
mActionNfc.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
showFab();
|
showFab();
|
||||||
// noinspection deprecation (no getDrawable with theme at current minApi level 15!)
|
// noinspection deprecation (no getDrawable with theme at current minApi level 15!)
|
||||||
mFab.setImageDrawable(getResources().getDrawable(R.drawable.ic_repeat_white_24dp));
|
mFab.setImageDrawable(getResources().getDrawable(R.drawable.ic_repeat_white_24dp));
|
||||||
@@ -1073,7 +1045,6 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
mActionEncryptFile.setVisibility(View.VISIBLE);
|
mActionEncryptFile.setVisibility(View.VISIBLE);
|
||||||
mActionEncryptText.setVisibility(View.VISIBLE);
|
mActionEncryptText.setVisibility(View.VISIBLE);
|
||||||
mQrCodeLayout.setVisibility(View.GONE);
|
mQrCodeLayout.setVisibility(View.GONE);
|
||||||
mActionNfc.setVisibility(View.INVISIBLE);
|
|
||||||
|
|
||||||
if (mIsVerified) {
|
if (mIsVerified) {
|
||||||
mStatusText.setText(R.string.view_key_verified);
|
mStatusText.setText(R.string.view_key_verified);
|
||||||
|
|||||||
@@ -1,216 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2013-2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
|
||||||
* Copyright (C) 2015 Kent Nguyen <kentnguyen@moneylover.me>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.util;
|
|
||||||
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.nfc.NdefMessage;
|
|
||||||
import android.nfc.NdefRecord;
|
|
||||||
import android.nfc.NfcAdapter;
|
|
||||||
import android.nfc.NfcEvent;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class contains NFC functionality that can be shared across Fragments or Activities.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class NfcHelper {
|
|
||||||
|
|
||||||
private Activity mActivity;
|
|
||||||
private KeyRepository mKeyRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC: This handler receives a message from onNdefPushComplete
|
|
||||||
*/
|
|
||||||
private static NfcHandler mNfcHandler;
|
|
||||||
|
|
||||||
private NfcAdapter mNfcAdapter;
|
|
||||||
private NfcAdapter.CreateNdefMessageCallback mNdefCallback;
|
|
||||||
private NfcAdapter.OnNdefPushCompleteCallback mNdefCompleteCallback;
|
|
||||||
private byte[] mNfcKeyringBytes;
|
|
||||||
private static final int NFC_SENT = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the NfcHelper.
|
|
||||||
*/
|
|
||||||
public NfcHelper(final Activity activity, final KeyRepository keyRepository) {
|
|
||||||
mActivity = activity;
|
|
||||||
mKeyRepository = keyRepository;
|
|
||||||
|
|
||||||
mNfcHandler = new NfcHandler(mActivity);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if the NFC Adapter of this Helper has any features enabled.
|
|
||||||
*
|
|
||||||
* @return true if this NFC Adapter has any features enabled
|
|
||||||
*/
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return mNfcAdapter.isEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC: Initialize NFC sharing if OS and device supports it
|
|
||||||
*/
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
||||||
public void initNfc(final Uri dataUri) {
|
|
||||||
// check if NFC Beam is supported (>= Android 4.1)
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
||||||
|
|
||||||
// Implementation for the CreateNdefMessageCallback interface
|
|
||||||
mNdefCallback = new NfcAdapter.CreateNdefMessageCallback() {
|
|
||||||
@Override
|
|
||||||
public NdefMessage createNdefMessage(NfcEvent event) {
|
|
||||||
/*
|
|
||||||
* When a device receives a push with an AAR in it, the application specified in the AAR is
|
|
||||||
* guaranteed to run. The AAR overrides the tag dispatch system. You can add it back in to
|
|
||||||
* guarantee that this activity starts when receiving a beamed message. For now, this code
|
|
||||||
* uses the tag dispatch system.
|
|
||||||
*/
|
|
||||||
return new NdefMessage(NdefRecord.createMime(Constants.MIME_TYPE_KEYS,
|
|
||||||
mNfcKeyringBytes), NdefRecord.createApplicationRecord(Constants.PACKAGE_NAME));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Implementation for the OnNdefPushCompleteCallback interface
|
|
||||||
mNdefCompleteCallback = new NfcAdapter.OnNdefPushCompleteCallback() {
|
|
||||||
@Override
|
|
||||||
public void onNdefPushComplete(NfcEvent event) {
|
|
||||||
// A handler is needed to send messages to the activity when this
|
|
||||||
// callback occurs, because it happens from a binder thread
|
|
||||||
mNfcHandler.obtainMessage(NFC_SENT).sendToTarget();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Check for available NFC Adapter
|
|
||||||
mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity);
|
|
||||||
if (mNfcAdapter != null) {
|
|
||||||
/*
|
|
||||||
* Retrieve mNfcKeyringBytes here asynchronously (to not block the UI)
|
|
||||||
* and init nfc adapter afterwards.
|
|
||||||
* mNfcKeyringBytes can not be retrieved in createNdefMessage, because this process
|
|
||||||
* has no permissions to query the Uri.
|
|
||||||
*/
|
|
||||||
AsyncTask<Void, Void, Void> initTask =
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
|
||||||
protected Void doInBackground(Void... unused) {
|
|
||||||
try {
|
|
||||||
long masterKeyId = mKeyRepository.getCachedPublicKeyRing(dataUri)
|
|
||||||
.extractOrGetMasterKeyId();
|
|
||||||
mNfcKeyringBytes = mKeyRepository.loadPublicKeyRingData(masterKeyId);
|
|
||||||
} catch (NotFoundException | PgpKeyNotFoundException e) {
|
|
||||||
Log.e(Constants.TAG, "key not found!", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// no AsyncTask return (Void)
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onPostExecute(Void unused) {
|
|
||||||
if (mActivity.isFinishing()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register callback to set NDEF message
|
|
||||||
mNfcAdapter.setNdefPushMessageCallback(mNdefCallback,
|
|
||||||
mActivity);
|
|
||||||
// Register callback to listen for message-sent success
|
|
||||||
mNfcAdapter.setOnNdefPushCompleteCallback(mNdefCompleteCallback,
|
|
||||||
mActivity);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
initTask.execute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
public void invokeNfcBeam() {
|
|
||||||
// Check if device supports NFC
|
|
||||||
if (!mActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
|
|
||||||
Notify.create(mActivity, R.string.no_nfc_support, Notify.LENGTH_LONG, Notify.Style.ERROR).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Check for available NFC Adapter
|
|
||||||
mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity);
|
|
||||||
if (mNfcAdapter == null || !mNfcAdapter.isEnabled()) {
|
|
||||||
Notify.create(mActivity, R.string.error_nfc_needed, Notify.LENGTH_LONG, Notify.Style.ERROR, new Notify.ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void onAction() {
|
|
||||||
Intent intentSettings = new Intent(Settings.ACTION_NFC_SETTINGS);
|
|
||||||
mActivity.startActivity(intentSettings);
|
|
||||||
}
|
|
||||||
}, R.string.menu_nfc_preferences).show();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mNfcAdapter.isNdefPushEnabled()) {
|
|
||||||
Notify.create(mActivity, R.string.error_beam_needed, Notify.LENGTH_LONG, Notify.Style.ERROR, new Notify.ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void onAction() {
|
|
||||||
Intent intentSettings = new Intent(Settings.ACTION_NFCSHARING_SETTINGS);
|
|
||||||
mActivity.startActivity(intentSettings);
|
|
||||||
}
|
|
||||||
}, R.string.menu_beam_preferences).show();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mNfcAdapter.invokeBeam(mActivity);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class NfcHandler extends Handler {
|
|
||||||
private final WeakReference<Activity> mActivityReference;
|
|
||||||
|
|
||||||
public NfcHandler(Activity activity) {
|
|
||||||
mActivityReference = new WeakReference<>(activity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
if (mActivityReference.get() != null) {
|
|
||||||
switch (msg.what) {
|
|
||||||
case NFC_SENT:
|
|
||||||
Notify.create(mActivityReference.get(), R.string.nfc_successful, Notify.Style.OK).show();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -111,17 +111,6 @@
|
|||||||
android:src="@drawable/ic_action_encrypt_text_24dp"
|
android:src="@drawable/ic_action_encrypt_text_24dp"
|
||||||
android:visibility="invisible"
|
android:visibility="invisible"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/view_key_action_nfc"
|
|
||||||
style="?android:attr/borderlessButtonStyle"
|
|
||||||
android:contentDescription="@string/cd_share_nfc"
|
|
||||||
android:layout_width="64dp"
|
|
||||||
android:layout_height="64dp"
|
|
||||||
android:src="@drawable/ic_nfc_white_24dp"
|
|
||||||
android:visibility="invisible"
|
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
|||||||
@@ -125,23 +125,6 @@
|
|||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:background="?android:attr/listDivider" />
|
android:background="?android:attr/listDivider" />
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/view_key_action_key_nfc"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:padding="8dp"
|
|
||||||
android:src="@drawable/ic_nfc_grey_24dp"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:background="?android:selectableItemBackground" />
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="1dip"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:gravity="right"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:background="?android:attr/listDivider" />
|
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/view_key_action_key_clipboard"
|
android:id="@+id/view_key_action_key_clipboard"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
Reference in New Issue
Block a user