fix: nightly

This commit is contained in:
Zane Schepke 2024-10-14 00:11:26 -04:00
parent 7ca23d3ef5
commit f08d73cbb7
8 changed files with 76 additions and 47 deletions

View File

@ -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
- name: Check for new commits in the last 23 hours
id: check_commits
run: |
commits=$(git rev-list --after="23 hours" HEAD --count)
echo "::set-output name=has-new-commits::$(($commits > 0))"
# 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:

View File

@ -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<T : BaseNetworkService<T>>(
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<T : BaseNetworkService<T>>(
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 <Result> Flow<NetworkStatus>.map(

View File

@ -10,4 +10,9 @@ class EthernetService
constructor(
@ApplicationContext context: Context,
) :
BaseNetworkService<EthernetService>(context, NetworkCapabilities.TRANSPORT_ETHERNET)
BaseNetworkService<EthernetService>(context, NetworkCapabilities.TRANSPORT_ETHERNET) {
override fun isNetworkSecure(): Boolean {
return true
}
}

View File

@ -10,4 +10,8 @@ class MobileDataService
constructor(
@ApplicationContext context: Context,
) :
BaseNetworkService<MobileDataService>(context, NetworkCapabilities.TRANSPORT_CELLULAR)
BaseNetworkService<MobileDataService>(context, NetworkCapabilities.TRANSPORT_CELLULAR) {
override fun isNetworkSecure(): Boolean {
return false
}
}

View File

@ -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
}

View File

@ -4,7 +4,11 @@ import android.net.NetworkCapabilities
import kotlinx.coroutines.flow.Flow
interface NetworkService<T> {
fun getNetworkName(networkCapabilities: NetworkCapabilities): String?
fun getNetworkName(networkCapabilities: NetworkCapabilities): String? {
return null
}
fun isNetworkSecure(): Boolean
val networkStatus: Flow<NetworkStatus>
}

View File

@ -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<WifiService>(context, NetworkCapabilities.TRANSPORT_WIFI)
BaseNetworkService<WifiService>(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
}
}