Skip to content

Commit 9a55d68

Browse files
Merge pull request #2078 from hussainmohd-a/v055n
v055r
2 parents 738d6af + b6461b8 commit 9a55d68

File tree

74 files changed

+2426
-1321
lines changed

Some content is hidden

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

74 files changed

+2426
-1321
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,20 @@ class ConnectionTrackerAdapter(private val context: Context) :
120120
displayProtocolDetails(connTracker.port, connTracker.protocol)
121121
displayAppDetails(connTracker)
122122
displaySummaryDetails(connTracker)
123-
displayFirewallRulesetHint(connTracker.isBlocked, connTracker.blockedByRule)
123+
// case: when the rule is set to RULE12 but no proxy is set, consider this as error
124+
// handle this as special case, and display the RULE1C hint
125+
// RULE1C is the hint for RULE12 with no proxy set.
126+
val blocked = if (connTracker.blockedByRule == FirewallRuleset.RULE12.id) {
127+
connTracker.proxyDetails.isEmpty()
128+
} else {
129+
connTracker.isBlocked
130+
}
131+
val rule = if (connTracker.blockedByRule == FirewallRuleset.RULE12.id && connTracker.proxyDetails.isEmpty()) {
132+
FirewallRuleset.RULE1C.id
133+
} else {
134+
connTracker.blockedByRule
135+
}
136+
displayFirewallRulesetHint(blocked, rule)
124137

125138
b.connectionParentLayout.setOnClickListener { openBottomSheet(connTracker) }
126139
}
@@ -382,7 +395,7 @@ class ConnectionTrackerAdapter(private val context: Context) :
382395
private fun isConnectionProxied(ruleName: String?, proxyDetails: String): Boolean {
383396
if (ruleName == null) return false
384397
val rule = FirewallRuleset.getFirewallRule(ruleName) ?: return false
385-
val proxy = ProxyManager.isIpnProxy(proxyDetails)
398+
val proxy = ProxyManager.isNotLocalAndRpnProxy(proxyDetails)
386399
return FirewallRuleset.isProxied(rule) && proxyDetails.isNotEmpty() && proxy
387400
}
388401

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ class CustomDomainAdapter(
404404
}
405405
}
406406

407+
b.customDomainCheckbox.setOnClickListener {
408+
toggleSelection(cd)
409+
}
410+
407411
b.customDomainSeeMoreChip.setOnClickListener { openAppWiseRulesActivity(cd.uid) }
408412

409413
b.customDomainContainer.setOnLongClickListener {
@@ -541,6 +545,10 @@ class CustomDomainAdapter(
541545
}
542546
}
543547

548+
b.customDomainCheckbox.setOnClickListener {
549+
toggleSelection(cd)
550+
}
551+
544552
b.customDomainContainer.setOnLongClickListener {
545553
isSelectionMode = true
546554
selectedItems.add(cd)

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule
7070
object : DiffUtil.ItemCallback<CustomIp>() {
7171

7272
override fun areItemsTheSame(oldConnection: CustomIp, newConnection: CustomIp) =
73-
oldConnection.ipAddress == newConnection.ipAddress &&
74-
oldConnection.status == newConnection.status &&
75-
oldConnection.proxyCC == newConnection.proxyCC &&
76-
oldConnection.proxyId == newConnection.proxyId
73+
oldConnection.uid == newConnection.uid &&
74+
oldConnection.ipAddress == newConnection.ipAddress &&
75+
oldConnection.port == newConnection.port
7776

7877
override fun areContentsTheSame(oldConnection: CustomIp, newConnection: CustomIp) =
79-
oldConnection == newConnection
78+
oldConnection.status == newConnection.status &&
79+
oldConnection.proxyCC == newConnection.proxyCC &&
80+
oldConnection.proxyId == newConnection.proxyId &&
81+
oldConnection.modifiedDateTime == newConnection.modifiedDateTime
8082
}
8183
}
8284

@@ -249,6 +251,14 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule
249251
}
250252
}
251253

254+
b.customIpCheckbox.setOnClickListener {
255+
if (!isSelectionMode) {
256+
isSelectionMode = true
257+
}
258+
toggleSelection(customIp)
259+
notifyDataSetChanged()
260+
}
261+
252262
b.customIpSeeMoreChip.setOnClickListener { openAppWiseRulesActivity(customIp.uid) }
253263

254264
b.customIpContainer.setOnLongClickListener {
@@ -412,6 +422,14 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule
412422
}
413423
}
414424

425+
b.customIpCheckbox.setOnClickListener {
426+
if (!isSelectionMode) {
427+
isSelectionMode = true
428+
}
429+
toggleSelection(customIp)
430+
notifyDataSetChanged()
431+
}
432+
415433
b.customIpContainer.setOnLongClickListener {
416434
isSelectionMode = true
417435
selectedItems.add(customIp)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class DnsLogAdapter(val context: Context, val loadFavIcon: Boolean, val isRethin
235235
private fun isConnectionProxied(proxy: String?): Boolean {
236236
if (proxy.isNullOrEmpty()) return false
237237

238-
return !ProxyManager.isIpnProxy(proxy)
238+
return !ProxyManager.isNotLocalAndRpnProxy(proxy)
239239
}
240240

241241
private fun containsMultipleIPs(log: DnsLog): Boolean {

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import com.celzero.bravedns.databinding.ListItemStatisticsSummaryBinding
3333
import com.celzero.bravedns.service.FirewallManager
3434
import com.celzero.bravedns.ui.activity.AppInfoActivity
3535
import com.celzero.bravedns.ui.activity.DomainConnectionsActivity
36+
import com.celzero.bravedns.ui.activity.NetworkLogsActivity
37+
import com.celzero.bravedns.ui.fragment.SummaryStatisticsFragment.SummaryStatisticsType
38+
import com.celzero.bravedns.util.Constants
3639
import com.celzero.bravedns.util.UIUtils.getCountryNameFromFlag
3740
import com.celzero.bravedns.util.Utilities
3841
import com.celzero.bravedns.util.Utilities.getFlag
@@ -129,11 +132,28 @@ class DomainConnectionsAdapter(private val context: Context, private val type: D
129132
b.ssProgress.visibility = View.GONE
130133

131134
b.ssContainer.setOnClickListener {
132-
val intent = Intent(context, AppInfoActivity::class.java)
133-
intent.putExtra(AppInfoActivity.INTENT_UID, dc.uid)
134-
context.startActivity(intent)
135+
io {
136+
if (isUnknownApp(dc)) {
137+
uiCtx {
138+
val intent = Intent(context, NetworkLogsActivity::class.java)
139+
intent.putExtra(Constants.VIEW_PAGER_SCREEN_TO_LOAD, NetworkLogsActivity.Tabs.NETWORK_LOGS.screen)
140+
intent.putExtra(Constants.SEARCH_QUERY, dc.appOrDnsName)
141+
context.startActivity(intent)
142+
}
143+
} else {
144+
uiCtx {
145+
val intent = Intent(context, AppInfoActivity::class.java)
146+
intent.putExtra(AppInfoActivity.INTENT_UID, dc.uid)
147+
context.startActivity(intent)
148+
}
149+
}
150+
}
135151
}
152+
}
136153

154+
private suspend fun isUnknownApp(appConnection: AppConnection): Boolean {
155+
val appInfo = FirewallManager.getAppInfoByUid(appConnection.uid)
156+
return appInfo == null
137157
}
138158

139159
private fun loadAppIcon(drawable: Drawable?) {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ class FirewallAppListAdapter(
6767
oldConnection: AppInfo,
6868
newConnection: AppInfo
6969
): Boolean {
70-
return oldConnection == newConnection
70+
return oldConnection.uid == newConnection.uid &&
71+
oldConnection.packageName == newConnection.packageName &&
72+
oldConnection.appName == newConnection.appName
73+
&& oldConnection.tombstoneTs == newConnection.tombstoneTs
74+
&& oldConnection.isProxyExcluded == newConnection.isProxyExcluded
75+
&& oldConnection.firewallStatus == newConnection.firewallStatus
76+
&& oldConnection.connectionStatus == newConnection.connectionStatus
7177
}
7278

7379
override fun areContentsTheSame(
@@ -241,8 +247,8 @@ class FirewallAppListAdapter(
241247
showWifiUnused()
242248
}
243249
else -> {
244-
showWifiDisabled()
245-
showMobileDataDisabled()
250+
showWifiEnabled()
251+
showMobileDataEnabled()
246252
}
247253
}
248254
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class RethinkLogAdapter(private val context: Context) :
298298
}
299299

300300
private fun isConnectionProxied(proxyDetails: String): Boolean {
301-
return ProxyManager.isIpnProxy(proxyDetails)
301+
return ProxyManager.isNotLocalAndRpnProxy(proxyDetails)
302302
}
303303

304304
private fun isConnectionHeavier(ct: RethinkLog): Boolean {

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,32 @@ class SummaryStatisticsAdapter(
432432
startAppInfoActivity(appConnection)
433433
}
434434
SummaryStatisticsType.MOST_CONNECTED_APPS -> {
435-
startAppInfoActivity(appConnection)
435+
io {
436+
if (isUnknownApp(appConnection)) {
437+
uiCtx {
438+
showNetworkLogs(
439+
appConnection,
440+
SummaryStatisticsType.MOST_CONNECTED_APPS
441+
)
442+
}
443+
} else {
444+
uiCtx { startAppInfoActivity(appConnection) }
445+
}
446+
}
436447
}
437448
SummaryStatisticsType.MOST_BLOCKED_APPS -> {
438-
startAppInfoActivity(appConnection)
449+
io {
450+
if (isUnknownApp(appConnection)) {
451+
uiCtx {
452+
showNetworkLogs(
453+
appConnection,
454+
SummaryStatisticsType.MOST_BLOCKED_APPS
455+
)
456+
}
457+
} else {
458+
uiCtx { startAppInfoActivity(appConnection) }
459+
}
460+
}
439461
}
440462
SummaryStatisticsType.MOST_CONNECTED_ASN -> {
441463
startDomainConnectionsActivity(appConnection, DomainConnectionsActivity.InputType.ASN)
@@ -462,6 +484,11 @@ class SummaryStatisticsAdapter(
462484
}
463485
}
464486

487+
private suspend fun isUnknownApp(appConnection: AppConnection): Boolean {
488+
val appInfo = FirewallManager.getAppInfoByUid(appConnection.uid)
489+
return appInfo == null
490+
}
491+
465492
private fun startDomainConnectionsActivity(appConnection: AppConnection, input: DomainConnectionsActivity.InputType, isBlocked: Boolean = false) {
466493
val intent = Intent(context, DomainConnectionsActivity::class.java)
467494
intent.putExtra(DomainConnectionsActivity.INTENT_EXTRA_TYPE, input.type)
@@ -548,7 +575,7 @@ class SummaryStatisticsAdapter(
548575
}
549576
else -> {
550577
// should never happen, but just in case we'll show all logs
551-
startActivity(NetworkLogsActivity.Tabs.NETWORK_LOGS.screen, "")
578+
startActivity(NetworkLogsActivity.Tabs.NETWORK_LOGS.screen, appConnection.appOrDnsName)
552579
}
553580
}
554581
}

app/src/full/java/com/celzero/bravedns/scheduler/BugReportZipper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.celzero.bravedns.BuildConfig
2626
import com.celzero.bravedns.service.VpnController
2727
import com.celzero.bravedns.util.Constants
2828
import com.celzero.bravedns.util.Utilities
29+
import com.celzero.firestack.intra.Intra
2930
import com.google.common.io.Files
3031
import java.io.File
3132
import java.io.FileInputStream
@@ -382,7 +383,7 @@ object BugReportZipper {
382383
file.appendText(prefsDetails.toString())
383384
val separator = "--------------------------------------------\n"
384385
file.appendText(separator)
385-
val build = VpnController.goBuildVersion(true)
386+
val build = Intra.build(true)
386387
file.appendText(build)
387388
file.appendText(separator)
388389
}

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ object ProxyManager : KoinComponent {
208208
m.forEach { addNewApp(it) }
209209
}
210210

211+
suspend fun updateApps(m: Collection<FirewallManager.AppInfoTuple>) {
212+
m.forEach { updateApp(it.uid, it.packageName) }
213+
}
214+
211215
suspend fun addApp(appInfo: AppInfo?) {
212216
addNewApp(appInfo)
213217
}
@@ -231,15 +235,15 @@ object ProxyManager : KoinComponent {
231235
}
232236

233237
suspend fun purgeDupsBeforeRefresh() {
234-
val visited = mutableSetOf<FirewallManager.AppInfoTuple>()
238+
val visited = mutableSetOf<String>() // contains package-names
235239
val dups = mutableSetOf<FirewallManager.AppInfoTuple>()
236240
pamSet
237241
.map { FirewallManager.AppInfoTuple(it.uid, it.packageName) }
238-
.forEach { if (visited.contains(it)) dups.add(it) else visited.add(it) }
242+
.forEach { if (visited.contains(it.packageName)) dups.add(it) else visited.add(it.packageName) }
239243
// duplicates are unexpected; but since refreshDatabase only deals in uid+package-name
240244
// and proxy-mapper primary keys on uid+package-name+proxy-id, there have been cases
241245
// of duplicate entries in the proxy-mapper. Purge all entries that have same
242-
// uid+package-name pair. Note that, doing so also removes entry for an app even if it is
246+
// package-name. Note that, doing so also removes entry for an app even if it is
243247
// currently installed.
244248
// This is okay, given we do not expect any dups. Also: This fn must be called before
245249
// refreshDatabase so that any entries removed are added back as "new mappings" via
@@ -303,12 +307,29 @@ object ProxyManager : KoinComponent {
303307
}
304308
}
305309

310+
suspend fun deleteAppByPkgName(packageName: String) {
311+
// delete the app from the cache
312+
pamSet.removeIf { it.packageName == packageName }
313+
// delete the app from the database
314+
db.deleteAppByPkgName(packageName)
315+
Logger.i(LOG_TAG_PROXY, "deleting app for mapping by package name: $packageName")
316+
}
317+
306318
suspend fun clear() {
307319
pamSet.clear()
308320
db.deleteAll()
309321
Logger.d(LOG_TAG_PROXY, "deleting all apps for mapping")
310322
}
311323

324+
suspend fun tombstoneApp(oldUid: Int) {
325+
// tombstone the app in the database and reload the cache
326+
val newUid = -1 * oldUid // negative uid to indicate tombstone app
327+
db.tombstoneApp(oldUid, newUid)
328+
// reload the cache
329+
load()
330+
Logger.i(LOG_TAG_PROXY, "tombstoning app for mapping: $oldUid, $newUid")
331+
}
332+
312333
fun isAnyAppSelected(proxyId: String): Boolean {
313334
return pamSet.any { it.proxyId == proxyId }
314335
}
@@ -327,7 +348,7 @@ object ProxyManager : KoinComponent {
327348
return pamSet.count { it.proxyId == proxyId }
328349
}
329350

330-
fun isIpnProxy(ipnProxyId: String): Boolean {
351+
fun isNotLocalAndRpnProxy(ipnProxyId: String): Boolean {
331352
if (ipnProxyId.isEmpty()) return false
332353
// check if the proxy id is not the base, block, exit, auto or ingress
333354
// all these are special cases and should not be considered as proxied traffic
@@ -336,7 +357,6 @@ object ProxyManager : KoinComponent {
336357
ipnProxyId != Backend.Exit &&
337358
ipnProxyId != Backend.Auto &&
338359
ipnProxyId != Backend.Ingress &&
339-
ipnProxyId != Backend.Plus &&
340360
!ipnProxyId.endsWith(Backend.RPN)
341361
}
342362

0 commit comments

Comments
 (0)