Skip to content

Commit

Permalink
Fix #1059: show proxy icon irrespective of domain rule
Browse files Browse the repository at this point in the history
  • Loading branch information
hussainmohd-a committed Sep 19, 2023
1 parent f6523a4 commit 91952e1
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ import com.celzero.bravedns.database.ConnectionTracker
import com.celzero.bravedns.databinding.ConnectionTransactionRowBinding
import com.celzero.bravedns.service.FirewallManager
import com.celzero.bravedns.service.FirewallRuleset
import com.celzero.bravedns.service.ProxyManager
import com.celzero.bravedns.service.VpnController
import com.celzero.bravedns.ui.bottomsheet.ConnTrackerBottomSheet
import com.celzero.bravedns.util.Constants.Companion.TIME_FORMAT_1
import com.celzero.bravedns.util.KnownPorts
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_TAG_UI
import com.celzero.bravedns.util.Protocol
import com.celzero.bravedns.util.UIUtils.getDurationInHumanReadableFormat
import com.celzero.bravedns.util.Utilities
import com.celzero.bravedns.util.Utilities.getDurationInHumanReadableFormat
import com.celzero.bravedns.util.Utilities.getIcon
import com.google.gson.Gson
import java.util.Locale
Expand Down Expand Up @@ -115,10 +116,7 @@ class ConnectionTrackerAdapter(private val context: Context) :
val bottomSheetFragment = ConnTrackerBottomSheet()
// see AppIpRulesAdapter.kt#openBottomSheet()
val bundle = Bundle()
bundle.putString(
ConnTrackerBottomSheet.INSTANCE_STATE_IPDETAILS,
Gson().toJson(ct)
)
bundle.putString(ConnTrackerBottomSheet.INSTANCE_STATE_IPDETAILS, Gson().toJson(ct))
bottomSheetFragment.arguments = bundle
bottomSheetFragment.show(context.supportFragmentManager, bottomSheetFragment.tag)
}
Expand Down Expand Up @@ -220,7 +218,7 @@ class ConnectionTrackerAdapter(private val context: Context) :
b.connectionDelay.text = ""
hasMinSummary = true
}
if (isConnectionProxied(ct.blockedByRule)) {
if (isConnectionProxied(ct.blockedByRule, ct.proxyDetails)) {
b.connectionSummaryLl.visibility = View.VISIBLE
b.connectionDelay.text = context.getString(R.string.symbol_key)
hasMinSummary = true
Expand Down Expand Up @@ -254,7 +252,7 @@ class ConnectionTrackerAdapter(private val context: Context) :
b.connectionDelay.text =
b.connectionDelay.text.toString() + context.getString(R.string.symbol_turtle)
}
if (isConnectionProxied(ct.blockedByRule)) {
if (isConnectionProxied(ct.blockedByRule, ct.proxyDetails)) {
b.connectionDelay.text =
b.connectionDelay.text.toString() + context.getString(R.string.symbol_key)
}
Expand All @@ -263,12 +261,11 @@ class ConnectionTrackerAdapter(private val context: Context) :
}
}

private fun isConnectionProxied(ruleName: String?): Boolean {
private fun isConnectionProxied(ruleName: String?, proxyDetails: String): Boolean {
if (ruleName == null) return false

val rule = FirewallRuleset.getFirewallRule(ruleName) ?: return false

return FirewallRuleset.isProxied(rule)
val proxy = ProxyManager.isProxied(proxyDetails)
return FirewallRuleset.isProxied(rule) || proxy
}

private fun isConnectionHeavier(ct: ConnectionTracker): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.celzero.bravedns.database.AppInfo
import com.celzero.bravedns.database.ProxyAppMappingRepository
import com.celzero.bravedns.database.ProxyApplicationMapping
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_TAG_PROXY
import ipn.Ipn
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -191,6 +192,14 @@ object ProxyManager : KoinComponent {
io { proxyAppMappingRepository.removeAllWgProxies() }
}

fun isProxied(proxyId: String): Boolean {
if (proxyId == "") return false

// determine whether the connection is proxied or not
// if the connection is not Ipn.Base, Ipn.Block then it is proxied
return proxyId != Ipn.Base && proxyId != Ipn.Block
}

private fun io(f: suspend () -> Unit) {
CoroutineScope(Dispatchers.IO).launch { f() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data class ConnTrackerMetaData(
val timestamp: Long,
var isBlocked: Boolean,
var blockedByRule: String,
var proxyDetails: String,
var blocklists: String,
val protocol: Int,
var query: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ConnectionTracker {
var isBlocked: Boolean = false
var blockedByRule: String = ""
var blocklists: String = ""
var proxyDetails: String = ""
var flag: String = ""
var dnsQuery: String? = null
var timeStamp: Long = INIT_TIME_MS
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/celzero/bravedns/database/LogDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import androidx.sqlite.db.SimpleSQLiteQuery
import androidx.sqlite.db.SupportSQLiteDatabase
import com.celzero.bravedns.util.Utilities

@Database(entities = [ConnectionTracker::class, DnsLog::class], version = 5, exportSchema = false)
@Database(entities = [ConnectionTracker::class, DnsLog::class], version = 6, exportSchema = false)
@TypeConverters(Converters::class)
abstract class LogDatabase : RoomDatabase() {

Expand Down Expand Up @@ -62,6 +62,7 @@ abstract class LogDatabase : RoomDatabase() {
.addMigrations(MIGRATION_2_3)
.addMigrations(MIGRATION_3_4)
.addMigrations(MIGRATION_4_5)
.addMigrations(MIGRATION_5_6)
.build()
}

Expand Down Expand Up @@ -209,6 +210,15 @@ abstract class LogDatabase : RoomDatabase() {
)
}
}

private val MIGRATION_5_6: Migration =
object : Migration(5, 6) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"ALTER TABLE ConnectionTracker ADD COLUMN proxyDetails TEXT DEFAULT '' NOT NULL"
)
}
}
}

fun checkPoint() {
Expand Down
Loading

0 comments on commit 91952e1

Please sign in to comment.