use CryptoOperationFragment for linked id fragments, and some warning cleanup

This commit is contained in:
Vincent Breitmoser
2015-04-24 15:44:33 +02:00
parent b4aec3114d
commit b12aa63cb3
6 changed files with 38 additions and 80 deletions

View File

@@ -88,7 +88,9 @@ public class CertifyKeyFragment extends CryptoOperationFragment
}; };
private static final int INDEX_MASTER_KEY_ID = 1; private static final int INDEX_MASTER_KEY_ID = 1;
private static final int INDEX_USER_ID = 2; private static final int INDEX_USER_ID = 2;
@SuppressWarnings("unused")
private static final int INDEX_IS_PRIMARY = 3; private static final int INDEX_IS_PRIMARY = 3;
@SuppressWarnings("unused")
private static final int INDEX_IS_REVOKED = 4; private static final int INDEX_IS_REVOKED = 4;
private MultiUserIdsAdapter mUserIdsAdapter; private MultiUserIdsAdapter mUserIdsAdapter;

View File

@@ -312,10 +312,10 @@ public class ViewKeyActivity extends BaseNfcActivity implements
.replace(R.id.view_key_fragment, frag) .replace(R.id.view_key_fragment, frag)
.commit(); .commit();
manager.popBackStack(); manager.popBackStack();
} else { } /* else {
// not sure yet if we actually want this! // not sure yet if we actually want this!
// manager.popBackStack(); manager.popBackStack();
} } */
} }
}); });

View File

@@ -1,6 +1,5 @@
package org.sufficientlysecure.keychain.ui.linked; package org.sufficientlysecure.keychain.ui.linked;
import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
@@ -8,7 +7,6 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
@@ -28,14 +26,11 @@ import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
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.ui.PassphraseDialogActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment.ServiceType; import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment.ServiceType;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.util.Passphrase;
public abstract class LinkedIdCreateFinalFragment extends Fragment { public abstract class LinkedIdCreateFinalFragment extends CryptoOperationFragment {
protected static final int REQUEST_CODE_PASSPHRASE = 0x00007008;
protected LinkedIdWizard mLinkedIdWizard; protected LinkedIdWizard mLinkedIdWizard;
@@ -63,7 +58,7 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
startCertify(); cryptoOperation();
} }
}); });
@@ -174,29 +169,28 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
} }
private void startCertify() { protected void cryptoOperation(CryptoInputParcel cryptoInput) {
if (mVerifiedResource == null) { if (mVerifiedResource == null) {
Notify.create(getActivity(), R.string.linked_need_verify, Notify.Style.ERROR).show(); Notify.create(getActivity(), R.string.linked_need_verify, Notify.Style.ERROR).show();
return; return;
} }
Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class);
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mLinkedIdWizard.mMasterKeyId);
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
}
private void certifyLinkedIdentity (CryptoInputParcel cryptoInput) {
ServiceProgressHandler saveHandler = new ServiceProgressHandler( ServiceProgressHandler saveHandler = new ServiceProgressHandler(
getActivity(), getActivity(),
getString(R.string.progress_saving), getString(R.string.progress_saving),
ProgressDialog.STYLE_HORIZONTAL, ProgressDialog.STYLE_HORIZONTAL,
true, ServiceType.KEYCHAIN_INTENT) { true, ServiceType.KEYCHAIN_INTENT) {
public void handleMessage(Message message) { public void handleMessage(Message message) {
// handle messages by standard KeychainIntentServiceHandler first // handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message); super.handleMessage(message);
// handle pending messages
if (handlePendingMessage(message)) {
return;
}
if (message.arg1 == MessageStatus.OKAY.ordinal()) { if (message.arg1 == MessageStatus.OKAY.ordinal()) {
// get returned data bundle // get returned data bundle
@@ -252,20 +246,4 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment {
} }
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_PASSPHRASE:
if (resultCode == Activity.RESULT_OK && data != null) {
CryptoInputParcel cryptoInput =
data.getParcelableExtra(PassphraseDialogActivity.RESULT_CRYPTO_INPUT);
certifyLinkedIdentity(cryptoInput);
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
} }

View File

@@ -4,7 +4,6 @@ import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
@@ -16,7 +15,6 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentManager.OnBackStackChangedListener; import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager;
@@ -45,12 +43,11 @@ import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
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.ui.PassphraseDialogActivity;
import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter; import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter;
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
import org.sufficientlysecure.keychain.ui.linked.LinkedIdViewFragment.ViewHolder.VerifyState; import org.sufficientlysecure.keychain.ui.linked.LinkedIdViewFragment.ViewHolder.VerifyState;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
@@ -60,14 +57,11 @@ import org.sufficientlysecure.keychain.ui.util.SubtleAttentionSeeker;
import org.sufficientlysecure.keychain.ui.widget.CertListWidget; import org.sufficientlysecure.keychain.ui.widget.CertListWidget;
import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase;
public class LinkedIdViewFragment extends Fragment implements public class LinkedIdViewFragment extends CryptoOperationFragment implements
LoaderManager.LoaderCallbacks<Cursor>, OnBackStackChangedListener { LoaderManager.LoaderCallbacks<Cursor>, OnBackStackChangedListener {
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
private static final String ARG_DATA_URI = "data_uri"; private static final String ARG_DATA_URI = "data_uri";
private static final String ARG_LID_RANK = "rank"; private static final String ARG_LID_RANK = "rank";
private static final String ARG_IS_SECRET = "verified"; private static final String ARG_IS_SECRET = "verified";
@@ -512,44 +506,20 @@ public class LinkedIdViewFragment extends Fragment implements
return; return;
} }
Passphrase passphrase; cryptoOperation();
try {
passphrase = PassphraseCacheService.getCachedPassphrase(
getActivity(), mCertifyKeyId, mCertifyKeyId);
} catch (PassphraseCacheService.KeyNotFoundException e) {
Log.e(Constants.TAG, "Key not found!", e);
getActivity().finish();
return;
}
if (passphrase == null) {
Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class);
intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mCertifyKeyId);
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
// bail out; need to wait until the user has entered the passphrase before trying again
} else {
certifyResource(new CryptoInputParcel());
}
} }
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onCryptoOperationCancelled() {
switch (requestCode) { super.onCryptoOperationCancelled();
case REQUEST_CODE_PASSPHRASE: {
if (resultCode == Activity.RESULT_OK && data != null) { // go back to 'verified ok'
CryptoInputParcel cryptoInput = data.getParcelableExtra( setShowVerifying(false);
PassphraseDialogActivity.RESULT_CRYPTO_INPUT);
certifyResource(cryptoInput);
}
return;
}
default: {
super.onActivityResult(requestCode, resultCode, data);
}
}
} }
private void certifyResource(CryptoInputParcel cryptoInput) { @Override
protected void cryptoOperation(CryptoInputParcel cryptoInput) {
if (mIsSecret) { if (mIsSecret) {
return; return;
@@ -588,9 +558,13 @@ public class LinkedIdViewFragment extends Fragment implements
// handle messages by standard KeychainIntentServiceHandler first // handle messages by standard KeychainIntentServiceHandler first
super.handleMessage(message); super.handleMessage(message);
Bundle data = message.getData(); // handle pending messages
if (handlePendingMessage(message)) {
return;
}
if (message.arg1 == MessageStatus.OKAY.ordinal()) { if (message.arg1 == MessageStatus.OKAY.ordinal()) {
Bundle data = message.getData();
CertifyResult result = data.getParcelable(CertifyResult.EXTRA_RESULT); CertifyResult result = data.getParcelable(CertifyResult.EXTRA_RESULT);
result.createNotify(getActivity()).show(); result.createNotify(getActivity()).show();
// no need to do anything else, we will get a loader refresh! // no need to do anything else, we will get a loader refresh!

View File

@@ -1,7 +1,8 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"> android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -48,6 +49,8 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
card_view:cardBackgroundColor="@android:color/white" card_view:cardBackgroundColor="@android:color/white"
card_view:cardElevation="2dp" card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true" card_view:cardUseCompatPadding="true"
@@ -84,7 +87,7 @@
android:drawablePadding="3dp" android:drawablePadding="3dp"
android:clickable="true" android:clickable="true"
android:textColor="@color/tertiary_text_light" android:textColor="@color/tertiary_text_light"
android:text="%d more unknown identity types" android:text="@string/linked_ids_more_unknown"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingRight="8dp" android:paddingRight="8dp"
android:background="?android:selectableItemBackground" /> android:background="?android:selectableItemBackground" />

View File

@@ -1370,5 +1370,6 @@
<string name="linked_text_verifying">Verifying…</string> <string name="linked_text_verifying">Verifying…</string>
<string name="linked_text_error">Error</string> <string name="linked_text_error">Error</string>
<string name="linked_text_confirming">Confirming…</string> <string name="linked_text_confirming">Confirming…</string>
<string name="linked_ids_more_unknown">%d more unknown identity types</string>
</resources> </resources>