Fixing crashes with new encrypt ui

This commit is contained in:
Dominik Schürmann 2015-03-29 20:37:54 +02:00
parent b82f273284
commit 95f1527afe
8 changed files with 70 additions and 43 deletions

View file

@ -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 org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
public class InputPendingResult extends OperationResult {
// the fourth bit indicates a "data pending" result! (it's also a form of non-success)

View file

@ -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.content.Intent;
@ -7,14 +24,15 @@ import android.os.Bundle;
import android.os.Message;
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.OperationResult;
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
/**
* All fragments executing crypto operations need to extend this class.
*/
public abstract class CryptoOperationFragment extends Fragment {
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
@ -40,7 +58,6 @@ public abstract class CryptoOperationFragment extends Fragment {
}
throw new RuntimeException("Unhandled pending result!");
}
@Override
@ -77,8 +94,8 @@ public abstract class CryptoOperationFragment extends Fragment {
if (message.arg1 == ServiceProgressHandler.MessageStatus.OKAY.ordinal()) {
Bundle data = message.getData();
OperationResult result = data.getParcelable(CertifyResult.EXTRA_RESULT);
if (result == null || ! (result instanceof InputPendingResult)) {
OperationResult result = data.getParcelable(OperationResult.EXTRA_RESULT);
if (result == null || !(result instanceof InputPendingResult)) {
return false;
}

View file

@ -80,7 +80,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
private IMode mModeInterface;
private boolean mSymmetricMode = true;
private boolean mSymmetricMode = false;
private boolean mUseArmor = false;
private boolean mUseCompression = true;
private boolean mDeleteAfterEncrypt = false;
@ -188,7 +188,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
if (mInputUris.contains(inputUri)) {
Notify.create(getActivity(),
getActivity().getString(R.string.error_file_added_already, FileHelper.getFilename(getActivity(), inputUri)),
Notify.Style.ERROR).show(this);
Notify.Style.ERROR).show();
return;
}
@ -222,7 +222,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
private void encryptClicked(boolean share) {
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;
}
if (share) {
@ -238,7 +238,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
startEncrypt(true);
} else {
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;
}
showOutputFileDialog();
@ -260,7 +260,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.encrypt_file_activity, menu);
inflater.inflate(R.menu.encrypt_file_fragment, menu);
}
@Override
@ -319,12 +319,14 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
if (mInputUris.isEmpty()) {
Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR)
.show(this);
.show();
return false;
} else if (mInputUris.size() > 1 && !mShareAfterEncrypt) {
Log.e(Constants.TAG, "Aborting: mInputUris.size() > 1 && !mShareAfterEncrypt");
// This should be impossible...
return false;
} else if (mInputUris.size() != mOutputUris.size()) {
Log.e(Constants.TAG, "Aborting: mInputUris.size() != mOutputUris.size()");
// This as well
return false;
}
@ -334,12 +336,12 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
if (mPassphrase == null) {
Notify.create(getActivity(), R.string.passphrases_do_not_match, Notify.Style.ERROR)
.show(this);
.show();
return false;
}
if (mPassphrase.isEmpty()) {
Notify.create(getActivity(), R.string.passphrase_must_not_be_empty, Notify.Style.ERROR)
.show(this);
.show();
return false;
}
@ -352,7 +354,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
// 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);
.show();
return false;
}
}
@ -361,7 +363,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
public void startEncrypt(boolean share) {
mShareAfterEncrypt = share;
startEncrypt();
cryptoOperation(new CryptoInputParcel());
}
public void onEncryptSuccess(final SignEncryptResult result) {
@ -470,18 +472,15 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
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.
Log.d(Constants.TAG, "Input not valid!");
return;
}
Log.d(Constants.TAG, "Input valid!");
// Send all information needed to service to edit key in other thread
Intent intent = new Intent(getActivity(), KeychainIntentService.class);

View file

@ -64,7 +64,7 @@ public class EncryptTextFragment extends CryptoOperationFragment {
private IMode mModeInterface;
private boolean mSymmetricMode = true;
private boolean mSymmetricMode = false;
private boolean mShareAfterEncrypt = false;
private boolean mUseCompression = true;
private boolean mHiddenRecipients = false;
@ -159,7 +159,7 @@ public class EncryptTextFragment extends CryptoOperationFragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.encrypt_text_activity, menu);
inflater.inflate(R.menu.encrypt_text_fragment, menu);
}
@Override
@ -289,7 +289,7 @@ public class EncryptTextFragment extends CryptoOperationFragment {
protected boolean inputIsValid() {
if (mMessage == null) {
Notify.create(getActivity(), R.string.error_message, Notify.Style.ERROR)
.show(this);
.show();
return false;
}
@ -298,12 +298,12 @@ public class EncryptTextFragment extends CryptoOperationFragment {
if (mPassphrase == null) {
Notify.create(getActivity(), R.string.passphrases_do_not_match, Notify.Style.ERROR)
.show(this);
.show();
return false;
}
if (mPassphrase.isEmpty()) {
Notify.create(getActivity(), R.string.passphrase_must_not_be_empty, Notify.Style.ERROR)
.show(this);
.show();
return false;
}
@ -315,7 +315,7 @@ public class EncryptTextFragment extends CryptoOperationFragment {
if (!gotEncryptionKeys && mSigningKeyId == 0) {
Notify.create(getActivity(), R.string.select_encryption_or_signature_key, Notify.Style.ERROR)
.show(this);
.show();
return false;
}
}
@ -348,7 +348,7 @@ public class EncryptTextFragment extends CryptoOperationFragment {
input.setCryptoInput(cryptoInput);
}
Bundle data = new Bundle();
final Bundle data = new Bundle();
data.putParcelable(KeychainIntentService.SIGN_ENCRYPT_PARCEL, input);
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
@ -362,10 +362,11 @@ public class EncryptTextFragment extends CryptoOperationFragment {
// handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message);
// handle pending messages
if (handlePendingMessage(message)) {
return;
}
// TODO: We need a InputPendingResult!
// // handle pending messages
// if (handlePendingMessage(message)) {
// return;
// }
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
SignEncryptResult result =

View file

@ -191,9 +191,6 @@ public class NfcHelper {
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 final WeakReference<Activity> mActivityReference;
@ -203,12 +200,10 @@ public class NfcHelper {
@Override
public void handleMessage(Message msg) {
Activity activity = mActivityReference.get();
if (activity != null) {
if (mActivityReference.get() != null) {
switch (msg.what) {
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;
}
}

View file

@ -25,8 +25,7 @@
<FrameLayout
android:id="@+id/encrypt_mode_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/encrypt_text_container"