mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Merge pull request #11694 from nextcloud/rememberMnemonic
Remember mnemonic on device rotation
This commit is contained in:
commit
2996cfbe4f
4 changed files with 25 additions and 8 deletions
|
@ -42,7 +42,7 @@ class SetupEncryptionDialogFragmentIT : AbstractIT() {
|
|||
|
||||
sut.show(activity.supportFragmentManager, "1")
|
||||
|
||||
val keyWords = listOf(
|
||||
val keyWords = arrayListOf(
|
||||
"ability",
|
||||
"able",
|
||||
"about",
|
||||
|
|
|
@ -192,6 +192,7 @@
|
|||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".ui.activity.SetupEncryptionActivity"
|
||||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
|
||||
android:theme="@style/Theme.NoBackground"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
|
|
|
@ -52,8 +52,8 @@ import com.owncloud.android.utils.theme.ViewThemeUtils;
|
|||
import java.io.IOException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.PrivateKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -64,6 +64,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import static com.owncloud.android.utils.EncryptionUtils.MNEMONIC;
|
||||
import static com.owncloud.android.utils.EncryptionUtils.decodeStringToBase64Bytes;
|
||||
import static com.owncloud.android.utils.EncryptionUtils.decryptStringAsymmetric;
|
||||
import static com.owncloud.android.utils.EncryptionUtils.encodeBytesToBase64String;
|
||||
|
@ -99,7 +100,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
|
|||
private Button neutralButton;
|
||||
private DownloadKeysAsyncTask task;
|
||||
private String keyResult;
|
||||
private List<String> keyWords;
|
||||
private ArrayList<String> keyWords;
|
||||
private SetupEncryptionDialogBinding binding;
|
||||
|
||||
/**
|
||||
|
@ -135,12 +136,19 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
|
|||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
if (getArguments() == null) {
|
||||
throw new IllegalStateException("Arguments may not be null");
|
||||
}
|
||||
user = getArguments().getParcelable(ARG_USER);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
keyWords = savedInstanceState.getStringArrayList(MNEMONIC);
|
||||
}
|
||||
|
||||
arbitraryDataProvider = new ArbitraryDataProviderImpl(getContext());
|
||||
|
||||
// Inflate the layout for the dialog
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
||||
binding = SetupEncryptionDialogBinding.inflate(inflater, null, false);
|
||||
|
||||
// Setup layout
|
||||
|
@ -278,6 +286,12 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
|
|||
getParentFragmentManager().setFragmentResult(RESULT_REQUEST_KEY, bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
outState.putStringArrayList(MNEMONIC, keyWords);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
public class DownloadKeysAsyncTask extends AsyncTask<Void, Void, String> {
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
|
@ -328,7 +342,9 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
|
|||
if (privateKey == null) {
|
||||
// first show info
|
||||
try {
|
||||
keyWords = EncryptionUtils.getRandomWords(12, requireContext());
|
||||
if (keyWords == null || keyWords.isEmpty()) {
|
||||
keyWords = EncryptionUtils.getRandomWords(12, requireContext());
|
||||
}
|
||||
showMnemonicInfo();
|
||||
} catch (IOException e) {
|
||||
binding.encryptionStatus.setText(R.string.common_error);
|
||||
|
@ -478,7 +494,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void setMnemonic(List<String> keyWords) {
|
||||
public void setMnemonic(ArrayList<String> keyWords) {
|
||||
this.keyWords = keyWords;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -893,7 +893,7 @@ public final class EncryptionUtils {
|
|||
Helper
|
||||
*/
|
||||
|
||||
public static List<String> getRandomWords(int count, Context context) throws IOException {
|
||||
public static ArrayList<String> getRandomWords(int count, Context context) throws IOException {
|
||||
InputStream ins = context.getResources().openRawResource(R.raw.encryption_key_words);
|
||||
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(ins);
|
||||
|
@ -908,7 +908,7 @@ public final class EncryptionUtils {
|
|||
|
||||
SecureRandom random = new SecureRandom();
|
||||
|
||||
List<String> outputLines = Lists.newArrayListWithCapacity(count);
|
||||
ArrayList<String> outputLines = Lists.newArrayListWithCapacity(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
int randomLine = random.nextInt(lines.size());
|
||||
outputLines.add(lines.get(randomLine));
|
||||
|
|
Loading…
Reference in a new issue