Skip to content

Commit 849d356

Browse files
Merge pull request #1506 from hussainmohd-a/v055n
v055n
2 parents d774cb1 + b00a089 commit 849d356

38 files changed

+1291
-463
lines changed

app/build.gradle

+5-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,11 @@ dependencies {
249249
fullImplementation 'com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.9'
250250

251251
// from: https://jitpack.io/#celzero/firestack
252-
download 'com.github.celzero:firestack:ad33ecd668@aar'
253-
implementation 'com.github.celzero:firestack:ad33ecd668@aar'
252+
download 'com.github.celzero:firestack:ee0a5ac71f@aar'
253+
websiteImplementation 'com.github.celzero:firestack:ee0a5ac71f@aar'
254+
fdroidImplementation 'com.github.celzero:firestack:ee0a5ac71f@aar'
255+
// debug symbols for crashlytics
256+
playImplementation 'com.github.celzero:firestack:ee0a5ac71f:debug@aar'
254257

255258
// Work manager
256259
implementation('androidx.work:work-runtime-ktx:2.9.0') {

app/proguard-rules.pro

+19
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@
3636
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
3737
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
3838

39+
# JSR 305 annotations are for embedding nullability information.
40+
-dontwarn javax.annotation.**
41+
42+
# A resource is loaded with a relative path so the package of this class must be preserved.
43+
# ref: github.com/square/okhttp/issues/8154#issuecomment-1868462895
44+
# issue: https://github.com/celzero/rethink-app/issues/1495
45+
# square.github.io/okhttp/features/r8_proguard/
46+
-keeppackagenames okhttp3.internal.publicsuffix.*
47+
-adaptresourcefilenames okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz
48+
49+
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
50+
-dontwarn org.codehaus.mojo.animal_sniffer.*
51+
52+
# OkHttp platform used only on JVM and when Conscrypt and other security providers are available.
53+
-dontwarn okhttp3.internal.platform.**
54+
-dontwarn org.conscrypt.**
55+
-dontwarn org.bouncycastle.**
56+
-dontwarn org.openjsse.**
57+
3958
# If you keep the line number information, uncomment this to
4059
# hide the original source file name.
4160
#-renamesourcefileattribute SourceFile

app/src/fdroid/java/com/celzero/bravedns/util/Logger.kt

+36-2
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,49 @@ object Logger : KoinComponent {
3232
const val LOG_TAG_DOWNLOAD = "DownloadManager"
3333
const val LOG_TAG_UI = "ActivityManager"
3434
const val LOG_TAG_SCHEDULER = "JobScheduler"
35+
const val LOG_TAG_BUG_REPORT = "BugReport"
3536
const val LOG_TAG_BACKUP_RESTORE = "BackupRestore"
3637
const val LOG_PROVIDER = "BlocklistProvider"
3738
const val LOG_TAG_PROXY = "ProxyLogs"
3839
const val LOG_QR_CODE = "QrCodeFromFileScanner"
40+
const val LOG_GO_LOGGER = "LibLogger"
3941

42+
// github.com/celzero/firestack/blob/bce8de917fec5e48a41ed1e96c9d942ee0f7996b/intra/log/logger.go#L76
4043
enum class LoggerType(val id: Int) {
4144
VERY_VERBOSE(0),
4245
VERBOSE(1),
4346
DEBUG(2),
4447
INFO(3),
4548
WARN(4),
46-
ERROR(5)
49+
ERROR(5),
50+
STACKTRACE(6),
51+
USR(7),
52+
NONE(8);
53+
54+
companion object {
55+
fun fromId(id: Int): LoggerType {
56+
return when (id) {
57+
0 -> VERY_VERBOSE
58+
1 -> VERBOSE
59+
2 -> DEBUG
60+
3 -> INFO
61+
4 -> WARN
62+
5 -> ERROR
63+
6 -> STACKTRACE
64+
7 -> USR
65+
8 -> NONE
66+
else -> NONE
67+
}
68+
}
69+
}
70+
71+
fun stacktrace(): Boolean {
72+
return this == STACKTRACE
73+
}
74+
75+
fun user(): Boolean {
76+
return this == USR
77+
}
4778
}
4879

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

73-
fun crash(tag: String, message: String, e: Exception) {
104+
fun crash(tag: String, message: String, e: Exception?= null) {
74105
log(tag, message, LoggerType.ERROR, e)
75106
}
76107

@@ -94,6 +125,9 @@ object Logger : KoinComponent {
94125
LoggerType.INFO -> if (logLevel <= LoggerType.INFO.id) Log.i(tag, msg)
95126
LoggerType.WARN -> if (logLevel <= LoggerType.WARN.id) Log.w(tag, msg, e)
96127
LoggerType.ERROR -> if (logLevel <= LoggerType.ERROR.id) Log.e(tag, msg, e)
128+
LoggerType.STACKTRACE -> if (logLevel <= LoggerType.ERROR.id) Log.e(tag, msg, e)
129+
LoggerType.USR -> {} // Do nothing
130+
LoggerType.NONE -> {} // Do nothing
97131
}
98132
}
99133
}

app/src/full/java/com/celzero/bravedns/RethinkDnsApplication.kt

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ package com.celzero.bravedns
33
import Logger
44
import Logger.LOG_TAG_SCHEDULER
55
import android.app.Application
6+
import android.content.ComponentCallbacks2
67
import android.content.pm.ApplicationInfo
78
import android.os.StrictMode
89
import com.celzero.bravedns.scheduler.ScheduleManager
910
import com.celzero.bravedns.scheduler.WorkScheduler
11+
import kotlinx.coroutines.CoroutineScope
12+
import kotlinx.coroutines.SupervisorJob
13+
import kotlinx.coroutines.launch
1014
import org.koin.android.ext.android.get
1115
import org.koin.android.ext.koin.androidContext
1216
import org.koin.android.ext.koin.androidLogger
@@ -36,7 +40,7 @@ class RethinkDnsApplication : Application() {
3640
super.onCreate()
3741
DEBUG =
3842
applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE ==
39-
ApplicationInfo.FLAG_DEBUGGABLE
43+
ApplicationInfo.FLAG_DEBUGGABLE
4044

4145
startKoin {
4246
if (DEBUG) androidLogger()
@@ -46,6 +50,12 @@ class RethinkDnsApplication : Application() {
4650

4751
turnOnStrictMode()
4852

53+
CoroutineScope(SupervisorJob()).launch {
54+
scheduleJobs()
55+
}
56+
}
57+
58+
private suspend fun scheduleJobs() {
4959
Logger.d(LOG_TAG_SCHEDULER, "Schedule job")
5060
get<WorkScheduler>().scheduleAppExitInfoCollectionJob()
5161
// database refresh is used in both headless and main project

app/src/full/java/com/celzero/bravedns/adapter/DnsCryptEndpointAdapter.kt

+12-5
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,7 @@ class DnsCryptEndpointAdapter(private val context: Context, private val appConfi
159159
return
160160
}
161161

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

169165
private fun showExplanationOnImageClick(dnsCryptEndpoint: DnsCryptEndpoint) {
@@ -244,6 +240,17 @@ class DnsCryptEndpointAdapter(private val context: Context, private val appConfi
244240
}
245241
}
246242

243+
private fun updateDnsStatus() {
244+
io {
245+
val state = VpnController.getDnsStatus(Backend.Preferred)
246+
val status = UIUtils.getDnsStatusStringRes(state)
247+
uiCtx {
248+
b.dnsCryptEndpointListUrlExplanation.text =
249+
context.getString(status).replaceFirstChar(Char::titlecase)
250+
}
251+
}
252+
}
253+
247254
private fun deleteEndpoint(id: Int) {
248255
io {
249256
appConfig.deleteDnscryptEndpoint(id)

app/src/full/java/com/celzero/bravedns/adapter/DnsCryptRelayEndpointAdapter.kt

+9-5
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,15 @@ class DnsCryptRelayEndpointAdapter(
133133
}
134134

135135
private fun updateSelectedStatus() {
136-
// always use the id as Dnsx.Preffered as it is the primary dns id for now
137-
val state = VpnController.getDnsStatus(Backend.Preferred)
138-
val status = UIUtils.getDnsStatusStringRes(state)
139-
b.dnsCryptEndpointListUrlExplanation.text =
140-
context.getString(status).replaceFirstChar(Char::titlecase)
136+
io {
137+
// always use the id as Dnsx.Preffered as it is the primary dns id for now
138+
val state = VpnController.getDnsStatus(Backend.Preferred)
139+
val status = UIUtils.getDnsStatusStringRes(state)
140+
uiCtx {
141+
b.dnsCryptEndpointListUrlExplanation.text =
142+
context.getString(status).replaceFirstChar(Char::titlecase)
143+
}
144+
}
141145
}
142146

143147
private fun promptUser(endpoint: DnsCryptRelayEndpoint) {

app/src/full/java/com/celzero/bravedns/adapter/DoTEndpointAdapter.kt

+11-4
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,17 @@ class DoTEndpointAdapter(private val context: Context, private val appConfig: Ap
147147
return
148148
}
149149

150-
// always use the id as Dnsx.Preffered as it is the primary dns id for now
151-
val state = VpnController.getDnsStatus(Backend.Preferred)
152-
val status = getDnsStatusStringRes(state)
153-
b.endpointDesc.text = context.getString(status).replaceFirstChar(Char::titlecase)
150+
updateDnsStatus()
151+
}
152+
153+
private fun updateDnsStatus() {
154+
io {
155+
val state = VpnController.getDnsStatus(Backend.Preferred)
156+
val status = getDnsStatusStringRes(state)
157+
uiCtx {
158+
b.endpointDesc.text = context.getString(status).replaceFirstChar(Char::titlecase)
159+
}
160+
}
154161
}
155162

156163
private fun showIcon(endpoint: DoTEndpoint) {

app/src/full/java/com/celzero/bravedns/adapter/DohEndpointAdapter.kt

+20-13
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ class DohEndpointAdapter(private val context: Context, private val appConfig: Ap
6060
newConnection: DoHEndpoint
6161
): Boolean {
6262
return (oldConnection.id == newConnection.id &&
63-
oldConnection.isSelected == newConnection.isSelected)
63+
oldConnection.isSelected == newConnection.isSelected)
6464
}
6565

6666
override fun areContentsTheSame(
6767
oldConnection: DoHEndpoint,
6868
newConnection: DoHEndpoint
6969
): Boolean {
7070
return (oldConnection.id == newConnection.id &&
71-
oldConnection.isSelected != newConnection.isSelected)
71+
oldConnection.isSelected != newConnection.isSelected)
7272
}
7373
}
7474
}
@@ -140,16 +140,25 @@ class DohEndpointAdapter(private val context: Context, private val appConfig: Ap
140140
?.lifecycle
141141
?.currentState
142142
?.isAtLeast(androidx.lifecycle.Lifecycle.State.STARTED) == false ||
143-
bindingAdapterPosition == RecyclerView.NO_POSITION
143+
bindingAdapterPosition == RecyclerView.NO_POSITION
144144
) {
145145
statusCheckJob?.cancel()
146146
return
147147
}
148148

149-
// always use the id as Dnsx.Preffered as it is the primary dns id for now
150-
val state = VpnController.getDnsStatus(Backend.Preferred)
151-
val status = getDnsStatusStringRes(state)
152-
b.endpointDesc.text = context.getString(status).replaceFirstChar(Char::titlecase)
149+
updateDnsStatus()
150+
}
151+
152+
private fun updateDnsStatus() {
153+
io {
154+
// always use the id as Dnsx.Preffered as it is the primary dns id for now
155+
val state = VpnController.getDnsStatus(Backend.Preferred)
156+
val status = getDnsStatusStringRes(state)
157+
uiCtx {
158+
b.endpointDesc.text =
159+
context.getString(status).replaceFirstChar(Char::titlecase)
160+
}
161+
}
153162
}
154163

155164
private fun showIcon(endpoint: DoHEndpoint) {
@@ -198,14 +207,12 @@ class DohEndpointAdapter(private val context: Context, private val appConfig: Ap
198207
builder.setTitle(title)
199208
builder.setMessage(url + "\n\n" + getDnsDesc(message))
200209
builder.setCancelable(true)
201-
builder.setPositiveButton(context.getString(R.string.dns_info_positive)) {
202-
dialogInterface,
203-
_ ->
210+
builder.setPositiveButton(context.getString(R.string.dns_info_positive)) { dialogInterface,
211+
_ ->
204212
dialogInterface.dismiss()
205213
}
206-
builder.setNeutralButton(context.getString(R.string.dns_info_neutral)) {
207-
_: DialogInterface,
208-
_: Int ->
214+
builder.setNeutralButton(context.getString(R.string.dns_info_neutral)) { _: DialogInterface,
215+
_: Int ->
209216
clipboardCopy(context, url, context.getString(R.string.copy_clipboard_label))
210217
Utilities.showToastUiCentered(
211218
context,

app/src/full/java/com/celzero/bravedns/adapter/ODoHEndpointAdapter.kt

+13-4
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,19 @@ class ODoHEndpointAdapter(private val context: Context, private val appConfig: A
138138
return
139139
}
140140

141-
// always use the id as Dnsx.Preffered as it is the primary dns id for now
142-
val state = VpnController.getDnsStatus(Backend.Preferred)
143-
val status = getDnsStatusStringRes(state)
144-
b.endpointDesc.text = context.getString(status).replaceFirstChar(Char::titlecase)
141+
updateDnsStatus()
142+
143+
}
144+
145+
private fun updateDnsStatus() {
146+
io {
147+
// always use the id as Dnsx.Preffered as it is the primary dns id for now
148+
val state = VpnController.getDnsStatus(Backend.Preferred)
149+
val status = getDnsStatusStringRes(state)
150+
uiCtx {
151+
b.endpointDesc.text = context.getString(status).replaceFirstChar(Char::titlecase)
152+
}
153+
}
145154
}
146155

147156
private fun showIcon(endpoint: ODoHEndpoint) {

app/src/full/java/com/celzero/bravedns/adapter/OneWgConfigAdapter.kt

+12-12
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
106106
fun update(config: WgConfigFiles) {
107107
b.interfaceNameText.text = config.name
108108
b.oneWgCheck.isChecked = config.isActive
109-
updateStatus(config)
109+
io {
110+
updateStatus(config)
111+
}
110112
setupClickListeners(config)
111113
if (config.oneWireGuard) {
112114
keepStatusUpdated(config)
@@ -122,7 +124,7 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
122124
}
123125

124126
private fun keepStatusUpdated(config: WgConfigFiles) {
125-
statusCheckJob = ui {
127+
statusCheckJob = io {
126128
while (true) {
127129
updateStatus(config)
128130
delay(ONE_SEC)
@@ -158,7 +160,7 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
158160
}
159161
}
160162

161-
private fun updateStatus(config: WgConfigFiles) {
163+
private suspend fun updateStatus(config: WgConfigFiles) {
162164
// if the view is not active then cancel the job
163165
if (
164166
lifecycleOwner
@@ -181,9 +183,11 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
181183
} else {
182184
false
183185
}
184-
updateStatusUi(config, statusId, stats)
185-
updateProtocolChip(pair)
186-
updateSplitTunnelChip(isSplitTunnel)
186+
uiCtx {
187+
updateStatusUi(config, statusId, stats)
188+
updateProtocolChip(pair)
189+
updateSplitTunnelChip(isSplitTunnel)
190+
}
187191
}
188192

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

366-
private fun ui(f: suspend () -> Unit): Job? {
367-
return lifecycleOwner?.lifecycleScope?.launch(Dispatchers.Main) { f() }
368-
}
369-
370-
private fun io(f: suspend () -> Unit) {
371-
lifecycleOwner?.lifecycleScope?.launch(Dispatchers.IO) { f() }
370+
private fun io(f: suspend () -> Unit): Job? {
371+
return lifecycleOwner?.lifecycleScope?.launch(Dispatchers.IO) { f() }
372372
}
373373
}

0 commit comments

Comments
 (0)