Skip to content

Commit

Permalink
Merge pull request #1301 from hussainmohd-a/v055b
Browse files Browse the repository at this point in the history
V055d
  • Loading branch information
hussainmohd-a authored Apr 1, 2024
2 parents 73f1c0f + 0c9e738 commit 0146817
Show file tree
Hide file tree
Showing 121 changed files with 3,790 additions and 2,259 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ dependencies {
fullImplementation 'com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.9'

// from: https://jitpack.io/#celzero/firestack
download 'com.github.celzero:firestack:21000918a3@aar'
implementation 'com.github.celzero:firestack:21000918a3@aar'
download 'com.github.celzero:firestack:f5a2218ed6@aar'
implementation 'com.github.celzero:firestack:f5a2218ed6@aar'

// Work manager
implementation('androidx.work:work-runtime-ktx:2.9.0') {
Expand Down
4 changes: 4 additions & 0 deletions app/src/full/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32"
Expand Down Expand Up @@ -104,6 +106,8 @@
<activity
android:name=".ui.activity.ConfigureOtherDnsActivity"
android:finishOnTaskLaunch="true" />
<activity android:name=".ui.activity.AppWiseLogsActivity"
android:finishOnTaskLaunch="true" />
<activity
android:name=".ui.NotificationHandlerDialog"
android:excludeFromRecents="true"
Expand Down
192 changes: 96 additions & 96 deletions app/src/full/java/com/celzero/bravedns/adapter/AlertAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,113 +14,113 @@
* limitations under the License.
*//*
package com.celzero.bravedns.adapter
package com.celzero.bravedns.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.celzero.bravedns.database.AlertRegistry
import com.celzero.bravedns.databinding.ListItemAlertRegistryBinding
import com.celzero.bravedns.service.AlertCategory
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.celzero.bravedns.database.AlertRegistry
import com.celzero.bravedns.databinding.ListItemAlertRegistryBinding
import com.celzero.bravedns.service.AlertCategory
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class AlertAdapter(
private val context: Context,
private val alertRegistries: Array<AlertRegistry?>
) : RecyclerView.Adapter<AlertAdapter.AlertRegistryViewHolder>() {
class AlertAdapter(
private val context: Context,
private val alertRegistries: Array<AlertRegistry?>
) : RecyclerView.Adapter<AlertAdapter.AlertRegistryViewHolder>() {
override fun onBindViewHolder(holder: AlertAdapter.AlertRegistryViewHolder, position: Int) {
val alerts: AlertRegistry = alertRegistries[position] ?: return
holder.update(alerts)
}
override fun onBindViewHolder(holder: AlertAdapter.AlertRegistryViewHolder, position: Int) {
val alerts: AlertRegistry = alertRegistries[position] ?: return
holder.update(alerts)
}
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): AlertAdapter.AlertRegistryViewHolder {
val itemBinding =
ListItemAlertRegistryBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return AlertRegistryViewHolder(itemBinding)
}
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): AlertAdapter.AlertRegistryViewHolder {
val itemBinding =
ListItemAlertRegistryBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return AlertRegistryViewHolder(itemBinding)
}
override fun getItemCount(): Int {
return alertRegistries.size
}
override fun getItemCount(): Int {
return alertRegistries.size
}
inner class AlertRegistryViewHolder(private val b: ListItemAlertRegistryBinding) :
RecyclerView.ViewHolder(b.root) {
fun update(alert: AlertRegistry) {
// do not show the alert if the message is empty
if (alert.alertMessage.isEmpty()) {
b.root.visibility = View.GONE
return
}
b.title.text = alert.alertTitle
val message = ""
*/
inner class AlertRegistryViewHolder(private val b: ListItemAlertRegistryBinding) :
RecyclerView.ViewHolder(b.root) {
fun update(alert: AlertRegistry) {
// do not show the alert if the message is empty
if (alert.alertMessage.isEmpty()) {
b.root.visibility = View.GONE
return
}
b.title.text = alert.alertTitle
val message = ""
*/
/*when (AlertCategory.valueOf(alert.alertCategory)) {
AlertCategory.DNS ->
"List of domains blocked in past one hour. Click to <<see more>>..."
AlertCategory.FIREWALL ->
"List of IP addresses blocked in past one hour. Click to <<see more>>..."
AlertCategory.APP ->
"List of apps blocked in past one hour. Click to <<see more>>..."
else -> "Unknown category"
}*//*
AlertCategory.DNS ->
"List of domains blocked in past one hour. Click to <<see more>>..."
AlertCategory.FIREWALL ->
"List of IP addresses blocked in past one hour. Click to <<see more>>..."
AlertCategory.APP ->
"List of apps blocked in past one hour. Click to <<see more>>..."
else -> "Unknown category"
}*//*
b.description.text = message
b.descriptionMore.text = alert.alertMessage
b.priority.text = alert.alertSeverity.lowercase().replaceFirstChar(Char::uppercase)
setupClickListeners(alert)
}
b.description.text = message
b.descriptionMore.text = alert.alertMessage
b.priority.text = alert.alertSeverity.lowercase().replaceFirstChar(Char::uppercase)
setupClickListeners(alert)
}
fun setupClickListeners(alert: AlertRegistry) {
b.description.setOnClickListener {
if (b.descriptionMore.visibility == View.VISIBLE)
b.descriptionMore.visibility = View.GONE
else if (b.descriptionMore.visibility == View.GONE)
b.descriptionMore.visibility = View.VISIBLE
}
fun setupClickListeners(alert: AlertRegistry) {
b.description.setOnClickListener {
if (b.descriptionMore.visibility == View.VISIBLE)
b.descriptionMore.visibility = View.GONE
else if (b.descriptionMore.visibility == View.GONE)
b.descriptionMore.visibility = View.VISIBLE
}
b.descriptionMore.setOnClickListener {
if (b.descriptionMore.visibility == View.VISIBLE)
b.descriptionMore.visibility = View.GONE
else if (b.descriptionMore.visibility == View.GONE)
b.descriptionMore.visibility = View.VISIBLE
}
b.descriptionMore.setOnClickListener {
if (b.descriptionMore.visibility == View.VISIBLE)
b.descriptionMore.visibility = View.GONE
else if (b.descriptionMore.visibility == View.GONE)
b.descriptionMore.visibility = View.VISIBLE
}
b.action.setOnClickListener {
val category = AlertCategory.valueOf(alert.alertCategory)
showActionDialog(category)
}
}
b.action.setOnClickListener {
val category = AlertCategory.valueOf(alert.alertCategory)
showActionDialog(category)
}
}
private fun showActionDialog(category: AlertCategory) {
// show dialog with actions to be taken on the alert
val message = ""
*/
private fun showActionDialog(category: AlertCategory) {
// show dialog with actions to be taken on the alert
val message = ""
*/
/*when (category) {
AlertCategory.DNS ->
"Some actions to be taken on the alert \n\n 1. Allow the connection \n\n 2. Block the connection \n\n 3. Allow all connections from this domain \n\n 4. Block all connections from this domain"
AlertCategory.FIREWALL ->
"Some actions to be taken on the alert \n\n 1. Allow the connection \n\n 2. Block the connection \n\n 3. Allow this connections for all app \n\n 4. Block this connections for all app"
AlertCategory.APP ->
"Some actions to be taken on the alert \n\n 1. Allow the connection \n\n 2. Block the connection \n\n 3. Allow all connections from this app \n\n 4. Block all connections from this app"
else -> "Unknown category"
}*//*
AlertCategory.DNS ->
"Some actions to be taken on the alert \n\n 1. Allow the connection \n\n 2. Block the connection \n\n 3. Allow all connections from this domain \n\n 4. Block all connections from this domain"
AlertCategory.FIREWALL ->
"Some actions to be taken on the alert \n\n 1. Allow the connection \n\n 2. Block the connection \n\n 3. Allow this connections for all app \n\n 4. Block this connections for all app"
AlertCategory.APP ->
"Some actions to be taken on the alert \n\n 1. Allow the connection \n\n 2. Block the connection \n\n 3. Allow all connections from this app \n\n 4. Block all connections from this app"
else -> "Unknown category"
}*//*
MaterialAlertDialogBuilder(context)
.setTitle("Actions")
.setMessage(message)
.setPositiveButton("Okay") { dialog, _ ->
// allow the connection
dialog.dismiss()
}
.create()
.show()
}
}
}
*/
MaterialAlertDialogBuilder(context)
.setTitle("Actions")
.setMessage(message)
.setPositiveButton("Okay") { dialog, _ ->
// allow the connection
dialog.dismiss()
}
.create()
.show()
}
}
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -36,9 +35,6 @@ import com.celzero.bravedns.ui.bottomsheet.AppConnectionBottomSheet
import com.celzero.bravedns.util.Logger
import com.celzero.bravedns.util.UIUtils.fetchColor
import com.celzero.bravedns.util.Utilities.removeBeginningTrailingCommas
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class AppConnectionAdapter(val context: Context, val lifecycleOwner: LifecycleOwner, val uid: Int) :
PagingDataAdapter<AppConnection, AppConnectionAdapter.ConnectionDetailsViewHolder>(
Expand Down Expand Up @@ -106,7 +102,7 @@ class AppConnectionAdapter(val context: Context, val lifecycleOwner: LifecycleOw

private fun openBottomSheet(appConn: AppConnection) {
if (context !is AppCompatActivity) {
Log.wtf(Logger.LOG_TAG_UI, "Error opening the app conn bottom sheet")
Log.w(Logger.LOG_TAG_UI, "Error opening the app conn bottom sheet")
return
}

Expand Down Expand Up @@ -146,30 +142,26 @@ class AppConnectionAdapter(val context: Context, val lifecycleOwner: LifecycleOw
}

private fun updateStatusUi(uid: Int, ipAddress: String) {
io {
val status = IpRulesManager.getMostSpecificRuleMatch(uid, ipAddress)
uiCtx {
when (status) {
IpRulesManager.IpRuleStatus.NONE -> {
b.acdFlag.text = context.getString(R.string.ci_no_rule_initial)
}
IpRulesManager.IpRuleStatus.BLOCK -> {
b.acdFlag.text = context.getString(R.string.ci_blocked_initial)
}
IpRulesManager.IpRuleStatus.BYPASS_UNIVERSAL -> {
b.acdFlag.text = context.getString(R.string.ci_bypass_universal_initial)
}
IpRulesManager.IpRuleStatus.TRUST -> {
b.acdFlag.text = context.getString(R.string.ci_trust_initial)
}
}

// returns the text and background color for the button
val t = getToggleBtnUiParams(status)
b.acdFlag.setTextColor(t.txtColor)
b.acdFlag.backgroundTintList = ColorStateList.valueOf(t.bgColor)
val status = IpRulesManager.getMostSpecificRuleMatch(uid, ipAddress)
when (status) {
IpRulesManager.IpRuleStatus.NONE -> {
b.acdFlag.text = context.getString(R.string.ci_no_rule_initial)
}
IpRulesManager.IpRuleStatus.BLOCK -> {
b.acdFlag.text = context.getString(R.string.ci_blocked_initial)
}
IpRulesManager.IpRuleStatus.BYPASS_UNIVERSAL -> {
b.acdFlag.text = context.getString(R.string.ci_bypass_universal_initial)
}
IpRulesManager.IpRuleStatus.TRUST -> {
b.acdFlag.text = context.getString(R.string.ci_trust_initial)
}
}

// returns the text and background color for the button
val t = getToggleBtnUiParams(status)
b.acdFlag.setTextColor(t.txtColor)
b.acdFlag.backgroundTintList = ColorStateList.valueOf(t.bgColor)
}

private fun getToggleBtnUiParams(id: IpRulesManager.IpRuleStatus): ToggleBtnUi {
Expand Down Expand Up @@ -205,12 +197,4 @@ class AppConnectionAdapter(val context: Context, val lifecycleOwner: LifecycleOw
override fun notifyDataset(position: Int) {
this.notifyItemChanged(position)
}

private suspend fun uiCtx(f: suspend () -> Unit) {
withContext(Dispatchers.Main) { f() }
}

private fun io(f: suspend () -> Unit) {
lifecycleOwner.lifecycleScope.launch(Dispatchers.IO) { f() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ConnectionTrackerAdapter(private val context: Context) :

private fun openBottomSheet(ct: ConnectionTracker) {
if (context !is FragmentActivity) {
Log.wtf(LOG_TAG_UI, "err opening the connection tracker bottomsheet")
Log.w(LOG_TAG_UI, "err opening the connection tracker bottomsheet")
return
}

Expand Down
Loading

0 comments on commit 0146817

Please sign in to comment.