mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| acae5ad33d | |||
| 13b7457881 | |||
| 2bca6de331 | |||
| d9608e073c | |||
| 6417065c32 | |||
| ca946e1cf1 | |||
| 3c0f993584 | |||
| 385c0dfbfc |
+10
-10
@@ -1,6 +1,4 @@
|
||||
name: build
|
||||
permissions:
|
||||
contents: read
|
||||
name: Build
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
@@ -22,7 +20,7 @@ on:
|
||||
default: fdroid
|
||||
options:
|
||||
- fdroid
|
||||
- standalone
|
||||
- full
|
||||
secrets:
|
||||
SIGNING_KEY_ALIAS:
|
||||
required: false
|
||||
@@ -96,7 +94,10 @@ jobs:
|
||||
run: |
|
||||
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
||||
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
||||
|
||||
- name: Create service_account.json
|
||||
if: ${{ inputs.build_type != 'debug' }}
|
||||
id: createServiceAccount
|
||||
run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json
|
||||
- name: Build APK
|
||||
run: |
|
||||
flavor=${{ inputs.flavor }}
|
||||
@@ -118,10 +119,9 @@ jobs:
|
||||
- name: Get release apk path
|
||||
id: apk-path
|
||||
run: echo "path=$(find . -regex '^.*/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/.*\.apk$' -type f | head -1 | tail -c+2)" >> $GITHUB_OUTPUT
|
||||
- name: Upload APK
|
||||
- name: Upload release apk
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: android_artifacts_${{ inputs.flavor }}
|
||||
path: app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/wgtunnel-${{ inputs.flavor }}${{ inputs.flavor == 'fdroid' && '-release' || '' }}-*.apk
|
||||
retention-days: 1
|
||||
if-no-files-found: warn
|
||||
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||
path: ${{ github.workspace }}/${{ steps.apk-path.outputs.path }}
|
||||
retention-days: 1
|
||||
@@ -1,127 +0,0 @@
|
||||
name: nightly
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "4 3 * * *"
|
||||
|
||||
jobs:
|
||||
check_commits:
|
||||
name: Check for New Commits
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Check for new commits
|
||||
id: check
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||
run: |
|
||||
NEW_COMMITS=$(git rev-list --count --after="$(date -Iseconds -d '23 hours ago')" ${{ github.sha }})
|
||||
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
||||
|
||||
build-standalone-nightly:
|
||||
uses: ./.github/workflows/build.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
build_type: "nightly"
|
||||
flavor: standalone
|
||||
|
||||
publish:
|
||||
needs:
|
||||
- check_commits
|
||||
- build-standalone-nightly
|
||||
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
||||
name: publish-nightly
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt update && sudo apt install -y gh apksigner
|
||||
- name: Set latest tag
|
||||
uses: rickstaa/action-create-tag@v1
|
||||
id: tag_creation
|
||||
with:
|
||||
tag: "latest"
|
||||
message: "Automated tag for HEAD commit"
|
||||
force_push_tag: true
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag_exists_error: false
|
||||
|
||||
- name: Generate Changelog
|
||||
id: changelog
|
||||
uses: requarks/changelog-action@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
toTag: "nightly"
|
||||
fromTag: "latest"
|
||||
writeToFile: false
|
||||
|
||||
- name: Make download dir
|
||||
run: mkdir ${{ github.workspace }}/temp
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: android_artifacts_*
|
||||
path: ${{ github.workspace }}/temp
|
||||
|
||||
- name: Set release notes
|
||||
run: |
|
||||
echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV
|
||||
|
||||
- name: Delete previous nightly version
|
||||
uses: ClementTsang/delete-tag-and-release@v0.4.0
|
||||
with:
|
||||
tag_name: "nightly"
|
||||
delete_release: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get checksum
|
||||
id: checksum
|
||||
run: |
|
||||
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | head -n 1)
|
||||
if [ -z "$file_path" ]; then
|
||||
echo "No APK file found"
|
||||
exit 1
|
||||
fi
|
||||
checksum=$(apksigner verify --print-certs "$file_path" | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")
|
||||
echo "checksum=$checksum" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create nightly release
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
body: |
|
||||
${{ env.RELEASE_NOTES }}
|
||||
|
||||
SHA-256 fingerprints for the 4096-bit signing certificate:
|
||||
```sh
|
||||
${{ steps.checksum.outputs.checksum }}
|
||||
```
|
||||
|
||||
To verify fingerprint:
|
||||
```sh
|
||||
apksigner verify --print-certs [path to APK file] | grep SHA-256
|
||||
```
|
||||
|
||||
### Changelog
|
||||
${{ steps.changelog.outputs.changes }}
|
||||
tag_name: nightly
|
||||
name: nightly
|
||||
draft: false
|
||||
prerelease: true
|
||||
make_latest: false
|
||||
files: |
|
||||
${{ github.workspace }}/temp/**/*.apk
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -1,6 +1,4 @@
|
||||
name: on-pr
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
+78
-101
@@ -1,9 +1,8 @@
|
||||
name: publish
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "4 3 * * *"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
track:
|
||||
@@ -23,60 +22,95 @@ on:
|
||||
options:
|
||||
- none
|
||||
- prerelease
|
||||
- nightly
|
||||
- release
|
||||
default: release
|
||||
required: true
|
||||
tag_name:
|
||||
description: "Tag name for release"
|
||||
required: false
|
||||
default: 1.1.1
|
||||
default: nightly
|
||||
flavor:
|
||||
type: choice
|
||||
description: "Product flavor"
|
||||
required: true
|
||||
default: standalone
|
||||
default: full
|
||||
options:
|
||||
- fdroid
|
||||
- standalone
|
||||
- full
|
||||
workflow_call:
|
||||
inputs:
|
||||
flavor:
|
||||
type: string
|
||||
description: "Product flavor"
|
||||
required: false
|
||||
default: standalone
|
||||
default: full
|
||||
|
||||
env:
|
||||
UPLOAD_DIR_ANDROID: android_artifacts
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
check_commits:
|
||||
name: Check for New Commits
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Check for new commits
|
||||
id: check
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||
run: |
|
||||
NEW_COMMITS=$(git rev-list --count --after="$(date -Iseconds -d '23 hours ago')" ${{ github.sha }})
|
||||
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
||||
|
||||
build-fdroid:
|
||||
if: ${{ inputs.release_type == 'release' || inputs.flavor == 'fdroid' }}
|
||||
uses: ./.github/workflows/build.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
build_type: ${{ inputs.release_type }}
|
||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
||||
flavor: fdroid
|
||||
|
||||
build-standalone:
|
||||
if: ${{ inputs.release_type == 'release' || inputs.release_type == 'prerelease' || inputs.flavor == 'standalone' }}
|
||||
build-full:
|
||||
if: ${{ inputs.release_type == 'release' || inputs.release_type == 'nightly' || inputs.release_type == 'prerelease' || inputs.flavor == 'full' }}
|
||||
uses: ./.github/workflows/build.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
build_type: ${{ inputs.release_type }}
|
||||
flavor: standalone
|
||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
||||
flavor: full
|
||||
|
||||
publish:
|
||||
needs:
|
||||
- build-standalone
|
||||
- check_commits
|
||||
- build-full
|
||||
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
||||
name: publish-github
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: main
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt update && sudo apt install -y gh apksigner
|
||||
|
||||
- name: Set TAG_NAME
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
|
||||
elif [ "${{ github.event_name }}" = "schedule" ]; then
|
||||
echo "TAG_NAME=nightly" >> $GITHUB_ENV
|
||||
echo "RELEASE_TYPE=nightly" >> $GITHUB_ENV
|
||||
fi
|
||||
- name: Set latest tag
|
||||
uses: rickstaa/action-create-tag@v1
|
||||
id: tag_creation
|
||||
@@ -92,26 +126,21 @@ jobs:
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
latest: true
|
||||
|
||||
- name: Generate Changelog
|
||||
id: changelog
|
||||
uses: requarks/changelog-action@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
toTag: ${{ steps.latest_release.outputs.tag_name }}
|
||||
toTag: ${{ github.event_name == 'schedule' && 'nightly' || steps.latest_release.outputs.tag_name }}
|
||||
fromTag: "latest"
|
||||
writeToFile: false
|
||||
|
||||
- name: Make download dir
|
||||
run: mkdir ${{ github.workspace }}/temp
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: android_artifacts_*
|
||||
name: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||
path: ${{ github.workspace }}/temp
|
||||
merge-multiple: true
|
||||
|
||||
- name: Set version release notes
|
||||
if: ${{ inputs.release_type == 'release' }}
|
||||
run: |
|
||||
@@ -121,22 +150,36 @@ jobs:
|
||||
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
|
||||
- name: On nightly release notes
|
||||
if: ${{ contains(env.TAG_NAME, 'nightly') }}
|
||||
run: |
|
||||
echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV
|
||||
|
||||
- name: On prerelease release notes
|
||||
if: ${{ inputs.release_type == 'prerelease' }}
|
||||
run: |
|
||||
echo "RELEASE_NOTES=Testing version of app for specific feature." >> $GITHUB_ENV
|
||||
|
||||
- name: Get checksum
|
||||
- name: Delete previous release
|
||||
if: ${{ contains(env.TAG_NAME, 'nightly') || inputs.release_type == 'prerelease' }}
|
||||
uses: ClementTsang/delete-tag-and-release@v0.3.1
|
||||
with:
|
||||
tag_name: ${{ env.TAG_NAME }}
|
||||
delete_release: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get checksums
|
||||
id: checksum
|
||||
run: |
|
||||
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | head -n 1)
|
||||
if [ -z "$file_path" ]; then
|
||||
echo "No APK file found"
|
||||
exit 1
|
||||
fi
|
||||
checksum=$(apksigner verify --print-certs "$file_path" | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")
|
||||
echo "checksum=$checksum" >> $GITHUB_OUTPUT
|
||||
|
||||
checksums=""
|
||||
for file_path in $(find ${{ github.workspace }}/temp -type f -iname "*.apk"); do
|
||||
checksum=$(apksigner verify -print-certs $file_path | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")
|
||||
checksums="$checksums\n$file_path: $checksum"
|
||||
done
|
||||
echo "checksum<<EOF" >> $GITHUB_OUTPUT
|
||||
echo -e "$checksums" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@v2
|
||||
@@ -156,78 +199,12 @@ jobs:
|
||||
|
||||
### Changelog
|
||||
${{ steps.changelog.outputs.changes }}
|
||||
tag_name: ${{ github.event.inputs.tag_name }}
|
||||
name: ${{ github.event.inputs.tag_name }}
|
||||
tag_name: ${{ env.TAG_NAME }}
|
||||
name: ${{ env.TAG_NAME }}
|
||||
draft: false
|
||||
prerelease: ${{ inputs.release_type == 'prerelease' }}
|
||||
prerelease: ${{ inputs.release_type == 'prerelease' || inputs.release_type == '' || inputs.release_type == 'nightly' }}
|
||||
make_latest: ${{ inputs.release_type == 'release' }}
|
||||
files: |
|
||||
${{ github.workspace }}/temp/**/*.apk
|
||||
${{ github.workspace }}/temp/*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
publish-fdroid-public:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build-fdroid
|
||||
if: inputs.release_type == 'release'
|
||||
steps:
|
||||
- name: Dispatch update for fdroid repo
|
||||
uses: peter-evans/repository-dispatch@v3
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
repository: wgtunnel/fdroid
|
||||
event-type: fdroid-update
|
||||
|
||||
publish-play:
|
||||
if: ${{ inputs.track != 'none' }}
|
||||
name: Publish to Google Play
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||
KEY_STORE_FILE: 'android_keystore.jks'
|
||||
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
cache: gradle
|
||||
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
|
||||
# Here we need to decode keystore.jks from base64 string and place it
|
||||
# in the folder specified in the release signing configuration
|
||||
- name: Decode Keystore
|
||||
id: decode_keystore
|
||||
uses: timheuer/base64-to-file@v1.2
|
||||
with:
|
||||
fileName: ${{ env.KEY_STORE_FILE }}
|
||||
fileDir: ${{ env.KEY_STORE_LOCATION }}
|
||||
encodedString: ${{ secrets.KEYSTORE }}
|
||||
|
||||
# create keystore path for gradle to read
|
||||
- name: Create keystore path env var
|
||||
run: |
|
||||
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
||||
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
||||
|
||||
- name: Create service_account.json
|
||||
id: createServiceAccount
|
||||
run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json
|
||||
|
||||
- name: Deploy with fastlane
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: '3.2' # Not needed with a .ruby-version file
|
||||
bundler-cache: true
|
||||
|
||||
- name: Distribute app to Prod track 🚀
|
||||
run: (cd ${{ github.workspace }} && bundle install && bundle exec fastlane ${{ inputs.track }})
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -103,10 +103,7 @@ android {
|
||||
dimension = "type"
|
||||
buildConfigField("String", "FLAVOR", "\"google\"")
|
||||
}
|
||||
create("standalone") {
|
||||
dimension = "type"
|
||||
buildConfigField("String", "FLAVOR", "\"standalone\"")
|
||||
}
|
||||
create("full") { dimension = "type" }
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
|
||||
@@ -166,11 +166,15 @@
|
||||
<receiver
|
||||
android:name=".core.broadcast.RestartReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="false">
|
||||
android:exported="false"
|
||||
android:directBootAware="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SCREEN_ON" />
|
||||
<action android:name="android.intent.action.USER_PRESENT" />
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
@@ -39,6 +39,7 @@ import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.toRoute
|
||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
||||
@@ -109,7 +110,6 @@ class MainActivity : AppCompatActivity() {
|
||||
val isTv = isRunningOnTv()
|
||||
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
||||
val tunnelError by viewModel.tunnelManager.errorEvents.collectAsStateWithLifecycle(null)
|
||||
|
||||
val navController = rememberNavController()
|
||||
val backStackEntry by navController.currentBackStackEntryAsState()
|
||||
@@ -134,7 +134,6 @@ class MainActivity : AppCompatActivity() {
|
||||
vpnPermissionDenied = true
|
||||
} else {
|
||||
vpnPermissionDenied = false
|
||||
showVpnPermissionDialog = false
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -152,15 +151,6 @@ class MainActivity : AppCompatActivity() {
|
||||
viewModel.handleEvent(AppEvent.SetBatteryOptimizeDisableShown)
|
||||
}
|
||||
|
||||
LaunchedEffect(tunnelError) {
|
||||
if (tunnelError == null) return@LaunchedEffect
|
||||
val message = tunnelError!!.second.toStringRes()
|
||||
val context = this@MainActivity
|
||||
snackbar.showSnackbar(
|
||||
context.getString(R.string.tunnel_error_template, context.getString(message))
|
||||
)
|
||||
}
|
||||
|
||||
with(appViewState) {
|
||||
LaunchedEffect(isConfigChanged) {
|
||||
if (isConfigChanged) {
|
||||
@@ -176,6 +166,21 @@ class MainActivity : AppCompatActivity() {
|
||||
viewModel.handleEvent(AppEvent.MessageShown)
|
||||
}
|
||||
}
|
||||
LaunchedEffect(appUiState.activeTunnels) {
|
||||
appUiState.activeTunnels.mapNotNull { (tunnelConf, tunnelState) ->
|
||||
(tunnelState.status as? TunnelStatus.Error)?.let { error ->
|
||||
val message = error.error.toStringRes()
|
||||
val context = this@MainActivity
|
||||
snackbar.showSnackbar(
|
||||
context.getString(
|
||||
R.string.tunnel_error_template,
|
||||
context.getString(message),
|
||||
)
|
||||
)
|
||||
viewModel.handleEvent(AppEvent.ClearTunnelError(tunnelConf))
|
||||
}
|
||||
}
|
||||
}
|
||||
LaunchedEffect(popBackStack) {
|
||||
if (popBackStack) {
|
||||
navController.popBackStack()
|
||||
@@ -209,10 +214,7 @@ class MainActivity : AppCompatActivity() {
|
||||
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||
VpnDeniedDialog(
|
||||
showVpnPermissionDialog,
|
||||
onDismiss = {
|
||||
showVpnPermissionDialog = false
|
||||
vpnPermissionDenied = false
|
||||
},
|
||||
onDismiss = { showVpnPermissionDialog = false },
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
|
||||
+6
-7
@@ -3,12 +3,12 @@ package com.zaneschepke.wireguardautotunnel.core.broadcast
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.zaneschepke.logcatter.LogReader
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
@@ -26,20 +26,20 @@ class RestartReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var tunnelManager: TunnelManager
|
||||
|
||||
@Inject lateinit var logReader: LogReader
|
||||
|
||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
||||
// screen on for Android TV only to help with sleep shutdowns
|
||||
val isTv = context.isRunningOnTv()
|
||||
if (intent.action == Intent.ACTION_SCREEN_ON && !isTv) return
|
||||
if (intent.action == Intent.ACTION_USER_PRESENT && !isTv) return
|
||||
serviceManager.updateTunnelTile()
|
||||
serviceManager.updateAutoTunnelTile()
|
||||
applicationScope.launch(ioDispatcher) {
|
||||
val settings = appDataRepository.settings.get()
|
||||
if (settings.isRestoreOnBootEnabled) {
|
||||
if (
|
||||
settings.isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null
|
||||
) {
|
||||
if (settings.isAutoTunnelEnabled && !serviceManager.autoTunnelActive.value) {
|
||||
Timber.d("Starting auto-tunnel on boot/update")
|
||||
serviceManager.startAutoTunnel()
|
||||
} else {
|
||||
@@ -49,7 +49,6 @@ class RestartReceiver : BroadcastReceiver() {
|
||||
} else {
|
||||
Timber.d("Restore on boot disabled, skipping")
|
||||
}
|
||||
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) logReader.deleteAndClearLogs()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+54
-70
@@ -1,11 +1,10 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.service
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.net.VpnService
|
||||
import android.os.IBinder
|
||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
@@ -14,6 +13,7 @@ import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
||||
import jakarta.inject.Inject
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -37,37 +37,23 @@ constructor(
|
||||
|
||||
private val autoTunnelMutex = Mutex()
|
||||
|
||||
private val _tunnelService = MutableStateFlow<TunnelForegroundService?>(null)
|
||||
private val _autoTunnelService = MutableStateFlow<AutoTunnelService?>(null)
|
||||
val autoTunnelService = _autoTunnelService.asStateFlow()
|
||||
private val _autoTunnelActive = MutableStateFlow(false)
|
||||
val autoTunnelActive = _autoTunnelActive.asStateFlow()
|
||||
|
||||
private val tunnelServiceConnection =
|
||||
object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
||||
val binder = service as? TunnelForegroundService.LocalBinder
|
||||
_tunnelService.value = binder?.service
|
||||
Timber.d("TunnelForegroundService connected")
|
||||
}
|
||||
var autoTunnelService = CompletableDeferred<AutoTunnelService>()
|
||||
var backgroundService = CompletableDeferred<TunnelForegroundService>()
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName) {
|
||||
_tunnelService.value = null
|
||||
Timber.d("TunnelForegroundService disconnected")
|
||||
private fun <T : Service> startService(cls: Class<T>, background: Boolean) {
|
||||
runCatching {
|
||||
val intent = Intent(context, cls)
|
||||
if (background) {
|
||||
context.startForegroundService(intent)
|
||||
} else {
|
||||
context.startService(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val autoTunnelServiceConnection =
|
||||
object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
||||
val binder = service as? AutoTunnelService.LocalBinder
|
||||
_autoTunnelService.value = binder?.service
|
||||
Timber.d("AutoTunnelService connected")
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName) {
|
||||
_autoTunnelService.value = null
|
||||
Timber.d("AutoTunnelService disconnected")
|
||||
}
|
||||
}
|
||||
.onFailure { Timber.e(it) }
|
||||
}
|
||||
|
||||
fun hasVpnPermission(): Boolean {
|
||||
return VpnService.prepare(context) == null
|
||||
@@ -77,13 +63,20 @@ constructor(
|
||||
autoTunnelMutex.withLock {
|
||||
val settings = appDataRepository.settings.get()
|
||||
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = true))
|
||||
if (_autoTunnelService.value != null) return
|
||||
withContext(ioDispatcher) {
|
||||
val intent = Intent(context, AutoTunnelService::class.java)
|
||||
context.startForegroundService(intent)
|
||||
context.bindService(intent, autoTunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||
if (autoTunnelService.isCompleted) {
|
||||
_autoTunnelActive.update { true }
|
||||
return
|
||||
}
|
||||
runCatching {
|
||||
autoTunnelService = CompletableDeferred()
|
||||
startService(AutoTunnelService::class.java, !WireGuardAutoTunnel.isForeground())
|
||||
_autoTunnelActive.update { true }
|
||||
}
|
||||
.onFailure {
|
||||
Timber.e(it)
|
||||
_autoTunnelActive.update { false }
|
||||
}
|
||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,44 +84,43 @@ constructor(
|
||||
autoTunnelMutex.withLock {
|
||||
val settings = appDataRepository.settings.get()
|
||||
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = false))
|
||||
if (_autoTunnelService.value == null) return
|
||||
_autoTunnelService.value?.let { service ->
|
||||
service.stop()
|
||||
try {
|
||||
context.unbindService(autoTunnelServiceConnection)
|
||||
} finally {
|
||||
_tunnelService.value = null
|
||||
if (!autoTunnelService.isCompleted) return
|
||||
runCatching {
|
||||
val service = autoTunnelService.await()
|
||||
service.stop()
|
||||
_autoTunnelActive.update { false }
|
||||
autoTunnelService = CompletableDeferred()
|
||||
}
|
||||
}
|
||||
.onFailure { Timber.e(it) }
|
||||
withContext(mainDispatcher) { updateAutoTunnelTile() }
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun startTunnelForegroundService() {
|
||||
if (_tunnelService.value != null) return
|
||||
withContext(ioDispatcher) {
|
||||
applicationScope.launch(ioDispatcher) {
|
||||
val intent = Intent(context, TunnelForegroundService::class.java)
|
||||
context.startForegroundService(intent)
|
||||
context.bindService(intent, tunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
||||
fun startTunnelForegroundService() {
|
||||
if (backgroundService.isCompleted) return
|
||||
runCatching {
|
||||
backgroundService = CompletableDeferred()
|
||||
startService(
|
||||
TunnelForegroundService::class.java,
|
||||
!WireGuardAutoTunnel.isForeground(),
|
||||
)
|
||||
}
|
||||
}
|
||||
.onFailure { Timber.e(it) }
|
||||
}
|
||||
|
||||
fun stopTunnelForegroundService() {
|
||||
_tunnelService.value?.let { service ->
|
||||
service.stop()
|
||||
try {
|
||||
context.unbindService(tunnelServiceConnection)
|
||||
} finally {
|
||||
_tunnelService.value = null
|
||||
suspend fun stopTunnelForegroundService() {
|
||||
if (!backgroundService.isCompleted) return
|
||||
runCatching {
|
||||
val service = backgroundService.await()
|
||||
service.stop()
|
||||
backgroundService = CompletableDeferred()
|
||||
}
|
||||
}
|
||||
.onFailure { Timber.e(it) }
|
||||
}
|
||||
|
||||
fun toggleAutoTunnel() {
|
||||
applicationScope.launch(ioDispatcher) {
|
||||
if (_autoTunnelService.value != null) stopAutoTunnel() else startAutoTunnel()
|
||||
if (_autoTunnelActive.value) stopAutoTunnel() else startAutoTunnel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,12 +131,4 @@ constructor(
|
||||
fun updateTunnelTile() {
|
||||
context.requestTunnelTileServiceStateUpdate()
|
||||
}
|
||||
|
||||
fun handleTunnelServiceDestroy() {
|
||||
_tunnelService.update { null }
|
||||
}
|
||||
|
||||
fun handleAutoTunnelServiceDestroy() {
|
||||
_autoTunnelService.update { null }
|
||||
}
|
||||
}
|
||||
|
||||
+8
-14
@@ -2,7 +2,6 @@ package com.zaneschepke.wireguardautotunnel.core.service
|
||||
|
||||
import android.app.Notification
|
||||
import android.content.Intent
|
||||
import android.os.Binder
|
||||
import android.os.IBinder
|
||||
import androidx.core.app.ServiceCompat
|
||||
import androidx.lifecycle.LifecycleService
|
||||
@@ -24,6 +23,7 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
@@ -64,12 +64,9 @@ class TunnelForegroundService : LifecycleService() {
|
||||
|
||||
private val jobsMutex = Mutex()
|
||||
|
||||
class LocalBinder(val service: TunnelForegroundService) : Binder()
|
||||
|
||||
private val binder = LocalBinder(this)
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
serviceManager.backgroundService.complete(this)
|
||||
ServiceCompat.startForeground(
|
||||
this@TunnelForegroundService,
|
||||
NotificationManager.VPN_NOTIFICATION_ID,
|
||||
@@ -78,13 +75,14 @@ class TunnelForegroundService : LifecycleService() {
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent): IBinder {
|
||||
override fun onBind(intent: Intent): IBinder? {
|
||||
super.onBind(intent)
|
||||
return binder
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
serviceManager.backgroundService.complete(this)
|
||||
ServiceCompat.startForeground(
|
||||
this@TunnelForegroundService,
|
||||
NotificationManager.VPN_NOTIFICATION_ID,
|
||||
@@ -165,12 +163,8 @@ class TunnelForegroundService : LifecycleService() {
|
||||
} else {
|
||||
pingJobs[tun]?.cancel() // Cancel any stale job
|
||||
if (tun.isPingEnabled) {
|
||||
if (tun.isStaticallyConfigured()) {
|
||||
Timber.d("Skipping ping for statically configured tunnel")
|
||||
} else {
|
||||
pingJobs[tun] = startPingJob(tun)
|
||||
Timber.d("Started ping job for ${tun.tunName}")
|
||||
}
|
||||
pingJobs[tun] = startPingJob(tun)
|
||||
Timber.d("Started ping job for ${tun.tunName}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -279,7 +273,7 @@ class TunnelForegroundService : LifecycleService() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
serviceManager.handleTunnelServiceDestroy()
|
||||
serviceManager.backgroundService = CompletableDeferred()
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
+6
-8
@@ -1,7 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Binder
|
||||
import android.os.IBinder
|
||||
import android.os.PowerManager
|
||||
import androidx.core.app.ServiceCompat
|
||||
@@ -29,6 +28,7 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
@@ -68,23 +68,21 @@ class AutoTunnelService : LifecycleService() {
|
||||
|
||||
private var killSwitchJob: Job? = null
|
||||
|
||||
class LocalBinder(val service: AutoTunnelService) : Binder()
|
||||
|
||||
private val binder = LocalBinder(this)
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
serviceManager.autoTunnelService.complete(this)
|
||||
launchWatcherNotification()
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent): IBinder {
|
||||
override fun onBind(intent: Intent): IBinder? {
|
||||
super.onBind(intent)
|
||||
return binder
|
||||
return null
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
Timber.d("onStartCommand executed with startId: $startId")
|
||||
serviceManager.autoTunnelService.complete(this)
|
||||
start()
|
||||
return START_STICKY
|
||||
}
|
||||
@@ -107,7 +105,7 @@ class AutoTunnelService : LifecycleService() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
serviceManager.handleAutoTunnelServiceDestroy()
|
||||
serviceManager.autoTunnelService = CompletableDeferred()
|
||||
restoreVpnKillSwitch()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
+3
-3
@@ -38,8 +38,8 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
||||
Timber.d("Start listening called for auto tunnel tile")
|
||||
lifecycleScope.launch {
|
||||
serviceManager.autoTunnelService.collect {
|
||||
if (it != null) return@collect setActive()
|
||||
serviceManager.autoTunnelActive.collect {
|
||||
if (it) return@collect setActive()
|
||||
setInactive()
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
||||
super.onClick()
|
||||
unlockAndRun {
|
||||
lifecycleScope.launch {
|
||||
if (serviceManager.autoTunnelService.value != null) {
|
||||
if (serviceManager.autoTunnelActive.value) {
|
||||
serviceManager.stopAutoTunnel()
|
||||
setInactive()
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||
|
||||
import com.wireguard.android.backend.BackendException
|
||||
import com.wireguard.android.backend.Tunnel
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
@@ -10,11 +11,14 @@ import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.concurrent.thread
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
@@ -27,10 +31,6 @@ abstract class BaseTunnel(
|
||||
private val serviceManager: ServiceManager,
|
||||
) : TunnelProvider {
|
||||
|
||||
private val _errorEvents =
|
||||
MutableSharedFlow<Pair<TunnelConf, BackendError>>(replay = 0, extraBufferCapacity = 1)
|
||||
override val errorEvents = _errorEvents.asSharedFlow()
|
||||
|
||||
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
||||
private val tunThreads = ConcurrentHashMap<Int, Thread>()
|
||||
override val activeTunnels = activeTuns.asStateFlow()
|
||||
@@ -45,34 +45,37 @@ abstract class BaseTunnel(
|
||||
|
||||
abstract fun stopBackend(tunnel: TunnelConf)
|
||||
|
||||
override suspend fun clearError(tunnelConf: TunnelConf) =
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||
|
||||
override fun hasVpnPermission(): Boolean {
|
||||
return serviceManager.hasVpnPermission()
|
||||
}
|
||||
|
||||
protected suspend fun updateTunnelStatus(
|
||||
tunnelConf: TunnelConf,
|
||||
status: TunnelStatus? = null,
|
||||
state: TunnelStatus? = null,
|
||||
stats: TunnelStatistics? = null,
|
||||
) {
|
||||
tunStatusMutex.withLock {
|
||||
activeTuns.update { currentTuns ->
|
||||
val originalConf = currentTuns.getKeyById(tunnelConf.id) ?: tunnelConf
|
||||
val existingState = currentTuns.getValueById(tunnelConf.id) ?: TunnelState()
|
||||
val newState = status ?: existingState.status
|
||||
activeTuns.update { current ->
|
||||
val originalConf = current.getKeyById(tunnelConf.id) ?: tunnelConf
|
||||
val existingState = current.getValueById(tunnelConf.id) ?: TunnelState()
|
||||
val newState = state ?: existingState.status
|
||||
if (newState == TunnelStatus.Down) {
|
||||
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
||||
cleanUpTunThread(tunnelConf)
|
||||
currentTuns - originalConf
|
||||
current - originalConf
|
||||
} else if (existingState.status == newState && stats == null) {
|
||||
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
||||
currentTuns
|
||||
current
|
||||
} else {
|
||||
val updated =
|
||||
existingState.copy(
|
||||
status = newState,
|
||||
statistics = stats ?: existingState.statistics,
|
||||
)
|
||||
currentTuns + (originalConf to updated)
|
||||
current + (originalConf to updated)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,17 +117,23 @@ abstract class BaseTunnel(
|
||||
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
||||
tunMutex.withLock {
|
||||
tunThreads[tunnelConf.id] = thread {
|
||||
runBlocking {
|
||||
try {
|
||||
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
||||
startTunnelInner(tunnelConf)
|
||||
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
||||
} catch (e: InterruptedException) {
|
||||
Timber.w(
|
||||
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
||||
)
|
||||
runCatching {
|
||||
runBlocking {
|
||||
try {
|
||||
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
||||
startTunnelInner(tunnelConf)
|
||||
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
||||
} catch (e: BackendError) {
|
||||
Timber.e(e, "Failed to start tunnel ${tunnelConf.name} userspace")
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(e))
|
||||
} catch (e: InterruptedException) {
|
||||
Timber.w(
|
||||
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onFailure { Timber.w("Tunnel start has been interrupted") }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,10 +147,11 @@ abstract class BaseTunnel(
|
||||
Timber.d("Started for tun ${tunnelConf.id}...")
|
||||
saveTunnelActiveState(tunnelConf, true)
|
||||
serviceManager.startTunnelForegroundService()
|
||||
} catch (e: BackendError) {
|
||||
} catch (e: BackendException) {
|
||||
Timber.e(e, "Failed to start backend for ${tunnelConf.name}")
|
||||
_errorEvents.emit(tunnelConf to e)
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||
val backendError = e.toBackendError()
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(backendError))
|
||||
throw backendError
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,27 +163,26 @@ abstract class BaseTunnel(
|
||||
override suspend fun stopTunnel(tunnelConf: TunnelConf?, reason: TunnelStatus.StopReason) {
|
||||
if (tunnelConf == null) return stopActiveTunnels()
|
||||
tunMutex.withLock {
|
||||
if (activeTuns.isStarting(tunnelConf.id))
|
||||
return handleStuckStartingTunnelShutdown(tunnelConf)
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Stopping(reason))
|
||||
stopTunnelInner(tunnelConf)
|
||||
try {
|
||||
if (activeTuns.isStarting(tunnelConf.id))
|
||||
return handleStuckStartingTunnelShutdown(tunnelConf)
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Stopping(reason))
|
||||
stopTunnelInner(tunnelConf)
|
||||
} catch (e: BackendError) {
|
||||
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Error(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun stopTunnelInner(tunnelConf: TunnelConf) {
|
||||
try {
|
||||
val tunnel = activeTuns.findTunnel(tunnelConf.id) ?: return
|
||||
stopBackend(tunnel)
|
||||
saveTunnelActiveState(tunnelConf, false)
|
||||
removeActiveTunnel(tunnel)
|
||||
} catch (e: BackendError) {
|
||||
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
||||
_errorEvents.emit(tunnelConf to e)
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||
}
|
||||
val tunnel = activeTuns.findTunnel(tunnelConf.id) ?: return
|
||||
stopBackend(tunnel)
|
||||
saveTunnelActiveState(tunnelConf, false)
|
||||
removeActiveTunnel(tunnel)
|
||||
}
|
||||
|
||||
private fun handleServiceStateOnChange() {
|
||||
private suspend fun handleServiceStateOnChange() {
|
||||
if (activeTuns.value.isEmpty() && bouncingTunnelIds.isEmpty())
|
||||
serviceManager.stopTunnelForegroundService()
|
||||
}
|
||||
@@ -184,15 +193,15 @@ abstract class BaseTunnel(
|
||||
tunThreads[tunnel.id]?.let {
|
||||
if (it.state != Thread.State.TERMINATED) {
|
||||
it.interrupt()
|
||||
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
||||
} else {
|
||||
Timber.d("Thread already terminated")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Failed to stop tunnel thread for ${tunnel.name}")
|
||||
} finally {
|
||||
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
||||
}
|
||||
cleanUpTunThread(tunnel)
|
||||
}
|
||||
|
||||
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
||||
@@ -212,7 +221,7 @@ abstract class BaseTunnel(
|
||||
bouncingTunnelIds[tunnelConf.id] = reason
|
||||
try {
|
||||
stopTunnel(tunnelConf, reason)
|
||||
delay(BOUNCE_DELAY)
|
||||
delay(300L)
|
||||
startTunnel(tunnelConf)
|
||||
} finally {
|
||||
bouncingTunnelIds.remove(tunnelConf.id)
|
||||
@@ -226,8 +235,4 @@ abstract class BaseTunnel(
|
||||
|
||||
override suspend fun runningTunnelNames(): Set<String> =
|
||||
activeTuns.value.keys.map { it.tunName }.toSet()
|
||||
|
||||
companion object {
|
||||
const val BOUNCE_DELAY = 300L
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
||||
import com.zaneschepke.wireguardautotunnel.di.Userspace
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
@@ -16,7 +15,6 @@ import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
@@ -64,9 +62,6 @@ constructor(
|
||||
initialValue = emptyMap(),
|
||||
)
|
||||
|
||||
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||
get() = tunnelProviderFlow.value.errorEvents
|
||||
|
||||
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
||||
tunnelProviderFlow.value.bouncingTunnelIds
|
||||
|
||||
@@ -74,6 +69,10 @@ constructor(
|
||||
return userspaceTunnel.hasVpnPermission()
|
||||
}
|
||||
|
||||
override suspend fun clearError(tunnelConf: TunnelConf) {
|
||||
tunnelProviderFlow.value.clearError(tunnelConf)
|
||||
}
|
||||
|
||||
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
||||
tunnelProviderFlow.value.updateTunnelStatistics(tunnel)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface TunnelProvider {
|
||||
@@ -48,11 +46,11 @@ interface TunnelProvider {
|
||||
|
||||
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
||||
|
||||
val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||
|
||||
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
||||
|
||||
fun hasVpnPermission(): Boolean
|
||||
|
||||
suspend fun clearError(tunnelConf: TunnelConf)
|
||||
|
||||
suspend fun updateTunnelStatistics(tunnel: TunnelConf)
|
||||
}
|
||||
|
||||
+2
-3
@@ -50,9 +50,8 @@ constructor(
|
||||
} catch (e: BackendException) {
|
||||
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
||||
throw e.toBackendError()
|
||||
} finally {
|
||||
handlePreviouslyEnabledVpnKillSwitch()
|
||||
}
|
||||
handlePreviouslyEnabledVpnKillSwitch()
|
||||
}
|
||||
|
||||
// stop vpn kill switch if we need to resolve DNS for peer endpoints
|
||||
@@ -70,7 +69,7 @@ constructor(
|
||||
// restore vpn kill switch if needed
|
||||
private fun handlePreviouslyEnabledVpnKillSwitch() {
|
||||
// let auto tunnel handle this if it is active
|
||||
if (serviceManager.autoTunnelService.value == null) {
|
||||
if (!serviceManager.autoTunnelActive.value) {
|
||||
previousBackendState?.let { (state, lanEnabled) ->
|
||||
Timber.d("Restoring kill switch configuration")
|
||||
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
|
||||
|
||||
@@ -57,7 +57,7 @@ constructor(
|
||||
withContext(ioDispatcher) {
|
||||
Timber.i("Service worker started")
|
||||
with(appDataRepository.settings.get()) {
|
||||
if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null)
|
||||
if (isAutoTunnelEnabled && !serviceManager.autoTunnelActive.value)
|
||||
return@with serviceManager.startAutoTunnel()
|
||||
if (tunnelManager.activeTunnels.value.isEmpty())
|
||||
tunnelManager.restorePreviousState()
|
||||
|
||||
@@ -60,10 +60,6 @@ data class TunnelConf(
|
||||
return result
|
||||
}
|
||||
|
||||
fun isStaticallyConfigured(): Boolean {
|
||||
return toAmConfig().peers.all { it.endpoint.get().host.isValidIpv4orIpv6Address() }
|
||||
}
|
||||
|
||||
fun copyWithCallback(
|
||||
id: Int = this.id,
|
||||
tunName: String = this.tunName,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||
|
||||
sealed class TunnelStatus {
|
||||
data class Error(val error: BackendError) : TunnelStatus()
|
||||
|
||||
data object Up : TunnelStatus()
|
||||
|
||||
|
||||
-1
@@ -12,7 +12,6 @@ class AmneziaStatistics(private val statistics: Statistics) : TunnelStatistics()
|
||||
rxBytes = stats.rxBytes,
|
||||
txBytes = stats.txBytes,
|
||||
latestHandshakeEpochMillis = stats.latestHandshakeEpochMillis,
|
||||
resolvedEndpoint = stats.resolvedEndpoint,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ abstract class TunnelStatistics {
|
||||
val rxBytes: Long,
|
||||
val txBytes: Long,
|
||||
val latestHandshakeEpochMillis: Long,
|
||||
val resolvedEndpoint: String,
|
||||
)
|
||||
|
||||
abstract fun peerStats(peer: Key): PeerStats?
|
||||
|
||||
-1
@@ -12,7 +12,6 @@ class WireGuardStatistics(private val statistics: Statistics) : TunnelStatistics
|
||||
txBytes = peerStats.txBytes,
|
||||
rxBytes = peerStats.rxBytes,
|
||||
latestHandshakeEpochMillis = peerStats.latestHandshakeEpochMillis,
|
||||
resolvedEndpoint = peerStats.resolvedEndpoint,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+23
-15
@@ -2,21 +2,22 @@ package com.zaneschepke.wireguardautotunnel.ui.common
|
||||
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.indication
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.PressInteraction
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.ripple
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
@@ -43,25 +44,32 @@ fun ExpandingRowListItem(
|
||||
modifier =
|
||||
Modifier.animateContentSize()
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.background(
|
||||
if (isSelected) MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
|
||||
else Color.Transparent
|
||||
)
|
||||
.then(
|
||||
if (!isTv) {
|
||||
Modifier.combinedClickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = ripple(),
|
||||
onClick = onClick,
|
||||
onLongClick = {
|
||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onHold()
|
||||
},
|
||||
onDoubleClick = onDoubleClick,
|
||||
)
|
||||
onClick = onClick,
|
||||
onLongClick = {
|
||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onHold()
|
||||
},
|
||||
onDoubleClick = onDoubleClick,
|
||||
)
|
||||
.indication(
|
||||
interactionSource = interactionSource,
|
||||
indication = ripple(),
|
||||
)
|
||||
} else Modifier
|
||||
)
|
||||
) {
|
||||
LaunchedEffect(isSelected) {
|
||||
if (isSelected) {
|
||||
interactionSource.emit(PressInteraction.Press(Offset.Zero))
|
||||
} else {
|
||||
interactionSource.emit(
|
||||
PressInteraction.Release(PressInteraction.Press(Offset.Zero))
|
||||
)
|
||||
}
|
||||
}
|
||||
Column {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.functions
|
||||
|
||||
import android.content.ClipData
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.platform.ClipEntry
|
||||
import androidx.compose.ui.platform.Clipboard
|
||||
import androidx.compose.ui.platform.LocalClipboard
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ClipboardHelper(
|
||||
private val clipboard: Clipboard,
|
||||
private val coroutineScope: CoroutineScope,
|
||||
private val dispatcher: CoroutineDispatcher = Dispatchers.Main,
|
||||
) {
|
||||
fun copy(text: String, label: String = "") {
|
||||
coroutineScope.launch(dispatcher) {
|
||||
val clipData = ClipData.newPlainText(label, text)
|
||||
clipboard.setClipEntry(ClipEntry(clipData))
|
||||
}
|
||||
}
|
||||
|
||||
fun paste(onResult: (String?) -> Unit) {
|
||||
coroutineScope.launch(dispatcher) {
|
||||
val entry = clipboard.getClipEntry()
|
||||
val text = entry?.clipData?.getItemAt(0)?.text?.toString()
|
||||
onResult(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberClipboardHelper(
|
||||
coroutineScope: CoroutineScope = rememberCoroutineScope()
|
||||
): ClipboardHelper {
|
||||
val clipboard = LocalClipboard.current
|
||||
return remember(clipboard, coroutineScope) { ClipboardHelper(clipboard, coroutineScope) }
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.PublicOff
|
||||
import androidx.compose.material.icons.outlined.AirplanemodeActive
|
||||
import androidx.compose.material.icons.outlined.SettingsEthernet
|
||||
import androidx.compose.material.icons.outlined.SignalCellular4Bar
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -95,7 +95,7 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
||||
),
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Outlined.PublicOff,
|
||||
leadingIcon = Icons.Outlined.AirplanemodeActive,
|
||||
title = {
|
||||
Text(
|
||||
stringResource(R.string.stop_on_no_internet),
|
||||
|
||||
+20
-31
@@ -22,15 +22,16 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.networkmonitor.NetworkStatus
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LearnMoreLinkLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||
@@ -47,7 +48,7 @@ fun WifiTunnelingItems(
|
||||
isWifiNameReadable: () -> Boolean,
|
||||
): List<SelectionItem> {
|
||||
val context = LocalContext.current
|
||||
val clipboardHelper = rememberClipboardHelper()
|
||||
val clipboard = LocalClipboardManager.current
|
||||
|
||||
val baseItems =
|
||||
listOf(
|
||||
@@ -70,41 +71,29 @@ fun WifiTunnelingItems(
|
||||
)
|
||||
},
|
||||
description = {
|
||||
val wifiInfo by
|
||||
val wifiName by
|
||||
remember(uiState.networkStatus) {
|
||||
derivedStateOf {
|
||||
(uiState.networkStatus as? NetworkStatus.Connected)
|
||||
?.takeIf { it.wifiConnected }
|
||||
.let { Pair(it?.wifiSsid, it?.securityType) }
|
||||
?.wifiSsid
|
||||
}
|
||||
}
|
||||
val (wifiName, securityType) = wifiInfo
|
||||
Column {
|
||||
Text(
|
||||
text =
|
||||
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
||||
?: stringResource(R.string.inactive),
|
||||
style =
|
||||
MaterialTheme.typography.bodySmall.copy(
|
||||
color = MaterialTheme.colorScheme.outline
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier =
|
||||
Modifier.clickable { wifiName?.let { clipboardHelper.copy(it) } },
|
||||
)
|
||||
securityType?.let {
|
||||
Text(
|
||||
text = stringResource(R.string.security_template, it.name),
|
||||
style =
|
||||
MaterialTheme.typography.bodySmall.copy(
|
||||
color = MaterialTheme.colorScheme.outline
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
Text(
|
||||
text =
|
||||
wifiName?.let { stringResource(R.string.wifi_name_template, it) }
|
||||
?: stringResource(R.string.inactive),
|
||||
style =
|
||||
MaterialTheme.typography.bodySmall.copy(
|
||||
color = MaterialTheme.colorScheme.outline
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier =
|
||||
Modifier.clickable {
|
||||
wifiName?.let { clipboard.setText(AnnotatedString(it)) }
|
||||
},
|
||||
)
|
||||
},
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnWifi) },
|
||||
),
|
||||
|
||||
@@ -7,12 +7,12 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberFileImportLauncherForResult
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.components.ExportTunnelsBottomSheet
|
||||
@@ -29,7 +29,7 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
@Composable
|
||||
fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: AppViewModel) {
|
||||
val navController = LocalNavController.current
|
||||
val clipboard = rememberClipboardHelper()
|
||||
val clipboard = LocalClipboardManager.current
|
||||
|
||||
var showUrlImportDialog by remember { mutableStateOf(false) }
|
||||
|
||||
@@ -90,9 +90,8 @@ fun MainScreen(appUiState: AppUiState, appViewState: AppViewState, viewModel: Ap
|
||||
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
|
||||
},
|
||||
onClipboardClick = {
|
||||
clipboard.paste { result ->
|
||||
if (result != null)
|
||||
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(result))
|
||||
clipboard.getText()?.text?.let {
|
||||
viewModel.handleEvent(AppEvent.ImportTunnelFromClipboard(it))
|
||||
}
|
||||
},
|
||||
onManualImportClick = {
|
||||
|
||||
+4
-18
@@ -7,7 +7,6 @@ import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.overscroll
|
||||
import androidx.compose.foundation.rememberOverscrollEffect
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -19,7 +18,6 @@ import com.zaneschepke.wireguardautotunnel.core.tunnel.getValueById
|
||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||
@@ -37,19 +35,12 @@ fun TunnelList(
|
||||
onToggleTunnel: (TunnelConf, Boolean) -> Unit,
|
||||
viewModel: AppViewModel,
|
||||
) {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
val context = LocalContext.current
|
||||
val navController = LocalNavController.current
|
||||
val collator = Collator.getInstance(Locale.getDefault())
|
||||
val sortedTunnels =
|
||||
remember(appUiState.tunnels) {
|
||||
appUiState.tunnels.sortedWith(
|
||||
compareBy(
|
||||
// primary tunnel first
|
||||
{ !it.isPrimaryTunnel },
|
||||
{ collator.compare(it.tunName, "") },
|
||||
)
|
||||
)
|
||||
appUiState.tunnels.sortedWith(compareBy(collator) { it.tunName })
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
@@ -58,7 +49,7 @@ fun TunnelList(
|
||||
modifier =
|
||||
modifier
|
||||
.pointerInput(Unit) { if (appUiState.tunnels.isEmpty()) return@pointerInput }
|
||||
.overscroll(rememberOverscrollEffect()),
|
||||
.overscroll(ScrollableDefaults.overscrollEffect()),
|
||||
state = rememberLazyListState(0, appUiState.tunnels.count()),
|
||||
userScrollEnabled = true,
|
||||
reverseLayout = false,
|
||||
@@ -80,12 +71,8 @@ fun TunnelList(
|
||||
tunnel = tunnel,
|
||||
tunnelState = tunnelState,
|
||||
onClick = {
|
||||
if (selectedTunnels.isNotEmpty() && !isTv) {
|
||||
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(tunnel))
|
||||
} else {
|
||||
navController.navigate(Route.TunnelOptions(tunnel.id))
|
||||
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||
}
|
||||
navController.navigate(Route.TunnelOptions(tunnel.id))
|
||||
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||
},
|
||||
onDoubleClick = {
|
||||
viewModel.handleEvent(AppEvent.ToggleTunnelStatsExpanded(tunnel.id))
|
||||
@@ -94,7 +81,6 @@ fun TunnelList(
|
||||
viewModel.handleEvent(AppEvent.ToggleSelectedTunnel(it))
|
||||
},
|
||||
onSwitchClick = { checked -> onToggleTunnel(tunnel, checked) },
|
||||
isTv = isTv,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -26,6 +26,7 @@ import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.ExpandingRowListItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asColor
|
||||
|
||||
@Composable
|
||||
@@ -39,8 +40,9 @@ fun TunnelRowItem(
|
||||
onDoubleClick: () -> Unit,
|
||||
onToggleSelectedTunnel: (TunnelConf) -> Unit,
|
||||
onSwitchClick: (Boolean) -> Unit,
|
||||
isTv: Boolean,
|
||||
) {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
|
||||
val leadingIconColor =
|
||||
remember(state) {
|
||||
if (state.status.isUp()) tunnelState.statistics.asColor() else Color.Gray
|
||||
|
||||
+23
-67
@@ -8,9 +8,6 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -24,90 +21,49 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.toThreeDecimalPlaceSt
|
||||
@Composable
|
||||
fun TunnelStatisticsRow(statistics: TunnelStatistics?, tunnelConf: TunnelConf) {
|
||||
val config = TunnelConf.configFromAmQuick(tunnelConf.wgQuick)
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(start = 45.dp, bottom = 10.dp, end = 10.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp, Alignment.CenterVertically),
|
||||
horizontalAlignment = Alignment.Start,
|
||||
) {
|
||||
config.peers.forEach { peer ->
|
||||
val peerId = remember { peer.publicKey.toBase64().subSequence(0, 3).toString() + "***" }
|
||||
val endpoint =
|
||||
remember(statistics) { statistics?.peerStats(peer.publicKey)?.resolvedEndpoint }
|
||||
val peerRxMB by
|
||||
remember(statistics) {
|
||||
derivedStateOf {
|
||||
statistics
|
||||
?.peerStats(peer.publicKey)
|
||||
?.rxBytes
|
||||
?.let { NumberUtils.bytesToMB(it) }
|
||||
?.toThreeDecimalPlaceString()
|
||||
config.peers.forEach { peer ->
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(end = 10.dp, bottom = 10.dp, start = 45.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(5.dp, Alignment.Start),
|
||||
) {
|
||||
val peerId = peer.publicKey.toBase64().subSequence(0, 3).toString() + "***"
|
||||
val peerRx = statistics?.peerStats(peer.publicKey)?.rxBytes ?: 0
|
||||
val peerTx = statistics?.peerStats(peer.publicKey)?.txBytes ?: 0
|
||||
val peerTxMB = NumberUtils.bytesToMB(peerTx).toThreeDecimalPlaceString()
|
||||
val peerRxMB = NumberUtils.bytesToMB(peerRx).toThreeDecimalPlaceString()
|
||||
val handshake =
|
||||
statistics?.peerStats(peer.publicKey)?.latestHandshakeEpochMillis?.let {
|
||||
if (it == 0L) {
|
||||
stringResource(R.string.never)
|
||||
} else {
|
||||
"${NumberUtils.getSecondsBetweenTimestampAndNow(it)} ${stringResource(R.string.sec)}"
|
||||
}
|
||||
}
|
||||
val peerTxMB by
|
||||
remember(statistics) {
|
||||
derivedStateOf {
|
||||
statistics
|
||||
?.peerStats(peer.publicKey)
|
||||
?.txBytes
|
||||
?.let { NumberUtils.bytesToMB(it) }
|
||||
?.toThreeDecimalPlaceString()
|
||||
}
|
||||
}
|
||||
val handshake by
|
||||
remember(statistics) {
|
||||
derivedStateOf {
|
||||
statistics?.peerStats(peer.publicKey)?.latestHandshakeEpochMillis?.let {
|
||||
if (it == 0L) {
|
||||
null
|
||||
} else {
|
||||
"${NumberUtils.getSecondsBetweenTimestampAndNow(it)}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
||||
) {
|
||||
} ?: stringResource(R.string.never)
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Text(
|
||||
stringResource(R.string.peer).lowercase() + ": $peerId",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
)
|
||||
Text(
|
||||
stringResource(R.string.handshake) +
|
||||
": ${if(handshake == null) stringResource(R.string.never) else handshake + " " + stringResource(R.string.sec)}",
|
||||
"tx: $peerTxMB MB",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
)
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
||||
) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Text(
|
||||
"rx: ${peerRxMB ?: 0.00} MB",
|
||||
stringResource(R.string.handshake) + ": $handshake",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
)
|
||||
Text(
|
||||
"tx: ${peerTxMB ?: 0.00} MB",
|
||||
"rx: $peerRxMB MB",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
)
|
||||
}
|
||||
if (endpoint != null) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
|
||||
) {
|
||||
Text(
|
||||
"endpoint: $endpoint",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -16,15 +16,16 @@ import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.InterfaceProxy
|
||||
|
||||
@Composable
|
||||
@@ -37,7 +38,7 @@ fun InterfaceFields(
|
||||
onInterfaceChange: (InterfaceProxy) -> Unit,
|
||||
) {
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
val clipboardManager = rememberClipboardHelper()
|
||||
val clipboardManager = LocalClipboardManager.current
|
||||
val keyboardActions = KeyboardActions(onDone = { keyboardController?.hide() })
|
||||
val keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
|
||||
|
||||
@@ -52,9 +53,8 @@ fun InterfaceFields(
|
||||
if (isAuthenticated) VisualTransformation.None else PasswordVisualTransformation(),
|
||||
trailingIcon = {
|
||||
IconButton(
|
||||
enabled = true,
|
||||
enabled = isAuthenticated,
|
||||
onClick = {
|
||||
if (!isAuthenticated) return@IconButton showAuthPrompt()
|
||||
val keypair = com.wireguard.crypto.KeyPair()
|
||||
onInterfaceChange(
|
||||
interfaceState.copy(
|
||||
@@ -88,7 +88,9 @@ fun InterfaceFields(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
singleLine = true,
|
||||
trailingIcon = {
|
||||
IconButton(onClick = { clipboardManager.copy(interfaceState.publicKey) }) {
|
||||
IconButton(
|
||||
onClick = { clipboardManager.setText(AnnotatedString(interfaceState.publicKey)) }
|
||||
) {
|
||||
Icon(Icons.Rounded.ContentCopy, stringResource(R.string.copy_public_key))
|
||||
}
|
||||
},
|
||||
|
||||
+17
-15
@@ -1,15 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
@@ -37,16 +34,21 @@ fun SplitTunnelScreen(
|
||||
appViewModel.handleEvent(AppEvent.PopBackStack(true))
|
||||
}
|
||||
}
|
||||
if (uiState.loading) {
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
CircularProgressIndicator(modifier = Modifier.size(30.dp), strokeWidth = 5.dp)
|
||||
|
||||
Crossfade(
|
||||
targetState = uiState.loading,
|
||||
animationSpec = tween(200),
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) { isLoading ->
|
||||
if (isLoading) {
|
||||
SplitTunnelSkeleton()
|
||||
} else {
|
||||
SplitTunnelContent(
|
||||
uiState = uiState,
|
||||
onSplitOptionChange = viewModel::updateSplitOption,
|
||||
onAppSelectionToggle = viewModel::toggleAppSelection,
|
||||
onQueryChange = viewModel::onSearchQuery,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
SplitTunnelContent(
|
||||
uiState = uiState,
|
||||
onSplitOptionChange = viewModel::updateSplitOption,
|
||||
onAppSelectionToggle = viewModel::toggleAppSelection,
|
||||
onQueryChange = viewModel::onSearchQuery,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.animation.ShimmerEffect
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||
|
||||
@Composable
|
||||
fun SplitTunnelSkeleton() {
|
||||
val shimmerBrush = ShimmerEffect()
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.CenterVertically),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 24.dp),
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp).height(45.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
repeat(3) {
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.weight(1f)
|
||||
.height(45.dp)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.background(shimmerBrush)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp).height(45.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.height(45.dp)
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.background(shimmerBrush)
|
||||
)
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
contentPadding = PaddingValues(top = 10.dp),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
items(20) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp, vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.size(iconSize).clip(CircleShape).background(shimmerBrush)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Box(
|
||||
modifier =
|
||||
Modifier.height(20.dp)
|
||||
.weight(1f)
|
||||
.clip(RoundedCornerShape(4.dp))
|
||||
.background(shimmerBrush)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Box(modifier = Modifier.size(24.dp).clip(CircleShape).background(shimmerBrush))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -18,6 +18,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import java.text.Collator
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
@@ -49,6 +50,7 @@ constructor(
|
||||
tunnelId?.let { loadInitialState(it) }
|
||||
}
|
||||
|
||||
// TODO improve this loading experience
|
||||
private fun loadInitialState(tunnelId: Int) =
|
||||
viewModelScope.launch {
|
||||
val tunnel = tunnelRepository.getById(tunnelId) ?: return@launch
|
||||
@@ -64,7 +66,7 @@ constructor(
|
||||
|
||||
val installedPackages = packages.map { it.packageName }.toSet()
|
||||
|
||||
// Remove uninstalled apps
|
||||
// remove uninstalled apps
|
||||
proxyInterface.includedApplications.retainAll { it in installedPackages }
|
||||
proxyInterface.excludedApplications.retainAll { it in installedPackages }
|
||||
|
||||
@@ -96,13 +98,12 @@ constructor(
|
||||
selected,
|
||||
)
|
||||
}
|
||||
.sortedWith(
|
||||
compareByDescending<Pair<TunnelApp, Boolean>> { it.second }
|
||||
.thenBy(collator) { it.first.name }
|
||||
)
|
||||
.sortedWith(compareBy(collator) { it.first.name })
|
||||
|
||||
allTunneledApps = tunneledApps
|
||||
|
||||
delay(500)
|
||||
|
||||
_uiState.update {
|
||||
SplitTunnelUiState(
|
||||
loading = false,
|
||||
|
||||
+5
-3
@@ -8,19 +8,20 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
|
||||
@Composable
|
||||
fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionItem {
|
||||
val clipboardManager = rememberClipboardHelper()
|
||||
val clipboardManager = LocalClipboardManager.current
|
||||
|
||||
return SelectionItem(
|
||||
leadingIcon = Icons.Filled.SmartToy,
|
||||
@@ -41,7 +42,8 @@ fun RemoteControlItem(uiState: AppUiState, viewModel: AppViewModel): SelectionIt
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.clickable { clipboardManager.copy(key) },
|
||||
modifier =
|
||||
Modifier.clickable { clipboardManager.setText(AnnotatedString(key)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+20
-16
@@ -23,21 +23,25 @@ fun DisplayScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
||||
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.Top),
|
||||
modifier = Modifier.fillMaxSize().padding(top = 24.dp).padding(horizontal = 24.dp),
|
||||
) {
|
||||
enumValues<Theme>().forEach {
|
||||
val title =
|
||||
when (it) {
|
||||
Theme.DARK -> stringResource(R.string.dark)
|
||||
Theme.LIGHT -> stringResource(R.string.light)
|
||||
Theme.AUTOMATIC -> stringResource(R.string.automatic)
|
||||
Theme.DYNAMIC -> stringResource(R.string.dynamic)
|
||||
Theme.DARKER -> stringResource(R.string.darker)
|
||||
Theme.AMOLED -> stringResource(R.string.amoled)
|
||||
}
|
||||
IconSurfaceButton(
|
||||
title = title,
|
||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(it)) },
|
||||
selected = appUiState.appState.theme == it,
|
||||
)
|
||||
}
|
||||
IconSurfaceButton(
|
||||
title = stringResource(R.string.automatic),
|
||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.AUTOMATIC)) },
|
||||
selected = appUiState.appState.theme == Theme.AUTOMATIC,
|
||||
)
|
||||
IconSurfaceButton(
|
||||
title = stringResource(R.string.light),
|
||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.LIGHT)) },
|
||||
selected = appUiState.appState.theme == Theme.LIGHT,
|
||||
)
|
||||
IconSurfaceButton(
|
||||
title = stringResource(R.string.dark),
|
||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.DARK)) },
|
||||
selected = appUiState.appState.theme == Theme.DARK,
|
||||
)
|
||||
IconSurfaceButton(
|
||||
title = stringResource(R.string.dynamic),
|
||||
onClick = { viewModel.handleEvent(AppEvent.SetTheme(Theme.DYNAMIC)) },
|
||||
selected = appUiState.appState.theme == Theme.DYNAMIC,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -11,16 +11,17 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.zaneschepke.logcatter.model.LogMessage
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.LogTypeLabel
|
||||
|
||||
@Composable
|
||||
fun LogItem(log: LogMessage) {
|
||||
val clipboardManager = rememberClipboardHelper()
|
||||
val clipboardManager = LocalClipboardManager.current
|
||||
val fontSize = 10.sp
|
||||
|
||||
Row(
|
||||
@@ -31,7 +32,7 @@ fun LogItem(log: LogMessage) {
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = null,
|
||||
onClick = { clipboardManager.copy(log.toString()) },
|
||||
onClick = { clipboardManager.setText(AnnotatedString(log.toString())) },
|
||||
),
|
||||
) {
|
||||
Text(text = log.tag, modifier = Modifier.fillMaxSize(0.3f), fontSize = fontSize)
|
||||
|
||||
+3
-9
@@ -23,7 +23,6 @@ import com.zaneschepke.wireguardautotunnel.ui.common.label.GroupLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.ContactSupportOptions
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.GeneralSupportOptions
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.components.UpdateSection
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.canInstallPackages
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestInstallPackagesPermission
|
||||
@@ -55,7 +54,7 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
||||
InfoDialog(
|
||||
onDismiss = { viewModel.handleUpdateShown() },
|
||||
onAttest = {
|
||||
if (BuildConfig.FLAVOR != Constants.STANDALONE_FLAVOR) {
|
||||
if (BuildConfig.FLAVOR != "full") {
|
||||
uiState.appUpdate?.apkUrl?.let { context.openWebUrl(it) }
|
||||
return@InfoDialog
|
||||
}
|
||||
@@ -87,8 +86,7 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
||||
},
|
||||
confirmText = {
|
||||
Text(
|
||||
if (BuildConfig.FLAVOR != Constants.STANDALONE_FLAVOR)
|
||||
stringResource(R.string.download)
|
||||
if (BuildConfig.FLAVOR != "full") stringResource(R.string.download)
|
||||
else stringResource(R.string.download_and_install)
|
||||
)
|
||||
},
|
||||
@@ -123,11 +121,7 @@ fun SupportScreen(viewModel: SupportViewModel = hiltViewModel(), appViewModel: A
|
||||
)
|
||||
UpdateSection(
|
||||
onUpdateCheck = {
|
||||
if (
|
||||
BuildConfig.DEBUG ||
|
||||
BuildConfig.VERSION_NAME.contains("beta") ||
|
||||
BuildConfig.FLAVOR == Constants.GOOGLE_PLAY_FLAVOR
|
||||
)
|
||||
if (BuildConfig.DEBUG || BuildConfig.VERSION_NAME.contains("beta"))
|
||||
return@UpdateSection context.showToast(R.string.update_check_unsupported)
|
||||
context.showToast(R.string.checking_for_update)
|
||||
viewModel.handleUpdateCheck()
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ fun ContactSupportOptions(context: android.content.Context) {
|
||||
),
|
||||
)
|
||||
)
|
||||
if (BuildConfig.FLAVOR != Constants.GOOGLE_PLAY_FLAVOR) {
|
||||
if (BuildConfig.FLAVOR == Constants.FDROID_FLAVOR) {
|
||||
add(
|
||||
SelectionItem(
|
||||
leadingIcon = Icons.Filled.Favorite,
|
||||
|
||||
@@ -10,9 +10,6 @@ val Plantation = Color(0xFF264A49)
|
||||
val Shark = Color(0xFF21272A)
|
||||
val BalticSea = Color(0xFF1C1B1F)
|
||||
|
||||
// amoled
|
||||
val ElectricTeal = Color(0xFF4DD0E1)
|
||||
|
||||
// Status colors
|
||||
val SilverTree = Color(0xFF6DB58B)
|
||||
val Brick = Color(0xFFCE4257)
|
||||
|
||||
@@ -44,8 +44,6 @@ enum class Theme {
|
||||
AUTOMATIC,
|
||||
LIGHT,
|
||||
DARK,
|
||||
DARKER,
|
||||
AMOLED,
|
||||
DYNAMIC,
|
||||
}
|
||||
|
||||
@@ -61,18 +59,6 @@ fun WireguardAutoTunnelTheme(theme: Theme = Theme.AUTOMATIC, content: @Composabl
|
||||
isDark = true
|
||||
DarkColorScheme
|
||||
}
|
||||
Theme.DARKER -> {
|
||||
isDark = true
|
||||
DarkColorScheme.copy(surface = BalticSea, background = BalticSea)
|
||||
}
|
||||
Theme.AMOLED -> {
|
||||
isDark = true
|
||||
DarkColorScheme.copy(
|
||||
surface = Color.Black,
|
||||
background = Color.Black,
|
||||
primary = ElectricTeal,
|
||||
)
|
||||
}
|
||||
Theme.LIGHT -> {
|
||||
isDark = false
|
||||
LightColorScheme
|
||||
|
||||
@@ -35,7 +35,5 @@ object Constants {
|
||||
const val QR_CODE_NAME_PROPERTY = "# Name ="
|
||||
|
||||
const val FDROID_FLAVOR = "fdroid"
|
||||
const val GOOGLE_PLAY_FLAVOR = "google"
|
||||
const val STANDALONE_FLAVOR = "standalone"
|
||||
const val RELEASE = "release"
|
||||
}
|
||||
|
||||
+4
-19
@@ -1,29 +1,14 @@
|
||||
package com.zaneschepke.wireguardautotunnel.util.extensions
|
||||
|
||||
import java.util.regex.Pattern
|
||||
import timber.log.Timber
|
||||
|
||||
val hasNumberInParentheses = """^(.+?)\((\d+)\)$""".toRegex()
|
||||
|
||||
fun String.isValidIpv4orIpv6Address(): Boolean {
|
||||
val sanitized = removeSurrounding("[", "]")
|
||||
val ipv6Pattern =
|
||||
Regex(
|
||||
"(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:)" +
|
||||
"{1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]" +
|
||||
"{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:" +
|
||||
"[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4})" +
|
||||
"{1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}" +
|
||||
":((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]" +
|
||||
"{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}" +
|
||||
"[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:)" +
|
||||
"{1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"
|
||||
)
|
||||
val ipv4Pattern =
|
||||
Regex(
|
||||
"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}" +
|
||||
"(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
||||
)
|
||||
return ipv4Pattern.matches(sanitized) || ipv6Pattern.matches(sanitized)
|
||||
val ipv4Pattern = Pattern.compile("^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\$")
|
||||
val ipv6Pattern = Pattern.compile("^([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\$")
|
||||
return ipv4Pattern.matcher(this).matches() || ipv6Pattern.matcher(this).matches()
|
||||
}
|
||||
|
||||
fun String.hasNumberInParentheses(): Boolean {
|
||||
|
||||
@@ -39,8 +39,6 @@ import java.time.Instant
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import kotlin.collections.component1
|
||||
import kotlin.collections.component2
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
@@ -58,7 +56,7 @@ constructor(
|
||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
@MainDispatcher private val mainDispatcher: CoroutineDispatcher,
|
||||
@AppShell private val rootShell: Provider<RootShell>,
|
||||
val tunnelManager: TunnelManager,
|
||||
private val tunnelManager: TunnelManager,
|
||||
private val serviceManager: ServiceManager,
|
||||
private val logReader: LogReader,
|
||||
private val fileUtils: FileUtils,
|
||||
@@ -88,7 +86,7 @@ constructor(
|
||||
appDataRepository.tunnels.flow,
|
||||
appDataRepository.appState.flow,
|
||||
tunnelManager.activeTunnels,
|
||||
serviceManager.autoTunnelService.map { it != null },
|
||||
serviceManager.autoTunnelActive,
|
||||
networkMonitor.networkStatusFlow,
|
||||
) { array ->
|
||||
val settings = array[0] as AppSettings
|
||||
@@ -208,6 +206,7 @@ constructor(
|
||||
is AppEvent.ShowMessage -> handleShowMessage(event.message)
|
||||
is AppEvent.PopBackStack ->
|
||||
_appViewState.update { it.copy(popBackStack = event.pop) }
|
||||
is AppEvent.ClearTunnelError -> tunnelManager.clearError(event.tunnel)
|
||||
AppEvent.ToggleRemoteControl -> handleToggleRemoteControl(state.appState)
|
||||
AppEvent.ClearSelectedTunnels -> clearSelectedTunnels()
|
||||
is AppEvent.SetShowModal ->
|
||||
@@ -266,9 +265,6 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleTunnelErrors() =
|
||||
viewModelScope.launch { tunnelManager.errorEvents.collect { errorEvent -> } }
|
||||
|
||||
private suspend fun handleAppReadyCheck(tunnels: List<TunnelConf>) {
|
||||
if (tunnels.size == appDataRepository.tunnels.count()) {
|
||||
_appViewState.update { it.copy(isAppReady = true) }
|
||||
|
||||
@@ -106,6 +106,8 @@ sealed class AppEvent {
|
||||
|
||||
data class ShowMessage(val message: StringValue) : AppEvent()
|
||||
|
||||
data class ClearTunnelError(val tunnel: TunnelConf) : AppEvent()
|
||||
|
||||
data class PopBackStack(val pop: Boolean) : AppEvent()
|
||||
|
||||
data class SetBottomSheet(val showSheet: AppViewState.BottomSheet) : AppEvent()
|
||||
|
||||
@@ -221,7 +221,6 @@
|
||||
<string name="wifi_name_template">Active: %1$s</string>
|
||||
<string name="remote_key_template">Key: %1$s</string>
|
||||
<string name="version_template">Version: %1$s</string>
|
||||
<string name="security_template">Security: %1$s</string>
|
||||
<string name="flavor_template">Flavor: %1$s</string>
|
||||
<string name="config_error">config error</string>
|
||||
<string name="dns_resolve_error">dns resolution error</string>
|
||||
@@ -256,6 +255,4 @@
|
||||
<string name="allow">Allow</string>
|
||||
<string name="licenses">Licenses</string>
|
||||
<string name="update_check_unsupported">Update check not supported this build type.</string>
|
||||
<string name="darker">Darker</string>
|
||||
<string name="amoled">AMOLED</string>
|
||||
</resources>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
object Constants {
|
||||
const val VERSION_NAME = "3.9.0"
|
||||
const val VERSION_NAME = "3.8.3"
|
||||
const val JVM_TARGET = "17"
|
||||
const val VERSION_CODE = 38900
|
||||
const val VERSION_CODE = 38300
|
||||
const val TARGET_SDK = 35
|
||||
const val MIN_SDK = 26
|
||||
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
||||
|
||||
@@ -80,8 +80,8 @@ fun Project.computeVersionName(): String {
|
||||
// Bump minor for pre-release
|
||||
val preReleaseVersion = Semver.of(
|
||||
baseVersion.major,
|
||||
baseVersion.minor,
|
||||
0 + 1,
|
||||
baseVersion.minor + 1,
|
||||
0
|
||||
)
|
||||
"${preReleaseVersion}-beta+git.${getGitCommitHash()}"
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
What's new:
|
||||
- Fix Android TV Banners
|
||||
- Add multi-select for tunnels
|
||||
- Add in-app update checker
|
||||
- Add license screen
|
||||
- Various bug fixes
|
||||
@@ -1,12 +1,12 @@
|
||||
[versions]
|
||||
accompanist = "0.37.2"
|
||||
activityCompose = "1.10.1"
|
||||
amneziawgAndroid = "1.3.10"
|
||||
amneziawgAndroid = "1.3.8"
|
||||
androidx-junit = "1.2.1"
|
||||
appcompat = "1.7.0"
|
||||
biometricKtx = "1.2.0-alpha05"
|
||||
coreKtx = "1.16.0"
|
||||
datastorePreferences = "1.2.0-alpha01"
|
||||
datastorePreferences = "1.1.4"
|
||||
desugar_jdk_libs = "2.1.5"
|
||||
espressoCore = "3.6.1"
|
||||
hiltAndroid = "2.56.2"
|
||||
@@ -19,18 +19,17 @@ material3 = "1.3.2"
|
||||
navigationCompose = "2.8.9"
|
||||
pinLockCompose = "1.0.4"
|
||||
qrcodeKotlin = "4.4.1"
|
||||
roomVersion = "2.7.1"
|
||||
roomVersion = "2.7.0"
|
||||
semver4j = "3.1.0"
|
||||
slf4jAndroid = "1.7.36"
|
||||
timber = "5.0.1"
|
||||
tunnel = "1.2.16"
|
||||
tunnel = "1.2.14"
|
||||
androidGradlePlugin = "8.9.2"
|
||||
kotlin = "2.1.20"
|
||||
ksp = "2.1.20-2.0.0"
|
||||
composeBom = "2025.04.01"
|
||||
compose = "1.8.0"
|
||||
icons = "1.7.8"
|
||||
workRuntimeKtxVersion = "2.10.1"
|
||||
composeBom = "2025.04.00"
|
||||
compose = "1.7.8"
|
||||
workRuntimeKtxVersion = "2.10.0"
|
||||
zxingAndroidEmbedded = "4.3.0"
|
||||
coreSplashscreen = "1.0.1"
|
||||
gradlePlugins-grgit = "5.3.0"
|
||||
@@ -96,7 +95,7 @@ ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktorCli
|
||||
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorClientCore" }
|
||||
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktorClientCore" }
|
||||
lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle-runtime-compose" }
|
||||
material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "icons" }
|
||||
material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "compose" }
|
||||
|
||||
pin-lock-compose = { module = "com.zaneschepke:pin_lock_compose", version.ref = "pinLockCompose" }
|
||||
qrcode-kotlin = { module = "io.github.g0dkar:qrcode-kotlin", version.ref = "qrcodeKotlin" }
|
||||
|
||||
+8
-34
@@ -12,7 +12,6 @@ import android.net.NetworkRequest
|
||||
import android.net.wifi.WifiManager
|
||||
import android.os.Build
|
||||
import com.wireguard.android.util.RootShell
|
||||
import java.util.Collections
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
@@ -46,18 +45,10 @@ class AndroidNetworkMonitor(
|
||||
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||
|
||||
@get:Synchronized @set:Synchronized var currentSsid: String? = null
|
||||
@get:Synchronized @set:Synchronized var securityType: WifiSecurityType? = null
|
||||
|
||||
@get:Synchronized @set:Synchronized var wifiConnected = false
|
||||
|
||||
// Track active Wi-Fi networks and last active network ID
|
||||
private val activeNetworks = Collections.synchronizedSet(mutableSetOf<Network>())
|
||||
|
||||
data class WifiState(
|
||||
val connected: Boolean = false,
|
||||
val ssid: String? = null,
|
||||
val securityType: WifiSecurityType? = null,
|
||||
)
|
||||
data class WifiState(val connected: Boolean = false, val ssid: String? = null)
|
||||
|
||||
data class TransportState(val connected: Boolean = false)
|
||||
|
||||
@@ -81,15 +72,15 @@ class AndroidNetworkMonitor(
|
||||
|
||||
suspend fun handleUnknownWifi() {
|
||||
val newSsid = getWifiSsid()
|
||||
val securityType = wifiManager?.getCurrentSecurityType()
|
||||
// Only update if new SSID is valid; preserve existing valid SSID otherwise
|
||||
if (newSsid != null && newSsid != WifiManager.UNKNOWN_SSID) {
|
||||
currentSsid = newSsid
|
||||
trySend(WifiState(wifiConnected, currentSsid, securityType))
|
||||
trySend(WifiState(connected = wifiConnected, ssid = currentSsid))
|
||||
} else if (currentSsid == null || currentSsid == WifiManager.UNKNOWN_SSID) {
|
||||
currentSsid = newSsid
|
||||
trySend(WifiState(wifiConnected, currentSsid, securityType))
|
||||
trySend(WifiState(connected = wifiConnected, ssid = currentSsid))
|
||||
}
|
||||
Timber.d("handleUnknownWifi: currentSsid=$currentSsid")
|
||||
}
|
||||
|
||||
val locationPermissionReceiver =
|
||||
@@ -148,34 +139,18 @@ class AndroidNetworkMonitor(
|
||||
object : ConnectivityManager.NetworkCallback() {
|
||||
override fun onAvailable(network: Network) {
|
||||
Timber.d("Wi-Fi onAvailable: network=$network")
|
||||
activeNetworks.add(network)
|
||||
launch {
|
||||
currentSsid = getWifiSsid()
|
||||
securityType = wifiManager?.getCurrentSecurityType()
|
||||
wifiConnected = true
|
||||
trySend(
|
||||
WifiState(
|
||||
connected = true,
|
||||
ssid = currentSsid,
|
||||
securityType = securityType,
|
||||
)
|
||||
)
|
||||
trySend(WifiState(connected = true, ssid = currentSsid))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLost(network: Network) {
|
||||
Timber.d("Wi-Fi onLost: network=$network")
|
||||
activeNetworks.remove(network)
|
||||
if (activeNetworks.isEmpty()) {
|
||||
Timber.d(
|
||||
"All Wi-Fi networks disconnected, clearing currentSsid and wifiConnected"
|
||||
)
|
||||
currentSsid = null
|
||||
wifiConnected = false
|
||||
trySend(WifiState(connected = false, ssid = null, securityType = null))
|
||||
} else {
|
||||
Timber.d("Wi-Fi onLost, but still connected to other networks, ignoring")
|
||||
}
|
||||
currentSsid = null
|
||||
wifiConnected = false
|
||||
trySend(WifiState(connected = false, ssid = null))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +228,6 @@ class AndroidNetworkMonitor(
|
||||
if (hasAnyConnection) {
|
||||
NetworkStatus.Connected(
|
||||
wifiSsid = wifi.ssid,
|
||||
securityType = wifi.securityType,
|
||||
wifiConnected = wifi.connected,
|
||||
cellularConnected = cellular.connected,
|
||||
ethernetConnected = ethernet.connected,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.zaneschepke.networkmonitor
|
||||
|
||||
import android.net.wifi.WifiManager
|
||||
import android.os.Build
|
||||
import com.wireguard.android.util.RootShell
|
||||
|
||||
fun RootShell.getCurrentWifiName(): String? {
|
||||
@@ -12,12 +10,3 @@ fun RootShell.getCurrentWifiName(): String? {
|
||||
)
|
||||
return response.firstOrNull()
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun WifiManager.getCurrentSecurityType(): WifiSecurityType? {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
WifiSecurityType.from(connectionInfo.currentSecurityType)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ sealed class NetworkStatus {
|
||||
|
||||
data class Connected(
|
||||
val wifiSsid: String? = null,
|
||||
val securityType: WifiSecurityType? = null,
|
||||
override val wifiConnected: Boolean = false,
|
||||
override val ethernetConnected: Boolean = false,
|
||||
override val cellularConnected: Boolean = false,
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.zaneschepke.networkmonitor
|
||||
|
||||
import android.net.wifi.WifiInfo
|
||||
|
||||
enum class WifiSecurityType {
|
||||
UNKNOWN,
|
||||
OPEN,
|
||||
WEP,
|
||||
WPA2, // WPA and WPA2
|
||||
WPA3, // WPA3-Personal (SAE)
|
||||
OWE,
|
||||
WAPI, // All WAPI_PSK and WAPI_CERT
|
||||
EAP, // All EAP (covers both WPA3 and others)
|
||||
PASSPOINT, // All Passpoint versions
|
||||
DPP;
|
||||
|
||||
companion object {
|
||||
fun from(securityType: Int): WifiSecurityType {
|
||||
return when (securityType) {
|
||||
WifiInfo.SECURITY_TYPE_OPEN -> OPEN
|
||||
WifiInfo.SECURITY_TYPE_WEP -> WEP
|
||||
WifiInfo.SECURITY_TYPE_PSK -> WPA2
|
||||
WifiInfo.SECURITY_TYPE_EAP -> EAP
|
||||
WifiInfo.SECURITY_TYPE_SAE -> WPA3
|
||||
WifiInfo.SECURITY_TYPE_OWE -> OWE
|
||||
WifiInfo.SECURITY_TYPE_WAPI_PSK,
|
||||
WifiInfo.SECURITY_TYPE_WAPI_CERT -> WAPI
|
||||
WifiInfo.SECURITY_TYPE_EAP_WPA3_ENTERPRISE -> EAP
|
||||
WifiInfo.SECURITY_TYPE_EAP_WPA3_ENTERPRISE_192_BIT -> EAP
|
||||
WifiInfo.SECURITY_TYPE_PASSPOINT_R1_R2,
|
||||
WifiInfo.SECURITY_TYPE_PASSPOINT_R3 -> PASSPOINT
|
||||
WifiInfo.SECURITY_TYPE_DPP -> DPP
|
||||
WifiInfo.SECURITY_TYPE_UNKNOWN -> UNKNOWN
|
||||
else -> UNKNOWN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user