Skip to content

Commit

Permalink
Add internal setting for manually initializing PNP mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Dec 30, 2022
1 parent f1d204b commit 202f208
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -103,7 +108,7 @@ class InternalSettingsViewModel(private val repository: InternalSettingsReposito
repository.addSampleReleaseNote()
}

private fun refresh() {
fun refresh() {
store.update { getState().copy(emojiVersion = it.emojiVersion) }
}

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit 202f208

Please sign in to comment.