Skip to content

Commit e97c2c5

Browse files
Merge pull request #2484 from hussainmohd-a/main
minor ui improvements
2 parents f3ada87 + 00a9f47 commit e97c2c5

30 files changed

+998
-424
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*/
1616
package com.celzero.bravedns.adapter
1717

18-
import android.R
1918
import android.view.LayoutInflater
2019
import android.view.ViewGroup
2120
import androidx.paging.PagingDataAdapter
2221
import androidx.recyclerview.widget.DiffUtil
2322
import androidx.recyclerview.widget.RecyclerView
23+
import com.celzero.bravedns.R
2424
import com.celzero.bravedns.data.AllowedAppInfo
2525
import com.celzero.bravedns.databinding.ItemAllowedAppBinding
2626

@@ -67,7 +67,7 @@ class BubbleAllowedAppsAdapter(
6767
val icon = packageManager.getApplicationIcon(app.packageName)
6868
binding.allowedAppIcon.setImageDrawable(icon)
6969
} catch (_: Exception) {
70-
binding.allowedAppIcon.setImageResource(R.drawable.sym_def_app_icon)
70+
binding.allowedAppIcon.setImageResource(R.drawable.default_app_icon)
7171
}
7272

7373
binding.allowedRemoveBtn.setOnClickListener {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ class BubbleBlockedAppsAdapter(
9696
if (packageName != "Unknown") {
9797
itemView.context.packageManager.getApplicationIcon(packageName)
9898
} else {
99-
ContextCompat.getDrawable(itemView.context, R.drawable.ic_launcher_foreground)!!
99+
ContextCompat.getDrawable(itemView.context, R.drawable.default_app_icon)!!
100100
}
101101
} catch (_: PackageManager.NameNotFoundException) {
102102
Logger.e(TAG, "App icon not found for $packageName")
103-
ContextCompat.getDrawable(itemView.context, R.drawable.ic_launcher_foreground)!!
103+
ContextCompat.getDrawable(itemView.context, R.drawable.default_app_icon)!!
104104
}
105105
}
106106

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ class CustomDomainAdapter(
638638
}
639639

640640
private fun showButtonsBottomSheet(customDomain: CustomDomain) {
641-
val bottomSheetFragment = CustomDomainRulesBtmSheet(customDomain)
641+
val bottomSheetFragment = CustomDomainRulesBtmSheet.newInstance(customDomain)
642642
bottomSheetFragment.show(fragment.parentFragmentManager, bottomSheetFragment.tag)
643643
}
644644

@@ -654,4 +654,3 @@ class CustomDomainAdapter(
654654
withContext(Dispatchers.Main) { f() }
655655
}
656656
}
657-

app/src/full/java/com/celzero/bravedns/service/WireguardManager.kt

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.celzero.bravedns.data.SsidItem
2525
import com.celzero.bravedns.database.WgConfigFiles
2626
import com.celzero.bravedns.database.WgConfigFilesImmutable
2727
import com.celzero.bravedns.database.WgConfigFilesRepository
28+
import com.celzero.bravedns.service.EncryptionException
2829
import com.celzero.bravedns.service.ProxyManager.ID_NONE
2930
import com.celzero.bravedns.service.ProxyManager.ID_WG_BASE
3031
import com.celzero.bravedns.util.Constants.Companion.WIREGUARD_FOLDER_NAME
@@ -97,8 +98,13 @@ object WireguardManager : KoinComponent {
9798
mappings = CopyOnWriteArraySet(m)
9899
mappings.forEach {
99100
val path = it.configPath
100-
val config =
101+
val config = try {
101102
EncryptedFileManager.readWireguardConfig(applicationContext, path)
103+
} catch (e: EncryptionException) {
104+
// Critical encryption failure - config is unreadable
105+
Logger.e(LOG_TAG_PROXY, "Critical encryption failure for wg config: $path, deleting config", e)
106+
return@forEach
107+
}
102108
if (config == null) {
103109
Logger.e(LOG_TAG_PROXY, "err loading wg config: $path, invalid config")
104110
// TODO: delete the warp config from the wireguard directory, now part of rpn proxy
@@ -1025,7 +1031,13 @@ object WireguardManager : KoinComponent {
10251031
// write the contents to the encrypted file
10261032
val parsedCfg = cfg.toWgQuickString()
10271033
val fileName = getConfigFileName(cfg.getId())
1028-
EncryptedFileManager.writeWireguardConfig(applicationContext, parsedCfg, fileName)
1034+
try {
1035+
EncryptedFileManager.writeWireguardConfig(applicationContext, parsedCfg, fileName)
1036+
} catch (e: EncryptionException) {
1037+
// Critical encryption failure - cannot save config
1038+
Logger.e(LOG_TAG_PROXY, "Critical encryption failure writing wg config: ${cfg.getId()}", e)
1039+
throw e // Bubble up to caller
1040+
}
10291041
val path = getConfigFilePath() + fileName
10301042
Logger.i(LOG_TAG_PROXY, "writing wg config to file: $path")
10311043
val file = db.isConfigAdded(cfg.getId())
@@ -1171,17 +1183,38 @@ object WireguardManager : KoinComponent {
11711183
// read the contents of the file and write it to the EncryptedFileManager
11721184
val bytes = file.readBytes()
11731185
val encryptFile = File(c.configPath)
1174-
if (!encryptFile.exists()) {
1175-
encryptFile.parentFile?.mkdirs()
1176-
encryptFile.createNewFile()
1186+
val parentDir = encryptFile.parentFile
1187+
if (parentDir == null) {
1188+
Logger.e(LOG_TAG_PROXY, "wg restore failed, invalid path: ${c.configPath}")
1189+
db.deleteConfig(c.id)
1190+
return@forEach
11771191
}
1178-
val res = EncryptedFileManager.write(applicationContext, bytes, encryptFile)
1179-
if (res) {
1180-
Logger.i(LOG_TAG_PROXY, "restored wg config: ${c.id}, ${c.name}")
1181-
} else {
1182-
Logger.e(LOG_TAG_PROXY, "err restoring wg config: ${c.id}, ${c.name}")
1183-
// in case of error, delete the entry from the database
1192+
if (!parentDir.exists() && !parentDir.mkdirs()) {
1193+
Logger.e(LOG_TAG_PROXY, "wg restore failed, unable to create dir: ${parentDir.absolutePath}")
1194+
db.deleteConfig(c.id)
1195+
return@forEach
1196+
}
1197+
val created = runCatching {
1198+
if (!encryptFile.exists()) {
1199+
encryptFile.createNewFile()
1200+
} else {
1201+
true
1202+
}
1203+
}.getOrElse { ex ->
1204+
Logger.w(LOG_TAG_PROXY, "wg restore failed, unable to create file: ${encryptFile.absolutePath}, err: ${ex.message}")
11841205
db.deleteConfig(c.id)
1206+
return@forEach
1207+
}
1208+
if (!created) {
1209+
Logger.e(LOG_TAG_PROXY, "wg restore failed, createNewFile returned false: ${encryptFile.absolutePath}")
1210+
db.deleteConfig(c.id)
1211+
return@forEach
1212+
}
1213+
try {
1214+
EncryptedFileManager.write(applicationContext, bytes, encryptFile)
1215+
Logger.i(LOG_TAG_PROXY, "restored wg config: ${c.id}, ${c.name}")
1216+
} catch (e: EncryptionException) {
1217+
Logger.e(LOG_TAG_PROXY, "Critical encryption failure restoring wg config: ${c.id}, ${c.name}", e)
11851218
}
11861219
}
11871220

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.os.Bundle
2121
import android.view.View
2222
import androidx.activity.addCallback
2323
import androidx.appcompat.app.AppCompatActivity
24+
import androidx.core.view.WindowInsetsControllerCompat
2425
import androidx.lifecycle.lifecycleScope
2526
import androidx.paging.Pager
2627
import androidx.paging.PagingConfig
@@ -42,6 +43,8 @@ import com.celzero.bravedns.service.FirewallManager
4243
import com.celzero.bravedns.service.PersistentState
4344
import com.celzero.bravedns.service.VpnController
4445
import com.celzero.bravedns.util.Themes.Companion.getCurrentTheme
46+
import com.celzero.bravedns.util.Utilities.isAtleastQ
47+
import com.celzero.bravedns.util.handleFrostEffectIfNeeded
4548
import kotlinx.coroutines.CancellationException
4649
import kotlinx.coroutines.Dispatchers
4750
import kotlinx.coroutines.launch

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import by.kirich1409.viewbindingdelegate.viewBinding
3434
import com.celzero.bravedns.R
3535
import com.celzero.bravedns.databinding.ActivityCheckoutProxyBinding
3636
import com.celzero.bravedns.service.EncryptedFileManager
37+
import com.celzero.bravedns.service.EncryptionException
3738
import com.celzero.bravedns.service.PersistentState
3839
import com.celzero.bravedns.service.TcpProxyHelper
3940
import com.celzero.bravedns.util.Themes
@@ -207,9 +208,14 @@ class CheckoutActivity : AppCompatActivity(R.layout.activity_checkout_proxy) {
207208
File.separator +
208209
TcpProxyHelper.PIP_KEY_FILE_NAME
209210
)
210-
EncryptedFileManager.writeTcpConfig(this, keyState.v().tos() ?: "", TcpProxyHelper.PIP_KEY_FILE_NAME)
211-
val content = EncryptedFileManager.read(this, path)
212-
Logger.d(Logger.LOG_TAG_PROXY, "Content: $content")
211+
try {
212+
EncryptedFileManager.writeTcpConfig(this, keyState.v().tos() ?: "", TcpProxyHelper.PIP_KEY_FILE_NAME)
213+
val content = EncryptedFileManager.read(this, path)
214+
Logger.d(Logger.LOG_TAG_PROXY, "Content: $content")
215+
} catch (e: EncryptionException) {
216+
Logger.e(Logger.LOG_TAG_PROXY, "Critical encryption failure in handleKeys", e)
217+
// EncryptionException already logged to event system by EncryptedFileManager
218+
}
213219
} catch (e: Exception) {
214220
Logger.e(Logger.LOG_TAG_PROXY, "err in handleKeys: ${e.message}", e)
215221
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ class ConsoleLogActivity : AppCompatActivity(R.layout.activity_console_log), and
145145
}
146146
}
147147
b.searchView.setOnQueryTextListener(this)
148+
val logLevel = Logger.uiLogLevel.toInt()
149+
if (logLevel <= Logger.LoggerLevel.ERROR.id) {
150+
showFilterDialog()
151+
}
148152
}
149153

150154
var recyclerAdapter: ConsoleLogAdapter? = null

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ import com.celzero.bravedns.service.PersistentState
3838
import com.celzero.bravedns.util.Themes
3939
import com.celzero.bravedns.util.Utilities
4040
import com.celzero.bravedns.util.Utilities.isAtleastO
41+
import com.celzero.bravedns.util.Utilities.isAtleastQ
4142
import com.celzero.bravedns.util.Utilities.showToastUiCentered
4243
import com.celzero.bravedns.util.useTransparentNoDimBackground
44+
import com.google.android.material.bottomsheet.BottomSheetBehavior
45+
import com.google.android.material.bottomsheet.BottomSheetDialog
4346
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
4447
import kotlinx.coroutines.Dispatchers
4548
import kotlinx.coroutines.launch
@@ -91,7 +94,22 @@ class BugReportFilesBottomSheet : BottomSheetDialogFragment() {
9194

9295
override fun onStart() {
9396
super.onStart()
94-
dialog?.useTransparentNoDimBackground()
97+
dialog?.window?.let { window ->
98+
if (isAtleastQ()) {
99+
val controller = WindowInsetsControllerCompat(window, window.decorView)
100+
controller.isAppearanceLightNavigationBars = false
101+
window.isNavigationBarContrastEnforced = false
102+
}
103+
}
104+
dialog?.let {
105+
val bottomSheet = it.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
106+
bottomSheet?.layoutParams?.height = ViewGroup.LayoutParams.MATCH_PARENT
107+
}
108+
(dialog as? BottomSheetDialog)?.behavior?.apply {
109+
skipCollapsed = true
110+
state = BottomSheetBehavior.STATE_EXPANDED
111+
isDraggable = true
112+
}
95113
}
96114

97115
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -572,4 +590,3 @@ class BugReportFilesBottomSheet : BottomSheetDialogFragment() {
572590
TEXT
573591
}
574592
}
575-

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import kotlinx.coroutines.launch
4444
import kotlinx.coroutines.withContext
4545
import org.koin.android.ext.android.inject
4646

47-
class CustomDomainRulesBtmSheet(private var cd: CustomDomain) :
47+
class CustomDomainRulesBtmSheet :
4848
BottomSheetDialogFragment(), ProxyCountriesBtmSheet.CountriesDismissListener, WireguardListBtmSheet.WireguardDismissListener {
4949
private var _binding: BottomSheetCustomDomainsBinding? = null
5050

@@ -55,6 +55,8 @@ class CustomDomainRulesBtmSheet(private var cd: CustomDomain) :
5555
private val persistentState by inject<PersistentState>()
5656
private val eventLogger by inject<EventLogger>()
5757

58+
private lateinit var cd: CustomDomain
59+
5860
override fun getTheme(): Int =
5961
getBottomsheetCurrentTheme(isDarkThemeOn(), persistentState.theme)
6062

@@ -65,6 +67,15 @@ class CustomDomainRulesBtmSheet(private var cd: CustomDomain) :
6567

6668
companion object {
6769
private const val TAG = "CDRBtmSht"
70+
private const val ARG_CUSTOM_DOMAIN = "custom_domain"
71+
72+
fun newInstance(customDomain: CustomDomain): CustomDomainRulesBtmSheet {
73+
val fragment = CustomDomainRulesBtmSheet()
74+
val args = Bundle()
75+
args.putSerializable(ARG_CUSTOM_DOMAIN, customDomain)
76+
fragment.arguments = args
77+
return fragment
78+
}
6879
}
6980

7081
override fun onCreateView(
@@ -88,6 +99,15 @@ class CustomDomainRulesBtmSheet(private var cd: CustomDomain) :
8899

89100
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
90101
super.onViewCreated(view, savedInstanceState)
102+
103+
// Retrieve CustomDomain from arguments
104+
@Suppress("DEPRECATION")
105+
cd = arguments?.getSerializable(ARG_CUSTOM_DOMAIN) as? CustomDomain ?: run {
106+
Logger.e(LOG_TAG_UI, "$TAG CustomDomain not found in arguments, dismissing")
107+
dismiss()
108+
return
109+
}
110+
91111
dialog?.window?.let { window ->
92112
if (isAtleastQ()) {
93113
val controller = WindowInsetsControllerCompat(window, window.decorView)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import kotlinx.coroutines.launch
4545
import kotlinx.coroutines.withContext
4646
import org.koin.android.ext.android.inject
4747

48-
class CustomIpRulesBtmSheet() :
48+
class CustomIpRulesBtmSheet :
4949
BottomSheetDialogFragment(), ProxyCountriesBtmSheet.CountriesDismissListener, WireguardListBtmSheet.WireguardDismissListener {
5050
private var _binding: BottomSheetCustomIpsBinding? = null
5151

0 commit comments

Comments
 (0)