Introduce ProviderHelper.NotFoundException, remove dead code
This commit is contained in:
@@ -286,9 +286,13 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
||||
} else {
|
||||
Log.d(Constants.TAG, "uri: " + mDataUri);
|
||||
|
||||
// get master key id using row id
|
||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
|
||||
finallyEdit(masterKeyId);
|
||||
try {
|
||||
// get master key id using row id
|
||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
|
||||
finallyEdit(masterKeyId);
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG, "key not found!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,11 +34,14 @@ import org.spongycastle.openpgp.PGPPublicKey;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.Id;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Vector;
|
||||
@@ -160,11 +163,15 @@ public class EncryptAsymmetricFragment extends Fragment {
|
||||
if (preselectedEncryptionKeyIds != null) {
|
||||
Vector<Long> goodIds = new Vector<Long>();
|
||||
for (int i = 0; i < preselectedEncryptionKeyIds.length; ++i) {
|
||||
long id = ProviderHelper.getMasterKeyId(getActivity(),
|
||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(preselectedEncryptionKeyIds[i]))
|
||||
);
|
||||
// TODO check for available encrypt keys... is this even relevant?
|
||||
goodIds.add(id);
|
||||
try {
|
||||
long id = ProviderHelper.getMasterKeyId(getActivity(),
|
||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(preselectedEncryptionKeyIds[i]))
|
||||
);
|
||||
goodIds.add(id);
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG, "key not found!", e);
|
||||
}
|
||||
}
|
||||
if (goodIds.size() > 0) {
|
||||
long[] keyIds = new long[goodIds.size()];
|
||||
|
||||
@@ -234,17 +234,20 @@ public class ViewCertActivity extends ActionBarActivity
|
||||
} else {
|
||||
viewIntent = new Intent(this, ViewKeyActivityJB.class);
|
||||
}
|
||||
//
|
||||
long signerMasterKeyId = ProviderHelper.getMasterKeyId(this,
|
||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(mSignerKeyId))
|
||||
);
|
||||
// TODO notify user of this, maybe offer download?
|
||||
if (mSignerKeyId == 0L)
|
||||
return true;
|
||||
viewIntent.setData(KeyRings.buildGenericKeyRingUri(
|
||||
Long.toString(signerMasterKeyId))
|
||||
);
|
||||
startActivity(viewIntent);
|
||||
|
||||
try {
|
||||
long signerMasterKeyId = ProviderHelper.getMasterKeyId(this,
|
||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(mSignerKeyId))
|
||||
);
|
||||
viewIntent.setData(KeyRings.buildGenericKeyRingUri(
|
||||
Long.toString(signerMasterKeyId))
|
||||
);
|
||||
startActivity(viewIntent);
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
// TODO notify user of this, maybe offer download?
|
||||
Log.e(Constants.TAG, "key not found!", e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.TabsAdapter;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.ShareNfcDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.ShareQrCodeDialogFragment;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -184,7 +185,7 @@ public class ViewKeyActivity extends ActionBarActivity {
|
||||
}
|
||||
|
||||
private void shareKey(Uri dataUri, boolean fingerprintOnly) {
|
||||
String content;
|
||||
String content = null;
|
||||
if (fingerprintOnly) {
|
||||
byte[] data = (byte[]) ProviderHelper.getGenericData(
|
||||
this, KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri),
|
||||
@@ -199,27 +200,36 @@ public class ViewKeyActivity extends ActionBarActivity {
|
||||
}
|
||||
} else {
|
||||
// get public keyring as ascii armored string
|
||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||
this, new long[]{masterKeyId});
|
||||
try {
|
||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||
|
||||
content = keyringArmored.get(0);
|
||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||
this, new long[]{masterKeyId});
|
||||
|
||||
// Android will fail with android.os.TransactionTooLargeException if key is too big
|
||||
// see http://www.lonestarprod.com/?p=34
|
||||
if (content.length() >= 86389) {
|
||||
Toast.makeText(getApplicationContext(), R.string.key_too_big_for_sharing,
|
||||
Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
content = keyringArmored.get(0);
|
||||
|
||||
// Android will fail with android.os.TransactionTooLargeException if key is too big
|
||||
// see http://www.lonestarprod.com/?p=34
|
||||
if (content.length() >= 86389) {
|
||||
Toast.makeText(getApplicationContext(), R.string.key_too_big_for_sharing,
|
||||
Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG, "key not found!", e);
|
||||
}
|
||||
}
|
||||
|
||||
// let user choose application
|
||||
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, content);
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(Intent.createChooser(sendIntent,
|
||||
getResources().getText(R.string.action_share_key_with)));
|
||||
if (content != null) {
|
||||
// let user choose application
|
||||
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, content);
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(Intent.createChooser(sendIntent,
|
||||
getResources().getText(R.string.action_share_key_with)));
|
||||
} else {
|
||||
Log.e(Constants.TAG, "content is null!");
|
||||
}
|
||||
}
|
||||
|
||||
private void shareKeyQrCode(Uri dataUri, boolean fingerprintOnly) {
|
||||
@@ -230,13 +240,18 @@ public class ViewKeyActivity extends ActionBarActivity {
|
||||
|
||||
private void copyToClipboard(Uri dataUri) {
|
||||
// get public keyring as ascii armored string
|
||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||
this, new long[]{masterKeyId});
|
||||
try {
|
||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||
|
||||
ClipboardReflection.copyToClipboard(this, keyringArmored.get(0));
|
||||
Toast.makeText(getApplicationContext(), R.string.key_copied_to_clipboard, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||
this, new long[]{masterKeyId});
|
||||
|
||||
ClipboardReflection.copyToClipboard(this, keyringArmored.get(0));
|
||||
Toast.makeText(getApplicationContext(), R.string.key_copied_to_clipboard, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG, "key not found!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void shareNfc() {
|
||||
|
||||
@@ -328,14 +328,18 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
|
||||
private void encryptToContact(Uri dataUri) {
|
||||
// TODO preselect from uri? should be feasible without trivial query
|
||||
long keyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
||||
try {
|
||||
long keyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
||||
|
||||
long[] encryptionKeyIds = new long[]{ keyId };
|
||||
Intent intent = new Intent(getActivity(), EncryptActivity.class);
|
||||
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
|
||||
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
|
||||
// used instead of startActivity set actionbar based on callingPackage
|
||||
startActivityForResult(intent, 0);
|
||||
long[] encryptionKeyIds = new long[]{ keyId };
|
||||
Intent intent = new Intent(getActivity(), EncryptActivity.class);
|
||||
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
|
||||
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
|
||||
// used instead of startActivity set actionbar based on callingPackage
|
||||
startActivityForResult(intent, 0);
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG, "key not found!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void certifyKey(Uri dataUri) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.QrCodeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -106,7 +107,12 @@ public class ShareQrCodeDialogFragment extends DialogFragment {
|
||||
mText.setText(R.string.share_qr_code_dialog_start);
|
||||
|
||||
// TODO works, but
|
||||
long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
||||
long masterKeyId = 0;
|
||||
try {
|
||||
masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG, "key not found!", e);
|
||||
}
|
||||
// get public keyring as ascii armored string
|
||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||
getActivity(), new long[] { masterKeyId });
|
||||
|
||||
Reference in New Issue
Block a user