Skip to content
Merged

E2e ux #11031

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,124 changes: 1,124 additions & 0 deletions app/schemas/com.nextcloud.client.database.NextcloudDatabase/66.json

Large diffs are not rendered by default.

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.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@
android:name=".ui.activity.TextEditorWebView"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:exported="false" />
<activity
android:name=".ui.activity.SetupEncryptionActivity"
android:theme="@style/Theme.NoBackground"
android:exported="false" />
<activity
android:name=".ui.activity.ContactsPreferenceActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.nextcloud.client.database

import android.content.Context
import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
Expand Down Expand Up @@ -55,6 +56,9 @@ import com.owncloud.android.db.ProviderMeta
VirtualEntity::class
],
version = ProviderMeta.DB_VERSION,
autoMigrations = [
AutoMigration(from = 65, to = 66)
],
exportSchema = true
)
@Suppress("Detekt.UnnecessaryAbstractClass") // needed by Room
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ data class CapabilityEntity(
val serverBackgroundUrl: String?,
@ColumnInfo(name = ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION)
val endToEndEncryption: Int?,
@ColumnInfo(name = ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION_KEYS_EXIST)
val endToEndEncryptionKeysExist: Int?,
@ColumnInfo(name = ProviderTableMeta.CAPABILITIES_ACTIVITY)
val activity: Int?,
@ColumnInfo(name = ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ class AccountRemovalWork(
uploadsStorageManager.removeUserUploads(user)

// delete stored E2E keys and mnemonic
arbitraryDataProvider.deleteKeyForAccount(user.accountName, EncryptionUtils.PRIVATE_KEY)
arbitraryDataProvider.deleteKeyForAccount(user.accountName, EncryptionUtils.PUBLIC_KEY)
arbitraryDataProvider.deleteKeyForAccount(user.accountName, EncryptionUtils.MNEMONIC)
EncryptionUtils.removeE2E(arbitraryDataProvider, user)

// unset default account, if needed
if (preferences.currentAccountName.equals(user.accountName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,8 @@ private ContentValues createContentValues(String accountName, OCCapability capab
capability.getServerLogo());
contentValues.put(ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION,
capability.getEndToEndEncryption().getValue());
contentValues.put(ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION_KEYS_EXIST,
capability.getEndToEndEncryptionKeysExist().getValue());
contentValues.put(ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT,
capability.getServerBackgroundDefault().getValue());
contentValues.put(ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_PLAIN,
Expand Down Expand Up @@ -2117,6 +2119,10 @@ private OCCapability createCapabilityInstance(Cursor cursor) {
capability.setServerSlogan(getString(cursor, ProviderTableMeta.CAPABILITIES_SERVER_SLOGAN));
capability.setServerLogo(getString(cursor, ProviderTableMeta.CAPABILITIES_SERVER_LOGO));
capability.setEndToEndEncryption(getBoolean(cursor, ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION));
capability.setEndToEndEncryptionKeysExist(
getBoolean(cursor,
ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION_KEYS_EXIST)
);
capability.setServerBackgroundDefault(
getBoolean(cursor, ProviderTableMeta.CAPABILITIES_SERVER_BACKGROUND_DEFAULT));
capability.setServerBackgroundPlain(getBoolean(cursor,
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 65;
public static final int DB_VERSION = 66;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -237,6 +237,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String CAPABILITIES_SERVER_BACKGROUND_DEFAULT = "background_default";
public static final String CAPABILITIES_SERVER_BACKGROUND_PLAIN = "background_plain";
public static final String CAPABILITIES_END_TO_END_ENCRYPTION = "end_to_end_encryption";
public static final String CAPABILITIES_END_TO_END_ENCRYPTION_KEYS_EXIST = "end_to_end_encryption_keys_exist";
public static final String CAPABILITIES_ACTIVITY = "activity";
public static final String CAPABILITIES_RICHDOCUMENT = "richdocument";
public static final String CAPABILITIES_RICHDOCUMENT_MIMETYPE_LIST = "richdocument_mimetype_list";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@
import com.owncloud.android.providers.DocumentsStorageProvider;
import com.owncloud.android.ui.ThemeableSwitchPreference;
import com.owncloud.android.ui.asynctasks.LoadingVersionNumberTask;
import com.owncloud.android.ui.dialog.SetupEncryptionDialogFragment;
import com.owncloud.android.ui.helpers.FileOperationsHelper;
import com.owncloud.android.utils.ClipboardUtil;
import com.owncloud.android.utils.DeviceCredentialUtils;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.EncryptionUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.theme.CapabilityUtils;
import com.owncloud.android.utils.theme.ViewThemeUtils;

import java.util.ArrayList;
Expand All @@ -98,7 +102,8 @@
* It proxies the necessary calls via {@link androidx.appcompat.app.AppCompatDelegate} to be used with AppCompat.
*/
public class SettingsActivity extends PreferenceActivity
implements StorageMigration.StorageMigrationProgressListener, LoadingVersionNumberTask.VersionDevInterface,
implements StorageMigration.StorageMigrationProgressListener,
LoadingVersionNumberTask.VersionDevInterface,
Injectable {

private static final String TAG = SettingsActivity.class.getSimpleName();
Expand All @@ -118,6 +123,7 @@ public class SettingsActivity extends PreferenceActivity
private static final int ACTION_CONFIRM_DEVICE_CREDENTIALS = 7;
private static final int ACTION_REQUEST_CODE_DAVDROID_SETUP = 10;
private static final int ACTION_SHOW_MNEMONIC = 11;
private static final int ACTION_E2E = 12;
private static final int TRUE_VALUE = 1;

private static final String DAV_PATH = "/remote.php/dav";
Expand Down Expand Up @@ -323,8 +329,14 @@ private void setupMoreCategory() {

setupBackupPreference();

setupE2EPreference(preferenceCategoryMore);

setupE2EKeysExist(preferenceCategoryMore);

setupE2EMnemonicPreference(preferenceCategoryMore);

removeE2E(preferenceCategoryMore);

setupHelpPreference(preferenceCategoryMore);

setupRecommendPreference(preferenceCategoryMore);
Expand Down Expand Up @@ -411,6 +423,47 @@ private void setupRecommendPreference(PreferenceCategory preferenceCategoryMore)
}
}

private void setupE2EPreference(PreferenceCategory preferenceCategoryMore) {
Preference preference = findPreference("setup_e2e");

if (preference != null) {
if (FileOperationsHelper.isEndToEndEncryptionSetup(this, user) ||
CapabilityUtils.getCapability(this).getEndToEndEncryptionKeysExist().isTrue()) {
preferenceCategoryMore.removePreference(preference);
} else {
preference.setOnPreferenceClickListener(p -> {
Intent i = new Intent(MainApp.getAppContext(), SetupEncryptionActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
i.putExtra("EXTRA_USER", user);
startActivityForResult(i, ACTION_E2E);

return true;
});
}
}
}

private void setupE2EKeysExist(PreferenceCategory preferenceCategoryMore) {
Preference preference = findPreference("setup_e2e_keys_exist");

if (preference != null) {
if (!CapabilityUtils.getCapability(this).getEndToEndEncryptionKeysExist().isTrue() ||
(CapabilityUtils.getCapability(this).getEndToEndEncryptionKeysExist().isTrue() &&
FileOperationsHelper.isEndToEndEncryptionSetup(this, user))) {
preferenceCategoryMore.removePreference(preference);
} else {
preference.setOnPreferenceClickListener(p -> {
Intent i = new Intent(MainApp.getAppContext(), SetupEncryptionActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
i.putExtra("EXTRA_USER", user);
startActivityForResult(i, ACTION_E2E);

return true;
});
}
}
}

private void setupE2EMnemonicPreference(PreferenceCategory preferenceCategoryMore) {
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC);

Expand All @@ -436,6 +489,40 @@ private void setupE2EMnemonicPreference(PreferenceCategory preferenceCategoryMor
}
}

private void removeE2E(PreferenceCategory preferenceCategoryMore) {
Preference preference = findPreference("remove_e2e");

if (preference != null) {
if (!FileOperationsHelper.isEndToEndEncryptionSetup(this, user)) {
preferenceCategoryMore.removePreference(preference);
} else {
preference.setOnPreferenceClickListener(p -> {
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.FallbackTheming_Dialog);
AlertDialog alertDialog = builder.setTitle(R.string.prefs_e2e_mnemonic)
.setMessage(getString(R.string.remove_e2e_message))
.setCancelable(true)
.setNegativeButton(R.string.common_cancel, ((dialog, i) -> dialog.dismiss()))
.setPositiveButton(R.string.confirm_removal, (dialog, which) -> {
EncryptionUtils.removeE2E(arbitraryDataProvider, user);
preferenceCategoryMore.removePreference(preference);

Preference pMnemonic = findPreference("mnemonic");
if (pMnemonic != null) {
preferenceCategoryMore.removePreference(pMnemonic);
}

dialog.dismiss();
})
.create();

alertDialog.show();

return true;
});
}
}
}

private void setupHelpPreference(PreferenceCategory preferenceCategoryMore) {
boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
Preference pHelp = findPreference("help");
Expand Down Expand Up @@ -861,6 +948,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
} else if (requestCode == ACTION_SHOW_MNEMONIC && resultCode == RESULT_OK) {
handleMnemonicRequest(data);
} else if (requestCode == ACTION_E2E && data != null && data.getBooleanExtra(SetupEncryptionDialogFragment.SUCCESS, false)) {
Intent i = new Intent(this, SettingsActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
}
}

Expand All @@ -879,6 +971,9 @@ public void handleMnemonicRequest(Intent data) {
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.FallbackTheming_Dialog);
AlertDialog alertDialog = builder.setTitle(R.string.prefs_e2e_mnemonic)
.setMessage(mnemonic)
.setNegativeButton(R.string.common_cancel, (dialog, i) -> dialog.dismiss())
.setNeutralButton(R.string.common_copy, (dialog, i) ->
ClipboardUtil.copyToClipboard(this, mnemonic, false))
.setPositiveButton(R.string.common_ok, (dialog, which) -> dialog.dismiss())
.create();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2022 Tobias Kaminsky
* Copyright (C) 2022 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.activity

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.nextcloud.client.account.User
import com.owncloud.android.R
import com.owncloud.android.ui.dialog.SetupEncryptionDialogFragment

class SetupEncryptionActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val user = intent?.getParcelableExtra("EXTRA_USER") as User?

if (user == null) {
Toast.makeText(this, getString(R.string.error_showing_encryption_dialog), Toast.LENGTH_LONG).show()
finish()
}

val setupEncryptionDialogFragment = SetupEncryptionDialogFragment.newInstance(user, -1)
supportFragmentManager.setFragmentResultListener(
SetupEncryptionDialogFragment.RESULT_REQUEST_KEY,
this
) { requestKey, result ->
if (requestKey == SetupEncryptionDialogFragment.RESULT_REQUEST_KEY) {
if (!result.getBoolean(SetupEncryptionDialogFragment.RESULT_KEY_CANCELLED, false)) {
setResult(
SetupEncryptionDialogFragment.SETUP_ENCRYPTION_RESULT_CODE,
buildResultIntentFromBundle(result)
)
}
}
finish()
}
setupEncryptionDialogFragment.show(supportFragmentManager, "setup_encryption")
}

private fun buildResultIntentFromBundle(result: Bundle): Intent {
val intent = Intent()
intent.putExtra(
SetupEncryptionDialogFragment.SUCCESS,
result.getBoolean(SetupEncryptionDialogFragment.SUCCESS)
)
intent.putExtra(
SetupEncryptionDialogFragment.ARG_POSITION,
result.getInt(SetupEncryptionDialogFragment.ARG_POSITION)
)
return intent
}
}
Loading