diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java index c42446c9e..c0aaf6d89 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java @@ -51,7 +51,7 @@ public class ExportHelper { public void deleteKey(Uri dataUri, Handler deleteHandler) { try { - long masterKeyId = ProviderHelper.getMasterKeyId(mActivity, dataUri); + long masterKeyId = ProviderHelper.extractOrGetMasterKeyId(mActivity, dataUri); // Create a new Messenger for the communication back Messenger messenger = new Messenger(deleteHandler); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index 43fbf7045..8e1bb3f60 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -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 * 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 -// String firstSegment = queryUri.getPathSegments().get(1); -// if(!firstSegment.equals("find")) try { -// return Long.parseLong(firstSegment); -// } catch(NumberFormatException e) { -// // didn't work? oh well. -// Log.d(Constants.TAG, "Couldn't get masterKeyId from URI, querying..."); -// } + String firstSegment = queryUri.getPathSegments().get(1); + if(!firstSegment.equals("find")) try { + return Long.parseLong(firstSegment); + } catch(NumberFormatException e) { + // didn't work? oh well. + 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); if(data != null) { return (Long) data; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java index 321d2a83f..a13c7a953 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java @@ -180,7 +180,8 @@ public class AccountSettingsFragment extends Fragment implements if (resultCode == Activity.RESULT_OK) { // select newly created key try { - long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), data.getData()); + long masterKeyId = ProviderHelper.extractOrGetMasterKeyId( + getActivity(), data.getData()); mSelectKeyFragment.selectKey(masterKeyId); } catch (ProviderHelper.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java index a7543d194..386342a48 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java @@ -331,11 +331,8 @@ public class ViewKeyMainFragment extends Fragment implements } private void encryptToContact(Uri dataUri) { - // TODO preselect from uri? should be feasible without trivial query try { - long keyId = ProviderHelper.getMasterKeyId(getActivity(), - KeyRingData.buildPublicKeyRingUri(dataUri)); - + long keyId = ProviderHelper.extractOrGetMasterKeyId(getActivity(), dataUri); long[] encryptionKeyIds = new long[]{ keyId }; Intent intent = new Intent(getActivity(), EncryptActivity.class); intent.setAction(EncryptActivity.ACTION_ENCRYPT); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java index 01d3db235..7e9a3d800 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ShareQrCodeDialogFragment.java @@ -82,7 +82,6 @@ public class ShareQrCodeDialogFragment extends DialogFragment { mFingerprintOnly = getArguments().getBoolean(ARG_FINGERPRINT_ONLY); AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); - alert.setTitle(R.string.share_qr_code_dialog_title); LayoutInflater inflater = activity.getLayoutInflater(); @@ -100,7 +99,8 @@ public class ShareQrCodeDialogFragment extends DialogFragment { getActivity(), KeyRings.buildUnifiedKeyRingUri(dataUri), KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); 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; }