Add internal setting for manually initializing PNP mode.

This commit is contained in:
Greyson Parrelli 2022-12-20 14:09:36 -05:00
parent f1d204b834
commit 202f20893c
4 changed files with 52 additions and 4 deletions

View file

@ -29,6 +29,7 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.jobmanager.JobTracker
import org.thoughtcrime.securesms.jobs.DownloadLatestEmojiDataJob
import org.thoughtcrime.securesms.jobs.EmojiSearchIndexDownloadJob
import org.thoughtcrime.securesms.jobs.PnpInitializeDevicesJob
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob
import org.thoughtcrime.securesms.jobs.RefreshOwnProfileJob
import org.thoughtcrime.securesms.jobs.RemoteConfigRefreshJob
@ -544,6 +545,37 @@ class InternalSettingsFragment : DSLSettingsFragment(R.string.preferences__inter
findNavController().safeNavigate(InternalSettingsFragmentDirections.actionInternalSettingsFragmentToStoryDialogsLauncherFragment())
}
)
dividerPref()
sectionHeaderPref(DSLSettingsText.from("PNP"))
clickPref(
title = DSLSettingsText.from("Trigger No-Op Change Number"),
summary = DSLSettingsText.from("Mimics the 'Hello world' event"),
isEnabled = true,
onClick = {
SimpleTask.run(viewLifecycleOwner.lifecycle, {
ApplicationDependencies.getJobManager().runSynchronously(PnpInitializeDevicesJob(), 10.seconds.inWholeMilliseconds)
}, { state ->
if (state.isPresent) {
Toast.makeText(context, "Job finished with result: ${state.get()}!", Toast.LENGTH_SHORT).show()
viewModel.refresh()
} else {
Toast.makeText(context, "Job timed out after 10 seconds!", Toast.LENGTH_SHORT).show()
}
})
}
)
clickPref(
title = DSLSettingsText.from("Reset 'PNP initialized' state"),
summary = DSLSettingsText.from("Current initialized state: ${state.pnpInitialized}"),
isEnabled = state.pnpInitialized,
onClick = {
viewModel.resetPnpInitializedState()
}
)
}
}

View file

@ -20,5 +20,6 @@ data class InternalSettingsState(
val removeSenderKeyMinimium: Boolean,
val delayResends: Boolean,
val disableStorageService: Boolean,
val canClearOnboardingState: Boolean
val canClearOnboardingState: Boolean,
val pnpInitialized: Boolean
)

View file

@ -64,6 +64,11 @@ class InternalSettingsViewModel(private val repository: InternalSettingsReposito
refresh()
}
fun resetPnpInitializedState() {
SignalStore.misc().setPniInitializedDevices(false)
refresh()
}
fun setUseBuiltInEmoji(enabled: Boolean) {
preferenceDataStore.putBoolean(InternalValues.FORCE_BUILT_IN_EMOJI, enabled)
refresh()
@ -103,7 +108,7 @@ class InternalSettingsViewModel(private val repository: InternalSettingsReposito
repository.addSampleReleaseNote()
}
private fun refresh() {
fun refresh() {
store.update { getState().copy(emojiVersion = it.emojiVersion) }
}
@ -124,7 +129,8 @@ class InternalSettingsViewModel(private val repository: InternalSettingsReposito
removeSenderKeyMinimium = SignalStore.internalValues().removeSenderKeyMinimum(),
delayResends = SignalStore.internalValues().delayResends(),
disableStorageService = SignalStore.internalValues().storageServiceDisabled(),
canClearOnboardingState = SignalStore.storyValues().hasDownloadedOnboardingStory && Stories.isFeatureEnabled()
canClearOnboardingState = SignalStore.storyValues().hasDownloadedOnboardingStory && Stories.isFeatureEnabled(),
pnpInitialized = SignalStore.misc().hasPniInitializedDevices()
)
fun onClearOnboardingState() {

View file

@ -10,6 +10,7 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.registration.VerifyAccountResponseWithoutKbs
import org.thoughtcrime.securesms.util.FeatureFlags
import org.thoughtcrime.securesms.util.TextSecurePreferences
import java.io.IOException
@ -27,7 +28,7 @@ class PnpInitializeDevicesJob private constructor(parameters: Parameters) : Base
@JvmStatic
fun enqueueIfNecessary() {
if (SignalStore.misc().hasPniInitializedDevices() || !SignalStore.account().isRegistered || SignalStore.account().aci == null || Recipient.self().pnpCapability != Recipient.Capability.SUPPORTED) {
if (SignalStore.misc().hasPniInitializedDevices() || !SignalStore.account().isRegistered || SignalStore.account().aci == null || Recipient.self().pnpCapability != Recipient.Capability.SUPPORTED || !FeatureFlags.phoneNumberPrivacy()) {
return
}
@ -49,6 +50,14 @@ class PnpInitializeDevicesJob private constructor(parameters: Parameters) : Base
@Throws(Exception::class)
public override fun onRun() {
if (Recipient.self().pnpCapability != Recipient.Capability.SUPPORTED) {
throw IllegalStateException("This should only be run if you have the capability!")
}
if (!FeatureFlags.phoneNumberPrivacy()) {
throw IllegalStateException("This should only be running if PNP is enabled!")
}
if (!SignalStore.account().isRegistered || SignalStore.account().aci == null) {
Log.w(TAG, "Not registered! Skipping, as it wouldn't do anything.")
return