Skip to content

Commit

Permalink
Improve UI/UX around device transfer.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal committed Mar 16, 2021
1 parent ace85df commit 490944a
Show file tree
Hide file tree
Showing 24 changed files with 397 additions and 171 deletions.
Expand Up @@ -37,6 +37,7 @@
import org.thoughtcrime.securesms.profiles.AvatarHelper;
import org.thoughtcrime.securesms.util.SetUtil;
import org.thoughtcrime.securesms.util.Stopwatch;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.libsignal.kdf.HKDFv3;
import org.whispersystems.libsignal.util.ByteUtil;
Expand Down Expand Up @@ -154,6 +155,12 @@ private static void internalExport(@NonNull Context context,
EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.PROGRESS, ++count));
outputStream.write(preference);
}

for (BackupProtos.SharedPreference preference : TextSecurePreferences.getPreferencesToSaveToBackup(context)) {
throwIfCanceled(cancellationSignal);
EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.PROGRESS, ++count));
outputStream.write(preference);
}

stopwatch.split("prefs");

Expand Down
Expand Up @@ -45,6 +45,7 @@
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -213,7 +214,14 @@ private static void processAvatar(@NonNull Context context, @NonNull SQLiteDatab
@SuppressLint("ApplySharedPref")
private static void processPreference(@NonNull Context context, SharedPreference preference) {
SharedPreferences preferences = context.getSharedPreferences(preference.getFile(), 0);
preferences.edit().putString(preference.getKey(), preference.getValue()).commit();

if (preference.hasValue()) {
preferences.edit().putString(preference.getKey(), preference.getValue()).commit();
} else if (preference.hasBooleanValue()) {
preferences.edit().putBoolean(preference.getKey(), preference.getBooleanValue()).commit();
} else if (preference.hasIsStringSetValue() && preference.getIsStringSetValue()) {
preferences.edit().putStringSet(preference.getKey(), new HashSet<>(preference.getStringSetValueList())).commit();
}
}

private static void dropAllTables(@NonNull SQLiteDatabase db) {
Expand Down
Expand Up @@ -73,7 +73,8 @@ public DeviceTransferSetupFragment() {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
Group progressGroup = view.findViewById(R.id.device_transfer_setup_fragment_progress_group);
Group errorGroup = view.findViewById(R.id.device_transfer_setup_fragment_error_group);
Group verifyGroup = view.findViewById(R.id.device_transfer_setup_fragment_verify_group);
View verifyGroup = view.findViewById(R.id.device_transfer_setup_fragment_verify);
View waitingGroup = view.findViewById(R.id.device_transfer_setup_fragment_waiting);
View troubleshooting = view.findViewById(R.id.device_transfer_setup_fragment_troubleshooting);
TextView status = view.findViewById(R.id.device_transfer_setup_fragment_status);
TextView error = view.findViewById(R.id.device_transfer_setup_fragment_error);
Expand All @@ -90,6 +91,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
progressGroup.setVisibility(step.isProgress() ? View.VISIBLE : View.GONE);
errorGroup.setVisibility(step.isError() ? View.VISIBLE : View.GONE);
verifyGroup.setVisibility(step == SetupStep.VERIFY ? View.VISIBLE : View.GONE);
waitingGroup.setVisibility(step == SetupStep.WAITING_FOR_OTHER_TO_VERIFY ? View.VISIBLE : View.GONE);
troubleshooting.setVisibility(step == SetupStep.TROUBLESHOOTING ? View.VISIBLE : View.GONE);

Log.i(TAG, "Handling step: " + step.name());
Expand Down Expand Up @@ -166,8 +168,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
viewModel.onVerified();
});
break;
case CONNECTING:
status.setText(getStatusTextForStep(step, false));
case WAITING_FOR_OTHER_TO_VERIFY:
break;
case CONNECTED:
Log.d(TAG, "Connected! isNotShutdown: " + viewModel.isNotShutdown());
Expand Down
Expand Up @@ -59,6 +59,7 @@ public void onTransferEvent(@NonNull TransferStatus event) {
case SERVICE_CONNECTED:
store.update(s -> s.updateStep(SetupStep.CONNECTED));
break;
case SHUTDOWN:
case FAILED:
store.update(s -> s.updateStep(SetupStep.ERROR));
break;
Expand Down Expand Up @@ -116,7 +117,7 @@ public void onWifiDirectAvailable() {
}

public void onVerified() {
store.update(s -> s.updateStep(SetupStep.CONNECTING));
store.update(s -> s.updateStep(SetupStep.WAITING_FOR_OTHER_TO_VERIFY));
}

public void onResume() {
Expand Down
Expand Up @@ -18,7 +18,7 @@ public enum SetupStep {
SETTING_UP(true, false),
WAITING(true, false),
VERIFY(false, false),
CONNECTING(true, false),
WAITING_FOR_OTHER_TO_VERIFY(false, false),
CONNECTED(true, false),
TROUBLESHOOTING(false, false),
ERROR(false, true);
Expand Down
Expand Up @@ -67,8 +67,6 @@ protected void navigateToTransferConnected() {
: R.string.NewDeviceTransferSetup__preparing_to_connect_to_old_android_device;
case WAITING:
return R.string.NewDeviceTransferSetup__waiting_for_old_device_to_connect;
case CONNECTING:
return R.string.NewDeviceTransferSetup__connecting_to_old_android_device;
case ERROR:
return R.string.NewDeviceTransferSetup__an_unexpected_error_occurred_while_attempting_to_connect_to_your_old_device;
case TROUBLESHOOTING:
Expand Down
Expand Up @@ -29,8 +29,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
view.findViewById(R.id.transfer_or_restore_fragment_restore)
.setOnClickListener(v -> Navigation.findNavController(v).navigate(R.id.action_choose_backup));

String description = getString(R.string.TransferOrRestoreFragment__transfer_your_account_and_message_history_from_your_old_android_device);
String toBold = getString(R.string.TransferOrRestoreFragment__you_must_have_access_to_your_old_device);
String description = getString(R.string.TransferOrRestoreFragment__transfer_your_account_and_messages_from_your_old_android_device);
String toBold = getString(R.string.TransferOrRestoreFragment__you_need_access_to_your_old_device);

TextView transferDescriptionView = view.findViewById(R.id.transfer_or_restore_fragment_transfer_description);
transferDescriptionView.setText(SpanUtil.boldSubstring(description, toBold));
Expand Down
@@ -1,24 +1,36 @@
package org.thoughtcrime.securesms.devicetransfer.olddevice;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

public class OldDeviceExitActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
finish();
finishAll(this);
}

public static void exit(Context context) {
Intent intent = new Intent(context, OldDeviceExitActivity.class);
public static void exit(@NonNull Activity activity) {
Intent intent = new Intent(activity, OldDeviceExitActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
activity.startActivity(intent);
finishAll(activity);
}

private static void finishAll(@NonNull Activity activity) {
if (Build.VERSION.SDK_INT < 21) {
activity.finishAffinity();
} else {
activity.finishAndRemoveTask();
}
}
}
Expand Up @@ -36,6 +36,6 @@ public void handleOnBackPressed() {
}

private void close() {
OldDeviceExitActivity.exit(requireContext());
OldDeviceExitActivity.exit(requireActivity());
}
}
Expand Up @@ -93,8 +93,6 @@ protected void startTransfer() {
case SETTING_UP:
case WAITING:
return R.string.OldDeviceTransferSetup__searching_for_your_new_android_device;
case CONNECTING:
return R.string.OldDeviceTransferSetup__connecting_to_new_android_device;
case ERROR:
return R.string.OldDeviceTransferSetup__an_unexpected_error_occurred_while_attempting_to_connect_to_your_old_device;
case TROUBLESHOOTING:
Expand Down
Expand Up @@ -16,6 +16,7 @@
import org.greenrobot.eventbus.EventBus;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.backup.BackupProtos;
import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraintObserver;
import org.thoughtcrime.securesms.keyvalue.SettingsValues;
import org.thoughtcrime.securesms.lock.RegistrationLockReminders;
Expand All @@ -25,9 +26,11 @@

import java.io.IOException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -209,6 +212,74 @@ public class TextSecurePreferences {

private static final String ARGON2_TESTED = "argon2_tested";

private static final String[] booleanPreferencesToBackup = {SCREEN_SECURITY_PREF,
INCOGNITO_KEYBORAD_PREF,
ALWAYS_RELAY_CALLS_PREF,
READ_RECEIPTS_PREF,
TYPING_INDICATORS,
SHOW_UNIDENTIFIED_DELIVERY_INDICATORS,
UNIVERSAL_UNIDENTIFIED_ACCESS,
NOTIFICATION_PREF,
VIBRATE_PREF,
IN_THREAD_NOTIFICATION_PREF,
CALL_NOTIFICATIONS_PREF,
CALL_VIBRATE_PREF,
NEW_CONTACTS_NOTIFICATIONS,
SHOW_INVITE_REMINDER_PREF,
SYSTEM_EMOJI_PREF,
ENTER_SENDS_PREF};

private static final String[] stringPreferencesToBackup = {LED_COLOR_PREF,
LED_BLINK_PREF,
REPEAT_ALERTS_PREF,
NOTIFICATION_PRIVACY_PREF,
THEME_PREF,
LANGUAGE_PREF,
MESSAGE_BODY_TEXT_SIZE_PREF};

private static final String[] stringSetPreferencesToBackup = {MEDIA_DOWNLOAD_MOBILE_PREF,
MEDIA_DOWNLOAD_WIFI_PREF,
MEDIA_DOWNLOAD_ROAMING_PREF};

public static List<BackupProtos.SharedPreference> getPreferencesToSaveToBackup(@NonNull Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
List<BackupProtos.SharedPreference> backupProtos = new ArrayList<>();
String defaultFile = context.getPackageName() + "_preferences";

for (String booleanPreference : booleanPreferencesToBackup) {
if (preferences.contains(booleanPreference)) {
backupProtos.add(BackupProtos.SharedPreference.newBuilder()
.setFile(defaultFile)
.setKey(booleanPreference)
.setBooleanValue(preferences.getBoolean(booleanPreference, false))
.build());
}
}

for (String stringPreference : stringPreferencesToBackup) {
if (preferences.contains(stringPreference)) {
backupProtos.add(BackupProtos.SharedPreference.newBuilder()
.setFile(defaultFile)
.setKey(stringPreference)
.setValue(preferences.getString(stringPreference, null))
.build());
}
}

for (String stringSetPreference : stringSetPreferencesToBackup) {
if (preferences.contains(stringSetPreference)) {
backupProtos.add(BackupProtos.SharedPreference.newBuilder()
.setFile(defaultFile)
.setKey(stringSetPreference)
.setIsStringSetValue(true)
.addAllStringSetValue(preferences.getStringSet(stringSetPreference, Collections.emptySet()))
.build());
}
}

return backupProtos;
}

public static boolean isScreenLockEnabled(@NonNull Context context) {
return getBooleanPreference(context, SCREEN_LOCK, false);
}
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/proto/Backups.proto
Expand Up @@ -25,9 +25,12 @@ message SqlStatement {
}

message SharedPreference {
optional string file = 1;
optional string key = 2;
optional string value = 3;
optional string file = 1;
optional string key = 2;
optional string value = 3;
optional bool booleanValue = 4;
repeated string stringSetValue = 5;
optional bool isStringSetValue = 6;
}

message Attachment {
Expand Down

0 comments on commit 490944a

Please sign in to comment.