-
-
Notifications
You must be signed in to change notification settings - Fork 317
latest changes and bug fixes post v055z #2961
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
Changes from 29 commits
c973245
c0da877
f654f01
cc446c0
ff275a0
ce3d355
392a304
ee4744d
a319630
9f59a70
7506009
42df4c5
05fc6bd
3ba1138
9b4e347
1295825
e2ac7ba
74844a5
b2dab8b
4614ea2
9a05e95
b04c67d
8e0cd68
a448aa1
1aa519a
9d206eb
53c9c66
4c63062
175244c
74f786d
1ae9118
ffd8e46
71de4d5
85c8d87
1d07adb
b91ba82
cbf01b8
b4e672e
ecb3618
620235a
d38a5c3
a36b0c6
b6ddfaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,16 +62,20 @@ import kotlinx.coroutines.cancel | |||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.isActive | ||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.launch | ||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.withContext | ||||||||||||||||||||||||||||||||||||
| import java.util.Collections | ||||||||||||||||||||||||||||||||||||
| import java.util.Locale | ||||||||||||||||||||||||||||||||||||
| import java.util.concurrent.ConcurrentHashMap | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| class ConnectionLogAdapter(private val context: Context) : | ||||||||||||||||||||||||||||||||||||
| PagingDataAdapter<MergedConnectionLog, ConnectionLogAdapter.ConnectionLogViewHolder>( | ||||||||||||||||||||||||||||||||||||
| DIFF_CALLBACK | ||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Per-uid cache of package names, invalidated on each new page submission. | ||||||||||||||||||||||||||||||||||||
| private val packageNameCache = Collections.synchronizedMap(HashMap<Int, List<String>>()) | ||||||||||||||||||||||||||||||||||||
| // Per-uid cache of package names (immutable snapshots), living for the adapter's | ||||||||||||||||||||||||||||||||||||
| // lifetime (recreated with the fragment; uids are stable across paging pages). | ||||||||||||||||||||||||||||||||||||
| // ConcurrentHashMap: lock-free reads, non-blocking writes. Compute-on-miss cannot | ||||||||||||||||||||||||||||||||||||
| // be atomic (computeIfAbsent's lambda is not suspendable), so a rare duplicate | ||||||||||||||||||||||||||||||||||||
| // compute for the same uid is benign: the values are idempotent and immutable. | ||||||||||||||||||||||||||||||||||||
| private val packageNameCache = ConcurrentHashMap<Int, List<String>>() | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| companion object { | ||||||||||||||||||||||||||||||||||||
| private val DIFF_CALLBACK = | ||||||||||||||||||||||||||||||||||||
|
|
@@ -165,7 +169,6 @@ class ConnectionLogAdapter(private val context: Context) : | |||||||||||||||||||||||||||||||||||
| displayTransactionDetails(log) | ||||||||||||||||||||||||||||||||||||
| displayProtocolDetails(log.port, log.protocol) | ||||||||||||||||||||||||||||||||||||
| displayAppDetails(log) | ||||||||||||||||||||||||||||||||||||
| displaySummaryDetails(log) | ||||||||||||||||||||||||||||||||||||
| val blocked = if (log.blockedByRule == FirewallRuleset.RULE12.id) { | ||||||||||||||||||||||||||||||||||||
| log.proxyDetails.isEmpty() | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -176,6 +179,7 @@ class ConnectionLogAdapter(private val context: Context) : | |||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| log.blockedByRule | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| displaySummaryDetails(blocked, log) | ||||||||||||||||||||||||||||||||||||
| displayFirewallRulesetHint(blocked, rule) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| b.connectionParentLayout.setOnClickListener { openBottomSheet(log) } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -232,7 +236,12 @@ class ConnectionLogAdapter(private val context: Context) : | |||||||||||||||||||||||||||||||||||
| private fun displayAppDetails(log: MergedConnectionLog) { | ||||||||||||||||||||||||||||||||||||
| launchBinding { | ||||||||||||||||||||||||||||||||||||
| val apps = packageNameCache.getOrPut(log.uid) { | ||||||||||||||||||||||||||||||||||||
| FirewallManager.getPackageNamesByUid(log.uid) | ||||||||||||||||||||||||||||||||||||
| // Guard against iterator faults from Guava's HashMultimap in | ||||||||||||||||||||||||||||||||||||
| // FirewallManager (see snapshotAppInfos fallbacks). On failure the | ||||||||||||||||||||||||||||||||||||
| // entry is not cached, so the next bind retries; empty list is | ||||||||||||||||||||||||||||||||||||
| // rendered as the default icon by the caller. | ||||||||||||||||||||||||||||||||||||
| runCatching { FirewallManager.getPackageNamesByUid(log.uid) } | ||||||||||||||||||||||||||||||||||||
| .getOrDefault(emptyList()) | ||||||||||||||||||||||||||||||||||||
|
hussainmohd-a marked this conversation as resolved.
hussainmohd-a marked this conversation as resolved.
Comment on lines
+243
to
+244
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · low] Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
hussainmohd-a marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
| val count = apps.count() | ||||||||||||||||||||||||||||||||||||
| val pkgName = log.packageName ?: "" | ||||||||||||||||||||||||||||||||||||
|
|
@@ -312,7 +321,7 @@ class ConnectionLogAdapter(private val context: Context) : | |||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private fun displaySummaryDetails(log: MergedConnectionLog) { | ||||||||||||||||||||||||||||||||||||
| private fun displaySummaryDetails(blocked: Boolean, log: MergedConnectionLog) { | ||||||||||||||||||||||||||||||||||||
| launchBinding { | ||||||||||||||||||||||||||||||||||||
| val hasCid = VpnController.hasCid(log.connId, log.uid) | ||||||||||||||||||||||||||||||||||||
| val connType = ConnectionTracker.ConnType.get(log.connType) | ||||||||||||||||||||||||||||||||||||
|
|
@@ -335,8 +344,15 @@ class ConnectionLogAdapter(private val context: Context) : | |||||||||||||||||||||||||||||||||||
| b.connectionDelay.text = "" | ||||||||||||||||||||||||||||||||||||
| hasMinSummary = true | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| if (blocked) { | ||||||||||||||||||||||||||||||||||||
| b.connectionDuration.text = context.getString(R.string.symbol_red_circle) | ||||||||||||||||||||||||||||||||||||
| b.connectionDuration.alpha = 0.7f | ||||||||||||||||||||||||||||||||||||
|
hussainmohd-a marked this conversation as resolved.
hussainmohd-a marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
| hasMinSummary = true | ||||||||||||||||||||||||||||||||||||
|
hussainmohd-a marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| b.connectionDuration.text = "" | ||||||||||||||||||||||||||||||||||||
| b.connectionDuration.alpha = 1f | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
hussainmohd-a marked this conversation as resolved.
Comment on lines
+347
to
+354
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · medium] Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||
| b.connectionDataUsage.text = "" | ||||||||||||||||||||||||||||||||||||
| b.connectionDuration.text = "" | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if (connType.isMetered()) { | ||||||||||||||||||||||||||||||||||||
| b.connectionDelay.text = context.getString(R.string.symbol_currency) | ||||||||||||||||||||||||||||||||||||
|
|
@@ -370,8 +386,15 @@ class ConnectionLogAdapter(private val context: Context) : | |||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| b.connectionSummaryLl.visibility = View.VISIBLE | ||||||||||||||||||||||||||||||||||||
| val duration = getDurationInHumanReadableFormat(context, log.duration) | ||||||||||||||||||||||||||||||||||||
| b.connectionDuration.text = context.getString(R.string.single_argument, duration) | ||||||||||||||||||||||||||||||||||||
| if (blocked) { | ||||||||||||||||||||||||||||||||||||
| b.connectionDuration.text = context.getString(R.string.symbol_red_circle) | ||||||||||||||||||||||||||||||||||||
| b.connectionDuration.alpha = 0.7f | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| b.connectionDuration.alpha = 1f | ||||||||||||||||||||||||||||||||||||
| val duration = getDurationInHumanReadableFormat(context, log.duration) | ||||||||||||||||||||||||||||||||||||
| b.connectionDuration.text = | ||||||||||||||||||||||||||||||||||||
| context.getString(R.string.single_argument, duration) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| val download = | ||||||||||||||||||||||||||||||||||||
| context.getString( | ||||||||||||||||||||||||||||||||||||
| R.string.symbol_download, | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,10 +44,6 @@ import com.celzero.bravedns.service.IpRulesManager | |||||
| 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.service.WireguardManager.WG_UPTIME_THRESHOLD | ||||||
| import com.celzero.bravedns.ui.activity.WgConfigDetailActivity | ||||||
| import com.celzero.bravedns.ui.activity.WgConfigDetailActivity.Companion.INTENT_EXTRA_WG_TYPE | ||||||
|
|
@@ -56,6 +52,7 @@ import com.celzero.bravedns.util.UIUtils | |||||
| import com.celzero.bravedns.util.UIUtils.fetchColor | ||||||
| import com.celzero.bravedns.util.Utilities | ||||||
| import com.celzero.firestack.backend.RouterStats | ||||||
| import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||||||
| import inet.ipaddr.HostName | ||||||
| import kotlinx.coroutines.Dispatchers | ||||||
| import kotlinx.coroutines.Job | ||||||
|
|
@@ -438,7 +435,6 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns | |||||
| uiCtx { | ||||||
| Utilities.showToastUiCentered( | ||||||
| context, | ||||||
| ERR_CODE_VPN_NOT_ACTIVE + | ||||||
| context.getString(R.string.settings_socks5_vpn_disabled_error), | ||||||
| Toast.LENGTH_LONG | ||||||
| ) | ||||||
|
|
@@ -448,30 +444,15 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns | |||||
| return | ||||||
| } | ||||||
|
|
||||||
| // checks only for app mode, so show appropriate error message if not enabled | ||||||
| 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), | ||||||
| context.getString(R.string.wireguard_dns_mode_conflict), | ||||||
| Toast.LENGTH_LONG | ||||||
| ) | ||||||
| } | ||||||
|
|
@@ -483,33 +464,65 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns | |||||
| 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 | ||||||
| ) | ||||||
| showInvalidConfigDialog() | ||||||
| } | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| // One-WireGuard is mutually exclusive: if another one-wg config is active, swap it | ||||||
| // out for the newly selected one rather than blocking the user with an error. | ||||||
| var replacedOthers = false | ||||||
| if (WireguardManager.isAnyOtherOneWgEnabled(config.id)) { | ||||||
| Logger.i(LOG_TAG_PROXY, "another one-wg config is active; replacing it") | ||||||
| WireguardManager.disableOtherOneWireGuardConfigs(config.id) | ||||||
| replacedOthers = true | ||||||
| } | ||||||
|
hussainmohd-a marked this conversation as resolved.
hussainmohd-a marked this conversation as resolved.
hussainmohd-a marked this conversation as resolved.
hussainmohd-a marked this conversation as resolved.
hussainmohd-a marked this conversation as resolved.
Comment on lines
+474
to
+479
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · high] |
||||||
|
|
||||||
| 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() } | ||||||
| uiCtx { | ||||||
| listener.onDnsStatusChanged() | ||||||
| if (replacedOthers) { | ||||||
| Utilities.showToastUiCentered( | ||||||
| context, | ||||||
| context.getString(R.string.wireguard_replaced_active_config), | ||||||
| Toast.LENGTH_SHORT | ||||||
| ) | ||||||
| } | ||||||
| } | ||||||
| logEvent("One-WireGuard enabled", "WG ID: ${config.id}") | ||||||
| } | ||||||
|
|
||||||
| // Shows an "invalid config" AlertDialog when an Activity context is | ||||||
| // available; otherwise falls back to a toast so the error is never silently dropped. | ||||||
| private fun showInvalidConfigDialog() { | ||||||
| val ctx = context | ||||||
| if (ctx is android.app.Activity && !ctx.isFinishing) { | ||||||
|
hussainmohd-a marked this conversation as resolved.
hussainmohd-a marked this conversation as resolved.
hussainmohd-a marked this conversation as resolved.
hussainmohd-a marked this conversation as resolved.
hussainmohd-a marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · medium] Suggestion:
Suggested change
|
||||||
| MaterialAlertDialogBuilder(ctx, R.style.App_Dialog_NoDim) | ||||||
| .setTitle(R.string.wireguard_invalid_config_title) | ||||||
| .setMessage(R.string.wireguard_invalid_config_message) | ||||||
| .setCancelable(true) | ||||||
| .setPositiveButton(R.string.lbl_dismiss) { d, _ -> d.dismiss() } | ||||||
| .show() | ||||||
| } else { | ||||||
| Utilities.showToastUiCentered( | ||||||
| context, | ||||||
| context.getString(R.string.wireguard_invalid_config_message), | ||||||
| Toast.LENGTH_LONG | ||||||
| ) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private suspend fun disableWgIfPossible(config: WgConfigFiles) { | ||||||
| if (!VpnController.hasTunnel()) { | ||||||
| Logger.i(LOG_TAG_PROXY, "VPN not active, cannot disable WireGuard") | ||||||
| uiCtx { | ||||||
| // reset the check box | ||||||
| b.oneWgCheck.isChecked = true | ||||||
| Utilities.showToastUiCentered( | ||||||
| context, | ||||||
| ERR_CODE_VPN_NOT_ACTIVE + | ||||||
| context.getString(R.string.settings_socks5_vpn_disabled_error), | ||||||
| context, context.getString(R.string.settings_socks5_vpn_disabled_error), | ||||||
| Toast.LENGTH_LONG | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.