Skip to content

Commit

Permalink
Merge pull request #3240 from deltachat/r10s/no-encrypt-database
Browse files Browse the repository at this point in the history
stop 'encrypted database' experiment
  • Loading branch information
adbenitez committed Aug 25, 2024
2 parents c4698fc + c6b6b8e commit 25f4766
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 128 deletions.
6 changes: 0 additions & 6 deletions jni/dc_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,6 @@ JNIEXPORT jint Java_com_b44t_messenger_DcAccounts_addAccount(JNIEnv *env, jobjec
}


JNIEXPORT jint Java_com_b44t_messenger_DcAccounts_addClosedAccount(JNIEnv *env, jobject obj)
{
return dc_accounts_add_closed_account(get_dc_accounts(env, obj));
}


JNIEXPORT jint Java_com_b44t_messenger_DcAccounts_migrateAccount(JNIEnv *env, jobject obj, jstring dbfile)
{
CHAR_REF(dbfile);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/b44t/messenger/DcAccounts.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void unref() {
public native void setPushDeviceToken (String token);

public native int addAccount ();
public native int addClosedAccount ();
public native int migrateAccount (String dbfile);
public native boolean removeAccount (int accountId);
public native int[] getAll ();
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/org/thoughtcrime/securesms/RegistrationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import com.b44t.messenger.util.concurrent.SettableFuture;
import com.google.android.material.textfield.TextInputEditText;

import org.thoughtcrime.securesms.connect.AccountManager;
import org.thoughtcrime.securesms.connect.DcEventCenter;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.permissions.Permissions;
Expand Down Expand Up @@ -87,8 +86,6 @@ private enum VerificationType {
private TextView providerLink;
private @Nullable DcProvider provider;

private CheckBox encryptCheckbox;

private Group advancedGroup;
private ImageView advancedIcon;
private ProgressDialog progressDialog;
Expand Down Expand Up @@ -116,8 +113,6 @@ public void onCreate(Bundle bundle) {
providerLink = findViewById(R.id.provider_link);
providerLink.setOnClickListener(l -> onProviderLink());

encryptCheckbox = findViewById(R.id.encrypt_checkbox);

advancedGroup = findViewById(R.id.advanced_group);
advancedIcon = findViewById(R.id.advanced_icon);
TextView advancedTextView = findViewById(R.id.advanced_text);
Expand Down Expand Up @@ -248,10 +243,6 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { }
certCheck.setSelection(certCheckFlags);
expandAdvanced = expandAdvanced || certCheckFlags != 0;

encryptCheckbox.setHeight(0);
encryptCheckbox.setClickable(false);
encryptCheckbox.setFocusable(false);

if (expandAdvanced) { onAdvancedSettings(); }
} else if (getIntent() != null && getIntent().getBundleExtra(ACCOUNT_DATA) != null) {
// Companion app might have sent account data
Expand Down Expand Up @@ -599,35 +590,6 @@ private void onLogin() {
return;
}

if (encryptCheckbox.isChecked()) {
AccountManager accountManager = AccountManager.getInstance();

if (progressDialog != null) {
progressDialog.dismiss();
progressDialog = null;
}

progressDialog = new ProgressDialog(this);
progressDialog.setMessage(getString(R.string.one_moment));
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
progressDialog.show();

// Prevent the user from disabling the checkbox again, switching to unencrypted account is currently not implemented
encryptCheckbox.setEnabled(false);
Util.runOnBackground(() -> {
DcHelper.getEventCenter(this).removeObservers(this);
accountManager.switchToEncrypted(this);
// Event center changed, register for events again
registerForEvents();
Util.runOnMain(this::continueLogin);
});
} else {
continueLogin();
}
}

private void continueLogin() {
setupConfig();

if (progressDialog != null) {
Expand Down
52 changes: 4 additions & 48 deletions src/main/java/org/thoughtcrime/securesms/WelcomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,11 @@ private void startImportBackup() {
} else {
final String backupFile = dcContext.imexHasBackup(imexDir.getAbsolutePath());
if (backupFile != null) {


View gl = View.inflate(this, R.layout.dialog_with_checkbox, null);
CheckBox encryptCheckbox = gl.findViewById(R.id.dialog_checkbox);
TextView msg = gl.findViewById(R.id.dialog_message);

// If we'd use both `setMessage()` and `setView()` on the same AlertDialog, on small screens the
// "OK" and "Cancel" buttons would not be show. So, put the message into our custom view:
msg.setText(String.format(getResources().getString(R.string.import_backup_ask), backupFile) );
encryptCheckbox.setText("Encrypt database (highly experimental, use at your own risk)");
int[] tintAttr = new int[]{android.R.attr.textColorSecondary};
TypedArray typedArray = obtainStyledAttributes(tintAttr);
int color = typedArray.getColor(0, Color.GRAY);
typedArray.recycle();
encryptCheckbox.setTextColor(color);

new AlertDialog.Builder(this)
.setTitle(R.string.import_backup_title)
.setView(gl)
.setMessage(String.format(getResources().getString(R.string.import_backup_ask), backupFile))
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, (dialog, which) -> startImport(backupFile, null, encryptCheckbox.isChecked()))
.setPositiveButton(android.R.string.ok, (dialog, which) -> startImport(backupFile, null))
.show();
}
else {
Expand All @@ -216,38 +200,10 @@ private void startImportBackup() {
.execute();
}

private void startImport(@Nullable final String backupFile, final @Nullable Uri backupFileUri, boolean encrypt)
private void startImport(@Nullable final String backupFile, final @Nullable Uri backupFileUri)
{
notificationController = GenericForegroundService.startForegroundTask(this, getString(R.string.import_backup_title));

if (encrypt) {
AccountManager accountManager = AccountManager.getInstance();

if (progressDialog != null) {
progressDialog.dismiss();
progressDialog = null;
}

progressDialog = new ProgressDialog(this);
progressDialog.setMessage(getString(R.string.one_moment));
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
progressDialog.show();

Util.runOnBackground(() -> {
DcHelper.getEventCenter(this).removeObservers(this);
accountManager.switchToEncrypted(this);
// Event center changed, register for events again
registerForEvents();
Util.runOnMain(() -> continueStartBackup(backupFile, backupFileUri));
});
} else {
continueStartBackup(backupFile, backupFileUri);
}

}

private void continueStartBackup(String backupFile, Uri backupFileUri) {
if( progressDialog!=null ) {
progressDialog.dismiss();
progressDialog = null;
Expand Down Expand Up @@ -411,7 +367,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e(TAG, " Can't import null URI");
return;
}
startImport(null, uri, false);
startImport(null, uri);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,6 @@ private void switchAccountAndStartActivity(Activity activity, int destAccountId,
}
}

/**
* Deletes the current account (must be unconfigured) and creates an encrypted account instead.
* @throws IllegalStateException if the currently selected account is already configured.
*/
public void switchToEncrypted(Activity activity) {
Log.i(TAG, "Switching to encrypted account...");
DcAccounts accounts = DcHelper.getAccounts(activity);
DcContext selectedAccount = accounts.getSelectedAccount();
if (selectedAccount.isConfigured() == 1) {
throw new IllegalStateException("Can't switch to encrypted account if already configured");
}

int selectedAccountId = selectedAccount.getAccountId();
accounts.addClosedAccount();
accounts.removeAccount(selectedAccountId);

DcContext newAccount = accounts.getSelectedAccount();
DatabaseSecret secret = DatabaseSecretProvider.getOrCreateDatabaseSecret(activity, newAccount.getAccountId());
newAccount.open(secret.asString());
resetDcContext(activity);
}

// ui

public void showSwitchAccountMenu(Activity activity) {
Expand Down
15 changes: 2 additions & 13 deletions src/main/res/layout/registration_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
app:constraint_referenced_ids="encrypt_checkbox, inbox, imap_login, imap_server, imap_port, imap_security_label, imap_security, outbox_view_spacer_top,
app:constraint_referenced_ids="inbox, imap_login, imap_server, imap_port, imap_security_label, imap_security, outbox_view_spacer_top,
outbox, smtp_login, smtp_password, smtp_server, smtp_port, smtp_security_label, smtp_security, auth_method_label, auth_method, cert_check_label, cert_check, view_log_button, socks5_switch" />

<ImageView
Expand Down Expand Up @@ -151,17 +151,6 @@
app:layout_constraintStart_toEndOf="@id/advanced_icon"
app:layout_constraintTop_toBottomOf="@id/no_servers_hint" />

<CheckBox
android:id="@+id/encrypt_checkbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Encrypt database (highly experimental, use at your own risk)"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
app:layout_constraintStart_toStartOf="@id/guideline_root_start"
app:layout_constraintEnd_toEndOf="@id/guideline_root_end"
app:layout_constraintTop_toBottomOf="@id/advanced_text" />

<TextView
android:id="@+id/inbox"
android:layout_width="wrap_content"
Expand All @@ -170,7 +159,7 @@
android:layout_marginTop="8dp"
android:text="@string/login_inbox"
app:layout_constraintStart_toStartOf="@id/guideline_root_start"
app:layout_constraintTop_toBottomOf="@id/encrypt_checkbox" />
app:layout_constraintTop_toBottomOf="@id/advanced_text" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/imap_login"
Expand Down

0 comments on commit 25f4766

Please sign in to comment.