mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
parent
b77fb2fcc0
commit
baa3c86e12
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user