Fixing crashes with new encrypt ui
This commit is contained in:
@@ -1,11 +1,27 @@
|
|||||||
package org.sufficientlysecure.keychain.operations.results;
|
/*
|
||||||
|
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
* Copyright (C) 2015 Vincent Breitmoser <v.breitmoser@mugenguild.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.sufficientlysecure.keychain.operations.results;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
|
|
||||||
|
|
||||||
public class InputPendingResult extends OperationResult {
|
public class InputPendingResult extends OperationResult {
|
||||||
|
|
||||||
// the fourth bit indicates a "data pending" result! (it's also a form of non-success)
|
// the fourth bit indicates a "data pending" result! (it's also a form of non-success)
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
package org.sufficientlysecure.keychain.ui;
|
/*
|
||||||
|
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
* Copyright (C) 2015 Vincent Breitmoser <v.breitmoser@mugenguild.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -7,14 +24,15 @@ import android.os.Bundle;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.operations.results.CertifyResult;
|
|
||||||
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
|
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All fragments executing crypto operations need to extend this class.
|
||||||
|
*/
|
||||||
public abstract class CryptoOperationFragment extends Fragment {
|
public abstract class CryptoOperationFragment extends Fragment {
|
||||||
|
|
||||||
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
|
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
|
||||||
@@ -40,7 +58,6 @@ public abstract class CryptoOperationFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException("Unhandled pending result!");
|
throw new RuntimeException("Unhandled pending result!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,8 +94,8 @@ public abstract class CryptoOperationFragment extends Fragment {
|
|||||||
if (message.arg1 == ServiceProgressHandler.MessageStatus.OKAY.ordinal()) {
|
if (message.arg1 == ServiceProgressHandler.MessageStatus.OKAY.ordinal()) {
|
||||||
Bundle data = message.getData();
|
Bundle data = message.getData();
|
||||||
|
|
||||||
OperationResult result = data.getParcelable(CertifyResult.EXTRA_RESULT);
|
OperationResult result = data.getParcelable(OperationResult.EXTRA_RESULT);
|
||||||
if (result == null || ! (result instanceof InputPendingResult)) {
|
if (result == null || !(result instanceof InputPendingResult)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
|||||||
|
|
||||||
private IMode mModeInterface;
|
private IMode mModeInterface;
|
||||||
|
|
||||||
private boolean mSymmetricMode = true;
|
private boolean mSymmetricMode = false;
|
||||||
private boolean mUseArmor = false;
|
private boolean mUseArmor = false;
|
||||||
private boolean mUseCompression = true;
|
private boolean mUseCompression = true;
|
||||||
private boolean mDeleteAfterEncrypt = false;
|
private boolean mDeleteAfterEncrypt = false;
|
||||||
@@ -188,7 +188,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
|||||||
if (mInputUris.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();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
|||||||
|
|
||||||
private void encryptClicked(boolean share) {
|
private void encryptClicked(boolean share) {
|
||||||
if (mInputUris.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();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (share) {
|
if (share) {
|
||||||
@@ -238,7 +238,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
|||||||
startEncrypt(true);
|
startEncrypt(true);
|
||||||
} else {
|
} else {
|
||||||
if (mInputUris.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();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showOutputFileDialog();
|
showOutputFileDialog();
|
||||||
@@ -260,7 +260,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
inflater.inflate(R.menu.encrypt_file_activity, menu);
|
inflater.inflate(R.menu.encrypt_file_fragment, menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -319,12 +319,14 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
|||||||
|
|
||||||
if (mInputUris.isEmpty()) {
|
if (mInputUris.isEmpty()) {
|
||||||
Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR)
|
Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR)
|
||||||
.show(this);
|
.show();
|
||||||
return false;
|
return false;
|
||||||
} else if (mInputUris.size() > 1 && !mShareAfterEncrypt) {
|
} else if (mInputUris.size() > 1 && !mShareAfterEncrypt) {
|
||||||
|
Log.e(Constants.TAG, "Aborting: mInputUris.size() > 1 && !mShareAfterEncrypt");
|
||||||
// This should be impossible...
|
// This should be impossible...
|
||||||
return false;
|
return false;
|
||||||
} else if (mInputUris.size() != mOutputUris.size()) {
|
} else if (mInputUris.size() != mOutputUris.size()) {
|
||||||
|
Log.e(Constants.TAG, "Aborting: mInputUris.size() != mOutputUris.size()");
|
||||||
// This as well
|
// This as well
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -334,12 +336,12 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
|||||||
|
|
||||||
if (mPassphrase == null) {
|
if (mPassphrase == null) {
|
||||||
Notify.create(getActivity(), R.string.passphrases_do_not_match, Notify.Style.ERROR)
|
Notify.create(getActivity(), R.string.passphrases_do_not_match, Notify.Style.ERROR)
|
||||||
.show(this);
|
.show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mPassphrase.isEmpty()) {
|
if (mPassphrase.isEmpty()) {
|
||||||
Notify.create(getActivity(), R.string.passphrase_must_not_be_empty, Notify.Style.ERROR)
|
Notify.create(getActivity(), R.string.passphrase_must_not_be_empty, Notify.Style.ERROR)
|
||||||
.show(this);
|
.show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,7 +354,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
|||||||
// Files must be encrypted, only text can be signed-only right now
|
// Files must be encrypted, only text can be signed-only right now
|
||||||
if (!gotEncryptionKeys) {
|
if (!gotEncryptionKeys) {
|
||||||
Notify.create(getActivity(), R.string.select_encryption_key, Notify.Style.ERROR)
|
Notify.create(getActivity(), R.string.select_encryption_key, Notify.Style.ERROR)
|
||||||
.show(this);
|
.show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -361,7 +363,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
|||||||
|
|
||||||
public void startEncrypt(boolean share) {
|
public void startEncrypt(boolean share) {
|
||||||
mShareAfterEncrypt = share;
|
mShareAfterEncrypt = share;
|
||||||
startEncrypt();
|
cryptoOperation(new CryptoInputParcel());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEncryptSuccess(final SignEncryptResult result) {
|
public void onEncryptSuccess(final SignEncryptResult result) {
|
||||||
@@ -470,18 +472,15 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
|||||||
return sendIntent;
|
return sendIntent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startEncrypt() {
|
|
||||||
cryptoOperation(new CryptoInputParcel());
|
|
||||||
}
|
|
||||||
|
|
||||||
// public void startEncrypt(CryptoInputParcel cryptoInput) {
|
|
||||||
@Override
|
@Override
|
||||||
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
|
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
|
||||||
|
|
||||||
if (!inputIsValid()) {
|
if (!inputIsValid()) {
|
||||||
// Notify was created by inputIsValid.
|
// Notify was created by inputIsValid.
|
||||||
|
Log.d(Constants.TAG, "Input not valid!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Log.d(Constants.TAG, "Input valid!");
|
||||||
|
|
||||||
// Send all information needed to service to edit key in other thread
|
// Send all information needed to service to edit key in other thread
|
||||||
Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class EncryptTextFragment extends CryptoOperationFragment {
|
|||||||
|
|
||||||
private IMode mModeInterface;
|
private IMode mModeInterface;
|
||||||
|
|
||||||
private boolean mSymmetricMode = true;
|
private boolean mSymmetricMode = false;
|
||||||
private boolean mShareAfterEncrypt = false;
|
private boolean mShareAfterEncrypt = false;
|
||||||
private boolean mUseCompression = true;
|
private boolean mUseCompression = true;
|
||||||
private boolean mHiddenRecipients = false;
|
private boolean mHiddenRecipients = false;
|
||||||
@@ -159,7 +159,7 @@ public class EncryptTextFragment extends CryptoOperationFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
inflater.inflate(R.menu.encrypt_text_activity, menu);
|
inflater.inflate(R.menu.encrypt_text_fragment, menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -289,7 +289,7 @@ public class EncryptTextFragment extends CryptoOperationFragment {
|
|||||||
protected boolean inputIsValid() {
|
protected boolean inputIsValid() {
|
||||||
if (mMessage == null) {
|
if (mMessage == null) {
|
||||||
Notify.create(getActivity(), R.string.error_message, Notify.Style.ERROR)
|
Notify.create(getActivity(), R.string.error_message, Notify.Style.ERROR)
|
||||||
.show(this);
|
.show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,12 +298,12 @@ public class EncryptTextFragment extends CryptoOperationFragment {
|
|||||||
|
|
||||||
if (mPassphrase == null) {
|
if (mPassphrase == null) {
|
||||||
Notify.create(getActivity(), R.string.passphrases_do_not_match, Notify.Style.ERROR)
|
Notify.create(getActivity(), R.string.passphrases_do_not_match, Notify.Style.ERROR)
|
||||||
.show(this);
|
.show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mPassphrase.isEmpty()) {
|
if (mPassphrase.isEmpty()) {
|
||||||
Notify.create(getActivity(), R.string.passphrase_must_not_be_empty, Notify.Style.ERROR)
|
Notify.create(getActivity(), R.string.passphrase_must_not_be_empty, Notify.Style.ERROR)
|
||||||
.show(this);
|
.show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ public class EncryptTextFragment extends CryptoOperationFragment {
|
|||||||
|
|
||||||
if (!gotEncryptionKeys && mSigningKeyId == 0) {
|
if (!gotEncryptionKeys && mSigningKeyId == 0) {
|
||||||
Notify.create(getActivity(), R.string.select_encryption_or_signature_key, Notify.Style.ERROR)
|
Notify.create(getActivity(), R.string.select_encryption_or_signature_key, Notify.Style.ERROR)
|
||||||
.show(this);
|
.show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -348,7 +348,7 @@ public class EncryptTextFragment extends CryptoOperationFragment {
|
|||||||
input.setCryptoInput(cryptoInput);
|
input.setCryptoInput(cryptoInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bundle data = new Bundle();
|
final Bundle data = new Bundle();
|
||||||
data.putParcelable(KeychainIntentService.SIGN_ENCRYPT_PARCEL, input);
|
data.putParcelable(KeychainIntentService.SIGN_ENCRYPT_PARCEL, input);
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
@@ -362,10 +362,11 @@ public class EncryptTextFragment extends CryptoOperationFragment {
|
|||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
|
||||||
// handle pending messages
|
// TODO: We need a InputPendingResult!
|
||||||
if (handlePendingMessage(message)) {
|
// // handle pending messages
|
||||||
return;
|
// if (handlePendingMessage(message)) {
|
||||||
}
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
||||||
SignEncryptResult result =
|
SignEncryptResult result =
|
||||||
|
|||||||
@@ -191,9 +191,6 @@ public class NfcHelper {
|
|||||||
mNfcAdapter.invokeBeam(mActivity);
|
mNfcAdapter.invokeBeam(mActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A static subclass of {@link Handler} with a {@link WeakReference} to an {@link Activity} to avoid memory leaks.
|
|
||||||
*/
|
|
||||||
private static class NfcHandler extends Handler {
|
private static class NfcHandler extends Handler {
|
||||||
private final WeakReference<Activity> mActivityReference;
|
private final WeakReference<Activity> mActivityReference;
|
||||||
|
|
||||||
@@ -203,12 +200,10 @@ public class NfcHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
Activity activity = mActivityReference.get();
|
if (mActivityReference.get() != null) {
|
||||||
|
|
||||||
if (activity != null) {
|
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case NFC_SENT:
|
case NFC_SENT:
|
||||||
Notify.create(activity, R.string.nfc_successful, Notify.Style.OK).show();
|
Notify.create(mActivityReference.get(), R.string.nfc_successful, Notify.Style.OK).show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,7 @@
|
|||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/encrypt_mode_container"
|
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" />
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/encrypt_text_container"
|
android:id="@+id/encrypt_text_container"
|
||||||
|
|||||||
Reference in New Issue
Block a user