mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-01-30 22:50:19 -05:00
Start refactoring encrypt ui, EncryptFileActivity no longer crashing
This commit is contained in:
parent
1ef63f3187
commit
76db0b3b8e
@ -51,8 +51,9 @@ public abstract class CryptoOperationFragment extends Fragment {
|
|||||||
CryptoInputParcel cryptoInput =
|
CryptoInputParcel cryptoInput =
|
||||||
data.getParcelableExtra(PassphraseDialogActivity.RESULT_DATA);
|
data.getParcelableExtra(PassphraseDialogActivity.RESULT_DATA);
|
||||||
cryptoOperation(cryptoInput);
|
cryptoOperation(cryptoInput);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case REQUEST_CODE_NFC: {
|
case REQUEST_CODE_NFC: {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -40,7 +40,17 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class EncryptAsymmetricFragment extends Fragment implements EncryptActivityInterface.UpdateListener {
|
public class EncryptAsymmetricFragment extends Fragment {
|
||||||
|
|
||||||
|
public interface IAsymmetric {
|
||||||
|
|
||||||
|
public void onSignatureKeyIdChanged(long signatureKeyId);
|
||||||
|
|
||||||
|
public void onEncryptionKeyIdsChanged(long[] encryptionKeyIds);
|
||||||
|
|
||||||
|
public void onEncryptionUserIdsChanged(String[] encryptionUserIds);
|
||||||
|
}
|
||||||
|
|
||||||
ProviderHelper mProviderHelper;
|
ProviderHelper mProviderHelper;
|
||||||
|
|
||||||
// view
|
// view
|
||||||
@ -48,37 +58,43 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
|
|||||||
private EncryptKeyCompletionView mEncryptKeyView;
|
private EncryptKeyCompletionView mEncryptKeyView;
|
||||||
|
|
||||||
// model
|
// model
|
||||||
private EncryptActivityInterface mEncryptInterface;
|
private IAsymmetric mEncryptInterface;
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public void onNotifyUpdate() {
|
// public void onNotifyUpdate() {
|
||||||
if (mSign != null) {
|
// if (mSign != null) {
|
||||||
mSign.setSelectedKeyId(mEncryptInterface.getSignatureKey());
|
// mSign.setSelectedKeyId(mEncryptInterface.getSignatureKey());
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
public static final String ARG_SINGATURE_KEY_ID = "signature_key_id";
|
||||||
|
public static final String ARG_ENCRYPTION_KEY_IDS = "encryption_key_ids";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new instance of this fragment
|
||||||
|
*/
|
||||||
|
public static EncryptAsymmetricFragment newInstance(long signatureKey, long[] encryptionKeyIds) {
|
||||||
|
EncryptAsymmetricFragment frag = new EncryptAsymmetricFragment();
|
||||||
|
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putLong(ARG_SINGATURE_KEY_ID, signatureKey);
|
||||||
|
args.putLongArray(ARG_ENCRYPTION_KEY_IDS, encryptionKeyIds);
|
||||||
|
frag.setArguments(args);
|
||||||
|
|
||||||
|
return frag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
try {
|
try {
|
||||||
mEncryptInterface = (EncryptActivityInterface) activity;
|
mEncryptInterface = (IAsymmetric) activity;
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
throw new ClassCastException(activity.toString() + " must implement EncryptActivityInterface");
|
throw new ClassCastException(activity.toString() + " must implement IAsymmetric");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSignatureKeyId(long signatureKeyId) {
|
|
||||||
mEncryptInterface.setSignatureKey(signatureKeyId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setEncryptionKeyIds(long[] encryptionKeyIds) {
|
|
||||||
mEncryptInterface.setEncryptionKeys(encryptionKeyIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setEncryptionUserIds(String[] encryptionUserIds) {
|
|
||||||
mEncryptInterface.setEncryptionUsers(encryptionUserIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inflate the layout for this fragment
|
* Inflate the layout for this fragment
|
||||||
*/
|
*/
|
||||||
@ -90,7 +106,7 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
|
|||||||
mSign.setOnKeyChangedListener(new KeySpinner.OnKeyChangedListener() {
|
mSign.setOnKeyChangedListener(new KeySpinner.OnKeyChangedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onKeyChanged(long masterKeyId) {
|
public void onKeyChanged(long masterKeyId) {
|
||||||
setSignatureKeyId(masterKeyId);
|
mEncryptInterface.onSignatureKeyIdChanged(masterKeyId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mEncryptKeyView = (EncryptKeyCompletionView) view.findViewById(R.id.recipient_list);
|
mEncryptKeyView = (EncryptKeyCompletionView) view.findViewById(R.id.recipient_list);
|
||||||
@ -105,7 +121,9 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
|
|||||||
mProviderHelper = new ProviderHelper(getActivity());
|
mProviderHelper = new ProviderHelper(getActivity());
|
||||||
|
|
||||||
// preselect keys given
|
// preselect keys given
|
||||||
preselectKeys();
|
long signatureKeyId = getArguments().getLong(ARG_SINGATURE_KEY_ID);
|
||||||
|
long[] encryptionKeyIds = getArguments().getLongArray(ARG_ENCRYPTION_KEY_IDS);
|
||||||
|
preselectKeys(signatureKeyId, encryptionKeyIds);
|
||||||
|
|
||||||
mEncryptKeyView.setTokenListener(new TokenCompleteTextView.TokenListener() {
|
mEncryptKeyView.setTokenListener(new TokenCompleteTextView.TokenListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -127,24 +145,20 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
|
|||||||
/**
|
/**
|
||||||
* If an Intent gives a signatureMasterKeyId and/or encryptionMasterKeyIds, preselect those!
|
* If an Intent gives a signatureMasterKeyId and/or encryptionMasterKeyIds, preselect those!
|
||||||
*/
|
*/
|
||||||
private void preselectKeys() {
|
private void preselectKeys(long signatureKeyId, long[] encryptionKeyIds) {
|
||||||
// TODO all of this works under the assumption that the first suitable subkey is always used!
|
if (signatureKeyId != Constants.key.none) {
|
||||||
// not sure if we need to distinguish between different subkeys here?
|
|
||||||
long signatureKey = mEncryptInterface.getSignatureKey();
|
|
||||||
if (signatureKey != Constants.key.none) {
|
|
||||||
try {
|
try {
|
||||||
CachedPublicKeyRing keyring = mProviderHelper.getCachedPublicKeyRing(
|
CachedPublicKeyRing keyring = mProviderHelper.getCachedPublicKeyRing(
|
||||||
KeyRings.buildUnifiedKeyRingUri(signatureKey));
|
KeyRings.buildUnifiedKeyRingUri(signatureKeyId));
|
||||||
if (keyring.hasAnySecret()) {
|
if (keyring.hasAnySecret()) {
|
||||||
setSignatureKeyId(keyring.getMasterKeyId());
|
mEncryptInterface.onSignatureKeyIdChanged(keyring.getMasterKeyId());
|
||||||
mSign.setSelectedKeyId(mEncryptInterface.getSignatureKey());
|
mSign.setSelectedKeyId(signatureKeyId);
|
||||||
}
|
}
|
||||||
} catch (PgpKeyNotFoundException e) {
|
} catch (PgpKeyNotFoundException e) {
|
||||||
Log.e(Constants.TAG, "key not found!", e);
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long[] encryptionKeyIds = mEncryptInterface.getEncryptionKeys();
|
|
||||||
if (encryptionKeyIds != null) {
|
if (encryptionKeyIds != null) {
|
||||||
for (long preselectedId : encryptionKeyIds) {
|
for (long preselectedId : encryptionKeyIds) {
|
||||||
try {
|
try {
|
||||||
@ -176,7 +190,7 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
|
|||||||
for (int i = 0; i < keyIds.size(); i++) {
|
for (int i = 0; i < keyIds.size(); i++) {
|
||||||
keyIdsArr[i] = iterator.next();
|
keyIdsArr[i] = iterator.next();
|
||||||
}
|
}
|
||||||
setEncryptionKeyIds(keyIdsArr);
|
mEncryptInterface.onEncryptionKeyIdsChanged(keyIdsArr);
|
||||||
setEncryptionUserIds(userIds.toArray(new String[userIds.size()]));
|
mEncryptInterface.onEncryptionUserIdsChanged(userIds.toArray(new String[userIds.size()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
* Copyright (C) 2012-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
* Copyright (C) 2010-2014 Thialfihar <thi@thialfihar.org>
|
* Copyright (C) 2010-2014 Thialfihar <thi@thialfihar.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@ -22,28 +22,19 @@ import android.content.Intent;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.Menu;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.view.MenuItem;
|
|
||||||
|
|
||||||
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.api.OpenKeychainIntents;
|
import org.sufficientlysecure.keychain.api.OpenKeychainIntents;
|
||||||
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpConstants;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
|
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
import org.sufficientlysecure.keychain.util.ShareHelper;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class EncryptFilesActivity extends EncryptActivity implements EncryptActivityInterface {
|
public class EncryptFilesActivity extends BaseActivity implements
|
||||||
|
EncryptAsymmetricFragment.IAsymmetric, EncryptSymmetricFragment.ISymmetric,
|
||||||
|
EncryptFilesFragment.IMode {
|
||||||
|
|
||||||
/* Intents */
|
/* Intents */
|
||||||
public static final String ACTION_ENCRYPT_DATA = OpenKeychainIntents.ENCRYPT_DATA;
|
public static final String ACTION_ENCRYPT_DATA = OpenKeychainIntents.ENCRYPT_DATA;
|
||||||
@ -55,301 +46,15 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
|
|||||||
public static final String EXTRA_SIGNATURE_KEY_ID = Constants.EXTRA_PREFIX + "EXTRA_SIGNATURE_KEY_ID";
|
public static final String EXTRA_SIGNATURE_KEY_ID = Constants.EXTRA_PREFIX + "EXTRA_SIGNATURE_KEY_ID";
|
||||||
public static final String EXTRA_ENCRYPTION_KEY_IDS = Constants.EXTRA_PREFIX + "EXTRA_ENCRYPTION_IDS";
|
public static final String EXTRA_ENCRYPTION_KEY_IDS = Constants.EXTRA_PREFIX + "EXTRA_ENCRYPTION_IDS";
|
||||||
|
|
||||||
// view
|
Fragment mModeFragment;
|
||||||
private int mCurrentMode = MODE_ASYMMETRIC;
|
EncryptFilesFragment mEncryptFragment;
|
||||||
|
|
||||||
// tabs
|
|
||||||
private static final int MODE_ASYMMETRIC = 0;
|
|
||||||
private static final int MODE_SYMMETRIC = 1;
|
|
||||||
|
|
||||||
// model used by fragments
|
|
||||||
private boolean mUseArmor = false;
|
|
||||||
private boolean mUseCompression = true;
|
|
||||||
private boolean mDeleteAfterEncrypt = false;
|
|
||||||
private boolean mShareAfterEncrypt = false;
|
|
||||||
private boolean mEncryptFilenames = true;
|
|
||||||
private boolean mHiddenRecipients = false;
|
|
||||||
|
|
||||||
private long mEncryptionKeyIds[] = null;
|
|
||||||
private String mEncryptionUserIds[] = null;
|
|
||||||
private long mSigningKeyId = Constants.key.none;
|
|
||||||
private Passphrase mPassphrase = new Passphrase();
|
|
||||||
|
|
||||||
private ArrayList<Uri> mInputUris;
|
|
||||||
private ArrayList<Uri> mOutputUris;
|
|
||||||
private String mMessage = "";
|
|
||||||
|
|
||||||
public boolean isModeSymmetric() {
|
|
||||||
return MODE_SYMMETRIC == mCurrentMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUseArmor() {
|
|
||||||
return mUseArmor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUseCompression() {
|
|
||||||
return mUseCompression;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEncryptFilenames() {
|
|
||||||
return mEncryptFilenames;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isHiddenRecipients() {
|
|
||||||
return mHiddenRecipients;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getSignatureKey() {
|
|
||||||
return mSigningKeyId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long[] getEncryptionKeys() {
|
|
||||||
return mEncryptionKeyIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getEncryptionUsers() {
|
|
||||||
return mEncryptionUserIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSignatureKey(long signatureKey) {
|
|
||||||
mSigningKeyId = signatureKey;
|
|
||||||
notifyUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEncryptionKeys(long[] encryptionKeys) {
|
|
||||||
mEncryptionKeyIds = encryptionKeys;
|
|
||||||
notifyUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEncryptionUsers(String[] encryptionUsers) {
|
|
||||||
mEncryptionUserIds = encryptionUsers;
|
|
||||||
notifyUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPassphrase(Passphrase passphrase) {
|
|
||||||
mPassphrase = passphrase;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<Uri> getInputUris() {
|
|
||||||
if (mInputUris == null) mInputUris = new ArrayList<>();
|
|
||||||
return mInputUris;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<Uri> getOutputUris() {
|
|
||||||
if (mOutputUris == null) mOutputUris = new ArrayList<>();
|
|
||||||
return mOutputUris;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setInputUris(ArrayList<Uri> uris) {
|
|
||||||
mInputUris = uris;
|
|
||||||
notifyUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOutputUris(ArrayList<Uri> uris) {
|
|
||||||
mOutputUris = uris;
|
|
||||||
notifyUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
return mMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMessage(String message) {
|
|
||||||
mMessage = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notifyUpdate() {
|
|
||||||
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
|
|
||||||
if (fragment instanceof EncryptActivityInterface.UpdateListener) {
|
|
||||||
((UpdateListener) fragment).onNotifyUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startEncrypt(boolean share) {
|
|
||||||
mShareAfterEncrypt = share;
|
|
||||||
startEncrypt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEncryptSuccess(final SignEncryptResult result) {
|
|
||||||
if (mDeleteAfterEncrypt) {
|
|
||||||
final Uri[] inputUris = mInputUris.toArray(new Uri[mInputUris.size()]);
|
|
||||||
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(inputUris);
|
|
||||||
deleteFileDialog.setOnDeletedListener(new DeleteFileDialogFragment.OnDeletedListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDeleted() {
|
|
||||||
if (mShareAfterEncrypt) {
|
|
||||||
// Share encrypted message/file
|
|
||||||
startActivity(sendWithChooserExcludingEncrypt());
|
|
||||||
} else {
|
|
||||||
// Save encrypted file
|
|
||||||
result.createNotify(EncryptFilesActivity.this).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
|
|
||||||
|
|
||||||
mInputUris.clear();
|
|
||||||
notifyUpdate();
|
|
||||||
} else {
|
|
||||||
if (mShareAfterEncrypt) {
|
|
||||||
// Share encrypted message/file
|
|
||||||
startActivity(sendWithChooserExcludingEncrypt());
|
|
||||||
} else {
|
|
||||||
// Save encrypted file
|
|
||||||
result.createNotify(EncryptFilesActivity.this).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected SignEncryptParcel createEncryptBundle() {
|
|
||||||
// fill values for this action
|
|
||||||
SignEncryptParcel data = new SignEncryptParcel();
|
|
||||||
|
|
||||||
data.addInputUris(mInputUris);
|
|
||||||
data.addOutputUris(mOutputUris);
|
|
||||||
|
|
||||||
if (mUseCompression) {
|
|
||||||
data.setCompressionId(PgpConstants.sPreferredCompressionAlgorithms.get(0));
|
|
||||||
} else {
|
|
||||||
data.setCompressionId(CompressionAlgorithmTags.UNCOMPRESSED);
|
|
||||||
}
|
|
||||||
data.setHiddenRecipients(mHiddenRecipients);
|
|
||||||
data.setEnableAsciiArmorOutput(mUseArmor);
|
|
||||||
data.setSymmetricEncryptionAlgorithm(PgpConstants.OpenKeychainSymmetricKeyAlgorithmTags.USE_PREFERRED);
|
|
||||||
data.setSignatureHashAlgorithm(PgpConstants.OpenKeychainSymmetricKeyAlgorithmTags.USE_PREFERRED);
|
|
||||||
|
|
||||||
if (isModeSymmetric()) {
|
|
||||||
Log.d(Constants.TAG, "Symmetric encryption enabled!");
|
|
||||||
Passphrase passphrase = mPassphrase;
|
|
||||||
if (passphrase.isEmpty()) {
|
|
||||||
passphrase = null;
|
|
||||||
}
|
|
||||||
data.setSymmetricPassphrase(passphrase);
|
|
||||||
} else {
|
|
||||||
data.setEncryptionMasterKeyIds(mEncryptionKeyIds);
|
|
||||||
data.setSignatureMasterKeyId(mSigningKeyId);
|
|
||||||
data.setSignaturePassphrase(mSigningKeyPassphrase);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create Intent Chooser but exclude OK's EncryptActivity.
|
|
||||||
*/
|
|
||||||
private Intent sendWithChooserExcludingEncrypt() {
|
|
||||||
Intent prototype = createSendIntent();
|
|
||||||
String title = getString(R.string.title_share_file);
|
|
||||||
|
|
||||||
// we don't want to encrypt the encrypted, no inception ;)
|
|
||||||
String[] blacklist = new String[]{
|
|
||||||
Constants.PACKAGE_NAME + ".ui.EncryptFileActivity",
|
|
||||||
"org.thialfihar.android.apg.ui.EncryptActivity"
|
|
||||||
};
|
|
||||||
|
|
||||||
return new ShareHelper(this).createChooserExcluding(prototype, title, blacklist);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Intent createSendIntent() {
|
|
||||||
Intent sendIntent;
|
|
||||||
// file
|
|
||||||
if (mOutputUris.size() == 1) {
|
|
||||||
sendIntent = new Intent(Intent.ACTION_SEND);
|
|
||||||
sendIntent.putExtra(Intent.EXTRA_STREAM, mOutputUris.get(0));
|
|
||||||
} else {
|
|
||||||
sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
|
|
||||||
sendIntent.putExtra(Intent.EXTRA_STREAM, mOutputUris);
|
|
||||||
}
|
|
||||||
sendIntent.setType(Constants.ENCRYPTED_FILES_MIME);
|
|
||||||
|
|
||||||
if (!isModeSymmetric() && mEncryptionUserIds != null) {
|
|
||||||
Set<String> users = new HashSet<>();
|
|
||||||
for (String user : mEncryptionUserIds) {
|
|
||||||
KeyRing.UserId userId = KeyRing.splitUserId(user);
|
|
||||||
if (userId.email != null) {
|
|
||||||
users.add(userId.email);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendIntent.putExtra(Intent.EXTRA_EMAIL, users.toArray(new String[users.size()]));
|
|
||||||
}
|
|
||||||
return sendIntent;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean inputIsValid() {
|
|
||||||
// file checks
|
|
||||||
|
|
||||||
if (mInputUris.isEmpty()) {
|
|
||||||
Notify.create(this, R.string.no_file_selected, Notify.Style.ERROR)
|
|
||||||
.show(getSupportFragmentManager().findFragmentById(R.id.encrypt_file_fragment));
|
|
||||||
return false;
|
|
||||||
} else if (mInputUris.size() > 1 && !mShareAfterEncrypt) {
|
|
||||||
// This should be impossible...
|
|
||||||
return false;
|
|
||||||
} else if (mInputUris.size() != mOutputUris.size()) {
|
|
||||||
// This as well
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isModeSymmetric()) {
|
|
||||||
// symmetric encryption checks
|
|
||||||
|
|
||||||
if (mPassphrase == null) {
|
|
||||||
Notify.create(this, R.string.passphrases_do_not_match, Notify.Style.ERROR)
|
|
||||||
.show(getSupportFragmentManager().findFragmentById(R.id.encrypt_file_fragment));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (mPassphrase.isEmpty()) {
|
|
||||||
Notify.create(this, R.string.passphrase_must_not_be_empty, Notify.Style.ERROR)
|
|
||||||
.show(getSupportFragmentManager().findFragmentById(R.id.encrypt_file_fragment));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// asymmetric encryption checks
|
|
||||||
|
|
||||||
boolean gotEncryptionKeys = (mEncryptionKeyIds != null
|
|
||||||
&& mEncryptionKeyIds.length > 0);
|
|
||||||
|
|
||||||
// Files must be encrypted, only text can be signed-only right now
|
|
||||||
if (!gotEncryptionKeys) {
|
|
||||||
Notify.create(this, R.string.select_encryption_key, Notify.Style.ERROR)
|
|
||||||
.show(getSupportFragmentManager().findFragmentById(R.id.encrypt_file_fragment));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// Handle intent actions
|
// Handle intent actions
|
||||||
handleActions(getIntent());
|
handleActions(getIntent(), savedInstanceState);
|
||||||
updateModeFragment();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -357,73 +62,10 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
|
|||||||
setContentView(R.layout.encrypt_files_activity);
|
setContentView(R.layout.encrypt_files_activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
getMenuInflater().inflate(R.menu.encrypt_file_activity, menu);
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
if (item.isCheckable()) {
|
|
||||||
item.setChecked(!item.isChecked());
|
|
||||||
}
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.check_use_symmetric: {
|
|
||||||
mCurrentMode = item.isChecked() ? MODE_SYMMETRIC : MODE_ASYMMETRIC;
|
|
||||||
updateModeFragment();
|
|
||||||
notifyUpdate();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case R.id.check_use_armor: {
|
|
||||||
mUseArmor = item.isChecked();
|
|
||||||
notifyUpdate();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case R.id.check_delete_after_encrypt: {
|
|
||||||
mDeleteAfterEncrypt = item.isChecked();
|
|
||||||
notifyUpdate();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case R.id.check_enable_compression: {
|
|
||||||
mUseCompression = item.isChecked();
|
|
||||||
notifyUpdate();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case R.id.check_encrypt_filenames: {
|
|
||||||
mEncryptFilenames = item.isChecked();
|
|
||||||
notifyUpdate();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// case R.id.check_hidden_recipients: {
|
|
||||||
// mHiddenRecipients = item.isChecked();
|
|
||||||
// notifyUpdate();
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
default: {
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateModeFragment() {
|
|
||||||
getSupportFragmentManager().beginTransaction()
|
|
||||||
.replace(R.id.encrypt_pager_mode,
|
|
||||||
mCurrentMode == MODE_SYMMETRIC
|
|
||||||
? new EncryptSymmetricFragment()
|
|
||||||
: new EncryptAsymmetricFragment()
|
|
||||||
)
|
|
||||||
.commitAllowingStateLoss();
|
|
||||||
getSupportFragmentManager().executePendingTransactions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles all actions with this intent
|
* Handles all actions with this intent
|
||||||
*
|
|
||||||
* @param intent
|
|
||||||
*/
|
*/
|
||||||
private void handleActions(Intent intent) {
|
private void handleActions(Intent intent, Bundle savedInstanceState) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
String type = intent.getType();
|
String type = intent.getType();
|
||||||
@ -452,14 +94,56 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
|
|||||||
uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
mUseArmor = extras.getBoolean(EXTRA_ASCII_ARMOR, false);
|
long mSigningKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
|
||||||
|
long[] mEncryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);
|
||||||
|
boolean useArmor = extras.getBoolean(EXTRA_ASCII_ARMOR, false);
|
||||||
|
|
||||||
// preselect keys given by intent
|
if (savedInstanceState == null) {
|
||||||
mSigningKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
|
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||||
mEncryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);
|
|
||||||
|
|
||||||
// Save uris
|
mModeFragment = EncryptAsymmetricFragment.newInstance(mSigningKeyId, mEncryptionKeyIds);
|
||||||
mInputUris = uris;
|
transaction.replace(R.id.encrypt_mode_container, mModeFragment, "mode");
|
||||||
|
|
||||||
|
mEncryptFragment = EncryptFilesFragment.newInstance(uris, useArmor);
|
||||||
|
transaction.replace(R.id.encrypt_file_container, mEncryptFragment, "files");
|
||||||
|
|
||||||
|
transaction.commit();
|
||||||
|
|
||||||
|
getSupportFragmentManager().executePendingTransactions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onModeChanged(boolean symmetric) {
|
||||||
|
// switch fragments
|
||||||
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.replace(R.id.encrypt_mode_container,
|
||||||
|
symmetric
|
||||||
|
? EncryptSymmetricFragment.newInstance()
|
||||||
|
: EncryptAsymmetricFragment.newInstance(0, null)
|
||||||
|
)
|
||||||
|
.commitAllowingStateLoss();
|
||||||
|
getSupportFragmentManager().executePendingTransactions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSignatureKeyIdChanged(long signatureKeyId) {
|
||||||
|
mEncryptFragment.setSigningKeyId(signatureKeyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEncryptionKeyIdsChanged(long[] encryptionKeyIds) {
|
||||||
|
mEncryptFragment.setEncryptionKeyIds(encryptionKeyIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEncryptionUserIdsChanged(String[] encryptionUserIds) {
|
||||||
|
mEncryptFragment.setEncryptionUserIds(encryptionUserIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPassphraseChanged(Passphrase passphrase) {
|
||||||
|
mEncryptFragment.setPassphrase(passphrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,18 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -35,39 +39,108 @@ import android.widget.ImageView;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.PgpConstants;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
||||||
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
|
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
import org.sufficientlysecure.keychain.util.ShareHelper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class EncryptFilesFragment extends Fragment implements EncryptActivityInterface.UpdateListener {
|
public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||||
public static final String ARG_URIS = "uris";
|
|
||||||
|
|
||||||
private static final int REQUEST_CODE_INPUT = 0x00007003;
|
private static final int REQUEST_CODE_INPUT = 0x00007003;
|
||||||
private static final int REQUEST_CODE_OUTPUT = 0x00007007;
|
private static final int REQUEST_CODE_OUTPUT = 0x00007007;
|
||||||
|
|
||||||
private EncryptActivityInterface mEncryptInterface;
|
public interface IMode {
|
||||||
|
|
||||||
|
public void onModeChanged(boolean symmetric);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IMode mModeInterface;
|
||||||
|
|
||||||
|
// model used by fragments
|
||||||
|
private boolean mSymmetricMode = true;
|
||||||
|
private boolean mUseArmor = false;
|
||||||
|
private boolean mUseCompression = true;
|
||||||
|
private boolean mDeleteAfterEncrypt = false;
|
||||||
|
private boolean mShareAfterEncrypt = false;
|
||||||
|
private boolean mEncryptFilenames = true;
|
||||||
|
private boolean mHiddenRecipients = false;
|
||||||
|
|
||||||
|
private long mEncryptionKeyIds[] = null;
|
||||||
|
private String mEncryptionUserIds[] = null;
|
||||||
|
private long mSigningKeyId = Constants.key.none;
|
||||||
|
private Passphrase mPassphrase = new Passphrase();
|
||||||
|
|
||||||
|
private ArrayList<Uri> mInputUris = new ArrayList<Uri>();
|
||||||
|
private ArrayList<Uri> mOutputUris = new ArrayList<Uri>();
|
||||||
|
|
||||||
// view
|
|
||||||
private View mAddView;
|
|
||||||
private ListView mSelectedFiles;
|
private ListView mSelectedFiles;
|
||||||
private SelectedFilesAdapter mAdapter = new SelectedFilesAdapter();
|
private SelectedFilesAdapter mAdapter = new SelectedFilesAdapter();
|
||||||
private final Map<Uri, Bitmap> thumbnailCache = new HashMap<>();
|
private final Map<Uri, Bitmap> thumbnailCache = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
public static final String ARG_USE_ASCII_ARMOR = "use_ascii_armor";
|
||||||
|
public static final String ARG_URIS = "uris";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new instance of this fragment
|
||||||
|
*/
|
||||||
|
public static EncryptFilesFragment newInstance(ArrayList<Uri> uris, boolean useArmor) {
|
||||||
|
EncryptFilesFragment frag = new EncryptFilesFragment();
|
||||||
|
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putBoolean(ARG_USE_ASCII_ARMOR, useArmor);
|
||||||
|
args.putParcelableArrayList(ARG_URIS, uris);
|
||||||
|
frag.setArguments(args);
|
||||||
|
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEncryptionKeyIds(long[] encryptionKeyIds) {
|
||||||
|
mEncryptionKeyIds = encryptionKeyIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEncryptionUserIds(String[] encryptionUserIds) {
|
||||||
|
mEncryptionUserIds = encryptionUserIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSigningKeyId(long signingKeyId) {
|
||||||
|
mSigningKeyId = signingKeyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassphrase(Passphrase passphrase) {
|
||||||
|
mPassphrase = passphrase;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
try {
|
try {
|
||||||
mEncryptInterface = (EncryptActivityInterface) activity;
|
mModeInterface = (IMode) activity;
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
throw new ClassCastException(activity.toString() + " must implement EncryptActivityInterface");
|
throw new ClassCastException(activity.toString() + " must be IMode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,15 +151,15 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.encrypt_files_fragment, container, false);
|
View view = inflater.inflate(R.layout.encrypt_files_fragment, container, false);
|
||||||
|
|
||||||
mAddView = inflater.inflate(R.layout.file_list_entry_add, null);
|
View addView = inflater.inflate(R.layout.file_list_entry_add, null);
|
||||||
mAddView.setOnClickListener(new View.OnClickListener() {
|
addView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
addInputUri();
|
addInputUri();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mSelectedFiles = (ListView) view.findViewById(R.id.selected_files_list);
|
mSelectedFiles = (ListView) view.findViewById(R.id.selected_files_list);
|
||||||
mSelectedFiles.addFooterView(mAddView);
|
mSelectedFiles.addFooterView(addView);
|
||||||
mSelectedFiles.setAdapter(mAdapter);
|
mSelectedFiles.setAdapter(mAdapter);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
@ -95,16 +168,18 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
|
mInputUris = getArguments().getParcelableArrayList(ARG_URIS);
|
||||||
|
mUseArmor = getArguments().getBoolean(ARG_USE_ASCII_ARMOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addInputUri() {
|
private void addInputUri() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
FileHelper.openDocument(EncryptFilesFragment.this, "*/*", true, REQUEST_CODE_INPUT);
|
FileHelper.openDocument(EncryptFilesFragment.this, "*/*", true, REQUEST_CODE_INPUT);
|
||||||
} else {
|
} else {
|
||||||
FileHelper.openFile(EncryptFilesFragment.this, mEncryptInterface.getInputUris().isEmpty() ?
|
FileHelper.openFile(EncryptFilesFragment.this, mInputUris.isEmpty() ?
|
||||||
null : mEncryptInterface.getInputUris().get(mEncryptInterface.getInputUris().size() - 1),
|
null : mInputUris.get(mInputUris.size() - 1),
|
||||||
"*/*", REQUEST_CODE_INPUT);
|
"*/*", REQUEST_CODE_INPUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,32 +189,30 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mEncryptInterface.getInputUris().contains(inputUri)) {
|
if (mInputUris.contains(inputUri)) {
|
||||||
Notify.create(getActivity(),
|
Notify.create(getActivity(),
|
||||||
getActivity().getString(R.string.error_file_added_already, FileHelper.getFilename(getActivity(), inputUri)),
|
getActivity().getString(R.string.error_file_added_already, FileHelper.getFilename(getActivity(), inputUri)),
|
||||||
Notify.Style.ERROR).show(this);
|
Notify.Style.ERROR).show(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mEncryptInterface.getInputUris().add(inputUri);
|
mInputUris.add(inputUri);
|
||||||
mEncryptInterface.notifyUpdate();
|
|
||||||
mSelectedFiles.requestFocus();
|
mSelectedFiles.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void delInputUri(int position) {
|
private void delInputUri(int position) {
|
||||||
mEncryptInterface.getInputUris().remove(position);
|
mInputUris.remove(position);
|
||||||
mEncryptInterface.notifyUpdate();
|
|
||||||
mSelectedFiles.requestFocus();
|
mSelectedFiles.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showOutputFileDialog() {
|
private void showOutputFileDialog() {
|
||||||
if (mEncryptInterface.getInputUris().size() > 1 || mEncryptInterface.getInputUris().isEmpty()) {
|
if (mInputUris.size() > 1 || mInputUris.isEmpty()) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
Uri inputUri = mEncryptInterface.getInputUris().get(0);
|
Uri inputUri = mInputUris.get(0);
|
||||||
String targetName =
|
String targetName =
|
||||||
(mEncryptInterface.isEncryptFilenames() ? "1" : FileHelper.getFilename(getActivity(), inputUri))
|
(mEncryptFilenames ? "1" : FileHelper.getFilename(getActivity(), inputUri))
|
||||||
+ (mEncryptInterface.isUseArmor() ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN);
|
+ (mUseArmor ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN);
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||||
File file = new File(inputUri.getPath());
|
File file = new File(inputUri.getPath());
|
||||||
File parentDir = file.exists() ? file.getParentFile() : Constants.Path.APP_DIR;
|
File parentDir = file.exists() ? file.getParentFile() : Constants.Path.APP_DIR;
|
||||||
@ -152,23 +225,23 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void encryptClicked(boolean share) {
|
private void encryptClicked(boolean share) {
|
||||||
if (mEncryptInterface.getInputUris().isEmpty()) {
|
if (mInputUris.isEmpty()) {
|
||||||
Notify.create(getActivity(), R.string.error_no_file_selected, Notify.Style.ERROR).show(this);
|
Notify.create(getActivity(), R.string.error_no_file_selected, Notify.Style.ERROR).show(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (share) {
|
if (share) {
|
||||||
mEncryptInterface.getOutputUris().clear();
|
mOutputUris.clear();
|
||||||
int filenameCounter = 1;
|
int filenameCounter = 1;
|
||||||
for (Uri uri : mEncryptInterface.getInputUris()) {
|
for (Uri uri : mInputUris) {
|
||||||
String targetName =
|
String targetName =
|
||||||
(mEncryptInterface.isEncryptFilenames() ? String.valueOf(filenameCounter) : FileHelper.getFilename(getActivity(), uri))
|
(mEncryptFilenames ? String.valueOf(filenameCounter) : FileHelper.getFilename(getActivity(), uri))
|
||||||
+ (mEncryptInterface.isUseArmor() ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN);
|
+ (mUseArmor ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN);
|
||||||
mEncryptInterface.getOutputUris().add(TemporaryStorageProvider.createFile(getActivity(), targetName));
|
mOutputUris.add(TemporaryStorageProvider.createFile(getActivity(), targetName));
|
||||||
filenameCounter++;
|
filenameCounter++;
|
||||||
}
|
}
|
||||||
mEncryptInterface.startEncrypt(true);
|
startEncrypt(true);
|
||||||
} else {
|
} else {
|
||||||
if (mEncryptInterface.getInputUris().size() > 1) {
|
if (mInputUris.size() > 1) {
|
||||||
Notify.create(getActivity(), R.string.error_multi_not_supported, Notify.Style.ERROR).show(this);
|
Notify.create(getActivity(), R.string.error_multi_not_supported, Notify.Style.ERROR).show(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -188,8 +261,17 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
inflater.inflate(R.menu.encrypt_file_activity, menu);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.isCheckable()) {
|
||||||
|
item.setChecked(!item.isChecked());
|
||||||
|
}
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.encrypt_save: {
|
case R.id.encrypt_save: {
|
||||||
encryptClicked(false);
|
encryptClicked(false);
|
||||||
@ -199,6 +281,36 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
encryptClicked(true);
|
encryptClicked(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case R.id.check_use_symmetric: {
|
||||||
|
mSymmetricMode = item.isChecked();
|
||||||
|
mModeInterface.onModeChanged(mSymmetricMode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case R.id.check_use_armor: {
|
||||||
|
mUseArmor = item.isChecked();
|
||||||
|
// notifyUpdate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case R.id.check_delete_after_encrypt: {
|
||||||
|
mDeleteAfterEncrypt = item.isChecked();
|
||||||
|
// notifyUpdate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case R.id.check_enable_compression: {
|
||||||
|
mUseCompression = item.isChecked();
|
||||||
|
// onNotifyUpdate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case R.id.check_encrypt_filenames: {
|
||||||
|
mEncryptFilenames = item.isChecked();
|
||||||
|
// onNotifyUpdate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// case R.id.check_hidden_recipients: {
|
||||||
|
// mHiddenRecipients = item.isChecked();
|
||||||
|
// notifyUpdate();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
default: {
|
default: {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@ -206,6 +318,251 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean inputIsValid() {
|
||||||
|
// file checks
|
||||||
|
|
||||||
|
if (mInputUris.isEmpty()) {
|
||||||
|
Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR)
|
||||||
|
.show(this);
|
||||||
|
return false;
|
||||||
|
} else if (mInputUris.size() > 1 && !mShareAfterEncrypt) {
|
||||||
|
// This should be impossible...
|
||||||
|
return false;
|
||||||
|
} else if (mInputUris.size() != mOutputUris.size()) {
|
||||||
|
// This as well
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mSymmetricMode) {
|
||||||
|
// symmetric encryption checks
|
||||||
|
|
||||||
|
if (mPassphrase == null) {
|
||||||
|
Notify.create(getActivity(), R.string.passphrases_do_not_match, Notify.Style.ERROR)
|
||||||
|
.show(this);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (mPassphrase.isEmpty()) {
|
||||||
|
Notify.create(getActivity(), R.string.passphrase_must_not_be_empty, Notify.Style.ERROR)
|
||||||
|
.show(this);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// asymmetric encryption checks
|
||||||
|
|
||||||
|
boolean gotEncryptionKeys = (mEncryptionKeyIds != null
|
||||||
|
&& mEncryptionKeyIds.length > 0);
|
||||||
|
|
||||||
|
// Files must be encrypted, only text can be signed-only right now
|
||||||
|
if (!gotEncryptionKeys) {
|
||||||
|
Notify.create(getActivity(), R.string.select_encryption_key, Notify.Style.ERROR)
|
||||||
|
.show(this);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startEncrypt(boolean share) {
|
||||||
|
mShareAfterEncrypt = share;
|
||||||
|
startEncrypt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEncryptSuccess(final SignEncryptResult result) {
|
||||||
|
if (mDeleteAfterEncrypt) {
|
||||||
|
final Uri[] inputUris = mInputUris.toArray(new Uri[mInputUris.size()]);
|
||||||
|
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(inputUris);
|
||||||
|
deleteFileDialog.setOnDeletedListener(new DeleteFileDialogFragment.OnDeletedListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeleted() {
|
||||||
|
if (mShareAfterEncrypt) {
|
||||||
|
// Share encrypted message/file
|
||||||
|
startActivity(sendWithChooserExcludingEncrypt());
|
||||||
|
} else {
|
||||||
|
// Save encrypted file
|
||||||
|
result.createNotify(getActivity()).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
|
||||||
|
|
||||||
|
mInputUris.clear();
|
||||||
|
onNotifyUpdate();
|
||||||
|
} else {
|
||||||
|
if (mShareAfterEncrypt) {
|
||||||
|
// Share encrypted message/file
|
||||||
|
startActivity(sendWithChooserExcludingEncrypt());
|
||||||
|
} else {
|
||||||
|
// Save encrypted file
|
||||||
|
result.createNotify(getActivity()).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SignEncryptParcel createEncryptBundle() {
|
||||||
|
// fill values for this action
|
||||||
|
SignEncryptParcel data = new SignEncryptParcel();
|
||||||
|
|
||||||
|
data.addInputUris(mInputUris);
|
||||||
|
data.addOutputUris(mOutputUris);
|
||||||
|
|
||||||
|
if (mUseCompression) {
|
||||||
|
data.setCompressionId(PgpConstants.sPreferredCompressionAlgorithms.get(0));
|
||||||
|
} else {
|
||||||
|
data.setCompressionId(CompressionAlgorithmTags.UNCOMPRESSED);
|
||||||
|
}
|
||||||
|
data.setHiddenRecipients(mHiddenRecipients);
|
||||||
|
data.setEnableAsciiArmorOutput(mUseArmor);
|
||||||
|
data.setSymmetricEncryptionAlgorithm(PgpConstants.OpenKeychainSymmetricKeyAlgorithmTags.USE_PREFERRED);
|
||||||
|
data.setSignatureHashAlgorithm(PgpConstants.OpenKeychainSymmetricKeyAlgorithmTags.USE_PREFERRED);
|
||||||
|
|
||||||
|
if (mSymmetricMode) {
|
||||||
|
Log.d(Constants.TAG, "Symmetric encryption enabled!");
|
||||||
|
Passphrase passphrase = mPassphrase;
|
||||||
|
if (passphrase.isEmpty()) {
|
||||||
|
passphrase = null;
|
||||||
|
}
|
||||||
|
data.setSymmetricPassphrase(passphrase);
|
||||||
|
} else {
|
||||||
|
data.setEncryptionMasterKeyIds(mEncryptionKeyIds);
|
||||||
|
data.setSignatureMasterKeyId(mSigningKeyId);
|
||||||
|
// data.setSignaturePassphrase(mSigningKeyPassphrase);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Intent Chooser but exclude OK's EncryptActivity.
|
||||||
|
*/
|
||||||
|
private Intent sendWithChooserExcludingEncrypt() {
|
||||||
|
Intent prototype = createSendIntent();
|
||||||
|
String title = getString(R.string.title_share_file);
|
||||||
|
|
||||||
|
// we don't want to encrypt the encrypted, no inception ;)
|
||||||
|
String[] blacklist = new String[]{
|
||||||
|
Constants.PACKAGE_NAME + ".ui.EncryptFileActivity",
|
||||||
|
"org.thialfihar.android.apg.ui.EncryptActivity"
|
||||||
|
};
|
||||||
|
|
||||||
|
return new ShareHelper(getActivity()).createChooserExcluding(prototype, title, blacklist);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Intent createSendIntent() {
|
||||||
|
Intent sendIntent;
|
||||||
|
// file
|
||||||
|
if (mOutputUris.size() == 1) {
|
||||||
|
sendIntent = new Intent(Intent.ACTION_SEND);
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_STREAM, mOutputUris.get(0));
|
||||||
|
} else {
|
||||||
|
sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_STREAM, mOutputUris);
|
||||||
|
}
|
||||||
|
sendIntent.setType(Constants.ENCRYPTED_FILES_MIME);
|
||||||
|
|
||||||
|
if (!mSymmetricMode && mEncryptionUserIds != null) {
|
||||||
|
Set<String> users = new HashSet<>();
|
||||||
|
for (String user : mEncryptionUserIds) {
|
||||||
|
KeyRing.UserId userId = KeyRing.splitUserId(user);
|
||||||
|
if (userId.email != null) {
|
||||||
|
users.add(userId.email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_EMAIL, users.toArray(new String[users.size()]));
|
||||||
|
}
|
||||||
|
return sendIntent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startEncrypt() {
|
||||||
|
cryptoOperation(new CryptoInputParcel());
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void startEncrypt(CryptoInputParcel cryptoInput) {
|
||||||
|
@Override
|
||||||
|
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
|
||||||
|
|
||||||
|
if (!inputIsValid()) {
|
||||||
|
// Notify was created by inputIsValid.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send all information needed to service to edit key in other thread
|
||||||
|
Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
||||||
|
intent.setAction(KeychainIntentService.ACTION_SIGN_ENCRYPT);
|
||||||
|
|
||||||
|
final SignEncryptParcel input = createEncryptBundle();
|
||||||
|
if (cryptoInput != null) {
|
||||||
|
input.setCryptoInput(cryptoInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
data.putParcelable(KeychainIntentService.SIGN_ENCRYPT_PARCEL, input);
|
||||||
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
|
// Message is received after encrypting is done in KeychainIntentService
|
||||||
|
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(
|
||||||
|
getActivity(),
|
||||||
|
getString(R.string.progress_encrypting),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
true,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
|
public void handleMessage(Message message) {
|
||||||
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
|
super.handleMessage(message);
|
||||||
|
|
||||||
|
// handle pending messages
|
||||||
|
if (handlePendingMessage(message)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
||||||
|
SignEncryptResult result =
|
||||||
|
message.getData().getParcelable(SignEncryptResult.EXTRA_RESULT);
|
||||||
|
|
||||||
|
// PgpSignEncryptResult pgpResult = result.getPending();
|
||||||
|
//
|
||||||
|
// if (pgpResult != null && pgpResult.isPending()) {
|
||||||
|
// if ((pgpResult.getResult() & PgpSignEncryptResult.RESULT_PENDING_PASSPHRASE) ==
|
||||||
|
// PgpSignEncryptResult.RESULT_PENDING_PASSPHRASE) {
|
||||||
|
// startPassphraseDialog(pgpResult.getKeyIdPassphraseNeeded());
|
||||||
|
// } else if ((pgpResult.getResult() & PgpSignEncryptResult.RESULT_PENDING_NFC) ==
|
||||||
|
// PgpSignEncryptResult.RESULT_PENDING_NFC) {
|
||||||
|
//
|
||||||
|
// RequiredInputParcel parcel = RequiredInputParcel.createNfcSignOperation(
|
||||||
|
// pgpResult.getNfcHash(),
|
||||||
|
// pgpResult.getNfcAlgo(),
|
||||||
|
// input.getSignatureTime());
|
||||||
|
// startNfcSign(pgpResult.getNfcKeyId(), parcel);
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
// throw new RuntimeException("Unhandled pending result!");
|
||||||
|
// }
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (result.success()) {
|
||||||
|
onEncryptSuccess(result);
|
||||||
|
} else {
|
||||||
|
result.createNotify(getActivity()).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// no matter the result, reset parameters
|
||||||
|
// mSigningKeyPassphrase = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(serviceHandler);
|
||||||
|
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
|
// show progress dialog
|
||||||
|
serviceHandler.showProgressDialog(getActivity());
|
||||||
|
|
||||||
|
// start service with intent
|
||||||
|
getActivity().startService(intent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
@ -220,10 +577,10 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
case REQUEST_CODE_OUTPUT: {
|
case REQUEST_CODE_OUTPUT: {
|
||||||
// This happens after output file was selected, so start our operation
|
// This happens after output file was selected, so start our operation
|
||||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||||
mEncryptInterface.getOutputUris().clear();
|
mOutputUris.clear();
|
||||||
mEncryptInterface.getOutputUris().add(data.getData());
|
mOutputUris.add(data.getData());
|
||||||
mEncryptInterface.notifyUpdate();
|
onNotifyUpdate();
|
||||||
mEncryptInterface.startEncrypt(false);
|
startEncrypt(false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -236,11 +593,10 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNotifyUpdate() {
|
public void onNotifyUpdate() {
|
||||||
// Clear cache if needed
|
// Clear cache if needed
|
||||||
for (Uri uri : new HashSet<>(thumbnailCache.keySet())) {
|
for (Uri uri : new HashSet<>(thumbnailCache.keySet())) {
|
||||||
if (!mEncryptInterface.getInputUris().contains(uri)) {
|
if (!mInputUris.contains(uri)) {
|
||||||
thumbnailCache.remove(uri);
|
thumbnailCache.remove(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,12 +607,12 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
private class SelectedFilesAdapter extends BaseAdapter {
|
private class SelectedFilesAdapter extends BaseAdapter {
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return mEncryptInterface.getInputUris().size();
|
return mInputUris.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
return mEncryptInterface.getInputUris().get(position);
|
return mInputUris.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -266,7 +622,7 @@ public class EncryptFilesFragment extends Fragment implements EncryptActivityInt
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
Uri inputUri = mEncryptInterface.getInputUris().get(position);
|
Uri inputUri = mInputUris.get(position);
|
||||||
View view;
|
View view;
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
view = getActivity().getLayoutInflater().inflate(R.layout.file_list_entry, null);
|
view = getActivity().getLayoutInflater().inflate(R.layout.file_list_entry, null);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -30,20 +30,37 @@ import android.widget.EditText;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
|
||||||
public class EncryptSymmetricFragment extends Fragment implements EncryptActivityInterface.UpdateListener {
|
public class EncryptSymmetricFragment extends Fragment {
|
||||||
|
|
||||||
EncryptActivityInterface mEncryptInterface;
|
public interface ISymmetric {
|
||||||
|
|
||||||
|
public void onPassphraseChanged(Passphrase passphrase);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISymmetric mEncryptInterface;
|
||||||
|
|
||||||
private EditText mPassphrase;
|
private EditText mPassphrase;
|
||||||
private EditText mPassphraseAgain;
|
private EditText mPassphraseAgain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new instance of this fragment
|
||||||
|
*/
|
||||||
|
public static EncryptSymmetricFragment newInstance() {
|
||||||
|
EncryptSymmetricFragment frag = new EncryptSymmetricFragment();
|
||||||
|
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
frag.setArguments(args);
|
||||||
|
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
try {
|
try {
|
||||||
mEncryptInterface = (EncryptActivityInterface) activity;
|
mEncryptInterface = (ISymmetric) activity;
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
throw new ClassCastException(activity.toString() + " must implement EncryptActivityInterface");
|
throw new ClassCastException(activity.toString() + " must implement ISymmetric");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,9 +91,9 @@ public class EncryptSymmetricFragment extends Fragment implements EncryptActivit
|
|||||||
p1.removeFromMemory();
|
p1.removeFromMemory();
|
||||||
p2.removeFromMemory();
|
p2.removeFromMemory();
|
||||||
if (passesEquals) {
|
if (passesEquals) {
|
||||||
mEncryptInterface.setPassphrase(new Passphrase(mPassphrase.getText()));
|
mEncryptInterface.onPassphraseChanged(new Passphrase(mPassphrase.getText()));
|
||||||
} else {
|
} else {
|
||||||
mEncryptInterface.setPassphrase(null);
|
mEncryptInterface.onPassphraseChanged(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -86,8 +103,4 @@ public class EncryptSymmetricFragment extends Fragment implements EncryptActivit
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNotifyUpdate() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class EncryptTextActivity extends EncryptActivity implements EncryptActivityInterface {
|
public class EncryptTextActivity extends EncryptActivity {
|
||||||
|
|
||||||
/* Intents */
|
/* Intents */
|
||||||
public static final String ACTION_ENCRYPT_TEXT = OpenKeychainIntents.ENCRYPT_TEXT;
|
public static final String ACTION_ENCRYPT_TEXT = OpenKeychainIntents.ENCRYPT_TEXT;
|
||||||
@ -81,60 +80,38 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
|
|||||||
return MODE_SYMMETRIC == mCurrentMode;
|
return MODE_SYMMETRIC == mCurrentMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUseArmor() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEncryptFilenames() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUseCompression() {
|
public boolean isUseCompression() {
|
||||||
return mUseCompression;
|
return mUseCompression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isHiddenRecipients() {
|
public boolean isHiddenRecipients() {
|
||||||
return mHiddenRecipients;
|
return mHiddenRecipients;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getSignatureKey() {
|
public long getSignatureKey() {
|
||||||
return mSigningKeyId;
|
return mSigningKeyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long[] getEncryptionKeys() {
|
public long[] getEncryptionKeys() {
|
||||||
return mEncryptionKeyIds;
|
return mEncryptionKeyIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getEncryptionUsers() {
|
public String[] getEncryptionUsers() {
|
||||||
return mEncryptionUserIds;
|
return mEncryptionUserIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSignatureKey(long signatureKey) {
|
public void setSignatureKey(long signatureKey) {
|
||||||
mSigningKeyId = signatureKey;
|
mSigningKeyId = signatureKey;
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEncryptionKeys(long[] encryptionKeys) {
|
public void setEncryptionKeys(long[] encryptionKeys) {
|
||||||
mEncryptionKeyIds = encryptionKeys;
|
mEncryptionKeyIds = encryptionKeys;
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEncryptionUsers(String[] encryptionUsers) {
|
public void setEncryptionUsers(String[] encryptionUsers) {
|
||||||
mEncryptionUserIds = encryptionUsers;
|
mEncryptionUserIds = encryptionUsers;
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPassphrase(Passphrase passphrase) {
|
public void setPassphrase(Passphrase passphrase) {
|
||||||
if (mPassphrase != null) {
|
if (mPassphrase != null) {
|
||||||
mPassphrase.removeFromMemory();
|
mPassphrase.removeFromMemory();
|
||||||
@ -142,50 +119,32 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
|
|||||||
mPassphrase = passphrase;
|
mPassphrase = passphrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<Uri> getInputUris() {
|
public ArrayList<Uri> getInputUris() {
|
||||||
if (mInputUris == null) mInputUris = new ArrayList<>();
|
if (mInputUris == null) mInputUris = new ArrayList<>();
|
||||||
return mInputUris;
|
return mInputUris;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<Uri> getOutputUris() {
|
public ArrayList<Uri> getOutputUris() {
|
||||||
if (mOutputUris == null) mOutputUris = new ArrayList<>();
|
if (mOutputUris == null) mOutputUris = new ArrayList<>();
|
||||||
return mOutputUris;
|
return mOutputUris;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setInputUris(ArrayList<Uri> uris) {
|
public void setInputUris(ArrayList<Uri> uris) {
|
||||||
mInputUris = uris;
|
mInputUris = uris;
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOutputUris(ArrayList<Uri> uris) {
|
public void setOutputUris(ArrayList<Uri> uris) {
|
||||||
mOutputUris = uris;
|
mOutputUris = uris;
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return mMessage;
|
return mMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMessage(String message) {
|
public void setMessage(String message) {
|
||||||
mMessage = message;
|
mMessage = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notifyUpdate() {
|
|
||||||
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
|
|
||||||
if (fragment instanceof UpdateListener) {
|
|
||||||
((UpdateListener) fragment).onNotifyUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startEncrypt(boolean share) {
|
public void startEncrypt(boolean share) {
|
||||||
mShareAfterEncrypt = share;
|
mShareAfterEncrypt = share;
|
||||||
startEncrypt();
|
startEncrypt();
|
||||||
@ -348,7 +307,7 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
|
|||||||
|
|
||||||
private void updateModeFragment() {
|
private void updateModeFragment() {
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction()
|
||||||
.replace(R.id.encrypt_pager_mode,
|
.replace(R.id.encrypt_mode,
|
||||||
mCurrentMode == MODE_SYMMETRIC
|
mCurrentMode == MODE_SYMMETRIC
|
||||||
? new EncryptSymmetricFragment()
|
? new EncryptSymmetricFragment()
|
||||||
: new EncryptAsymmetricFragment()
|
: new EncryptAsymmetricFragment()
|
||||||
@ -366,12 +325,10 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
|
|||||||
case R.id.check_use_symmetric: {
|
case R.id.check_use_symmetric: {
|
||||||
mCurrentMode = item.isChecked() ? MODE_SYMMETRIC : MODE_ASYMMETRIC;
|
mCurrentMode = item.isChecked() ? MODE_SYMMETRIC : MODE_ASYMMETRIC;
|
||||||
updateModeFragment();
|
updateModeFragment();
|
||||||
notifyUpdate();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case R.id.check_enable_compression: {
|
case R.id.check_enable_compression: {
|
||||||
mUseCompression = item.isChecked();
|
mUseCompression = item.isChecked();
|
||||||
notifyUpdate();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// case R.id.check_hidden_recipients: {
|
// case R.id.check_hidden_recipients: {
|
||||||
|
@ -23,14 +23,12 @@
|
|||||||
<include layout="@layout/notify_area" />
|
<include layout="@layout/notify_area" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/encrypt_pager_mode"
|
android:id="@+id/encrypt_mode_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" />
|
||||||
android:orientation="vertical" />
|
|
||||||
|
|
||||||
<fragment
|
<FrameLayout
|
||||||
android:id="@+id/encrypt_file_fragment"
|
android:id="@+id/encrypt_file_container"
|
||||||
android:name="org.sufficientlysecure.keychain.ui.EncryptFilesFragment"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:paddingLeft="16dp"
|
|
||||||
android:paddingRight="16dp"
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
@ -12,6 +10,8 @@
|
|||||||
android:divider="@android:color/transparent"
|
android:divider="@android:color/transparent"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:focusableInTouchMode="true"
|
android:focusableInTouchMode="true"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<include layout="@layout/notify_area" />
|
<include layout="@layout/notify_area" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/encrypt_pager_mode"
|
android:id="@+id/encrypt_mode"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical" />
|
android:orientation="vertical" />
|
||||||
|
Loading…
Reference in New Issue
Block a user