Update registration for new restore flows.

This commit is contained in:
Cody Henthorne
2024-11-07 10:42:54 -05:00
committed by Greyson Parrelli
parent aad2624bd5
commit 22c4e2d084
140 changed files with 8364 additions and 2679 deletions

View File

@@ -69,10 +69,10 @@ class AccountSettingsFragment : DSLSettingsFragment(R.string.AccountSettingsFrag
@Suppress("DEPRECATION")
clickPref(
title = DSLSettingsText.from(if (state.hasPin) R.string.preferences_app_protection__change_your_pin else R.string.preferences_app_protection__create_a_pin),
title = DSLSettingsText.from(if (state.hasOptedInWithAccess) R.string.preferences_app_protection__change_your_pin else R.string.preferences_app_protection__create_a_pin),
isEnabled = state.isDeprecatedOrUnregistered(),
onClick = {
if (state.hasPin) {
if (state.hasOptedInWithAccess) {
startActivityForResult(CreateSvrPinActivity.getIntentForPinChangeFromSettings(requireContext()), CreateSvrPinActivity.REQUEST_NEW_PIN)
} else {
startActivityForResult(CreateSvrPinActivity.getIntentForPinCreate(requireContext()), CreateSvrPinActivity.REQUEST_NEW_PIN)
@@ -94,7 +94,7 @@ class AccountSettingsFragment : DSLSettingsFragment(R.string.AccountSettingsFrag
title = DSLSettingsText.from(R.string.preferences_app_protection__registration_lock),
summary = DSLSettingsText.from(R.string.AccountSettingsFragment__require_your_signal_pin),
isChecked = state.registrationLockEnabled,
isEnabled = state.hasPin && state.isDeprecatedOrUnregistered(),
isEnabled = (state.hasOptedInWithAccess) && state.isDeprecatedOrUnregistered(),
onClick = {
setRegistrationLockEnabled(!state.registrationLockEnabled)
}
@@ -125,7 +125,6 @@ class AccountSettingsFragment : DSLSettingsFragment(R.string.AccountSettingsFrag
clickPref(
title = DSLSettingsText.from(R.string.preferences_chats__transfer_account),
summary = DSLSettingsText.from(R.string.preferences_chats__transfer_account_to_a_new_android_device),
isEnabled = state.isDeprecatedOrUnregistered(),
onClick = {
Navigation.findNavController(requireView()).safeNavigate(R.id.action_accountSettingsFragment_to_oldDeviceTransferActivity)
}

View File

@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.components.settings.app.account
data class AccountSettingsState(
val hasPin: Boolean,
val hasOptedInWithAccess: Boolean,
val pinRemindersEnabled: Boolean,
val registrationLockEnabled: Boolean,
val userUnregistered: Boolean,

View File

@@ -19,7 +19,8 @@ class AccountSettingsViewModel : ViewModel() {
private fun getCurrentState(): AccountSettingsState {
return AccountSettingsState(
hasPin = SignalStore.svr.hasPin() && !SignalStore.svr.hasOptedOut(),
pinRemindersEnabled = SignalStore.pin.arePinRemindersEnabled(),
hasOptedInWithAccess = SignalStore.svr.hasOptedInWithAccess(),
pinRemindersEnabled = SignalStore.pin.arePinRemindersEnabled() && SignalStore.svr.hasPin(),
registrationLockEnabled = SignalStore.svr.isRegistrationLockEnabled,
userUnregistered = TextSecurePreferences.isUnauthorizedReceived(AppDependencies.application),
clientDeprecated = SignalStore.misc.isClientDeprecated

View File

@@ -392,7 +392,7 @@ class ChangeNumberViewModel : ViewModel() {
private suspend fun changeNumberWithRecoveryPassword(): Boolean {
Log.v(TAG, "changeNumberWithRecoveryPassword()")
SignalStore.svr.recoveryPassword?.let { recoveryPassword ->
if (SignalStore.svr.hasPin()) {
if (SignalStore.svr.hasOptedInWithAccess()) {
val result = repository.changeNumberWithRecoveryPassword(recoveryPassword = recoveryPassword, newE164 = number.e164Number)
if (result is ChangeNumberResult.Success) {

View File

@@ -837,7 +837,7 @@ class InternalSettingsFragment : DSLSettingsFragment(R.string.preferences__inter
SignalStore.account.setRegistered(false)
SignalStore.registration.clearRegistrationComplete()
SignalStore.registration.clearHasUploadedProfile()
SignalStore.registration.clearSkippedTransferOrRestore()
SignalStore.registration.debugClearSkippedTransferOrRestore()
Toast.makeText(context, "Unregistered!", Toast.LENGTH_SHORT).show()
}

View File

@@ -63,13 +63,17 @@ fun DrawScope.drawQr(
val deadzonePaddingPercent = 0.045f
// We want an even number of dots on either side of the deadzone
val deadzoneRadius: Int = (data.height * (deadzonePercent + deadzonePaddingPercent)).toInt().let { candidateDeadzoneHeight ->
if ((data.height - candidateDeadzoneHeight) % 2 == 0) {
candidateDeadzoneHeight
} else {
candidateDeadzoneHeight + 1
}
} / 2
val deadzoneRadius: Int = if (data.canSupportIconOverlay) {
(data.height * (deadzonePercent + deadzonePaddingPercent)).toInt().let { candidateDeadzoneHeight ->
if ((data.height - candidateDeadzoneHeight) % 2 == 0) {
candidateDeadzoneHeight
} else {
candidateDeadzoneHeight + 1
}
} / 2
} else {
0
}
val cellWidthPx: Float = size.width / data.width
val cornerRadius = CornerRadius(7f, 7f)
@@ -108,25 +112,27 @@ fun DrawScope.drawQr(
}
}
// Logo border
val logoBorderRadiusPx = ((deadzonePercent - deadzonePaddingPercent) * size.width) / 2
drawCircle(
color = foregroundColor,
radius = logoBorderRadiusPx,
style = Stroke(width = cellWidthPx * 0.75f),
center = this.center
)
// Logo
val logoWidthPx = (((deadzonePercent - deadzonePaddingPercent) * 0.6f) * size.width).toInt()
val logoOffsetPx = ((size.width - logoWidthPx) / 2).toInt()
if (logo != null) {
drawImage(
image = logo,
dstOffset = IntOffset(logoOffsetPx, logoOffsetPx),
dstSize = IntSize(logoWidthPx, logoWidthPx),
colorFilter = ColorFilter.tint(foregroundColor)
if (data.canSupportIconOverlay) {
// Logo border
val logoBorderRadiusPx = ((deadzonePercent - deadzonePaddingPercent) * size.width) / 2
drawCircle(
color = foregroundColor,
radius = logoBorderRadiusPx,
style = Stroke(width = cellWidthPx * 0.75f),
center = this.center
)
// Logo
val logoWidthPx = (((deadzonePercent - deadzonePaddingPercent) * 0.6f) * size.width).toInt()
val logoOffsetPx = ((size.width - logoWidthPx) / 2).toInt()
if (logo != null) {
drawImage(
image = logo,
dstOffset = IntOffset(logoOffsetPx, logoOffsetPx),
dstSize = IntSize(logoWidthPx, logoWidthPx),
colorFilter = ColorFilter.tint(foregroundColor)
)
}
}
}
@@ -135,7 +141,7 @@ fun DrawScope.drawQr(
private fun Preview() {
Surface {
QrCode(
data = QrCodeData.forData("https://signal.org", 64),
data = QrCodeData.forData("https://signal.org"),
modifier = Modifier.size(350.dp)
)
}

View File

@@ -24,7 +24,6 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@@ -170,13 +169,13 @@ private fun PreviewWithCodeShort() {
Surface {
Column {
QrCodeBadge(
data = QrCodeState.Present(QrCodeData.forData("https://signal.org", 64)),
data = QrCodeState.Present(QrCodeData.forData("https://signal.org")),
colorScheme = UsernameQrCodeColorScheme.Blue,
username = "parker.42",
usernameCopyable = false
)
QrCodeBadge(
data = QrCodeState.Present(QrCodeData.forData("https://signal.org", 64)),
data = QrCodeState.Present(QrCodeData.forData("https://signal.org")),
colorScheme = UsernameQrCodeColorScheme.Blue,
username = "parker.42",
usernameCopyable = true
@@ -193,14 +192,14 @@ private fun PreviewWithCodeLong() {
Surface {
Column {
QrCodeBadge(
data = QrCodeState.Present(QrCodeData.forData("https://signal.org", 64)),
data = QrCodeState.Present(QrCodeData.forData("https://signal.org")),
colorScheme = UsernameQrCodeColorScheme.Blue,
username = "TheAmazingSpiderMan.42",
usernameCopyable = false
)
Spacer(modifier = Modifier.height(8.dp))
QrCodeBadge(
data = QrCodeState.Present(QrCodeData.forData("https://signal.org", 64)),
data = QrCodeState.Present(QrCodeData.forData("https://signal.org")),
colorScheme = UsernameQrCodeColorScheme.Blue,
username = "TheAmazingSpiderMan.42",
usernameCopyable = true
@@ -249,7 +248,7 @@ private fun PreviewAllColorsP2() {
@Composable
private fun SampleCode(colorScheme: UsernameQrCodeColorScheme) {
QrCodeBadge(
data = QrCodeState.Present(QrCodeData.forData("https://signal.me/#eu/asdfasdfasdfasdfasdfasdfasdfasdfasdf", 64)),
data = QrCodeState.Present(QrCodeData.forData("https://signal.me/#eu/asdfasdfasdfasdfasdfasdfasdfasdfasdf")),
colorScheme = colorScheme,
username = "parker.42"
)

View File

@@ -15,6 +15,7 @@ import java.util.BitSet
class QrCodeData(
val width: Int,
val height: Int,
val canSupportIconOverlay: Boolean,
private val bits: BitSet
) {
@@ -34,13 +35,17 @@ class QrCodeData(
/**
* Converts the provided string data into a QR representation.
*
* @param supportIconOverlay indicates data can be rendered with the icon overlay. Rendering with an icon relies on more error correction
* data in the QR which requires a denser rendering which is sometimes not easily scanned by our scanner. Set to false if data is expected to be
* long to prevent scanning issues.
*/
@WorkerThread
fun forData(data: String, size: Int): QrCodeData {
fun forData(data: String, supportIconOverlay: Boolean = true): QrCodeData {
val qrCodeWriter = QRCodeWriter()
val hints = mapOf(EncodeHintType.ERROR_CORRECTION to ErrorCorrectionLevel.Q.toString())
val hints = mapOf(EncodeHintType.ERROR_CORRECTION to if (supportIconOverlay) ErrorCorrectionLevel.Q.toString() else ErrorCorrectionLevel.L.toString())
val padded = qrCodeWriter.encode(data, BarcodeFormat.QR_CODE, size, size, hints)
val padded = qrCodeWriter.encode(data, BarcodeFormat.QR_CODE, 64, 64, hints)
val dimens = padded.enclosingRectangle
val xStart = dimens[0]
val yStart = dimens[1]
@@ -58,7 +63,7 @@ class QrCodeData(
}
}
return QrCodeData(width, height, bitSet)
return QrCodeData(width, height, supportIconOverlay, bitSet)
}
}
}

View File

@@ -39,7 +39,7 @@ class UsernameLinkQrColorPickerViewModel : ViewModel() {
if (usernameLink != null) {
disposable += Single
.fromCallable { QrCodeData.forData(usernameLink.toLink(), 64) }
.fromCallable { QrCodeData.forData(usernameLink.toLink()) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { qrData ->

View File

@@ -371,7 +371,7 @@ private fun MainScreenPreview() {
activeTab = ActiveTab.Code,
username = "PeterParker.42",
usernameLinkState = UsernameLinkState.Present("https://signal.org"),
qrCodeState = QrCodeState.Present(QrCodeData.forData("PeterParker.42", 64)),
qrCodeState = QrCodeState.Present(QrCodeData.forData("PeterParker.42")),
qrCodeColorScheme = UsernameQrCodeColorScheme.Orange
)
)

View File

@@ -203,7 +203,7 @@ class UsernameLinkSettingsViewModel : ViewModel() {
private fun generateQrCodeData(url: Optional<String>): Single<Optional<QrCodeData>> {
return Single.fromCallable {
url.map { QrCodeData.forData(it, 64) }
url.map { QrCodeData.forData(it) }
}
}

View File

@@ -334,7 +334,7 @@ private fun previewState(): UsernameLinkSettingsState {
activeTab = ActiveTab.Code,
username = "parker.42",
usernameLinkState = UsernameLinkState.Present("https://signal.me/#eu/asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf"),
qrCodeState = QrCodeState.Present(QrCodeData.forData(link, 64)),
qrCodeState = QrCodeState.Present(QrCodeData.forData(link)),
qrCodeColorScheme = UsernameQrCodeColorScheme.Blue
)
}