Skip to content

Commit

Permalink
Merge pull request #1506 from hussainmohd-a/v055n
Browse files Browse the repository at this point in the history
v055n
  • Loading branch information
hussainmohd-a committed Jun 9, 2024
2 parents d774cb1 + b00a089 commit 849d356
Show file tree
Hide file tree
Showing 38 changed files with 1,291 additions and 463 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@ dependencies {
fullImplementation 'com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.9'

// from: https://jitpack.io/#celzero/firestack
download 'com.github.celzero:firestack:ad33ecd668@aar'
implementation 'com.github.celzero:firestack:ad33ecd668@aar'
download 'com.github.celzero:firestack:ee0a5ac71f@aar'
websiteImplementation 'com.github.celzero:firestack:ee0a5ac71f@aar'
fdroidImplementation 'com.github.celzero:firestack:ee0a5ac71f@aar'
// debug symbols for crashlytics
playImplementation 'com.github.celzero:firestack:ee0a5ac71f:debug@aar'

// Work manager
implementation('androidx.work:work-runtime-ktx:2.9.0') {
Expand Down
19 changes: 19 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken

# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

# A resource is loaded with a relative path so the package of this class must be preserved.
# ref: github.com/square/okhttp/issues/8154#issuecomment-1868462895
# issue: https://github.com/celzero/rethink-app/issues/1495
# square.github.io/okhttp/features/r8_proguard/
-keeppackagenames okhttp3.internal.publicsuffix.*
-adaptresourcefilenames okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

# OkHttp platform used only on JVM and when Conscrypt and other security providers are available.
-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
38 changes: 36 additions & 2 deletions app/src/fdroid/java/com/celzero/bravedns/util/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,49 @@ object Logger : KoinComponent {
const val LOG_TAG_DOWNLOAD = "DownloadManager"
const val LOG_TAG_UI = "ActivityManager"
const val LOG_TAG_SCHEDULER = "JobScheduler"
const val LOG_TAG_BUG_REPORT = "BugReport"
const val LOG_TAG_BACKUP_RESTORE = "BackupRestore"
const val LOG_PROVIDER = "BlocklistProvider"
const val LOG_TAG_PROXY = "ProxyLogs"
const val LOG_QR_CODE = "QrCodeFromFileScanner"
const val LOG_GO_LOGGER = "LibLogger"

// github.com/celzero/firestack/blob/bce8de917fec5e48a41ed1e96c9d942ee0f7996b/intra/log/logger.go#L76
enum class LoggerType(val id: Int) {
VERY_VERBOSE(0),
VERBOSE(1),
DEBUG(2),
INFO(3),
WARN(4),
ERROR(5)
ERROR(5),
STACKTRACE(6),
USR(7),
NONE(8);

companion object {
fun fromId(id: Int): LoggerType {
return when (id) {
0 -> VERY_VERBOSE
1 -> VERBOSE
2 -> DEBUG
3 -> INFO
4 -> WARN
5 -> ERROR
6 -> STACKTRACE
7 -> USR
8 -> NONE
else -> NONE
}
}
}

fun stacktrace(): Boolean {
return this == STACKTRACE
}

fun user(): Boolean {
return this == USR
}
}

fun vv(tag: String, message: String) {
Expand All @@ -70,7 +101,7 @@ object Logger : KoinComponent {
log(tag, message, LoggerType.ERROR, e)
}

fun crash(tag: String, message: String, e: Exception) {
fun crash(tag: String, message: String, e: Exception?= null) {
log(tag, message, LoggerType.ERROR, e)
}

Expand All @@ -94,6 +125,9 @@ object Logger : KoinComponent {
LoggerType.INFO -> if (logLevel <= LoggerType.INFO.id) Log.i(tag, msg)
LoggerType.WARN -> if (logLevel <= LoggerType.WARN.id) Log.w(tag, msg, e)
LoggerType.ERROR -> if (logLevel <= LoggerType.ERROR.id) Log.e(tag, msg, e)
LoggerType.STACKTRACE -> if (logLevel <= LoggerType.ERROR.id) Log.e(tag, msg, e)
LoggerType.USR -> {} // Do nothing
LoggerType.NONE -> {} // Do nothing
}
}
}
12 changes: 11 additions & 1 deletion app/src/full/java/com/celzero/bravedns/RethinkDnsApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package com.celzero.bravedns
import Logger
import Logger.LOG_TAG_SCHEDULER
import android.app.Application
import android.content.ComponentCallbacks2
import android.content.pm.ApplicationInfo
import android.os.StrictMode
import com.celzero.bravedns.scheduler.ScheduleManager
import com.celzero.bravedns.scheduler.WorkScheduler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import org.koin.android.ext.android.get
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
Expand Down Expand Up @@ -36,7 +40,7 @@ class RethinkDnsApplication : Application() {
super.onCreate()
DEBUG =
applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE ==
ApplicationInfo.FLAG_DEBUGGABLE
ApplicationInfo.FLAG_DEBUGGABLE

startKoin {
if (DEBUG) androidLogger()
Expand All @@ -46,6 +50,12 @@ class RethinkDnsApplication : Application() {

turnOnStrictMode()

CoroutineScope(SupervisorJob()).launch {
scheduleJobs()
}
}

private suspend fun scheduleJobs() {
Logger.d(LOG_TAG_SCHEDULER, "Schedule job")
get<WorkScheduler>().scheduleAppExitInfoCollectionJob()
// database refresh is used in both headless and main project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ class DnsCryptEndpointAdapter(private val context: Context, private val appConfi
return
}

// always use the id as Dnsx.Preffered as it is the primary dns id for now
val state = VpnController.getDnsStatus(Backend.Preferred)
val status = UIUtils.getDnsStatusStringRes(state)
b.dnsCryptEndpointListUrlExplanation.text =
context.getString(status).replaceFirstChar(Char::titlecase)
updateDnsStatus()
}

private fun showExplanationOnImageClick(dnsCryptEndpoint: DnsCryptEndpoint) {
Expand Down Expand Up @@ -244,6 +240,17 @@ class DnsCryptEndpointAdapter(private val context: Context, private val appConfi
}
}

private fun updateDnsStatus() {
io {
val state = VpnController.getDnsStatus(Backend.Preferred)
val status = UIUtils.getDnsStatusStringRes(state)
uiCtx {
b.dnsCryptEndpointListUrlExplanation.text =
context.getString(status).replaceFirstChar(Char::titlecase)
}
}
}

private fun deleteEndpoint(id: Int) {
io {
appConfig.deleteDnscryptEndpoint(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,15 @@ class DnsCryptRelayEndpointAdapter(
}

private fun updateSelectedStatus() {
// always use the id as Dnsx.Preffered as it is the primary dns id for now
val state = VpnController.getDnsStatus(Backend.Preferred)
val status = UIUtils.getDnsStatusStringRes(state)
b.dnsCryptEndpointListUrlExplanation.text =
context.getString(status).replaceFirstChar(Char::titlecase)
io {
// always use the id as Dnsx.Preffered as it is the primary dns id for now
val state = VpnController.getDnsStatus(Backend.Preferred)
val status = UIUtils.getDnsStatusStringRes(state)
uiCtx {
b.dnsCryptEndpointListUrlExplanation.text =
context.getString(status).replaceFirstChar(Char::titlecase)
}
}
}

private fun promptUser(endpoint: DnsCryptRelayEndpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,17 @@ class DoTEndpointAdapter(private val context: Context, private val appConfig: Ap
return
}

// always use the id as Dnsx.Preffered as it is the primary dns id for now
val state = VpnController.getDnsStatus(Backend.Preferred)
val status = getDnsStatusStringRes(state)
b.endpointDesc.text = context.getString(status).replaceFirstChar(Char::titlecase)
updateDnsStatus()
}

private fun updateDnsStatus() {
io {
val state = VpnController.getDnsStatus(Backend.Preferred)
val status = getDnsStatusStringRes(state)
uiCtx {
b.endpointDesc.text = context.getString(status).replaceFirstChar(Char::titlecase)
}
}
}

private fun showIcon(endpoint: DoTEndpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ class DohEndpointAdapter(private val context: Context, private val appConfig: Ap
newConnection: DoHEndpoint
): Boolean {
return (oldConnection.id == newConnection.id &&
oldConnection.isSelected == newConnection.isSelected)
oldConnection.isSelected == newConnection.isSelected)
}

override fun areContentsTheSame(
oldConnection: DoHEndpoint,
newConnection: DoHEndpoint
): Boolean {
return (oldConnection.id == newConnection.id &&
oldConnection.isSelected != newConnection.isSelected)
oldConnection.isSelected != newConnection.isSelected)
}
}
}
Expand Down Expand Up @@ -140,16 +140,25 @@ class DohEndpointAdapter(private val context: Context, private val appConfig: Ap
?.lifecycle
?.currentState
?.isAtLeast(androidx.lifecycle.Lifecycle.State.STARTED) == false ||
bindingAdapterPosition == RecyclerView.NO_POSITION
bindingAdapterPosition == RecyclerView.NO_POSITION
) {
statusCheckJob?.cancel()
return
}

// always use the id as Dnsx.Preffered as it is the primary dns id for now
val state = VpnController.getDnsStatus(Backend.Preferred)
val status = getDnsStatusStringRes(state)
b.endpointDesc.text = context.getString(status).replaceFirstChar(Char::titlecase)
updateDnsStatus()
}

private fun updateDnsStatus() {
io {
// always use the id as Dnsx.Preffered as it is the primary dns id for now
val state = VpnController.getDnsStatus(Backend.Preferred)
val status = getDnsStatusStringRes(state)
uiCtx {
b.endpointDesc.text =
context.getString(status).replaceFirstChar(Char::titlecase)
}
}
}

private fun showIcon(endpoint: DoHEndpoint) {
Expand Down Expand Up @@ -198,14 +207,12 @@ class DohEndpointAdapter(private val context: Context, private val appConfig: Ap
builder.setTitle(title)
builder.setMessage(url + "\n\n" + getDnsDesc(message))
builder.setCancelable(true)
builder.setPositiveButton(context.getString(R.string.dns_info_positive)) {
dialogInterface,
_ ->
builder.setPositiveButton(context.getString(R.string.dns_info_positive)) { dialogInterface,
_ ->
dialogInterface.dismiss()
}
builder.setNeutralButton(context.getString(R.string.dns_info_neutral)) {
_: DialogInterface,
_: Int ->
builder.setNeutralButton(context.getString(R.string.dns_info_neutral)) { _: DialogInterface,
_: Int ->
clipboardCopy(context, url, context.getString(R.string.copy_clipboard_label))
Utilities.showToastUiCentered(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,19 @@ class ODoHEndpointAdapter(private val context: Context, private val appConfig: A
return
}

// always use the id as Dnsx.Preffered as it is the primary dns id for now
val state = VpnController.getDnsStatus(Backend.Preferred)
val status = getDnsStatusStringRes(state)
b.endpointDesc.text = context.getString(status).replaceFirstChar(Char::titlecase)
updateDnsStatus()

}

private fun updateDnsStatus() {
io {
// always use the id as Dnsx.Preffered as it is the primary dns id for now
val state = VpnController.getDnsStatus(Backend.Preferred)
val status = getDnsStatusStringRes(state)
uiCtx {
b.endpointDesc.text = context.getString(status).replaceFirstChar(Char::titlecase)
}
}
}

private fun showIcon(endpoint: ODoHEndpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
fun update(config: WgConfigFiles) {
b.interfaceNameText.text = config.name
b.oneWgCheck.isChecked = config.isActive
updateStatus(config)
io {
updateStatus(config)
}
setupClickListeners(config)
if (config.oneWireGuard) {
keepStatusUpdated(config)
Expand All @@ -122,7 +124,7 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
}

private fun keepStatusUpdated(config: WgConfigFiles) {
statusCheckJob = ui {
statusCheckJob = io {
while (true) {
updateStatus(config)
delay(ONE_SEC)
Expand Down Expand Up @@ -158,7 +160,7 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
}
}

private fun updateStatus(config: WgConfigFiles) {
private suspend fun updateStatus(config: WgConfigFiles) {
// if the view is not active then cancel the job
if (
lifecycleOwner
Expand All @@ -181,9 +183,11 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
} else {
false
}
updateStatusUi(config, statusId, stats)
updateProtocolChip(pair)
updateSplitTunnelChip(isSplitTunnel)
uiCtx {
updateStatusUi(config, statusId, stats)
updateProtocolChip(pair)
updateSplitTunnelChip(isSplitTunnel)
}
}

private fun updateStatusUi(config: WgConfigFiles, statusId: Long?, stats: Stats?) {
Expand Down Expand Up @@ -363,11 +367,7 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
withContext(Dispatchers.Main) { f() }
}

private fun ui(f: suspend () -> Unit): Job? {
return lifecycleOwner?.lifecycleScope?.launch(Dispatchers.Main) { f() }
}

private fun io(f: suspend () -> Unit) {
lifecycleOwner?.lifecycleScope?.launch(Dispatchers.IO) { f() }
private fun io(f: suspend () -> Unit): Job? {
return lifecycleOwner?.lifecycleScope?.launch(Dispatchers.IO) { f() }
}
}
Loading

0 comments on commit 849d356

Please sign in to comment.