Skip to content

Commit 9435e29

Browse files
Merge pull request #2027 from hussainmohd-a/v055n
v055p
2 parents 587ea76 + 820dfbd commit 9435e29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+918
-531
lines changed

app/src/full/java/com/celzero/bravedns/adapter/SummaryStatisticsAdapter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ class SummaryStatisticsAdapter(
485485
when (input) {
486486
DomainConnectionsActivity.InputType.DOMAIN -> {
487487
intent.putExtra(DomainConnectionsActivity.INTENT_EXTRA_DOMAIN, appConnection.appOrDnsName)
488+
intent.putExtra(DomainConnectionsActivity.INTENT_EXTRA_IS_BLOCKED, false)
488489
}
489490
DomainConnectionsActivity.InputType.ASN -> {
490491
intent.putExtra(DomainConnectionsActivity.INTENT_EXTRA_ASN, appConnection.appOrDnsName)

app/src/full/java/com/celzero/bravedns/adapter/WgConfigAdapter.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ class WgConfigAdapter(private val context: Context, private val listener: DnsSta
405405
private fun getStrokeColorForStatus(status: UIUtils.ProxyStatus?, stats: RouterStats?): Int {
406406
return when (status) {
407407
UIUtils.ProxyStatus.TOK -> if (stats?.lastOK == 0L) return R.attr.chipTextNeutral else R.attr.accentGood
408-
UIUtils.ProxyStatus.TUP, UIUtils.ProxyStatus.TZZ -> R.attr.chipTextNeutral
408+
UIUtils.ProxyStatus.TUP, UIUtils.ProxyStatus.TZZ, UIUtils.ProxyStatus.TPU -> R.attr.chipTextNeutral
409409
else -> R.attr.chipTextNegative // TNT, TKO, TEND
410410
}
411411
}
@@ -417,14 +417,20 @@ class WgConfigAdapter(private val context: Context, private val listener: DnsSta
417417
errMsg: String? = null
418418
): String {
419419
if (status == null) {
420-
val txt = if (errMsg != null) {
420+
val txt = if (!errMsg.isNullOrEmpty()) {
421421
context.getString(R.string.status_waiting) + " ($errMsg)"
422422
} else {
423423
context.getString(R.string.status_waiting)
424424
}
425425
return txt.replaceFirstChar(Char::titlecase)
426426
}
427427

428+
// no need to check for lastOk/since for paused wg
429+
if (status == UIUtils.ProxyStatus.TPU) {
430+
return context.getString(UIUtils.getProxyStatusStringRes(status.id))
431+
.replaceFirstChar(Char::titlecase)
432+
}
433+
428434
val now = System.currentTimeMillis()
429435
val lastOk = stats?.lastOK ?: 0L
430436
val since = stats?.since ?: 0L

app/src/full/java/com/celzero/bravedns/customdownloader/IpInfoDownloader.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ package com.celzero.bravedns.customdownloader
1717

1818
import Logger
1919
import Logger.LOG_TAG_DOWNLOAD
20+
import Logger.LOG_TAG_VPN
2021
import com.celzero.bravedns.RethinkDnsApplication.Companion.DEBUG
2122
import com.celzero.bravedns.database.IpInfo
2223
import com.celzero.bravedns.database.IpInfoRepository
2324
import com.celzero.bravedns.service.PersistentState
25+
import com.celzero.bravedns.util.Constants.Companion.UNSPECIFIED_IP_IPV4
26+
import com.celzero.bravedns.util.Constants.Companion.UNSPECIFIED_IP_IPV6
2427
import com.google.gson.Gson
2528
import com.google.gson.JsonObject
2629
import com.google.gson.JsonSyntaxException
30+
import inet.ipaddr.IPAddressString
2731
import org.koin.core.component.KoinComponent
2832
import org.koin.core.component.inject
2933
import retrofit2.converter.gson.GsonConverterFactory
@@ -46,6 +50,13 @@ object IpInfoDownloader: KoinComponent {
4650
return
4751
}
4852

53+
val isLanIp = isLanIp(ipToLookup)
54+
if (isLanIp == null || isLanIp) {
55+
// if the ip is LAN IPv4 or IPv6, skip download
56+
Logger.vv(LOG_TAG_DOWNLOAD, "$TAG; lan-ip ($ipToLookup), skip download")
57+
return
58+
}
59+
4960
// check in database whether the ip info is already downloaded
5061
val ipInfo = db.getIpInfo(ipToLookup)
5162
if (ipInfo != null) {
@@ -58,6 +69,18 @@ object IpInfoDownloader: KoinComponent {
5869
Logger.d(LOG_TAG_DOWNLOAD, "$TAG; download complete, success? $downloadSuccessful")
5970
}
6071

72+
private fun isLanIp(ipAddress: String): Boolean? {
73+
try {
74+
val ip = IPAddressString(ipAddress).address ?: return null
75+
76+
return ip.isLoopback || ip.isLocal || ip.isAnyLocal || UNSPECIFIED_IP_IPV4.equals(ip) || UNSPECIFIED_IP_IPV6.equals(ip)
77+
} catch (e: Exception) {
78+
Logger.e(LOG_TAG_VPN, "err in isLanIp ${e.message}", e)
79+
}
80+
return null
81+
}
82+
83+
6184
private suspend fun performIpInfoDownload(ipToLookup: String): Boolean {
6285
if (DEBUG) OkHttpDebugLogging.enableHttp2()
6386
if (DEBUG) OkHttpDebugLogging.enableTaskRunner()

app/src/full/java/com/celzero/bravedns/service/WireguardManager.kt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ object WireguardManager : KoinComponent {
260260
}
261261

262262
fun canDisableConfig(map: WgConfigFilesImmutable): Boolean {
263-
// do not allow to disable the proxy if it is catch-all
264-
val catchAll = !map.isCatchAll
265-
// do not allow if the config is either hop or via
266-
val isHopOrVia = WgHopManager.isWgEitherHopOrSrc(map.id)
267-
return !catchAll || !isHopOrVia
263+
return when {
264+
map.isCatchAll -> false // cannot disable catch-all
265+
WgHopManager.isWgEitherHopOrSrc(map.id) -> false // cannot disable hop/via
266+
else -> true // safe to disable
267+
}
268268
}
269269

270270
fun canDisableAllActiveConfigs(): Boolean {
@@ -407,6 +407,8 @@ object WireguardManager : KoinComponent {
407407
return proxyIds
408408
}
409409

410+
/* TODO: commenting the code as v055o doesn't use ip-app specific and domain-app specific
411+
// rules
410412
// check for ip-app specific config first
411413
// returns Pair<String, String> - first is ProxyId, second is CC
412414
val ipc = IpRulesManager.hasProxy(uid, ip, port)
@@ -441,6 +443,7 @@ object WireguardManager : KoinComponent {
441443
}
442444
// add the domain-app specific config to the list
443445
if (dcProxyPair.first.isNotEmpty()) proxyIds.add(dcProxyPair.first) // domain-app specific
446+
*/
444447

445448
// check for app specific config
446449
val ac = ProxyManager.getProxyIdForApp(uid)
@@ -462,6 +465,7 @@ object WireguardManager : KoinComponent {
462465
// add the app specific config to the list
463466
if (appProxyPair.first.isNotEmpty()) proxyIds.add(appProxyPair.first)
464467

468+
/* TODO: commenting the code as v055o doesn't use universal ip and domain rules
465469
// check for universal ip config
466470
val uipc = IpRulesManager.hasProxy(UID_EVERYBODY, ip, port)
467471
val uipcProxyPair = canUseConfig(uipc.first, "univ-ip($ip:$port)", usesMeteredNw)
@@ -494,10 +498,11 @@ object WireguardManager : KoinComponent {
494498
}
495499
496500
// add the universal domain config to the list
497-
if (udcProxyPair.first.isNotEmpty()) proxyIds.add(udcProxyPair.first)
501+
if (udcProxyPair.first.isNotEmpty()) proxyIds.add(udcProxyPair.first)*/
498502

499503
// once the app-specific config is added, check if any catch-all config is enabled
500504
// if catch-all config is enabled, then add the config id to the list
505+
501506
val cac = mappings.filter { it.isActive && it.isCatchAll }
502507
cac.forEach {
503508
if (checkEligibilityBasedOnNw(it.id, usesMeteredNw)) {
@@ -509,6 +514,11 @@ object WireguardManager : KoinComponent {
509514
}
510515
}
511516

517+
if (proxyIds.isEmpty()) {
518+
Logger.i(LOG_TAG_PROXY, "no proxy ids found for $uid, $ip, $port, $domain; returning empty list")
519+
return emptyList()
520+
}
521+
512522
// add the default proxy to the end, will not be true for lockdown but lockdown is handled
513523
// above, so no need to check here
514524
if (default.isNotEmpty()) proxyIds.add(default)
@@ -750,7 +760,7 @@ object WireguardManager : KoinComponent {
750760
return
751761
}
752762
Logger.i(LOG_TAG_PROXY, "updating useMobileNw as $useMobileNw for config: $id, ${config.getName()}")
753-
db.updateCatchAllConfig(id, useMobileNw)
763+
db.updateMobileConfig(id, useMobileNw)
754764
val m = mappings.find { it.id == id } ?: return
755765
mappings.remove(m)
756766
val newMap =
@@ -760,15 +770,16 @@ object WireguardManager : KoinComponent {
760770
m.configPath,
761771
m.serverResponse,
762772
m.isActive,
763-
m.isCatchAll, // just updating catch all field
773+
m.isCatchAll,
764774
m.isLockdown,
765775
m.oneWireGuard,
766-
useMobileNw,
776+
useMobileNw, // just updating useOnMetered field
767777
m.isDeletable
768778
)
769779
mappings.add(newMap)
770-
771-
enableConfig(newMap) // catch all should be always enabled
780+
if (m.isActive) {
781+
VpnController.addWireGuardProxy(id = ID_WG_BASE + id)
782+
}
772783
}
773784

774785
suspend fun addPeer(id: Int, peer: Peer) {

app/src/full/java/com/celzero/bravedns/ui/HomeScreenActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,11 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) {
319319
// to fail due to the "Block connections without VPN" option.
320320
persistentState.allowBypass = false
321321

322+
// reset stall on no networks to false, for v055p
323+
persistentState.stallOnNoNetwork = false
324+
322325
// change the persistent state for defaultDnsUrl, if its google.com (only for v055d)
323-
// fixme: remove this post v054.
326+
// TODO: remove this post v054.
324327
// this is to fix the default dns url, as the default dns url is changed from
325328
// dns.google.com to dns.google. In servers.xml default ips available for dns.google
326329
// so changing the default dns url to dns.google

app/src/full/java/com/celzero/bravedns/ui/activity/AntiCensorshipActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ class AntiCensorshipActivity : AppCompatActivity(R.layout.activity_anti_censorsh
206206
if (mode == DialStrategies.NEVER_SPLIT.mode) {
207207
// disable retry radio buttons for never split
208208
handleRetryMode(true, RetryStrategies.RETRY_NEVER.mode, showToast = false)
209+
} else if (mode == DialStrategies.SPLIT_AUTO.mode) {
210+
// enable retry radio buttons for desync
211+
handleRetryMode(true, RetryStrategies.RETRY_WITH_SPLIT.mode, showToast = false)
209212
}
210213
} else {
211214
// no-op

app/src/full/java/com/celzero/bravedns/ui/activity/AppListActivity.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ class AppListActivity :
205205
window.isNavigationBarContrastEnforced = false
206206
}
207207

208+
filters.value = Filters()
208209
initView()
209210
initObserver()
210211
setupClickListener()
@@ -213,13 +214,12 @@ class AppListActivity :
213214
override fun onResume() {
214215
super.onResume()
215216
setFirewallFilter(filters.value?.firewallFilter)
217+
filters.value = filters.value ?: Filters()
216218
b.ffaAppList.requestFocus()
217219
}
218220

219221
private fun initObserver() {
220222
filters.observe(this) {
221-
// update the ui based on the filter
222-
resetFirewallIcons(BlockType.UNMETER)
223223
if (it == null) return@observe
224224

225225
appInfoViewModel.setFilter(it)
@@ -255,12 +255,6 @@ class AppListActivity :
255255
super.onPause()
256256
}
257257

258-
override fun onStop() {
259-
super.onStop()
260-
// clear the filters when the activity is stopped
261-
filters.value = Filters()
262-
}
263-
264258
override fun onQueryTextSubmit(query: String): Boolean {
265259
addQueryToFilters(query)
266260
b.ffaSearch.clearFocus()

app/src/full/java/com/celzero/bravedns/ui/activity/DomainConnectionsActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class DomainConnectionsActivity : AppCompatActivity(R.layout.activity_domain_con
7575
when (type) {
7676
InputType.DOMAIN -> {
7777
val domain = intent.getStringExtra(INTENT_EXTRA_DOMAIN) ?: ""
78-
viewModel.setDomain(domain)
78+
val isBlocked = intent.getBooleanExtra(INTENT_EXTRA_IS_BLOCKED, false)
79+
viewModel.setDomain(domain, isBlocked)
7980
b.dcTitle.text = domain
8081
}
8182
InputType.FLAG -> {

app/src/full/java/com/celzero/bravedns/ui/activity/ProxySettingsActivity.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import com.celzero.bravedns.database.ProxyEndpoint
4545
import com.celzero.bravedns.database.ProxyEndpoint.Companion.DEFAULT_PROXY_TYPE
4646
import com.celzero.bravedns.databinding.DialogSetProxyBinding
4747
import com.celzero.bravedns.databinding.FragmentProxyConfigureBinding
48-
import com.celzero.bravedns.rpnproxy.RpnProxyManager
4948
import com.celzero.bravedns.service.FirewallManager
5049
import com.celzero.bravedns.service.PersistentState
5150
import com.celzero.bravedns.service.ProxyManager
@@ -267,7 +266,7 @@ class ProxySettingsActivity : AppCompatActivity(R.layout.fragment_proxy_configur
267266
b.wgRefresh.isEnabled = false
268267
b.wgRefresh.animation = animation
269268
b.wgRefresh.startAnimation(animation)
270-
VpnController.refreshOrReAddProxies()
269+
io { VpnController.refreshOrPauseOrResumeOrReAddProxies() }
271270
delay(REFRESH_TIMEOUT, lifecycleScope) {
272271
b.wgRefresh.isEnabled = true
273272
b.wgRefresh.clearAnimation()

app/src/full/java/com/celzero/bravedns/ui/activity/TunnelSettingsActivity.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,16 @@ class TunnelSettingsActivity : AppCompatActivity(R.layout.activity_tunnel_settin
9292
b.dvTimeoutTxt.setBadgeDotVisible(this, idleTimeout)
9393
b.genSettingsExcludeProxyAppsTxt.setBadgeDotVisible(this, loopback)
9494
b.dvEimfTxt.setBadgeDotVisible(this, eimf)
95-
b.genFailOpenTxt.setBadgeDotVisible(this, doNotStall)
95+
b.genStallNoNwTxt.setBadgeDotVisible(this, doNotStall)
9696
b.genSettingsConnectivityChecksTxt.setBadgeDotVisible(this, performConnectionCheck)
9797
b.dvWgListenPortTxt.setBadgeDotVisible(this, randomizeWgPort)
9898
b.genSettingsMobileMeteredTxt.setBadgeDotVisible(this, mobileMetered)
9999
}
100100

101101
private fun initView() {
102102
b.settingsActivityWireguardText.text = getString(R.string.settings_proxy_header).lowercase()
103-
b.settingsActivityTcpText.text = getString(R.string.orbot_status_arg_2).lowercase()
103+
val text = getString(R.string.two_argument, getString(R.string.orbot_status_arg_2).lowercase(), getString(R.string.lbl_ip))
104+
b.settingsActivityTcpText.text = text.lowercase()
104105

105106
b.settingsActivityAllowBypassProgress.visibility = View.GONE
106107
displayAllowBypassUi()
@@ -122,7 +123,7 @@ class TunnelSettingsActivity : AppCompatActivity(R.layout.activity_tunnel_settin
122123

123124
b.settingsActivityMobileMeteredSwitch.isChecked = persistentState.treatOnlyMobileNetworkAsMetered
124125

125-
b.settingsFailOpenSwitch.isChecked = persistentState.failOpenOnNoNetwork
126+
b.settingsStallNoNwSwitch.isChecked = persistentState.stallOnNoNetwork
126127

127128
b.dvWgListenPortSwitch.isChecked = !persistentState.randomizeListenPort
128129

@@ -344,13 +345,13 @@ class TunnelSettingsActivity : AppCompatActivity(R.layout.activity_tunnel_settin
344345
!b.settingsActivityMobileMeteredSwitch.isChecked
345346
}
346347

347-
b.settingsFailOpenSwitch.setOnCheckedChangeListener { _, isChecked ->
348+
b.settingsStallNoNwSwitch.setOnCheckedChangeListener { _, isChecked ->
348349
NewSettingsManager.markSettingSeen(NewSettingsManager.DO_NOT_STALL)
349-
persistentState.failOpenOnNoNetwork = isChecked
350+
persistentState.stallOnNoNetwork = isChecked
350351
}
351352

352-
b.settingsFailOpenRl.setOnClickListener {
353-
b.settingsFailOpenSwitch.isChecked = !b.settingsFailOpenSwitch.isChecked
353+
b.settingsStallNoNwRl.setOnClickListener {
354+
b.settingsStallNoNwSwitch.isChecked = !b.settingsStallNoNwSwitch.isChecked
354355
}
355356

356357
b.dvWgListenPortSwitch.setOnCheckedChangeListener { _, isChecked ->

0 commit comments

Comments
 (0)