Generic share of keyring via Android Intent SEND, renaming of own share intents

This commit is contained in:
Dominik Schürmann 2013-01-08 22:12:23 +01:00
parent 049dc908f8
commit d515b26796
8 changed files with 62 additions and 32 deletions

View File

@ -81,8 +81,11 @@ public class ApgIntentHelper {
/** /**
* Share actions * Share actions
*/ */
public static final String ACTION_SHARE_WITH_QR_CODE = APG_INTENT_PREFIX + "SHARE_WITH_QR_CODE"; public static final String ACTION_SHARE_KEYRING = APG_INTENT_PREFIX + "SHARE_KEYRING";
public static final String ACTION_SHARE_WITH_NFC = APG_INTENT_PREFIX + "SHARE_WITH_NFC"; public static final String ACTION_SHARE_KEYRING_WITH_QR_CODE = APG_INTENT_PREFIX
+ "SHARE_KEYRING_WITH_QR_CODE";
public static final String ACTION_SHARE_KEYRING_WITH_NFC = APG_INTENT_PREFIX
+ "SHARE_KEYRING_WITH_NFC";
// used by SHARE_WITH_QR_CODE and SHARE_WITH_NFC // used by SHARE_WITH_QR_CODE and SHARE_WITH_NFC
public static final String EXTRA_MASTER_KEY_ID = "masterKeyId"; public static final String EXTRA_MASTER_KEY_ID = "masterKeyId";
@ -168,7 +171,7 @@ public class ApgIntentHelper {
* @return true when activity was found and executed successfully * @return true when activity was found and executed successfully
*/ */
public boolean shareWithQrCode(long masterKeyId) { public boolean shareWithQrCode(long masterKeyId) {
Intent intent = new Intent(ACTION_SHARE_WITH_QR_CODE); Intent intent = new Intent(ACTION_SHARE_KEYRING_WITH_QR_CODE);
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION); intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
intent.putExtra(EXTRA_MASTER_KEY_ID, masterKeyId); intent.putExtra(EXTRA_MASTER_KEY_ID, masterKeyId);
try { try {
@ -186,7 +189,7 @@ public class ApgIntentHelper {
* @return true when activity was found and executed successfully * @return true when activity was found and executed successfully
*/ */
public boolean shareWithNfc(long masterKeyId) { public boolean shareWithNfc(long masterKeyId) {
Intent intent = new Intent(ACTION_SHARE_WITH_NFC); Intent intent = new Intent(ACTION_SHARE_KEYRING_WITH_NFC);
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION); intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
intent.putExtra(EXTRA_MASTER_KEY_ID, masterKeyId); intent.putExtra(EXTRA_MASTER_KEY_ID, masterKeyId);
try { try {

View File

@ -364,7 +364,7 @@
android:launchMode="singleTop" android:launchMode="singleTop"
android:uiOptions="splitActionBarWhenNarrow" > android:uiOptions="splitActionBarWhenNarrow" >
<intent-filter> <intent-filter>
<action android:name="org.thialfihar.android.apg.intent.SHARE_WITH_NFC" /> <action android:name="org.thialfihar.android.apg.intent.SHARE_KEYRING_WITH_NFC" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
@ -378,9 +378,10 @@
<data android:mimeType="application/org.thialfihar.android.apg" /> <data android:mimeType="application/org.thialfihar.android.apg" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="org.thialfihar.android.apg.ui.ShareQrCodeActivity" > <activity android:name="org.thialfihar.android.apg.ui.ShareActivity" >
<intent-filter> <intent-filter>
<action android:name="org.thialfihar.android.apg.intent.SHARE_WITH_QR_CODE" /> <action android:name="org.thialfihar.android.apg.intent.SHARE_KEYRING" />
<action android:name="org.thialfihar.android.apg.intent.SHARE_KEYRING_WITH_QR_CODE" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>

View File

@ -102,6 +102,7 @@
<string name="menu_keyServer">Query Key Server</string> <string name="menu_keyServer">Query Key Server</string>
<string name="menu_updateKey">Update from Server</string> <string name="menu_updateKey">Update from Server</string>
<string name="menu_exportKeyToServer">Export To Server</string> <string name="menu_exportKeyToServer">Export To Server</string>
<string name="menu_share">Share with…</string>
<string name="menu_shareQrCode">Share with QR Code</string> <string name="menu_shareQrCode">Share with QR Code</string>
<string name="menu_shareNfc">Share with NFC</string> <string name="menu_shareNfc">Share with NFC</string>
<string name="menu_scanQRCode">Scan QR Code</string> <string name="menu_scanQRCode">Scan QR Code</string>
@ -321,6 +322,7 @@
<string name="hint_publicKeys">Search Public Keyrings</string> <string name="hint_publicKeys">Search Public Keyrings</string>
<string name="hint_secretKeys">Search Secret Keyrings</string> <string name="hint_secretKeys">Search Secret Keyrings</string>
<string name="filterInfo">Filter: \"%s\"</string> <string name="filterInfo">Filter: \"%s\"</string>
<string name="shareKeyringWith">Share keyring with…</string>
<!-- misc --> <!-- misc -->
<string name="fast">fast</string> <string name="fast">fast</string>

View File

@ -35,9 +35,10 @@ public final class Id {
public static final int edit = 0x21070003; public static final int edit = 0x21070003;
public static final int update = 0x21070004; public static final int update = 0x21070004;
public static final int exportToServer = 0x21070005; public static final int exportToServer = 0x21070005;
public static final int share_qr_code = 0x21070006; public static final int share = 0x21070006;
public static final int share_nfc = 0x21070007; public static final int share_qr_code = 0x21070007;
public static final int signKey = 0x21070008; public static final int share_nfc = 0x21070008;
public static final int signKey = 0x21070009;
public static final class option { public static final class option {
public static final int new_pass_phrase = 0x21070001; public static final int new_pass_phrase = 0x21070001;

View File

@ -76,8 +76,9 @@ public class KeyListPublicFragment extends KeyListFragment implements
menu.add(0, Id.menu.update, 1, R.string.menu_updateKey); menu.add(0, Id.menu.update, 1, R.string.menu_updateKey);
menu.add(0, Id.menu.signKey, 2, R.string.menu_signKey); menu.add(0, Id.menu.signKey, 2, R.string.menu_signKey);
menu.add(0, Id.menu.exportToServer, 3, R.string.menu_exportKeyToServer); menu.add(0, Id.menu.exportToServer, 3, R.string.menu_exportKeyToServer);
menu.add(0, Id.menu.share_qr_code, 6, R.string.menu_shareQrCode); menu.add(0, Id.menu.share, 6, R.string.menu_share);
menu.add(0, Id.menu.share_nfc, 7, R.string.menu_shareNfc); menu.add(0, Id.menu.share_qr_code, 7, R.string.menu_shareQrCode);
menu.add(0, Id.menu.share_nfc, 8, R.string.menu_shareNfc);
} }
@ -142,9 +143,9 @@ public class KeyListPublicFragment extends KeyListFragment implements
// get master key id using row id // get master key id using row id
long masterKeyId = ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId); long masterKeyId = ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId);
Intent qrCodeIntent = new Intent(mKeyListActivity, ShareQrCodeActivity.class); Intent qrCodeIntent = new Intent(mKeyListActivity, ShareActivity.class);
qrCodeIntent.setAction(ShareQrCodeActivity.ACTION_SHARE_WITH_QR_CODE); qrCodeIntent.setAction(ShareActivity.ACTION_SHARE_KEYRING_WITH_QR_CODE);
qrCodeIntent.putExtra(ShareQrCodeActivity.EXTRA_MASTER_KEY_ID, masterKeyId); qrCodeIntent.putExtra(ShareActivity.EXTRA_MASTER_KEY_ID, masterKeyId);
startActivityForResult(qrCodeIntent, 0); startActivityForResult(qrCodeIntent, 0);
return true; return true;
@ -154,12 +155,23 @@ public class KeyListPublicFragment extends KeyListFragment implements
long masterKeyId2 = ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId); long masterKeyId2 = ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId);
Intent nfcIntent = new Intent(mKeyListActivity, ShareNfcBeamActivity.class); Intent nfcIntent = new Intent(mKeyListActivity, ShareNfcBeamActivity.class);
nfcIntent.setAction(ShareNfcBeamActivity.ACTION_SHARE_WITH_NFC); nfcIntent.setAction(ShareNfcBeamActivity.ACTION_SHARE_KEYRING_WITH_NFC);
nfcIntent.putExtra(ShareNfcBeamActivity.EXTRA_MASTER_KEY_ID, masterKeyId2); nfcIntent.putExtra(ShareNfcBeamActivity.EXTRA_MASTER_KEY_ID, masterKeyId2);
startActivityForResult(nfcIntent, 0); startActivityForResult(nfcIntent, 0);
return true; return true;
case Id.menu.share:
// get master key id using row id
long masterKeyId3 = ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId);
Intent shareIntent = new Intent(mKeyListActivity, ShareActivity.class);
shareIntent.setAction(ShareActivity.ACTION_SHARE_KEYRING);
shareIntent.putExtra(ShareActivity.EXTRA_MASTER_KEY_ID, masterKeyId3);
startActivityForResult(shareIntent, 0);
return true;
default: default:
return super.onContextItemSelected(item); return super.onContextItemSelected(item);

View File

@ -19,6 +19,7 @@ package org.thialfihar.android.apg.ui;
import java.util.ArrayList; import java.util.ArrayList;
import org.thialfihar.android.apg.Constants; import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.provider.ProviderHelper; import org.thialfihar.android.apg.provider.ProviderHelper;
import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.SherlockFragmentActivity;
@ -27,9 +28,10 @@ import com.google.zxing.integration.android.IntentIntegrator;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
public class ShareQrCodeActivity extends SherlockFragmentActivity { public class ShareActivity extends SherlockFragmentActivity {
public static final String ACTION_SHARE_WITH_QR_CODE = Constants.INTENT_PREFIX public static final String ACTION_SHARE_KEYRING = Constants.INTENT_PREFIX + "SHARE_KEYRING";
+ "SHARE_WITH_QR_CODE"; public static final String ACTION_SHARE_KEYRING_WITH_QR_CODE = Constants.INTENT_PREFIX
+ "SHARE_KEYRING_WITH_QR_CODE";
public static final String EXTRA_MASTER_KEY_ID = "masterKeyId"; public static final String EXTRA_MASTER_KEY_ID = "masterKeyId";
@ -48,18 +50,25 @@ public class ShareQrCodeActivity extends SherlockFragmentActivity {
extras = new Bundle(); extras = new Bundle();
} }
if (ACTION_SHARE_WITH_QR_CODE.equals(action)) { long masterKeyId = extras.getLong(EXTRA_MASTER_KEY_ID);
long masterKeyId = extras.getLong(EXTRA_MASTER_KEY_ID);
// get public keyring as ascii armored string // get public keyring as ascii armored string
ArrayList<String> keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString( ArrayList<String> keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString(this,
this, new long[] { masterKeyId }); new long[] { masterKeyId });
// close this activity
finish();
// close this activity
finish();
if (ACTION_SHARE_KEYRING.equals(action)) {
// let user choose application
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, keyringArmored.get(0));
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent,
getResources().getText(R.string.shareKeyringWith)));
} else if (ACTION_SHARE_KEYRING_WITH_QR_CODE.equals(action)) {
// use barcode scanner integration library // use barcode scanner integration library
new IntentIntegrator(this).shareText(keyringArmored.get(0)); new IntentIntegrator(this).shareText(keyringArmored.get(0));
} }
} }
} }

View File

@ -54,7 +54,8 @@ import android.text.method.LinkMovementMethod;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class ShareNfcBeamActivity extends SherlockFragmentActivity implements public class ShareNfcBeamActivity extends SherlockFragmentActivity implements
CreateNdefMessageCallback, OnNdefPushCompleteCallback { CreateNdefMessageCallback, OnNdefPushCompleteCallback {
public static final String ACTION_SHARE_WITH_NFC = Constants.INTENT_PREFIX + "SHARE_WITH_NFC"; public static final String ACTION_SHARE_KEYRING_WITH_NFC = Constants.INTENT_PREFIX
+ "SHARE_KEYRING_WITH_NFC";
public static final String EXTRA_MASTER_KEY_ID = "masterKeyId"; public static final String EXTRA_MASTER_KEY_ID = "masterKeyId";
@ -96,7 +97,7 @@ public class ShareNfcBeamActivity extends SherlockFragmentActivity implements
extras = new Bundle(); extras = new Bundle();
} }
if (ACTION_SHARE_WITH_NFC.equals(action)) { if (ACTION_SHARE_KEYRING_WITH_NFC.equals(action)) {
long masterKeyId = extras.getLong(EXTRA_MASTER_KEY_ID); long masterKeyId = extras.getLong(EXTRA_MASTER_KEY_ID);
// get public keyring as byte array // get public keyring as byte array

View File

@ -83,8 +83,9 @@ Android primitives to exchange data: Intent, Intent with return values, Send (al
* IMPORT_FROM_FILE * IMPORT_FROM_FILE
* IMPORT_FROM_QR_CODE * IMPORT_FROM_QR_CODE
* IMPORT_FROM_NFC * IMPORT_FROM_NFC
* SHARE_WITH_QR_CODE * SHARE_KEYRING
* SHARE_WITH_NFC * SHARE_KEYRING_WITH_QR_CODE
* SHARE_KEYRING_WITH_NFC
* EDIT_KEY * EDIT_KEY
* SELECT_PUBLIC_KEYS * SELECT_PUBLIC_KEYS
* SELECT_SECRET_KEY * SELECT_SECRET_KEY