Skip to content

Commit 7bd0fbb

Browse files
Merge pull request #1459 from hussainmohd-a/v055k
V055k
2 parents c663833 + f73100e commit 7bd0fbb

25 files changed

+368
-126
lines changed

app/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ dependencies {
250250
fullImplementation 'com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.9'
251251

252252
// from: https://jitpack.io/#celzero/firestack
253-
download 'com.github.celzero:firestack:d92f398622@aar'
254-
implementation 'com.github.celzero:firestack:d92f398622@aar'
253+
download 'com.github.celzero:firestack:177d6a51d8@aar'
254+
implementation 'com.github.celzero:firestack:177d6a51d8@aar'
255255

256256
// Work manager
257257
implementation('androidx.work:work-runtime-ktx:2.9.0') {
@@ -289,6 +289,8 @@ dependencies {
289289
// barcode scanner for wireguard
290290
fullImplementation 'com.journeyapps:zxing-android-embedded:4.3.0'
291291

292+
// only using firebase crashlytics experimentally for stability tracking, only in play variant
293+
// not in fdroid or website
292294
playImplementation 'com.google.firebase:firebase-crashlytics:19.0.0'
293295
playImplementation 'com.google.firebase:firebase-crashlytics-ndk:19.0.0'
294296
}

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
5959
}
6060

6161
companion object {
62-
private const val ONE_SEC = 1000L
62+
private const val ONE_SEC = 1500L
6363

6464
private val DIFF_CALLBACK =
6565
object : DiffUtil.ItemCallback<WgConfigFiles>() {
@@ -192,7 +192,7 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
192192
b.oneWgCheck.isChecked = true
193193
b.interfaceAppsCount.visibility = View.VISIBLE
194194
b.interfaceAppsCount.text = context.getString(R.string.one_wg_apps_added)
195-
val status: String
195+
var status: String
196196
val handShakeTime = getHandshakeTime(stats)
197197
if (statusId != null) {
198198
var resId = UIUtils.getProxyStatusStringRes(statusId)
@@ -206,8 +206,6 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
206206
b.interfaceDetailCard.strokeColor =
207207
fetchColor(context, R.attr.accentGood)
208208
}
209-
// cancel the job, as the status is connected
210-
statusCheckJob?.cancel()
211209
} else if (statusId == Backend.TUP || statusId == Backend.TZZ) {
212210
b.interfaceDetailCard.strokeColor =
213211
fetchColor(context, R.attr.chipTextNeutral)
@@ -225,6 +223,20 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
225223
handShakeTime
226224
)
227225
}
226+
227+
if ((statusId == Backend.TZZ || statusId == Backend.TNT) && stats != null) {
228+
// for idle state, if lastOk is less than 30 sec, then show as connected
229+
if (
230+
stats.lastOK != 0L &&
231+
System.currentTimeMillis() - stats.lastOK <
232+
30 * DateUtils.SECOND_IN_MILLIS
233+
) {
234+
status =
235+
context
236+
.getString(R.string.dns_connected)
237+
.replaceFirstChar(Char::titlecase)
238+
}
239+
}
228240
} else {
229241
b.interfaceDetailCard.strokeColor = fetchColor(context, R.attr.chipTextNegative)
230242
b.interfaceDetailCard.strokeWidth = 2
@@ -328,10 +340,12 @@ class OneWgConfigAdapter(private val context: Context, private val listener: Dns
328340
}
329341
} else {
330342
config.oneWireGuard = false
331-
b.oneWgCheck.isChecked = false
332343
WireguardManager.updateOneWireGuardConfig(config.id, owg = false)
333344
WireguardManager.disableConfig(config.toImmutable())
334-
uiCtx { listener.onDnsStatusChanged() }
345+
uiCtx {
346+
b.oneWgCheck.isChecked = false
347+
listener.onDnsStatusChanged()
348+
}
335349
}
336350
}
337351
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class WgConfigAdapter(private val context: Context) :
5353
private var lifecycleOwner: LifecycleOwner? = null
5454

5555
companion object {
56-
private const val ONE_SEC_MS = 1000L
56+
private const val ONE_SEC_MS = 1500L
5757
private val DIFF_CALLBACK =
5858
object : DiffUtil.ItemCallback<WgConfigFiles>() {
5959

@@ -280,7 +280,7 @@ class WgConfigAdapter(private val context: Context) :
280280
b.interfaceDetailCard.strokeWidth = 2
281281
b.interfaceStatus.visibility = View.VISIBLE
282282
b.interfaceConfigStatus.visibility = View.VISIBLE
283-
val status: String
283+
var status: String
284284
b.interfaceActiveLayout.visibility = View.VISIBLE
285285
val time = getUpTime(stats)
286286
val rxtx = getRxTx(stats)
@@ -311,7 +311,6 @@ class WgConfigAdapter(private val context: Context) :
311311
b.interfaceDetailCard.strokeColor =
312312
UIUtils.fetchColor(context, R.attr.accentGood)
313313
}
314-
cancelJobIfAny(config.id)
315314
} else if (
316315
statusId == Backend.TUP ||
317316
statusId == Backend.TZZ ||
@@ -333,6 +332,19 @@ class WgConfigAdapter(private val context: Context) :
333332
handShakeTime
334333
)
335334
}
335+
if ((statusId == Backend.TZZ || statusId == Backend.TNT) && stats != null) {
336+
// for idle state, if lastOk is less than 30 sec, then show as connected
337+
if (
338+
stats.lastOK != 0L &&
339+
System.currentTimeMillis() - stats.lastOK <
340+
30 * DateUtils.SECOND_IN_MILLIS
341+
) {
342+
status =
343+
context
344+
.getString(R.string.dns_connected)
345+
.replaceFirstChar(Char::titlecase)
346+
}
347+
}
336348
} else {
337349
b.interfaceDetailCard.strokeColor =
338350
UIUtils.fetchColor(context, R.attr.accentBad)

app/src/full/java/com/celzero/bravedns/customdownloader/LocalBlocklistCoordinator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class LocalBlocklistCoordinator(val context: Context, workerParams: WorkerParame
304304
val elapsedMs = SystemClock.elapsedRealtime() - startMs
305305
downloadedMB += bytesToMB(bytesRead)
306306
val progress =
307-
if (contentLength == Long.MAX_VALUE) 0
307+
if (contentLength == Long.MAX_VALUE || expectedMB == 0.0) 0
308308
else (downloadedMB * 100 / expectedMB).toInt()
309309
if (elapsedMs >= progressJumpsMs) {
310310
updateProgress(context, progress)

app/src/full/java/com/celzero/bravedns/ui/activity/AppInfoActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class AppInfoActivity : AppCompatActivity(R.layout.activity_app_details) {
105105
}
106106

107107
private fun init() {
108+
val rethinkPkgName = this.packageName
108109
io {
109110
val appInfo = FirewallManager.getAppInfoByUid(uid)
110111
// case: app is uninstalled but still available in RethinkDNS database
@@ -127,7 +128,7 @@ class AppInfoActivity : AppCompatActivity(R.layout.activity_app_details) {
127128
)
128129

129130
// do not show the firewall status if the app is Rethink
130-
if (appInfo.packageName == this.packageName) {
131+
if (appInfo.packageName == rethinkPkgName) {
131132
b.aadFirewallStatus.visibility = View.GONE
132133
hideFirewallStatusUi()
133134
hideDomainBlockUi()

app/src/full/java/com/celzero/bravedns/ui/activity/MiscSettingsActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ class MiscSettingsActivity : AppCompatActivity(R.layout.activity_misc_settings)
383383
}
384384

385385
private fun invokeImportExport() {
386+
if (this.isFinishing || this.isDestroyed) {
387+
Logger.w(LOG_TAG_UI, "err opening bkup btmsheet, activity is destroyed")
388+
return
389+
}
390+
386391
val bottomSheetFragment = BackupRestoreBottomSheet()
387392
bottomSheetFragment.show(this.supportFragmentManager, bottomSheetFragment.tag)
388393
}

app/src/full/java/com/celzero/bravedns/ui/bottomsheet/AppIpRulesBottomSheet.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ import com.celzero.bravedns.R
2929
import com.celzero.bravedns.adapter.AppWiseIpsAdapter
3030
import com.celzero.bravedns.adapter.DomainRulesBtmSheetAdapter
3131
import com.celzero.bravedns.databinding.BottomSheetAppConnectionsBinding
32+
import com.celzero.bravedns.service.FirewallManager
3233
import com.celzero.bravedns.service.IpRulesManager
3334
import com.celzero.bravedns.service.PersistentState
3435
import com.celzero.bravedns.util.Constants.Companion.INVALID_UID
3536
import com.celzero.bravedns.util.CustomLinearLayoutManager
3637
import com.celzero.bravedns.util.Themes.Companion.getBottomsheetCurrentTheme
3738
import com.celzero.bravedns.util.UIUtils.updateHtmlEncodedText
39+
import com.celzero.bravedns.util.Utilities
3840
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
3941
import kotlinx.coroutines.Dispatchers
4042
import kotlinx.coroutines.launch
@@ -115,6 +117,8 @@ class AppIpRulesBottomSheet : BottomSheetDialogFragment() {
115117
this.dismiss()
116118
return
117119
}
120+
121+
updateAppDetails()
118122
b.bsacIpAddressTv.text = ipAddress
119123

120124
b.bsacIpRuleTxt.text = updateHtmlEncodedText(getString(R.string.bsct_block_ip))
@@ -123,6 +127,46 @@ class AppIpRulesBottomSheet : BottomSheetDialogFragment() {
123127
setupRecycler()
124128
}
125129

130+
private fun updateAppDetails() {
131+
if (uid == -1) return
132+
133+
io {
134+
val appNames = FirewallManager.getAppNamesByUid(uid)
135+
if (appNames.isEmpty()) {
136+
uiCtx { handleNonApp() }
137+
return@io
138+
}
139+
val pkgName = FirewallManager.getPackageNameByAppName(appNames[0])
140+
141+
val appCount = appNames.count()
142+
uiCtx {
143+
if (appCount >= 1) {
144+
b.bsacAppName.text =
145+
if (appCount >= 2) {
146+
getString(
147+
R.string.ctbs_app_other_apps,
148+
appNames[0],
149+
appCount.minus(1).toString()
150+
)
151+
} else {
152+
appNames[0]
153+
}
154+
if (pkgName == null) return@uiCtx
155+
b.bsacAppIcon.setImageDrawable(Utilities.getIcon(requireContext(), pkgName))
156+
} else {
157+
// apps which are not available in cache are treated as non app.
158+
// TODO: check packageManager#getApplicationInfo() for appInfo
159+
handleNonApp()
160+
}
161+
}
162+
}
163+
}
164+
165+
private fun handleNonApp() {
166+
b.bsacAppName.visibility = View.GONE
167+
b.bsacAppIcon.visibility = View.GONE
168+
}
169+
126170
private fun setupRecycler() {
127171
if (domains.isEmpty()) {
128172
b.bsacDomainLl.visibility = View.GONE

app/src/full/java/com/celzero/bravedns/ui/bottomsheet/BackupRestoreBottomSheet.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ import com.celzero.bravedns.util.Utilities
5858
import com.celzero.bravedns.util.Utilities.delay
5959
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
6060
import com.google.android.material.dialog.MaterialAlertDialogBuilder
61-
import org.koin.android.ext.android.inject
6261
import java.text.SimpleDateFormat
6362
import java.util.Date
6463
import java.util.Locale
6564
import java.util.concurrent.TimeUnit
65+
import org.koin.android.ext.android.inject
6666

6767
class BackupRestoreBottomSheet : BottomSheetDialogFragment() {
6868
private var _binding: ActivityBackupRestoreBinding? = null
@@ -204,13 +204,22 @@ class BackupRestoreBottomSheet : BottomSheetDialogFragment() {
204204
}
205205

206206
private fun restore() {
207-
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
208-
intent.addCategory(Intent.CATEGORY_OPENABLE)
209-
intent.type = "*/*"
210-
val mimeTypes = arrayOf(INTENT_TYPE_OCTET, INTENT_TYPE_XZIP)
211-
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
212-
213-
restoreActivityResult.launch(intent)
207+
try {
208+
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
209+
intent.addCategory(Intent.CATEGORY_OPENABLE)
210+
intent.type = "*/*"
211+
val mimeTypes = arrayOf(INTENT_TYPE_OCTET, INTENT_TYPE_XZIP)
212+
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
213+
214+
restoreActivityResult.launch(intent)
215+
} catch (e: Exception) {
216+
Logger.e(LOG_TAG_BACKUP_RESTORE, "err opening file picker: ${e.message}")
217+
Utilities.showToastUiCentered(
218+
requireContext(),
219+
getString(R.string.blocklist_update_check_failure),
220+
Toast.LENGTH_SHORT
221+
)
222+
}
214223
}
215224

216225
private fun result() {

app/src/full/java/com/celzero/bravedns/ui/fragment/HomeScreenFragment.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,16 @@ class HomeScreenFragment : Fragment(R.layout.fragment_home_screen) {
11841184
builder.setMessage(R.string.hsf_vpn_dialog_message)
11851185
builder.setCancelable(false)
11861186
builder.setPositiveButton(R.string.lbl_proceed) { _, _ ->
1187-
startForResult.launch(prepareVpnIntent)
1187+
try {
1188+
startForResult.launch(prepareVpnIntent)
1189+
} catch (e: ActivityNotFoundException) {
1190+
Logger.e(LOG_TAG_VPN, "Activity not found to start VPN service", e)
1191+
showToastUiCentered(
1192+
requireContext(),
1193+
getString(R.string.hsf_vpn_prepare_failure),
1194+
Toast.LENGTH_LONG
1195+
)
1196+
}
11881197
}
11891198

11901199
builder.setNegativeButton(R.string.lbl_cancel) { _, _ ->

app/src/full/java/com/celzero/bravedns/ui/fragment/SummaryStatisticsFragment.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ class SummaryStatisticsFragment : Fragment(R.layout.fragment_summary_statistics)
172172
}
173173

174174
private fun calculatePercentage(value: Long, maxValue: Long): Int {
175+
if (maxValue == 0L) return 0
176+
175177
return (value * 100 / maxValue).toInt()
176178
}
177179

0 commit comments

Comments
 (0)