Result parcel refactorings (WIP)

This commit is contained in:
Dominik Schürmann 2014-09-17 15:08:02 +02:00
parent a3e7406b3d
commit 8724916866
11 changed files with 192 additions and 160 deletions

View File

@ -138,7 +138,7 @@
android:label="@string/title_select_recipients"
android:launchMode="singleTop" />
<activity
android:name=".ui.EncryptFileActivity"
android:name=".ui.EncryptFilesActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/title_encrypt_files"
android:windowSoftInputMode="stateHidden">

View File

@ -22,7 +22,7 @@ import android.os.Environment;
import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.sufficientlysecure.keychain.remote.ui.AppsListActivity;
import org.sufficientlysecure.keychain.ui.DecryptActivity;
import org.sufficientlysecure.keychain.ui.EncryptFileActivity;
import org.sufficientlysecure.keychain.ui.EncryptFilesActivity;
import org.sufficientlysecure.keychain.ui.EncryptTextActivity;
import org.sufficientlysecure.keychain.ui.KeyListActivity;
@ -94,7 +94,7 @@ public final class Constants {
public static final class DrawerItems {
public static final Class KEY_LIST = KeyListActivity.class;
public static final Class ENCRYPT_TEXT = EncryptTextActivity.class;
public static final Class ENCRYPT_FILE = EncryptFileActivity.class;
public static final Class ENCRYPT_FILE = EncryptFilesActivity.class;
public static final Class DECRYPT = DecryptActivity.class;
public static final Class REGISTERED_APPS_LIST = AppsListActivity.class;
public static final Class[] ARRAY = new Class[]{

View File

@ -48,7 +48,7 @@ import java.io.File;
public class DecryptFilesFragment extends DecryptFragment {
public static final String ARG_URI = "uri";
// public static final String ARG_FROM_VIEW_INTENT = "view_intent";
// public static final String ARG_FROM_VIEW_INTENT = "view_intent";
public static final String ARG_OPEN_DIRECTLY = "open_directly";
private static final int REQUEST_CODE_INPUT = 0x00007003;
@ -204,20 +204,28 @@ public class DecryptFilesFragment extends DecryptFragment {
// get returned data bundle
Bundle returnData = message.getData();
DecryptVerifyResult result =
DecryptVerifyResult pgpResult =
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
switch (result.getResult()) {
case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE:
showPassphraseDialog(result.getKeyIdPassphraseNeeded());
return;
case DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE:
if (pgpResult.isPending()) {
if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) ==
DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) {
showPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) ==
DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) {
showPassphraseDialog(Constants.key.symmetric);
return;
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
DecryptVerifyResult.RESULT_PENDING_NFC) {
// TODO
} else {
throw new RuntimeException("Unhandled pending result!");
}
} else if (pgpResult.success()) {
// go on...
askForOutputFilename(pgpResult.getDecryptMetadata().getFilename());
} else {
pgpResult.createNotify(getActivity()).show();
}
// go on...
askForOutputFilename(result.getDecryptMetadata().getFilename());
}
}
};
@ -284,41 +292,45 @@ public class DecryptFilesFragment extends DecryptFragment {
// get returned data bundle
Bundle returnData = message.getData();
DecryptVerifyResult result =
DecryptVerifyResult pgpResult =
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
if (result.isPending()) {
switch (result.getResult()) {
case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE:
showPassphraseDialog(result.getKeyIdPassphraseNeeded());
return;
case DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE:
showPassphraseDialog(Constants.key.symmetric);
return;
if (pgpResult.isPending()) {
if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) ==
DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) {
showPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) ==
DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) {
showPassphraseDialog(Constants.key.symmetric);
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
DecryptVerifyResult.RESULT_PENDING_NFC) {
// TODO
} else {
throw new RuntimeException("Unhandled pending result!");
}
// error, we can't work with this!
result.createNotify(getActivity());
return;
}
} else if (pgpResult.success()) {
// display signature result in activity
onResult(result);
// display signature result in activity
onResult(pgpResult);
if (mDeleteAfter.isChecked()) {
// Create and show dialog to delete original file
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(mInputUri);
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
setInputUri(null);
}
if (mDeleteAfter.isChecked()) {
// Create and show dialog to delete original file
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(mInputUri);
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
setInputUri(null);
}
/*
// A future open after decryption feature
if () {
Intent viewFile = new Intent(Intent.ACTION_VIEW);
viewFile.setData(mOutputUri);
startActivity(viewFile);
/*
// A future open after decryption feature
if () {
Intent viewFile = new Intent(Intent.ACTION_VIEW);
viewFile.setData(mOutputUri);
startActivity(viewFile);
}
*/
} else {
pgpResult.createNotify(getActivity()).show();
}
*/
}
}

View File

@ -126,34 +126,37 @@ public class DecryptTextFragment extends DecryptFragment {
// get returned data bundle
Bundle returnData = message.getData();
DecryptVerifyResult result =
DecryptVerifyResult pgpResult =
returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);
if (result.isPending()) {
switch (result.getResult()) {
case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE:
showPassphraseDialog(result.getKeyIdPassphraseNeeded());
return;
case DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE:
showPassphraseDialog(Constants.key.symmetric);
return;
if (pgpResult.isPending()) {
if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) ==
DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE) {
showPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) ==
DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE) {
showPassphraseDialog(Constants.key.symmetric);
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
DecryptVerifyResult.RESULT_PENDING_NFC) {
// TODO
} else {
throw new RuntimeException("Unhandled pending result!");
}
// error, we can't work with this!
result.createNotify(getActivity()).show();
return;
} else if (pgpResult.success()) {
byte[] decryptedMessage = returnData
.getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES);
mMessage.setText(new String(decryptedMessage));
mMessage.setHorizontallyScrolling(false);
pgpResult.createNotify(getActivity()).show();
// display signature result in activity
onResult(pgpResult);
} else {
pgpResult.createNotify(getActivity()).show();
}
byte[] decryptedMessage = returnData
.getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES);
mMessage.setText(new String(decryptedMessage));
mMessage.setHorizontallyScrolling(false);
result.createNotify(getActivity()).show();
// display signature result in activity
onResult(result);
}
}
};

View File

@ -0,0 +1,37 @@
package org.sufficientlysecure.keychain.ui;
import android.content.Intent;
import org.sufficientlysecure.keychain.nfc.NfcActivity;
public class EncryptActivity extends DrawerActivity {
protected void startNfcSign(String pin, byte[] hashToSign, int hashAlgo) {
Intent data = new Intent();
// build PendingIntent for Yubikey NFC operations
Intent intent = new Intent(this, NfcActivity.class);
intent.setAction(NfcActivity.ACTION_SIGN_HASH);
// pass params through to activity that it can be returned again later to repeat pgp operation
intent.putExtra(NfcActivity.EXTRA_DATA, data);
intent.putExtra(NfcActivity.EXTRA_PIN, pin);
intent.putExtra(NfcActivity.EXTRA_NFC_HASH_TO_SIGN, hashToSign);
intent.putExtra(NfcActivity.EXTRA_NFC_HASH_ALGO, hashAlgo);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, 0);
}
protected void startPassphraseDialog(long subkeyId) {
Intent data = new Intent();
// build PendingIntent for Yubikey NFC operations
Intent intent = new Intent(this, PassphraseDialogActivity.class);
// pass params through to activity that it can be returned again later to repeat pgp operation
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, subkeyId);
// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, 0);
}
}

View File

@ -22,7 +22,6 @@ 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.support.v4.app.Fragment;
@ -32,15 +31,13 @@ import android.view.MenuItem;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.api.OpenKeychainIntents;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.helper.ShareHelper;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.service.results.SignEncryptResult;
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Notify;
@ -48,7 +45,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class EncryptFileActivity extends DrawerActivity implements EncryptActivityInterface {
public class EncryptFilesActivity extends EncryptActivity implements EncryptActivityInterface {
/* Intents */
public static final String ACTION_ENCRYPT_DATA = OpenKeychainIntents.ENCRYPT_DATA;
@ -194,24 +191,44 @@ public class EncryptFileActivity extends DrawerActivity implements EncryptActivi
super.handleMessage(message);
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
Notify.showNotify(EncryptFileActivity.this, R.string.encrypt_sign_successful, Notify.Style.INFO);
Notify.showNotify(EncryptFilesActivity.this, R.string.encrypt_sign_successful, Notify.Style.INFO);
if (mDeleteAfterEncrypt) {
for (Uri inputUri : mInputUris) {
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(inputUri);
deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
SignEncryptResult pgpResult =
message.getData().getParcelable(SignEncryptResult.EXTRA_RESULT);
if (pgpResult.isPending()) {
if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_PASSPHRASE) ==
SignEncryptResult.RESULT_PENDING_PASSPHRASE) {
startPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
} else if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_NFC) ==
SignEncryptResult.RESULT_PENDING_NFC) {
// use after nfc sign
//// data.putExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, result.getNfcTimestamp().getTime());
startNfcSign("123456", pgpResult.getNfcHash(), pgpResult.getNfcAlgo());
} else {
throw new RuntimeException("Unhandled pending result!");
}
} else if (pgpResult.success()) {
if (mDeleteAfterEncrypt) {
for (Uri inputUri : mInputUris) {
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(inputUri);
deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
}
mInputUris.clear();
notifyUpdate();
}
mInputUris.clear();
notifyUpdate();
}
if (mShareAfterEncrypt) {
// Share encrypted message/file
startActivity(sendWithChooserExcludingEncrypt(message));
if (mShareAfterEncrypt) {
// Share encrypted message/file
startActivity(sendWithChooserExcludingEncrypt(message));
} else {
// Save encrypted file
Notify.showNotify(EncryptFilesActivity.this,
R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO);
}
} else {
// Save encrypted file
Notify.showNotify(EncryptFileActivity.this,
R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO);
pgpResult.createNotify(EncryptFilesActivity.this).show();
}
}
}
@ -336,25 +353,25 @@ public class EncryptFileActivity extends DrawerActivity implements EncryptActivi
return false;
}
try {
if (mSigningKeyId != 0 && PassphraseCacheService.getCachedPassphrase(this, mSigningKeyId) == null) {
PassphraseDialogFragment.show(this, mSigningKeyId,
new Handler() {
@Override
public void handleMessage(Message message) {
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
// restart
startEncrypt();
}
}
}
);
return false;
}
} catch (PassphraseCacheService.KeyNotFoundException e) {
Log.e(Constants.TAG, "Key not found!", e);
}
// try {
// if (mSigningKeyId != 0 && PassphraseCacheService.getCachedPassphrase(this, mSigningKeyId) == null) {
// PassphraseDialogFragment.show(this, mSigningKeyId,
// new Handler() {
// @Override
// public void handleMessage(Message message) {
// if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
// // restart
// startEncrypt();
// }
// }
// }
// );
//
// return false;
// }
// } catch (PassphraseCacheService.KeyNotFoundException e) {
// Log.e(Constants.TAG, "Key not found!", e);
// }
}
return true;
}

View File

@ -43,10 +43,9 @@ import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
public class EncryptFileFragment extends Fragment implements EncryptActivityInterface.UpdateListener {
public class EncryptFilesFragment extends Fragment implements EncryptActivityInterface.UpdateListener {
public static final String ARG_URIS = "uris";
private static final int REQUEST_CODE_INPUT = 0x00007003;
@ -115,9 +114,9 @@ public class EncryptFileFragment extends Fragment implements EncryptActivityInte
private void addInputUri() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
FileHelper.openDocument(EncryptFileFragment.this, "*/*", true, REQUEST_CODE_INPUT);
FileHelper.openDocument(EncryptFilesFragment.this, "*/*", true, REQUEST_CODE_INPUT);
} else {
FileHelper.openFile(EncryptFileFragment.this, mEncryptInterface.getInputUris().isEmpty() ?
FileHelper.openFile(EncryptFilesFragment.this, mEncryptInterface.getInputUris().isEmpty() ?
null : mEncryptInterface.getInputUris().get(mEncryptInterface.getInputUris().size() - 1),
"*/*", REQUEST_CODE_INPUT);
}

View File

@ -46,7 +46,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class EncryptTextActivity extends DrawerActivity implements EncryptActivityInterface {
public class EncryptTextActivity extends EncryptActivity implements EncryptActivityInterface {
/* Intents */
public static final String ACTION_ENCRYPT_TEXT = OpenKeychainIntents.ENCRYPT_TEXT;
@ -192,39 +192,35 @@ public class EncryptTextActivity extends DrawerActivity implements EncryptActivi
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
SignEncryptResult result =
SignEncryptResult pgpResult =
message.getData().getParcelable(SignEncryptResult.EXTRA_RESULT);
if (result.isPending()) {
Log.d(Constants.TAG, "result.getResult() " + result.getResult());
if ((result.getResult() & SignEncryptResult.RESULT_PENDING_PASSPHRASE) ==
if (pgpResult.isPending()) {
if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_PASSPHRASE) ==
SignEncryptResult.RESULT_PENDING_PASSPHRASE) {
Log.d(Constants.TAG, "passp");
startPassphraseDialog(result.getKeyIdPassphraseNeeded());
} else if ((result.getResult() & SignEncryptResult.RESULT_PENDING_NFC) ==
startPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
} else if ((pgpResult.getResult() & SignEncryptResult.RESULT_PENDING_NFC) ==
SignEncryptResult.RESULT_PENDING_NFC) {
Log.d(Constants.TAG, "nfc");
// use after nfc sign
//// data.putExtra(OpenPgpApi.EXTRA_NFC_SIG_CREATION_TIMESTAMP, result.getNfcTimestamp().getTime());
startNfcSign("123456", result.getNfcHash(), result.getNfcAlgo());
startNfcSign("123456", pgpResult.getNfcHash(), pgpResult.getNfcAlgo());
} else {
throw new RuntimeException("Unhandled pending result!");
}
} else if (result.success()) {
} else if (pgpResult.success()) {
if (mShareAfterEncrypt) {
// Share encrypted message/file
startActivity(sendWithChooserExcludingEncrypt(message));
} else {
// Copy to clipboard
copyToClipboard(message);
result.createNotify(EncryptTextActivity.this).show();
pgpResult.createNotify(EncryptTextActivity.this).show();
// Notify.showNotify(EncryptTextActivity.this,
// R.string.encrypt_sign_clipboard_successful, Notify.Style.INFO);
}
} else {
result.createNotify(EncryptTextActivity.this).show();
pgpResult.createNotify(EncryptTextActivity.this).show();
}
}
}
@ -240,36 +236,6 @@ public class EncryptTextActivity extends DrawerActivity implements EncryptActivi
startService(intent);
}
private void startNfcSign(String pin, byte[] hashToSign, int hashAlgo) {
Intent data = new Intent();
// build PendingIntent for Yubikey NFC operations
Intent intent = new Intent(this, NfcActivity.class);
intent.setAction(NfcActivity.ACTION_SIGN_HASH);
// pass params through to activity that it can be returned again later to repeat pgp operation
intent.putExtra(NfcActivity.EXTRA_DATA, data);
intent.putExtra(NfcActivity.EXTRA_PIN, pin);
intent.putExtra(NfcActivity.EXTRA_NFC_HASH_TO_SIGN, hashToSign);
intent.putExtra(NfcActivity.EXTRA_NFC_HASH_ALGO, hashAlgo);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, 0);
}
private void startPassphraseDialog(long subkeyId) {
Intent data = new Intent();
// build PendingIntent for Yubikey NFC operations
Intent intent = new Intent(this, PassphraseDialogActivity.class);
// pass params through to activity that it can be returned again later to repeat pgp operation
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, subkeyId);
// intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, 0);
}
private Bundle createEncryptBundle() {
// fill values for this action
Bundle data = new Bundle();

View File

@ -35,8 +35,6 @@ import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.CursorAdapter;
import android.support.v4.widget.NoScrollableSwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
@ -394,9 +392,9 @@ public class KeyListFragment extends LoaderFragment
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void encrypt(ActionMode mode, long[] masterKeyIds) {
Intent intent = new Intent(getActivity(), EncryptFileActivity.class);
intent.setAction(EncryptFileActivity.ACTION_ENCRYPT_DATA);
intent.putExtra(EncryptFileActivity.EXTRA_ENCRYPTION_KEY_IDS, masterKeyIds);
Intent intent = new Intent(getActivity(), EncryptFilesActivity.class);
intent.setAction(EncryptFilesActivity.ACTION_ENCRYPT_DATA);
intent.putExtra(EncryptFilesActivity.EXTRA_ENCRYPTION_KEY_IDS, masterKeyIds);
// used instead of startActivity set actionbar based on callingPackage
startActivityForResult(intent, 0);

View File

@ -302,9 +302,9 @@ public class ViewKeyMainFragment extends LoaderFragment implements
intent.setAction(EncryptTextActivity.ACTION_ENCRYPT_TEXT);
intent.putExtra(EncryptTextActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
} else {
intent = new Intent(getActivity(), EncryptFileActivity.class);
intent.setAction(EncryptFileActivity.ACTION_ENCRYPT_DATA);
intent.putExtra(EncryptFileActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
intent = new Intent(getActivity(), EncryptFilesActivity.class);
intent.setAction(EncryptFilesActivity.ACTION_ENCRYPT_DATA);
intent.putExtra(EncryptFilesActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
}
// used instead of startActivity set actionbar based on callingPackage
startActivityForResult(intent, 0);

View File

@ -17,7 +17,7 @@
<fragment
android:id="@+id/encrypt_file_fragment"
android:name="org.sufficientlysecure.keychain.ui.EncryptFileFragment"
android:name="org.sufficientlysecure.keychain.ui.EncryptFilesFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />