Skip to content

Commit

Permalink
Merge pull request #1342 from hussainmohd-a/v055e_rel
Browse files Browse the repository at this point in the history
V055e release
  • Loading branch information
hussainmohd-a authored Apr 6, 2024
2 parents 9aa085f + 6214c3b commit 21fa180
Show file tree
Hide file tree
Showing 217 changed files with 3,124 additions and 2,122 deletions.
7 changes: 4 additions & 3 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:f5a2218ed6@aar'
implementation 'com.github.celzero:firestack:f5a2218ed6@aar'
download 'com.github.celzero:firestack:a94a7e78a6@aar'
implementation 'com.github.celzero:firestack:a94a7e78a6@aar'

// Work manager
implementation('androidx.work:work-runtime-ktx:2.9.0') {
Expand All @@ -275,7 +275,8 @@ dependencies {

fullImplementation 'androidx.biometric:biometric:1.1.0'

playImplementation 'com.google.android.play:core:1.10.3' // for new version updater
playImplementation 'com.google.android.play:app-update:2.1.0'
playImplementation 'com.google.android.play:app-update-ktx:2.1.0'

// for encrypting wireguard configuration files
implementation("androidx.security:security-crypto:1.1.0-alpha06")
Expand Down
20 changes: 13 additions & 7 deletions app/src/full/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
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.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32"
Expand Down Expand Up @@ -106,7 +107,11 @@
<activity
android:name=".ui.activity.ConfigureOtherDnsActivity"
android:finishOnTaskLaunch="true" />
<activity android:name=".ui.activity.AppWiseLogsActivity"
<activity
android:name=".ui.activity.AppWiseIpLogsActivity"
android:finishOnTaskLaunch="true" />
<activity
android:name=".ui.activity.AppWiseDomainLogsActivity"
android:finishOnTaskLaunch="true" />
<activity
android:name=".ui.NotificationHandlerDialog"
Expand All @@ -120,14 +125,14 @@
tools:replace="screenOrientation" />
<activity
android:name=".ui.activity.AlertsActivity"
android:finishOnTaskLaunch="true" />
android:finishOnTaskLaunch="true" />

<receiver
android:name=".receiver.BraveAutoStartReceiver"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
android:directBootAware="false"
android:label="@string/app_name">
android:exported="true"
android:label="@string/app_name"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter android:priority="999">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
Expand All @@ -136,6 +141,7 @@
</receiver>
<receiver
android:name=".receiver.NotificationActionReceiver"
android:exported="false"
android:label="@string/app_name" />

<service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/*
* Copyright 2021 RethinkDNS and its authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.celzero.bravedns.adapter

import android.content.Context
import android.content.res.ColorStateList
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LifecycleOwner
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.celzero.bravedns.R
import com.celzero.bravedns.data.AppConnection
import com.celzero.bravedns.databinding.ListItemAppDomainDetailsBinding
import com.celzero.bravedns.service.DomainRulesManager
import com.celzero.bravedns.ui.bottomsheet.AppDomainRulesBottomSheet
import com.celzero.bravedns.util.Logger
import com.celzero.bravedns.util.UIUtils.fetchColor
import com.celzero.bravedns.util.Utilities.removeBeginningTrailingCommas

class AppWiseDomainsAdapter(
val context: Context,
val lifecycleOwner: LifecycleOwner,
val uid: Int
) :
PagingDataAdapter<AppConnection, AppWiseDomainsAdapter.ConnectionDetailsViewHolder>(
DIFF_CALLBACK
),
AppDomainRulesBottomSheet.OnBottomSheetDialogFragmentDismiss {

companion object {
private val DIFF_CALLBACK =
object : DiffUtil.ItemCallback<AppConnection>() {

override fun areItemsTheSame(
oldConnection: AppConnection,
newConnection: AppConnection
) = oldConnection == newConnection

override fun areContentsTheSame(
oldConnection: AppConnection,
newConnection: AppConnection
) = oldConnection == newConnection
}
}

private lateinit var adapter: AppWiseDomainsAdapter

// ui component to update/toggle the buttons
data class ToggleBtnUi(val txtColor: Int, val bgColor: Int)

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): AppWiseDomainsAdapter.ConnectionDetailsViewHolder {
val itemBinding =
ListItemAppDomainDetailsBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
adapter = this
return ConnectionDetailsViewHolder(itemBinding)
}

override fun onBindViewHolder(
holder: AppWiseDomainsAdapter.ConnectionDetailsViewHolder,
position: Int
) {
val appConnection: AppConnection = getItem(position) ?: return
// updates the app-wise connections from network log to AppInfo screen
holder.update(appConnection)
}

inner class ConnectionDetailsViewHolder(private val b: ListItemAppDomainDetailsBinding) :
RecyclerView.ViewHolder(b.root) {
fun update(conn: AppConnection) {
displayTransactionDetails(conn)
setupClickListeners(conn)
}

private fun displayTransactionDetails(appConnection: AppConnection) {
b.acdCount.text = appConnection.count.toString()
b.acdDomain.text = appConnection.appOrDnsName
if (appConnection.ipAddress.isNotEmpty()) {
b.acdIpAddress.visibility = View.VISIBLE
b.acdIpAddress.text = beautifyIpString(appConnection.ipAddress)
} else {
b.acdIpAddress.visibility = View.GONE
}
updateStatusUi(appConnection.uid, appConnection.appOrDnsName)
}

private fun setupClickListeners(appConn: AppConnection) {
b.acdContainer.setOnClickListener {
// open bottom sheet to apply domain/ip rules
openBottomSheet(appConn)
}
}

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

val bottomSheetFragment = AppDomainRulesBottomSheet()
// Fix: free-form window crash
// all BottomSheetDialogFragment classes created must have a public, no-arg constructor.
// the best practice is to simply never define any constructors at all.
// so sending the data using Bundles
val bundle = Bundle()
bundle.putInt(AppDomainRulesBottomSheet.UID, uid)
bundle.putString(AppDomainRulesBottomSheet.DOMAIN, appConn.appOrDnsName)
bottomSheetFragment.arguments = bundle
bottomSheetFragment.dismissListener(adapter, absoluteAdapterPosition)
bottomSheetFragment.show(context.supportFragmentManager, bottomSheetFragment.tag)
}

private fun beautifyIpString(d: String): String {
// replace two commas in the string to one
// add space after all the commas
return removeBeginningTrailingCommas(d).replace(",,", ",").replace(",", ", ")
}

private fun updateStatusUi(uid: Int, domain: String?) {
if (domain == null) {
b.acdFlag.text = context.getString(R.string.ci_no_rule_initial)
return
}

val status = DomainRulesManager.getDomainRule(domain, uid)
when (status) {
DomainRulesManager.Status.NONE -> {
b.acdFlag.text = context.getString(R.string.ci_no_rule_initial)
}
DomainRulesManager.Status.BLOCK -> {
b.acdFlag.text = context.getString(R.string.ci_blocked_initial)
}
DomainRulesManager.Status.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: DomainRulesManager.Status): ToggleBtnUi {
return when (id) {
DomainRulesManager.Status.NONE -> {
ToggleBtnUi(
fetchColor(context, R.attr.chipTextNeutral),
fetchColor(context, R.attr.chipBgColorNeutral)
)
}
DomainRulesManager.Status.BLOCK -> {
ToggleBtnUi(
fetchColor(context, R.attr.chipTextNegative),
fetchColor(context, R.attr.chipBgColorNegative)
)
}
DomainRulesManager.Status.TRUST -> {
ToggleBtnUi(
fetchColor(context, R.attr.chipTextPositive),
fetchColor(context, R.attr.chipBgColorPositive)
)
}
}
}
}

override fun notifyDataset(position: Int) {
this.notifyItemChanged(position)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.celzero.bravedns.R
import com.celzero.bravedns.data.AppConnection
import com.celzero.bravedns.databinding.ListItemAppConnDetailsBinding
import com.celzero.bravedns.databinding.ListItemAppIpDetailsBinding
import com.celzero.bravedns.service.IpRulesManager
import com.celzero.bravedns.ui.bottomsheet.AppConnectionBottomSheet
import com.celzero.bravedns.ui.bottomsheet.AppIpRulesBottomSheet
import com.celzero.bravedns.util.Logger
import com.celzero.bravedns.util.UIUtils.fetchColor
import com.celzero.bravedns.util.Utilities.removeBeginningTrailingCommas

class AppConnectionAdapter(val context: Context, val lifecycleOwner: LifecycleOwner, val uid: Int) :
PagingDataAdapter<AppConnection, AppConnectionAdapter.ConnectionDetailsViewHolder>(
DIFF_CALLBACK
),
AppConnectionBottomSheet.OnBottomSheetDialogFragmentDismiss {
class AppWiseIpsAdapter(val context: Context, val lifecycleOwner: LifecycleOwner, val uid: Int) :
PagingDataAdapter<AppConnection, AppWiseIpsAdapter.ConnectionDetailsViewHolder>(DIFF_CALLBACK),
AppIpRulesBottomSheet.OnBottomSheetDialogFragmentDismiss {

companion object {
private val DIFF_CALLBACK =
Expand All @@ -58,35 +56,31 @@ class AppConnectionAdapter(val context: Context, val lifecycleOwner: LifecycleOw
}
}

private lateinit var adapter: AppConnectionAdapter
private lateinit var adapter: AppWiseIpsAdapter

// ui component to update/toggle the buttons
data class ToggleBtnUi(val txtColor: Int, val bgColor: Int)

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): AppConnectionAdapter.ConnectionDetailsViewHolder {
): AppWiseIpsAdapter.ConnectionDetailsViewHolder {
val itemBinding =
ListItemAppConnDetailsBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
ListItemAppIpDetailsBinding.inflate(LayoutInflater.from(parent.context), parent, false)
adapter = this
return ConnectionDetailsViewHolder(itemBinding)
}

override fun onBindViewHolder(
holder: AppConnectionAdapter.ConnectionDetailsViewHolder,
holder: AppWiseIpsAdapter.ConnectionDetailsViewHolder,
position: Int
) {
val appConnection: AppConnection = getItem(position) ?: return
// updates the app-wise connections from network log to AppInfo screen
holder.update(appConnection)
}

inner class ConnectionDetailsViewHolder(private val b: ListItemAppConnDetailsBinding) :
inner class ConnectionDetailsViewHolder(private val b: ListItemAppIpDetailsBinding) :
RecyclerView.ViewHolder(b.root) {
fun update(conn: AppConnection) {
displayTransactionDetails(conn)
Expand All @@ -106,16 +100,16 @@ class AppConnectionAdapter(val context: Context, val lifecycleOwner: LifecycleOw
return
}

val bottomSheetFragment = AppConnectionBottomSheet()
val bottomSheetFragment = AppIpRulesBottomSheet()
// Fix: free-form window crash
// all BottomSheetDialogFragment classes created must have a public, no-arg constructor.
// the best practice is to simply never define any constructors at all.
// so sending the data using Bundles
val bundle = Bundle()
bundle.putInt(AppConnectionBottomSheet.UID, uid)
bundle.putString(AppConnectionBottomSheet.IP_ADDRESS, appConn.ipAddress)
bundle.putInt(AppIpRulesBottomSheet.UID, uid)
bundle.putString(AppIpRulesBottomSheet.IP_ADDRESS, appConn.ipAddress)
bundle.putString(
AppConnectionBottomSheet.DOMAINS,
AppIpRulesBottomSheet.DOMAINS,
beautifyDomainString(appConn.appOrDnsName ?: "")
)
bottomSheetFragment.arguments = bundle
Expand Down
Loading

0 comments on commit 21fa180

Please sign in to comment.