Skip to content

Commit

Permalink
Merge pull request #1272 from hussainmohd-a/headless
Browse files Browse the repository at this point in the history
Headless Changes Post v055c
  • Loading branch information
hussainmohd-a authored Mar 12, 2024
2 parents d24918c + 877d3d1 commit c2e8754
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 130 deletions.
8 changes: 2 additions & 6 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,18 @@ android_app {
"androidx.work_work-runtime-ktx",
"com.google.android.material_material",
"firestack",
"gson-prebuilt-jar",
"gson",
"guava",
"ipaddress",
"koin-android",
"koin-core",
"krate",
"okio-lib",
],

use_embedded_native_libs: true
}

android_library_import {
name: "androidx.room_room-paging",
aars: ["app/libs/room-paging*.aar"],
}

android_library_import {
name: "firestack",
aars: ["app/libs/firestack*.aar"],
Expand Down
33 changes: 18 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ android {
defaultConfig {
applicationId "com.celzero.bravedns"
minSdkVersion 23
targetSdkVersion 33
targetSdkVersion 34
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -98,6 +98,7 @@ android {

buildFeatures {
viewBinding true
buildConfig true
}

compileOptions {
Expand Down Expand Up @@ -134,6 +135,7 @@ android {
}
headless {
dimension "releaseType"
minSdkVersion 31
// stackoverflow.com/a/60560178
// buildConfigField 'string', 'timestamp', '1662384683026'
}
Expand All @@ -147,7 +149,7 @@ android {
vectorDrawables.useSupportLibrary = true
}
}
lintOptions {
lint {
abortOnError false
}

Expand Down Expand Up @@ -179,7 +181,7 @@ dependencies {
// included to fix issues with Android 6 support, issue#563
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")

fullImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10'
fullImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.21'
fullImplementation 'androidx.appcompat:appcompat:1.6.1'
fullImplementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.preference:preference-ktx:1.2.1'
Expand All @@ -190,51 +192,52 @@ dependencies {
fullImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'

// LiveData
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.7.0'

implementation 'com.google.code.gson:gson:2.10.1'

implementation "androidx.room:room-runtime:$room_version"
ksp "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
download "androidx.room:room-paging:$room_version"
implementation "androidx.room:room-paging:$room_version"

fullImplementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
fullImplementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
fullImplementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
fullImplementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0'
fullImplementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'

// Pagers Views
implementation "androidx.paging:paging-runtime-ktx:$paging_version"
fullImplementation 'androidx.fragment:fragment-ktx:1.6.2'
implementation 'com.google.android.material:material:1.11.0'
fullImplementation 'androidx.viewpager2:viewpager2:1.0.0'

fullImplementation 'com.squareup.okhttp3:okhttp:4.11.0'
fullImplementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.11.0'
fullImplementation 'com.squareup.okhttp3:okhttp:4.12.0'
fullImplementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.12.0'

fullImplementation 'com.squareup.retrofit2:retrofit:2.9.0'
fullImplementation 'com.squareup.retrofit2:converter-gson:2.9.0'

implementation 'com.squareup.okio:okio-jvm:3.6.0'
// Glide
fullImplementation('com.github.bumptech.glide:glide:4.16.0') {
exclude group: 'glide-parent'
}
fullImplementation('com.github.bumptech.glide:okhttp3-integration:4.16.0') {
exclude group: 'glide-parent'
}

// Ref: https://stackoverflow.com/a/46638213
kspFull 'com.github.bumptech.glide:compiler:4.15.1'

// Swipe button animation
fullImplementation 'com.facebook.shimmer:shimmer:0.5.0'

// Koin core
download 'io.insert-koin:koin-core:3.2.0'
implementation 'io.insert-koin:koin-core:3.4.3'
download 'io.insert-koin:koin-core:3.5.0'
implementation 'io.insert-koin:koin-core:3.5.0'
// Koin main (Scope, ViewModel ...)
download 'io.insert-koin:koin-android:3.2.0'
implementation 'io.insert-koin:koin-android:3.4.3'
download 'io.insert-koin:koin-android:3.5.0'
implementation 'io.insert-koin:koin-android:3.5.0'

download 'hu.autsoft:krate:2.0.0'
implementation 'hu.autsoft:krate:2.0.0'
Expand Down Expand Up @@ -267,8 +270,8 @@ dependencies {

leakCanaryImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'

fullImplementation 'androidx.navigation:navigation-fragment-ktx:2.7.6'
fullImplementation 'androidx.navigation:navigation-ui-ktx:2.7.6'
fullImplementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
fullImplementation 'androidx.navigation:navigation-ui-ktx:2.7.7'

fullImplementation 'androidx.biometric:biometric:1.1.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import by.kirich1409.viewbindingdelegate.viewBinding
import com.celzero.bravedns.R
import com.celzero.bravedns.adapter.SummaryStatisticsAdapter
import com.celzero.bravedns.data.AppConfig
import com.celzero.bravedns.data.DataUsageSummary
import com.celzero.bravedns.databinding.FragmentSummaryStatisticsBinding
import com.celzero.bravedns.service.FirewallManager
import com.celzero.bravedns.service.PersistentState
Expand All @@ -50,13 +51,6 @@ class SummaryStatisticsFragment : Fragment(R.layout.fragment_summary_statistics)

private var isVpnActive: Boolean = false

data class DataUsage(
val totalDownload: Long,
val totalUpload: Long,
val connectionsCount: Int,
val meteredDataUsage: Long
)

enum class SummaryStatisticsType(val tid: Int) {
MOST_CONNECTED_APPS(0),
MOST_BLOCKED_APPS(1),
Expand Down Expand Up @@ -133,7 +127,7 @@ class SummaryStatisticsFragment : Fragment(R.layout.fragment_summary_statistics)
}
}

private fun setTotalUsagesUi(dataUsage: DataUsage) {
private fun setTotalUsagesUi(dataUsage: DataUsageSummary) {
val unmeteredUsage = (dataUsage.totalDownload + dataUsage.totalUpload)
val totalUsage = unmeteredUsage + dataUsage.meteredDataUsage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.paging.PagingConfig
import androidx.paging.cachedIn
import androidx.paging.liveData
import com.celzero.bravedns.data.AppConfig
import com.celzero.bravedns.data.DataUsageSummary
import com.celzero.bravedns.database.ConnectionTracker
import com.celzero.bravedns.database.ConnectionTrackerDAO
import com.celzero.bravedns.database.DnsLogDAO
Expand Down Expand Up @@ -192,7 +193,7 @@ class SummaryStatisticsViewModel(
.cachedIn(viewModelScope)
}

suspend fun totalUsage(): SummaryStatisticsFragment.DataUsage {
suspend fun totalUsage(): DataUsageSummary {
val to = startTime.value ?: 0L
return connectionTrackerDAO.getTotalUsages(to, ConnectionTracker.ConnType.METERED.value)
}
Expand Down
9 changes: 0 additions & 9 deletions app/src/full/res/xml/accessibility_service_config.xml

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/full/res/xml/file_provider_paths.xml

This file was deleted.

1 change: 0 additions & 1 deletion app/src/headless/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.celzero.bravedns">

<permission
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.celzero.bravedns;

public final class BuildConfig {
public static final String APPLICATION_ID = "com.celzero.bravedns";
public static final String FLAVOR_releaseChannel = "fdroid";
public static final String FLAVOR_releaseType = "headless";
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,15 @@ import org.koin.android.ext.koin.androidContext
import org.koin.core.module.Module
import org.koin.dsl.module

private val RootModule = module {
single<ContentResolver> { androidContext().contentResolver }
}
private val rootModule = module { single<ContentResolver> { androidContext().contentResolver } }

private val orbotHelperModule = module {
single { OrbotHelper(androidContext(), get(), get()) }
}
private val schedulerModule = module { single { ScheduleManager(androidContext()) } }

private val schedulerModule = module {
single { ScheduleManager(androidContext()) }
}
private val orbotHelperModule = module { single { OrbotHelper(androidContext(), get(), get()) } }

val AppModules: List<Module> by lazy {
mutableListOf<Module>().apply {
add(RootModule)
add(rootModule)
addAll(DatabaseModule.modules)
addAll(DataModule.modules)
add(schedulerModule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import android.util.Log
import com.celzero.bravedns.database.AppInfo
import com.celzero.bravedns.database.AppInfoRepository
import com.celzero.bravedns.service.FirewallManager
import com.celzero.bravedns.util.LoggerConstants
import com.celzero.bravedns.util.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -61,7 +61,7 @@ class ApplicationProvider : ContentProvider() {
sortOrder: String?
): Cursor {
if (!isValidRequest(uri)) {
Log.e(LoggerConstants.LOG_PROVIDER, "invalid uri, cannot update without ID: $uri")
Log.e(Logger.LOG_PROVIDER, "invalid uri, cannot update without ID: $uri")
throw java.lang.IllegalArgumentException("Invalid URI, cannot update without ID$uri")
}
return appInfoRepository.getAppsCursor()
Expand All @@ -79,31 +79,31 @@ class ApplicationProvider : ContentProvider() {

override fun insert(uri: Uri, values: ContentValues?): Uri? {
if (!isValidRequest(uri)) {
Log.e(LoggerConstants.LOG_PROVIDER, "invalid uri, cannot update without ID: $uri")
Log.e(Logger.LOG_PROVIDER, "invalid uri, cannot update without ID: $uri")
throw java.lang.IllegalArgumentException("invalid uri, cannot update without ID$uri")
}
val appInfo = AppInfo(values)

val id = appInfoRepository.cpInsert(appInfo)
// update the app info cache
CoroutineScope(Dispatchers.IO).launch { FirewallManager.reloadAppList() }
CoroutineScope(Dispatchers.IO).launch { FirewallManager.load() }
context?.contentResolver?.notifyChange(uri, null)
return ContentUris.withAppendedId(uri, id)
}

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int {
if (!isValidRequest(uri)) {
Log.e(LoggerConstants.LOG_PROVIDER, "invalid uri, cannot update without ID: $uri")
Log.e(Logger.LOG_PROVIDER, "invalid uri, cannot update without ID: $uri")
throw java.lang.IllegalArgumentException("Invalid URI, cannot update without ID$uri")
}
Log.i(
LoggerConstants.LOG_PROVIDER,
Logger.LOG_PROVIDER,
"request to delete app, parameters $uri, $selection, $selectionArgs"
)
val id = ContentUris.parseId(uri).toInt()
val count = appInfoRepository.cpDelete(id)
// update the app info cache
CoroutineScope(Dispatchers.IO).launch { FirewallManager.reloadAppList() }
CoroutineScope(Dispatchers.IO).launch { FirewallManager.load() }
context?.contentResolver?.notifyChange(uri, null)
return count
}
Expand All @@ -115,7 +115,7 @@ class ApplicationProvider : ContentProvider() {
selectionArgs: Array<out String>?
): Int {
if (!isValidRequest(uri)) {
Log.e(LoggerConstants.LOG_PROVIDER, "invalid uri, cannot update without ID: $uri")
Log.e(Logger.LOG_PROVIDER, "invalid uri, cannot update without ID: $uri")
throw java.lang.IllegalArgumentException("invalid uri, cannot update without ID$uri")
}

Expand All @@ -126,14 +126,14 @@ class ApplicationProvider : ContentProvider() {
val count = appInfoRepository.cpUpdate(appInfo)
context.contentResolver?.notifyChange(uri, null)
// update the app info cache
CoroutineScope(Dispatchers.IO).launch { FirewallManager.reloadAppList() }
CoroutineScope(Dispatchers.IO).launch { FirewallManager.load() }
return count
} else if (selectionClause.contains("uid") || selectionClause.contains("packageName")) {
val c = selectionClause.count { it == '?' }
// if the selection clause contains uid or packageName, then the selectionArgs should
// contain the values for the same.
if (c != (selectionArgs?.size ?: 0)) {
Log.e(LoggerConstants.LOG_PROVIDER, "invalid selection clause: $selectionClause")
Log.e(Logger.LOG_PROVIDER, "invalid selection clause: $selectionClause")
throw java.lang.IllegalArgumentException(
"invalid selection clause: $selectionClause"
)
Expand All @@ -144,16 +144,16 @@ class ApplicationProvider : ContentProvider() {
clause = clause.replaceFirst("?", selectionArgs?.get(i) ?: "")
}
Log.i(
LoggerConstants.LOG_PROVIDER,
Logger.LOG_PROVIDER,
"selection ${appInfo.appName}, ${appInfo.uid}, ${appInfo.firewallStatus} clause: $clause"
)
val count = appInfoRepository.cpUpdate(appInfo, clause)
// update the app info cache
CoroutineScope(Dispatchers.IO).launch { FirewallManager.reloadAppList() }
CoroutineScope(Dispatchers.IO).launch { FirewallManager.load() }
context.contentResolver?.notifyChange(uri, null)
return count
} else {
Log.e(LoggerConstants.LOG_PROVIDER, "invalid selection clause: $selectionClause")
Log.e(Logger.LOG_PROVIDER, "invalid selection clause: $selectionClause")
throw java.lang.IllegalArgumentException("invalid selection clause: $selectionClause")
}
}
Expand All @@ -162,7 +162,7 @@ class ApplicationProvider : ContentProvider() {
// check the calling package
if (callingPackage != RESOLVER_PACKAGE_NAME) {
Log.e(
LoggerConstants.LOG_PROVIDER,
Logger.LOG_PROVIDER,
"request received from unknown package: $callingPackage"
)
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.celzero.bravedns.database.RethinkLocalFileTag
import com.celzero.bravedns.database.RethinkLocalFileTagRepository
import com.celzero.bravedns.service.PersistentState
import com.celzero.bravedns.service.RethinkBlocklistManager
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_PROVIDER
import com.celzero.bravedns.util.Logger.Companion.LOG_PROVIDER
import org.koin.android.ext.android.inject

class BlocklistProvider : ContentProvider() {
Expand Down
Loading

0 comments on commit c2e8754

Please sign in to comment.