Skip to content
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

Connection monitor changes #282

Merged
merged 33 commits into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a179d4b
Connection monitor changes
hussainmohd-a May 5, 2021
c5368bc
Changes on connection monitor
hussainmohd-a May 10, 2021
97d6477
Modifications on Connection Monitor
hussainmohd-a May 15, 2021
d98e06c
Added logs
hussainmohd-a May 15, 2021
de2171c
Notification action changes
hussainmohd-a May 16, 2021
ee6ffb5
Changes on Notification receiver and Connection monitor
hussainmohd-a May 18, 2021
b5f88d3
Remove raw integers
hussainmohd-a May 21, 2021
10512e0
Removal of raw literals, global variables
hussainmohd-a May 23, 2021
27e58dc
Code formatting
hussainmohd-a May 23, 2021
98e21c2
Remove Global variable, changes in logger statements
hussainmohd-a May 28, 2021
a6ad26a
Update new line
hussainmohd-a May 28, 2021
1a471d7
Reserved Port 853 - service name change
hussainmohd-a May 30, 2021
a41c9d6
VpnService.Builder.establish() sporadically null
hussainmohd-a Jun 2, 2021
12dcb01
Constants, comments changes, code abstract
hussainmohd-a Jun 4, 2021
0905cc5
Block unknown connection fix
hussainmohd-a Jun 4, 2021
7049d65
Logger changes, more comments
hussainmohd-a Jun 14, 2021
3169cc9
Remove ReceiverHelper class, comments, logs
hussainmohd-a Jun 14, 2021
f4a9c67
Valid UI check, reorganize constants and magic ints
hussainmohd-a Jun 16, 2021
f26f394
Simplify code, Error Handling
hussainmohd-a Jun 23, 2021
c73582c
Simplify code, Error Handling - second pass
hussainmohd-a Jun 24, 2021
14e060f
Simplify code, Error Handling - third pass
hussainmohd-a Jun 25, 2021
6d433c7
Code Format
hussainmohd-a Jul 1, 2021
4df0dec
Remove magic int's from themes
hussainmohd-a Jul 1, 2021
9615200
Simplify code, Error Handling, comments and logs changes
hussainmohd-a Jul 3, 2021
ef2c0c2
Error Handling, comments, Code simplification - Second pass
hussainmohd-a Jul 3, 2021
7a915f8
Rename variable
hussainmohd-a Jul 3, 2021
b028a60
Always on issue fix for android version 12 and above
hussainmohd-a Jul 5, 2021
94d985a
Code simplification, error Handling, comments
hussainmohd-a Jul 8, 2021
2e87fcf
Code formatting, bug fix
hussainmohd-a Jul 8, 2021
baa0ae2
Code refractor, log changes, variable rename
hussainmohd-a Jul 20, 2021
ff1eb73
App not in use notification change
hussainmohd-a Jul 20, 2021
52d798d
Code refractor, variable/method rename
hussainmohd-a Jul 28, 2021
632a3d1
Merge branch 'master' into v053f
ignoramous Jul 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ android {
applicationId "com.celzero.bravedns"
minSdkVersion 23
targetSdkVersion 30
versionCode 16 // For version name 053e
versionName "0.5.3e"
versionCode 17 // For version name 053f
versionName "0.5.3f"
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
35 changes: 26 additions & 9 deletions app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ import settings.Settings
import java.net.InetAddress
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.collections.LinkedHashSet
import kotlin.random.Random


class BraveVPNService : VpnService(), ConnectionCapabilityMonitor.NetworkListener, Protector, Blocker,
class BraveVPNService : VpnService(), ConnectionMonitor.NetworkListener, Protector, Blocker,
OnSharedPreferenceChangeListener {

@GuardedBy("vpnController") private var connectionCapabilityMonitor : ConnectionCapabilityMonitor ?= null
//@GuardedBy("vpnController") private var connectionCapabilityMonitor : ConnectionCapabilityMonitor ?= null
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
@GuardedBy("vpnController") private var connectionMonitor : ConnectionMonitor ?= null
@GuardedBy("vpnController") private var vpnAdapter: GoVpnAdapter? = null

companion object {
Expand Down Expand Up @@ -408,7 +411,7 @@ class BraveVPNService : VpnService(), ConnectionCapabilityMonitor.NetworkListene
// (apps lose connectivity during switch over Mobile Data from WiFi)
// Whenever the VPN is started the list which is stored in the ConnectionCapabilityMonitor
// class is set for the underlying networks.
builder.setUnderlyingNetworks(connectionCapabilityMonitor?.getNetworkList()?.toTypedArray())
builder.setUnderlyingNetworks(connectionMonitor?.getNetworkList()?.toTypedArray())
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
ignoramous marked this conversation as resolved.
Show resolved Hide resolved

//Fix - Cloud Backups were failing thinking that the VPN connection is metered.
//The below code will fix that.
Expand Down Expand Up @@ -621,13 +624,13 @@ class BraveVPNService : VpnService(), ConnectionCapabilityMonitor.NetworkListene
if(DEBUG) Log.d(LOG_TAG, "$FILE_LOG_TAG Registering the shared pref changes with the vpn service")
persistentState.sharedPreferences.registerOnSharedPreferenceChangeListener(this)

if (connectionCapabilityMonitor != null) {
if (connectionMonitor != null) {
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
spawnServerUpdate()
return Service.START_REDELIVER_INTENT
}

// Register for ConnectivityManager
connectionCapabilityMonitor = ConnectionCapabilityMonitor(this, this)
connectionMonitor = ConnectionMonitor(this, this)
ignoramous marked this conversation as resolved.
Show resolved Hide resolved

// Part of issue fix(#242) - StartVPN thread that for some reason is waiting
// Avoiding the call from ConnectivityManager to invoke startVPN is removed.
Expand Down Expand Up @@ -682,7 +685,7 @@ class BraveVPNService : VpnService(), ConnectionCapabilityMonitor.NetworkListene
private fun spawnServerUpdate() {
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
if (vpnController != null) {
synchronized(vpnController) {
if (connectionCapabilityMonitor != null) {
if (connectionMonitor != null) {
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
Thread({ updateServerConnection() }, "updateServerConnection-onStartCommand").start()
}
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down Expand Up @@ -823,6 +826,10 @@ class BraveVPNService : VpnService(), ConnectionCapabilityMonitor.NetworkListene
Log.i(LOG_TAG, "$FILE_LOG_TAG ORBOT proxy change - restart vpn ${appMode.getProxyMode()}")
restartVpn(appMode.getDNSMode(), appMode.getFirewallMode(), appMode.getProxyMode())
}

if(PersistentState.NETWORK == key){
connectionMonitor?.onPreferenceChanged()
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
}
}

fun signalStopService(userInitiated: Boolean) {
Expand Down Expand Up @@ -919,11 +926,21 @@ class BraveVPNService : VpnService(), ConnectionCapabilityMonitor.NetworkListene
vpnController!!.onConnectionStateChanged(this, State.FAILING)
}

override fun onNetworkChange(networkSet: MutableSet<Network>) {
override fun onNetworkConnected(networkSet: LinkedHashSet<Network>) {
setUnderlyingNetworks(networkSet.toTypedArray())
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
}

override fun checkLockDown() {
override fun onUpdateActiveNetwork(network: Network?) {
if(network == null){
setUnderlyingNetworks(null)
return
}
val networkList = ArrayList<Network?>()
networkList.add(network)
setUnderlyingNetworks(networkList.toTypedArray())
}
ignoramous marked this conversation as resolved.
Show resolved Hide resolved

private fun checkLockDown() {
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
if (VERSION.SDK_INT >= VERSION_CODES.Q) {
if (DEBUG) Log.d(LOG_TAG, "BraveVPNService Value for isLockDownEnabled - ${isLockdownEnabled}, $isLockDownPrevious")
if (isLockdownEnabled != isLockDownPrevious) {
Expand Down Expand Up @@ -960,7 +977,7 @@ class BraveVPNService : VpnService(), ConnectionCapabilityMonitor.NetworkListene
synchronized(vpnController!!) {
Log.w(LOG_TAG, "$FILE_LOG_TAG Destroying DNS VPN service")
persistentState.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
connectionCapabilityMonitor?.removeCallBack()
connectionMonitor?.removeCallBack()
vpnController.setBraveVpnService(null)
stopForeground(true)
if (vpnAdapter != null) {
Expand Down

This file was deleted.

Loading