mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-12 11:14:20 +00:00
Fix device linking
This commit is contained in:
parent
e6e5cb5adb
commit
45706b8e66
@ -3,6 +3,7 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:background="@drawable/default_dialog_background_inset"
|
android:background="@drawable/default_dialog_background_inset"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@ -12,6 +13,7 @@
|
|||||||
android:paddingBottom="@dimen/medium_spacing">
|
android:paddingBottom="@dimen/medium_spacing">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
android:id="@+id/qrCodeImageViewContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/small_spacing"
|
android:layout_marginTop="@dimen/small_spacing"
|
||||||
@ -24,6 +26,15 @@
|
|||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<com.github.ybq.android.spinkit.SpinKitView
|
||||||
|
style="@style/SpinKitView.DoubleBounce"
|
||||||
|
android:id="@+id/spinner"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:SpinKit_Color="@color/text" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/titleTextView"
|
android:id="@+id/titleTextView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -56,6 +67,7 @@
|
|||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/buttonContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/large_spacing"
|
android:layout_marginTop="@dimen/large_spacing"
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_centerInParent="true"
|
|
||||||
app:SpinKit_Color="@color/text" />
|
app:SpinKit_Color="@color/text" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -11,7 +11,6 @@ import android.view.View
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import kotlinx.android.synthetic.main.activity_linked_devices.*
|
import kotlinx.android.synthetic.main.activity_linked_devices.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import nl.komponents.kovenant.functional.bind
|
|
||||||
import nl.komponents.kovenant.ui.failUi
|
import nl.komponents.kovenant.ui.failUi
|
||||||
import nl.komponents.kovenant.ui.successUi
|
import nl.komponents.kovenant.ui.successUi
|
||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
@ -21,13 +20,10 @@ import org.thoughtcrime.securesms.database.DatabaseFactory
|
|||||||
import org.thoughtcrime.securesms.devicelist.Device
|
import org.thoughtcrime.securesms.devicelist.Device
|
||||||
import org.thoughtcrime.securesms.loki.dialogs.*
|
import org.thoughtcrime.securesms.loki.dialogs.*
|
||||||
import org.thoughtcrime.securesms.loki.protocol.EphemeralMessage
|
import org.thoughtcrime.securesms.loki.protocol.EphemeralMessage
|
||||||
import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
|
|
||||||
import org.thoughtcrime.securesms.loki.protocol.PushEphemeralMessageSendJob
|
import org.thoughtcrime.securesms.loki.protocol.PushEphemeralMessageSendJob
|
||||||
import org.thoughtcrime.securesms.loki.protocol.SyncMessagesProtocol
|
import org.thoughtcrime.securesms.loki.protocol.SyncMessagesProtocol
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||||
import org.whispersystems.signalservice.loki.api.LokiAPI
|
|
||||||
import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI
|
import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI
|
||||||
import org.whispersystems.signalservice.loki.protocol.multidevice.DeviceLink
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.schedule
|
import kotlin.concurrent.schedule
|
||||||
|
|
||||||
@ -147,24 +143,17 @@ class LinkedDevicesActivity : PassphraseRequiredActionBarActivity, LoaderManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDeviceLinkRequestAuthorized(deviceLink: DeviceLink) {
|
override fun onDeviceLinkRequestAuthorized() {
|
||||||
LokiFileServerAPI.shared.addDeviceLink(deviceLink).bind(LokiAPI.sharedContext) {
|
SyncMessagesProtocol.syncAllClosedGroups(this)
|
||||||
MultiDeviceProtocol.signAndSendDeviceLinkMessage(this, deviceLink)
|
SyncMessagesProtocol.syncAllOpenGroups(this)
|
||||||
}.success {
|
|
||||||
TextSecurePreferences.setMultiDevice(this, true)
|
|
||||||
SyncMessagesProtocol.syncAllClosedGroups(this@LinkedDevicesActivity)
|
|
||||||
SyncMessagesProtocol.syncAllOpenGroups(this@LinkedDevicesActivity)
|
|
||||||
Timer().schedule(4000) { // Not the best way to do this but the idea is to wait for the closed groups sync to go through first
|
Timer().schedule(4000) { // Not the best way to do this but the idea is to wait for the closed groups sync to go through first
|
||||||
SyncMessagesProtocol.syncAllContacts(this@LinkedDevicesActivity)
|
SyncMessagesProtocol.syncAllContacts(this@LinkedDevicesActivity)
|
||||||
}
|
}
|
||||||
}.successUi {
|
|
||||||
LoaderManager.getInstance(this).restartLoader(0, null, this)
|
LoaderManager.getInstance(this).restartLoader(0, null, this)
|
||||||
}.fail {
|
|
||||||
LokiFileServerAPI.shared.removeDeviceLink(deviceLink) // If this fails we have a problem
|
|
||||||
DatabaseFactory.getLokiPreKeyBundleDatabase(this).removePreKeyBundle(deviceLink.slaveHexEncodedPublicKey)
|
|
||||||
}.failUi {
|
|
||||||
Toast.makeText(this, "Couldn't link device", Toast.LENGTH_LONG).show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDeviceLinkAuthorizationFailed() {
|
||||||
|
Toast.makeText(this, "Couldn't link device", Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDeviceLinkCanceled() {
|
override fun onDeviceLinkCanceled() {
|
||||||
|
@ -11,12 +11,18 @@ import android.view.View
|
|||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import kotlinx.android.synthetic.main.dialog_link_device_master_mode.view.*
|
import kotlinx.android.synthetic.main.dialog_link_device_master_mode.view.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
|
import nl.komponents.kovenant.functional.bind
|
||||||
|
import nl.komponents.kovenant.ui.failUi
|
||||||
|
import nl.komponents.kovenant.ui.successUi
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
import org.thoughtcrime.securesms.loki.utilities.toPx
|
import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
|
||||||
import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities
|
import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities
|
||||||
import org.thoughtcrime.securesms.loki.utilities.QRCodeUtilities
|
import org.thoughtcrime.securesms.loki.utilities.QRCodeUtilities
|
||||||
|
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||||
import org.thoughtcrime.securesms.util.Util
|
import org.thoughtcrime.securesms.util.Util
|
||||||
|
import org.whispersystems.signalservice.loki.api.LokiAPI
|
||||||
|
import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI
|
||||||
import org.whispersystems.signalservice.loki.crypto.MnemonicCodec
|
import org.whispersystems.signalservice.loki.crypto.MnemonicCodec
|
||||||
import org.whispersystems.signalservice.loki.protocol.multidevice.DeviceLink
|
import org.whispersystems.signalservice.loki.protocol.multidevice.DeviceLink
|
||||||
import org.whispersystems.signalservice.loki.protocol.multidevice.DeviceLinkingSession
|
import org.whispersystems.signalservice.loki.protocol.multidevice.DeviceLinkingSession
|
||||||
@ -62,11 +68,36 @@ class LinkDeviceMasterModeDialog : DialogFragment(), DeviceLinkingSessionListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun authorizeDeviceLink() {
|
private fun authorizeDeviceLink() {
|
||||||
val authorization = this.deviceLink ?: return
|
val deviceLink = this.deviceLink ?: return
|
||||||
delegate?.onDeviceLinkRequestAuthorized(authorization)
|
|
||||||
DeviceLinkingSession.shared.stopListeningForLinkingRequests()
|
DeviceLinkingSession.shared.stopListeningForLinkingRequests()
|
||||||
DeviceLinkingSession.shared.removeListener(this)
|
DeviceLinkingSession.shared.removeListener(this)
|
||||||
|
Util.runOnMain {
|
||||||
|
contentView.qrCodeImageViewContainer.visibility = View.GONE
|
||||||
|
contentView.spinner.visibility = View.VISIBLE
|
||||||
|
val titleTextViewLayoutParams = contentView.titleTextView.layoutParams as LinearLayout.LayoutParams
|
||||||
|
titleTextViewLayoutParams.topMargin = toPx(24, resources)
|
||||||
|
contentView.titleTextView.layoutParams = titleTextViewLayoutParams
|
||||||
|
contentView.titleTextView.text = "Authorizing Device Link"
|
||||||
|
contentView.explanationTextView.text = "Please wait while the device link is created. This can take up to a minute."
|
||||||
|
contentView.mnemonicTextView.visibility = View.GONE
|
||||||
|
contentView.buttonContainer.visibility = View.GONE
|
||||||
|
contentView.cancelButton.visibility = View.GONE
|
||||||
|
contentView.authorizeButton.visibility = View.GONE
|
||||||
|
}
|
||||||
|
LokiFileServerAPI.shared.addDeviceLink(deviceLink).bind(LokiAPI.sharedContext) {
|
||||||
|
MultiDeviceProtocol.signAndSendDeviceLinkMessage(context!!, deviceLink)
|
||||||
|
}.success {
|
||||||
|
TextSecurePreferences.setMultiDevice(context!!, true)
|
||||||
|
}.successUi {
|
||||||
|
delegate?.onDeviceLinkRequestAuthorized()
|
||||||
dismiss()
|
dismiss()
|
||||||
|
}.fail {
|
||||||
|
LokiFileServerAPI.shared.removeDeviceLink(deviceLink) // If this fails we have a problem
|
||||||
|
DatabaseFactory.getLokiPreKeyBundleDatabase(context!!).removePreKeyBundle(deviceLink.slaveHexEncodedPublicKey)
|
||||||
|
}.failUi {
|
||||||
|
delegate?.onDeviceLinkAuthorizationFailed()
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onDeviceLinkCanceled() {
|
private fun onDeviceLinkCanceled() {
|
||||||
@ -82,6 +113,7 @@ class LinkDeviceMasterModeDialog : DialogFragment(), DeviceLinkingSessionListene
|
|||||||
|
|
||||||
interface LinkDeviceMasterModeDialogDelegate {
|
interface LinkDeviceMasterModeDialogDelegate {
|
||||||
|
|
||||||
fun onDeviceLinkRequestAuthorized(authorization: DeviceLink)
|
fun onDeviceLinkRequestAuthorized()
|
||||||
|
fun onDeviceLinkAuthorizationFailed()
|
||||||
fun onDeviceLinkCanceled()
|
fun onDeviceLinkCanceled()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user