diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 30010aa..dfaf4f5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: release-android on: schedule: - - cron: "4 3 * * *" + - cron: "*/10 * * * *" workflow_dispatch: inputs: track: @@ -33,23 +33,30 @@ on: workflow_call: jobs: - check-commits: + check_commits: runs-on: ubuntu-latest - outputs: - has_new_commits: ${{ steps.commits_check.outputs.has-new-commits }} steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all history for all branches and tags - - name: Check for commits in the last 23 hours - id: commits_check - run: | - commits=$(git rev-list --after="23 hours" HEAD --count) - echo "::set-output name=has-new-commits::$(($commits > 0))" + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Check for new commits in the last 23 hours + id: check_commits + run: | + # Get the current time and the time 23 hours ago in ISO 8601 format + now=$(date --utc +%Y-%m-%dT%H:%M:%SZ) + past=$(date --utc --date='23 hours ago' +%Y-%m-%dT%H:%M:%SZ) + + # Fetch commit history and check for commits in the last 23 hours + if git rev-list --since="$past" --count HEAD > /dev/null; then + echo "New commits found in the last 23 hours." + echo "::set-output name=new_commits::true" + else + echo "No new commits found in the last 23 hours." + echo "::set-output name=new_commits::false" + fi build: - needs: check-commits - if: ${{ needs.check-commits.outputs.has_new_commits == 'true' || github.event_name != 'schedule' }} + needs: check_commits + if: ${{ needs.check_commits.outputs.new_commits == 'true' || github.event_name != 'schedule'}} name: Build Signed APK runs-on: ubuntu-latest env: diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/BaseNetworkService.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/BaseNetworkService.kt index e39e11d..fbfb931 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/BaseNetworkService.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/BaseNetworkService.kt @@ -5,8 +5,6 @@ import android.net.ConnectivityManager import android.net.Network import android.net.NetworkCapabilities import android.net.NetworkRequest -import android.net.wifi.SupplicantState -import android.net.wifi.WifiInfo import android.net.wifi.WifiManager import android.os.Build import kotlinx.coroutines.channels.awaitClose @@ -21,7 +19,7 @@ abstract class BaseNetworkService>( private val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager - private val wifiManager = + val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager override val networkStatus = @@ -83,30 +81,6 @@ abstract class BaseNetworkService>( awaitClose { connectivityManager.unregisterNetworkCallback(networkStatusCallback) } } - - override fun getNetworkName(networkCapabilities: NetworkCapabilities): String? { - var ssid: String? = getWifiNameFromCapabilities(networkCapabilities) - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { - val info = wifiManager.connectionInfo - if (info.supplicantState === SupplicantState.COMPLETED) { - ssid = info.ssid - } - } - return ssid?.trim('"') - } - - companion object { - private fun getWifiNameFromCapabilities(networkCapabilities: NetworkCapabilities): String? { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - val info: WifiInfo - if (networkCapabilities.transportInfo is WifiInfo) { - info = networkCapabilities.transportInfo as WifiInfo - return info.ssid - } - } - return null - } - } } inline fun Flow.map( diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/EthernetService.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/EthernetService.kt index 24a8b5d..1ce2e66 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/EthernetService.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/EthernetService.kt @@ -10,4 +10,9 @@ class EthernetService constructor( @ApplicationContext context: Context, ) : - BaseNetworkService(context, NetworkCapabilities.TRANSPORT_ETHERNET) + BaseNetworkService(context, NetworkCapabilities.TRANSPORT_ETHERNET) { + + override fun isNetworkSecure(): Boolean { + return true + } +} diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/MobileDataService.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/MobileDataService.kt index 034ba9f..63ff72d 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/MobileDataService.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/MobileDataService.kt @@ -10,4 +10,8 @@ class MobileDataService constructor( @ApplicationContext context: Context, ) : - BaseNetworkService(context, NetworkCapabilities.TRANSPORT_CELLULAR) + BaseNetworkService(context, NetworkCapabilities.TRANSPORT_CELLULAR) { + override fun isNetworkSecure(): Boolean { + return false + } +} diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/NetworkExtensions.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/NetworkExtensions.kt new file mode 100644 index 0000000..0a28c56 --- /dev/null +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/NetworkExtensions.kt @@ -0,0 +1,16 @@ +package com.zaneschepke.wireguardautotunnel.service.network + +import android.net.NetworkCapabilities +import android.net.wifi.WifiInfo +import android.os.Build + +fun NetworkCapabilities.getWifiName(): String? { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + val info: WifiInfo + if (transportInfo is WifiInfo) { + info = transportInfo as WifiInfo + return info.ssid + } + } + return null +} diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/NetworkService.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/NetworkService.kt index 609164a..385851f 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/NetworkService.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/NetworkService.kt @@ -4,7 +4,11 @@ import android.net.NetworkCapabilities import kotlinx.coroutines.flow.Flow interface NetworkService { - fun getNetworkName(networkCapabilities: NetworkCapabilities): String? + fun getNetworkName(networkCapabilities: NetworkCapabilities): String? { + return null + } + + fun isNetworkSecure(): Boolean val networkStatus: Flow } diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/WifiService.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/WifiService.kt index 8bba30a..7a56835 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/WifiService.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/network/WifiService.kt @@ -2,6 +2,8 @@ package com.zaneschepke.wireguardautotunnel.service.network import android.content.Context import android.net.NetworkCapabilities +import android.net.wifi.SupplicantState +import android.os.Build import dagger.hilt.android.qualifiers.ApplicationContext import javax.inject.Inject @@ -10,4 +12,21 @@ class WifiService constructor( @ApplicationContext context: Context, ) : - BaseNetworkService(context, NetworkCapabilities.TRANSPORT_WIFI) + BaseNetworkService(context, NetworkCapabilities.TRANSPORT_WIFI) { + + override fun getNetworkName(networkCapabilities: NetworkCapabilities): String? { + var ssid = networkCapabilities.getWifiName() + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S) { + val info = wifiManager.connectionInfo + if (info.supplicantState === SupplicantState.COMPLETED) { + ssid = info.ssid + } + } + return ssid?.trim('"') + } + + override fun isNetworkSecure(): Boolean { + // TODO + return false + } +} diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/model/InterfaceProxy.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/model/InterfaceProxy.kt index 1addd28..87aeb67 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/model/InterfaceProxy.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/model/InterfaceProxy.kt @@ -44,7 +44,7 @@ data class InterfaceProxy( publicKey = i.keyPair.publicKey.toBase64().trim(), privateKey = i.keyPair.privateKey.toBase64().trim(), addresses = i.addresses.joinToString(", ").trim(), - dnsServers = (i.dnsServers + i.dnsSearchDomains).joinToString(", ").replace("/", "").trim() , + dnsServers = (i.dnsServers + i.dnsSearchDomains).joinToString(", ").replace("/", "").trim(), listenPort = if (i.listenPort.isPresent) { i.listenPort.get().toString().trim()