Do not use ImportKeysListFragment for Security Token import, fixes #1959. Also introduces radio button to import key information from file

This commit is contained in:
Dominik Schürmann
2016-12-04 22:58:41 +01:00
parent 553f90f145
commit dd69621408
3 changed files with 33 additions and 24 deletions

View File

@@ -27,6 +27,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.ProgressBar;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.TextView; import android.widget.TextView;
@@ -67,11 +68,11 @@ public class CreateSecurityTokenImportResetFragment
private byte[] mTokenAid; private byte[] mTokenAid;
private String mTokenUserId; private String mTokenUserId;
private String mTokenFingerprint; private String mTokenFingerprint;
private ImportKeysListFragment mListFragment;
private TextView vSerNo; private TextView vSerNo;
private TextView vUserId; private TextView vUserId;
private TextView mNextButton; private TextView mNextButton;
private RadioButton mRadioImport; private RadioButton mRadioImport;
private RadioButton mRadioFile;
private RadioButton mRadioReset; private RadioButton mRadioReset;
private View mResetWarning; private View mResetWarning;
@@ -116,6 +117,7 @@ public class CreateSecurityTokenImportResetFragment
vUserId = (TextView) view.findViewById(R.id.token_userid); vUserId = (TextView) view.findViewById(R.id.token_userid);
mNextButton = (TextView) view.findViewById(R.id.create_key_next_button); mNextButton = (TextView) view.findViewById(R.id.create_key_next_button);
mRadioImport = (RadioButton) view.findViewById(R.id.token_decision_import); mRadioImport = (RadioButton) view.findViewById(R.id.token_decision_import);
mRadioFile = (RadioButton) view.findViewById(R.id.token_decision_file);
mRadioReset = (RadioButton) view.findViewById(R.id.token_decision_reset); mRadioReset = (RadioButton) view.findViewById(R.id.token_decision_reset);
mResetWarning = view.findViewById(R.id.token_import_reset_warning); mResetWarning = view.findViewById(R.id.token_import_reset_warning);
@@ -137,15 +139,14 @@ public class CreateSecurityTokenImportResetFragment
public void onClick(View v) { public void onClick(View v) {
if (mRadioReset.isChecked()) { if (mRadioReset.isChecked()) {
resetCard(); resetCard();
} else { } else if (mRadioImport.isChecked()){
importKey(); importKey();
} else {
importFile();
} }
} }
}); });
mListFragment = ImportKeysListFragment.newInstance(null, null,
"0x" + mTokenFingerprint, true, null);
mRadioImport.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { mRadioImport.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@@ -154,13 +155,17 @@ public class CreateSecurityTokenImportResetFragment
mNextButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_key_plus_grey600_24dp, 0); mNextButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_key_plus_grey600_24dp, 0);
mNextButton.setVisibility(View.VISIBLE); mNextButton.setVisibility(View.VISIBLE);
mResetWarning.setVisibility(View.GONE); mResetWarning.setVisibility(View.GONE);
}
getFragmentManager().beginTransaction() }
.replace(R.id.security_token_import_fragment, mListFragment, "token_import") });
.commit(); mRadioFile.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
getFragmentManager().executePendingTransactions(); public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
refreshSearch(); if (isChecked) {
mNextButton.setText(R.string.key_list_fab_import);
mNextButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_folder_grey_24dp, 0);
mNextButton.setVisibility(View.VISIBLE);
mResetWarning.setVisibility(View.GONE);
} }
} }
}); });
@@ -172,10 +177,6 @@ public class CreateSecurityTokenImportResetFragment
mNextButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_close_grey_24dp, 0); mNextButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_close_grey_24dp, 0);
mNextButton.setVisibility(View.VISIBLE); mNextButton.setVisibility(View.VISIBLE);
mResetWarning.setVisibility(View.VISIBLE); mResetWarning.setVisibility(View.VISIBLE);
getFragmentManager().beginTransaction()
.remove(mListFragment)
.commit();
} }
} }
}); });
@@ -212,13 +213,7 @@ public class CreateSecurityTokenImportResetFragment
} }
} }
public void refreshSearch() {
mListFragment.loadState(new CloudLoaderState("0x" + mTokenFingerprint,
Preferences.getPreferences(getActivity()).getCloudSearchPrefs()));
}
public void importKey() { public void importKey() {
ArrayList<ParcelableKeyRing> keyList = new ArrayList<>(); ArrayList<ParcelableKeyRing> keyList = new ArrayList<>();
keyList.add(new ParcelableKeyRing(mTokenFingerprint, null, null, null)); keyList.add(new ParcelableKeyRing(mTokenFingerprint, null, null, null));
mKeyList = keyList; mKeyList = keyList;
@@ -228,7 +223,12 @@ public class CreateSecurityTokenImportResetFragment
super.setProgressMessageResource(R.string.progress_importing); super.setProgressMessageResource(R.string.progress_importing);
super.cryptoOperation(); super.cryptoOperation();
}
public void importFile() {
Intent intent = new Intent(getActivity(), ImportKeysActivity.class);
intent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE);
startActivity(intent);
} }
public void resetCard() { public void resetCard() {

View File

@@ -82,6 +82,13 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:text="@string/security_token_import_radio" /> android:text="@string/security_token_import_radio" />
<RadioButton
android:id="@+id/token_decision_file"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/security_token_file_radio" />
<RadioButton <RadioButton
android:id="@+id/token_decision_reset" android:id="@+id/token_decision_reset"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -117,6 +124,7 @@
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/android_red_dark" android:textColor="@color/android_red_dark"
android:visibility="gone" /> android:visibility="gone" />
</FrameLayout> </FrameLayout>
</RelativeLayout> </RelativeLayout>

View File

@@ -1576,9 +1576,10 @@
<string name="security_token_status_unbound">"Security Token matches, can be bound to key"</string> <string name="security_token_status_unbound">"Security Token matches, can be bound to key"</string>
<string name="security_token_status_partly">"Security Token matches, partly bound to key"</string> <string name="security_token_status_partly">"Security Token matches, partly bound to key"</string>
<string name="security_token_create">"Hold Security Token against the back of your device."</string> <string name="security_token_create">"Hold Security Token against the back of your device."</string>
<string name="security_token_reset_or_import">"This Security Token already contains a key. You can import the key using the cloud or reset the Security Token."</string> <string name="security_token_reset_or_import">"This Security Token already contains a key. To use it, we need additional key information. These information can be searched on a keyserver or imported from a file."</string>
<string name="btn_reset">"Reset"</string> <string name="btn_reset">"Reset"</string>
<string name="security_token_import_radio">"Import key"</string> <string name="security_token_import_radio">"Search key information on keyserver"</string>
<string name="security_token_file_radio">"Import key information from file"</string>
<string name="security_token_reset_radio">"Reset Security Token"</string> <string name="security_token_reset_radio">"Reset Security Token"</string>
<string name="security_token_reset_warning">"Resetting the Security Token completely destroys the keys on it. Afterwards, you will not be able to decrypt messages/files encrypted with this key!"</string> <string name="security_token_reset_warning">"Resetting the Security Token completely destroys the keys on it. Afterwards, you will not be able to decrypt messages/files encrypted with this key!"</string>
<string name="snack_security_token_other">Different key stored on Security Token!</string> <string name="snack_security_token_other">Different key stored on Security Token!</string>