Skip to content

Commit

Permalink
Merge pull request nextcloud#7001 from nextcloud/mnemonic
Browse files Browse the repository at this point in the history
enhance mnemonic on dark mode
Signed-off-by: thelittlefireman <thelittlefireman@users.noreply.github.com>
  • Loading branch information
tobiasKaminsky authored Sep 25, 2020
2 parents e1861a7 + c670a54 commit a461ff3
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 35 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/androidTest/java/com/owncloud/android/AbstractIT.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.owncloud.android;

import android.Manifest;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
Expand Down Expand Up @@ -41,6 +42,7 @@

import org.apache.commons.io.FileUtils;
import org.junit.BeforeClass;
import org.junit.Rule;

import java.io.File;
import java.io.FileWriter;
Expand All @@ -52,6 +54,7 @@
import androidx.test.espresso.contrib.DrawerActions;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.GrantPermissionRule;
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
import androidx.test.runner.lifecycle.Stage;

Expand All @@ -67,7 +70,9 @@
*/

public abstract class AbstractIT {
//@Rule public RetryTestRule retryTestRule = new RetryTestRule();
@Rule
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE);

protected static OwnCloudClient client;
protected static Account account;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2020 Tobias Kaminsky
* Copyright (C) 2020 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui.dialog

import android.view.Window
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
import com.nextcloud.client.TestActivity
import com.owncloud.android.AbstractIT
import com.owncloud.android.utils.ScreenshotTest
import org.junit.Rule
import org.junit.Test
import java.util.Objects

class SetupEncryptionDialogFragmentIT : AbstractIT() {
@get:Rule
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)

@Test
@ScreenshotTest
fun showMnemonic() {
val activity = testActivityRule.launchActivity(null)

val sut = SetupEncryptionDialogFragment.newInstance(user, 0)

sut.show(activity.supportFragmentManager, "1")

val keyWords = listOf(
"ability",
"able",
"about",
"above",
"absent",
"absorb",
"abstract",
"absurd",
"abuse",
"access",
"accident",
"account",
"accuse"
)

sut.setMnemonic(keyWords)

UiThreadStatement.runOnUiThread {
sut.showMnemonicInfo()
}

waitForIdleSync()

screenshot(Objects.requireNonNull<Window>(sut.requireDialog().window).decorView)
}

@Test
@ScreenshotTest
fun error() {
val activity = testActivityRule.launchActivity(null)

val sut = SetupEncryptionDialogFragment.newInstance(user, 0)

sut.show(activity.supportFragmentManager, "1")

UiThreadStatement.runOnUiThread {
sut.errorSavingKeys()
}

waitForIdleSync()

screenshot(Objects.requireNonNull<Window>(sut.requireDialog().window).decorView)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

package com.owncloud.android.ui.dialog;

import android.Manifest;

import com.owncloud.android.AbstractIT;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.FileDisplayActivity;
Expand All @@ -34,7 +32,6 @@
import java.util.Objects;

import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.rule.GrantPermissionRule;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

Expand All @@ -43,11 +40,6 @@ public class SyncFileNotEnoughSpaceDialogFragmentTest extends AbstractIT {
true,
false);

@Rule
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE);


@Test
public void showNotEnoughSpaceDialogForFolder() {
FileDisplayActivity test = activityRule.launchActivity(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.Locale;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.DialogFragment;
Expand Down Expand Up @@ -284,21 +285,8 @@ protected void onPostExecute(String privateKey) {
if (privateKey == null) {
// first show info
try {
keyWords = EncryptionUtils.getRandomWords(12, getContext());

getDialog().setTitle(R.string.end_to_end_encryption_passphrase_title);

textView.setText(R.string.end_to_end_encryption_keywords_description);

passphraseTextView.setText(generateMnemonicString(true));

passphraseTextView.setVisibility(View.VISIBLE);
positiveButton.setText(R.string.end_to_end_encryption_confirm_button);
positiveButton.setVisibility(View.VISIBLE);

negativeButton.setVisibility(View.VISIBLE);

keyResult = KEY_GENERATE;
keyWords = EncryptionUtils.getRandomWords(12, requireContext());
showMnemonicInfo();
} catch (IOException e) {
textView.setText(R.string.common_error);
}
Expand Down Expand Up @@ -386,20 +374,15 @@ protected void onPostExecute(String s) {
super.onPostExecute(s);

if (s.isEmpty()) {
keyResult = KEY_FAILED;

getDialog().setTitle(R.string.common_error);
textView.setText(R.string.end_to_end_encryption_unsuccessful);
positiveButton.setText(R.string.end_to_end_encryption_dialog_close);
positiveButton.setVisibility(View.VISIBLE);
errorSavingKeys();
} else {
getDialog().dismiss();
requireDialog().dismiss();

Intent intentExisting = new Intent();
intentExisting.putExtra(SUCCESS, true);
intentExisting.putExtra(ARG_POSITION, getArguments().getInt(ARG_POSITION));
intentExisting.putExtra(ARG_POSITION, requireArguments().getInt(ARG_POSITION));
getTargetFragment().onActivityResult(getTargetRequestCode(),
SETUP_ENCRYPTION_RESULT_CODE, intentExisting);
SETUP_ENCRYPTION_RESULT_CODE, intentExisting);
}
}
}
Expand All @@ -416,4 +399,36 @@ private String generateMnemonicString(boolean withWhitespace) {

return stringBuilder.toString();
}

@VisibleForTesting
public void showMnemonicInfo() {
requireDialog().setTitle(R.string.end_to_end_encryption_passphrase_title);

textView.setText(R.string.end_to_end_encryption_keywords_description);

passphraseTextView.setText(generateMnemonicString(true));

passphraseTextView.setVisibility(View.VISIBLE);
positiveButton.setText(R.string.end_to_end_encryption_confirm_button);
positiveButton.setVisibility(View.VISIBLE);

negativeButton.setVisibility(View.VISIBLE);

keyResult = KEY_GENERATE;
}

@VisibleForTesting
public void errorSavingKeys() {
keyResult = KEY_FAILED;

requireDialog().setTitle(R.string.common_error);
textView.setText(R.string.end_to_end_encryption_unsuccessful);
positiveButton.setText(R.string.end_to_end_encryption_dialog_close);
positiveButton.setVisibility(View.VISIBLE);
}

@VisibleForTesting
public void setMnemonic(List<String> keyWords) {
this.keyWords = keyWords;
}
}
2 changes: 1 addition & 1 deletion src/main/res/drawable/e2e_border.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#000000"/>
android:color="@color/dark" />

<solid android:color="@color/grey_200"/>
</shape>
2 changes: 2 additions & 0 deletions src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
<color name="list_divider_background">#222222</color>

<!-- Colors -->
<color name="dark">#ffffff</color>
<color name="bg_default">#121212</color>
<color name="fg_contrast">#717171</color>
<color name="primary_button_text_color">#000000</color>
<color name="bg_elevation_one">#2D2D2D</color>
<color name="grey_200">#818181</color>

<!-- Multiselect backgrounds -->
<color name="action_mode_background">@color/appbar</color>
Expand Down
2 changes: 1 addition & 1 deletion src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

<!-- Colors -->
<color name="standard_grey">#757575</color>
<color name="grey_200">#EEEEEE</color>
<color name="grey_db">#dbdbdb</color>
<color name="actionbar_shadow">#222222</color>

Expand All @@ -47,6 +46,7 @@
<color name="infolevel_warning">#e9322d</color>

<!-- Colors -->
<color name="dark">#000000</color>
<color name="login_btn_tint">#ffffff</color>
<color name="login_btn_stroke">#ffffff</color>
<color name="bg_default">#FFFFFF</color>
Expand Down

0 comments on commit a461ff3

Please sign in to comment.