Skip to content

Commit

Permalink
Merge pull request #1110 from hussainmohd-a/headless
Browse files Browse the repository at this point in the history
Headless variant fix
  • Loading branch information
hussainmohd-a authored Oct 12, 2023
2 parents b22b171 + 6864460 commit 133ee90
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 89 deletions.
24 changes: 12 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ try {
}

android {
compileSdk 33
compileSdk 34
// https://developer.android.com/studio/build/configure-app-module
namespace 'com.celzero.bravedns'

defaultConfig {
applicationId "com.celzero.bravedns"
minSdkVersion 23
targetSdkVersion 33
targetSdkVersion 34
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -132,7 +132,7 @@ configurations {
dependencies {
androidTestImplementation 'androidx.test:rules:1.5.0'
def room_version = "2.5.2"
def paging_version = "3.2.0"
def paging_version = "3.2.1"

implementation 'com.google.guava:guava:32.1.1-android'

Expand All @@ -142,7 +142,7 @@ dependencies {

fullImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0'
fullImplementation 'androidx.appcompat:appcompat:1.6.1'
fullImplementation 'androidx.core:core-ktx:1.10.1'
fullImplementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.preference:preference-ktx:1.2.1'
fullImplementation 'androidx.constraintlayout:constraintlayout:2.1.4'
fullImplementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
Expand All @@ -151,7 +151,7 @@ dependencies {
fullImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'

// For liveData implementation
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'

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

Expand All @@ -162,13 +162,13 @@ dependencies {
implementation "androidx.room:room-paging:$room_version"

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

// For paging - connection tracker
implementation "androidx.paging:paging-runtime-ktx:$paging_version"
fullImplementation 'androidx.fragment:fragment-ktx:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.android.material:material:1.10.0'
fullImplementation 'androidx.viewpager2:viewpager2:1.0.0'

fullImplementation 'com.squareup.okhttp3:okhttp:4.11.0'
Expand Down Expand Up @@ -229,8 +229,8 @@ dependencies {

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

fullImplementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
fullImplementation 'androidx.navigation:navigation-ui-ktx:2.6.0'
fullImplementation 'androidx.navigation:navigation-fragment-ktx:2.7.4'
fullImplementation 'androidx.navigation:navigation-ui-ktx:2.7.4'

fullImplementation 'androidx.biometric:biometric:1.1.0'

Expand All @@ -246,7 +246,7 @@ dependencies {
}

// github.com/michel-kraemer/gradle-download-task/issues/131#issuecomment-464476903
task downloadBlocklists(type: Download) {
tasks.register('downloadBlocklists', Download) {
// def assetsDir = new File(projectDir, 'src/main/assets'
def assetsDir = android.sourceSets.headless.assets.srcDirs[0]
// the filenames are ignored by dl, but acts as a hint for the output
Expand All @@ -271,7 +271,7 @@ task downloadBlocklists(type: Download) {
overwrite true
}

task downloadDependencies(type: Copy) {
tasks.register('downloadDependencies', Copy) {
dependsOn downloadBlocklists
from configurations.download
into "libs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.celzero.bravedns.database.WgConfigFiles
import com.celzero.bravedns.databinding.ListItemWgInterfaceBinding
import com.celzero.bravedns.service.ProxyManager
import com.celzero.bravedns.service.VpnController
import com.celzero.bravedns.service.WireGuardManager
import com.celzero.bravedns.service.WireguardManager
import com.celzero.bravedns.ui.WgConfigDetailActivity
import com.celzero.bravedns.ui.WgConfigEditorActivity.Companion.INTENT_EXTRA_WG_ID
import com.celzero.bravedns.util.UIUtils
Expand Down Expand Up @@ -122,8 +122,8 @@ class WgConfigAdapter(private val context: Context) :
b.interfaceSwitch.setOnClickListener {
val checked = b.interfaceSwitch.isChecked
if (checked) {
if (WireGuardManager.canEnableConfig(config)) {
WireGuardManager.enableConfig(config)
if (WireguardManager.canEnableConfig(config)) {
WireguardManager.enableConfig(config)
updateStatus(config)
} else {
b.interfaceSwitch.isChecked = false
Expand All @@ -135,7 +135,7 @@ class WgConfigAdapter(private val context: Context) :
.show()
}
} else {
WireGuardManager.disableConfig(config)
WireguardManager.disableConfig(config)
updateStatus(config)
}
}
Expand Down
10 changes: 5 additions & 5 deletions app/src/full/java/com/celzero/bravedns/adapter/WgPeersAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import com.celzero.bravedns.R
import com.celzero.bravedns.databinding.ListItemWgPeersBinding
import com.celzero.bravedns.service.WireGuardManager
import com.celzero.bravedns.service.WireGuardManager.WARP_ID
import com.celzero.bravedns.service.WireguardManager
import com.celzero.bravedns.service.WireguardManager.WARP_ID
import com.celzero.bravedns.ui.WgAddPeerDialog
import com.celzero.bravedns.wireguard.Peer
import com.google.android.material.dialog.MaterialAlertDialogBuilder
Expand Down Expand Up @@ -110,7 +110,7 @@ class WgPeersAdapter(

fun dataChanged() {
peers.clear()
peers.addAll(WireGuardManager.getPeers(configId))
peers.addAll(WireguardManager.getPeers(configId))
this?.notifyDataSetChanged()
}

Expand All @@ -132,8 +132,8 @@ class WgPeersAdapter(
private fun deletePeer(wgPeer: Peer) {
ui {
ioCtx {
WireGuardManager.deletePeer(configId, wgPeer)
peers = WireGuardManager.getPeers(configId)
WireguardManager.deletePeer(configId, wgPeer)
peers = WireguardManager.getPeers(configId)
}
this.notifyDataSetChanged()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object ProxyManager : KoinComponent {
private var appConfigMappings = mutableSetOf<ProxyApplicationMapping>()

suspend fun load() {
WireGuardManager.load()
WireguardManager.load()
appConfigMappings = proxyAppMappingRepository.getApps().toMutableSet()
}

Expand Down Expand Up @@ -81,7 +81,7 @@ object ProxyManager : KoinComponent {
} else if (proxyId.contains(ID_ORBOT_BASE)) {
appConfig.isOrbotProxyEnabled()
} else if (proxyId.contains(ID_WG_BASE)) {
WireGuardManager.isConfigActive(proxyId)
WireguardManager.isConfigActive(proxyId)
} else if (proxyId.contains(ID_TCP_BASE)) {
TcpProxyHelper.isTcpProxyEnabled()
} else if (proxyId.contains(ID_S5_BASE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import java.util.Locale
import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.write

object WireGuardManager : KoinComponent {
object WireguardManager : KoinComponent {

private val wgConfigFilesRepository: WgConfigFilesRepository by inject()
private val applicationContext: Context by inject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import com.celzero.bravedns.service.IpRulesManager
import com.celzero.bravedns.service.PersistentState
import com.celzero.bravedns.service.RethinkBlocklistManager
import com.celzero.bravedns.service.VpnController
import com.celzero.bravedns.service.WireGuardManager
import com.celzero.bravedns.service.WireguardManager
import com.celzero.bravedns.util.Constants
import com.celzero.bravedns.util.Constants.Companion.INIT_TIME_MS
import com.celzero.bravedns.util.Constants.Companion.INVALID_PORT
Expand Down Expand Up @@ -254,7 +254,7 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) {
refreshDatabase.refreshAppInfoDatabase()
IpRulesManager.loadIpRules()
DomainRulesManager.load()
WireGuardManager.restoreProcessDeleteWireGuardEntries()
WireguardManager.restoreProcessDeleteWireGuardEntries()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import com.celzero.bravedns.service.PersistentState
import com.celzero.bravedns.service.ProxyManager
import com.celzero.bravedns.service.TcpProxyHelper
import com.celzero.bravedns.service.VpnController
import com.celzero.bravedns.service.WireGuardManager
import com.celzero.bravedns.service.WireguardManager
import com.celzero.bravedns.util.Constants
import com.celzero.bravedns.util.LoggerConstants
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_TAG_UI
Expand Down Expand Up @@ -369,7 +369,7 @@ class ProxySettingsActivity : AppCompatActivity(R.layout.fragment_proxy_configur
}

private fun displayWireguardUi() {
val activeWgs = WireGuardManager.getActiveConfigs()
val activeWgs = WireguardManager.getActiveConfigs()
if (activeWgs.isEmpty()) {
b.settingsActivityWireguardDesc.text = getString(R.string.wireguard_description)
return
Expand Down
32 changes: 16 additions & 16 deletions app/src/full/java/com/celzero/bravedns/ui/TcpProxyMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import com.celzero.bravedns.databinding.ActivityTcpProxyBinding
import com.celzero.bravedns.service.PersistentState
import com.celzero.bravedns.service.ProxyManager
import com.celzero.bravedns.service.TcpProxyHelper
import com.celzero.bravedns.service.WireGuardManager
import com.celzero.bravedns.service.WireGuardManager.SEC_WARP_ID
import com.celzero.bravedns.service.WireGuardManager.WARP_ID
import com.celzero.bravedns.service.WireGuardManager.isWarpWorking
import com.celzero.bravedns.service.WireguardManager
import com.celzero.bravedns.service.WireguardManager.SEC_WARP_ID
import com.celzero.bravedns.service.WireguardManager.WARP_ID
import com.celzero.bravedns.service.WireguardManager.isWarpWorking
import com.celzero.bravedns.util.LoggerConstants
import com.celzero.bravedns.util.Themes
import com.celzero.bravedns.util.Utilities
Expand Down Expand Up @@ -92,13 +92,13 @@ class TcpProxyMainActivity : AppCompatActivity(R.layout.activity_tcp_proxy) {
}

private fun displayWarpStatus() {
val config = WireGuardManager.getWarpConfig()
val config = WireguardManager.getWarpConfig()
if (config == null) {
b.warpStatus.text = "Fetch from server" // getString(R.string.tcp_proxy_description)
b.warpSwitch.isChecked = false
return
}
if (WireGuardManager.getConfigFilesById(WARP_ID)?.isActive == true) {
if (WireguardManager.getConfigFilesById(WARP_ID)?.isActive == true) {
b.warpStatus.text = "Active" // getString(R.string.tcp_proxy_description_active)
b.warpSwitch.isChecked = true
} else {
Expand All @@ -109,7 +109,7 @@ class TcpProxyMainActivity : AppCompatActivity(R.layout.activity_tcp_proxy) {

private fun setupClickListeners() {
b.tcpProxySwitch.setOnCheckedChangeListener { _, checked ->
if (checked && WireGuardManager.isConfigActive(ProxyManager.ID_WG_BASE + WARP_ID)) {
if (checked && WireguardManager.isConfigActive(ProxyManager.ID_WG_BASE + WARP_ID)) {
b.tcpProxySwitch.isChecked = false
Utilities.showToastUiCentered(
this,
Expand Down Expand Up @@ -158,12 +158,12 @@ class TcpProxyMainActivity : AppCompatActivity(R.layout.activity_tcp_proxy) {
b.enableUdpRelay.setOnCheckedChangeListener { _, b ->
if (b) {
io {
val alreadyDownloaded = WireGuardManager.isSecWarpAvailable()
val alreadyDownloaded = WireguardManager.isSecWarpAvailable()
if (alreadyDownloaded) {
val cf =
WireGuardManager.getConfigFilesById(SEC_WARP_ID)
WireguardManager.getConfigFilesById(SEC_WARP_ID)
?: return@io
WireGuardManager.enableConfig(cf)
WireguardManager.enableConfig(cf)
} else {
createConfigOrShowErrorLayout()
}
Expand All @@ -172,9 +172,9 @@ class TcpProxyMainActivity : AppCompatActivity(R.layout.activity_tcp_proxy) {

io {
val cf =
WireGuardManager.getConfigFilesById(SEC_WARP_ID)
WireguardManager.getConfigFilesById(SEC_WARP_ID)
?: return@io
WireGuardManager.disableConfig(cf)
WireguardManager.disableConfig(cf)
}
}
}
Expand Down Expand Up @@ -202,12 +202,12 @@ class TcpProxyMainActivity : AppCompatActivity(R.layout.activity_tcp_proxy) {
}

val configFiles =
WireGuardManager.getConfigFilesById(WARP_ID) ?: return@setOnCheckedChangeListener
WireguardManager.getConfigFilesById(WARP_ID) ?: return@setOnCheckedChangeListener
if (checked) {
WireGuardManager.enableConfig(configFiles)
WireguardManager.enableConfig(configFiles)
b.warpStatus.text = "Active" // getString(R.string.tcp_proxy_description_active)
} else {
WireGuardManager.disableConfig(configFiles)
WireguardManager.disableConfig(configFiles)
b.warpStatus.text = "Not active" // getString(R.string.tcp_proxy_description)
}
}
Expand Down Expand Up @@ -245,7 +245,7 @@ class TcpProxyMainActivity : AppCompatActivity(R.layout.activity_tcp_proxy) {
}

private suspend fun fetchWarpConfigFromServer() {
val config = WireGuardManager.getNewWarpConfig(SEC_WARP_ID)
val config = WireguardManager.getNewWarpConfig(SEC_WARP_ID)
Log.i(LoggerConstants.LOG_TAG_PROXY, "new config from server: ${config?.getName()}")
if (config == null) {
showConfigCreationError()
Expand Down
6 changes: 3 additions & 3 deletions app/src/full/java/com/celzero/bravedns/ui/WgAddPeerDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import android.widget.Toast
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.celzero.bravedns.databinding.DialogWgAddPeerBinding
import com.celzero.bravedns.service.WireGuardManager
import com.celzero.bravedns.service.WireguardManager
import com.celzero.bravedns.util.LoggerConstants
import com.celzero.bravedns.wireguard.Peer
import com.celzero.bravedns.wireguard.util.ErrorMessages
Expand Down Expand Up @@ -101,8 +101,8 @@ class WgAddPeerDialog(
ui {
io {
if (wgPeer != null && isEditing)
WireGuardManager.deletePeer(configId, wgPeer)
WireGuardManager.addPeer(configId, newPeer)
WireguardManager.deletePeer(configId, wgPeer)
WireguardManager.addPeer(configId, newPeer)
}
this.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ import com.celzero.bravedns.adapter.WgPeersAdapter
import com.celzero.bravedns.databinding.ActivityWgDetailBinding
import com.celzero.bravedns.service.PersistentState
import com.celzero.bravedns.service.ProxyManager
import com.celzero.bravedns.service.WireGuardManager
import com.celzero.bravedns.service.WireGuardManager.INVALID_CONF_ID
import com.celzero.bravedns.service.WireGuardManager.WARP_ID
import com.celzero.bravedns.service.WireGuardManager.isWarpWorking
import com.celzero.bravedns.service.WireguardManager
import com.celzero.bravedns.service.WireguardManager.INVALID_CONF_ID
import com.celzero.bravedns.service.WireguardManager.WARP_ID
import com.celzero.bravedns.service.WireguardManager.isWarpWorking
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_TAG_PROXY
import com.celzero.bravedns.util.Themes
import com.celzero.bravedns.util.UIUtils
Expand Down Expand Up @@ -105,7 +105,7 @@ class WgConfigDetailActivity : AppCompatActivity(R.layout.activity_wg_detail) {
private fun init() {
handleWarpConfigView()
handleAppsCount()
val config = WireGuardManager.getConfigById(configId)
val config = WireguardManager.getConfigById(configId)
if (config == null && configId == WARP_ID) {
showNewWarpConfigLayout()
return
Expand Down Expand Up @@ -172,7 +172,7 @@ class WgConfigDetailActivity : AppCompatActivity(R.layout.activity_wg_detail) {
}

private suspend fun fetchWarpConfigFromServer() {
val config = WireGuardManager.getNewWarpConfig(WARP_ID)
val config = WireguardManager.getNewWarpConfig(WARP_ID)
Log.i(LOG_TAG_PROXY, "new config from server: ${config?.getName()}")
if (config == null) {
showConfigCreationError()
Expand Down Expand Up @@ -202,7 +202,7 @@ class WgConfigDetailActivity : AppCompatActivity(R.layout.activity_wg_detail) {
}

private fun isWarpConfAvailable(): Boolean {
return WireGuardManager.getWarpConfig() != null
return WireguardManager.getWarpConfig() != null
}

private fun showNewWarpConfigLayout() {
Expand Down Expand Up @@ -293,7 +293,7 @@ class WgConfigDetailActivity : AppCompatActivity(R.layout.activity_wg_detail) {
private fun openAppsDialog() {
val themeId = Themes.getCurrentTheme(isDarkThemeOn(), persistentState.theme)
val proxyId = ProxyManager.ID_WG_BASE + configId
val proxyName = WireGuardManager.getConfigName(configId)
val proxyName = WireguardManager.getConfigName(configId)
val appsAdapter = WgIncludeAppsAdapter(this, proxyId, proxyName)
mappingViewModel.apps.observe(this) { appsAdapter.submitData(lifecycle, it) }
val includeAppsDialog =
Expand All @@ -308,7 +308,7 @@ class WgConfigDetailActivity : AppCompatActivity(R.layout.activity_wg_detail) {
builder.setMessage(getString(R.string.config_delete_dialog_desc))
builder.setCancelable(true)
builder.setPositiveButton(this.getString(R.string.lbl_delete)) { _, _ ->
WireGuardManager.deleteConfig(configId)
WireguardManager.deleteConfig(configId)
Toast.makeText(
this,
getString(R.string.config_delete_success_toast),
Expand Down
Loading

0 comments on commit 133ee90

Please sign in to comment.