add blink to android
This commit is contained in:
1 parent
95f22d464b
commit
66cba1a228
14 files changed
+542
-4
No files matched your search
@@ -38,6 +38,7 @@ import bypass.whitelist.tunnel.TunnelMode
|
|||||||
import bypass.whitelist.tunnel.TunnelServiceState
|
import bypass.whitelist.tunnel.TunnelServiceState
|
||||||
import bypass.whitelist.tunnel.TunnelVpnService
|
import bypass.whitelist.tunnel.TunnelVpnService
|
||||||
import bypass.whitelist.tunnel.VpnStatus
|
import bypass.whitelist.tunnel.VpnStatus
|
||||||
|
import bypass.whitelist.ui.BlinkLoginSheet
|
||||||
import bypass.whitelist.ui.CallsListener
|
import bypass.whitelist.ui.CallsListener
|
||||||
import bypass.whitelist.ui.HeadlessVkFragment
|
import bypass.whitelist.ui.HeadlessVkFragment
|
||||||
import bypass.whitelist.ui.JoinFragmentHost
|
import bypass.whitelist.ui.JoinFragmentHost
|
||||||
@@ -96,6 +97,7 @@ class MainActivity :
|
|||||||
@Volatile private var overlayVisible: Boolean = false
|
@Volatile private var overlayVisible: Boolean = false
|
||||||
@Volatile private var resetGeneration: Long = 0L
|
@Volatile private var resetGeneration: Long = 0L
|
||||||
private var pendingConnectConfig: CallConfig? = null
|
private var pendingConnectConfig: CallConfig? = null
|
||||||
|
private var blinkLoginLink: String? = null
|
||||||
private val navColorEvaluator = ArgbEvaluator()
|
private val navColorEvaluator = ArgbEvaluator()
|
||||||
|
|
||||||
private val vpnLauncher = registerForActivityResult(
|
private val vpnLauncher = registerForActivityResult(
|
||||||
@@ -282,6 +284,7 @@ class MainActivity :
|
|||||||
onDisconnectFromService()
|
onDisconnectFromService()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
showBlinkLoginSheet()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
@@ -425,12 +428,22 @@ class MainActivity :
|
|||||||
runOnUiThread { mainFragment()?.onStatusTextChanged(text) }
|
runOnUiThread { mainFragment()?.onStatusTextChanged(text) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onLoginLink(link: String) {
|
||||||
|
runOnUiThread {
|
||||||
|
blinkLoginLink = link
|
||||||
|
showBlinkLoginSheet()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onJoinStatus(status: VpnStatus) {
|
override fun onJoinStatus(status: VpnStatus) {
|
||||||
if (resetInProgress && status != VpnStatus.CALL_FAILED) return
|
if (resetInProgress && status != VpnStatus.CALL_FAILED) return
|
||||||
TunnelVpnService.instance?.updateStatus(status)
|
TunnelVpnService.instance?.updateStatus(status)
|
||||||
ProxyService.instance?.updateStatus(status)
|
ProxyService.instance?.updateStatus(status)
|
||||||
lastStatus = status
|
lastStatus = status
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
if (status != VpnStatus.ACTION_REQUIRED_LOGIN) {
|
||||||
|
dismissBlinkLoginSheet()
|
||||||
|
}
|
||||||
if (status == VpnStatus.CALL_FAILED) {
|
if (status == VpnStatus.CALL_FAILED) {
|
||||||
fullReset()
|
fullReset()
|
||||||
lastStatus = VpnStatus.CALL_FAILED
|
lastStatus = VpnStatus.CALL_FAILED
|
||||||
@@ -721,12 +734,13 @@ class MainActivity :
|
|||||||
mainFragment()?.onConnectedChanged(false)
|
mainFragment()?.onConnectedChanged(false)
|
||||||
|
|
||||||
val headlessMode =
|
val headlessMode =
|
||||||
Prefs.headless || platform == CallPlatform.WBSTREAM || platform == CallPlatform.DION || platform == CallPlatform.BITRIX
|
Prefs.headless || platform == CallPlatform.WBSTREAM || platform == CallPlatform.DION || platform == CallPlatform.BITRIX || platform == CallPlatform.BLINK
|
||||||
|
|
||||||
if (headlessMode && platform != CallPlatform.VK) {
|
if (headlessMode && platform != CallPlatform.VK) {
|
||||||
setJoinOverlayVisible(false)
|
setJoinOverlayVisible(false)
|
||||||
activeHeadlessController = HeadlessJoinController(
|
activeHeadlessController = HeadlessJoinController(
|
||||||
applicationInfo.nativeLibraryDir,
|
applicationInfo.nativeLibraryDir,
|
||||||
|
filesDir,
|
||||||
this,
|
this,
|
||||||
platform,
|
platform,
|
||||||
url,
|
url,
|
||||||
@@ -778,6 +792,7 @@ class MainActivity :
|
|||||||
activeJoinUrl = ""
|
activeJoinUrl = ""
|
||||||
|
|
||||||
removeJoinFragment()
|
removeJoinFragment()
|
||||||
|
dismissBlinkLoginSheet()
|
||||||
TunnelVpnService.requestStop(this)
|
TunnelVpnService.requestStop(this)
|
||||||
ProxyService.requestStop(this)
|
ProxyService.requestStop(this)
|
||||||
HeadlessSessionService.requestStop(this)
|
HeadlessSessionService.requestStop(this)
|
||||||
@@ -888,6 +903,23 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showBlinkLoginSheet() {
|
||||||
|
val link = blinkLoginLink ?: return
|
||||||
|
val shown = supportFragmentManager.findFragmentByTag(BlinkLoginSheet.TAG) as? BlinkLoginSheet
|
||||||
|
if (shown != null) {
|
||||||
|
shown.updateLink(link)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (isDestroyed || supportFragmentManager.isStateSaved) return
|
||||||
|
BlinkLoginSheet.show(supportFragmentManager, link) { onJoinCancel() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dismissBlinkLoginSheet() {
|
||||||
|
blinkLoginLink = null
|
||||||
|
val shown = supportFragmentManager.findFragmentByTag(BlinkLoginSheet.TAG) as? BlinkLoginSheet
|
||||||
|
shown?.dismissAllowingStateLoss()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val ACTION_AUTO_START = "bypass.whitelist.AUTO_START"
|
const val ACTION_AUTO_START = "bypass.whitelist.AUTO_START"
|
||||||
private const val SUB_PAGE_TAG = "sub_page"
|
private const val SUB_PAGE_TAG = "sub_page"
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ data class CallConfig(
|
|||||||
CallPlatform.WBSTREAM -> "WB"
|
CallPlatform.WBSTREAM -> "WB"
|
||||||
CallPlatform.DION -> "DN"
|
CallPlatform.DION -> "DN"
|
||||||
CallPlatform.BITRIX -> "BX"
|
CallPlatform.BITRIX -> "BX"
|
||||||
|
CallPlatform.BLINK -> "BL"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toJson(): JSONObject = JSONObject().apply {
|
fun toJson(): JSONObject = JSONObject().apply {
|
||||||
@@ -76,6 +77,7 @@ data class CallConfig(
|
|||||||
CallPlatform.WBSTREAM -> "WB Stream"
|
CallPlatform.WBSTREAM -> "WB Stream"
|
||||||
CallPlatform.DION -> "DION"
|
CallPlatform.DION -> "DION"
|
||||||
CallPlatform.BITRIX -> "Bitrix"
|
CallPlatform.BITRIX -> "Bitrix"
|
||||||
|
CallPlatform.BLINK -> "Blink"
|
||||||
}
|
}
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,15 @@ enum class CallPlatform(val id: String, val urlMarker: String) {
|
|||||||
TELEMOST("telemost", "telemost"),
|
TELEMOST("telemost", "telemost"),
|
||||||
WBSTREAM("wbstream", "wbstream://"),
|
WBSTREAM("wbstream", "wbstream://"),
|
||||||
DION("dion", "dion://"),
|
DION("dion", "dion://"),
|
||||||
BITRIX("bitrix", "/video/");
|
BITRIX("bitrix", "/video/"),
|
||||||
|
BLINK("blink", "blink://");
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun fromUrl(url: String): CallPlatform = when {
|
fun fromUrl(url: String): CallPlatform = when {
|
||||||
url.contains(DION.urlMarker) || url.contains("dion.vc/event/") -> DION
|
url.contains(DION.urlMarker) || url.contains("dion.vc/event/") -> DION
|
||||||
url.contains(WBSTREAM.urlMarker) -> WBSTREAM
|
url.contains(WBSTREAM.urlMarker) -> WBSTREAM
|
||||||
url.contains("bitrix24") && url.contains(BITRIX.urlMarker) -> BITRIX
|
url.contains("bitrix24") && url.contains(BITRIX.urlMarker) -> BITRIX
|
||||||
|
url.contains(BLINK.urlMarker) || (url.contains("blinkmap.com") && url.contains("/join/")) -> BLINK
|
||||||
url.contains(TELEMOST.urlMarker) -> TELEMOST
|
url.contains(TELEMOST.urlMarker) -> TELEMOST
|
||||||
else -> VK
|
else -> VK
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ import android.util.Log
|
|||||||
import bypass.whitelist.ui.JoinFragmentHost
|
import bypass.whitelist.ui.JoinFragmentHost
|
||||||
import bypass.whitelist.util.Prefs
|
import bypass.whitelist.util.Prefs
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import java.io.File
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
class HeadlessJoinController(
|
class HeadlessJoinController(
|
||||||
nativeLibraryDir: String,
|
nativeLibraryDir: String,
|
||||||
|
private val filesDir: File,
|
||||||
private val host: JoinFragmentHost,
|
private val host: JoinFragmentHost,
|
||||||
private val platform: CallPlatform,
|
private val platform: CallPlatform,
|
||||||
private val url: String,
|
private val url: String,
|
||||||
@@ -22,6 +24,7 @@ class HeadlessJoinController(
|
|||||||
relayMode = "${platform.id}-headless-joiner",
|
relayMode = "${platform.id}-headless-joiner",
|
||||||
onLog = { host.appendLog(it) },
|
onLog = { host.appendLog(it) },
|
||||||
onStatus = ::handleStatus,
|
onStatus = ::handleStatus,
|
||||||
|
onLoginLink = { host.onLoginLink(it) },
|
||||||
)
|
)
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
@@ -65,6 +68,11 @@ class HeadlessJoinController(
|
|||||||
put("tunnelMode", Prefs.activeTunnelMode.relayArg)
|
put("tunnelMode", Prefs.activeTunnelMode.relayArg)
|
||||||
}
|
}
|
||||||
CallPlatform.DION -> put("roomId", CallPlatform.extractRoomId(url))
|
CallPlatform.DION -> put("roomId", CallPlatform.extractRoomId(url))
|
||||||
|
CallPlatform.BLINK -> {
|
||||||
|
put("joinLink", url)
|
||||||
|
put("tunnelMode", Prefs.activeTunnelMode.relayArg)
|
||||||
|
put("cookiesPath", File(filesDir, BLINK_COOKIES_FILE).absolutePath)
|
||||||
|
}
|
||||||
CallPlatform.VK -> error("VK headless flow uses HeadlessVkFragment for captcha UI")
|
CallPlatform.VK -> error("VK headless flow uses HeadlessVkFragment for captcha UI")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,5 +84,6 @@ class HeadlessJoinController(
|
|||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
const val LOG_TAG = "HeadlessJoinController"
|
const val LOG_TAG = "HeadlessJoinController"
|
||||||
|
const val BLINK_COOKIES_FILE = "cookies-blink.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,7 @@ class HeadlessRelayController(
|
|||||||
private val onLog: ParamCallback<String>,
|
private val onLog: ParamCallback<String>,
|
||||||
private val onStatus: ParamCallback<VpnStatus>,
|
private val onStatus: ParamCallback<VpnStatus>,
|
||||||
private val onCaptchaUrl: ParamCallback<String>? = null,
|
private val onCaptchaUrl: ParamCallback<String>? = null,
|
||||||
|
private val onLoginLink: ParamCallback<String>? = null,
|
||||||
) {
|
) {
|
||||||
private var process: Process? = null
|
private var process: Process? = null
|
||||||
private var thread: Thread? = null
|
private var thread: Thread? = null
|
||||||
@@ -101,6 +102,11 @@ class HeadlessRelayController(
|
|||||||
onStatus.invoke(VpnStatus.ACTION_REQUIRED_CAPTCHA)
|
onStatus.invoke(VpnStatus.ACTION_REQUIRED_CAPTCHA)
|
||||||
onCaptchaUrl?.invoke(captchaUrl)
|
onCaptchaUrl?.invoke(captchaUrl)
|
||||||
}
|
}
|
||||||
|
status.startsWith("LOGIN_LINK:") -> {
|
||||||
|
val loginLink = status.removePrefix("LOGIN_LINK:")
|
||||||
|
onStatus.invoke(VpnStatus.ACTION_REQUIRED_LOGIN)
|
||||||
|
onLoginLink?.invoke(loginLink)
|
||||||
|
}
|
||||||
status.startsWith("ERROR:") -> {
|
status.startsWith("ERROR:") -> {
|
||||||
onLog.invoke("Headless relay error: $status")
|
onLog.invoke("Headless relay error: $status")
|
||||||
onStatus.invoke(VpnStatus.CALL_FAILED)
|
onStatus.invoke(VpnStatus.CALL_FAILED)
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ class HeadlessSessionService : Service() {
|
|||||||
platform == CallPlatform.WBSTREAM ||
|
platform == CallPlatform.WBSTREAM ||
|
||||||
platform == CallPlatform.DION ||
|
platform == CallPlatform.DION ||
|
||||||
platform == CallPlatform.TELEMOST ||
|
platform == CallPlatform.TELEMOST ||
|
||||||
platform == CallPlatform.BITRIX
|
platform == CallPlatform.BITRIX ||
|
||||||
|
platform == CallPlatform.BLINK
|
||||||
if (!headlessMode) {
|
if (!headlessMode) {
|
||||||
showToast(R.string.tile_requires_headless_destination)
|
showToast(R.string.tile_requires_headless_destination)
|
||||||
safeStopSelf()
|
safeStopSelf()
|
||||||
@@ -95,6 +96,7 @@ class HeadlessSessionService : Service() {
|
|||||||
sessionRunning = true
|
sessionRunning = true
|
||||||
controller = HeadlessJoinController(
|
controller = HeadlessJoinController(
|
||||||
applicationInfo.nativeLibraryDir,
|
applicationInfo.nativeLibraryDir,
|
||||||
|
filesDir,
|
||||||
object : JoinFragmentHost {
|
object : JoinFragmentHost {
|
||||||
override fun appendLog(message: String) {
|
override fun appendLog(message: String) {
|
||||||
logWriter.append(message)
|
logWriter.append(message)
|
||||||
@@ -114,6 +116,13 @@ class HeadlessSessionService : Service() {
|
|||||||
updateNotification(text)
|
updateNotification(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onLoginLink(link: String) {
|
||||||
|
logWriter.append(getString(R.string.tile_blink_login_required))
|
||||||
|
updateNotification(getString(R.string.tile_blink_login_required))
|
||||||
|
showToast(R.string.tile_blink_login_required)
|
||||||
|
stopSession(stopDependentServices = true)
|
||||||
|
}
|
||||||
|
|
||||||
override fun requestVpn() {
|
override fun requestVpn() {
|
||||||
if (Prefs.proxyOnly) {
|
if (Prefs.proxyOnly) {
|
||||||
logWriter.append("Proxy only mode, skipping VPN")
|
logWriter.append("Proxy only mode, skipping VPN")
|
||||||
|
|||||||
@@ -16,5 +16,6 @@ enum class VpnStatus(@StringRes val labelRes: Int) {
|
|||||||
CALL_FAILED(R.string.vpn_call_failed),
|
CALL_FAILED(R.string.vpn_call_failed),
|
||||||
PORT_BUSY(R.string.vpn_port_busy),
|
PORT_BUSY(R.string.vpn_port_busy),
|
||||||
VPN_CONFLICT(R.string.vpn_foreign_active),
|
VPN_CONFLICT(R.string.vpn_foreign_active),
|
||||||
ACTION_REQUIRED_CAPTCHA(R.string.action_required_captcha)
|
ACTION_REQUIRED_CAPTCHA(R.string.action_required_captcha),
|
||||||
|
ACTION_REQUIRED_LOGIN(R.string.action_required_login)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package bypass.whitelist.ui
|
||||||
|
|
||||||
|
import android.content.ClipData
|
||||||
|
import android.content.ClipboardManager
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import bypass.whitelist.R
|
||||||
|
import bypass.whitelist.util.Callback
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
|
import com.google.android.material.button.MaterialButton
|
||||||
|
import com.google.zxing.BarcodeFormat
|
||||||
|
import com.journeyapps.barcodescanner.BarcodeEncoder
|
||||||
|
|
||||||
|
class BlinkLoginSheet : BottomSheetDialogFragment() {
|
||||||
|
|
||||||
|
private var loginLink: String = ""
|
||||||
|
private var onCancel: Callback? = null
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
isCancelable = false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?,
|
||||||
|
): View = inflater.inflate(R.layout.sheet_blink_login, container, false)
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
val copy = view.findViewById<MaterialButton>(R.id.buttonCopy)
|
||||||
|
val open = view.findViewById<MaterialButton>(R.id.buttonOpen)
|
||||||
|
val cancel = view.findViewById<MaterialButton>(R.id.buttonCancel)
|
||||||
|
|
||||||
|
copy.setOnClickListener {
|
||||||
|
val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
|
clipboard.setPrimaryClip(ClipData.newPlainText("Blink login link", loginLink))
|
||||||
|
Toast.makeText(requireContext(), R.string.blink_login_copied, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
open.setOnClickListener {
|
||||||
|
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(loginLink)))
|
||||||
|
}
|
||||||
|
cancel.setOnClickListener {
|
||||||
|
onCancel?.invoke()
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
renderLink(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateLink(link: String) {
|
||||||
|
loginLink = link
|
||||||
|
view?.let(::renderLink)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun renderLink(view: View) {
|
||||||
|
val qrSize = (QR_SIZE_DP * resources.displayMetrics.density).toInt()
|
||||||
|
val qr = BarcodeEncoder().encodeBitmap(loginLink, BarcodeFormat.QR_CODE, qrSize, qrSize)
|
||||||
|
view.findViewById<ImageView>(R.id.loginQr).setImageBitmap(qr)
|
||||||
|
view.findViewById<TextView>(R.id.loginLink).text = loginLink
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "BlinkLoginSheet"
|
||||||
|
|
||||||
|
private const val QR_SIZE_DP = 204
|
||||||
|
|
||||||
|
fun show(manager: FragmentManager, loginLink: String, onCancel: Callback) {
|
||||||
|
BlinkLoginSheet().apply {
|
||||||
|
this.loginLink = loginLink
|
||||||
|
this.onCancel = onCancel
|
||||||
|
}.show(manager, TAG)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ interface JoinFragmentHost {
|
|||||||
fun appendLog(message: String)
|
fun appendLog(message: String)
|
||||||
fun onJoinStatus(status: VpnStatus)
|
fun onJoinStatus(status: VpnStatus)
|
||||||
fun onJoinStatusText(text: String)
|
fun onJoinStatusText(text: String)
|
||||||
|
fun onLoginLink(link: String)
|
||||||
fun requestVpn()
|
fun requestVpn()
|
||||||
fun setJoinUiVisible(visible: Boolean)
|
fun setJoinUiVisible(visible: Boolean)
|
||||||
fun onJoinCancel()
|
fun onJoinCancel()
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@color/panel_bg"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:fillViewport="true">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingHorizontal="20dp"
|
||||||
|
android:paddingTop="20dp"
|
||||||
|
android:paddingBottom="22dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/sheetTitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/blink_login_title"
|
||||||
|
android:textColor="@color/ink"
|
||||||
|
android:textSize="17sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/sheetSubtitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="6dp"
|
||||||
|
android:text="@string/blink_login_subtitle"
|
||||||
|
android:textColor="@color/ink_3"
|
||||||
|
android:textSize="13sp" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/loginQr"
|
||||||
|
android:layout_width="220dp"
|
||||||
|
android:layout_height="220dp"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:background="@android:color/white"
|
||||||
|
android:contentDescription="@string/blink_login_title"
|
||||||
|
android:padding="8dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/loginLink"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:textColor="@color/ink_2"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="18dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/buttonCopy"
|
||||||
|
style="@style/Widget.Material3.Button.TonalButton"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/blink_login_copy" />
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/buttonOpen"
|
||||||
|
style="@style/Widget.Material3.Button"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/blink_login_open" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/buttonCancel"
|
||||||
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:text="@string/sheet_cancel" />
|
||||||
|
</LinearLayout>
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
@@ -23,6 +23,12 @@
|
|||||||
<string name="vpn_port_busy" tools:ignore="PluralsCandidate">Port %1$d busy</string>
|
<string name="vpn_port_busy" tools:ignore="PluralsCandidate">Port %1$d busy</string>
|
||||||
<string name="vpn_foreign_active">Another VPN is active. Turn it off first.</string>
|
<string name="vpn_foreign_active">Another VPN is active. Turn it off first.</string>
|
||||||
<string name="action_required_captcha">Action required (captcha)</string>
|
<string name="action_required_captcha">Action required (captcha)</string>
|
||||||
|
<string name="action_required_login">Action required (Blink login)</string>
|
||||||
|
<string name="blink_login_title">Log in to Blink</string>
|
||||||
|
<string name="blink_login_subtitle">Scan the QR with the Blink app on another phone, open the link on this phone, or copy it and send it to whoever has Blink.</string>
|
||||||
|
<string name="blink_login_open">Open in Blink</string>
|
||||||
|
<string name="blink_login_copy">Copy link</string>
|
||||||
|
<string name="blink_login_copied">Login link copied</string>
|
||||||
<string name="captcha_pill_label">Captcha required / id.vk.com</string>
|
<string name="captcha_pill_label">Captcha required / id.vk.com</string>
|
||||||
<string name="jshook_pill_label">Live / interactive page</string>
|
<string name="jshook_pill_label">Live / interactive page</string>
|
||||||
<string name="proxy_settings_title">Proxy</string>
|
<string name="proxy_settings_title">Proxy</string>
|
||||||
@@ -48,6 +54,7 @@
|
|||||||
<string name="dc_mode_not_supported">DC mode not supported - falling back to video</string>
|
<string name="dc_mode_not_supported">DC mode not supported - falling back to video</string>
|
||||||
<string name="tile_requires_headless_destination">Select a headless destination first</string>
|
<string name="tile_requires_headless_destination">Select a headless destination first</string>
|
||||||
<string name="tile_vpn_permission_required">Open the app once and grant VPN permission</string>
|
<string name="tile_vpn_permission_required">Open the app once and grant VPN permission</string>
|
||||||
|
<string name="tile_blink_login_required">Blink login required, connect from the app</string>
|
||||||
|
|
||||||
<string name="nav_main">Main</string>
|
<string name="nav_main">Main</string>
|
||||||
<string name="nav_settings">Settings</string>
|
<string name="nav_settings">Settings</string>
|
||||||
|
|||||||
@@ -148,6 +148,10 @@ func main() {
|
|||||||
c := android.NewBitrixHeadlessJoiner(log.Printf)
|
c := android.NewBitrixHeadlessJoiner(log.Printf)
|
||||||
c.OnConnected = newPersistentJoinerBridge(c.MarkConfigAcked)
|
c.OnConnected = newPersistentJoinerBridge(c.MarkConfigAcked)
|
||||||
c.Run()
|
c.Run()
|
||||||
|
case "blink-headless-joiner":
|
||||||
|
c := android.NewBlinkHeadlessJoiner(log.Printf)
|
||||||
|
c.OnConnected = newPersistentJoinerBridge(c.MarkConfigAcked)
|
||||||
|
c.Run()
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "Unknown mode: %s\n", *mode)
|
fmt.Fprintf(os.Stderr, "Unknown mode: %s\n", *mode)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package android
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"whitelist-bypass/relay/common"
|
||||||
|
joiner "whitelist-bypass/relay/pion/headless-joiner-common"
|
||||||
|
"whitelist-bypass/relay/tunnel"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BlinkHeadlessJoiner struct {
|
||||||
|
inner *joiner.BlinkHeadlessJoiner
|
||||||
|
OnConnected func(tunnel.DataTunnel)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBlinkHeadlessJoiner(logFn func(string, ...any)) *BlinkHeadlessJoiner {
|
||||||
|
if logFn == nil {
|
||||||
|
logFn = log.Printf
|
||||||
|
}
|
||||||
|
inner := joiner.NewBlinkHeadlessJoiner(logFn, RequestResolve, StatusEmitter{}, PCConfigurer{})
|
||||||
|
wrapper := &BlinkHeadlessJoiner{inner: inner}
|
||||||
|
inner.OnConnected = func(tun tunnel.DataTunnel) {
|
||||||
|
if wrapper.OnConnected != nil {
|
||||||
|
wrapper.OnConnected(tun)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) MarkConfigAcked() { j.inner.MarkConfigAcked() }
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) Run() {
|
||||||
|
j.inner.Status.EmitStatus(common.StatusReady)
|
||||||
|
for {
|
||||||
|
line, err := ReadStdinLine()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("blink-joiner: stdin closed: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(line, "JOIN:") {
|
||||||
|
j.inner.RunWithParams(strings.TrimPrefix(line, "JOIN:"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,250 @@
|
|||||||
|
package joiner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/kulikov0/headless-client/webrtc"
|
||||||
|
"whitelist-bypass/relay/blink"
|
||||||
|
"whitelist-bypass/relay/common"
|
||||||
|
"whitelist-bypass/relay/tunnel"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BlinkHeadlessJoiner struct {
|
||||||
|
logFn func(string, ...any)
|
||||||
|
OnConnected func(tunnel.DataTunnel)
|
||||||
|
ResolveFn ResolveFunc
|
||||||
|
Status StatusEmitter
|
||||||
|
PCConfig PeerConnectionConfigurer
|
||||||
|
|
||||||
|
httpClient *http.Client
|
||||||
|
cookiesPath string
|
||||||
|
|
||||||
|
mu sync.Mutex
|
||||||
|
session *blink.Session
|
||||||
|
closed bool
|
||||||
|
stopCh chan struct{}
|
||||||
|
stopOnce sync.Once
|
||||||
|
}
|
||||||
|
|
||||||
|
type blinkJoinParams struct {
|
||||||
|
JoinLink string `json:"joinLink"`
|
||||||
|
CookiesPath string `json:"cookiesPath"`
|
||||||
|
TunnelMode string `json:"tunnelMode"`
|
||||||
|
VP8FPS int `json:"vp8Fps"`
|
||||||
|
VP8Batch int `json:"vp8Batch"`
|
||||||
|
DualTrack bool `json:"dualTrack"`
|
||||||
|
Reliable *bool `json:"reliable"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBlinkHeadlessJoiner(logFn func(string, ...any), resolveFn ResolveFunc, status StatusEmitter, pcConfig PeerConnectionConfigurer) *BlinkHeadlessJoiner {
|
||||||
|
return &BlinkHeadlessJoiner{
|
||||||
|
logFn: logFn,
|
||||||
|
ResolveFn: resolveFn,
|
||||||
|
Status: status,
|
||||||
|
PCConfig: pcConfig,
|
||||||
|
stopCh: make(chan struct{}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) RunWithParams(jsonParams string) {
|
||||||
|
var params blinkJoinParams
|
||||||
|
if err := json.Unmarshal([]byte(jsonParams), ¶ms); err != nil {
|
||||||
|
j.logFn("blink-joiner: failed to parse params: %v", err)
|
||||||
|
j.Status.EmitStatusError("bad params: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if params.JoinLink == "" || params.CookiesPath == "" {
|
||||||
|
j.logFn("blink-joiner: missing joinLink or cookiesPath")
|
||||||
|
j.Status.EmitStatusError("missing joinLink or cookiesPath")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
j.httpClient = resolvingHTTPClient(j.ResolveFn)
|
||||||
|
j.cookiesPath = params.CookiesPath
|
||||||
|
|
||||||
|
credentials, err := j.loadCredentials()
|
||||||
|
if err != nil {
|
||||||
|
j.logFn("blink-joiner: login failed: %v", err)
|
||||||
|
j.Status.EmitStatusError("login: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
chatID, err := retryAfterLogin(j, func() (int64, error) {
|
||||||
|
return credentials.ResolveChatID(params.JoinLink)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
j.logFn("blink-joiner: bad join link: %v", err)
|
||||||
|
j.Status.EmitStatusError("bad join link: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
j.logFn("blink-joiner: chat=%d vp8Fps=%d vp8Batch=%d dualTrack=%v", chatID, params.VP8FPS, params.VP8Batch, params.DualTrack)
|
||||||
|
|
||||||
|
keySource := strconv.FormatInt(chatID, 10)
|
||||||
|
obf, err := tunnel.NewTunnelObfuscator(tunnel.DeriveSecretFromJoinLink(keySource))
|
||||||
|
if err != nil {
|
||||||
|
j.logFn("blink-joiner: obfuscator init failed: %v", err)
|
||||||
|
j.Status.EmitStatusError("obfuscator init: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
j.logFn("blink-joiner: obf key-source=%q localEpoch=0x%08x", keySource, obf.LocalEpoch())
|
||||||
|
|
||||||
|
var configureSettingEngine func(*webrtc.SettingEngine)
|
||||||
|
if j.PCConfig != nil {
|
||||||
|
configureSettingEngine = j.PCConfig.ConfigureSettingEngine
|
||||||
|
}
|
||||||
|
|
||||||
|
var attempt atomic.Int32
|
||||||
|
|
||||||
|
j.Status.EmitStatus(common.StatusConnecting)
|
||||||
|
if err := j.runOnce(credentials, chatID, params, obf, configureSettingEngine, &attempt); err != nil {
|
||||||
|
j.Status.EmitStatusError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
if j.isClosed() {
|
||||||
|
j.logFn("blink-joiner: stopped")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
j.Status.EmitStatus(common.StatusTunnelLost)
|
||||||
|
if !j.waitBeforeRetry(int(attempt.Load())) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
attempt.Add(1)
|
||||||
|
if j.isClosed() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
j.logFn("blink-joiner: reconnect attempt #%d", attempt.Load())
|
||||||
|
j.Status.EmitStatus(common.StatusReconnecting)
|
||||||
|
if err := j.runOnce(credentials, chatID, params, obf, configureSettingEngine, &attempt); err != nil {
|
||||||
|
j.logFn("blink-joiner: %v, will retry", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) MarkConfigAcked() {
|
||||||
|
j.mu.Lock()
|
||||||
|
sess := j.session
|
||||||
|
j.mu.Unlock()
|
||||||
|
if sess != nil {
|
||||||
|
sess.MarkConfigAcked()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) Close() {
|
||||||
|
j.stopOnce.Do(func() { close(j.stopCh) })
|
||||||
|
j.mu.Lock()
|
||||||
|
j.closed = true
|
||||||
|
sess := j.session
|
||||||
|
j.session = nil
|
||||||
|
j.mu.Unlock()
|
||||||
|
if sess != nil {
|
||||||
|
sess.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) runOnce(credentials *blink.Credentials, chatID int64, params blinkJoinParams, obf *tunnel.TunnelObfuscator, configureSettingEngine func(*webrtc.SettingEngine), attempt *atomic.Int32) error {
|
||||||
|
connection, err := retryAfterLogin(j, func() (blink.CallConnection, error) {
|
||||||
|
return credentials.ConnectCall(chatID)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
j.logFn("blink-joiner: call=%s created=%v endpoint=%s", connection.CallID, connection.Created, connection.APIEndpoint)
|
||||||
|
if connection.Created {
|
||||||
|
j.logFn("blink-joiner: the chat had no active call, this joiner started a new one and the creator is not in it")
|
||||||
|
}
|
||||||
|
|
||||||
|
sess := blink.NewSession(blink.SessionConfig{
|
||||||
|
RoomToken: connection.Token,
|
||||||
|
ServerURL: connection.APIEndpoint,
|
||||||
|
TunnelMode: params.TunnelMode,
|
||||||
|
Obfuscator: obf,
|
||||||
|
LogFn: j.logFn,
|
||||||
|
ConfigureSettingEngine: configureSettingEngine,
|
||||||
|
NetDialContext: resolvingDialContext(j.ResolveFn),
|
||||||
|
ResolveICEHost: j.ResolveFn,
|
||||||
|
VP8FPS: params.VP8FPS,
|
||||||
|
VP8Batch: params.VP8Batch,
|
||||||
|
ScreenShare: params.DualTrack,
|
||||||
|
IsJoiner: true,
|
||||||
|
Reliable: params.Reliable != nil && *params.Reliable,
|
||||||
|
})
|
||||||
|
sess.OnConnected = func(tun tunnel.DataTunnel) {
|
||||||
|
attempt.Store(0)
|
||||||
|
j.logFn("blink-joiner: === TUNNEL CONNECTED ===")
|
||||||
|
j.Status.EmitStatus(common.StatusTunnelConnected)
|
||||||
|
if j.OnConnected != nil {
|
||||||
|
j.OnConnected(tun)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
j.mu.Lock()
|
||||||
|
if j.closed {
|
||||||
|
j.mu.Unlock()
|
||||||
|
sess.Close()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
j.session = sess
|
||||||
|
j.mu.Unlock()
|
||||||
|
|
||||||
|
if err := sess.Start(); err != nil {
|
||||||
|
j.clearSession(sess)
|
||||||
|
return fmt.Errorf("session: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
<-sess.Done()
|
||||||
|
sess.Close()
|
||||||
|
j.clearSession(sess)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) loadCredentials() (*blink.Credentials, error) {
|
||||||
|
credentials, err := blink.LoadCredentials(j.cookiesPath, j.httpClient, j.logFn)
|
||||||
|
if err == nil {
|
||||||
|
return credentials, nil
|
||||||
|
}
|
||||||
|
j.logFn("blink-joiner: no saved login, waiting for a new one: %v", err)
|
||||||
|
if err := j.login(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return blink.LoadCredentials(j.cookiesPath, j.httpClient, j.logFn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) login() error {
|
||||||
|
return blink.LoginToFile(j.cookiesPath, j.httpClient, j.Status.EmitStatus, j.logFn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) waitBeforeRetry(attempt int) bool {
|
||||||
|
return waitReconnectBackoff(attempt, j.logFn, "blink-joiner", j.stopCh, j.isClosed)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) clearSession(sess *blink.Session) {
|
||||||
|
j.mu.Lock()
|
||||||
|
if j.session == sess {
|
||||||
|
j.session = nil
|
||||||
|
}
|
||||||
|
j.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *BlinkHeadlessJoiner) isClosed() bool {
|
||||||
|
j.mu.Lock()
|
||||||
|
defer j.mu.Unlock()
|
||||||
|
return j.closed
|
||||||
|
}
|
||||||
|
|
||||||
|
func retryAfterLogin[T any](j *BlinkHeadlessJoiner, request func() (T, error)) (T, error) {
|
||||||
|
result, err := request()
|
||||||
|
if !blink.IsUnauthorized(err) {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
j.logFn("blink-joiner: the saved login is no longer valid, waiting for a new one: %v", err)
|
||||||
|
if err := j.login(); err != nil {
|
||||||
|
var empty T
|
||||||
|
return empty, err
|
||||||
|
}
|
||||||
|
return request()
|
||||||
|
}
|
||||||
Reference in new issue
Block a user