mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
parent
b77fb2fcc0
commit
baa3c86e12
@ -51,7 +51,7 @@ public class ExportHelper {
|
|||||||
|
|
||||||
public void deleteKey(Uri dataUri, Handler deleteHandler) {
|
public void deleteKey(Uri dataUri, Handler deleteHandler) {
|
||||||
try {
|
try {
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(mActivity, dataUri);
|
long masterKeyId = ProviderHelper.extractOrGetMasterKeyId(mActivity, dataUri);
|
||||||
|
|
||||||
// Create a new Messenger for the communication back
|
// Create a new Messenger for the communication back
|
||||||
Messenger messenger = new Messenger(deleteHandler);
|
Messenger messenger = new Messenger(deleteHandler);
|
||||||
|
@ -122,15 +122,20 @@ public class ProviderHelper {
|
|||||||
* Find the master key id related to a given query. The id will either be extracted from the
|
* Find the master key id related to a given query. The id will either be extracted from the
|
||||||
* query, which should work for all specific /key_rings/ queries, or will be queried if it can't.
|
* query, which should work for all specific /key_rings/ queries, or will be queried if it can't.
|
||||||
*/
|
*/
|
||||||
public static long getMasterKeyId(Context context, Uri queryUri) throws NotFoundException {
|
public static long extractOrGetMasterKeyId(Context context, Uri queryUri)
|
||||||
|
throws NotFoundException {
|
||||||
// try extracting from the uri first
|
// try extracting from the uri first
|
||||||
// String firstSegment = queryUri.getPathSegments().get(1);
|
String firstSegment = queryUri.getPathSegments().get(1);
|
||||||
// if(!firstSegment.equals("find")) try {
|
if(!firstSegment.equals("find")) try {
|
||||||
// return Long.parseLong(firstSegment);
|
return Long.parseLong(firstSegment);
|
||||||
// } catch(NumberFormatException e) {
|
} catch(NumberFormatException e) {
|
||||||
// // didn't work? oh well.
|
// didn't work? oh well.
|
||||||
// Log.d(Constants.TAG, "Couldn't get masterKeyId from URI, querying...");
|
Log.d(Constants.TAG, "Couldn't get masterKeyId from URI, querying...");
|
||||||
// }
|
}
|
||||||
|
return getMasterKeyId(context, queryUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getMasterKeyId(Context context, Uri queryUri) throws NotFoundException {
|
||||||
Object data = getGenericData(context, queryUri, KeyRings.MASTER_KEY_ID, FIELD_TYPE_INTEGER);
|
Object data = getGenericData(context, queryUri, KeyRings.MASTER_KEY_ID, FIELD_TYPE_INTEGER);
|
||||||
if(data != null) {
|
if(data != null) {
|
||||||
return (Long) data;
|
return (Long) data;
|
||||||
|
@ -180,7 +180,8 @@ public class AccountSettingsFragment extends Fragment implements
|
|||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
// select newly created key
|
// select newly created key
|
||||||
try {
|
try {
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), data.getData());
|
long masterKeyId = ProviderHelper.extractOrGetMasterKeyId(
|
||||||
|
getActivity(), data.getData());
|
||||||
mSelectKeyFragment.selectKey(masterKeyId);
|
mSelectKeyFragment.selectKey(masterKeyId);
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
Log.e(Constants.TAG, "key not found!", e);
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
@ -331,11 +331,8 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void encryptToContact(Uri dataUri) {
|
private void encryptToContact(Uri dataUri) {
|
||||||
// TODO preselect from uri? should be feasible without trivial query
|
|
||||||
try {
|
try {
|
||||||
long keyId = ProviderHelper.getMasterKeyId(getActivity(),
|
long keyId = ProviderHelper.extractOrGetMasterKeyId(getActivity(), dataUri);
|
||||||
KeyRingData.buildPublicKeyRingUri(dataUri));
|
|
||||||
|
|
||||||
long[] encryptionKeyIds = new long[]{ keyId };
|
long[] encryptionKeyIds = new long[]{ keyId };
|
||||||
Intent intent = new Intent(getActivity(), EncryptActivity.class);
|
Intent intent = new Intent(getActivity(), EncryptActivity.class);
|
||||||
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
|
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
|
||||||
|
@ -82,7 +82,6 @@ public class ShareQrCodeDialogFragment extends DialogFragment {
|
|||||||
mFingerprintOnly = getArguments().getBoolean(ARG_FINGERPRINT_ONLY);
|
mFingerprintOnly = getArguments().getBoolean(ARG_FINGERPRINT_ONLY);
|
||||||
|
|
||||||
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
||||||
|
|
||||||
alert.setTitle(R.string.share_qr_code_dialog_title);
|
alert.setTitle(R.string.share_qr_code_dialog_title);
|
||||||
|
|
||||||
LayoutInflater inflater = activity.getLayoutInflater();
|
LayoutInflater inflater = activity.getLayoutInflater();
|
||||||
@ -100,7 +99,8 @@ public class ShareQrCodeDialogFragment extends DialogFragment {
|
|||||||
getActivity(), KeyRings.buildUnifiedKeyRingUri(dataUri),
|
getActivity(), KeyRings.buildUnifiedKeyRingUri(dataUri),
|
||||||
KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB);
|
KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB);
|
||||||
if(blob == null) {
|
if(blob == null) {
|
||||||
// TODO error handling?!
|
Log.e(Constants.TAG, "key not found!");
|
||||||
|
AppMsg.makeText(getActivity(), R.string.error_key_not_found, AppMsg.STYLE_ALERT).show();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user