Skip to content

Commit

Permalink
Merge pull request #1476 from hussainmohd-a/v055m
Browse files Browse the repository at this point in the history
v055m
  • Loading branch information
hussainmohd-a committed May 29, 2024
2 parents 91ed53d + 9cbf03e commit 1c3a153
Show file tree
Hide file tree
Showing 28 changed files with 391 additions and 95 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ dependencies {
fullImplementation 'com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.9'

// from: https://jitpack.io/#celzero/firestack
download 'com.github.celzero:firestack:6cc4d626df@aar'
implementation 'com.github.celzero:firestack:6cc4d626df@aar'
download 'com.github.celzero:firestack:ad33ecd668@aar'
implementation 'com.github.celzero:firestack:ad33ecd668@aar'

// Work manager
implementation('androidx.work:work-runtime-ktx:2.9.0') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ object Logger : KoinComponent {
log(tag, message, LoggerType.ERROR, e)
}

fun crash(tag: String, message: String, e: Exception) {
log(tag, message, LoggerType.ERROR, e)
}

fun updateConfigLevel(level: Long) {
logLevel = level
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class RetrofitManager {
}
}
} catch (e: Exception) {
Logger.e(
Logger.crash(
Logger.LOG_TAG_DOWNLOAD,
"err while getting custom dns: ${e.message}",
e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class BlocklistDownloadHelper {
return processCheckDownloadResponse(r)
}
} catch (ex: Exception) {
Logger.e(LOG_TAG_DOWNLOAD, "exception in checkBlocklistUpdate: ${ex.message}", ex)
Logger.crash(LOG_TAG_DOWNLOAD, "exception in checkBlocklistUpdate: ${ex.message}", ex)
}
Logger.i(
LOG_TAG_DOWNLOAD,
Expand Down Expand Up @@ -204,7 +204,7 @@ class BlocklistDownloadHelper {

return BlocklistUpdateServerResponse(version, shouldUpdate, timestamp)
} catch (e: JSONException) {
Logger.e(LOG_TAG_DOWNLOAD, "Error in parsing the response: ${e.message}", e)
Logger.crash(LOG_TAG_DOWNLOAD, "Error in parsing the response: ${e.message}", e)
}
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ object WireguardManager : KoinComponent {
}

fun getConfigIdForApp(uid: Int): WgConfigFilesImmutable? {
// this method does not account the settings "Bypass all proxies" which is app-specific
val configId = ProxyManager.getProxyIdForApp(uid)
if (configId == "" || !configId.contains(ProxyManager.ID_WG_BASE)) {
Logger.d(LOG_TAG_PROXY, "app config mapping not found for uid: $uid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) {
installStateUpdatedListener
) // Might be play updater or web updater
} catch (e: Exception) {
Logger.e(LOG_TAG_APP_UPDATE, "err in app update check: ${e.message}", e)
Logger.crash(LOG_TAG_APP_UPDATE, "err in app update check: ${e.message}", e)
showDownloadDialog(
AppUpdater.InstallSource.STORE,
getString(R.string.download_update_dialog_failure_title),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,19 @@ class ConnTrackerBottomSheet : BottomSheetDialogFragment(), KoinComponent {

if (a == fStatus && c == connStatus) return@io

if (VpnController.isVpnLockdown() && fStatus.isExclude()) {
uiCtx {
// reset the spinner to previous selection
updateFirewallRulesUi(a, c)
showToastUiCentered(
requireContext(),
getString(R.string.hsf_exclude_error),
Toast.LENGTH_LONG
)
}
return@io
}

Logger.i(
LOG_TAG_FIREWALL,
"Change in firewall rule for app uid: ${info?.uid}, firewall status: $fStatus, conn status: $connStatus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ class HomeScreenFragment : Fragment(R.layout.fragment_home_screen) {
// versions.
// VpnService.prepare() is now registered with requireContext() instead of context.
// Issue #469
Logger.i(LOG_TAG_VPN, "Preparing VPN service")
VpnService.prepare(requireContext())
} catch (e: NullPointerException) {
// This exception is not mentioned in the documentation, but it has been encountered
Expand All @@ -1172,9 +1173,11 @@ class HomeScreenFragment : Fragment(R.layout.fragment_home_screen) {
// If the VPN.prepare() is not null, then the first time VPN dialog is shown, Show info
// dialog before that.
if (prepareVpnIntent != null) {
Logger.i(LOG_TAG_VPN, "VPN service is prepared")
showFirstTimeVpnDialog(prepareVpnIntent)
return false
}
Logger.i(LOG_TAG_VPN, "VPN service is prepared, starting VPN service")
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ class AppConnectionsViewModel(private val nwlogDao: ConnectionTrackerDAO) : View
startTime.value =
System.currentTimeMillis() - ONE_HOUR_MILLIS
}

TimeCategory.TWENTY_FOUR_HOUR -> {
startTime.value =
System.currentTimeMillis() - ONE_DAY_MILLIS
}

TimeCategory.SEVEN_DAYS -> {
startTime.value =
System.currentTimeMillis() - ONE_WEEK_MILLIS
Expand All @@ -102,21 +104,21 @@ class AppConnectionsViewModel(private val nwlogDao: ConnectionTrackerDAO) : View
private fun fetchIpLogs(uid: Int, input: String): LiveData<PagingData<AppConnection>> {
val to = getStartTime()
return if (input.isEmpty()) {
Pager(pagingConfig) { nwlogDao.getAppIpLogs(uid, to) }
} else {
Pager(pagingConfig) { nwlogDao.getAppIpLogsFiltered(uid, to, "%$input%") }
}
Pager(pagingConfig) { nwlogDao.getAppIpLogs(uid, to) }
} else {
Pager(pagingConfig) { nwlogDao.getAppIpLogsFiltered(uid, to, "%$input%") }
}
.liveData
.cachedIn(viewModelScope)
}

private fun fetchAppDomainLogs(uid: Int, input: String): LiveData<PagingData<AppConnection>> {
val to = getStartTime()
return if (input.isEmpty()) {
Pager(pagingConfig) { nwlogDao.getAppDomainLogs(uid, to) }
} else {
Pager(pagingConfig) { nwlogDao.getAppDomainLogsFiltered(uid, to, "%$input%") }
}
Pager(pagingConfig) { nwlogDao.getAppDomainLogs(uid, to) }
} else {
Pager(pagingConfig) { nwlogDao.getAppDomainLogsFiltered(uid, to, "%$input%") }
}
.liveData
.cachedIn(viewModelScope)
}
Expand All @@ -134,13 +136,15 @@ class AppConnectionsViewModel(private val nwlogDao: ConnectionTrackerDAO) : View
}

fun getDomainLogsLimited(uid: Int): LiveData<PagingData<AppConnection>> {
return Pager(pagingConfig) { nwlogDao.getAppDomainLogsLimited(uid) }
val to = System.currentTimeMillis() - ONE_WEEK_MILLIS
return Pager(pagingConfig) { nwlogDao.getAppDomainLogsLimited(uid, to) }
.liveData
.cachedIn(viewModelScope)
}

fun getIpLogsLimited(uid: Int): LiveData<PagingData<AppConnection>> {
return Pager(pagingConfig) { nwlogDao.getAppIpLogsLimited(uid) }
val to = System.currentTimeMillis() - ONE_WEEK_MILLIS
return Pager(pagingConfig) { nwlogDao.getAppIpLogsLimited(uid, to) }
.liveData
.cachedIn(viewModelScope)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/full/res/layout/list_item_app_domain_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
android:background="@drawable/drawable_purple_gradient"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:maxWidth="40dp"
android:maxWidth="60dp"
android:minWidth="40dp"
android:padding="5dp"
android:singleLine="true"
Expand Down
2 changes: 1 addition & 1 deletion app/src/full/res/layout/list_item_app_ip_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
android:background="@drawable/drawable_purple_gradient"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:maxWidth="40dp"
android:maxWidth="60dp"
android:minWidth="40dp"
android:padding="5dp"
android:singleLine="true"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.celzero.bravedns"
android:versionCode="43"
android:versionName="v055l"> <!-- 43(v055l) -->
android:versionCode="44"
android:versionName="v055m"> <!-- 44(v055m) -->

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED" />
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/celzero/bravedns/backup/BackupAgent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class BackupAgent(val context: Context, workerParams: WorkerParameters) :

return zipAndCopyToDestination(tempDir, backupFileUri)
} catch (e: Exception) {
Logger.e(
Logger.crash(
LOG_TAG_BACKUP_RESTORE,
"exception during backup process, reason? ${e.message}",
e
Expand Down Expand Up @@ -166,7 +166,7 @@ class BackupAgent(val context: Context, workerParams: WorkerParameters) :
filesPathToZip.add(metadataFile.absolutePath)
return true
} catch (e: Exception) {
Logger.e(
Logger.crash(
LOG_TAG_BACKUP_RESTORE,
"exception while creating meta data file, ${e.message}",
e
Expand Down Expand Up @@ -266,7 +266,7 @@ class BackupAgent(val context: Context, workerParams: WorkerParameters) :
val allPrefs = sharedPrefs.all
output.writeObject(allPrefs)
} catch (e: Exception) {
Logger.e(LOG_TAG_BACKUP_RESTORE, "exception during shared pref backup, ${e.message}", e)
Logger.crash(LOG_TAG_BACKUP_RESTORE, "exception during shared pref backup, ${e.message}", e)
return false
} finally {
try {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/celzero/bravedns/backup/RestoreAgent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class RestoreAgent(val context: Context, workerParams: WorkerParameters) :

return true
} catch (e: Exception) {
Logger.e(
Logger.crash(
LOG_TAG_BACKUP_RESTORE,
"exception during restore process, reason? ${e.message}",
e
Expand Down Expand Up @@ -257,7 +257,7 @@ class RestoreAgent(val context: Context, workerParams: WorkerParameters) :
val metadata = stream.bufferedReader().use { it.readText() }
isVersionSupported(metadata)
} catch (ignored: Exception) {
Logger.e(
Logger.crash(
LOG_TAG_BACKUP_RESTORE,
"error while restoring metadata, reason? ${ignored.message}",
ignored
Expand Down Expand Up @@ -316,7 +316,7 @@ class RestoreAgent(val context: Context, workerParams: WorkerParameters) :
}
return false
} catch (e: Exception) {
Logger.e(
Logger.crash(
LOG_TAG_BACKUP_RESTORE,
"exception while restoring shared pref, reason? ${e.message}",
e
Expand All @@ -340,7 +340,7 @@ class RestoreAgent(val context: Context, workerParams: WorkerParameters) :
// there is only one database), so do not consider the backups prior to that
return version >= minVersionSupported && persistentState.appVersion >= version
} catch (e: Exception) {
Logger.e(
Logger.crash(
LOG_TAG_BACKUP_RESTORE,
"error while reading metadata, reason? ${e.message}",
e
Expand Down Expand Up @@ -379,7 +379,7 @@ class RestoreAgent(val context: Context, workerParams: WorkerParameters) :
)
return true
} catch (e: Exception) {
Logger.e(
Logger.crash(
LOG_TAG_BACKUP_RESTORE,
"exception while restoring shared pref, reason? ${e.message}",
e
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/celzero/bravedns/data/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ internal constructor(
BraveMode.DNS.mode,
BraveMode.DNS_FIREWALL.mode -> determineTunDnsMode()
else -> {
Logger.e(LOG_TAG_VPN, "invalid brave mode: ${persistentState.braveMode}")
Logger.crash(
LOG_TAG_VPN,
"invalid brave mode: ${persistentState.braveMode}",
Exception()
)
TunDnsMode.NONE
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ interface ConnectionTrackerDAO {
fun getAppIpLogs(uid: Int, to: Long): PagingSource<Int, AppConnection>

@Query(
"SELECT uid, ipAddress, port, COUNT(ipAddress) as count, flag as flag, 0 as blocked, '' as appOrDnsName FROM ConnectionTracker WHERE uid = :uid GROUP BY ipAddress, uid, port ORDER BY count DESC LIMIT 3"
"SELECT uid, ipAddress, port, COUNT(ipAddress) as count, flag as flag, 0 as blocked, '' as appOrDnsName FROM ConnectionTracker WHERE uid = :uid and timeStamp > :to GROUP BY ipAddress, uid, port ORDER BY count DESC LIMIT 3"
)
fun getAppIpLogsLimited(uid: Int): PagingSource<Int, AppConnection>
fun getAppIpLogsLimited(uid: Int, to: Long): PagingSource<Int, AppConnection>

@Query(
"SELECT uid, ipAddress, port, COUNT(ipAddress) as count, flag as flag, 0 as blocked, GROUP_CONCAT(DISTINCT dnsQuery) as appOrDnsName FROM ConnectionTracker WHERE uid = :uid and timeStamp > :to and ipAddress like :query GROUP BY ipAddress, uid, port ORDER BY count DESC"
Expand All @@ -109,9 +109,9 @@ interface ConnectionTrackerDAO {
fun getAppDomainLogs(uid: Int, to: Long): PagingSource<Int, AppConnection>

@Query(
"SELECT uid, '' as ipAddress, port, COUNT(dnsQuery) as count, flag as flag, 0 as blocked, dnsQuery as appOrDnsName FROM ConnectionTracker WHERE uid = :uid and dnsQuery != '' GROUP BY dnsQuery ORDER BY count DESC LIMIT 3"
"SELECT uid, '' as ipAddress, port, COUNT(dnsQuery) as count, flag as flag, 0 as blocked, dnsQuery as appOrDnsName FROM ConnectionTracker WHERE uid = :uid and timeStamp > :to and dnsQuery != '' GROUP BY dnsQuery ORDER BY count DESC LIMIT 3"
)
fun getAppDomainLogsLimited(uid: Int): PagingSource<Int, AppConnection>
fun getAppDomainLogsLimited(uid: Int, to: Long): PagingSource<Int, AppConnection>

@Query(
"SELECT uid, GROUP_CONCAT(DISTINCT ipAddress) as ipAddress, port, COUNT(dnsQuery) as count, flag as flag, 0 as blocked, dnsQuery as appOrDnsName FROM ConnectionTracker WHERE uid = :uid and timeStamp > :to and dnsQuery != '' and dnsQuery like :query GROUP BY dnsQuery ORDER BY count DESC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ abstract class LogDatabase : RoomDatabase() {
}
db.enableWriteAheadLogging()
} catch (ignored: Exception) {
Logger.e(
Logger.crash(
"MIGRATION",
"error migrating from v1to2 on log db: ${ignored.message}",
ignored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ internal constructor(
// must be called after updateExistingPackagesIfNeeded
refreshDomainRules(packagesToUpdate)
} catch (e: RuntimeException) {
Logger.e(LOG_TAG_APP_DB, e.message ?: "refresh err", e)
Logger.crash(LOG_TAG_APP_DB, e.message ?: "refresh err", e)
throw e
} finally {
notifyEmptyFirewallRulesIfNeeded()
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/com/celzero/bravedns/net/go/GoVpnAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ class GoVpnAdapter : KoinComponent {
}
}

private fun newDefaultTransport(url: String): intra.DefaultDNS {
private fun newDefaultTransport(url: String): intra.DefaultDNS? {
val defaultDns = FALLBACK_DNS
try {
// when the url is empty, set the default transport to 8.8.4.4, 2001:4860:4860::8844
Expand All @@ -912,7 +912,12 @@ class GoVpnAdapter : KoinComponent {
Logger.e(LOG_TAG_VPN, "err new default transport($url): ${e.message}", e)
// most of the android devices have google dns, so add it as default transport
// TODO: notify the user that the default transport could not be set
return Intra.newDefaultDNS(Backend.DNS53, defaultDns, "")
try {
return Intra.newDefaultDNS(Backend.DNS53, defaultDns, "")
} catch (e: Exception) {
Logger.crash(LOG_TAG_VPN, "err add $defaultDns transport: ${e.message}", e)
return null
}
}
}

Expand Down Expand Up @@ -1138,7 +1143,7 @@ class GoVpnAdapter : KoinComponent {
}
return tunnel.resolver
} catch (e: Exception) {
Logger.e(LOG_TAG_VPN, "err get resolver: ${e.message}", e)
Logger.crash(LOG_TAG_VPN, "err get resolver: ${e.message}", e)
}
return null
}
Expand All @@ -1151,7 +1156,7 @@ class GoVpnAdapter : KoinComponent {
}
return tunnel.resolver
} catch (e: Exception) {
Logger.e(LOG_TAG_VPN, "err get resolver: ${e.message}", e)
Logger.crash(LOG_TAG_VPN, "err get resolver: ${e.message}", e)
}
return null
}
Expand Down
Loading

0 comments on commit 1c3a153

Please sign in to comment.