Skip to content

Commit

Permalink
Merge pull request #903 from hussainmohd-a/v055
Browse files Browse the repository at this point in the history
v055
  • Loading branch information
hussainmohd-a authored Aug 14, 2023
2 parents 9de7103 + 0424f76 commit 260672c
Show file tree
Hide file tree
Showing 274 changed files with 15,538 additions and 3,250 deletions.
18 changes: 13 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ android {
dimension "releaseType"
// getPackageInfo().versionCode not returning the correct value (in prod builds) when
// value is set in AndroidManifest.xml so setting it here
versionCode = 29
versionName = "v054c"
versionCode = 30
versionName = "v055"
vectorDrawables.useSupportLibrary = true
}
}

Expand Down Expand Up @@ -210,9 +211,8 @@ dependencies {
fullImplementation 'com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.9'

// Tun2socks (https://jitpack.io/#celzero/firestack)

download 'com.github.celzero:firestack:37b6b37c99'
implementation 'com.github.celzero:firestack:37b6b37c99'
download 'com.github.celzero:firestack:7905a346f2:arm64@aar'
implementation 'com.github.celzero:firestack:7905a346f2:full@aar'
// implementation project(":tun2socks")

// Work manager
Expand Down Expand Up @@ -241,6 +241,14 @@ dependencies {
fullImplementation 'androidx.biometric:biometric:1.1.0'

playImplementation 'com.google.android.play:core:1.10.3' // for new version updater

// for encrypted file management
implementation("androidx.security:security-crypto:1.1.0-alpha06")
implementation("androidx.security:security-app-authenticator:1.0.0-alpha02")
androidTestImplementation("androidx.security:security-app-authenticator:1.0.0-alpha02")

// barcode scanner for wireguard
fullImplementation 'com.journeyapps:zxing-android-embedded:4.3.0'
}

// github.com/michel-kraemer/gradle-download-task/issues/131#issuecomment-464476903
Expand Down
22 changes: 22 additions & 0 deletions app/src/full/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,34 @@
<activity
android:name=".ui.NetworkLogsActivity"
android:finishOnTaskLaunch="true" />
<activity
android:name=".ui.WgMainActivity"
android:finishOnTaskLaunch="true" />
<activity
android:name=".ui.WgConfigEditorActivity"
android:finishOnTaskLaunch="true" />
<activity
android:name=".ui.WgConfigDetailActivity"
android:finishOnTaskLaunch="true" />
<activity
android:name=".ui.CheckoutActivity"
android:finishOnTaskLaunch="true" />
<activity
android:name=".ui.TcpProxyMainActivity"
android:finishOnTaskLaunch="true" />
<activity
android:name=".ui.UniversalFirewallSettingsActivity"
android:finishOnTaskLaunch="true" />
<activity
android:name=".ui.NotificationHandlerDialog"
android:excludeFromRecents="true"
android:launchMode="singleInstance"
android:taskAffinity=""
android:theme="@style/AppThemeDialog" />
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="screenOrientation" />

<receiver
android:name=".receiver.BraveAutoStartReceiver"
Expand Down
26 changes: 6 additions & 20 deletions app/src/full/java/com/celzero/bravedns/RethinkDnsApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package com.celzero.bravedns

import android.app.Application
import android.content.pm.ApplicationInfo
import android.net.VpnService
import android.os.StrictMode
import android.util.Log
import com.celzero.bravedns.scheduler.ScheduleManager
import com.celzero.bravedns.scheduler.WorkScheduler
import com.celzero.bravedns.service.VpnController
import com.celzero.bravedns.util.LoggerConstants
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_TAG_SCHEDULER
import org.koin.android.ext.android.get
import org.koin.android.ext.koin.androidContext
Expand Down Expand Up @@ -37,35 +34,24 @@ class RethinkDnsApplication : Application() {

override fun onCreate() {
super.onCreate()

DEBUG = applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE == ApplicationInfo.FLAG_DEBUGGABLE

turnOnStrictMode()
DEBUG =
applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE ==
ApplicationInfo.FLAG_DEBUGGABLE

startKoin {
if (DEBUG) androidLogger()
androidContext(this@RethinkDnsApplication)
koin.loadModules(AppModules)
}

turnOnStrictMode()

if (DEBUG) Log.d(LOG_TAG_SCHEDULER, "Schedule job")
get<WorkScheduler>().scheduleAppExitInfoCollectionJob()
// database refresh is used in both headless and main project
get<ScheduleManager>().scheduleDatabaseRefreshJob()
get<WorkScheduler>().scheduleDataUsageJob()
get<WorkScheduler>().schedulePurgeConnectionsLog()

/**
* Issue fix - https://github.com/celzero/rethink-app/issues/57 When the application
* crashes/updates it goes into red waiting state. This causes confusion to the users also
* requires click of START button twice to start the app. FIX : The check for the controller
* state. If persistence state has vpn enabled and the VPN is not connected then the start
* will be initiated.
*/
val state = VpnController.state()
if (state.activationRequested && !state.on) {
Log.i(LoggerConstants.LOG_TAG_VPN, "start VPN (previous state)")
if (VpnService.prepare(this) == null) VpnController.start(this)
} else VpnController.stop(this)
}

private fun turnOnStrictMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import com.celzero.bravedns.databinding.ListItemAppConnDetailsBinding
import com.celzero.bravedns.service.IpRulesManager
import com.celzero.bravedns.ui.AppConnectionBottomSheet
import com.celzero.bravedns.util.LoggerConstants
import com.celzero.bravedns.util.UIUtils.fetchColor
import com.celzero.bravedns.util.UiUtils.fetchColor
import com.celzero.bravedns.util.Utilities.removeBeginningTrailingCommas

class AppConnectionAdapter(val context: Context, val uid: Int) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ import com.celzero.bravedns.databinding.ConnectionTransactionRowBinding
import com.celzero.bravedns.glide.GlideApp
import com.celzero.bravedns.service.FirewallManager
import com.celzero.bravedns.service.FirewallRuleset
import com.celzero.bravedns.service.VpnController
import com.celzero.bravedns.ui.ConnTrackerBottomSheetFragment
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.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 All @@ -63,6 +65,10 @@ class ConnectionTrackerAdapter(private val context: Context) :
newConnection: ConnectionTracker
) = oldConnection == newConnection
}

private const val MAX_BYTES = 500000 // 500 KB
private const val MAX_TIME_TCP = 120 // seconds
private const val MAX_TIME_UDP = 135 // seconds
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ConnectionTrackerViewHolder {
Expand All @@ -89,6 +95,7 @@ class ConnectionTrackerAdapter(private val context: Context) :
displayTransactionDetails(connTracker)
displayProtocolDetails(connTracker.port, connTracker.protocol)
displayAppDetails(connTracker)
displaySummaryDetails(connTracker)
displayFirewallRulesetHint(connTracker.isBlocked, connTracker.blockedByRule)

b.connectionParentLayout.setOnClickListener { openBottomSheet(connTracker) }
Expand Down Expand Up @@ -198,6 +205,81 @@ class ConnectionTrackerAdapter(private val context: Context) :
}
}

private fun displaySummaryDetails(ct: ConnectionTracker) {
if (
ct.duration == 0 &&
ct.downloadBytes == 0L &&
ct.uploadBytes == 0L &&
ct.message.isEmpty()
) {
if (VpnController.hasCid(ct.connId)) {
b.connectionSummaryLl.visibility = View.VISIBLE
b.connectionDataUsage.text = context.getString(R.string.lbl_active)
b.connectionDuration.text = context.getString(R.string.symbol_green_circle)
b.connectionDelay.text = ""
}
if (isConnectionProxied(ct.blockedByRule)) {
b.connectionSummaryLl.visibility = View.VISIBLE
b.connectionDelay.text = context.getString(R.string.symbol_key)
} else {
b.connectionDelay.text = ""
b.connectionSummaryLl.visibility = View.GONE
}
return
}

b.connectionSummaryLl.visibility = View.VISIBLE
val duration = getDurationInHumanReadableFormat(context, ct.duration)
b.connectionDuration.text = context.getString(R.string.single_argument, duration)
// add unicode for download and upload
val download =
context.getString(
R.string.symbol_download,
Utilities.humanReadableByteCount(ct.downloadBytes, true)
)
val upload =
context.getString(
R.string.symbol_upload,
Utilities.humanReadableByteCount(ct.uploadBytes, true)
)
b.connectionDataUsage.text = context.getString(R.string.two_argument, upload, download)
b.connectionDelay.text = ""
if (isConnectionHeavier(ct)) {
b.connectionDelay.visibility = View.VISIBLE
b.connectionDelay.text = context.getString(R.string.symbol_elephant)
}
if (isConnectionSlower(ct)) {
b.connectionDelay.visibility = View.VISIBLE
b.connectionDelay.text =
b.connectionDelay.text.toString() + context.getString(R.string.symbol_turtle)
}
if (isConnectionProxied(ct.blockedByRule)) {
b.connectionSummaryLl.visibility = View.VISIBLE
b.connectionDelay.text =
b.connectionDelay.text.toString() + context.getString(R.string.symbol_key)
} else {
b.connectionDelay.text = ""
b.connectionDelay.visibility = View.GONE
}
}

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

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

return FirewallRuleset.isProxied(rule)
}

private fun isConnectionHeavier(ct: ConnectionTracker): Boolean {
return ct.downloadBytes + ct.uploadBytes > MAX_BYTES
}

private fun isConnectionSlower(ct: ConnectionTracker): Boolean {
return (ct.protocol == Protocol.UDP.protocolType && ct.duration > MAX_TIME_UDP) ||
(ct.protocol == Protocol.TCP.protocolType && ct.duration > MAX_TIME_TCP)
}

private fun loadAppIcon(drawable: Drawable?) {
GlideApp.with(context)
.load(drawable)
Expand Down
Loading

0 comments on commit 260672c

Please sign in to comment.