обновление для приложения (#118)
* feat(android): rename to whitelistbypass and implement various UI, settings, and service enhancements * fix(android): prevent crash on service stop * Fix PORT_BUSY uncaught exception crash * fix(android): improve app stability and fix port 1080 busy * final fix * sync with main branch * fix(android): harden disconnect and session shutdown * cleanup imports/callbacks * more refactor * edit profiles for a specific call via settings, resolve errors/issues during ide analysis * fix callback in main fragment --------- Co-authored-by: kulikov0 <19497634+kulikov0@users.noreply.github.com>
This commit is contained in:
1 parent
dfdc494340
commit
98525f333c
39 files changed
+1684
-406
No files matched your search
@@ -62,7 +62,7 @@ dependencies {
|
|||||||
implementation(libs.material)
|
implementation(libs.material)
|
||||||
implementation(libs.androidx.activity)
|
implementation(libs.androidx.activity)
|
||||||
implementation(libs.androidx.constraintlayout)
|
implementation(libs.androidx.constraintlayout)
|
||||||
debugImplementation(libs.leakcanary.android)
|
implementation("androidx.viewpager2:viewpager2:1.1.0")
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
androidTestImplementation(libs.androidx.espresso.core)
|
androidTestImplementation(libs.androidx.espresso.core)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
||||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||||
tools:ignore="QueryAllPackagesPermission" />
|
tools:ignore="QueryAllPackagesPermission" />
|
||||||
|
|
||||||
@@ -30,6 +29,9 @@
|
|||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<service
|
<service
|
||||||
android:name=".tunnel.TunnelVpnService"
|
android:name=".tunnel.TunnelVpnService"
|
||||||
@@ -44,6 +46,10 @@
|
|||||||
android:name=".tunnel.ProxyService"
|
android:name=".tunnel.ProxyService"
|
||||||
android:foregroundServiceType="specialUse"
|
android:foregroundServiceType="specialUse"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
<service
|
||||||
|
android:name=".tunnel.HeadlessSessionService"
|
||||||
|
android:foregroundServiceType="specialUse"
|
||||||
|
android:exported="false" />
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.core.content.FileProvider"
|
android:name="androidx.core.content.FileProvider"
|
||||||
android:authorities="${applicationId}.fileprovider"
|
android:authorities="${applicationId}.fileprovider"
|
||||||
@@ -53,6 +59,16 @@
|
|||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/file_paths" />
|
android:resource="@xml/file_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
<service
|
||||||
|
android:name=".tunnel.VpnTileService"
|
||||||
|
android:label="whitelistbypass"
|
||||||
|
android:icon="@drawable/ic_power"
|
||||||
|
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,30 +1,46 @@
|
|||||||
package bypass.whitelist
|
package bypass.whitelist
|
||||||
|
|
||||||
|
import android.animation.ArgbEvaluator
|
||||||
|
import android.content.ClipData
|
||||||
|
import android.content.ClipboardManager
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.animation.AccelerateDecelerateInterpolator
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.ScrollView
|
||||||
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.core.view.doOnLayout
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
import bypass.whitelist.tunnel.CallConfig
|
import bypass.whitelist.tunnel.CallConfig
|
||||||
import bypass.whitelist.tunnel.CallPlatform
|
import bypass.whitelist.tunnel.CallPlatform
|
||||||
import bypass.whitelist.tunnel.HeadlessJoinController
|
import bypass.whitelist.tunnel.HeadlessJoinController
|
||||||
|
import bypass.whitelist.tunnel.HeadlessSessionService
|
||||||
|
import bypass.whitelist.tunnel.PortGuard
|
||||||
import bypass.whitelist.tunnel.ProxyService
|
import bypass.whitelist.tunnel.ProxyService
|
||||||
import bypass.whitelist.tunnel.TunnelMode
|
import bypass.whitelist.tunnel.TunnelMode
|
||||||
|
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.LogsFragment
|
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
|
||||||
|
import bypass.whitelist.ui.JoinSessionShutdown
|
||||||
import bypass.whitelist.ui.JsHookJoinFragment
|
import bypass.whitelist.ui.JsHookJoinFragment
|
||||||
|
import bypass.whitelist.ui.LogsFragment
|
||||||
import bypass.whitelist.ui.MainActivityHost
|
import bypass.whitelist.ui.MainActivityHost
|
||||||
import bypass.whitelist.ui.MainFragment
|
import bypass.whitelist.ui.MainFragment
|
||||||
import bypass.whitelist.ui.SettingsScreenFragment
|
import bypass.whitelist.ui.SettingsScreenFragment
|
||||||
@@ -33,10 +49,6 @@ import bypass.whitelist.util.Net
|
|||||||
import bypass.whitelist.util.Prefs
|
import bypass.whitelist.util.Prefs
|
||||||
import bypass.whitelist.util.SocksAuth
|
import bypass.whitelist.util.SocksAuth
|
||||||
import bypass.whitelist.util.maskUrl
|
import bypass.whitelist.util.maskUrl
|
||||||
import android.widget.ImageView
|
|
||||||
import android.widget.LinearLayout
|
|
||||||
import android.widget.TextView
|
|
||||||
import bypass.whitelist.ui.CallsListener
|
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.net.Socket
|
import java.net.Socket
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
@@ -56,22 +68,31 @@ class MainActivity :
|
|||||||
private lateinit var navMain: LinearLayout
|
private lateinit var navMain: LinearLayout
|
||||||
private lateinit var navSettings: LinearLayout
|
private lateinit var navSettings: LinearLayout
|
||||||
private lateinit var navLogs: LinearLayout
|
private lateinit var navLogs: LinearLayout
|
||||||
private lateinit var tabContainer: View
|
private lateinit var navMainIcon: ImageView
|
||||||
|
private lateinit var navSettingsIcon: ImageView
|
||||||
|
private lateinit var navLogsIcon: ImageView
|
||||||
|
private lateinit var navMainLabel: TextView
|
||||||
|
private lateinit var navSettingsLabel: TextView
|
||||||
|
private lateinit var navLogsLabel: TextView
|
||||||
|
private lateinit var tabContainer: ViewPager2
|
||||||
|
private lateinit var navIndicator: View
|
||||||
private lateinit var subPageContainer: View
|
private lateinit var subPageContainer: View
|
||||||
private lateinit var joinOverlayContainer: View
|
private lateinit var joinOverlayContainer: View
|
||||||
private lateinit var overlayLogs: View
|
private lateinit var overlayLogs: View
|
||||||
private lateinit var overlayLogsText: TextView
|
private lateinit var overlayLogsText: TextView
|
||||||
private lateinit var overlayLogsScroll: android.widget.ScrollView
|
private lateinit var overlayLogsScroll: ScrollView
|
||||||
private var currentTabId: Int = 0
|
|
||||||
|
|
||||||
|
private var currentTabId: Int = 0
|
||||||
private var lastStatus: VpnStatus? = null
|
private var lastStatus: VpnStatus? = null
|
||||||
private var connected: Boolean = false
|
private var connected: Boolean = false
|
||||||
private var activeJoinUrl: String = ""
|
private var activeJoinUrl: String = ""
|
||||||
private var activeHeadlessController: HeadlessJoinController? = null
|
private var activeHeadlessController: HeadlessJoinController? = null
|
||||||
|
private var navPageChangeCallback: ViewPager2.OnPageChangeCallback? = null
|
||||||
private val vpnPrepLauncher = registerForActivityResult(
|
private var navScrollState: Int = ViewPager2.SCROLL_STATE_IDLE
|
||||||
ActivityResultContracts.StartActivityForResult()
|
@Volatile private var resetInProgress: Boolean = false
|
||||||
) {}
|
@Volatile private var resetGeneration: Long = 0L
|
||||||
|
private var pendingConnectConfig: CallConfig? = null
|
||||||
|
private val navColorEvaluator = ArgbEvaluator()
|
||||||
|
|
||||||
private val vpnLauncher = registerForActivityResult(
|
private val vpnLauncher = registerForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.StartActivityForResult()
|
||||||
@@ -89,21 +110,74 @@ class MainActivity :
|
|||||||
navMain = findViewById(R.id.navMain)
|
navMain = findViewById(R.id.navMain)
|
||||||
navSettings = findViewById(R.id.navSettings)
|
navSettings = findViewById(R.id.navSettings)
|
||||||
navLogs = findViewById(R.id.navLogs)
|
navLogs = findViewById(R.id.navLogs)
|
||||||
|
navMainIcon = findViewById(R.id.navMainIcon)
|
||||||
|
navSettingsIcon = findViewById(R.id.navSettingsIcon)
|
||||||
|
navLogsIcon = findViewById(R.id.navLogsIcon)
|
||||||
|
navMainLabel = findViewById(R.id.navMainLabel)
|
||||||
|
navSettingsLabel = findViewById(R.id.navSettingsLabel)
|
||||||
|
navLogsLabel = findViewById(R.id.navLogsLabel)
|
||||||
tabContainer = findViewById(R.id.tabContainer)
|
tabContainer = findViewById(R.id.tabContainer)
|
||||||
|
navIndicator = findViewById(R.id.navIndicator)
|
||||||
subPageContainer = findViewById(R.id.subPageContainer)
|
subPageContainer = findViewById(R.id.subPageContainer)
|
||||||
joinOverlayContainer = findViewById(R.id.joinOverlayContainer)
|
joinOverlayContainer = findViewById(R.id.joinOverlayContainer)
|
||||||
overlayLogs = findViewById(R.id.overlayLogs)
|
overlayLogs = findViewById(R.id.overlayLogs)
|
||||||
overlayLogsText = findViewById(R.id.overlayLogsText)
|
overlayLogsText = findViewById(R.id.overlayLogsText)
|
||||||
overlayLogsScroll = findViewById(R.id.overlayLogsScroll)
|
overlayLogsScroll = findViewById(R.id.overlayLogsScroll)
|
||||||
|
|
||||||
|
tabContainer.adapter = object : FragmentStateAdapter(this) {
|
||||||
|
override fun getItemCount(): Int = 3
|
||||||
|
override fun createFragment(position: Int): Fragment {
|
||||||
|
return when (position) {
|
||||||
|
TAB_MAIN -> MainFragment()
|
||||||
|
TAB_SETTINGS -> SettingsScreenFragment()
|
||||||
|
else -> LogsFragment()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tabContainer.offscreenPageLimit = 3
|
||||||
|
|
||||||
|
navPageChangeCallback = object : ViewPager2.OnPageChangeCallback() {
|
||||||
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||||
|
moveNavIndicatorForPager(position, positionOffset)
|
||||||
|
interpolateNavSelection(position, positionOffset)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageSelected(position: Int) {
|
||||||
|
currentTabId = when (position) {
|
||||||
|
TAB_MAIN -> R.id.navMain
|
||||||
|
TAB_SETTINGS -> R.id.navSettings
|
||||||
|
TAB_LOGS -> R.id.navLogs
|
||||||
|
else -> return
|
||||||
|
}
|
||||||
|
if (navScrollState == ViewPager2.SCROLL_STATE_IDLE) {
|
||||||
|
updateNavSelection(currentTabId)
|
||||||
|
}
|
||||||
|
settingsFragment()?.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
|
navScrollState = state
|
||||||
|
if (state == ViewPager2.SCROLL_STATE_IDLE) {
|
||||||
|
updateNavSelection(currentTabId)
|
||||||
|
moveNavIndicatorTo(currentTabId, animate = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.also(tabContainer::registerOnPageChangeCallback)
|
||||||
|
|
||||||
findViewById<View>(R.id.overlayCopyButton).setOnClickListener { copyLogs() }
|
findViewById<View>(R.id.overlayCopyButton).setOnClickListener { copyLogs() }
|
||||||
findViewById<View>(R.id.overlayShareButton).setOnClickListener { shareLogs() }
|
findViewById<View>(R.id.overlayShareButton).setOnClickListener { shareLogs() }
|
||||||
|
|
||||||
val baseTabPaddingTop = tabContainer.paddingTop
|
val baseTabPaddingTop = findViewById<View>(R.id.tabContainerWrap).paddingTop
|
||||||
val bottomWrap = findViewById<View>(R.id.bottomWrap)
|
val bottomWrap = findViewById<View>(R.id.bottomWrap)
|
||||||
val baseBottomWrapPaddingBottom = bottomWrap.paddingBottom
|
val baseBottomWrapPaddingBottom = bottomWrap.paddingBottom
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { _, insets ->
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { _, insets ->
|
||||||
val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
tabContainer.setPadding(bars.left, baseTabPaddingTop + bars.top, bars.right, 0)
|
findViewById<View>(R.id.tabContainerWrap).setPadding(
|
||||||
|
bars.left,
|
||||||
|
baseTabPaddingTop + bars.top,
|
||||||
|
bars.right,
|
||||||
|
0
|
||||||
|
)
|
||||||
subPageContainer.setPadding(bars.left, bars.top, bars.right, 0)
|
subPageContainer.setPadding(bars.left, bars.top, bars.right, 0)
|
||||||
joinOverlayContainer.setPadding(bars.left, bars.top, bars.right, 0)
|
joinOverlayContainer.setPadding(bars.left, bars.top, bars.right, 0)
|
||||||
bottomWrap.setPadding(
|
bottomWrap.setPadding(
|
||||||
@@ -121,24 +195,101 @@ class MainActivity :
|
|||||||
|
|
||||||
val restoredTabId =
|
val restoredTabId =
|
||||||
savedInstanceState?.getInt(STATE_CURRENT_TAB_ID, R.id.navMain) ?: R.id.navMain
|
savedInstanceState?.getInt(STATE_CURRENT_TAB_ID, R.id.navMain) ?: R.id.navMain
|
||||||
selectNavTab(restoredTabId)
|
selectNavTab(restoredTabId, animatePager = false)
|
||||||
|
findViewById<View>(R.id.navItemsRow).doOnLayout {
|
||||||
|
moveNavIndicatorTo(currentTabId, animate = false)
|
||||||
|
}
|
||||||
|
|
||||||
TunnelVpnService.onDisconnect = { runOnUiThread { onDisconnectFromService() } }
|
TunnelVpnService.onDisconnect = { runOnUiThread { onDisconnectFromService() } }
|
||||||
ProxyService.onDisconnect = { runOnUiThread { onDisconnectFromService() } }
|
ProxyService.onDisconnect = { runOnUiThread { onDisconnectFromService() } }
|
||||||
|
|
||||||
VpnService.prepare(this)?.let { vpnPrepLauncher.launch(it) }
|
if (CALL_LINK.isNotEmpty() && !TunnelServiceState.isAnyTunnelComponentRunning(this)) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
|
startJoinFor(CallConfig.newWith(name = CallConfig.suggestNameFor(CALL_LINK), url = CALL_LINK))
|
||||||
checkSelfPermission(android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED
|
} else if (Prefs.connectOnStart && !TunnelServiceState.isAnyTunnelComponentRunning(this)) {
|
||||||
) {
|
Prefs.activeDestination?.let(::startJoinFor)
|
||||||
requestPermissions(arrayOf(android.Manifest.permission.POST_NOTIFICATIONS), 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CALL_LINK.isNotEmpty()) {
|
handleIntent(intent)
|
||||||
startJoinFor(CallConfig.newWith(name = CallConfig.suggestNameFor(CALL_LINK), url = CALL_LINK))
|
|
||||||
} else if (Prefs.connectOnStart) {
|
|
||||||
val active = Prefs.activeDestination
|
|
||||||
if (active != null) startJoinFor(active)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
TunnelVpnService.onDisconnect = { runOnUiThread { onDisconnectFromService() } }
|
||||||
|
ProxyService.onDisconnect = { runOnUiThread { onDisconnectFromService() } }
|
||||||
|
|
||||||
|
TunnelServiceState.vpnStatusCallback = { status ->
|
||||||
|
runOnUiThread {
|
||||||
|
if (resetInProgress) {
|
||||||
|
mainFragment()?.onStatusChanged(VpnStatus.STOPPING)
|
||||||
|
mainFragment()?.onStatusTextChanged("Stopping previous session...")
|
||||||
|
return@runOnUiThread
|
||||||
|
}
|
||||||
|
lastStatus = status
|
||||||
|
mainFragment()?.onStatusChanged(status)
|
||||||
|
if (status == VpnStatus.TUNNEL_ACTIVE) {
|
||||||
|
if (!connected) {
|
||||||
|
connected = true
|
||||||
|
mainFragment()?.onConnectedChanged(true)
|
||||||
|
}
|
||||||
|
} else if (status == VpnStatus.CALL_FAILED || status == VpnStatus.CALL_DISCONNECTED || status == VpnStatus.TUNNEL_LOST) {
|
||||||
|
if (connected) {
|
||||||
|
connected = false
|
||||||
|
mainFragment()?.onConnectedChanged(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TunnelServiceState.logCallback = { message ->
|
||||||
|
runOnUiThread { appendLog(message) }
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
resetInProgress -> {
|
||||||
|
connected = false
|
||||||
|
lastStatus = VpnStatus.STOPPING
|
||||||
|
mainFragment()?.onConnectedChanged(false)
|
||||||
|
mainFragment()?.onStatusChanged(VpnStatus.STOPPING)
|
||||||
|
mainFragment()?.onStatusTextChanged("Stopping previous session...")
|
||||||
|
}
|
||||||
|
TunnelServiceState.isTunnelActive(this) -> {
|
||||||
|
if (!connected || lastStatus != VpnStatus.TUNNEL_ACTIVE) {
|
||||||
|
connected = true
|
||||||
|
lastStatus = VpnStatus.TUNNEL_ACTIVE
|
||||||
|
mainFragment()?.onStatusChanged(VpnStatus.TUNNEL_ACTIVE)
|
||||||
|
mainFragment()?.onConnectedChanged(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TunnelServiceState.isHeadlessSessionRunning(this) -> {
|
||||||
|
connected = false
|
||||||
|
lastStatus = VpnStatus.CONNECTING
|
||||||
|
mainFragment()?.onConnectedChanged(false)
|
||||||
|
mainFragment()?.onStatusChanged(VpnStatus.CONNECTING)
|
||||||
|
}
|
||||||
|
connected && lastStatus == VpnStatus.TUNNEL_ACTIVE -> {
|
||||||
|
onDisconnectFromService()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
TunnelServiceState.vpnStatusCallback = null
|
||||||
|
TunnelServiceState.logCallback = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
navPageChangeCallback?.let(tabContainer::unregisterOnPageChangeCallback)
|
||||||
|
navPageChangeCallback = null
|
||||||
|
TunnelVpnService.onDisconnect = null
|
||||||
|
ProxyService.onDisconnect = null
|
||||||
|
logWriter.close()
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
handleIntent(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
@@ -146,99 +297,28 @@ class MainActivity :
|
|||||||
outState.putInt(STATE_CURRENT_TAB_ID, currentTabId)
|
outState.putInt(STATE_CURRENT_TAB_ID, currentTabId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
TunnelVpnService.onDisconnect = null
|
|
||||||
TunnelVpnService.instance?.stop()
|
|
||||||
ProxyService.onDisconnect = null
|
|
||||||
ProxyService.instance?.stop()
|
|
||||||
logWriter.close()
|
|
||||||
super.onDestroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun selectNavTab(itemId: Int) {
|
|
||||||
if (currentTabId == itemId) return
|
|
||||||
currentTabId = itemId
|
|
||||||
dismissSubPage()
|
|
||||||
when (itemId) {
|
|
||||||
R.id.navMain -> showTab(MainFragment::class.java)
|
|
||||||
R.id.navSettings -> showTab(SettingsScreenFragment::class.java)
|
|
||||||
R.id.navLogs -> showTab(LogsFragment::class.java)
|
|
||||||
}
|
|
||||||
updateNavSelection(itemId)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateNavSelection(itemId: Int) {
|
|
||||||
val transparent = android.graphics.Color.TRANSPARENT
|
|
||||||
val activeBg = R.drawable.bg_nav_item_active
|
|
||||||
val accent = getColor(R.color.accent_emerald)
|
|
||||||
val ink3 = getColor(R.color.ink_3)
|
|
||||||
|
|
||||||
listOf(navMain, navSettings, navLogs).forEach { it.setBackgroundColor(transparent) }
|
|
||||||
findViewById<ImageView>(R.id.navMainIcon).setColorFilter(ink3)
|
|
||||||
findViewById<ImageView>(R.id.navSettingsIcon).setColorFilter(ink3)
|
|
||||||
findViewById<ImageView>(R.id.navLogsIcon).setColorFilter(ink3)
|
|
||||||
findViewById<TextView>(R.id.navMainLabel).apply {
|
|
||||||
setTextColor(ink3); setTypeface(typeface, android.graphics.Typeface.NORMAL)
|
|
||||||
}
|
|
||||||
findViewById<TextView>(R.id.navSettingsLabel).apply {
|
|
||||||
setTextColor(ink3); setTypeface(typeface, android.graphics.Typeface.NORMAL)
|
|
||||||
}
|
|
||||||
findViewById<TextView>(R.id.navLogsLabel).apply {
|
|
||||||
setTextColor(ink3); setTypeface(typeface, android.graphics.Typeface.NORMAL)
|
|
||||||
}
|
|
||||||
val activeContainer = when (itemId) {
|
|
||||||
R.id.navMain -> navMain
|
|
||||||
R.id.navSettings -> navSettings
|
|
||||||
R.id.navLogs -> navLogs
|
|
||||||
else -> null
|
|
||||||
} ?: return
|
|
||||||
activeContainer.setBackgroundResource(activeBg)
|
|
||||||
val activeIcon = when (itemId) {
|
|
||||||
R.id.navMain -> R.id.navMainIcon
|
|
||||||
R.id.navSettings -> R.id.navSettingsIcon
|
|
||||||
R.id.navLogs -> R.id.navLogsIcon
|
|
||||||
else -> 0
|
|
||||||
}
|
|
||||||
val activeLabel = when (itemId) {
|
|
||||||
R.id.navMain -> R.id.navMainLabel
|
|
||||||
R.id.navSettings -> R.id.navSettingsLabel
|
|
||||||
R.id.navLogs -> R.id.navLogsLabel
|
|
||||||
else -> 0
|
|
||||||
}
|
|
||||||
findViewById<ImageView>(activeIcon).setColorFilter(accent)
|
|
||||||
findViewById<TextView>(activeLabel).apply {
|
|
||||||
setTextColor(accent)
|
|
||||||
setTypeface(typeface, android.graphics.Typeface.BOLD)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showTab(cls: Class<out Fragment>) {
|
|
||||||
val tag = cls.name
|
|
||||||
val existing = supportFragmentManager.findFragmentByTag(tag)
|
|
||||||
val tx = supportFragmentManager.beginTransaction()
|
|
||||||
supportFragmentManager.fragments
|
|
||||||
.filter { it.id == R.id.tabContainer && it.tag != tag }
|
|
||||||
.forEach { tx.hide(it) }
|
|
||||||
if (existing == null) {
|
|
||||||
tx.add(R.id.tabContainer, cls.getDeclaredConstructor().newInstance(), tag)
|
|
||||||
} else {
|
|
||||||
tx.show(existing)
|
|
||||||
if (existing is LogsFragment) existing.refresh()
|
|
||||||
}
|
|
||||||
tx.commit()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun mainFragment(): MainFragment? =
|
|
||||||
supportFragmentManager.findFragmentByTag(MainFragment::class.java.name) as? MainFragment
|
|
||||||
|
|
||||||
private fun logsFragment(): LogsFragment? =
|
|
||||||
supportFragmentManager.findFragmentByTag(LogsFragment::class.java.name) as? LogsFragment
|
|
||||||
|
|
||||||
override fun onConnectPressed(config: CallConfig) {
|
override fun onConnectPressed(config: CallConfig) {
|
||||||
|
if (resetInProgress) {
|
||||||
|
pendingConnectConfig = config
|
||||||
|
appendLog("Queued connect after previous session stops")
|
||||||
|
mainFragment()?.onStatusTextChanged("Stopping previous session...")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (TunnelServiceState.isAnyTunnelComponentRunning(this) || !PortGuard.isPortAvailable(Prefs.socksPort)) {
|
||||||
|
pendingConnectConfig = config
|
||||||
|
appendLog("Waiting for previous local tunnel to stop")
|
||||||
|
fullReset()
|
||||||
|
return
|
||||||
|
}
|
||||||
startJoinFor(config)
|
startJoinFor(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDisconnectPressed() {
|
override fun onDisconnectPressed() {
|
||||||
|
pendingConnectConfig = null
|
||||||
|
if (resetInProgress) {
|
||||||
|
forceUnlockReset("Stopped waiting for previous session")
|
||||||
|
return
|
||||||
|
}
|
||||||
fullReset()
|
fullReset()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,43 +335,6 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun probeViaSocks5(host: String, port: Int): Boolean {
|
|
||||||
Socket().use { socket ->
|
|
||||||
socket.connect(InetSocketAddress(Net.LOCALHOST, Prefs.socksPort.toInt()), 5000)
|
|
||||||
socket.soTimeout = 15000
|
|
||||||
val output = socket.getOutputStream()
|
|
||||||
val input = socket.getInputStream()
|
|
||||||
|
|
||||||
output.write(byteArrayOf(0x05, 0x01, 0x02))
|
|
||||||
output.flush()
|
|
||||||
if (input.read() != 0x05 || input.read() != 0x02) return false
|
|
||||||
|
|
||||||
val userBytes = SocksAuth.user.toByteArray(Charsets.US_ASCII)
|
|
||||||
val passBytes = SocksAuth.pass.toByteArray(Charsets.US_ASCII)
|
|
||||||
val authPacket = ByteArray(3 + userBytes.size + passBytes.size)
|
|
||||||
authPacket[0] = 0x01
|
|
||||||
authPacket[1] = userBytes.size.toByte()
|
|
||||||
System.arraycopy(userBytes, 0, authPacket, 2, userBytes.size)
|
|
||||||
authPacket[2 + userBytes.size] = passBytes.size.toByte()
|
|
||||||
System.arraycopy(passBytes, 0, authPacket, 3 + userBytes.size, passBytes.size)
|
|
||||||
output.write(authPacket)
|
|
||||||
output.flush()
|
|
||||||
if (input.read() != 0x01 || input.read() != 0x00) return false
|
|
||||||
|
|
||||||
val hostBytes = host.toByteArray(Charsets.US_ASCII)
|
|
||||||
val request = ByteArray(4 + 1 + hostBytes.size + 2)
|
|
||||||
request[0] = 0x05; request[1] = 0x01; request[2] = 0x00; request[3] = 0x03
|
|
||||||
request[4] = hostBytes.size.toByte()
|
|
||||||
System.arraycopy(hostBytes, 0, request, 5, hostBytes.size)
|
|
||||||
request[5 + hostBytes.size] = ((port shr 8) and 0xff).toByte()
|
|
||||||
request[6 + hostBytes.size] = (port and 0xff).toByte()
|
|
||||||
output.write(request)
|
|
||||||
output.flush()
|
|
||||||
|
|
||||||
return input.read() == 0x05 && input.read() == 0x00
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isTunnelActive(): Boolean = connected
|
override fun isTunnelActive(): Boolean = connected
|
||||||
|
|
||||||
override fun currentStatus(): VpnStatus? = lastStatus
|
override fun currentStatus(): VpnStatus? = lastStatus
|
||||||
@@ -320,7 +363,7 @@ class MainActivity :
|
|||||||
override fun onResetAllSettings() {
|
override fun onResetAllSettings() {
|
||||||
Prefs.resetAllSettings()
|
Prefs.resetAllSettings()
|
||||||
App.applyTheme(Prefs.themeMode)
|
App.applyTheme(Prefs.themeMode)
|
||||||
(supportFragmentManager.findFragmentByTag(SettingsScreenFragment::class.java.name) as? SettingsScreenFragment)?.refresh()
|
settingsFragment()?.refresh()
|
||||||
Toast.makeText(this, R.string.settings_toast_reset_done, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.settings_toast_reset_done, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,14 +377,16 @@ class MainActivity :
|
|||||||
val contents =
|
val contents =
|
||||||
if (logWriter.file.exists()) logWriter.file.readText() else logWriter.displayText()
|
if (logWriter.file.exists()) logWriter.file.readText() else logWriter.displayText()
|
||||||
val clipboard =
|
val clipboard =
|
||||||
getSystemService(android.content.Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager
|
getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
|
||||||
clipboard.setPrimaryClip(android.content.ClipData.newPlainText("relay.log", contents))
|
clipboard.setPrimaryClip(ClipData.newPlainText("relay.log", contents))
|
||||||
Toast.makeText(this, R.string.copy_logs_toast, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.copy_logs_toast, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shareLogs() {
|
override fun shareLogs() {
|
||||||
val uri = androidx.core.content.FileProvider.getUriForFile(
|
val uri = FileProvider.getUriForFile(
|
||||||
this, "${packageName}.fileprovider", logWriter.file
|
this,
|
||||||
|
"${packageName}.fileprovider",
|
||||||
|
logWriter.file
|
||||||
)
|
)
|
||||||
val share = Intent(Intent.ACTION_SEND).apply {
|
val share = Intent(Intent.ACTION_SEND).apply {
|
||||||
type = "text/plain"
|
type = "text/plain"
|
||||||
@@ -363,10 +408,12 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onJoinStatusText(text: String) {
|
override fun onJoinStatusText(text: String) {
|
||||||
|
if (resetInProgress) return
|
||||||
runOnUiThread { mainFragment()?.onStatusTextChanged(text) }
|
runOnUiThread { mainFragment()?.onStatusTextChanged(text) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onJoinStatus(status: VpnStatus) {
|
override fun onJoinStatus(status: VpnStatus) {
|
||||||
|
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
|
||||||
@@ -394,34 +441,216 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun popSubPage() {
|
override fun popSubPage() {
|
||||||
if (supportFragmentManager.popBackStackImmediate(
|
supportFragmentManager.popBackStackImmediate(
|
||||||
SUB_PAGE_TAG,
|
SUB_PAGE_TAG,
|
||||||
androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE
|
FragmentManager.POP_BACK_STACK_INCLUSIVE
|
||||||
)
|
)
|
||||||
) {
|
|
||||||
// popped
|
|
||||||
}
|
|
||||||
subPageContainer.visibility = View.GONE
|
subPageContainer.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onJoinCancel() {
|
||||||
|
pendingConnectConfig = null
|
||||||
|
runOnUiThread { fullReset() }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setJoinUiVisible(visible: Boolean) {
|
||||||
|
runOnUiThread { setJoinOverlayVisible(visible) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun requestVpn() {
|
||||||
|
if (Prefs.proxyOnly) {
|
||||||
|
appendLog("Proxy only mode, skipping VPN")
|
||||||
|
startService(Intent(this, ProxyService::class.java))
|
||||||
|
onJoinStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (TunnelServiceState.hasForeignVpn(this)) {
|
||||||
|
appendLog("Another VPN is active, requesting system VPN switch")
|
||||||
|
mainFragment()?.onStatusTextChanged("Requesting VPN replacement...")
|
||||||
|
}
|
||||||
|
val intent = VpnService.prepare(this)
|
||||||
|
if (intent != null) vpnLauncher.launch(intent) else startVpnService()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleIntent(intent: Intent?) {
|
||||||
|
if (intent?.action != ACTION_AUTO_START) return
|
||||||
|
intent.action = null
|
||||||
|
val isConnecting = lastStatus == VpnStatus.CONNECTING
|
||||||
|
if (!connected && !isConnecting && !TunnelServiceState.isAnyTunnelComponentRunning(this)) {
|
||||||
|
Prefs.activeDestination?.let(::onConnectPressed) ?: run {
|
||||||
|
Toast.makeText(this, R.string.error_no_destination, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
} else if (connected) {
|
||||||
|
onDisconnectPressed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun selectNavTab(itemId: Int, animatePager: Boolean = true) {
|
||||||
|
if (currentTabId == itemId) return
|
||||||
|
currentTabId = itemId
|
||||||
|
dismissSubPage()
|
||||||
|
val index = when (itemId) {
|
||||||
|
R.id.navMain -> TAB_MAIN
|
||||||
|
R.id.navSettings -> TAB_SETTINGS
|
||||||
|
R.id.navLogs -> TAB_LOGS
|
||||||
|
else -> TAB_MAIN
|
||||||
|
}
|
||||||
|
updateNavSelection(itemId)
|
||||||
|
val animateIndicator = tabContainer.currentItem != index
|
||||||
|
if (!animatePager || tabContainer.currentItem == index) {
|
||||||
|
moveNavIndicatorTo(itemId, animate = animateIndicator)
|
||||||
|
}
|
||||||
|
tabContainer.setCurrentItem(index, animatePager)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateNavSelection(itemId: Int) {
|
||||||
|
applyNavSelectionState(0f, when (itemId) {
|
||||||
|
R.id.navMain -> TAB_MAIN
|
||||||
|
R.id.navSettings -> TAB_SETTINGS
|
||||||
|
R.id.navLogs -> TAB_LOGS
|
||||||
|
else -> TAB_MAIN
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun moveNavIndicatorTo(itemId: Int, animate: Boolean) {
|
||||||
|
val target = when (itemId) {
|
||||||
|
R.id.navMain -> navMain
|
||||||
|
R.id.navSettings -> navSettings
|
||||||
|
R.id.navLogs -> navLogs
|
||||||
|
else -> null
|
||||||
|
} ?: return
|
||||||
|
|
||||||
|
navIndicator.layoutParams = navIndicator.layoutParams.apply {
|
||||||
|
width = target.width
|
||||||
|
height = target.height
|
||||||
|
}
|
||||||
|
navIndicator.requestLayout()
|
||||||
|
val targetTranslation = target.left.toFloat()
|
||||||
|
if (animate) {
|
||||||
|
navIndicator.animate()
|
||||||
|
.translationX(targetTranslation)
|
||||||
|
.setDuration(220L)
|
||||||
|
.setInterpolator(AccelerateDecelerateInterpolator())
|
||||||
|
.start()
|
||||||
|
} else {
|
||||||
|
navIndicator.animate().cancel()
|
||||||
|
navIndicator.translationX = targetTranslation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun moveNavIndicatorForPager(position: Int, positionOffset: Float) {
|
||||||
|
val targets = listOf(navMain, navSettings, navLogs)
|
||||||
|
val current = targets.getOrNull(position) ?: return
|
||||||
|
val next = targets.getOrNull(position + 1)
|
||||||
|
val targetLeft = if (next != null) {
|
||||||
|
current.left + ((next.left - current.left) * positionOffset)
|
||||||
|
} else {
|
||||||
|
current.left.toFloat()
|
||||||
|
}
|
||||||
|
val lp = navIndicator.layoutParams
|
||||||
|
if (lp.width != current.width || lp.height != current.height) {
|
||||||
|
navIndicator.layoutParams = lp.apply {
|
||||||
|
width = current.width
|
||||||
|
height = current.height
|
||||||
|
}
|
||||||
|
navIndicator.requestLayout()
|
||||||
|
}
|
||||||
|
navIndicator.animate().cancel()
|
||||||
|
navIndicator.translationX = targetLeft
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun interpolateNavSelection(position: Int, positionOffset: Float) {
|
||||||
|
if (navScrollState == ViewPager2.SCROLL_STATE_IDLE) return
|
||||||
|
val clampedOffset = positionOffset.coerceIn(0f, 1f)
|
||||||
|
applyNavSelectionState(clampedOffset, position)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun applyNavSelectionState(positionOffset: Float, position: Int) {
|
||||||
|
val emphasis = floatArrayOf(0f, 0f, 0f)
|
||||||
|
val baseIndex = position.coerceIn(0, emphasis.lastIndex)
|
||||||
|
emphasis[baseIndex] = 1f - positionOffset
|
||||||
|
val nextIndex = (baseIndex + 1).coerceAtMost(emphasis.lastIndex)
|
||||||
|
if (nextIndex != baseIndex) {
|
||||||
|
emphasis[nextIndex] = positionOffset
|
||||||
|
}
|
||||||
|
|
||||||
|
applyNavVisual(navMainIcon, navMainLabel, emphasis[0])
|
||||||
|
applyNavVisual(navSettingsIcon, navSettingsLabel, emphasis[1])
|
||||||
|
applyNavVisual(navLogsIcon, navLogsLabel, emphasis[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun applyNavVisual(icon: ImageView, label: TextView, emphasis: Float) {
|
||||||
|
val accent = getColor(R.color.accent_emerald)
|
||||||
|
val ink = getColor(R.color.ink_3)
|
||||||
|
val blended = navColorEvaluator.evaluate(emphasis, ink, accent) as Int
|
||||||
|
icon.setColorFilter(blended)
|
||||||
|
icon.alpha = 0.72f + (0.28f * emphasis)
|
||||||
|
label.setTextColor(blended)
|
||||||
|
label.alpha = 0.74f + (0.26f * emphasis)
|
||||||
|
label.scaleX = 1f + (0.06f * emphasis)
|
||||||
|
label.scaleY = 1f + (0.06f * emphasis)
|
||||||
|
label.paint.isFakeBoldText = emphasis > 0.92f
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun mainFragment(): MainFragment? =
|
||||||
|
supportFragmentManager.fragments.firstOrNull { it is MainFragment } as? MainFragment
|
||||||
|
|
||||||
|
private fun settingsFragment(): SettingsScreenFragment? =
|
||||||
|
supportFragmentManager.fragments.firstOrNull { it is SettingsScreenFragment } as? SettingsScreenFragment
|
||||||
|
|
||||||
|
private fun logsFragment(): LogsFragment? =
|
||||||
|
supportFragmentManager.fragments.firstOrNull { it is LogsFragment } as? LogsFragment
|
||||||
|
|
||||||
|
private fun probeViaSocks5(host: String, port: Int): Boolean {
|
||||||
|
Socket().use { socket ->
|
||||||
|
socket.connect(InetSocketAddress(Net.LOCALHOST, Prefs.socksPort.toInt()), 5000)
|
||||||
|
socket.soTimeout = 15000
|
||||||
|
val output = socket.getOutputStream()
|
||||||
|
val input = socket.getInputStream()
|
||||||
|
|
||||||
|
output.write(byteArrayOf(0x05, 0x01, 0x02))
|
||||||
|
output.flush()
|
||||||
|
if (input.read() != 0x05 || input.read() != 0x02) return false
|
||||||
|
|
||||||
|
val userBytes = SocksAuth.user.toByteArray(Charsets.US_ASCII)
|
||||||
|
val passBytes = SocksAuth.pass.toByteArray(Charsets.US_ASCII)
|
||||||
|
val authPacket = ByteArray(3 + userBytes.size + passBytes.size)
|
||||||
|
authPacket[0] = 0x01
|
||||||
|
authPacket[1] = userBytes.size.toByte()
|
||||||
|
System.arraycopy(userBytes, 0, authPacket, 2, userBytes.size)
|
||||||
|
authPacket[2 + userBytes.size] = passBytes.size.toByte()
|
||||||
|
System.arraycopy(passBytes, 0, authPacket, 3 + userBytes.size, passBytes.size)
|
||||||
|
output.write(authPacket)
|
||||||
|
output.flush()
|
||||||
|
if (input.read() != 0x01 || input.read() != 0x00) return false
|
||||||
|
|
||||||
|
val hostBytes = host.toByteArray(Charsets.US_ASCII)
|
||||||
|
val request = ByteArray(4 + 1 + hostBytes.size + 2)
|
||||||
|
request[0] = 0x05
|
||||||
|
request[1] = 0x01
|
||||||
|
request[2] = 0x00
|
||||||
|
request[3] = 0x03
|
||||||
|
request[4] = hostBytes.size.toByte()
|
||||||
|
System.arraycopy(hostBytes, 0, request, 5, hostBytes.size)
|
||||||
|
request[5 + hostBytes.size] = ((port shr 8) and 0xff).toByte()
|
||||||
|
request[6 + hostBytes.size] = (port and 0xff).toByte()
|
||||||
|
output.write(request)
|
||||||
|
output.flush()
|
||||||
|
|
||||||
|
return input.read() == 0x05 && input.read() == 0x00
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun dismissSubPage() {
|
private fun dismissSubPage() {
|
||||||
if (supportFragmentManager.backStackEntryCount > 0) {
|
if (supportFragmentManager.backStackEntryCount > 0) {
|
||||||
supportFragmentManager.popBackStack(
|
supportFragmentManager.popBackStack(
|
||||||
SUB_PAGE_TAG,
|
SUB_PAGE_TAG,
|
||||||
androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE
|
FragmentManager.POP_BACK_STACK_INCLUSIVE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
subPageContainer.visibility = View.GONE
|
subPageContainer.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onJoinCancel() {
|
|
||||||
runOnUiThread { fullReset() }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setJoinUiVisible(visible: Boolean) {
|
|
||||||
runOnUiThread { setJoinOverlayVisible(visible) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setJoinOverlayVisible(visible: Boolean) {
|
private fun setJoinOverlayVisible(visible: Boolean) {
|
||||||
joinOverlayContainer.visibility = if (visible) View.VISIBLE else View.GONE
|
joinOverlayContainer.visibility = if (visible) View.VISIBLE else View.GONE
|
||||||
overlayLogs.visibility = if (visible) View.VISIBLE else View.GONE
|
overlayLogs.visibility = if (visible) View.VISIBLE else View.GONE
|
||||||
@@ -432,23 +661,26 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun requestVpn() {
|
private fun startJoinFor(config: CallConfig) {
|
||||||
if (Prefs.proxyOnly) {
|
if (resetInProgress) {
|
||||||
appendLog("Proxy only mode, skipping VPN")
|
pendingConnectConfig = config
|
||||||
startService(Intent(this, ProxyService::class.java))
|
appendLog("Queued connect after previous session stops")
|
||||||
onJoinStatus(VpnStatus.TUNNEL_ACTIVE)
|
mainFragment()?.onStatusTextChanged("Stopping previous session...")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val intent = VpnService.prepare(this)
|
if (TunnelServiceState.isAnyTunnelComponentRunning(this) || !PortGuard.isPortAvailable(Prefs.socksPort)) {
|
||||||
if (intent != null) vpnLauncher.launch(intent) else startVpnService()
|
pendingConnectConfig = config
|
||||||
|
appendLog("Waiting for previous local tunnel to stop")
|
||||||
|
fullReset()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startJoinFor(config: CallConfig) {
|
|
||||||
val url = config.url.trim()
|
val url = config.url.trim()
|
||||||
if (url.isEmpty()) return
|
if (url.isEmpty()) return
|
||||||
|
|
||||||
val platform = config.platform
|
val platform = config.platform
|
||||||
if (Prefs.tunnelMode == TunnelMode.DC && (platform == CallPlatform.TELEMOST || platform == CallPlatform.DION)) {
|
if (Prefs.activeTunnelMode == TunnelMode.DC &&
|
||||||
|
(platform == CallPlatform.TELEMOST || platform == CallPlatform.DION)
|
||||||
|
) {
|
||||||
Toast.makeText(this, R.string.dc_mode_not_supported, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.dc_mode_not_supported, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,7 +702,10 @@ class MainActivity :
|
|||||||
if (headlessMode && platform != CallPlatform.VK) {
|
if (headlessMode && platform != CallPlatform.VK) {
|
||||||
setJoinOverlayVisible(false)
|
setJoinOverlayVisible(false)
|
||||||
activeHeadlessController = HeadlessJoinController(
|
activeHeadlessController = HeadlessJoinController(
|
||||||
applicationInfo.nativeLibraryDir, this, platform, url,
|
applicationInfo.nativeLibraryDir,
|
||||||
|
this,
|
||||||
|
platform,
|
||||||
|
url,
|
||||||
).also { it.start() }
|
).also { it.start() }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -490,11 +725,15 @@ class MainActivity :
|
|||||||
|
|
||||||
private fun startVpnService() {
|
private fun startVpnService() {
|
||||||
startService(Intent(this, TunnelVpnService::class.java))
|
startService(Intent(this, TunnelVpnService::class.java))
|
||||||
appendLog("VPN started")
|
appendLog("VPN start requested")
|
||||||
onJoinStatus(VpnStatus.TUNNEL_ACTIVE)
|
onJoinStatus(VpnStatus.STARTING)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onDisconnectFromService() {
|
private fun onDisconnectFromService() {
|
||||||
|
if (resetInProgress) {
|
||||||
|
maybeFinishReset()
|
||||||
|
return
|
||||||
|
}
|
||||||
connected = false
|
connected = false
|
||||||
lastStatus = null
|
lastStatus = null
|
||||||
closeActiveHeadlessController()
|
closeActiveHeadlessController()
|
||||||
@@ -505,22 +744,99 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun fullReset() {
|
private fun fullReset() {
|
||||||
|
if (resetInProgress) return
|
||||||
|
resetInProgress = true
|
||||||
|
val resetId = ++resetGeneration
|
||||||
connected = false
|
connected = false
|
||||||
lastStatus = null
|
lastStatus = VpnStatus.STOPPING
|
||||||
val controller = activeHeadlessController
|
val controller = activeHeadlessController
|
||||||
activeHeadlessController = null
|
activeHeadlessController = null
|
||||||
val vpn = TunnelVpnService.instance
|
activeJoinUrl = ""
|
||||||
val proxy = ProxyService.instance
|
|
||||||
|
removeJoinFragment()
|
||||||
|
TunnelVpnService.requestStop(this)
|
||||||
|
ProxyService.requestStop(this)
|
||||||
|
HeadlessSessionService.requestStop(this)
|
||||||
|
setJoinOverlayVisible(false)
|
||||||
|
mainFragment()?.onConnectedChanged(false)
|
||||||
|
mainFragment()?.onStatusChanged(VpnStatus.STOPPING)
|
||||||
|
mainFragment()?.onStatusTextChanged("Stopping previous session...")
|
||||||
|
thread(name = "full-reset-shutdown") {
|
||||||
|
controller?.close()
|
||||||
|
var attempts = 0
|
||||||
|
while (
|
||||||
|
attempts < 40 &&
|
||||||
|
(TunnelServiceState.isAnyTunnelComponentRunning(this@MainActivity) ||
|
||||||
|
!PortGuard.isPortAvailable(Prefs.socksPort))
|
||||||
|
) {
|
||||||
|
if (!isResetCurrent(resetId)) return@thread
|
||||||
|
Thread.sleep(100)
|
||||||
|
attempts++
|
||||||
|
}
|
||||||
|
if (!isResetCurrent(resetId)) return@thread
|
||||||
|
if (TunnelServiceState.isAnyTunnelComponentRunning(this@MainActivity) || !PortGuard.isPortAvailable(Prefs.socksPort)) {
|
||||||
|
TunnelVpnService.requestStop(this@MainActivity)
|
||||||
|
ProxyService.requestStop(this@MainActivity)
|
||||||
|
HeadlessSessionService.requestStop(this@MainActivity)
|
||||||
|
PortGuard.ensurePortFree(Prefs.socksPort)
|
||||||
|
Thread.sleep(150)
|
||||||
|
}
|
||||||
|
if (!isResetCurrent(resetId)) return@thread
|
||||||
|
if (TunnelServiceState.isAnyTunnelComponentRunning(this@MainActivity) || !PortGuard.isPortAvailable(Prefs.socksPort)) {
|
||||||
|
runOnUiThread {
|
||||||
|
if (isResetCurrent(resetId)) {
|
||||||
|
forceUnlockReset("Previous session is still shutting down. Try connect again.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@thread
|
||||||
|
}
|
||||||
|
Thread.sleep(400)
|
||||||
|
runOnUiThread {
|
||||||
|
if (isResetCurrent(resetId)) {
|
||||||
|
maybeFinishReset(resetId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun maybeFinishReset(expectedResetId: Long? = null) {
|
||||||
|
if (!resetInProgress) return
|
||||||
|
if (expectedResetId != null && expectedResetId != resetGeneration) return
|
||||||
|
if (TunnelServiceState.isAnyTunnelComponentRunning(this) || !PortGuard.isPortAvailable(Prefs.socksPort)) return
|
||||||
|
resetInProgress = false
|
||||||
|
connected = false
|
||||||
|
lastStatus = null
|
||||||
|
activeJoinUrl = ""
|
||||||
removeJoinFragment()
|
removeJoinFragment()
|
||||||
setJoinOverlayVisible(false)
|
setJoinOverlayVisible(false)
|
||||||
mainFragment()?.onConnectedChanged(false)
|
mainFragment()?.onConnectedChanged(false)
|
||||||
thread(name = "full-reset-shutdown") {
|
mainFragment()?.onStatusChanged(VpnStatus.CALL_DISCONNECTED)
|
||||||
controller?.close()
|
val pendingConfig = pendingConnectConfig
|
||||||
vpn?.stop()
|
pendingConnectConfig = null
|
||||||
proxy?.stop()
|
if (pendingConfig != null) {
|
||||||
|
appendLog("Previous session stopped, starting new connection")
|
||||||
|
startJoinFor(pendingConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun forceUnlockReset(message: String) {
|
||||||
|
resetInProgress = false
|
||||||
|
pendingConnectConfig = null
|
||||||
|
connected = false
|
||||||
|
activeJoinUrl = ""
|
||||||
|
lastStatus = if (PortGuard.isPortAvailable(Prefs.socksPort)) VpnStatus.CALL_DISCONNECTED else VpnStatus.PORT_BUSY
|
||||||
|
closeActiveHeadlessController()
|
||||||
|
removeJoinFragment()
|
||||||
|
setJoinOverlayVisible(false)
|
||||||
|
TunnelVpnService.requestStop(this)
|
||||||
|
ProxyService.requestStop(this)
|
||||||
|
HeadlessSessionService.requestStop(this)
|
||||||
|
mainFragment()?.onConnectedChanged(false)
|
||||||
|
mainFragment()?.onStatusChanged(lastStatus ?: VpnStatus.CALL_DISCONNECTED)
|
||||||
|
mainFragment()?.onStatusTextChanged(message)
|
||||||
|
appendLog(message)
|
||||||
|
}
|
||||||
|
|
||||||
private fun closeActiveHeadlessController() {
|
private fun closeActiveHeadlessController() {
|
||||||
val controller = activeHeadlessController
|
val controller = activeHeadlessController
|
||||||
activeHeadlessController = null
|
activeHeadlessController = null
|
||||||
@@ -529,18 +845,32 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isResetCurrent(resetId: Long): Boolean =
|
||||||
|
resetInProgress && resetGeneration == resetId
|
||||||
|
|
||||||
|
private fun shutdownJoinFragment() {
|
||||||
|
val fragment = supportFragmentManager.findFragmentById(R.id.joinOverlayContainer)
|
||||||
|
(fragment as? JoinSessionShutdown)?.shutdownSession()
|
||||||
|
}
|
||||||
|
|
||||||
private fun removeJoinFragment() {
|
private fun removeJoinFragment() {
|
||||||
|
shutdownJoinFragment()
|
||||||
|
if (isDestroyed || supportFragmentManager.isStateSaved) return
|
||||||
val fragment = supportFragmentManager.findFragmentById(R.id.joinOverlayContainer)
|
val fragment = supportFragmentManager.findFragmentById(R.id.joinOverlayContainer)
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
supportFragmentManager.beginTransaction()
|
supportFragmentManager.beginTransaction()
|
||||||
.remove(fragment)
|
.remove(fragment)
|
||||||
.commitNowAllowingStateLoss()
|
.commitAllowingStateLoss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
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"
|
||||||
private const val STATE_CURRENT_TAB_ID = "current_tab_id"
|
private const val STATE_CURRENT_TAB_ID = "current_tab_id"
|
||||||
private const val CALL_LINK = "" // Open call page on app start (do not delete - I need it for debug)
|
private const val CALL_LINK = ""
|
||||||
|
private const val TAB_MAIN = 0
|
||||||
|
private const val TAB_SETTINGS = 1
|
||||||
|
private const val TAB_LOGS = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,10 @@ data class CallConfig(
|
|||||||
val id: String,
|
val id: String,
|
||||||
val name: String,
|
val name: String,
|
||||||
val url: String,
|
val url: String,
|
||||||
|
val tunnelMode: TunnelMode? = null,
|
||||||
|
val vp8Fps: Int? = null,
|
||||||
|
val vp8Batch: Int? = null,
|
||||||
|
val dualTrack: Boolean? = null,
|
||||||
) {
|
) {
|
||||||
val platform: CallPlatform get() = CallPlatform.fromUrl(url)
|
val platform: CallPlatform get() = CallPlatform.fromUrl(url)
|
||||||
|
|
||||||
@@ -29,6 +33,10 @@ data class CallConfig(
|
|||||||
put("id", id)
|
put("id", id)
|
||||||
put("name", name)
|
put("name", name)
|
||||||
put("url", url)
|
put("url", url)
|
||||||
|
tunnelMode?.let { put("tunnelMode", it.name) }
|
||||||
|
vp8Fps?.let { put("vp8Fps", it) }
|
||||||
|
vp8Batch?.let { put("vp8Batch", it) }
|
||||||
|
dualTrack?.let { put("dualTrack", it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -39,6 +47,10 @@ data class CallConfig(
|
|||||||
id = obj.getString("id"),
|
id = obj.getString("id"),
|
||||||
name = obj.getString("name"),
|
name = obj.getString("name"),
|
||||||
url = obj.getString("url"),
|
url = obj.getString("url"),
|
||||||
|
tunnelMode = if (obj.has("tunnelMode")) try { TunnelMode.valueOf(obj.getString("tunnelMode")) } catch(e: Exception) { null } else null,
|
||||||
|
vp8Fps = if (obj.has("vp8Fps")) obj.getInt("vp8Fps") else null,
|
||||||
|
vp8Batch = if (obj.has("vp8Batch")) obj.getInt("vp8Batch") else null,
|
||||||
|
dualTrack = if (obj.has("dualTrack")) obj.getBoolean("dualTrack") else null,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun listToJson(items: List<CallConfig>): String {
|
fun listToJson(items: List<CallConfig>): String {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
class HeadlessJoinController(
|
class HeadlessJoinController(
|
||||||
nativeLibraryDir: String,
|
nativeLibraryDir: String,
|
||||||
@@ -15,6 +16,7 @@ class HeadlessJoinController(
|
|||||||
) : AutoCloseable {
|
) : AutoCloseable {
|
||||||
|
|
||||||
private val mainHandler = Handler(Looper.getMainLooper())
|
private val mainHandler = Handler(Looper.getMainLooper())
|
||||||
|
private val vpnRequested = AtomicBoolean(false)
|
||||||
private val relay: HeadlessRelayController = HeadlessRelayController(
|
private val relay: HeadlessRelayController = HeadlessRelayController(
|
||||||
nativeLibraryDir,
|
nativeLibraryDir,
|
||||||
relayMode = "${platform.id}-headless-joiner",
|
relayMode = "${platform.id}-headless-joiner",
|
||||||
@@ -28,24 +30,34 @@ class HeadlessJoinController(
|
|||||||
|
|
||||||
private fun handleStatus(status: VpnStatus) {
|
private fun handleStatus(status: VpnStatus) {
|
||||||
Log.d(LOG_TAG, "status: $status")
|
Log.d(LOG_TAG, "status: $status")
|
||||||
host.onJoinStatus(status)
|
|
||||||
when (status) {
|
when (status) {
|
||||||
VpnStatus.STARTING -> relay.sendJoinParams(buildJoinParams().toString())
|
VpnStatus.STARTING -> {
|
||||||
VpnStatus.TUNNEL_ACTIVE -> mainHandler.post { host.requestVpn() }
|
host.onJoinStatus(status)
|
||||||
else -> {}
|
relay.sendJoinParams(buildJoinParams().toString())
|
||||||
|
}
|
||||||
|
VpnStatus.TUNNEL_ACTIVE -> {
|
||||||
|
if (vpnRequested.compareAndSet(false, true)) {
|
||||||
|
host.onJoinStatusText("Relay ready, starting local VPN")
|
||||||
|
mainHandler.post { host.requestVpn() }
|
||||||
|
} else {
|
||||||
|
host.onJoinStatusText("Relay reconnected")
|
||||||
|
host.onJoinStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> host.onJoinStatus(status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildJoinParams(): JSONObject = JSONObject().apply {
|
private fun buildJoinParams(): JSONObject = JSONObject().apply {
|
||||||
put("displayName", Prefs.autofillName)
|
put("displayName", Prefs.autofillName)
|
||||||
put("vp8Fps", Prefs.vp8Fps)
|
put("vp8Fps", Prefs.activeVp8Fps)
|
||||||
put("vp8Batch", Prefs.vp8Batch)
|
put("vp8Batch", Prefs.activeVp8Batch)
|
||||||
put("dualTrack", Prefs.dualTrack)
|
put("dualTrack", Prefs.activeDualTrack)
|
||||||
when (platform) {
|
when (platform) {
|
||||||
CallPlatform.TELEMOST -> put("joinLink", url)
|
CallPlatform.TELEMOST -> put("joinLink", url)
|
||||||
CallPlatform.WBSTREAM -> {
|
CallPlatform.WBSTREAM -> {
|
||||||
put("roomId", CallPlatform.extractRoomId(url))
|
put("roomId", CallPlatform.extractRoomId(url))
|
||||||
put("tunnelMode", Prefs.tunnelMode.relayArg)
|
put("tunnelMode", Prefs.activeTunnelMode.relayArg)
|
||||||
}
|
}
|
||||||
CallPlatform.DION -> put("roomId", CallPlatform.extractRoomId(url))
|
CallPlatform.DION -> put("roomId", CallPlatform.extractRoomId(url))
|
||||||
CallPlatform.VK -> error("VK headless flow uses HeadlessVkFragment for captcha UI")
|
CallPlatform.VK -> error("VK headless flow uses HeadlessVkFragment for captcha UI")
|
||||||
@@ -53,6 +65,7 @@ class HeadlessJoinController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
|
mainHandler.removeCallbacksAndMessages(null)
|
||||||
relay.stop()
|
relay.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package bypass.whitelist.tunnel
|
package bypass.whitelist.tunnel
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import bypass.whitelist.util.ParamCallback
|
import bypass.whitelist.util.ParamCallback
|
||||||
import bypass.whitelist.util.Ports
|
import bypass.whitelist.util.Ports
|
||||||
@@ -11,6 +12,7 @@ import java.io.File
|
|||||||
import java.io.OutputStreamWriter
|
import java.io.OutputStreamWriter
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class HeadlessRelayController(
|
class HeadlessRelayController(
|
||||||
private val nativeLibDir: String,
|
private val nativeLibDir: String,
|
||||||
@@ -34,15 +36,21 @@ class HeadlessRelayController(
|
|||||||
|
|
||||||
val relayBin = File(nativeLibDir, "librelay.so")
|
val relayBin = File(nativeLibDir, "librelay.so")
|
||||||
if (!relayBin.exists()) {
|
if (!relayBin.exists()) {
|
||||||
onLog("Relay binary not found")
|
onLog.invoke("Relay binary not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
thread = Thread {
|
thread = Thread {
|
||||||
|
try {
|
||||||
val socksPort = Prefs.socksPort
|
val socksPort = Prefs.socksPort
|
||||||
if (!PortGuard.ensurePortFree(socksPort)) {
|
if (!PortGuard.ensurePortFree(socksPort)) {
|
||||||
onLog("SOCKS5 port $socksPort is busy and could not be freed")
|
onLog.invoke("SOCKS5 port $socksPort is busy and could not be freed")
|
||||||
onStatus(VpnStatus.PORT_BUSY)
|
onStatus.invoke(VpnStatus.PORT_BUSY)
|
||||||
|
isRunning = false
|
||||||
|
return@Thread
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
onLog.invoke("Port check error: ${e.message}")
|
||||||
isRunning = false
|
isRunning = false
|
||||||
return@Thread
|
return@Thread
|
||||||
}
|
}
|
||||||
@@ -64,7 +72,7 @@ class HeadlessRelayController(
|
|||||||
pendingCommands.forEach { writeStdin(it) }
|
pendingCommands.forEach { writeStdin(it) }
|
||||||
pendingCommands.clear()
|
pendingCommands.clear()
|
||||||
}
|
}
|
||||||
onLog("Headless relay started (signaling :${Ports.PION_SIGNALING}, SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@${Prefs.socksHost}:${Prefs.socksPort})")
|
onLog.invoke("Headless relay started (signaling :${Ports.PION_SIGNALING}, SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@${Prefs.socksHost}:${Prefs.socksPort})")
|
||||||
|
|
||||||
proc.inputStream.bufferedReader().forEachLine { line ->
|
proc.inputStream.bufferedReader().forEachLine { line ->
|
||||||
if (line.startsWith("RESOLVE:")) {
|
if (line.startsWith("RESOLVE:")) {
|
||||||
@@ -83,29 +91,38 @@ class HeadlessRelayController(
|
|||||||
val status = line.removePrefix("STATUS:")
|
val status = line.removePrefix("STATUS:")
|
||||||
Log.d("RELAY", "status: $status")
|
Log.d("RELAY", "status: $status")
|
||||||
when {
|
when {
|
||||||
status == "READY" -> onStatus(VpnStatus.STARTING)
|
status == "READY" -> onStatus.invoke(VpnStatus.STARTING)
|
||||||
status == "CONNECTING" -> onStatus(VpnStatus.CONNECTING)
|
status == "CONNECTING" -> onStatus.invoke(VpnStatus.CONNECTING)
|
||||||
status == "RECONNECTING" -> onStatus(VpnStatus.CONNECTING)
|
status == "RECONNECTING" -> onStatus.invoke(VpnStatus.CONNECTING)
|
||||||
status == "TUNNEL_CONNECTED" -> onStatus(VpnStatus.TUNNEL_ACTIVE)
|
status == "TUNNEL_CONNECTED" -> onStatus.invoke(VpnStatus.TUNNEL_ACTIVE)
|
||||||
status == "TUNNEL_LOST" -> onStatus(VpnStatus.TUNNEL_LOST)
|
status == "TUNNEL_LOST" -> onStatus.invoke(VpnStatus.TUNNEL_LOST)
|
||||||
status.startsWith("CAPTCHA:") -> {
|
status.startsWith("CAPTCHA:") -> {
|
||||||
val captchaUrl = status.removePrefix("CAPTCHA:")
|
val captchaUrl = status.removePrefix("CAPTCHA:")
|
||||||
onStatus(VpnStatus.ACTION_REQUIRED_CAPTCHA)
|
onStatus.invoke(VpnStatus.ACTION_REQUIRED_CAPTCHA)
|
||||||
onCaptchaUrl?.invoke(captchaUrl)
|
onCaptchaUrl?.invoke(captchaUrl)
|
||||||
}
|
}
|
||||||
status.startsWith("ERROR:") -> onStatus(VpnStatus.CALL_FAILED)
|
status.startsWith("ERROR:") -> {
|
||||||
|
onLog.invoke("Headless relay error: $status")
|
||||||
|
onStatus.invoke(VpnStatus.CALL_FAILED)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d("RELAY", line)
|
Log.d("RELAY", line)
|
||||||
onLog(line)
|
onLog.invoke(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proc.waitFor()
|
proc.waitFor()
|
||||||
Log.d("RELAY", "Headless relay exited: ${proc.exitValue()}")
|
Log.d("RELAY", "Headless relay exited: ${proc.exitValue()}")
|
||||||
|
if (isRunning) {
|
||||||
|
onStatus.invoke(VpnStatus.CALL_FAILED)
|
||||||
|
isRunning = false
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
Log.e("RELAY", "Headless relay error", e)
|
Log.e("RELAY", "Headless relay error", e)
|
||||||
onLog("Relay error: ${e.message}")
|
onLog.invoke("Relay error: ${e.message}")
|
||||||
|
onStatus.invoke(VpnStatus.CALL_FAILED)
|
||||||
|
isRunning = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.also { it.start() }
|
}.also { it.start() }
|
||||||
@@ -120,9 +137,9 @@ class HeadlessRelayController(
|
|||||||
put("joinLink", joinLink)
|
put("joinLink", joinLink)
|
||||||
put("displayName", displayName)
|
put("displayName", displayName)
|
||||||
put("tunnelMode", tunnelMode)
|
put("tunnelMode", tunnelMode)
|
||||||
put("vp8Fps", bypass.whitelist.util.Prefs.vp8Fps)
|
put("vp8Fps", Prefs.activeVp8Fps)
|
||||||
put("vp8Batch", bypass.whitelist.util.Prefs.vp8Batch)
|
put("vp8Batch", Prefs.activeVp8Batch)
|
||||||
put("dualTrack", bypass.whitelist.util.Prefs.dualTrack)
|
put("dualTrack", Prefs.activeDualTrack)
|
||||||
}
|
}
|
||||||
writeStdin("AUTH:$json")
|
writeStdin("AUTH:$json")
|
||||||
}
|
}
|
||||||
@@ -130,13 +147,32 @@ class HeadlessRelayController(
|
|||||||
@Synchronized
|
@Synchronized
|
||||||
fun stop() {
|
fun stop() {
|
||||||
isRunning = false
|
isRunning = false
|
||||||
process?.let {
|
try { stdinWriter?.close() } catch (_: Exception) {}
|
||||||
it.destroy()
|
|
||||||
it.waitFor()
|
|
||||||
}
|
|
||||||
process = null
|
|
||||||
stdinWriter = null
|
stdinWriter = null
|
||||||
thread?.interrupt()
|
val activeProcess = process
|
||||||
|
process = null
|
||||||
|
activeProcess?.destroy()
|
||||||
|
if (activeProcess != null) {
|
||||||
|
try {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
if (!activeProcess.waitFor(1500, TimeUnit.MILLISECONDS)) {
|
||||||
|
activeProcess.destroyForcibly()
|
||||||
|
activeProcess.waitFor(500, TimeUnit.MILLISECONDS)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
activeProcess.waitFor()
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val activeThread = thread
|
||||||
|
activeThread?.interrupt()
|
||||||
|
if (activeThread != null && activeThread !== Thread.currentThread()) {
|
||||||
|
try {
|
||||||
|
activeThread.join(500)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
thread = null
|
thread = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,330 @@
|
|||||||
|
package bypass.whitelist.tunnel
|
||||||
|
|
||||||
|
import android.app.Notification
|
||||||
|
import android.app.NotificationChannel
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.VpnService
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.IBinder
|
||||||
|
import android.os.Looper
|
||||||
|
import android.util.Log
|
||||||
|
import android.widget.Toast
|
||||||
|
import bypass.whitelist.MainActivity
|
||||||
|
import bypass.whitelist.R
|
||||||
|
import bypass.whitelist.ui.JoinFragmentHost
|
||||||
|
import bypass.whitelist.util.LogWriter
|
||||||
|
import bypass.whitelist.util.Prefs
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
|
class HeadlessSessionService : Service() {
|
||||||
|
|
||||||
|
private val logWriter by lazy { LogWriter(cacheDir) }
|
||||||
|
private var controller: HeadlessJoinController? = null
|
||||||
|
@Volatile private var sessionRunning: Boolean = false
|
||||||
|
@Volatile private var stopInProgress: Boolean = false
|
||||||
|
|
||||||
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
when (intent?.action) {
|
||||||
|
ACTION_STOP -> {
|
||||||
|
if (!hasLiveSessionInternal()) {
|
||||||
|
safeStopSelf()
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
|
stopSession(stopDependentServices = true)
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
|
ACTION_DEPENDENT_STOPPED -> {
|
||||||
|
if (!hasLiveSessionInternal()) {
|
||||||
|
safeStopSelf()
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
|
stopSession(stopDependentServices = false)
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
startForegroundNotification(getString(R.string.notification_session_connecting))
|
||||||
|
startSession()
|
||||||
|
return START_STICKY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private fun startSession() {
|
||||||
|
if (stopInProgress || sessionRunning) return
|
||||||
|
val config = Prefs.activeDestination
|
||||||
|
if (config == null) {
|
||||||
|
showToast(R.string.error_no_destination)
|
||||||
|
safeStopSelf()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val platform = config.platform
|
||||||
|
|
||||||
|
if (platform == CallPlatform.VK && !Prefs.headless) {
|
||||||
|
showToast(R.string.tile_requires_headless_destination)
|
||||||
|
safeStopSelf()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val headlessMode =
|
||||||
|
Prefs.headless ||
|
||||||
|
platform == CallPlatform.WBSTREAM ||
|
||||||
|
platform == CallPlatform.DION ||
|
||||||
|
platform == CallPlatform.TELEMOST
|
||||||
|
if (!headlessMode) {
|
||||||
|
showToast(R.string.tile_requires_headless_destination)
|
||||||
|
safeStopSelf()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logWriter.reset()
|
||||||
|
logWriter.append("Loading: ${config.url.trim()}")
|
||||||
|
controller?.close()
|
||||||
|
sessionRunning = true
|
||||||
|
controller = HeadlessJoinController(
|
||||||
|
applicationInfo.nativeLibraryDir,
|
||||||
|
object : JoinFragmentHost {
|
||||||
|
override fun appendLog(message: String) {
|
||||||
|
logWriter.append(message)
|
||||||
|
Log.d(TAG, message)
|
||||||
|
TunnelServiceState.logCallback?.invoke(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onJoinStatus(status: VpnStatus) {
|
||||||
|
updateNotification(getString(status.labelRes))
|
||||||
|
TunnelServiceState.vpnStatusCallback?.invoke(status)
|
||||||
|
if (status == VpnStatus.CALL_FAILED) {
|
||||||
|
stopSession(stopDependentServices = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onJoinStatusText(text: String) {
|
||||||
|
updateNotification(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun requestVpn() {
|
||||||
|
if (Prefs.proxyOnly) {
|
||||||
|
logWriter.append("Proxy only mode, skipping VPN")
|
||||||
|
startService(Intent(this@HeadlessSessionService, ProxyService::class.java))
|
||||||
|
updateNotification(getString(R.string.notification_proxy_title))
|
||||||
|
TunnelServiceState.vpnStatusCallback?.invoke(VpnStatus.TUNNEL_ACTIVE)
|
||||||
|
TunnelServiceState.requestTileRefresh(this@HeadlessSessionService)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TunnelServiceState.hasForeignVpn(this@HeadlessSessionService)) {
|
||||||
|
logWriter.append("Another VPN is active. Turn it off first.")
|
||||||
|
updateNotification(getString(R.string.vpn_foreign_active))
|
||||||
|
TunnelServiceState.vpnStatusCallback?.invoke(VpnStatus.VPN_CONFLICT)
|
||||||
|
showToast(R.string.vpn_foreign_active)
|
||||||
|
stopSession(stopDependentServices = true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VpnService.prepare(this@HeadlessSessionService) != null) {
|
||||||
|
logWriter.append("VPN permission required")
|
||||||
|
updateNotification(getString(R.string.tile_vpn_permission_required))
|
||||||
|
showToast(R.string.tile_vpn_permission_required)
|
||||||
|
stopSession(stopDependentServices = true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logWriter.append("VPN start requested")
|
||||||
|
startService(Intent(this@HeadlessSessionService, TunnelVpnService::class.java))
|
||||||
|
updateNotification(getString(R.string.vpn_starting))
|
||||||
|
TunnelServiceState.vpnStatusCallback?.invoke(VpnStatus.STARTING)
|
||||||
|
TunnelServiceState.requestTileRefresh(this@HeadlessSessionService)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setJoinUiVisible(visible: Boolean) = Unit
|
||||||
|
|
||||||
|
override fun onJoinCancel() {
|
||||||
|
stopSession(stopDependentServices = true)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
platform,
|
||||||
|
config.url.trim(),
|
||||||
|
)
|
||||||
|
controller?.start()
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startForegroundNotification(text: String) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
val channel = NotificationChannel(
|
||||||
|
CHANNEL_ID,
|
||||||
|
"Headless Session",
|
||||||
|
NotificationManager.IMPORTANCE_LOW
|
||||||
|
)
|
||||||
|
val nm = getSystemService(NotificationManager::class.java)
|
||||||
|
nm.createNotificationChannel(channel)
|
||||||
|
}
|
||||||
|
startForeground(NOTIFICATION_ID, buildNotification(text))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateNotification(text: String) {
|
||||||
|
val nm = getSystemService(NotificationManager::class.java)
|
||||||
|
nm.notify(NOTIFICATION_ID, buildNotification(text))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildNotification(text: String): Notification {
|
||||||
|
val openIntent = Intent(this, MainActivity::class.java).apply {
|
||||||
|
flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
}
|
||||||
|
val openPending = PendingIntent.getActivity(
|
||||||
|
this,
|
||||||
|
3,
|
||||||
|
openIntent,
|
||||||
|
PendingIntent.FLAG_IMMUTABLE,
|
||||||
|
)
|
||||||
|
val stopIntent = Intent(this, HeadlessSessionService::class.java).apply {
|
||||||
|
action = ACTION_STOP
|
||||||
|
}
|
||||||
|
val stopPending = PendingIntent.getService(
|
||||||
|
this,
|
||||||
|
4,
|
||||||
|
stopIntent,
|
||||||
|
PendingIntent.FLAG_IMMUTABLE,
|
||||||
|
)
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
Notification.Builder(this, CHANNEL_ID)
|
||||||
|
} else {
|
||||||
|
Notification.Builder(this)
|
||||||
|
}
|
||||||
|
return builder
|
||||||
|
.setContentTitle(getString(R.string.app_name))
|
||||||
|
.setContentText(text)
|
||||||
|
.setSmallIcon(android.R.drawable.ic_lock_lock)
|
||||||
|
.setOngoing(true)
|
||||||
|
.setContentIntent(openPending)
|
||||||
|
.addAction(Notification.Action.Builder(null, getString(R.string.notification_disconnect), stopPending).build())
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopSession(stopDependentServices: Boolean) {
|
||||||
|
if (stopInProgress) return
|
||||||
|
val activeController = controller
|
||||||
|
if (activeController == null && !sessionRunning) {
|
||||||
|
safeStopSelf()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stopInProgress = true
|
||||||
|
sessionRunning = false
|
||||||
|
controller = null
|
||||||
|
if (stopDependentServices) {
|
||||||
|
TunnelVpnService.requestStop(this)
|
||||||
|
ProxyService.requestStop(this)
|
||||||
|
}
|
||||||
|
thread(name = "headless-session-shutdown") {
|
||||||
|
val closeDone = CountDownLatch(1)
|
||||||
|
thread(name = "headless-controller-close") {
|
||||||
|
try {
|
||||||
|
activeController?.close()
|
||||||
|
} finally {
|
||||||
|
closeDone.countDown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closeDone.await(2200, TimeUnit.MILLISECONDS)
|
||||||
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
try {
|
||||||
|
TunnelServiceState.vpnStatusCallback?.invoke(VpnStatus.CALL_DISCONNECTED)
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
stopForeground(true)
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
|
stopSelf()
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
stopInProgress = false
|
||||||
|
Log.e(TAG, "Crash during HeadlessSession stop: ${t.message}", t)
|
||||||
|
safeStopSelf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hasLiveSessionInternal(): Boolean = sessionRunning || stopInProgress || controller != null
|
||||||
|
|
||||||
|
private fun safeStopSelf() {
|
||||||
|
sessionRunning = false
|
||||||
|
stopInProgress = false
|
||||||
|
controller = null
|
||||||
|
runCatching {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
stopForeground(true)
|
||||||
|
}
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showToast(messageRes: Int) {
|
||||||
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
Toast.makeText(applicationContext, messageRes, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val ACTION_STOP = "bypass.whitelist.STOP_HEADLESS_SESSION"
|
||||||
|
const val ACTION_DEPENDENT_STOPPED = "bypass.whitelist.HEADLESS_DEPENDENT_STOPPED"
|
||||||
|
|
||||||
|
private const val CHANNEL_ID = "headless_session_channel"
|
||||||
|
private const val NOTIFICATION_ID = 3
|
||||||
|
private const val TAG = "HeadlessSession"
|
||||||
|
|
||||||
|
@Volatile
|
||||||
|
var instance: HeadlessSessionService? = null
|
||||||
|
|
||||||
|
fun hasLiveSession(): Boolean = instance?.hasLiveSessionInternal() == true
|
||||||
|
|
||||||
|
fun requestStop(context: Context) {
|
||||||
|
val intent = Intent(context, HeadlessSessionService::class.java)
|
||||||
|
try {
|
||||||
|
if (hasLiveSession()) {
|
||||||
|
context.startService(intent.apply { action = ACTION_STOP })
|
||||||
|
} else {
|
||||||
|
context.stopService(intent)
|
||||||
|
TunnelServiceState.requestTileRefresh(context)
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun requestDependentStop(context: Context) {
|
||||||
|
val intent = Intent(context, HeadlessSessionService::class.java)
|
||||||
|
try {
|
||||||
|
if (hasLiveSession()) {
|
||||||
|
context.startService(intent.apply { action = ACTION_DEPENDENT_STOPPED })
|
||||||
|
} else {
|
||||||
|
context.stopService(intent)
|
||||||
|
TunnelServiceState.requestTileRefresh(context)
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
instance = this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
instance = null
|
||||||
|
sessionRunning = false
|
||||||
|
stopInProgress = false
|
||||||
|
controller = null
|
||||||
|
logWriter.close()
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,13 +10,18 @@ import java.net.ServerSocket
|
|||||||
object PortGuard {
|
object PortGuard {
|
||||||
|
|
||||||
private const val TAG = "PortGuard"
|
private const val TAG = "PortGuard"
|
||||||
|
private val myUid = Process.myUid()
|
||||||
|
|
||||||
fun ensurePortFree(port: Long): Boolean {
|
fun ensurePortFree(port: Long): Boolean {
|
||||||
if (tryBind(port)) return true
|
if (tryBind(port)) return true
|
||||||
Log.w(TAG, "Port $port is busy, killing occupying process")
|
Log.w(TAG, "Port $port is busy, killing occupying process")
|
||||||
killByPort(port)
|
killByPort(port)
|
||||||
for (attempt in 1..20) {
|
for (attempt in 1..20) {
|
||||||
|
try {
|
||||||
Thread.sleep(100)
|
Thread.sleep(100)
|
||||||
|
} catch (e: InterruptedException) {
|
||||||
|
break
|
||||||
|
}
|
||||||
if (tryBind(port)) {
|
if (tryBind(port)) {
|
||||||
Log.i(TAG, "Port $port freed after kill (attempt $attempt)")
|
Log.i(TAG, "Port $port freed after kill (attempt $attempt)")
|
||||||
return true
|
return true
|
||||||
@@ -26,6 +31,8 @@ object PortGuard {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isPortAvailable(port: Long): Boolean = tryBind(port)
|
||||||
|
|
||||||
private fun tryBind(port: Long): Boolean {
|
private fun tryBind(port: Long): Boolean {
|
||||||
return try {
|
return try {
|
||||||
ServerSocket(port.toInt(), 1, InetAddress.getByName(Prefs.socksHost)).use { true }
|
ServerSocket(port.toInt(), 1, InetAddress.getByName(Prefs.socksHost)).use { true }
|
||||||
@@ -61,6 +68,7 @@ object PortGuard {
|
|||||||
for (entry in procDir.listFiles() ?: emptyArray()) {
|
for (entry in procDir.listFiles() ?: emptyArray()) {
|
||||||
val pid = entry.name.toIntOrNull() ?: continue
|
val pid = entry.name.toIntOrNull() ?: continue
|
||||||
if (pid == myPid) continue
|
if (pid == myPid) continue
|
||||||
|
if (readUid(pid) != myUid) continue
|
||||||
val fdDir = File(entry, "fd")
|
val fdDir = File(entry, "fd")
|
||||||
if (!fdDir.canRead()) continue
|
if (!fdDir.canRead()) continue
|
||||||
for (fd in fdDir.listFiles() ?: emptyArray()) {
|
for (fd in fdDir.listFiles() ?: emptyArray()) {
|
||||||
@@ -84,7 +92,7 @@ object PortGuard {
|
|||||||
fuser.waitFor()
|
fuser.waitFor()
|
||||||
for (token in output.split("\\s+".toRegex())) {
|
for (token in output.split("\\s+".toRegex())) {
|
||||||
val pid = token.toIntOrNull() ?: continue
|
val pid = token.toIntOrNull() ?: continue
|
||||||
if (pid != myPid) {
|
if (pid != myPid && readUid(pid) == myUid) {
|
||||||
Log.w(TAG, "fuser: killing PID $pid for port $port")
|
Log.w(TAG, "fuser: killing PID $pid for port $port")
|
||||||
Process.killProcess(pid)
|
Process.killProcess(pid)
|
||||||
return
|
return
|
||||||
@@ -97,4 +105,18 @@ object PortGuard {
|
|||||||
Log.e(TAG, "killByPort error: ${e.message}")
|
Log.e(TAG, "killByPort error: ${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun readUid(pid: Int): Int? {
|
||||||
|
return try {
|
||||||
|
File("/proc/$pid/status").useLines { lines ->
|
||||||
|
lines.firstOrNull { it.startsWith("Uid:") }
|
||||||
|
?.trim()
|
||||||
|
?.split("\\s+".toRegex())
|
||||||
|
?.getOrNull(1)
|
||||||
|
?.toIntOrNull()
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,9 +5,11 @@ import android.app.NotificationChannel
|
|||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import android.util.Log
|
||||||
import bypass.whitelist.MainActivity
|
import bypass.whitelist.MainActivity
|
||||||
import bypass.whitelist.util.Callback
|
import bypass.whitelist.util.Callback
|
||||||
import bypass.whitelist.R
|
import bypass.whitelist.R
|
||||||
@@ -20,20 +22,40 @@ class ProxyService : Service() {
|
|||||||
const val ACTION_STOP = "bypass.whitelist.STOP_PROXY"
|
const val ACTION_STOP = "bypass.whitelist.STOP_PROXY"
|
||||||
@Volatile var instance: ProxyService? = null
|
@Volatile var instance: ProxyService? = null
|
||||||
@Volatile var onDisconnect: Callback? = null
|
@Volatile var onDisconnect: Callback? = null
|
||||||
|
|
||||||
|
fun requestStop(context: Context) {
|
||||||
|
val running = instance?.let { it.isRunning || it.stopInProgress } == true
|
||||||
|
val intent = Intent(context, ProxyService::class.java)
|
||||||
|
try {
|
||||||
|
if (running) {
|
||||||
|
context.startService(intent.apply { action = ACTION_STOP })
|
||||||
|
} else {
|
||||||
|
context.stopService(intent)
|
||||||
|
TunnelServiceState.requestTileRefresh(context)
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Volatile var isRunning = false
|
@Volatile var isRunning = false
|
||||||
private set
|
private set
|
||||||
|
@Volatile internal var stopInProgress = false
|
||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder? = null
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
instance = this
|
instance = this
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
if (intent?.action == ACTION_STOP) {
|
if (intent?.action == ACTION_STOP) {
|
||||||
|
if (!isRunning && !stopInProgress) {
|
||||||
|
safeStopSelf()
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
stop()
|
stop()
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
@@ -42,11 +64,15 @@ class ProxyService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
if (isRunning && !stopInProgress) {
|
||||||
stop()
|
stop()
|
||||||
|
}
|
||||||
if (instance === this) {
|
if (instance === this) {
|
||||||
instance = null
|
instance = null
|
||||||
}
|
}
|
||||||
onDisconnect = null
|
onDisconnect = null
|
||||||
|
stopInProgress = false
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,17 +83,42 @@ class ProxyService : Service() {
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun stop() {
|
fun stop() {
|
||||||
if (!isRunning) return
|
if (stopInProgress) return
|
||||||
|
if (!isRunning) {
|
||||||
|
safeStopSelf()
|
||||||
|
return
|
||||||
|
}
|
||||||
isRunning = false
|
isRunning = false
|
||||||
|
stopInProgress = true
|
||||||
|
val disconnectCallback = onDisconnect
|
||||||
|
try {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
stopForeground(true)
|
stopForeground(true)
|
||||||
|
HeadlessSessionService.requestDependentStop(this)
|
||||||
|
disconnectCallback?.invoke()
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
Log.e("ProxyService", "Crash during Proxy stop: ${t.message}", t)
|
||||||
|
} finally {
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun safeStopSelf() {
|
||||||
|
isRunning = false
|
||||||
|
stopInProgress = false
|
||||||
|
runCatching {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
stopForeground(true)
|
||||||
|
}
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
stopSelf()
|
stopSelf()
|
||||||
onDisconnect?.invoke()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun start() {
|
private fun start() {
|
||||||
if (isRunning) return
|
if (isRunning) return
|
||||||
isRunning = true
|
isRunning = true
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
val channel = NotificationChannel(
|
val channel = NotificationChannel(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package bypass.whitelist.tunnel
|
package bypass.whitelist.tunnel
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import bypass.whitelist.util.ParamCallback
|
import bypass.whitelist.util.ParamCallback
|
||||||
import bypass.whitelist.util.Ports
|
import bypass.whitelist.util.Ports
|
||||||
@@ -12,6 +13,7 @@ import java.io.File
|
|||||||
import java.io.OutputStreamWriter
|
import java.io.OutputStreamWriter
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class RelayController(
|
class RelayController(
|
||||||
private val nativeLibDir: String,
|
private val nativeLibDir: String,
|
||||||
@@ -39,8 +41,18 @@ class RelayController(
|
|||||||
|
|
||||||
pionProcess?.let {
|
pionProcess?.let {
|
||||||
it.destroy()
|
it.destroy()
|
||||||
|
try {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
if (!it.waitFor(1500, TimeUnit.MILLISECONDS)) {
|
||||||
|
it.destroyForcibly()
|
||||||
|
it.waitFor(500, TimeUnit.MILLISECONDS)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
it.waitFor()
|
it.waitFor()
|
||||||
}
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
pionProcess = null
|
pionProcess = null
|
||||||
pionThread?.interrupt()
|
pionThread?.interrupt()
|
||||||
pionThread = null
|
pionThread = null
|
||||||
@@ -57,7 +69,12 @@ class RelayController(
|
|||||||
else if (msg.contains("ws read error")) onStatus(VpnStatus.TUNNEL_LOST)
|
else if (msg.contains("ws read error")) onStatus(VpnStatus.TUNNEL_LOST)
|
||||||
}
|
}
|
||||||
dcThread = Thread {
|
dcThread = Thread {
|
||||||
|
try {
|
||||||
if (!checkPortOrAbort()) return@Thread
|
if (!checkPortOrAbort()) return@Thread
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (isRunning) onLog("Port check error: ${e.message}")
|
||||||
|
return@Thread
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Androidbind.startJoiner(Ports.DC_WS, Prefs.socksPort, Prefs.socksHost, SocksAuth.user, SocksAuth.pass, cb)
|
Androidbind.startJoiner(Ports.DC_WS, Prefs.socksPort, Prefs.socksHost, SocksAuth.user, SocksAuth.pass, cb)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -75,7 +92,12 @@ class RelayController(
|
|||||||
}
|
}
|
||||||
val relayMode = mode.relayMode(platform)
|
val relayMode = mode.relayMode(platform)
|
||||||
pionThread = Thread {
|
pionThread = Thread {
|
||||||
|
try {
|
||||||
if (!checkPortOrAbort()) return@Thread
|
if (!checkPortOrAbort()) return@Thread
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (isRunning) onLog("Port check error: ${e.message}")
|
||||||
|
return@Thread
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
val pb = ProcessBuilder(
|
val pb = ProcessBuilder(
|
||||||
relayBin.absolutePath,
|
relayBin.absolutePath,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ enum class TunnelMode(val label: String, val relayArg: String, val isPion: Boole
|
|||||||
return "${platform.id}-$relayArg-joiner"
|
return "${platform.id}-$relayArg-joiner"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun effectiveFor(platform: CallPlatform): TunnelMode {
|
fun forPlatform(platform: CallPlatform): TunnelMode {
|
||||||
if (this == DC && (platform == CallPlatform.TELEMOST || platform == CallPlatform.DION)) {
|
if (this == DC && (platform == CallPlatform.TELEMOST || platform == CallPlatform.DION)) {
|
||||||
return VIDEO
|
return VIDEO
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package bypass.whitelist.tunnel
|
||||||
|
|
||||||
|
import android.app.ActivityManager
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
import android.os.Build
|
||||||
|
import android.service.quicksettings.TileService
|
||||||
|
import bypass.whitelist.util.ParamCallback
|
||||||
|
|
||||||
|
object TunnelServiceState {
|
||||||
|
|
||||||
|
@Volatile
|
||||||
|
var vpnStatusCallback: ParamCallback<VpnStatus>? = null
|
||||||
|
|
||||||
|
@Volatile
|
||||||
|
var logCallback: ParamCallback<String>? = null
|
||||||
|
|
||||||
|
fun isTunnelActive(context: Context): Boolean {
|
||||||
|
val vpnActive = TunnelVpnService.instance?.let { it.isRunning || it.startInProgress || it.stopInProgress } == true
|
||||||
|
val proxyActive = ProxyService.instance?.let { it.isRunning || it.stopInProgress } == true
|
||||||
|
return vpnActive || proxyActive
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isHeadlessSessionRunning(context: Context): Boolean {
|
||||||
|
return HeadlessSessionService.hasLiveSession()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isAnyTunnelComponentRunning(context: Context): Boolean {
|
||||||
|
return isTunnelActive(context) || isHeadlessSessionRunning(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hasForeignVpn(context: Context): Boolean {
|
||||||
|
if (isTunnelActive(context)) return false
|
||||||
|
val connectivityManager = context.getSystemService(ConnectivityManager::class.java) ?: return false
|
||||||
|
val activeNetwork = connectivityManager.activeNetwork ?: return false
|
||||||
|
val capabilities = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false
|
||||||
|
return capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun requestTileRefresh(context: Context) {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return
|
||||||
|
TileService.requestListeningState(context, ComponentName(context, VpnTileService::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,13 @@ import android.app.Notification
|
|||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.os.ParcelFileDescriptor
|
import android.os.ParcelFileDescriptor
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import bypass.whitelist.MainActivity
|
import bypass.whitelist.MainActivity
|
||||||
@@ -18,6 +21,9 @@ import bypass.whitelist.util.Prefs
|
|||||||
import bypass.whitelist.util.SocksAuth
|
import bypass.whitelist.util.SocksAuth
|
||||||
import bypass.whitelist.util.Vpn
|
import bypass.whitelist.util.Vpn
|
||||||
import androidbind.Androidbind
|
import androidbind.Androidbind
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class TunnelVpnService : VpnService() {
|
class TunnelVpnService : VpnService() {
|
||||||
|
|
||||||
@@ -28,11 +34,29 @@ class TunnelVpnService : VpnService() {
|
|||||||
const val ACTION_STOP = "bypass.whitelist.STOP_VPN"
|
const val ACTION_STOP = "bypass.whitelist.STOP_VPN"
|
||||||
@Volatile var instance: TunnelVpnService? = null
|
@Volatile var instance: TunnelVpnService? = null
|
||||||
@Volatile var onDisconnect: Callback? = null
|
@Volatile var onDisconnect: Callback? = null
|
||||||
|
|
||||||
|
fun requestStop(context: Context) {
|
||||||
|
val running = instance?.let { it.isRunning || it.startInProgress || it.stopInProgress } == true
|
||||||
|
val intent = Intent(context, TunnelVpnService::class.java)
|
||||||
|
try {
|
||||||
|
if (running) {
|
||||||
|
context.startService(intent.apply { action = ACTION_STOP })
|
||||||
|
} else {
|
||||||
|
context.stopService(intent)
|
||||||
|
TunnelServiceState.requestTileRefresh(context)
|
||||||
|
}
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
Log.w(TAG, "requestStop failed: ${t.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Volatile var isRunning: Boolean = false
|
@Volatile var isRunning: Boolean = false
|
||||||
|
@Volatile internal var startInProgress: Boolean = false
|
||||||
|
@Volatile internal var stopInProgress: Boolean = false
|
||||||
private var vpnFd: ParcelFileDescriptor? = null
|
private var vpnFd: ParcelFileDescriptor? = null
|
||||||
private var tun2socksThread: Thread? = null
|
private var tun2socksThread: Thread? = null
|
||||||
|
@Volatile private var tunGeneration: Long = 0
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
@@ -41,6 +65,10 @@ class TunnelVpnService : VpnService() {
|
|||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
if (intent?.action == ACTION_STOP) {
|
if (intent?.action == ACTION_STOP) {
|
||||||
|
if (!isRunning && !startInProgress && !stopInProgress) {
|
||||||
|
safeStopSelf()
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
stop()
|
stop()
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
@@ -49,7 +77,9 @@ class TunnelVpnService : VpnService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
if ((isRunning || startInProgress) && !stopInProgress) {
|
||||||
stop()
|
stop()
|
||||||
|
}
|
||||||
if (instance === this) {
|
if (instance === this) {
|
||||||
instance = null
|
instance = null
|
||||||
}
|
}
|
||||||
@@ -60,28 +90,64 @@ class TunnelVpnService : VpnService() {
|
|||||||
fun updateStatus(status: VpnStatus) {
|
fun updateStatus(status: VpnStatus) {
|
||||||
val nm = getSystemService(NotificationManager::class.java)
|
val nm = getSystemService(NotificationManager::class.java)
|
||||||
nm.notify(NOTIFICATION_ID, buildNotification(getString(status.labelRes)))
|
nm.notify(NOTIFICATION_ID, buildNotification(getString(status.labelRes)))
|
||||||
|
TunnelServiceState.vpnStatusCallback?.invoke(status)
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun stop() {
|
fun stop() {
|
||||||
if (!isRunning) return
|
if (stopInProgress) return
|
||||||
isRunning = false
|
if (!isRunning && !startInProgress) {
|
||||||
try {
|
safeStopSelf()
|
||||||
Androidbind.stopTun2Socks()
|
return
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "tun2socks stop error: ${e.message}")
|
|
||||||
}
|
}
|
||||||
tun2socksThread?.join(3000)
|
isRunning = false
|
||||||
|
startInProgress = false
|
||||||
|
stopInProgress = true
|
||||||
|
bumpTunGeneration()
|
||||||
|
val disconnectCallback = onDisconnect
|
||||||
|
|
||||||
|
thread(name = "vpn-stop") {
|
||||||
|
stopTun2SocksWithTimeout()
|
||||||
|
|
||||||
|
try {
|
||||||
|
tun2socksThread?.join(1000)
|
||||||
|
} catch (e: Exception) {}
|
||||||
|
|
||||||
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
try {
|
||||||
tun2socksThread = null
|
tun2socksThread = null
|
||||||
vpnFd = null
|
vpnFd = null
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
stopForeground(true)
|
stopForeground(true)
|
||||||
//stopSelf()
|
disconnectCallback?.invoke()
|
||||||
onDisconnect?.invoke()
|
TunnelServiceState.requestTileRefresh(this@TunnelVpnService)
|
||||||
|
stopSelf()
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
stopInProgress = false
|
||||||
|
Log.e(TAG, "Crash during VPN stop: ${t.message}", t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopTun2SocksWithTimeout() {
|
||||||
|
val stopDone = CountDownLatch(1)
|
||||||
|
thread(name = "tun2socks-stop") {
|
||||||
|
try {
|
||||||
|
Androidbind.stopTun2Socks()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "tun2socks stop error: ${e.message}")
|
||||||
|
} finally {
|
||||||
|
stopDone.countDown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stopDone.await(2000, TimeUnit.MILLISECONDS)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun start() {
|
private fun start() {
|
||||||
if (isRunning) return
|
if (isRunning || startInProgress) return
|
||||||
|
startInProgress = true
|
||||||
|
|
||||||
startForegroundNotification()
|
startForegroundNotification()
|
||||||
|
|
||||||
@@ -143,25 +209,65 @@ class TunnelVpnService : VpnService() {
|
|||||||
vpnFd = builder.establish()
|
vpnFd = builder.establish()
|
||||||
if (vpnFd == null) {
|
if (vpnFd == null) {
|
||||||
Log.e(TAG, "Failed to establish VPN")
|
Log.e(TAG, "Failed to establish VPN")
|
||||||
|
startInProgress = false
|
||||||
|
TunnelServiceState.logCallback?.invoke("Failed to establish VPN")
|
||||||
|
TunnelServiceState.vpnStatusCallback?.invoke(VpnStatus.CALL_FAILED)
|
||||||
|
stopSelf()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isRunning = true
|
isRunning = true
|
||||||
|
startInProgress = false
|
||||||
val fd = vpnFd!!.detachFd()
|
val fd = vpnFd!!.detachFd()
|
||||||
vpnFd = null
|
vpnFd = null
|
||||||
Log.i(TAG, "VPN established, fd=$fd, SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@${Prefs.socksHost}:${Prefs.socksPort}")
|
Log.i(TAG, "VPN established, fd=$fd, SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@${Prefs.socksHost}:${Prefs.socksPort}")
|
||||||
updateStatus(VpnStatus.TUNNEL_ACTIVE)
|
updateStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||||
|
val startGeneration = bumpTunGeneration()
|
||||||
|
|
||||||
tun2socksThread = Thread {
|
tun2socksThread = Thread {
|
||||||
|
if (!isRunning || stopInProgress || !isTunGenerationCurrent(startGeneration)) {
|
||||||
|
closeRawFd(fd)
|
||||||
|
return@Thread
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Androidbind.startTun2Socks(fd.toLong(), Vpn.MTU.toLong(), Prefs.socksPort, SocksAuth.user, SocksAuth.pass)
|
Androidbind.startTun2Socks(fd.toLong(), Vpn.MTU.toLong(), Prefs.socksPort, SocksAuth.user, SocksAuth.pass)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "tun2socks error: ${e.message}")
|
Log.e(TAG, "tun2socks error: ${e.message}")
|
||||||
isRunning = false
|
isRunning = false
|
||||||
|
startInProgress = false
|
||||||
|
stopInProgress = false
|
||||||
|
TunnelServiceState.logCallback?.invoke("tun2socks error: ${e.message}")
|
||||||
|
TunnelServiceState.vpnStatusCallback?.invoke(VpnStatus.TUNNEL_LOST)
|
||||||
}
|
}
|
||||||
}.also { it.start() }
|
}.also { it.start() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun bumpTunGeneration(): Long = synchronized(this) {
|
||||||
|
tunGeneration += 1
|
||||||
|
tunGeneration
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isTunGenerationCurrent(generation: Long): Boolean = synchronized(this) {
|
||||||
|
tunGeneration == generation
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun closeRawFd(fd: Int) {
|
||||||
|
runCatching { ParcelFileDescriptor.adoptFd(fd).close() }
|
||||||
|
.onFailure { Log.w(TAG, "Failed to close stale tun fd=$fd: ${it.message}") }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun safeStopSelf() {
|
||||||
|
stopInProgress = false
|
||||||
|
isRunning = false
|
||||||
|
startInProgress = false
|
||||||
|
runCatching {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
stopForeground(true)
|
||||||
|
}
|
||||||
|
TunnelServiceState.requestTileRefresh(this)
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
|
|
||||||
private fun getSystemDnsServers(): List<String> {
|
private fun getSystemDnsServers(): List<String> {
|
||||||
val connectivityManager = getSystemService(ConnectivityManager::class.java) ?: return emptyList()
|
val connectivityManager = getSystemService(ConnectivityManager::class.java) ?: return emptyList()
|
||||||
val network = connectivityManager.activeNetwork ?: return emptyList()
|
val network = connectivityManager.activeNetwork ?: return emptyList()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import bypass.whitelist.R
|
|||||||
|
|
||||||
enum class VpnStatus(@StringRes val labelRes: Int) {
|
enum class VpnStatus(@StringRes val labelRes: Int) {
|
||||||
STARTING(R.string.vpn_starting),
|
STARTING(R.string.vpn_starting),
|
||||||
|
STOPPING(R.string.vpn_stopping),
|
||||||
CONNECTING(R.string.vpn_connecting),
|
CONNECTING(R.string.vpn_connecting),
|
||||||
CALL_CONNECTED(R.string.vpn_call_connected),
|
CALL_CONNECTED(R.string.vpn_call_connected),
|
||||||
DATACHANNEL_OPEN(R.string.vpn_datachannel_open),
|
DATACHANNEL_OPEN(R.string.vpn_datachannel_open),
|
||||||
@@ -14,5 +15,6 @@ enum class VpnStatus(@StringRes val labelRes: Int) {
|
|||||||
CALL_DISCONNECTED(R.string.vpn_call_disconnected),
|
CALL_DISCONNECTED(R.string.vpn_call_disconnected),
|
||||||
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),
|
||||||
ACTION_REQUIRED_CAPTCHA(R.string.action_required_captcha)
|
ACTION_REQUIRED_CAPTCHA(R.string.action_required_captcha)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package bypass.whitelist.tunnel
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
|
import android.service.quicksettings.Tile
|
||||||
|
import android.service.quicksettings.TileService
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
|
class VpnTileService : TileService() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "VpnTileService"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartListening() {
|
||||||
|
super.onStartListening()
|
||||||
|
updateTile()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick() {
|
||||||
|
super.onClick()
|
||||||
|
if (TunnelServiceState.isAnyTunnelComponentRunning(this)) {
|
||||||
|
stopAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLocked) {
|
||||||
|
updateTile()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
unlockAndRun {
|
||||||
|
startSession()
|
||||||
|
qsTile?.let {
|
||||||
|
it.state = Tile.STATE_ACTIVE
|
||||||
|
it.label = "Connecting..."
|
||||||
|
it.updateTile()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startSession() {
|
||||||
|
try {
|
||||||
|
val intent = Intent(this, HeadlessSessionService::class.java)
|
||||||
|
ContextCompat.startForegroundService(this, intent)
|
||||||
|
Log.d(TAG, "HeadlessSessionService start requested")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Failed to start HeadlessSessionService: ${e.message}", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopAll() {
|
||||||
|
HeadlessSessionService.requestStop(this)
|
||||||
|
TunnelVpnService.requestStop(this)
|
||||||
|
ProxyService.requestStop(this)
|
||||||
|
qsTile?.let {
|
||||||
|
it.state = Tile.STATE_INACTIVE
|
||||||
|
it.label = "whitelistbypass"
|
||||||
|
it.updateTile()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateTile() {
|
||||||
|
val tile = qsTile ?: return
|
||||||
|
when {
|
||||||
|
TunnelServiceState.isTunnelActive(this) -> {
|
||||||
|
tile.state = Tile.STATE_ACTIVE
|
||||||
|
tile.label = "Bypass ON"
|
||||||
|
}
|
||||||
|
TunnelServiceState.isHeadlessSessionRunning(this) -> {
|
||||||
|
tile.state = Tile.STATE_ACTIVE
|
||||||
|
tile.label = "Connecting..."
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
tile.state = Tile.STATE_INACTIVE
|
||||||
|
tile.label = "whitelistbypass"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tile.updateTile()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,8 +40,8 @@ class ConfirmActionSheet : BottomSheetDialogFragment() {
|
|||||||
|
|
||||||
if (destructive) {
|
if (destructive) {
|
||||||
val context = requireContext()
|
val context = requireContext()
|
||||||
titleView.setTextColor(context.getColor(R.color.error_red))
|
titleView.setTextColor(context.getColor(R.color.accent_emerald))
|
||||||
confirm.backgroundTintList = ColorStateList.valueOf(context.getColor(R.color.error_red))
|
confirm.backgroundTintList = ColorStateList.valueOf(context.getColor(R.color.accent_emerald))
|
||||||
confirm.setTextColor(context.getColor(R.color.panel_bg))
|
confirm.setTextColor(context.getColor(R.color.panel_bg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package bypass.whitelist.ui
|
package bypass.whitelist.ui
|
||||||
|
|
||||||
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@@ -15,11 +16,13 @@ import bypass.whitelist.tunnel.HeadlessRelayController
|
|||||||
import bypass.whitelist.tunnel.VpnStatus
|
import bypass.whitelist.tunnel.VpnStatus
|
||||||
import bypass.whitelist.util.BLANK_URL
|
import bypass.whitelist.util.BLANK_URL
|
||||||
import bypass.whitelist.util.Prefs
|
import bypass.whitelist.util.Prefs
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
class HeadlessVkFragment : Fragment() {
|
class HeadlessVkFragment : Fragment(), JoinSessionShutdown {
|
||||||
|
|
||||||
private lateinit var relay: HeadlessRelayController
|
private lateinit var relay: HeadlessRelayController
|
||||||
private lateinit var webView: WebView
|
private lateinit var webView: WebView
|
||||||
|
private val shutdownOnce = AtomicBoolean(false)
|
||||||
|
|
||||||
private val host: JoinFragmentHost?
|
private val host: JoinFragmentHost?
|
||||||
get() = activity as? JoinFragmentHost
|
get() = activity as? JoinFragmentHost
|
||||||
@@ -41,33 +44,40 @@ class HeadlessVkFragment : Fragment() {
|
|||||||
webView.settings.javaScriptEnabled = true
|
webView.settings.javaScriptEnabled = true
|
||||||
webView.settings.domStorageEnabled = true
|
webView.settings.domStorageEnabled = true
|
||||||
webView.webViewClient = WebViewClient()
|
webView.webViewClient = WebViewClient()
|
||||||
webView.setBackgroundColor(android.graphics.Color.WHITE)
|
webView.setBackgroundColor(Color.WHITE)
|
||||||
webView.isVisible = false
|
webView.isVisible = false
|
||||||
|
|
||||||
relay = HeadlessRelayController(
|
relay = HeadlessRelayController(
|
||||||
requireContext().applicationInfo.nativeLibraryDir,
|
requireContext().applicationInfo.nativeLibraryDir,
|
||||||
onLog = { message ->
|
onLog = { message ->
|
||||||
|
if (!isSessionAlive()) return@HeadlessRelayController
|
||||||
if (message.contains("ERROR:") && !message.contains("ortc ERROR")) {
|
if (message.contains("ERROR:") && !message.contains("ortc ERROR")) {
|
||||||
host?.onJoinStatusText(message)
|
host?.onJoinStatusText(message)
|
||||||
}
|
}
|
||||||
host?.appendLog(message)
|
host?.appendLog(message)
|
||||||
},
|
},
|
||||||
onStatus = { status ->
|
onStatus = { status ->
|
||||||
|
if (!isSessionAlive()) return@HeadlessRelayController
|
||||||
Log.d("HEADLESS-VK", "status: $status")
|
Log.d("HEADLESS-VK", "status: $status")
|
||||||
host?.onJoinStatus(status)
|
|
||||||
if (status == VpnStatus.TUNNEL_ACTIVE) {
|
if (status == VpnStatus.TUNNEL_ACTIVE) {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
|
if (!isSessionAlive()) return@runOnUiThread
|
||||||
|
host?.onJoinStatusText("Relay ready, starting local VPN")
|
||||||
webView.stopLoading()
|
webView.stopLoading()
|
||||||
webView.loadUrl(BLANK_URL)
|
webView.loadUrl(BLANK_URL)
|
||||||
webView.isVisible = false
|
webView.isVisible = false
|
||||||
host?.setJoinUiVisible(false)
|
host?.setJoinUiVisible(false)
|
||||||
host?.requestVpn()
|
host?.requestVpn()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
host?.onJoinStatus(status)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onCaptchaUrl = { captchaUrl ->
|
onCaptchaUrl = { captchaUrl ->
|
||||||
|
if (!isSessionAlive()) return@HeadlessRelayController
|
||||||
Log.d("HEADLESS-VK", "captcha URL: $captchaUrl")
|
Log.d("HEADLESS-VK", "captcha URL: $captchaUrl")
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
|
if (!isSessionAlive()) return@runOnUiThread
|
||||||
host?.setJoinUiVisible(true)
|
host?.setJoinUiVisible(true)
|
||||||
webView.isVisible = true
|
webView.isVisible = true
|
||||||
webView.loadUrl(captchaUrl)
|
webView.loadUrl(captchaUrl)
|
||||||
@@ -75,17 +85,36 @@ class HeadlessVkFragment : Fragment() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
relay.start()
|
relay.start()
|
||||||
relay.sendAuth(url, displayName, Prefs.tunnelMode.relayArg)
|
relay.sendAuth(url, displayName, Prefs.activeTunnelMode.relayArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
shutdownSession()
|
||||||
|
if (::webView.isInitialized) {
|
||||||
|
runCatching {
|
||||||
webView.stopLoading()
|
webView.stopLoading()
|
||||||
webView.loadUrl(BLANK_URL)
|
webView.loadUrl(BLANK_URL)
|
||||||
webView.destroy()
|
webView.destroy()
|
||||||
relay.stop()
|
}
|
||||||
|
}
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun shutdownSession() {
|
||||||
|
if (!shutdownOnce.compareAndSet(false, true)) return
|
||||||
|
if (::webView.isInitialized) {
|
||||||
|
runCatching {
|
||||||
|
webView.stopLoading()
|
||||||
|
webView.loadUrl(BLANK_URL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (::relay.isInitialized) {
|
||||||
|
runCatching { relay.stop() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isSessionAlive(): Boolean = !shutdownOnce.get()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val ARG_URL = "url"
|
const val ARG_URL = "url"
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import android.graphics.SweepGradient
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.animation.LinearInterpolator
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import bypass.whitelist.R
|
import bypass.whitelist.R
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ class HeroRingOuterView @JvmOverloads constructor(
|
|||||||
spinAnimator = ValueAnimator.ofFloat(0f, 360f).apply {
|
spinAnimator = ValueAnimator.ofFloat(0f, 360f).apply {
|
||||||
duration = durationMs
|
duration = durationMs
|
||||||
repeatCount = ValueAnimator.INFINITE
|
repeatCount = ValueAnimator.INFINITE
|
||||||
interpolator = android.view.animation.LinearInterpolator()
|
interpolator = LinearInterpolator()
|
||||||
addUpdateListener {
|
addUpdateListener {
|
||||||
sweepRotationDegrees = it.animatedValue as Float
|
sweepRotationDegrees = it.animatedValue as Float
|
||||||
invalidate()
|
invalidate()
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package bypass.whitelist.ui
|
||||||
|
|
||||||
|
interface JoinSessionShutdown {
|
||||||
|
fun shutdownSession()
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package bypass.whitelist.ui
|
package bypass.whitelist.ui
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -16,6 +17,7 @@ import android.webkit.WebResourceRequest
|
|||||||
import android.webkit.WebResourceResponse
|
import android.webkit.WebResourceResponse
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.webkit.WebViewClient
|
import android.webkit.WebViewClient
|
||||||
|
import android.widget.ImageButton
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
@@ -33,10 +35,11 @@ import java.net.HttpURLConnection
|
|||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
private data class HookKey(val isPion: Boolean, val platform: CallPlatform)
|
private data class HookKey(val isPion: Boolean, val platform: CallPlatform)
|
||||||
|
|
||||||
class JsHookJoinFragment : Fragment() {
|
class JsHookJoinFragment : Fragment(), JoinSessionShutdown {
|
||||||
|
|
||||||
private lateinit var webView: WebView
|
private lateinit var webView: WebView
|
||||||
private lateinit var toggleButton: View
|
private lateinit var toggleButton: View
|
||||||
@@ -46,12 +49,13 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
|
|
||||||
private var expanded = false
|
private var expanded = false
|
||||||
private var callUrl = ""
|
private var callUrl = ""
|
||||||
|
private val shutdownOnce = AtomicBoolean(false)
|
||||||
|
|
||||||
private val host: JoinFragmentHost?
|
private val host: JoinFragmentHost?
|
||||||
get() = activity as? JoinFragmentHost
|
get() = activity as? JoinFragmentHost
|
||||||
|
|
||||||
private val tunnelMode: TunnelMode
|
private val tunnelMode: TunnelMode
|
||||||
get() = Prefs.tunnelMode
|
get() = Prefs.activeTunnelMode
|
||||||
|
|
||||||
private val hooks = mapOf(
|
private val hooks = mapOf(
|
||||||
HookKey(false, CallPlatform.VK) to lazy { loadAsset("dc-joiner-vk.js") },
|
HookKey(false, CallPlatform.VK) to lazy { loadAsset("dc-joiner-vk.js") },
|
||||||
@@ -67,9 +71,6 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
|
|
||||||
private val muteAudioContext by lazy { loadAsset("mute-audio-context.js") }
|
private val muteAudioContext by lazy { loadAsset("mute-audio-context.js") }
|
||||||
|
|
||||||
private fun loadAsset(name: String): String =
|
|
||||||
requireContext().assets.open(name).bufferedReader().readText()
|
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
@@ -82,14 +83,18 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
toggleButton = view.findViewById(R.id.toggleWebViewButton)
|
toggleButton = view.findViewById(R.id.toggleWebViewButton)
|
||||||
toggleArrow = view.findViewById(R.id.toggleWebViewArrow)
|
toggleArrow = view.findViewById(R.id.toggleWebViewArrow)
|
||||||
toggleLabel = view.findViewById(R.id.toggleWebViewLabel)
|
toggleLabel = view.findViewById(R.id.toggleWebViewLabel)
|
||||||
view.findViewById<android.widget.ImageButton>(R.id.webviewBackButton).setOnClickListener {
|
view.findViewById<ImageButton>(R.id.webviewBackButton).setOnClickListener {
|
||||||
host?.onJoinCancel()
|
host?.onJoinCancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
relay = RelayController(
|
relay = RelayController(
|
||||||
nativeLibDir = requireContext().applicationInfo.nativeLibraryDir,
|
nativeLibDir = requireContext().applicationInfo.nativeLibraryDir,
|
||||||
onLog = { host?.appendLog(it) },
|
onLog = {
|
||||||
|
if (!isSessionAlive()) return@RelayController
|
||||||
|
host?.appendLog(it)
|
||||||
|
},
|
||||||
onStatus = { status ->
|
onStatus = { status ->
|
||||||
|
if (!isSessionAlive()) return@RelayController
|
||||||
if (!relay.isRunning) return@RelayController
|
if (!relay.isRunning) return@RelayController
|
||||||
host?.onJoinStatus(status)
|
host?.onJoinStatus(status)
|
||||||
},
|
},
|
||||||
@@ -123,6 +128,7 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onConsoleMessage(msg: ConsoleMessage): Boolean {
|
override fun onConsoleMessage(msg: ConsoleMessage): Boolean {
|
||||||
|
if (!isSessionAlive()) return true
|
||||||
val text = msg.message()
|
val text = msg.message()
|
||||||
Log.d("HOOK", text)
|
Log.d("HOOK", text)
|
||||||
if (text.contains("[HOOK]")) {
|
if (text.contains("[HOOK]")) {
|
||||||
@@ -131,7 +137,7 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
text.contains("CALL CONNECTED") -> host?.onJoinStatus(VpnStatus.CALL_CONNECTED)
|
text.contains("CALL CONNECTED") -> host?.onJoinStatus(VpnStatus.CALL_CONNECTED)
|
||||||
text.contains("DataChannel open") -> host?.onJoinStatus(VpnStatus.DATACHANNEL_OPEN)
|
text.contains("DataChannel open") -> host?.onJoinStatus(VpnStatus.DATACHANNEL_OPEN)
|
||||||
text.contains("DataChannel closed") -> host?.onJoinStatus(VpnStatus.DATACHANNEL_LOST)
|
text.contains("DataChannel closed") -> host?.onJoinStatus(VpnStatus.DATACHANNEL_LOST)
|
||||||
text.contains("WebSocket connected") -> host?.onJoinStatus(VpnStatus.TUNNEL_ACTIVE)
|
text.contains("WebSocket connected") -> host?.onJoinStatus(VpnStatus.CALL_CONNECTED)
|
||||||
text.contains("WebSocket disconnected") -> host?.onJoinStatus(VpnStatus.TUNNEL_LOST)
|
text.contains("WebSocket disconnected") -> host?.onJoinStatus(VpnStatus.TUNNEL_LOST)
|
||||||
text.contains("Connection state: connecting") -> host?.onJoinStatus(VpnStatus.CONNECTING)
|
text.contains("Connection state: connecting") -> host?.onJoinStatus(VpnStatus.CONNECTING)
|
||||||
text.contains("Connection state: disconnected") -> host?.onJoinStatus(VpnStatus.CALL_DISCONNECTED)
|
text.contains("Connection state: disconnected") -> host?.onJoinStatus(VpnStatus.CALL_DISCONNECTED)
|
||||||
@@ -144,6 +150,7 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
|
|
||||||
webView.webViewClient = object : WebViewClient() {
|
webView.webViewClient = object : WebViewClient() {
|
||||||
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
|
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
|
||||||
|
if (!isSessionAlive()) return null
|
||||||
val url = request.url.toString()
|
val url = request.url.toString()
|
||||||
val platform = CallPlatform.fromUrl(url)
|
val platform = CallPlatform.fromUrl(url)
|
||||||
if (platform != CallPlatform.TELEMOST || !url.contains("/j/") || request.method != "GET") return null
|
if (platform != CallPlatform.TELEMOST || !url.contains("/j/") || request.method != "GET") return null
|
||||||
@@ -151,14 +158,17 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
|
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
|
||||||
|
if (!isSessionAlive()) return
|
||||||
if (url.contains(BLANK_URL)) return
|
if (url.contains(BLANK_URL)) return
|
||||||
view.evaluateJavascript(muteAudioContext, null)
|
view.evaluateJavascript(muteAudioContext, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageFinished(view: WebView, url: String) {
|
override fun onPageFinished(view: WebView, url: String) {
|
||||||
|
if (!isSessionAlive()) return
|
||||||
if (url.contains(BLANK_URL)) return
|
if (url.contains(BLANK_URL)) return
|
||||||
if (!expanded && url != callUrl) activity?.runOnUiThread { setExpanded(true) }
|
if (!expanded && url != callUrl) activity?.runOnUiThread { setExpanded(true) }
|
||||||
view.evaluateJavascript("!!window.__hookInstalled") { result ->
|
view.evaluateJavascript("!!window.__hookInstalled") { result ->
|
||||||
|
if (!isSessionAlive()) return@evaluateJavascript
|
||||||
if (result == "true") {
|
if (result == "true") {
|
||||||
Log.d("HOOK", "Hook already injected, skipping")
|
Log.d("HOOK", "Hook already injected, skipping")
|
||||||
return@evaluateJavascript
|
return@evaluateJavascript
|
||||||
@@ -185,17 +195,34 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
shutdownSession()
|
||||||
|
if (::webView.isInitialized) {
|
||||||
|
runCatching {
|
||||||
webView.stopLoading()
|
webView.stopLoading()
|
||||||
webView.loadUrl(BLANK_URL)
|
webView.loadUrl(BLANK_URL)
|
||||||
webView.destroy()
|
webView.destroy()
|
||||||
relay.stop()
|
}
|
||||||
|
}
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun shutdownSession() {
|
||||||
|
if (!shutdownOnce.compareAndSet(false, true)) return
|
||||||
|
runCatching { relay.stop() }
|
||||||
|
if (::webView.isInitialized) {
|
||||||
|
runCatching {
|
||||||
|
webView.stopLoading()
|
||||||
|
webView.loadUrl(BLANK_URL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun expand() {
|
fun expand() {
|
||||||
setExpanded(true)
|
setExpanded(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isSessionAlive(): Boolean = !shutdownOnce.get()
|
||||||
|
|
||||||
private fun setExpanded(value: Boolean) {
|
private fun setExpanded(value: Boolean) {
|
||||||
expanded = value
|
expanded = value
|
||||||
webView.visibility = if (value) View.VISIBLE else View.GONE
|
webView.visibility = if (value) View.VISIBLE else View.GONE
|
||||||
@@ -231,7 +258,7 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
private fun getLocalIPAddress(): String {
|
private fun getLocalIPAddress(): String {
|
||||||
try {
|
try {
|
||||||
val context = context ?: return ""
|
val context = context ?: return ""
|
||||||
val connectivityManager = context.getSystemService(android.content.Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
val network = connectivityManager.activeNetwork ?: return ""
|
val network = connectivityManager.activeNetwork ?: return ""
|
||||||
val linkProperties = connectivityManager.getLinkProperties(network) ?: return ""
|
val linkProperties = connectivityManager.getLinkProperties(network) ?: return ""
|
||||||
for (addr in linkProperties.linkAddresses) {
|
for (addr in linkProperties.linkAddresses) {
|
||||||
@@ -246,10 +273,16 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadAsset(name: String): String =
|
||||||
|
requireContext().assets.open(name).bufferedReader().readText()
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
inner class JsBridge {
|
inner class JsBridge {
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
fun log(msg: String) = host?.appendLog(msg)
|
fun log(msg: String) {
|
||||||
|
if (!isSessionAlive()) return
|
||||||
|
host?.appendLog(msg)
|
||||||
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
fun getLocalIP(): String = getLocalIPAddress()
|
fun getLocalIP(): String = getLocalIPAddress()
|
||||||
@@ -269,13 +302,15 @@ class JsHookJoinFragment : Fragment() {
|
|||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
fun onTunnelReady() {
|
fun onTunnelReady() {
|
||||||
|
if (!isSessionAlive()) return
|
||||||
host?.appendLog("Tunnel ready, starting VPN...")
|
host?.appendLog("Tunnel ready, starting VPN...")
|
||||||
host?.onJoinStatus(VpnStatus.TUNNEL_ACTIVE)
|
host?.onJoinStatusText("Relay ready, starting local VPN")
|
||||||
activity?.runOnUiThread { host?.requestVpn() }
|
activity?.runOnUiThread { host?.requestVpn() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
fun onCaptchaDetected(isDone: Boolean) {
|
fun onCaptchaDetected(isDone: Boolean) {
|
||||||
|
if (!isSessionAlive()) return
|
||||||
if (!isDone) {
|
if (!isDone) {
|
||||||
host?.onJoinStatus(VpnStatus.ACTION_REQUIRED_CAPTCHA)
|
host?.onJoinStatus(VpnStatus.ACTION_REQUIRED_CAPTCHA)
|
||||||
activity?.runOnUiThread { expand() }
|
activity?.runOnUiThread { expand() }
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import android.os.Bundle
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.PopupMenu
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import bypass.whitelist.R
|
import bypass.whitelist.R
|
||||||
import bypass.whitelist.tunnel.CallConfig
|
import bypass.whitelist.tunnel.CallConfig
|
||||||
|
import bypass.whitelist.tunnel.CallPlatform
|
||||||
|
import bypass.whitelist.tunnel.TunnelMode
|
||||||
import bypass.whitelist.tunnel.VpnStatus
|
import bypass.whitelist.tunnel.VpnStatus
|
||||||
import bypass.whitelist.util.Prefs
|
import bypass.whitelist.util.Prefs
|
||||||
|
|
||||||
@@ -63,9 +63,7 @@ class MainFragment : Fragment(R.layout.fragment_main_screen) {
|
|||||||
Prefs.activeDestinationId = config.id
|
Prefs.activeDestinationId = config.id
|
||||||
container.bindCalls(Prefs.savedDestinations, Prefs.activeDestinationId)
|
container.bindCalls(Prefs.savedDestinations, Prefs.activeDestinationId)
|
||||||
}
|
}
|
||||||
container.onCallLongPressed = { config, anchor ->
|
container.onCallLongPressed = ::showRowMenu
|
||||||
showRowMenu(config, anchor)
|
|
||||||
}
|
|
||||||
|
|
||||||
pendingStatus?.let { container.bindStatus(it) }
|
pendingStatus?.let { container.bindStatus(it) }
|
||||||
pendingStatus = null
|
pendingStatus = null
|
||||||
@@ -115,23 +113,60 @@ class MainFragment : Fragment(R.layout.fragment_main_screen) {
|
|||||||
content?.bindCalls(Prefs.savedDestinations, Prefs.activeDestinationId)
|
content?.bindCalls(Prefs.savedDestinations, Prefs.activeDestinationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showRowMenu(config: CallConfig, anchor: View) {
|
private fun showRowMenu(config: CallConfig) {
|
||||||
|
val tunnelMode = (config.tunnelMode ?: Prefs.tunnelMode).forPlatform(config.platform)
|
||||||
|
val vp8Fps = config.vp8Fps ?: Prefs.vp8Fps
|
||||||
|
val vp8Batch = config.vp8Batch ?: Prefs.vp8Batch
|
||||||
|
val vp8SubRes = if (config.dualTrack ?: Prefs.dualTrack) R.string.settings_row_vp8_sub_dual else R.string.settings_row_vp8_sub
|
||||||
MenuActionSheet.show(
|
MenuActionSheet.show(
|
||||||
manager = parentFragmentManager,
|
manager = parentFragmentManager,
|
||||||
title = config.name,
|
title = config.name,
|
||||||
subtitle = config.url,
|
subtitle = config.url,
|
||||||
items = listOf(
|
items = listOf(
|
||||||
|
MenuActionSheet.MenuItem("tunnel", getString(R.string.settings_row_tunnel_mode), R.drawable.ic_setting_tunnel, value = tunnelMode.label),
|
||||||
|
MenuActionSheet.MenuItem("vp8", getString(R.string.settings_row_vp8), R.drawable.ic_setting_vp8, value = getString(vp8SubRes, vp8Fps, vp8Batch)),
|
||||||
MenuActionSheet.MenuItem("rename", getString(R.string.destination_menu_rename), R.drawable.ic_action_pencil),
|
MenuActionSheet.MenuItem("rename", getString(R.string.destination_menu_rename), R.drawable.ic_action_pencil),
|
||||||
MenuActionSheet.MenuItem("delete", getString(R.string.destination_menu_delete), R.drawable.ic_setting_trash, danger = true),
|
MenuActionSheet.MenuItem("delete", getString(R.string.destination_menu_delete), R.drawable.ic_setting_trash, danger = true),
|
||||||
),
|
),
|
||||||
) { item ->
|
) { item ->
|
||||||
when (item.id) {
|
when (item.id) {
|
||||||
|
"tunnel" -> editTunnelMode(config)
|
||||||
|
"vp8" -> editVp8(config)
|
||||||
"rename" -> promptRename(config)
|
"rename" -> promptRename(config)
|
||||||
"delete" -> confirmDelete(config)
|
"delete" -> confirmDelete(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun editTunnelMode(config: CallConfig) {
|
||||||
|
val current = (config.tunnelMode ?: Prefs.tunnelMode).forPlatform(config.platform)
|
||||||
|
ChoiceActionSheet.show(
|
||||||
|
manager = parentFragmentManager,
|
||||||
|
title = getString(R.string.settings_row_tunnel_mode),
|
||||||
|
options = TunnelMode.entries.filter { it == TunnelMode.VIDEO || (config.platform != CallPlatform.TELEMOST && config.platform != CallPlatform.DION) }.map { ChoiceActionSheet.Option(it.name, it.label) },
|
||||||
|
selectedId = current.name,
|
||||||
|
) { picked ->
|
||||||
|
val newMode = TunnelMode.valueOf(picked.id)
|
||||||
|
Prefs.updateDestination(config.copy(tunnelMode = newMode))
|
||||||
|
onDestinationsChanged()
|
||||||
|
if (Prefs.activeDestinationId == config.id) {
|
||||||
|
(activity as? SettingsScreenFragment.Host)?.onTunnelModeChanged(newMode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun editVp8(config: CallConfig) {
|
||||||
|
Vp8ActionSheet.show(
|
||||||
|
parentFragmentManager,
|
||||||
|
config.vp8Fps ?: Prefs.vp8Fps,
|
||||||
|
config.vp8Batch ?: Prefs.vp8Batch,
|
||||||
|
config.dualTrack ?: Prefs.dualTrack,
|
||||||
|
) { fps, batch, dual ->
|
||||||
|
Prefs.updateDestination(config.copy(vp8Fps = fps, vp8Batch = batch, dualTrack = dual))
|
||||||
|
onDestinationsChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun promptRename(config: CallConfig) {
|
private fun promptRename(config: CallConfig) {
|
||||||
InputActionSheet.show(
|
InputActionSheet.show(
|
||||||
manager = parentFragmentManager,
|
manager = parentFragmentManager,
|
||||||
@@ -164,8 +199,8 @@ class MainFragment : Fragment(R.layout.fragment_main_screen) {
|
|||||||
val view = content ?: return
|
val view = content ?: return
|
||||||
val uptimeMs = if (connectedSinceMs > 0L) System.currentTimeMillis() - connectedSinceMs else 0L
|
val uptimeMs = if (connectedSinceMs > 0L) System.currentTimeMillis() - connectedSinceMs else 0L
|
||||||
val active = Prefs.activeDestination
|
val active = Prefs.activeDestination
|
||||||
val effectiveMode = if (active != null) Prefs.tunnelMode.effectiveFor(active.platform) else Prefs.tunnelMode
|
val mode = if (active != null) Prefs.activeTunnelMode.forPlatform(active.platform) else Prefs.tunnelMode
|
||||||
view.setStats(uptimeText = formatUptime(uptimeMs), mode = effectiveMode.label)
|
view.setStats(uptimeText = formatUptime(uptimeMs), mode = mode.label)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatUptime(ms: Long): String {
|
private fun formatUptime(ms: Long): String {
|
||||||
@@ -182,6 +217,7 @@ class MainFragment : Fragment(R.layout.fragment_main_screen) {
|
|||||||
private fun isHostConnected(): Boolean = host()?.isTunnelActive() ?: false
|
private fun isHostConnected(): Boolean = host()?.isTunnelActive() ?: false
|
||||||
|
|
||||||
private fun isHostConnecting(): Boolean = when (hostStatus()) {
|
private fun isHostConnecting(): Boolean = when (hostStatus()) {
|
||||||
|
VpnStatus.STOPPING,
|
||||||
VpnStatus.CONNECTING,
|
VpnStatus.CONNECTING,
|
||||||
VpnStatus.STARTING,
|
VpnStatus.STARTING,
|
||||||
VpnStatus.CALL_CONNECTED,
|
VpnStatus.CALL_CONNECTED,
|
||||||
@@ -190,9 +226,4 @@ class MainFragment : Fragment(R.layout.fragment_main_screen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun hostStatus(): VpnStatus? = host()?.currentStatus()
|
private fun hostStatus(): VpnStatus? = host()?.currentStatus()
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val MENU_RENAME = 1
|
|
||||||
private const val MENU_DELETE = 2
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,11 @@ package bypass.whitelist.ui
|
|||||||
|
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.HapticFeedbackConstants
|
||||||
import android.view.animation.AlphaAnimation
|
import android.view.animation.AlphaAnimation
|
||||||
|
import android.view.animation.OvershootInterpolator
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
@@ -43,7 +46,7 @@ class MainFragmentView(private val root: View) {
|
|||||||
var onHeroPressed: Callback? = null
|
var onHeroPressed: Callback? = null
|
||||||
var onPingPressed: Callback? = null
|
var onPingPressed: Callback? = null
|
||||||
var onCallSelected: ParamCallback<CallConfig>? = null
|
var onCallSelected: ParamCallback<CallConfig>? = null
|
||||||
var onCallLongPressed: ((CallConfig, View) -> Unit)? = null
|
var onCallLongPressed: ParamCallback<CallConfig>? = null
|
||||||
|
|
||||||
private var pulseAnimator: ValueAnimator? = null
|
private var pulseAnimator: ValueAnimator? = null
|
||||||
private var collapsedToActive: Boolean = false
|
private var collapsedToActive: Boolean = false
|
||||||
@@ -55,7 +58,34 @@ class MainFragmentView(private val root: View) {
|
|||||||
pingButton.clipToOutline = true
|
pingButton.clipToOutline = true
|
||||||
addButton.setOnClickListener { onAddCallClicked?.invoke() }
|
addButton.setOnClickListener { onAddCallClicked?.invoke() }
|
||||||
emptyCta.setOnClickListener { onAddCallClicked?.invoke() }
|
emptyCta.setOnClickListener { onAddCallClicked?.invoke() }
|
||||||
hero.setOnClickListener { onHeroPressed?.invoke() }
|
hero.setOnTouchListener { v, event ->
|
||||||
|
when (event.action) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
v.animate().scaleX(0.92f).scaleY(0.92f)
|
||||||
|
.setDuration(100)
|
||||||
|
.setInterpolator(OvershootInterpolator(2f))
|
||||||
|
.start()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_UP -> {
|
||||||
|
v.animate().scaleX(1f).scaleY(1f)
|
||||||
|
.setDuration(200)
|
||||||
|
.setInterpolator(OvershootInterpolator(3f))
|
||||||
|
.start()
|
||||||
|
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
|
||||||
|
onHeroPressed?.invoke()
|
||||||
|
v.performClick()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_CANCEL -> {
|
||||||
|
v.animate().scaleX(1f).scaleY(1f)
|
||||||
|
.setDuration(150)
|
||||||
|
.start()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
pingButton.setOnClickListener { onPingPressed?.invoke() }
|
pingButton.setOnClickListener { onPingPressed?.invoke() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,67 +96,6 @@ class MainFragmentView(private val root: View) {
|
|||||||
updateHeaderSubForList(calls.size)
|
updateHeaderSubForList(calls.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderCalls() {
|
|
||||||
callsList.removeAllViews()
|
|
||||||
val inflater = LayoutInflater.from(root.context)
|
|
||||||
val visibleCalls = if (collapsedToActive) {
|
|
||||||
currentCalls.filter { it.id == activeCallId }
|
|
||||||
} else {
|
|
||||||
currentCalls
|
|
||||||
}
|
|
||||||
if (currentCalls.isEmpty()) {
|
|
||||||
emptyCta.visibility = View.VISIBLE
|
|
||||||
callsList.visibility = View.GONE
|
|
||||||
return
|
|
||||||
}
|
|
||||||
emptyCta.visibility = View.GONE
|
|
||||||
callsList.visibility = View.VISIBLE
|
|
||||||
visibleCalls.forEach { config ->
|
|
||||||
val row = inflater.inflate(R.layout.item_call_row, callsList, false)
|
|
||||||
row.clipToOutline = true
|
|
||||||
bindRow(row, config, isActive = config.id == activeCallId)
|
|
||||||
row.setOnClickListener { onCallSelected?.invoke(config) }
|
|
||||||
row.setOnLongClickListener {
|
|
||||||
onCallLongPressed?.invoke(config, row)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
callsList.addView(row)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun bindRow(row: View, config: CallConfig, isActive: Boolean) {
|
|
||||||
val context = row.context
|
|
||||||
val nameView = row.findViewById<TextView>(R.id.rowName)
|
|
||||||
val linkView = row.findViewById<TextView>(R.id.rowLink)
|
|
||||||
val glyphView = row.findViewById<TextView>(R.id.rowGlyph)
|
|
||||||
val glyphBox = row.findViewById<View>(R.id.rowGlyphBox)
|
|
||||||
val statusDot = row.findViewById<View>(R.id.rowStatusDot)
|
|
||||||
|
|
||||||
nameView.text = config.name
|
|
||||||
linkView.text = config.url
|
|
||||||
glyphView.text = config.platformGlyph
|
|
||||||
|
|
||||||
if (isActive) {
|
|
||||||
row.setBackgroundResource(R.drawable.bg_destination_card_active)
|
|
||||||
statusDot.setBackgroundResource(R.drawable.bg_status_dot_active)
|
|
||||||
glyphBox.setBackgroundResource(R.drawable.bg_glyph_chip_active)
|
|
||||||
glyphView.setTextColor(context.getColor(R.color.panel_bg))
|
|
||||||
} else {
|
|
||||||
row.setBackgroundResource(R.drawable.bg_destination_card)
|
|
||||||
statusDot.setBackgroundResource(R.drawable.bg_status_dot_idle)
|
|
||||||
glyphBox.setBackgroundResource(R.drawable.bg_glyph_chip)
|
|
||||||
glyphView.setTextColor(context.getColor(R.color.ink))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateHeaderSubForList(count: Int) {
|
|
||||||
if (collapsedToActive) return
|
|
||||||
headerSub.text = when (count) {
|
|
||||||
0 -> root.context.getString(R.string.main_sub_no_configs)
|
|
||||||
else -> root.context.resources.getQuantityString(R.plurals.main_sub_count, count, count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bindHero(connected: Boolean, status: VpnStatus?) {
|
fun bindHero(connected: Boolean, status: VpnStatus?) {
|
||||||
val context = root.context
|
val context = root.context
|
||||||
if (connected) {
|
if (connected) {
|
||||||
@@ -144,12 +113,12 @@ class MainFragmentView(private val root: View) {
|
|||||||
collapsedToActive = true
|
collapsedToActive = true
|
||||||
renderCalls()
|
renderCalls()
|
||||||
stopPulse()
|
stopPulse()
|
||||||
} else if (status == VpnStatus.CONNECTING || status == VpnStatus.STARTING || status == VpnStatus.CALL_CONNECTED || status == VpnStatus.DATACHANNEL_OPEN) {
|
} else if (status == VpnStatus.CONNECTING || status == VpnStatus.STARTING || status == VpnStatus.STOPPING || status == VpnStatus.CALL_CONNECTED || status == VpnStatus.DATACHANNEL_OPEN) {
|
||||||
heroLabel.text = context.getString(R.string.hero_cancel)
|
heroLabel.text = context.getString(R.string.hero_cancel)
|
||||||
hero.setBackgroundResource(R.drawable.bg_hero_active)
|
hero.setBackgroundResource(R.drawable.bg_hero_active)
|
||||||
heroLabel.setTextColor(context.getColor(R.color.accent_emerald))
|
heroLabel.setTextColor(context.getColor(R.color.accent_emerald))
|
||||||
heroPowerIcon.setColorFilter(context.getColor(R.color.accent_emerald))
|
heroPowerIcon.setColorFilter(context.getColor(R.color.accent_emerald))
|
||||||
statusHeadline.text = context.getString(R.string.status_headline_connecting)
|
statusHeadline.text = context.getString(if (status == VpnStatus.STOPPING) R.string.status_headline_disconnected else R.string.status_headline_connecting)
|
||||||
statsCard.visibility = View.GONE
|
statsCard.visibility = View.GONE
|
||||||
pingRow.visibility = View.GONE
|
pingRow.visibility = View.GONE
|
||||||
heroRingOuter.applyState(HeroRingOuterView.State.CONNECTING)
|
heroRingOuter.applyState(HeroRingOuterView.State.CONNECTING)
|
||||||
@@ -236,6 +205,69 @@ class MainFragmentView(private val root: View) {
|
|||||||
pingButton.clearAnimation()
|
pingButton.clearAnimation()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun renderCalls() {
|
||||||
|
callsList.removeAllViews()
|
||||||
|
val inflater = LayoutInflater.from(root.context)
|
||||||
|
val visibleCalls = if (collapsedToActive) {
|
||||||
|
currentCalls.filter { it.id == activeCallId }
|
||||||
|
} else {
|
||||||
|
currentCalls
|
||||||
|
}
|
||||||
|
if (currentCalls.isEmpty()) {
|
||||||
|
emptyCta.visibility = View.VISIBLE
|
||||||
|
callsList.visibility = View.GONE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emptyCta.visibility = View.GONE
|
||||||
|
callsList.visibility = View.VISIBLE
|
||||||
|
visibleCalls.forEach { config ->
|
||||||
|
val row = inflater.inflate(R.layout.item_call_row, callsList, false)
|
||||||
|
row.clipToOutline = true
|
||||||
|
bindRow(row, config, isActive = config.id == activeCallId)
|
||||||
|
row.setOnClickListener { onCallSelected?.invoke(config) }
|
||||||
|
row.setOnLongClickListener {
|
||||||
|
onCallLongPressed?.invoke(config)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
callsList.addView(row)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindRow(row: View, config: CallConfig, isActive: Boolean) {
|
||||||
|
val context = row.context
|
||||||
|
val nameView = row.findViewById<TextView>(R.id.rowName)
|
||||||
|
val linkView = row.findViewById<TextView>(R.id.rowLink)
|
||||||
|
val glyphView = row.findViewById<TextView>(R.id.rowGlyph)
|
||||||
|
val glyphBox = row.findViewById<View>(R.id.rowGlyphBox)
|
||||||
|
val statusDot = row.findViewById<View>(R.id.rowStatusDot)
|
||||||
|
|
||||||
|
nameView.text = config.name
|
||||||
|
linkView.text = config.url
|
||||||
|
glyphView.text = config.platformGlyph
|
||||||
|
|
||||||
|
if (isActive) {
|
||||||
|
row.setBackgroundResource(R.drawable.bg_destination_card_active)
|
||||||
|
statusDot.setBackgroundResource(R.drawable.bg_status_dot_active)
|
||||||
|
glyphBox.setBackgroundResource(R.drawable.bg_glyph_chip_active)
|
||||||
|
glyphView.setTextColor(context.getColor(R.color.panel_bg))
|
||||||
|
} else {
|
||||||
|
row.setBackgroundResource(R.drawable.bg_destination_card)
|
||||||
|
statusDot.setBackgroundResource(R.drawable.bg_status_dot_idle)
|
||||||
|
glyphBox.setBackgroundResource(R.drawable.bg_glyph_chip)
|
||||||
|
nameView.setTextColor(context.getColor(R.color.ink))
|
||||||
|
linkView.setTextColor(context.getColor(R.color.ink_3))
|
||||||
|
glyphView.setTextColor(context.getColor(R.color.ink))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateHeaderSubForList(count: Int) {
|
||||||
|
if (collapsedToActive) return
|
||||||
|
headerSub.text = when (count) {
|
||||||
|
0 -> root.context.getString(R.string.main_sub_no_configs)
|
||||||
|
else -> root.context.resources.getQuantityString(R.plurals.main_sub_count, count, count)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun startPulse() {
|
private fun startPulse() {
|
||||||
if (pulseAnimator?.isStarted == true) return
|
if (pulseAnimator?.isStarted == true) return
|
||||||
heroPulse.visibility = View.VISIBLE
|
heroPulse.visibility = View.VISIBLE
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class MenuActionSheet : BottomSheetDialogFragment() {
|
|||||||
val id: String,
|
val id: String,
|
||||||
val title: String,
|
val title: String,
|
||||||
val iconRes: Int,
|
val iconRes: Int,
|
||||||
|
val value: String? = null,
|
||||||
val danger: Boolean = false,
|
val danger: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -50,15 +51,22 @@ class MenuActionSheet : BottomSheetDialogFragment() {
|
|||||||
val row = inflater.inflate(R.layout.item_action_menu_row, menuContainer, false)
|
val row = inflater.inflate(R.layout.item_action_menu_row, menuContainer, false)
|
||||||
row.clipToOutline = true
|
row.clipToOutline = true
|
||||||
val label = row.findViewById<TextView>(R.id.menuLabel)
|
val label = row.findViewById<TextView>(R.id.menuLabel)
|
||||||
|
val valueView = row.findViewById<TextView>(R.id.menuValue)
|
||||||
val icon = row.findViewById<ImageView>(R.id.menuIcon)
|
val icon = row.findViewById<ImageView>(R.id.menuIcon)
|
||||||
val iconBox = row.findViewById<View>(R.id.menuIconBox)
|
val iconBox = row.findViewById<View>(R.id.menuIconBox)
|
||||||
|
|
||||||
label.text = item.title
|
label.text = item.title
|
||||||
|
if (item.value.isNullOrBlank()) {
|
||||||
|
valueView.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
valueView.text = item.value
|
||||||
|
valueView.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
icon.setImageResource(item.iconRes)
|
icon.setImageResource(item.iconRes)
|
||||||
if (item.danger) {
|
if (item.danger) {
|
||||||
label.setTextColor(requireContext().getColor(R.color.error_red))
|
label.setTextColor(requireContext().getColor(R.color.accent_emerald))
|
||||||
iconBox.setBackgroundResource(R.drawable.bg_settings_row_icon_danger)
|
iconBox.setBackgroundResource(R.drawable.bg_settings_row_icon_danger)
|
||||||
icon.setColorFilter(requireContext().getColor(R.color.error_red))
|
icon.setColorFilter(requireContext().getColor(R.color.accent_emerald))
|
||||||
}
|
}
|
||||||
row.setOnClickListener {
|
row.setOnClickListener {
|
||||||
onSelect?.invoke(item)
|
onSelect?.invoke(item)
|
||||||
|
|||||||
@@ -6,18 +6,17 @@ import android.view.ViewGroup
|
|||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
|
||||||
import androidx.core.view.isNotEmpty
|
import androidx.core.view.isNotEmpty
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.google.android.material.materialswitch.MaterialSwitch
|
|
||||||
import bypass.whitelist.App
|
import bypass.whitelist.App
|
||||||
import bypass.whitelist.R
|
import bypass.whitelist.R
|
||||||
import bypass.whitelist.tunnel.SplitTunnelingMode
|
import bypass.whitelist.tunnel.SplitTunnelingMode
|
||||||
import bypass.whitelist.tunnel.TunnelMode
|
import bypass.whitelist.tunnel.TunnelMode
|
||||||
import bypass.whitelist.tunnel.TunnelVpnService
|
import bypass.whitelist.util.Callback
|
||||||
|
import bypass.whitelist.util.ParamCallback
|
||||||
import bypass.whitelist.util.Prefs
|
import bypass.whitelist.util.Prefs
|
||||||
import bypass.whitelist.util.ThemeMode
|
import bypass.whitelist.util.ThemeMode
|
||||||
|
import com.google.android.material.materialswitch.MaterialSwitch
|
||||||
|
|
||||||
class SettingsScreenFragment : Fragment(R.layout.fragment_settings_screen) {
|
class SettingsScreenFragment : Fragment(R.layout.fragment_settings_screen) {
|
||||||
|
|
||||||
@@ -37,6 +36,11 @@ class SettingsScreenFragment : Fragment(R.layout.fragment_settings_screen) {
|
|||||||
root.addView(buildDangerSection())
|
root.addView(buildDangerSection())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
rebuild()
|
||||||
|
}
|
||||||
|
|
||||||
fun refresh() {
|
fun refresh() {
|
||||||
rebuild()
|
rebuild()
|
||||||
}
|
}
|
||||||
@@ -87,7 +91,12 @@ class SettingsScreenFragment : Fragment(R.layout.fragment_settings_screen) {
|
|||||||
|
|
||||||
val vp8SubRes = if (Prefs.dualTrack) R.string.settings_row_vp8_sub_dual else R.string.settings_row_vp8_sub
|
val vp8SubRes = if (Prefs.dualTrack) R.string.settings_row_vp8_sub_dual else R.string.settings_row_vp8_sub
|
||||||
addRow(card, R.drawable.ic_setting_vp8, getString(R.string.settings_row_vp8), getString(vp8SubRes, Prefs.vp8Fps, Prefs.vp8Batch), null) {
|
addRow(card, R.drawable.ic_setting_vp8, getString(R.string.settings_row_vp8), getString(vp8SubRes, Prefs.vp8Fps, Prefs.vp8Batch), null) {
|
||||||
Vp8ActionSheet.show(parentFragmentManager) { rebuild() }
|
Vp8ActionSheet.show(parentFragmentManager, Prefs.vp8Fps, Prefs.vp8Batch, Prefs.dualTrack) { fps, batch, dual ->
|
||||||
|
Prefs.vp8Fps = fps
|
||||||
|
Prefs.vp8Batch = batch
|
||||||
|
Prefs.dualTrack = dual
|
||||||
|
rebuild()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addRow(card, R.drawable.ic_setting_autofill, getString(R.string.settings_row_autofill), if (Prefs.autofillEnabled) Prefs.autofillName else getString(R.string.settings_row_autofill_off), null) {
|
addRow(card, R.drawable.ic_setting_autofill, getString(R.string.settings_row_autofill), if (Prefs.autofillEnabled) Prefs.autofillName else getString(R.string.settings_row_autofill_off), null) {
|
||||||
@@ -175,7 +184,7 @@ class SettingsScreenFragment : Fragment(R.layout.fragment_settings_screen) {
|
|||||||
sub: String?,
|
sub: String?,
|
||||||
trail: String?,
|
trail: String?,
|
||||||
danger: Boolean = false,
|
danger: Boolean = false,
|
||||||
onClick: () -> Unit,
|
onClick: Callback,
|
||||||
) {
|
) {
|
||||||
val row = layoutInflater.inflate(R.layout.item_settings_row, card, false)
|
val row = layoutInflater.inflate(R.layout.item_settings_row, card, false)
|
||||||
row.findViewById<ImageView>(R.id.rowIcon).setImageResource(iconRes)
|
row.findViewById<ImageView>(R.id.rowIcon).setImageResource(iconRes)
|
||||||
@@ -203,7 +212,7 @@ class SettingsScreenFragment : Fragment(R.layout.fragment_settings_screen) {
|
|||||||
title: String,
|
title: String,
|
||||||
sub: String?,
|
sub: String?,
|
||||||
initial: Boolean,
|
initial: Boolean,
|
||||||
onToggled: (Boolean) -> Unit,
|
onToggled: ParamCallback<Boolean>,
|
||||||
) {
|
) {
|
||||||
val row = layoutInflater.inflate(R.layout.item_settings_row, card, false)
|
val row = layoutInflater.inflate(R.layout.item_settings_row, card, false)
|
||||||
row.findViewById<ImageView>(R.id.rowIcon).setImageResource(iconRes)
|
row.findViewById<ImageView>(R.id.rowIcon).setImageResource(iconRes)
|
||||||
@@ -238,8 +247,4 @@ class SettingsScreenFragment : Fragment(R.layout.fragment_settings_screen) {
|
|||||||
val rootView = view ?: return
|
val rootView = view ?: return
|
||||||
onViewCreated(rootView, null)
|
onViewCreated(rootView, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val TAG = "SettingsScreenFragment"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ import android.widget.LinearLayout
|
|||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import bypass.whitelist.R
|
import bypass.whitelist.R
|
||||||
@@ -91,7 +92,7 @@ class SplitTunnelingScreenFragment : Fragment() {
|
|||||||
Prefs.splitTunnelingMode = mode
|
Prefs.splitTunnelingMode = mode
|
||||||
Prefs.splitTunnelingPackages = packages
|
Prefs.splitTunnelingPackages = packages
|
||||||
if (TunnelVpnService.instance?.isRunning == true) {
|
if (TunnelVpnService.instance?.isRunning == true) {
|
||||||
android.widget.Toast.makeText(requireContext(), R.string.split_tunneling_mode_changed, android.widget.Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), R.string.split_tunneling_mode_changed, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
(activity as? MainActivityHost)?.popSubPage()
|
(activity as? MainActivityHost)?.popSubPage()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,16 @@ import android.view.ViewGroup
|
|||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import bypass.whitelist.R
|
import bypass.whitelist.R
|
||||||
import bypass.whitelist.util.Callback
|
|
||||||
import bypass.whitelist.util.Prefs
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.materialswitch.MaterialSwitch
|
import com.google.android.material.materialswitch.MaterialSwitch
|
||||||
|
|
||||||
class Vp8ActionSheet : BottomSheetDialogFragment() {
|
class Vp8ActionSheet : BottomSheetDialogFragment() {
|
||||||
|
|
||||||
private var onSaved: Callback? = null
|
private var initialFps: Int = 0
|
||||||
|
private var initialBatch: Int = 0
|
||||||
|
private var initialDualTrack: Boolean = false
|
||||||
|
private var onSaved: ((fps: Int, batch: Int, dualTrack: Boolean) -> Unit)? = null
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
@@ -26,24 +27,34 @@ class Vp8ActionSheet : BottomSheetDialogFragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
val fps = view.findViewById<EditText>(R.id.vp8FpsInput)
|
val fps = view.findViewById<EditText>(R.id.vp8FpsInput)
|
||||||
val batch = view.findViewById<EditText>(R.id.vp8BatchInput)
|
val batch = view.findViewById<EditText>(R.id.vp8BatchInput)
|
||||||
val dualTrack = view.findViewById<MaterialSwitch>(R.id.vp8DualTrackSwitch)
|
val dualSwitch = view.findViewById<MaterialSwitch>(R.id.vp8DualTrackSwitch)
|
||||||
fps.setText(Prefs.vp8Fps.toString())
|
fps.setText(initialFps.toString())
|
||||||
batch.setText(Prefs.vp8Batch.toString())
|
batch.setText(initialBatch.toString())
|
||||||
dualTrack.isChecked = Prefs.dualTrack
|
dualSwitch.isChecked = initialDualTrack
|
||||||
|
|
||||||
view.findViewById<MaterialButton>(R.id.vp8CancelButton).setOnClickListener { dismiss() }
|
view.findViewById<MaterialButton>(R.id.vp8CancelButton).setOnClickListener { dismiss() }
|
||||||
view.findViewById<MaterialButton>(R.id.vp8SaveButton).setOnClickListener {
|
view.findViewById<MaterialButton>(R.id.vp8SaveButton).setOnClickListener {
|
||||||
fps.text.toString().toIntOrNull()?.takeIf { it in 1..240 }?.let { Prefs.vp8Fps = it }
|
val newFps = fps.text.toString().toIntOrNull()?.takeIf { it in 1..240 } ?: initialFps
|
||||||
batch.text.toString().toIntOrNull()?.takeIf { it in 1..256 }?.let { Prefs.vp8Batch = it }
|
val newBatch = batch.text.toString().toIntOrNull()?.takeIf { it in 1..256 } ?: initialBatch
|
||||||
Prefs.dualTrack = dualTrack.isChecked
|
onSaved?.invoke(newFps, newBatch, dualSwitch.isChecked)
|
||||||
onSaved?.invoke()
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun show(manager: FragmentManager, onSaved: Callback) {
|
fun show(
|
||||||
Vp8ActionSheet().apply { this.onSaved = onSaved }.show(manager, "Vp8ActionSheet")
|
manager: FragmentManager,
|
||||||
|
fps: Int,
|
||||||
|
batch: Int,
|
||||||
|
dualTrack: Boolean,
|
||||||
|
onSaved: (fps: Int, batch: Int, dualTrack: Boolean) -> Unit,
|
||||||
|
) {
|
||||||
|
Vp8ActionSheet().apply {
|
||||||
|
this.initialFps = fps
|
||||||
|
this.initialBatch = batch
|
||||||
|
this.initialDualTrack = dualTrack
|
||||||
|
this.onSaved = onSaved
|
||||||
|
}.show(manager, "Vp8ActionSheet")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,6 @@ enum class ThemeMode(val label: String) {
|
|||||||
object PrefsKeys {
|
object PrefsKeys {
|
||||||
const val CONNECT_ON_START = "connect_on_start"
|
const val CONNECT_ON_START = "connect_on_start"
|
||||||
const val TUNNEL_MODE = "tunnel_mode"
|
const val TUNNEL_MODE = "tunnel_mode"
|
||||||
const val SHOW_LOGS = "show_logs"
|
|
||||||
const val SPLIT_TUNNELING_MODE = "split_tunneling_mode"
|
const val SPLIT_TUNNELING_MODE = "split_tunneling_mode"
|
||||||
const val SPLIT_TUNNELING_PACKAGES = "split_tunneling_packages"
|
const val SPLIT_TUNNELING_PACKAGES = "split_tunneling_packages"
|
||||||
const val AUTOFILL_ENABLED = "autofill_enabled"
|
const val AUTOFILL_ENABLED = "autofill_enabled"
|
||||||
|
|||||||
@@ -30,10 +30,6 @@ object Prefs {
|
|||||||
}
|
}
|
||||||
set(value) = prefs.edit { putString(PrefsKeys.TUNNEL_MODE, value.name) }
|
set(value) = prefs.edit { putString(PrefsKeys.TUNNEL_MODE, value.name) }
|
||||||
|
|
||||||
var showLogs: Boolean
|
|
||||||
get() = prefs.getBoolean(PrefsKeys.SHOW_LOGS, false)
|
|
||||||
set(value) = prefs.edit { putBoolean(PrefsKeys.SHOW_LOGS, value) }
|
|
||||||
|
|
||||||
var splitTunnelingMode: SplitTunnelingMode
|
var splitTunnelingMode: SplitTunnelingMode
|
||||||
get() {
|
get() {
|
||||||
val title = prefs.getString(PrefsKeys.SPLIT_TUNNELING_MODE, SplitTunnelingMode.NONE.name)!!
|
val title = prefs.getString(PrefsKeys.SPLIT_TUNNELING_MODE, SplitTunnelingMode.NONE.name)!!
|
||||||
@@ -145,6 +141,27 @@ object Prefs {
|
|||||||
return savedDestinations.firstOrNull { it.id == id }
|
return savedDestinations.firstOrNull { it.id == id }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val activeTunnelMode: TunnelMode
|
||||||
|
get() = activeDestination?.tunnelMode ?: tunnelMode
|
||||||
|
|
||||||
|
val activeVp8Fps: Int
|
||||||
|
get() = activeDestination?.vp8Fps ?: vp8Fps
|
||||||
|
|
||||||
|
val activeVp8Batch: Int
|
||||||
|
get() = activeDestination?.vp8Batch ?: vp8Batch
|
||||||
|
|
||||||
|
val activeDualTrack: Boolean
|
||||||
|
get() = activeDestination?.dualTrack ?: dualTrack
|
||||||
|
|
||||||
|
fun updateDestination(config: CallConfig) {
|
||||||
|
val list = savedDestinations.toMutableList()
|
||||||
|
val index = list.indexOfFirst { it.id == config.id }
|
||||||
|
if (index != -1) {
|
||||||
|
list[index] = config
|
||||||
|
savedDestinations = list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun addDestination(config: CallConfig) {
|
fun addDestination(config: CallConfig) {
|
||||||
val list = savedDestinations.toMutableList()
|
val list = savedDestinations.toMutableList()
|
||||||
list.removeAll { it.id == config.id }
|
list.removeAll { it.id == config.id }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:shape="rectangle">
|
android:shape="rectangle">
|
||||||
<solid android:color="#14C24A2C" />
|
<solid android:color="#1F7B1C2A" />
|
||||||
<stroke android:width="1dp" android:color="#33C24A2C" />
|
<stroke android:width="1dp" android:color="#337B1C2A" />
|
||||||
<corners android:radius="9dp" />
|
<corners android:radius="9dp" />
|
||||||
</shape>
|
</shape>
|
||||||
@@ -11,10 +11,15 @@
|
|||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
|
|
||||||
<androidx.fragment.app.FragmentContainerView
|
<FrameLayout
|
||||||
|
android:id="@+id/tabContainerWrap"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<androidx.viewpager2.widget.ViewPager2
|
||||||
android:id="@+id/tabContainer"
|
android:id="@+id/tabContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/subPageContainer"
|
android:id="@+id/subPageContainer"
|
||||||
|
|||||||
@@ -36,4 +36,13 @@
|
|||||||
android:textColor="@color/ink"
|
android:textColor="@color/ink"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/menuValue"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:textColor="@color/ink_3"
|
||||||
|
android:textSize="13sp"
|
||||||
|
android:visibility="gone" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@color/panel_bg"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingHorizontal="20dp"
|
android:paddingHorizontal="20dp"
|
||||||
android:paddingTop="2dp"
|
android:paddingTop="2dp"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@color/panel_bg"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingHorizontal="20dp"
|
android:paddingHorizontal="20dp"
|
||||||
android:paddingTop="2dp"
|
android:paddingTop="2dp"
|
||||||
|
|||||||
@@ -10,15 +10,26 @@
|
|||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
android:background="@color/hair" />
|
android:background="@color/hair" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingHorizontal="16dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingBottom="12dp">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/navIndicator"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="10dp"
|
||||||
|
android:background="@drawable/bg_nav_item_active"
|
||||||
|
android:layout_gravity="start|center_vertical" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/navItemsRow"
|
android:id="@+id/navItemsRow"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:baselineAligned="false"
|
android:baselineAligned="false"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal">
|
||||||
android:paddingHorizontal="16dp"
|
|
||||||
android:paddingTop="8dp"
|
|
||||||
android:paddingBottom="12dp">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/navMain"
|
android:id="@+id/navMain"
|
||||||
@@ -26,7 +37,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_marginEnd="4dp"
|
android:layout_marginEnd="4dp"
|
||||||
android:background="@drawable/bg_nav_item_active"
|
android:background="@android:color/transparent"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
@@ -123,4 +134,5 @@
|
|||||||
android:textSize="10sp" />
|
android:textSize="10sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<color name="accent_emerald">#FF7B1C2A</color>
|
<color name="accent_emerald">#FF7B1C2A</color>
|
||||||
<color name="accent_emerald_soft">#1F7B1C2A</color>
|
<color name="accent_emerald_soft">#1F7B1C2A</color>
|
||||||
<color name="warn_amber">#FFB07A1D</color>
|
<color name="warn_amber">#FFB07A1D</color>
|
||||||
<color name="error_red">#FFC24A2C</color>
|
<color name="error_red">#FFD32F2F</color>
|
||||||
<color name="ink">#FF0D0D0C</color>
|
<color name="ink">#FF0D0D0C</color>
|
||||||
<color name="ink_2">#FF4A4946</color>
|
<color name="ink_2">#FF4A4946</color>
|
||||||
<color name="ink_3">#FF8A8782</color>
|
<color name="ink_3">#FF8A8782</color>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
<string name="app_name">WhitelistBypass</string>
|
<string name="app_name">whitelistbypass</string>
|
||||||
<string name="share_logs">Share logs</string>
|
<string name="share_logs">Share logs</string>
|
||||||
<string name="copy_logs_toast">Logs copied to clipboard</string>
|
<string name="copy_logs_toast">Logs copied to clipboard</string>
|
||||||
<string name="autofill_settings_title">Autofill settings</string>
|
<string name="autofill_settings_title">Autofill settings</string>
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<string name="expand_webview">Expand WebView</string>
|
<string name="expand_webview">Expand WebView</string>
|
||||||
<string name="collapse_webview">Collapse WebView</string>
|
<string name="collapse_webview">Collapse WebView</string>
|
||||||
<string name="vpn_starting">Starting…</string>
|
<string name="vpn_starting">Starting…</string>
|
||||||
|
<string name="vpn_stopping">Stopping…</string>
|
||||||
<string name="vpn_connecting">Connecting…</string>
|
<string name="vpn_connecting">Connecting…</string>
|
||||||
<string name="vpn_call_connected">Call connected</string>
|
<string name="vpn_call_connected">Call connected</string>
|
||||||
<string name="vpn_datachannel_open">DataChannel open</string>
|
<string name="vpn_datachannel_open">DataChannel open</string>
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
<string name="vpn_call_disconnected">Call disconnected</string>
|
<string name="vpn_call_disconnected">Call disconnected</string>
|
||||||
<string name="vpn_call_failed">Call failed</string>
|
<string name="vpn_call_failed">Call failed</string>
|
||||||
<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="action_required_captcha">Action required (captcha)</string>
|
<string name="action_required_captcha">Action required (captcha)</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>
|
||||||
@@ -38,8 +40,12 @@
|
|||||||
<string name="vp8_dual_track_sub">Publish a second VP8 track as screen-share and shard outbound across both.</string>
|
<string name="vp8_dual_track_sub">Publish a second VP8 track as screen-share and shard outbound across both.</string>
|
||||||
<string name="notification_vpn_title">VPN active</string>
|
<string name="notification_vpn_title">VPN active</string>
|
||||||
<string name="notification_proxy_title">Proxy active</string>
|
<string name="notification_proxy_title">Proxy active</string>
|
||||||
|
<string name="notification_session_connecting">Starting headless session</string>
|
||||||
|
<string name="error_no_destination">Add and select a destination first</string>
|
||||||
<string name="notification_disconnect">Disconnect</string>
|
<string name="notification_disconnect">Disconnect</string>
|
||||||
<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_vpn_permission_required">Open the app once and grant VPN permission</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>
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ appcompat = "1.7.1"
|
|||||||
material = "1.13.0"
|
material = "1.13.0"
|
||||||
activity = "1.12.4"
|
activity = "1.12.4"
|
||||||
constraintlayout = "2.2.1"
|
constraintlayout = "2.2.1"
|
||||||
leakcanary = "2.14"
|
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
@@ -20,7 +19,6 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version
|
|||||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||||
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
|
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
|
||||||
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
|
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
|
||||||
leakcanary-android = { group = "com.squareup.leakcanary", name = "leakcanary-android", version.ref = "leakcanary" }
|
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
|
|||||||
@@ -2,11 +2,24 @@
|
|||||||
|
|
||||||
package androidbind
|
package androidbind
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void disable_fdsan() {
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
extern void android_fdsan_set_error_level(uint32_t) __attribute__((weak));
|
||||||
|
if (android_fdsan_set_error_level) {
|
||||||
|
android_fdsan_set_error_level(0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/xjasonlyu/tun2socks/v2/engine"
|
"github.com/xjasonlyu/tun2socks/v2/engine"
|
||||||
|
|
||||||
@@ -15,47 +28,33 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
tunReady sync.WaitGroup
|
tunReady sync.WaitGroup
|
||||||
tunOrigFd int = -1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartTun2Socks(fd, mtu, socksPort int, socksUser, socksPass string) error {
|
func StartTun2Socks(fd, mtu, socksPort int, socksUser, socksPass string) error {
|
||||||
// dup the fd: tun2socks will close the dup on Stop(),
|
|
||||||
// we keep the original open to prevent the kernel from
|
|
||||||
// recycling the fd number while gvisor goroutines drain
|
|
||||||
dupFd, err := syscall.Dup(fd)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("dup tun fd: %w", err)
|
|
||||||
}
|
|
||||||
tunOrigFd = fd
|
|
||||||
|
|
||||||
var proxy string
|
var proxy string
|
||||||
if socksUser != "" {
|
if socksUser != "" {
|
||||||
proxy = fmt.Sprintf("socks5://%s:%s@%s:%d", socksUser, socksPass, common.SocksLocalhostIP, socksPort)
|
proxy = fmt.Sprintf("socks5://%s:%s@%s:%d", socksUser, socksPass, common.SocksLocalhostIP, socksPort)
|
||||||
} else {
|
} else {
|
||||||
proxy = fmt.Sprintf("socks5://%s:%d", common.SocksLocalhostIP, socksPort)
|
proxy = fmt.Sprintf("socks5://%s:%d", common.SocksLocalhostIP, socksPort)
|
||||||
}
|
}
|
||||||
logMsg("tun2socks: starting fd=%d (dup=%d) mtu=%d proxy=%s", fd, dupFd, mtu, proxy)
|
logMsg("tun2socks: starting fd=%d mtu=%d proxy=%s", fd, mtu, proxy)
|
||||||
os.Setenv("TUN2SOCKS_LOG_LEVEL", "info")
|
os.Setenv("TUN2SOCKS_LOG_LEVEL", "info")
|
||||||
|
tunReady.Add(1)
|
||||||
|
defer tunReady.Done()
|
||||||
key := &engine.Key{
|
key := &engine.Key{
|
||||||
Proxy: proxy,
|
Proxy: proxy,
|
||||||
Device: fmt.Sprintf("fd://%d", dupFd),
|
Device: fmt.Sprintf("fd://%d", fd),
|
||||||
MTU: mtu,
|
MTU: mtu,
|
||||||
}
|
}
|
||||||
tunReady.Add(1)
|
|
||||||
engine.Insert(key)
|
engine.Insert(key)
|
||||||
engine.Start()
|
engine.Start()
|
||||||
tunReady.Done()
|
|
||||||
logMsg("tun2socks: running")
|
logMsg("tun2socks: running")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func StopTun2Socks() {
|
func StopTun2Socks() {
|
||||||
tunReady.Wait()
|
tunReady.Wait()
|
||||||
|
C.disable_fdsan()
|
||||||
engine.Stop()
|
engine.Stop()
|
||||||
// now safe to close the original - gvisor goroutines are done
|
|
||||||
if tunOrigFd >= 0 {
|
|
||||||
syscall.Close(tunOrigFd)
|
|
||||||
tunOrigFd = -1
|
|
||||||
}
|
|
||||||
logMsg("tun2socks: stopped")
|
logMsg("tun2socks: stopped")
|
||||||
}
|
}
|
||||||
@@ -310,18 +310,21 @@ func UpdatePublisherTrackDescriptionMessage(pc *webrtc.PeerConnection, audioLabe
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
kind := strings.ToUpper(sender.Track().Kind().String())
|
kind := strings.ToUpper(sender.Track().Kind().String())
|
||||||
if kind == "AUDIO" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
mid := tr.Mid()
|
mid := tr.Mid()
|
||||||
|
label := videoLabel
|
||||||
|
groupId := 2
|
||||||
|
if kind == "AUDIO" {
|
||||||
|
label = audioLabel
|
||||||
|
groupId = 1
|
||||||
|
}
|
||||||
descs = append(descs, map[string]interface{}{
|
descs = append(descs, map[string]interface{}{
|
||||||
"mid": mid,
|
"mid": mid,
|
||||||
"transceiverMid": mid,
|
"transceiverMid": mid,
|
||||||
"kind": kind,
|
"kind": kind,
|
||||||
"priority": 0,
|
"priority": 0,
|
||||||
"label": videoLabel,
|
"label": label,
|
||||||
"codecs": map[string]interface{}{},
|
"codecs": map[string]interface{}{},
|
||||||
"groupId": 1,
|
"groupId": groupId,
|
||||||
"description": "",
|
"description": "",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user