Skip to content

Commit

Permalink
Do not mistake UnknownApp for NewApp
Browse files Browse the repository at this point in the history
When uid points to missing / unknown app, do not
treat it as a new (untracked) app and apply firewall
rules applicable to those (untracked / new apps)
  • Loading branch information
ignoramous authored Sep 23, 2021
1 parent 63efbf6 commit 46f08da
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,6 @@ class BraveVPNService : VpnService(), ConnectionMonitor.NetworkListener, Protect
val uid = connInfo.uid
val appStatus = FirewallManager.appStatus(uid)

if (settingUpOrbot.get()) {
if (OrbotHelper.ORBOT_PACKAGE_NAME == FirewallManager.getPackageNameByUid(uid)) {
return FirewallRuleset.RULE9B
} else {
// fall-through
}
}

if (allowOrbot(uid)) {
return FirewallRuleset.RULE9B
}
Expand Down Expand Up @@ -304,18 +296,18 @@ class BraveVPNService : VpnService(), ConnectionMonitor.NetworkListener, Protect
}
}

private fun waitAndCheckIfNewAppAllowed(uid: Int): Boolean {
private fun waitAndCheckIfUidBlocked(uid: Int): Boolean {
val allowed = testWithBackoff {
FirewallManager.hasUid(uid) && !FirewallManager.isUidFirewalled(uid)
}
return !allowed
}

private fun newAppBlocked(uid: Int): Boolean {
return if (!persistentState.blockNewlyInstalledApp) {
return if (!persistentState.blockNewlyInstalledApp || isMissingOrInvalidUid(uid)) {
false
} else {
waitAndCheckIfNewAppAllowed(uid)
waitAndCheckIfUidBlocked(uid)
}
}

Expand All @@ -333,10 +325,10 @@ class BraveVPNService : VpnService(), ConnectionMonitor.NetworkListener, Protect
}
}

private fun testWithBackoff(stallSec: Long = 20, waitSec: Long = 10,
private fun testWithBackoff(stallSec: Long = 20, durationSec: Long = 10,
test: () -> Boolean): Boolean {
val minWaitMs = TimeUnit.SECONDS.toMillis(stallSec)
var remainingWaitMs = TimeUnit.SECONDS.toMillis(waitSec)
var remainingWaitMs = TimeUnit.SECONDS.toMillis(durationSec)
var attempt = 0
while (remainingWaitMs > 0) {
if (test()) return true
Expand Down

0 comments on commit 46f08da

Please sign in to comment.