mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
key edit fixes
This commit is contained in:
parent
4ea64968af
commit
44117fb191
@ -118,7 +118,6 @@
|
|||||||
android:name=".ui.EditKeyActivity"
|
android:name=".ui.EditKeyActivity"
|
||||||
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
||||||
android:label="@string/title_edit_key"
|
android:label="@string/title_edit_key"
|
||||||
android:uiOptions="splitActionBarWhenNarrow"
|
|
||||||
android:windowSoftInputMode="stateHidden" />
|
android:windowSoftInputMode="stateHidden" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.KeyViewActivity"
|
android:name=".ui.KeyViewActivity"
|
||||||
|
17
OpenPGP-Keychain/res/menu/key_edit.xml
Normal file
17
OpenPGP-Keychain/res/menu/key_edit.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_key_edit_export_file"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/menu_export_key"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_key_edit_delete"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/menu_delete_key"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_key_edit_cancel"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/menu_key_edit_cancel"/>
|
||||||
|
|
||||||
|
</menu>
|
@ -100,6 +100,7 @@
|
|||||||
<string name="menu_copy_to_clipboard">Copy to clipboard</string>
|
<string name="menu_copy_to_clipboard">Copy to clipboard</string>
|
||||||
<string name="menu_sign_key">Sign key</string>
|
<string name="menu_sign_key">Sign key</string>
|
||||||
<string name="menu_beam_preferences">Beam settings</string>
|
<string name="menu_beam_preferences">Beam settings</string>
|
||||||
|
<string name="menu_key_edit_cancel">Cancel</string>
|
||||||
|
|
||||||
<!-- label -->
|
<!-- label -->
|
||||||
<string name="label_sign">Sign</string>
|
<string name="label_sign">Sign</string>
|
||||||
|
@ -493,7 +493,7 @@ public class ProviderHelper {
|
|||||||
*/
|
*/
|
||||||
public static long getPublicMasterKeyId(Context context, long keyRingRowId) {
|
public static long getPublicMasterKeyId(Context context, long keyRingRowId) {
|
||||||
Uri queryUri = KeyRings.buildPublicKeyRingsUri(String.valueOf(keyRingRowId));
|
Uri queryUri = KeyRings.buildPublicKeyRingsUri(String.valueOf(keyRingRowId));
|
||||||
return getMasterKeyId(context, queryUri, keyRingRowId);
|
return getMasterKeyId(context, queryUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -551,7 +551,7 @@ public class ProviderHelper {
|
|||||||
*/
|
*/
|
||||||
public static long getSecretMasterKeyId(Context context, long keyRingRowId) {
|
public static long getSecretMasterKeyId(Context context, long keyRingRowId) {
|
||||||
Uri queryUri = KeyRings.buildSecretKeyRingsUri(String.valueOf(keyRingRowId));
|
Uri queryUri = KeyRings.buildSecretKeyRingsUri(String.valueOf(keyRingRowId));
|
||||||
return getMasterKeyId(context, queryUri, keyRingRowId);
|
return getMasterKeyId(context, queryUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -562,7 +562,7 @@ public class ProviderHelper {
|
|||||||
* @param keyRingRowId
|
* @param keyRingRowId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static long getMasterKeyId(Context context, Uri queryUri, long keyRingRowId) {
|
public static long getMasterKeyId(Context context, Uri queryUri) {
|
||||||
String[] projection = new String[] { KeyRings.MASTER_KEY_ID };
|
String[] projection = new String[] { KeyRings.MASTER_KEY_ID };
|
||||||
|
|
||||||
ContentResolver cr = context.getContentResolver();
|
ContentResolver cr = context.getContentResolver();
|
||||||
@ -592,7 +592,7 @@ public class ProviderHelper {
|
|||||||
return getKeyRingsAsArmoredString(context, KeyRings.buildSecretKeyRingsUri(), masterKeyIds);
|
return getKeyRingsAsArmoredString(context, KeyRings.buildSecretKeyRingsUri(), masterKeyIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayList<String> getKeyRingsAsArmoredString(Context context, Uri uri,
|
public static ArrayList<String> getKeyRingsAsArmoredString(Context context, Uri uri,
|
||||||
long[] masterKeyIds) {
|
long[] masterKeyIds) {
|
||||||
ArrayList<String> output = new ArrayList<String>();
|
ArrayList<String> output = new ArrayList<String>();
|
||||||
|
|
||||||
@ -661,7 +661,7 @@ public class ProviderHelper {
|
|||||||
return getKeyRingsAsByteArray(context, KeyRings.buildSecretKeyRingsUri(), masterKeyIds);
|
return getKeyRingsAsByteArray(context, KeyRings.buildSecretKeyRingsUri(), masterKeyIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] getKeyRingsAsByteArray(Context context, Uri uri, long[] masterKeyIds) {
|
public static byte[] getKeyRingsAsByteArray(Context context, Uri uri, long[] masterKeyIds) {
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
if (masterKeyIds != null && masterKeyIds.length > 0) {
|
if (masterKeyIds != null && masterKeyIds.length > 0) {
|
||||||
|
@ -34,6 +34,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.KeyEditor;
|
import org.sufficientlysecure.keychain.ui.widget.KeyEditor;
|
||||||
@ -45,6 +46,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@ -60,9 +62,10 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.view.Menu;
|
||||||
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
public class EditKeyActivity extends SherlockFragmentActivity {
|
public class EditKeyActivity extends KeyActivity {
|
||||||
|
|
||||||
// Actions for internal use only:
|
// Actions for internal use only:
|
||||||
public static final String ACTION_CREATE_KEY = Constants.INTENT_PREFIX + "CREATE_KEY";
|
public static final String ACTION_CREATE_KEY = Constants.INTENT_PREFIX + "CREATE_KEY";
|
||||||
@ -72,13 +75,14 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
public static final String EXTRA_USER_IDS = "user_ids";
|
public static final String EXTRA_USER_IDS = "user_ids";
|
||||||
public static final String EXTRA_NO_PASSPHRASE = "no_passphrase";
|
public static final String EXTRA_NO_PASSPHRASE = "no_passphrase";
|
||||||
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generate_default_keys";
|
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generate_default_keys";
|
||||||
public static final String EXTRA_MASTER_KEY_ID = "master_key_id";
|
|
||||||
public static final String EXTRA_MASTER_CAN_SIGN = "master_can_sign";
|
|
||||||
|
|
||||||
// results when saving key
|
// results when saving key
|
||||||
public static final String RESULT_EXTRA_MASTER_KEY_ID = "master_key_id";
|
public static final String RESULT_EXTRA_MASTER_KEY_ID = "master_key_id";
|
||||||
public static final String RESULT_EXTRA_USER_ID = "user_id";
|
public static final String RESULT_EXTRA_USER_ID = "user_id";
|
||||||
|
|
||||||
|
// EDIT
|
||||||
|
private Uri mDataUri;
|
||||||
|
|
||||||
private PGPSecretKeyRing mKeyRing = null;
|
private PGPSecretKeyRing mKeyRing = null;
|
||||||
|
|
||||||
private SectionView mUserIdsView;
|
private SectionView mUserIdsView;
|
||||||
@ -96,29 +100,10 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
Vector<Integer> mKeysUsages;
|
Vector<Integer> mKeysUsages;
|
||||||
boolean masterCanSign = true;
|
boolean masterCanSign = true;
|
||||||
|
|
||||||
// will be set to false to build layout later in handler
|
|
||||||
private boolean mBuildLayout = true;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// Inflate a "Done"/"Cancel" custom action bar
|
|
||||||
ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_save,
|
|
||||||
new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
// save
|
|
||||||
saveClicked();
|
|
||||||
}
|
|
||||||
}, R.string.btn_do_not_save, new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
// cancel
|
|
||||||
cancelClicked();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mUserIds = new Vector<String>();
|
mUserIds = new Vector<String>();
|
||||||
mKeys = new Vector<PGPSecretKey>();
|
mKeys = new Vector<PGPSecretKey>();
|
||||||
mKeysUsages = new Vector<Integer>();
|
mKeysUsages = new Vector<Integer>();
|
||||||
@ -131,10 +116,6 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
} else if (ACTION_EDIT_KEY.equals(action)) {
|
} else if (ACTION_EDIT_KEY.equals(action)) {
|
||||||
handleActionEditKey(intent);
|
handleActionEditKey(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mBuildLayout) {
|
|
||||||
buildLayout();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,6 +124,20 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
* @param intent
|
* @param intent
|
||||||
*/
|
*/
|
||||||
private void handleActionCreateKey(Intent intent) {
|
private void handleActionCreateKey(Intent intent) {
|
||||||
|
// Inflate a "Done"/"Cancel" custom action bar
|
||||||
|
ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_save,
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
saveClicked();
|
||||||
|
}
|
||||||
|
}, R.string.btn_do_not_save, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
cancelClicked();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
|
|
||||||
mCurrentPassPhrase = "";
|
mCurrentPassPhrase = "";
|
||||||
@ -169,9 +164,6 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
boolean generateDefaultKeys = extras.getBoolean(EXTRA_GENERATE_DEFAULT_KEYS);
|
boolean generateDefaultKeys = extras.getBoolean(EXTRA_GENERATE_DEFAULT_KEYS);
|
||||||
if (generateDefaultKeys) {
|
if (generateDefaultKeys) {
|
||||||
|
|
||||||
// build layout in handler after generating keys not directly in onCreate
|
|
||||||
mBuildLayout = false;
|
|
||||||
|
|
||||||
// Send all information needed to service generate keys in other thread
|
// Send all information needed to service generate keys in other thread
|
||||||
Intent serviceIntent = new Intent(this, KeychainIntentService.class);
|
Intent serviceIntent = new Intent(this, KeychainIntentService.class);
|
||||||
serviceIntent.setAction(KeychainIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS);
|
serviceIntent.setAction(KeychainIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS);
|
||||||
@ -228,12 +220,55 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
startService(serviceIntent);
|
startService(serviceIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
buildLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle intent action to edit existing key
|
||||||
|
*
|
||||||
|
* @param intent
|
||||||
|
*/
|
||||||
|
private void handleActionEditKey(Intent intent) {
|
||||||
|
// Inflate a "Done"/"Cancel" custom action bar
|
||||||
|
ActionBarHelper.setDoneView(getSupportActionBar(), R.string.btn_save,
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
saveClicked();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mDataUri = intent.getData();
|
||||||
|
if (mDataUri == null) {
|
||||||
|
Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!");
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Log.d(Constants.TAG, "uri: " + mDataUri);
|
||||||
|
|
||||||
|
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
||||||
|
|
||||||
|
// get master key id using row id
|
||||||
|
long masterKeyId = ProviderHelper.getSecretMasterKeyId(this, keyRingRowId);
|
||||||
|
|
||||||
|
boolean masterCanSign = ProviderHelper.getSecretMasterKeyCanSign(this, keyRingRowId);
|
||||||
|
|
||||||
|
String passphrase = PassphraseCacheService.getCachedPassphrase(this, masterKeyId);
|
||||||
|
if (passphrase == null) {
|
||||||
|
showPassphraseDialog(masterKeyId, masterCanSign);
|
||||||
|
} else {
|
||||||
|
// PgpMain.setEditPassPhrase(passPhrase);
|
||||||
|
mCurrentPassPhrase = passphrase;
|
||||||
|
|
||||||
|
finallyEdit(masterKeyId, masterCanSign);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPassphraseDialog(final long masterKeyId, final boolean masterCanSign) {
|
private void showPassphraseDialog(final long masterKeyId, final boolean masterCanSign) {
|
||||||
// Message is received after passphrase is cached
|
// Message is received after passphrase is cached
|
||||||
final boolean mCanSign = masterCanSign;
|
|
||||||
Handler returnHandler = new Handler() {
|
Handler returnHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
@ -263,37 +298,41 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Handle intent action to edit existing key
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
*
|
// show menu only on edit
|
||||||
* @param intent
|
if (mDataUri != null) {
|
||||||
*/
|
return super.onPrepareOptionsMenu(menu);
|
||||||
private void handleActionEditKey(Intent intent) {
|
} else {
|
||||||
Bundle extras = intent.getExtras();
|
return false;
|
||||||
|
|
||||||
if (extras != null) {
|
|
||||||
if (extras.containsKey(EXTRA_MASTER_CAN_SIGN)) {
|
|
||||||
masterCanSign = extras.getBoolean(EXTRA_MASTER_CAN_SIGN);
|
|
||||||
}
|
|
||||||
if (extras.containsKey(EXTRA_MASTER_KEY_ID)) {
|
|
||||||
long masterKeyId = extras.getLong(EXTRA_MASTER_KEY_ID);
|
|
||||||
|
|
||||||
// build layout in edit()
|
|
||||||
mBuildLayout = false;
|
|
||||||
|
|
||||||
String passPhrase = PassphraseCacheService.getCachedPassphrase(this, masterKeyId);
|
|
||||||
if (passPhrase == null) {
|
|
||||||
showPassphraseDialog(masterKeyId, masterCanSign);
|
|
||||||
} else {
|
|
||||||
// PgpMain.setEditPassPhrase(passPhrase);
|
|
||||||
mCurrentPassPhrase = passPhrase;
|
|
||||||
|
|
||||||
finallyEdit(masterKeyId, masterCanSign);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
super.onCreateOptionsMenu(menu);
|
||||||
|
getSupportMenuInflater().inflate(R.menu.key_edit, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.menu_key_edit_cancel:
|
||||||
|
cancelClicked();
|
||||||
|
return true;
|
||||||
|
case R.id.menu_key_edit_export_file:
|
||||||
|
showExportKeysDialog(mDataUri, Id.type.secret_key, Constants.path.APP_DIR
|
||||||
|
+ "/secexport.asc");
|
||||||
|
return true;
|
||||||
|
case R.id.menu_key_edit_delete:
|
||||||
|
deleteKey(mDataUri, Id.type.secret_key);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private void finallyEdit(final long masterKeyId, final boolean masterCanSign) {
|
private void finallyEdit(final long masterKeyId, final boolean masterCanSign) {
|
||||||
if (masterKeyId != 0) {
|
if (masterKeyId != 0) {
|
||||||
PGPSecretKey masterKey = null;
|
PGPSecretKey masterKey = null;
|
||||||
@ -316,13 +355,13 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildLayout();
|
|
||||||
|
|
||||||
// TODO: ???
|
// TODO: ???
|
||||||
if (mCurrentPassPhrase == null) {
|
if (mCurrentPassPhrase == null) {
|
||||||
mCurrentPassPhrase = "";
|
mCurrentPassPhrase = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildLayout();
|
||||||
|
|
||||||
if (mCurrentPassPhrase.equals("")) {
|
if (mCurrentPassPhrase.equals("")) {
|
||||||
// check "no passphrase" checkbox and remove button
|
// check "no passphrase" checkbox and remove button
|
||||||
mNoPassphrase.setChecked(true);
|
mNoPassphrase.setChecked(true);
|
||||||
|
@ -0,0 +1,217 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
*
|
||||||
|
* 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.ui;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.Id;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
||||||
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: get key type by looking at dataUri!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class KeyActivity extends SherlockFragmentActivity {
|
||||||
|
|
||||||
|
protected FileDialogFragment mFileDialog;
|
||||||
|
protected String mExportFilename;
|
||||||
|
|
||||||
|
protected void deleteKey(Uri dataUri, final int keyType) {
|
||||||
|
long keyRingRowId = Long.valueOf(dataUri.getLastPathSegment());
|
||||||
|
|
||||||
|
// Message is received after key is deleted
|
||||||
|
Handler returnHandler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message message) {
|
||||||
|
if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
|
||||||
|
setResult(RESULT_CANCELED);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(returnHandler);
|
||||||
|
|
||||||
|
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
||||||
|
new long[] { keyRingRowId }, keyType);
|
||||||
|
|
||||||
|
deleteKeyDialog.show(getSupportFragmentManager(), "deleteKeyDialog");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show dialog where to export keys
|
||||||
|
*
|
||||||
|
* @param keyRingMasterKeyId
|
||||||
|
* if -1 export all keys
|
||||||
|
*/
|
||||||
|
public void showExportKeysDialog(Uri dataUri, final int keyType, final String exportFilename) {
|
||||||
|
long keyRingRowId = Long.valueOf(dataUri.getLastPathSegment());
|
||||||
|
|
||||||
|
// TODO?
|
||||||
|
final long keyRingMasterKeyId = ProviderHelper.getSecretMasterKeyId(this, keyRingRowId);
|
||||||
|
mExportFilename = exportFilename;
|
||||||
|
|
||||||
|
// Message is received after file is selected
|
||||||
|
Handler returnHandler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message message) {
|
||||||
|
if (message.what == FileDialogFragment.MESSAGE_OKAY) {
|
||||||
|
Bundle data = message.getData();
|
||||||
|
mExportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
|
||||||
|
|
||||||
|
exportKeys(keyRingMasterKeyId, keyType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
final Messenger messenger = new Messenger(returnHandler);
|
||||||
|
|
||||||
|
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
String title = null;
|
||||||
|
if (keyRingMasterKeyId != -1) {
|
||||||
|
// single key export
|
||||||
|
title = getString(R.string.title_export_key);
|
||||||
|
} else {
|
||||||
|
title = getString(R.string.title_export_keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = null;
|
||||||
|
if (keyType == Id.type.public_key) {
|
||||||
|
message = getString(R.string.specify_file_to_export_to);
|
||||||
|
} else {
|
||||||
|
message = getString(R.string.specify_file_to_export_secret_keys_to);
|
||||||
|
}
|
||||||
|
|
||||||
|
mFileDialog = FileDialogFragment.newInstance(messenger, title, message,
|
||||||
|
exportFilename, null, Id.request.filename);
|
||||||
|
|
||||||
|
mFileDialog.show(getSupportFragmentManager(), "fileDialog");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export keys
|
||||||
|
*
|
||||||
|
* @param keyRingMasterKeyId
|
||||||
|
* if -1 export all keys
|
||||||
|
*/
|
||||||
|
public void exportKeys(long keyRingMasterKeyId, int keyType) {
|
||||||
|
Log.d(Constants.TAG, "exportKeys started");
|
||||||
|
|
||||||
|
// Send all information needed to service to export key in other thread
|
||||||
|
Intent intent = new Intent(this, KeychainIntentService.class);
|
||||||
|
|
||||||
|
intent.setAction(KeychainIntentService.ACTION_EXPORT_KEYRING);
|
||||||
|
|
||||||
|
// fill values for this action
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
|
||||||
|
data.putString(KeychainIntentService.EXPORT_FILENAME, mExportFilename);
|
||||||
|
data.putInt(KeychainIntentService.EXPORT_KEY_TYPE, keyType);
|
||||||
|
|
||||||
|
if (keyRingMasterKeyId == -1) {
|
||||||
|
data.putBoolean(KeychainIntentService.EXPORT_ALL, true);
|
||||||
|
} else {
|
||||||
|
data.putLong(KeychainIntentService.EXPORT_KEY_RING_MASTER_KEY_ID, keyRingMasterKeyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
|
// Message is received after exporting is done in ApgService
|
||||||
|
KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(this,
|
||||||
|
R.string.progress_exporting, ProgressDialog.STYLE_HORIZONTAL) {
|
||||||
|
public void handleMessage(Message message) {
|
||||||
|
// handle messages by standard ApgHandler first
|
||||||
|
super.handleMessage(message);
|
||||||
|
|
||||||
|
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||||
|
// get returned data bundle
|
||||||
|
Bundle returnData = message.getData();
|
||||||
|
|
||||||
|
int exported = returnData.getInt(KeychainIntentService.RESULT_EXPORT);
|
||||||
|
String toastMessage;
|
||||||
|
if (exported == 1) {
|
||||||
|
toastMessage = getString(R.string.key_exported);
|
||||||
|
} else if (exported > 0) {
|
||||||
|
toastMessage = getString(R.string.keys_exported, exported);
|
||||||
|
} else {
|
||||||
|
toastMessage = getString(R.string.no_keys_exported);
|
||||||
|
}
|
||||||
|
Toast.makeText(KeyActivity.this, toastMessage, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(exportHandler);
|
||||||
|
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
|
// show progress dialog
|
||||||
|
exportHandler.showProgressDialog(this);
|
||||||
|
|
||||||
|
// start service with intent
|
||||||
|
startService(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
switch (requestCode) {
|
||||||
|
case Id.request.filename: {
|
||||||
|
if (resultCode == RESULT_OK && data != null) {
|
||||||
|
try {
|
||||||
|
String path = data.getData().getPath();
|
||||||
|
Log.d(Constants.TAG, "path=" + path);
|
||||||
|
|
||||||
|
// set filename used in export/import dialogs
|
||||||
|
mFileDialog.setFilename(path);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
Log.e(Constants.TAG, "Nullpointer while retrieving path!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
}
|
@ -35,9 +35,6 @@ import android.database.Cursor;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.os.Messenger;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
@ -233,25 +230,10 @@ public class KeyListPublicFragment extends Fragment implements AdapterView.OnIte
|
|||||||
/**
|
/**
|
||||||
* Show dialog to delete key
|
* Show dialog to delete key
|
||||||
*
|
*
|
||||||
* TODO: no messenger needed etc!
|
|
||||||
*
|
|
||||||
* @param keyRingRowIds
|
* @param keyRingRowIds
|
||||||
*/
|
*/
|
||||||
public void showDeleteKeyDialog(long[] keyRingRowIds) {
|
public void showDeleteKeyDialog(long[] keyRingRowIds) {
|
||||||
// Message is received after key is deleted
|
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(null,
|
||||||
Handler returnHandler = new Handler() {
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message message) {
|
|
||||||
if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
|
|
||||||
// no further actions needed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create a new Messenger for the communication back
|
|
||||||
Messenger messenger = new Messenger(returnHandler);
|
|
||||||
|
|
||||||
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
|
||||||
keyRingRowIds, Id.type.public_key);
|
keyRingRowIds, Id.type.public_key);
|
||||||
|
|
||||||
deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog");
|
deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog");
|
||||||
|
@ -45,8 +45,8 @@ public class KeyListSecretActivity extends KeyListActivity {
|
|||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
menu.add(1, Id.menu.option.create, 1, R.string.menu_create_key).setShowAsAction(
|
menu.add(1, Id.menu.option.create, 1, R.string.menu_create_key).setShowAsAction(
|
||||||
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
menu.add(1, Id.menu.option.createExpert, 2, R.string.menu_create_key_expert).setShowAsAction(
|
menu.add(1, Id.menu.option.createExpert, 2, R.string.menu_create_key_expert)
|
||||||
MenuItem.SHOW_AS_ACTION_NEVER);
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -84,12 +84,4 @@ public class KeyListSecretActivity extends KeyListActivity {
|
|||||||
startActivityForResult(intent, 0);
|
startActivityForResult(intent, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void editKey(long masterKeyId, boolean masterCanSign) {
|
|
||||||
Intent intent = new Intent(this, EditKeyActivity.class);
|
|
||||||
intent.setAction(EditKeyActivity.ACTION_EDIT_KEY);
|
|
||||||
intent.putExtra(EditKeyActivity.EXTRA_MASTER_KEY_ID, masterKeyId);
|
|
||||||
intent.putExtra(EditKeyActivity.EXTRA_MASTER_CAN_SIGN, masterCanSign);
|
|
||||||
startActivityForResult(intent, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,12 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Id;
|
import org.sufficientlysecure.keychain.Id;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.KeyListSecretAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.KeyListSecretAdapter;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -37,7 +38,7 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||||||
import com.actionbarsherlock.app.SherlockListFragment;
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
|
|
||||||
public class KeyListSecretFragment extends SherlockListFragment implements
|
public class KeyListSecretFragment extends SherlockListFragment implements
|
||||||
LoaderManager.LoaderCallbacks<Cursor> {
|
LoaderManager.LoaderCallbacks<Cursor>, OnItemClickListener {
|
||||||
|
|
||||||
private KeyListSecretActivity mKeyListSecretActivity;
|
private KeyListSecretActivity mKeyListSecretActivity;
|
||||||
|
|
||||||
@ -52,20 +53,7 @@ public class KeyListSecretFragment extends SherlockListFragment implements
|
|||||||
|
|
||||||
mKeyListSecretActivity = (KeyListSecretActivity) getActivity();
|
mKeyListSecretActivity = (KeyListSecretActivity) getActivity();
|
||||||
|
|
||||||
getListView().setOnItemClickListener(new OnItemClickListener() {
|
getListView().setOnItemClickListener(this);
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
|
||||||
// TODO: currently this is EDIT directly, later first show VIEW
|
|
||||||
|
|
||||||
// get master key id using row id
|
|
||||||
long masterKeyId = ProviderHelper.getSecretMasterKeyId(mKeyListSecretActivity, id);
|
|
||||||
|
|
||||||
boolean masterCanSign = ProviderHelper.getSecretMasterKeyCanSign(
|
|
||||||
mKeyListSecretActivity, id);
|
|
||||||
|
|
||||||
mKeyListSecretActivity.editKey(masterKeyId, masterCanSign);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Give some text to display if there is no data. In a real
|
// Give some text to display if there is no data. In a real
|
||||||
// application this would come from a resource.
|
// application this would come from a resource.
|
||||||
@ -124,4 +112,15 @@ public class KeyListSecretFragment extends SherlockListFragment implements
|
|||||||
// longer using it.
|
// longer using it.
|
||||||
mAdapter.swapCursor(null);
|
mAdapter.swapCursor(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On click on item, start key view activity
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
||||||
|
Intent editIntent = new Intent(mKeyListSecretActivity, EditKeyActivity.class);
|
||||||
|
editIntent.setData(KeychainContract.KeyRings.buildSecretKeyRingsUri(Long.toString(id)));
|
||||||
|
editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY);
|
||||||
|
startActivityForResult(editIntent, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,12 +52,11 @@ import android.text.format.DateFormat;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
public class KeyViewActivity extends SherlockFragmentActivity implements CreateNdefMessageCallback,
|
public class KeyViewActivity extends KeyActivity implements CreateNdefMessageCallback,
|
||||||
OnNdefPushCompleteCallback {
|
OnNdefPushCompleteCallback {
|
||||||
private Uri mDataUri;
|
private Uri mDataUri;
|
||||||
|
|
||||||
@ -96,7 +95,7 @@ public class KeyViewActivity extends SherlockFragmentActivity implements CreateN
|
|||||||
} else {
|
} else {
|
||||||
Log.d(Constants.TAG, "uri: " + mDataUri);
|
Log.d(Constants.TAG, "uri: " + mDataUri);
|
||||||
loadData(mDataUri);
|
loadData(mDataUri);
|
||||||
initNfc();
|
initNfc(mDataUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,31 +110,32 @@ public class KeyViewActivity extends SherlockFragmentActivity implements CreateN
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menu_key_view_update:
|
case R.id.menu_key_view_update:
|
||||||
updateFromKeyserver();
|
updateFromKeyserver(mDataUri);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_sign:
|
case R.id.menu_key_view_sign:
|
||||||
signKey();
|
signKey(mDataUri);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_export_keyserver:
|
case R.id.menu_key_view_export_keyserver:
|
||||||
uploadToKeyserver();
|
uploadToKeyserver(mDataUri);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_export_file:
|
case R.id.menu_key_view_export_file:
|
||||||
exportToFile();
|
showExportKeysDialog(mDataUri, Id.type.public_key, Constants.path.APP_DIR
|
||||||
|
+ "/pubexport.asc");
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_share_default:
|
case R.id.menu_key_view_share_default:
|
||||||
shareKey();
|
shareKey(mDataUri);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_share_qr_code:
|
case R.id.menu_key_view_share_qr_code:
|
||||||
shareKeyQrCode();
|
shareKeyQrCode(mDataUri);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_share_nfc:
|
case R.id.menu_key_view_share_nfc:
|
||||||
shareNfc();
|
shareNfc();
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_share_clipboard:
|
case R.id.menu_key_view_share_clipboard:
|
||||||
copyToClipboard();
|
copyToClipboard(mDataUri);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_delete:
|
case R.id.menu_key_view_delete:
|
||||||
deleteKey();
|
deleteKey(mDataUri, Id.type.public_key);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -188,24 +188,8 @@ public class KeyViewActivity extends SherlockFragmentActivity implements CreateN
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportToFile() {
|
private void uploadToKeyserver(Uri dataUri) {
|
||||||
// long masterKeyId = ProviderHelper.getPublicMasterKeyId(mKeyListActivity,
|
long keyRingRowId = Long.valueOf(dataUri.getLastPathSegment());
|
||||||
// keyRingRowId);
|
|
||||||
// if (masterKeyId == -1) {
|
|
||||||
// masterKeyId = ProviderHelper.getSecretMasterKeyId(mKeyListActivity, keyRingRowId);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// mKeyListActivity.showExportKeysDialog(masterKeyId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteKey() {
|
|
||||||
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
|
||||||
|
|
||||||
// mKeyListActivity.showDeleteKeyDialog(keyRingRowId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void uploadToKeyserver() {
|
|
||||||
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
|
||||||
|
|
||||||
Intent uploadIntent = new Intent(this, KeyServerUploadActivity.class);
|
Intent uploadIntent = new Intent(this, KeyServerUploadActivity.class);
|
||||||
uploadIntent.setAction(KeyServerUploadActivity.ACTION_EXPORT_KEY_TO_SERVER);
|
uploadIntent.setAction(KeyServerUploadActivity.ACTION_EXPORT_KEY_TO_SERVER);
|
||||||
@ -213,20 +197,22 @@ public class KeyViewActivity extends SherlockFragmentActivity implements CreateN
|
|||||||
startActivityForResult(uploadIntent, Id.request.export_to_server);
|
startActivityForResult(uploadIntent, Id.request.export_to_server);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFromKeyserver() {
|
private void updateFromKeyserver(Uri dataUri) {
|
||||||
// TODO: use data uri!
|
|
||||||
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
|
||||||
|
|
||||||
long updateKeyId = 0;
|
long updateKeyId = 0;
|
||||||
PGPPublicKeyRing updateKeyRing = ProviderHelper.getPGPPublicKeyRingByRowId(this,
|
PGPPublicKeyRing updateRing = (PGPPublicKeyRing) ProviderHelper
|
||||||
keyRingRowId);
|
.getPGPKeyRing(this, dataUri);
|
||||||
if (updateKeyRing != null) {
|
|
||||||
updateKeyId = PgpKeyHelper.getMasterKey(updateKeyRing).getKeyID();
|
if (updateRing != null) {
|
||||||
|
updateKeyId = PgpKeyHelper.getMasterKey(updateRing).getKeyID();
|
||||||
}
|
}
|
||||||
// if (updateKeyId == 0) {
|
if (updateKeyId == 0) {
|
||||||
// // this shouldn't happen
|
Log.e(Constants.TAG, "this shouldn't happen. KeyId == 0!");
|
||||||
// return true;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
Intent signIntent = new Intent(this, SignKeyActivity.class);
|
||||||
|
signIntent.putExtra(SignKeyActivity.EXTRA_KEY_ID, updateKeyId);
|
||||||
|
startActivity(signIntent);
|
||||||
|
|
||||||
Intent queryIntent = new Intent(this, KeyServerQueryActivity.class);
|
Intent queryIntent = new Intent(this, KeyServerQueryActivity.class);
|
||||||
queryIntent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID_AND_RETURN);
|
queryIntent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID_AND_RETURN);
|
||||||
@ -234,35 +220,29 @@ public class KeyViewActivity extends SherlockFragmentActivity implements CreateN
|
|||||||
|
|
||||||
// TODO: lookup??
|
// TODO: lookup??
|
||||||
startActivityForResult(queryIntent, Id.request.look_up_key_id);
|
startActivityForResult(queryIntent, Id.request.look_up_key_id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void signKey() {
|
private void signKey(Uri dataUri) {
|
||||||
// TODO: use data uri!
|
|
||||||
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
|
||||||
|
|
||||||
long keyId = 0;
|
long keyId = 0;
|
||||||
PGPPublicKeyRing signKeyRing = ProviderHelper
|
PGPPublicKeyRing signKey = (PGPPublicKeyRing) ProviderHelper.getPGPKeyRing(this, dataUri);
|
||||||
.getPGPPublicKeyRingByRowId(this, keyRingRowId);
|
|
||||||
if (signKeyRing != null) {
|
if (signKey != null) {
|
||||||
keyId = PgpKeyHelper.getMasterKey(signKeyRing).getKeyID();
|
keyId = PgpKeyHelper.getMasterKey(signKey).getKeyID();
|
||||||
|
}
|
||||||
|
if (keyId == 0) {
|
||||||
|
Log.e(Constants.TAG, "this shouldn't happen. KeyId == 0!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
// if (keyId == 0) {
|
|
||||||
// // this shouldn't happen
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
Intent signIntent = new Intent(this, SignKeyActivity.class);
|
Intent signIntent = new Intent(this, SignKeyActivity.class);
|
||||||
signIntent.putExtra(SignKeyActivity.EXTRA_KEY_ID, keyId);
|
signIntent.putExtra(SignKeyActivity.EXTRA_KEY_ID, keyId);
|
||||||
startActivity(signIntent);
|
startActivity(signIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shareKey() {
|
private void shareKey(Uri dataUri) {
|
||||||
// TODO: use data uri!
|
|
||||||
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
|
||||||
long masterKeyId = ProviderHelper.getPublicMasterKeyId(this, keyRingRowId);
|
|
||||||
// get public keyring as ascii armored string
|
// get public keyring as ascii armored string
|
||||||
ArrayList<String> keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString(this,
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||||
|
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(this, dataUri,
|
||||||
new long[] { masterKeyId });
|
new long[] { masterKeyId });
|
||||||
|
|
||||||
// let user choose application
|
// let user choose application
|
||||||
@ -273,12 +253,10 @@ public class KeyViewActivity extends SherlockFragmentActivity implements CreateN
|
|||||||
getResources().getText(R.string.action_share_key_with)));
|
getResources().getText(R.string.action_share_key_with)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shareKeyQrCode() {
|
private void shareKeyQrCode(Uri dataUri) {
|
||||||
// TODO: use data uri!
|
|
||||||
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
|
||||||
long masterKeyId = ProviderHelper.getPublicMasterKeyId(this, keyRingRowId);
|
|
||||||
// get public keyring as ascii armored string
|
// get public keyring as ascii armored string
|
||||||
ArrayList<String> keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString(this,
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||||
|
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(this, dataUri,
|
||||||
new long[] { masterKeyId });
|
new long[] { masterKeyId });
|
||||||
|
|
||||||
ShareQrCodeDialogFragment dialog = ShareQrCodeDialogFragment.newInstance(keyringArmored
|
ShareQrCodeDialogFragment dialog = ShareQrCodeDialogFragment.newInstance(keyringArmored
|
||||||
@ -286,38 +264,34 @@ public class KeyViewActivity extends SherlockFragmentActivity implements CreateN
|
|||||||
dialog.show(getSupportFragmentManager(), "shareQrCodeDialog");
|
dialog.show(getSupportFragmentManager(), "shareQrCodeDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shareNfc() {
|
private void copyToClipboard(Uri dataUri) {
|
||||||
ShareNfcDialogFragment dialog = ShareNfcDialogFragment.newInstance();
|
|
||||||
dialog.show(getSupportFragmentManager(), "shareNfcDialog");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyToClipboard() {
|
|
||||||
// TODO: use data uri!
|
|
||||||
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
|
||||||
long masterKeyId = ProviderHelper.getPublicMasterKeyId(this, keyRingRowId);
|
|
||||||
// get public keyring as ascii armored string
|
// get public keyring as ascii armored string
|
||||||
ArrayList<String> keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString(this,
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||||
|
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(this, dataUri,
|
||||||
new long[] { masterKeyId });
|
new long[] { masterKeyId });
|
||||||
|
|
||||||
ClipboardReflection.copyToClipboard(this, keyringArmored.get(0));
|
ClipboardReflection.copyToClipboard(this, keyringArmored.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void shareNfc() {
|
||||||
|
ShareNfcDialogFragment dialog = ShareNfcDialogFragment.newInstance();
|
||||||
|
dialog.show(getSupportFragmentManager(), "shareNfcDialog");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NFC: Initialize NFC sharing if OS and device supports it
|
* NFC: Initialize NFC sharing if OS and device supports it
|
||||||
*/
|
*/
|
||||||
private void initNfc() {
|
private void initNfc(Uri dataUri) {
|
||||||
// check if NFC Beam is supported (>= Android 4.1)
|
// check if NFC Beam is supported (>= Android 4.1)
|
||||||
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) {
|
if (mNfcAdapter != null) {
|
||||||
// init nfc
|
// init nfc
|
||||||
// TODO: use data uri!
|
|
||||||
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
|
||||||
long masterKeyId = ProviderHelper.getPublicMasterKeyId(this, keyRingRowId);
|
|
||||||
|
|
||||||
// get public keyring as byte array
|
// get public keyring as byte array
|
||||||
mSharedKeyringBytes = ProviderHelper.getPublicKeyRingsAsByteArray(this,
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||||
|
mSharedKeyringBytes = ProviderHelper.getKeyRingsAsByteArray(this, dataUri,
|
||||||
new long[] { masterKeyId });
|
new long[] { masterKeyId });
|
||||||
|
|
||||||
// Register callback to set NDEF message
|
// Register callback to set NDEF message
|
||||||
|
@ -120,7 +120,7 @@ On error see: http://code.google.com/p/zxing/issues/detail?id=1207
|
|||||||
|
|
||||||
## ZXing
|
## ZXing
|
||||||
|
|
||||||
XZing classes were extracted from the ZXing library (http://code.google.com/p/zxing/).
|
ZXing classes were extracted from the ZXing library (http://code.google.com/p/zxing/).
|
||||||
Only classes related to QR Code generation are utilized.
|
Only classes related to QR Code generation are utilized.
|
||||||
|
|
||||||
## Bouncy Castle
|
## Bouncy Castle
|
||||||
|
Loading…
Reference in New Issue
Block a user