2019-10-16 22:37:08 +00:00
|
|
|
package org.thoughtcrime.securesms.registration.fragments;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
2021-09-03 21:07:05 +00:00
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
2019-10-16 22:37:08 +00:00
|
|
|
import androidx.navigation.Navigation;
|
|
|
|
|
2020-12-04 23:31:58 +00:00
|
|
|
import org.signal.core.util.logging.Log;
|
2019-10-16 22:37:08 +00:00
|
|
|
import org.thoughtcrime.securesms.R;
|
2020-02-10 18:42:43 +00:00
|
|
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
2020-03-18 20:31:45 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.StorageAccountRestoreJob;
|
2021-06-18 14:45:00 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.StorageSyncJob;
|
2020-02-01 15:14:02 +00:00
|
|
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
2021-09-03 21:07:05 +00:00
|
|
|
import org.thoughtcrime.securesms.registration.viewmodel.BaseRegistrationViewModel;
|
2019-10-16 22:37:08 +00:00
|
|
|
import org.thoughtcrime.securesms.registration.viewmodel.RegistrationViewModel;
|
2021-02-01 16:58:33 +00:00
|
|
|
import org.thoughtcrime.securesms.util.CommunicationActions;
|
2021-06-18 14:45:00 +00:00
|
|
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
|
|
|
import org.thoughtcrime.securesms.util.Stopwatch;
|
2021-02-01 16:58:33 +00:00
|
|
|
import org.thoughtcrime.securesms.util.SupportEmailUtil;
|
2022-03-29 17:43:41 +00:00
|
|
|
import org.signal.core.util.concurrent.SimpleTask;
|
2021-12-15 21:07:54 +00:00
|
|
|
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
|
2019-10-16 22:37:08 +00:00
|
|
|
|
2021-06-18 14:45:00 +00:00
|
|
|
import java.io.IOException;
|
2019-10-16 22:37:08 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2022-03-14 19:49:46 +00:00
|
|
|
import static org.thoughtcrime.securesms.util.CircularProgressButtonUtil.cancelSpinning;
|
|
|
|
|
2021-09-03 21:07:05 +00:00
|
|
|
public final class RegistrationLockFragment extends BaseRegistrationLockFragment {
|
2019-10-16 22:37:08 +00:00
|
|
|
|
2019-12-03 17:31:23 +00:00
|
|
|
private static final String TAG = Log.tag(RegistrationLockFragment.class);
|
|
|
|
|
2021-09-03 21:07:05 +00:00
|
|
|
public RegistrationLockFragment() {
|
|
|
|
super(R.layout.fragment_registration_lock);
|
2019-10-16 22:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-09-03 21:07:05 +00:00
|
|
|
protected BaseRegistrationViewModel getViewModel() {
|
|
|
|
return new ViewModelProvider(requireActivity()).get(RegistrationViewModel.class);
|
2021-08-31 14:04:40 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 21:07:05 +00:00
|
|
|
@Override
|
|
|
|
protected void navigateToAccountLocked() {
|
2021-12-15 21:07:54 +00:00
|
|
|
SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), RegistrationLockFragmentDirections.actionAccountLocked());
|
2020-02-01 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 21:07:05 +00:00
|
|
|
@Override
|
|
|
|
protected void handleSuccessfulPinEntry(@NonNull String pin) {
|
2020-04-01 23:55:18 +00:00
|
|
|
SignalStore.pinValues().setKeyboardType(getPinEntryKeyboardType());
|
2020-02-10 18:42:43 +00:00
|
|
|
|
2020-04-02 21:09:25 +00:00
|
|
|
SimpleTask.run(() -> {
|
2021-01-09 04:00:41 +00:00
|
|
|
SignalStore.onboarding().clearAll();
|
2021-06-18 14:45:00 +00:00
|
|
|
|
|
|
|
Stopwatch stopwatch = new Stopwatch("RegistrationLockRestore");
|
|
|
|
|
|
|
|
ApplicationDependencies.getJobManager().runSynchronously(new StorageAccountRestoreJob(), StorageAccountRestoreJob.LIFESPAN);
|
|
|
|
stopwatch.split("AccountRestore");
|
|
|
|
|
|
|
|
ApplicationDependencies.getJobManager().runSynchronously(new StorageSyncJob(), TimeUnit.SECONDS.toMillis(10));
|
|
|
|
stopwatch.split("ContactRestore");
|
|
|
|
|
|
|
|
try {
|
|
|
|
FeatureFlags.refreshSync();
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, "Failed to refresh flags.", e);
|
2020-04-02 21:09:25 +00:00
|
|
|
}
|
2021-06-18 14:45:00 +00:00
|
|
|
stopwatch.split("FeatureFlags");
|
|
|
|
|
|
|
|
stopwatch.stop(TAG);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}, none -> {
|
2020-02-10 18:42:43 +00:00
|
|
|
cancelSpinning(pinButton);
|
2021-12-15 21:07:54 +00:00
|
|
|
SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), RegistrationLockFragmentDirections.actionSuccessfulRegistration());
|
2020-04-02 21:09:25 +00:00
|
|
|
});
|
2020-02-10 18:42:43 +00:00
|
|
|
}
|
2021-02-01 16:58:33 +00:00
|
|
|
|
2021-09-03 21:07:05 +00:00
|
|
|
@Override
|
|
|
|
protected void sendEmailToSupport() {
|
|
|
|
int subject = R.string.RegistrationLockFragment__signal_registration_need_help_with_pin_for_android_v2_pin;
|
2021-02-01 16:58:33 +00:00
|
|
|
|
|
|
|
String body = SupportEmailUtil.generateSupportEmailBody(requireContext(),
|
|
|
|
subject,
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
CommunicationActions.openEmail(requireContext(),
|
|
|
|
SupportEmailUtil.getSupportEmailAddress(requireContext()),
|
|
|
|
getString(subject),
|
|
|
|
body);
|
|
|
|
}
|
2019-10-16 22:37:08 +00:00
|
|
|
}
|