Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v055o #1581

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

v055o #1581

Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
51635ca
ui: new setting to enable/disable crashlytics in play version
hussainmohd-a Jun 12, 2024
9188e52
fix: #1529, better handling of wg states in ui
hussainmohd-a Jun 12, 2024
41a7f3f
tunnel: stop adapter on other vpn start by user
hussainmohd-a Jun 14, 2024
3423cca
disable GWP-ASan for the app
hussainmohd-a Jun 15, 2024
de43606
bump dependencies versions
hussainmohd-a Jun 24, 2024
d6ee645
logger: write console logs to an in-memory database
hussainmohd-a Jun 24, 2024
bf1a4d6
Merge branch 'v055n' of https://github.com/hussainmohd-a/rethink-app …
hussainmohd-a Jun 24, 2024
df29def
ui: new ui to show, save, and share console logs
hussainmohd-a Jun 24, 2024
ee9262c
ui: correct wg stats update using coroutines
hussainmohd-a Jun 24, 2024
49369d8
ui: ensure consistent upload and download order
hussainmohd-a Jun 24, 2024
751073e
add new 'region' column to dns logs and update ui
hussainmohd-a Jun 24, 2024
de30362
logger: append timestamp to crash logs
hussainmohd-a Jun 24, 2024
e0850a2
ui: align IP and domain rules screen layout
hussainmohd-a Jun 25, 2024
283f986
ui: add links for reddit, element, and mastodon
hussainmohd-a Jun 25, 2024
fd73d0d
ui: add links for reddit, element, and mastodon
hussainmohd-a Jun 25, 2024
d64e24e
ui: new ui for editing default IPs for connectivity checks
hussainmohd-a Jun 25, 2024
16c9e94
fix: #1557, handle proper closure for zip entries
hussainmohd-a Jun 26, 2024
0ea571d
ui: display wireguard id along with the name
hussainmohd-a Jun 26, 2024
7f2e219
strings: rmv unused literal from all xml files
hussainmohd-a Jun 26, 2024
1d51bef
logger: move in-memory writes to separate method
hussainmohd-a Jun 26, 2024
905d4c8
string: fix contacts in about screen
hussainmohd-a Jun 27, 2024
e277466
server: update server ips for sky, zero
hussainmohd-a Jun 27, 2024
c319815
ui: show rethink app's details in app info screen
hussainmohd-a Jun 29, 2024
4083e75
bugrpt: rmv unwanted close call for zipentry
hussainmohd-a Jun 29, 2024
8c68c8a
logger: purge console logs based on time instead of limit
hussainmohd-a Jun 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/src/fdroid/java/com/celzero/bravedns/util/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ object Logger : KoinComponent {
log(tag, message, LoggerType.ERROR, e)
}

fun enableCrashlytics() {
// no-op, crashlytics is not used for F-Droid builds
}

fun disableCrashlytics() {
// no-op, crashlytics is not used for F-Droid builds
}

fun updateConfigLevel(level: Long) {
logLevel = level
}
Expand Down
167 changes: 124 additions & 43 deletions app/src/full/java/com/celzero/bravedns/adapter/OneWgConfigAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.celzero.bravedns.adapter

import Logger.LOG_TAG_PROXY
import android.content.Context
import android.content.Intent
import android.text.format.DateUtils
Expand All @@ -37,6 +38,10 @@ import com.celzero.bravedns.databinding.ListItemWgOneInterfaceBinding
import com.celzero.bravedns.service.ProxyManager
import com.celzero.bravedns.service.VpnController
import com.celzero.bravedns.service.WireguardManager
import com.celzero.bravedns.service.WireguardManager.ERR_CODE_OTHER_WG_ACTIVE
import com.celzero.bravedns.service.WireguardManager.ERR_CODE_VPN_NOT_ACTIVE
import com.celzero.bravedns.service.WireguardManager.ERR_CODE_VPN_NOT_FULL
import com.celzero.bravedns.service.WireguardManager.ERR_CODE_WG_INVALID
import com.celzero.bravedns.ui.activity.WgConfigDetailActivity
import com.celzero.bravedns.ui.activity.WgConfigDetailActivity.Companion.INTENT_EXTRA_WG_TYPE
import com.celzero.bravedns.ui.activity.WgConfigEditorActivity.Companion.INTENT_EXTRA_WG_ID
Expand Down Expand Up @@ -105,27 +110,23 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns

fun update(config: WgConfigFiles) {
b.interfaceNameText.text = config.name
b.oneWgCheck.isChecked = config.isActive
io {
updateStatus(config)
}
val isWgActive = config.isActive && VpnController.hasTunnel()
b.oneWgCheck.isChecked = isWgActive
setupClickListeners(config)
if (config.oneWireGuard) {
if (isWgActive) {
keepStatusUpdated(config)
} else {
b.interfaceDetailCard.strokeWidth = 0
b.interfaceAppsCount.visibility = View.GONE
b.protocolInfoChipGroup.visibility = View.GONE
b.interfaceActiveLayout.visibility = View.GONE
b.oneWgCheck.isChecked = false
b.interfaceStatus.text =
context.getString(R.string.lbl_disabled).replaceFirstChar(Char::titlecase)
disableInterface()
}
}

private fun keepStatusUpdated(config: WgConfigFiles) {
if (statusCheckJob?.isActive == true) return

statusCheckJob = io {
while (true) {
for (i in 0 until 10) {
if (statusCheckJob?.isActive == false) return@io

updateStatus(config)
delay(ONE_SEC)
}
Expand Down Expand Up @@ -172,6 +173,11 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
return
}

if (config.isActive && !VpnController.hasTunnel()) {
disableInterface()
return
}

val id = ProxyManager.ID_WG_BASE + config.id
val statusId = VpnController.getProxyStatusById(id)
val pair = VpnController.getSupportedIpVersion(id)
Expand All @@ -191,7 +197,7 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
}

private fun updateStatusUi(config: WgConfigFiles, statusId: Long?, stats: Stats?) {
if (config.isActive) {
if (config.isActive && VpnController.hasTunnel()) {
b.interfaceDetailCard.strokeWidth = 2
b.oneWgCheck.isChecked = true
b.interfaceAppsCount.visibility = View.VISIBLE
Expand All @@ -210,7 +216,10 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
b.interfaceDetailCard.strokeColor =
fetchColor(context, R.attr.accentGood)
}
} else if (statusId == Backend.TUP || statusId == Backend.TZZ) {
} else if (statusId == Backend.TUP ||
statusId == Backend.TZZ ||
statusId == Backend.TNT
) {
b.interfaceDetailCard.strokeColor =
fetchColor(context, R.attr.chipTextNeutral)
} else {
Expand Down Expand Up @@ -265,15 +274,21 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
}
b.interfaceActiveRxTx.text = rxtx
} else {
b.interfaceDetailCard.strokeWidth = 0
b.interfaceAppsCount.visibility = View.GONE
b.oneWgCheck.isChecked = false
b.interfaceActiveLayout.visibility = View.GONE
b.interfaceStatus.text =
context.getString(R.string.lbl_disabled).replaceFirstChar(Char::titlecase)
disableInterface()
}
}

private fun disableInterface() {
statusCheckJob?.cancel()
b.interfaceDetailCard.strokeWidth = 0
b.protocolInfoChipGroup.visibility = View.GONE
b.interfaceAppsCount.visibility = View.GONE
b.oneWgCheck.isChecked = false
b.interfaceActiveLayout.visibility = View.GONE
b.interfaceStatus.text =
context.getString(R.string.lbl_disabled).replaceFirstChar(Char::titlecase)
}

private fun getUpTime(stats: Stats?): CharSequence {
if (stats == null) {
return ""
Expand Down Expand Up @@ -327,34 +342,100 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
val isChecked = b.oneWgCheck.isChecked
io {
if (isChecked) {
if (WireguardManager.canEnableConfig(config.toImmutable())) {
config.oneWireGuard = true
WireguardManager.updateOneWireGuardConfig(config.id, owg = true)
WireguardManager.enableConfig(config.toImmutable())
uiCtx { listener.onDnsStatusChanged() }
} else {
uiCtx {
b.oneWgCheck.isChecked = false
Utilities.showToastUiCentered(
context,
context.getString(R.string.wireguard_enabled_failure),
Toast.LENGTH_LONG
)
}
}
enableWgIfPossible(config)
} else {
config.oneWireGuard = false
WireguardManager.updateOneWireGuardConfig(config.id, owg = false)
WireguardManager.disableConfig(config.toImmutable())
uiCtx {
b.oneWgCheck.isChecked = false
listener.onDnsStatusChanged()
}
disableWgIfPossible(config)
}
}
}
}

private suspend fun enableWgIfPossible(config: WgConfigFiles) {
if (!VpnController.hasTunnel()) {
Logger.i(LOG_TAG_PROXY, "VPN not active, cannot enable WireGuard")
uiCtx {
Utilities.showToastUiCentered(
context,
ERR_CODE_VPN_NOT_ACTIVE + context.getString(R.string.settings_socks5_vpn_disabled_error),
Toast.LENGTH_LONG
)
// reset the check box
b.oneWgCheck.isChecked = false
}
return
}

if (!WireguardManager.canEnableProxy()) {
Logger.i(LOG_TAG_PROXY, "not in DNS+Firewall mode, cannot enable WireGuard")
uiCtx {
// reset the check box
b.oneWgCheck.isChecked = false
Utilities.showToastUiCentered(
context,
ERR_CODE_VPN_NOT_FULL + context.getString(R.string.wireguard_enabled_failure),
Toast.LENGTH_LONG
)
}
return
}

if (WireguardManager.isAnyOtherOneWgEnabled(config.id)) {
Logger.i(LOG_TAG_PROXY, "another WireGuard is already enabled")
uiCtx {
// reset the check box
b.oneWgCheck.isChecked = false
Utilities.showToastUiCentered(
context,
ERR_CODE_OTHER_WG_ACTIVE + context.getString(R.string.wireguard_enabled_failure),
Toast.LENGTH_LONG
)
}
return
}

if (!WireguardManager.isValidConfig(config.id)) {
Logger.i(LOG_TAG_PROXY, "invalid WireGuard config")
uiCtx {
// reset the check box
b.oneWgCheck.isChecked = false
Utilities.showToastUiCentered(
context,
ERR_CODE_WG_INVALID + context.getString(R.string.wireguard_enabled_failure),
Toast.LENGTH_LONG
)
}
return
}

Logger.i(LOG_TAG_PROXY, "enabling WireGuard, id: ${config.id}")
WireguardManager.updateOneWireGuardConfig(config.id, owg = true)
config.oneWireGuard = true
WireguardManager.enableConfig(config.toImmutable())
uiCtx { listener.onDnsStatusChanged() }
}

private suspend fun disableWgIfPossible(config: WgConfigFiles) {
if (!VpnController.hasTunnel()) {
Logger.i(LOG_TAG_PROXY, "VPN not active, cannot disable WireGuard")
uiCtx {
Utilities.showToastUiCentered(
context,
ERR_CODE_VPN_NOT_ACTIVE + context.getString(R.string.settings_socks5_vpn_disabled_error),
Toast.LENGTH_LONG
)
// reset the check box
b.oneWgCheck.isChecked = true
}
return
}

Logger.i(LOG_TAG_PROXY, "disabling WireGuard, id: ${config.id}")
WireguardManager.updateOneWireGuardConfig(config.id, owg = false)
config.oneWireGuard = false
WireguardManager.disableConfig(config.toImmutable())
uiCtx { listener.onDnsStatusChanged() }
}

private fun launchConfigDetail(id: Int) {
val intent = Intent(context, WgConfigDetailActivity::class.java)
intent.putExtra(INTENT_EXTRA_WG_ID, id)
Expand Down
Loading