mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-03-02 15:36:32 +00:00
Improve UI/UX around device transfer.
This commit is contained in:
@@ -37,6 +37,7 @@ import org.thoughtcrime.securesms.database.StickerDatabase;
|
||||
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;
|
||||
@@ -154,6 +155,12 @@ public class FullBackupExporter extends FullBackupBase {
|
||||
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");
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ import java.security.InvalidAlgorithmParameterException;
|
||||
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;
|
||||
@@ -213,7 +214,14 @@ public class FullBackupImporter extends FullBackupBase {
|
||||
@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) {
|
||||
|
||||
@@ -73,7 +73,8 @@ public abstract class DeviceTransferSetupFragment extends LoggingFragment {
|
||||
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);
|
||||
@@ -90,6 +91,7 @@ public abstract class DeviceTransferSetupFragment extends LoggingFragment {
|
||||
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());
|
||||
@@ -166,8 +168,7 @@ public abstract class DeviceTransferSetupFragment extends LoggingFragment {
|
||||
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());
|
||||
|
||||
@@ -59,6 +59,7 @@ public final class DeviceTransferSetupViewModel extends ViewModel {
|
||||
case SERVICE_CONNECTED:
|
||||
store.update(s -> s.updateStep(SetupStep.CONNECTED));
|
||||
break;
|
||||
case SHUTDOWN:
|
||||
case FAILED:
|
||||
store.update(s -> s.updateStep(SetupStep.ERROR));
|
||||
break;
|
||||
@@ -116,7 +117,7 @@ public final class DeviceTransferSetupViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
public void onVerified() {
|
||||
store.update(s -> s.updateStep(SetupStep.CONNECTING));
|
||||
store.update(s -> s.updateStep(SetupStep.WAITING_FOR_OTHER_TO_VERIFY));
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -67,8 +67,6 @@ public final class NewDeviceTransferSetupFragment extends DeviceTransferSetupFra
|
||||
: 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:
|
||||
|
||||
@@ -29,8 +29,8 @@ public final class TransferOrRestoreFragment extends LoggingFragment {
|
||||
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));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
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 {
|
||||
@@ -11,14 +14,23 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,6 @@ public final class OldDeviceTransferCompleteFragment extends LoggingFragment {
|
||||
}
|
||||
|
||||
private void close() {
|
||||
OldDeviceExitActivity.exit(requireContext());
|
||||
OldDeviceExitActivity.exit(requireActivity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +93,6 @@ public final class OldDeviceTransferSetupFragment extends DeviceTransferSetupFra
|
||||
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:
|
||||
|
||||
@@ -16,6 +16,7 @@ import androidx.core.app.NotificationCompat;
|
||||
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;
|
||||
@@ -25,9 +26,11 @@ import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user