mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
77 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 756d7cbea0 | |||
| 8a3d781bb3 | |||
| 99cd1d917a | |||
| 7940b97329 | |||
| 99419ebe9f | |||
| 3e2ffc1b64 | |||
| 5d8fb38906 | |||
| 6d100a2f46 | |||
| 5feb2827fd | |||
| 0336c2ac9f | |||
| 96d8114d37 | |||
| e78469c730 | |||
| 6f365a4490 | |||
| 2885d1a539 | |||
| c56b11599f | |||
| 753575c50d | |||
| 78b419dc6e | |||
| e8681af273 | |||
| cb92c9605f | |||
| 38ecb0b66b | |||
| 230cd0adb8 | |||
| 33b51823ab | |||
| f333319576 | |||
| e6ad1531c9 | |||
| 030082df34 | |||
| a825a2f2a4 | |||
| aa1a344bb2 | |||
| 3aa03c1896 | |||
| 21e56cda80 | |||
| b5196fbf01 | |||
| e46fe93ae0 | |||
| 872ff83a12 | |||
| 5563292a87 | |||
| 8ba760a5ff | |||
| d431c2d39f | |||
| 33437ab237 | |||
| 4a432d2bb7 | |||
| 3df972d031 | |||
| 8b828cca55 | |||
| a223289949 | |||
| c8b65fb7fa | |||
| feec7f0ffc | |||
| b63c6a9b73 | |||
| 46975607c4 | |||
| 0c7bcb5453 | |||
| 599bf9c9e0 | |||
| 03345bdf86 | |||
| b07e604003 | |||
| c8b3af4857 | |||
| 0a3447c63d | |||
| 7f3297db79 | |||
| aa33aebd2f | |||
| 53b1d03ca8 | |||
| 53f72850e2 | |||
| b8deb7b644 | |||
| d5a3090782 | |||
| 063cbf3ea6 | |||
| 4a45387efd | |||
| fa064ef3a6 | |||
| 3f8894a566 | |||
| 6d77ef878d | |||
| a05f11739d | |||
| fe519be5cc | |||
| ab0f67c897 | |||
| a5639cd129 | |||
| babbab051f | |||
| 2e984e8b6f | |||
| 044e6da7f5 | |||
| 77aa2c30d7 | |||
| e773238e6b | |||
| 85316bec3f | |||
| 1935653309 | |||
| e3e24b4a06 | |||
| 7af53dcc18 | |||
| 2eb0ab0f19 | |||
| 07857a53c2 | |||
| 25fd31e252 |
+12
-12
@@ -1,4 +1,6 @@
|
|||||||
name: Build
|
name: build
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -10,7 +12,6 @@ on:
|
|||||||
default: debug
|
default: debug
|
||||||
options:
|
options:
|
||||||
- debug
|
- debug
|
||||||
- prerelease
|
|
||||||
- nightly
|
- nightly
|
||||||
- release
|
- release
|
||||||
flavor:
|
flavor:
|
||||||
@@ -20,7 +21,7 @@ on:
|
|||||||
default: fdroid
|
default: fdroid
|
||||||
options:
|
options:
|
||||||
- fdroid
|
- fdroid
|
||||||
- full
|
- standalone
|
||||||
secrets:
|
secrets:
|
||||||
SIGNING_KEY_ALIAS:
|
SIGNING_KEY_ALIAS:
|
||||||
required: false
|
required: false
|
||||||
@@ -75,7 +76,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
@@ -94,10 +95,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
||||||
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
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
|
- name: Build APK
|
||||||
run: |
|
run: |
|
||||||
flavor=${{ inputs.flavor }}
|
flavor=${{ inputs.flavor }}
|
||||||
@@ -106,9 +104,6 @@ jobs:
|
|||||||
"release")
|
"release")
|
||||||
./gradlew :app:assemble${flavor^}Release --info
|
./gradlew :app:assemble${flavor^}Release --info
|
||||||
;;
|
;;
|
||||||
"prerelease")
|
|
||||||
./gradlew :app:assemble${flavor^}Prerelease --info
|
|
||||||
;;
|
|
||||||
"nightly")
|
"nightly")
|
||||||
./gradlew :app:assemble${flavor^}Nightly --info
|
./gradlew :app:assemble${flavor^}Nightly --info
|
||||||
;;
|
;;
|
||||||
@@ -123,6 +118,11 @@ jobs:
|
|||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: android_artifacts_${{ inputs.flavor }}
|
name: android_artifacts_${{ inputs.flavor }}
|
||||||
path: app/build/outputs/apk/${{ inputs.flavor }}/release/wgtunnel-${{ inputs.flavor }}-release-*.apk
|
path: >-
|
||||||
|
app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/${{
|
||||||
|
inputs.flavor == 'fdroid' && inputs.build_type == 'release'
|
||||||
|
&& 'wgtunnel-fdroid-release-*.apk'
|
||||||
|
|| format('wgtunnel-{0}-v*.apk', inputs.flavor)
|
||||||
|
}}
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
if-no-files-found: warn
|
if-no-files-found: warn
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
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.GITHUB_TOKEN }}
|
||||||
|
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@v5
|
||||||
|
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,4 +1,6 @@
|
|||||||
name: on-pr
|
name: on-pr
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -10,7 +12,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
name: publish
|
name: publish
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
push:
|
||||||
- cron: "4 3 * * *"
|
tags:
|
||||||
|
- '[0-9]*.[0-9]*.[0-9]*'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
track:
|
track:
|
||||||
@@ -21,96 +25,60 @@ on:
|
|||||||
description: "GitHub release type"
|
description: "GitHub release type"
|
||||||
options:
|
options:
|
||||||
- none
|
- none
|
||||||
- prerelease
|
|
||||||
- nightly
|
|
||||||
- release
|
- release
|
||||||
default: release
|
default: release
|
||||||
required: true
|
required: true
|
||||||
tag_name:
|
tag_name:
|
||||||
description: "Tag name for release"
|
description: "Tag name for release"
|
||||||
required: false
|
required: false
|
||||||
default: nightly
|
default: 1.1.1
|
||||||
flavor:
|
flavor:
|
||||||
type: choice
|
type: choice
|
||||||
description: "Product flavor"
|
description: "Product flavor"
|
||||||
required: true
|
required: true
|
||||||
default: full
|
default: standalone
|
||||||
options:
|
options:
|
||||||
- fdroid
|
- fdroid
|
||||||
- full
|
- standalone
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
flavor:
|
flavor:
|
||||||
type: string
|
type: string
|
||||||
description: "Product flavor"
|
description: "Product flavor"
|
||||||
required: false
|
required: false
|
||||||
default: full
|
default: standalone
|
||||||
|
|
||||||
env:
|
|
||||||
UPLOAD_DIR_ANDROID: android_artifacts
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
packages: write
|
|
||||||
|
|
||||||
jobs:
|
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:
|
build-fdroid:
|
||||||
if: ${{ inputs.release_type == 'release' || inputs.flavor == 'fdroid' }}
|
if: ${{ github.event_name == 'push' || inputs.release_type == 'release' || inputs.flavor == 'fdroid' }}
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
build_type: ${{ github.event_name == 'push' && 'release' || inputs.release_type }}
|
||||||
flavor: fdroid
|
flavor: fdroid
|
||||||
|
|
||||||
build-full:
|
build-standalone:
|
||||||
if: ${{ inputs.release_type == 'release' || inputs.release_type == 'nightly' || inputs.release_type == 'prerelease' || inputs.flavor == 'full' }}
|
if: ${{ github.event_name == 'push' || inputs.release_type == 'release' || inputs.release_type == 'debug' || inputs.flavor == 'standalone' }}
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
build_type: ${{ inputs.release_type == '' && 'nightly' || inputs.release_type }}
|
build_type: ${{ github.event_name == 'push' && 'release' || inputs.release_type }}
|
||||||
flavor: full
|
flavor: standalone
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
needs:
|
needs:
|
||||||
- check_commits
|
- build-standalone
|
||||||
- build-full
|
|
||||||
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
|
||||||
name: publish-github
|
name: publish-github
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
ref: ${{ github.event_name == 'push' && github.ref || 'main' }}
|
||||||
ref: main
|
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt update && sudo apt install -y gh apksigner
|
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
|
- name: Set latest tag
|
||||||
uses: rickstaa/action-create-tag@v1
|
uses: rickstaa/action-create-tag@v1
|
||||||
id: tag_creation
|
id: tag_creation
|
||||||
@@ -126,24 +94,28 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
latest: true
|
latest: true
|
||||||
|
|
||||||
- name: Generate Changelog
|
- name: Generate Changelog
|
||||||
id: changelog
|
id: changelog
|
||||||
uses: requarks/changelog-action@v1
|
uses: requarks/changelog-action@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
toTag: ${{ github.event_name == 'schedule' && 'nightly' || steps.latest_release.outputs.tag_name }}
|
toTag: ${{ steps.latest_release.outputs.tag_name }}
|
||||||
fromTag: "latest"
|
fromTag: "latest"
|
||||||
writeToFile: false
|
writeToFile: false
|
||||||
|
|
||||||
- name: Make download dir
|
- name: Make download dir
|
||||||
run: mkdir ${{ github.workspace }}/temp
|
run: mkdir ${{ github.workspace }}/temp
|
||||||
|
|
||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v5
|
||||||
with:
|
with:
|
||||||
pattern: android_artifacts_*
|
pattern: android_artifacts_*
|
||||||
path: ${{ github.workspace }}/temp
|
path: ${{ github.workspace }}/temp
|
||||||
merge-multiple: true
|
merge-multiple: true
|
||||||
|
|
||||||
- name: Set version release notes
|
- name: Set version release notes
|
||||||
if: ${{ inputs.release_type == 'release' }}
|
if: ${{ github.event_name == 'push' || inputs.release_type == 'release' }}
|
||||||
run: |
|
run: |
|
||||||
VERSION_NAME=$(grep "const val VERSION_NAME" buildSrc/src/main/kotlin/Constants.kt | awk -F'"' '{print $2}')
|
VERSION_NAME=$(grep "const val VERSION_NAME" buildSrc/src/main/kotlin/Constants.kt | awk -F'"' '{print $2}')
|
||||||
RELEASE_NOTES="$(cat ${{ github.workspace }}/fastlane/metadata/android/en-US/changelogs/${VERSION_NAME}.txt || echo "No changelog found for ${VERSION_NAME}")"
|
RELEASE_NOTES="$(cat ${{ github.workspace }}/fastlane/metadata/android/en-US/changelogs/${VERSION_NAME}.txt || echo "No changelog found for ${VERSION_NAME}")"
|
||||||
@@ -151,36 +123,17 @@ jobs:
|
|||||||
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
||||||
echo "EOF" >> $GITHUB_ENV
|
echo "EOF" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: On nightly release notes
|
- name: Get checksum
|
||||||
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: Delete previous release
|
|
||||||
if: ${{ contains(env.TAG_NAME, 'nightly') || inputs.release_type == 'prerelease' }}
|
|
||||||
uses: ClementTsang/delete-tag-and-release@v0.4.0
|
|
||||||
with:
|
|
||||||
tag_name: ${{ env.TAG_NAME }}
|
|
||||||
delete_release: true
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Get checksums
|
|
||||||
id: checksum
|
id: checksum
|
||||||
run: |
|
run: |
|
||||||
checksums=""
|
file_path=$(find ${{ github.workspace }}/temp -type f -iname "*.apk" | head -n 1)
|
||||||
for file_path in $(find ${{ github.workspace }}/temp -type f -iname "*.apk"); do
|
if [ -z "$file_path" ]; then
|
||||||
checksum=$(apksigner verify -print-certs $file_path | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")
|
echo "No APK file found"
|
||||||
checksums="$checksums\n$file_path: $checksum"
|
exit 1
|
||||||
done
|
fi
|
||||||
echo "checksum<<EOF" >> $GITHUB_OUTPUT
|
checksum=$(apksigner verify --print-certs "$file_path" | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")
|
||||||
echo -e "$checksums" >> $GITHUB_OUTPUT
|
echo "checksum=$checksum" >> $GITHUB_OUTPUT
|
||||||
echo "EOF" >> $GITHUB_OUTPUT
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
@@ -200,13 +153,13 @@ jobs:
|
|||||||
|
|
||||||
### Changelog
|
### Changelog
|
||||||
${{ steps.changelog.outputs.changes }}
|
${{ steps.changelog.outputs.changes }}
|
||||||
tag_name: ${{ env.TAG_NAME }}
|
tag_name: ${{ github.event_name == 'push' && github.ref_name || github.event.inputs.tag_name }}
|
||||||
name: ${{ env.TAG_NAME }}
|
name: ${{ github.event_name == 'push' && github.ref_name || github.event.inputs.tag_name }}
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: ${{ inputs.release_type == 'prerelease' || inputs.release_type == '' || inputs.release_type == 'nightly' }}
|
prerelease: false
|
||||||
make_latest: ${{ inputs.release_type == 'release' }}
|
make_latest: true
|
||||||
files: |
|
files: |
|
||||||
${{ github.workspace }}/temp/*
|
${{ github.workspace }}/temp/**/*.apk
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
@@ -214,7 +167,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs:
|
needs:
|
||||||
- build-fdroid
|
- build-fdroid
|
||||||
if: inputs.release_type == 'release'
|
if: ${{ github.event_name == 'push' || inputs.release_type == 'release' }}
|
||||||
steps:
|
steps:
|
||||||
- name: Dispatch update for fdroid repo
|
- name: Dispatch update for fdroid repo
|
||||||
uses: peter-evans/repository-dispatch@v3
|
uses: peter-evans/repository-dispatch@v3
|
||||||
@@ -224,7 +177,7 @@ jobs:
|
|||||||
event-type: fdroid-update
|
event-type: fdroid-update
|
||||||
|
|
||||||
publish-play:
|
publish-play:
|
||||||
if: ${{ inputs.track != 'none' && inputs.track != '' }}
|
if: ${{ github.event_name == 'push' || inputs.track != 'none' }}
|
||||||
name: Publish to Google Play
|
name: Publish to Google Play
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
@@ -238,7 +191,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
@@ -274,4 +227,6 @@ jobs:
|
|||||||
bundler-cache: true
|
bundler-cache: true
|
||||||
|
|
||||||
- name: Distribute app to Prod track 🚀
|
- name: Distribute app to Prod track 🚀
|
||||||
run: (cd ${{ github.workspace }} && bundle install && bundle exec fastlane ${{ inputs.track }})
|
run: |
|
||||||
|
track=${{ github.event_name == 'push' && 'production' || inputs.track }}
|
||||||
|
(cd ${{ github.workspace }} && bundle install && bundle exec fastlane $track)
|
||||||
+42
-23
@@ -1,3 +1,5 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application)
|
alias(libs.plugins.android.application)
|
||||||
alias(libs.plugins.kotlin.android)
|
alias(libs.plugins.kotlin.android)
|
||||||
@@ -20,6 +22,8 @@ android {
|
|||||||
includeInBundle = false
|
includeInBundle = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = Constants.APP_ID
|
applicationId = Constants.APP_ID
|
||||||
minSdk = Constants.MIN_SDK
|
minSdk = Constants.MIN_SDK
|
||||||
@@ -27,15 +31,10 @@ android {
|
|||||||
versionCode = computeVersionCode()
|
versionCode = computeVersionCode()
|
||||||
versionName = computeVersionName()
|
versionName = computeVersionName()
|
||||||
|
|
||||||
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
|
|
||||||
|
|
||||||
sourceSets { getByName("debug").assets.srcDirs(files("$projectDir/schemas")) }
|
sourceSets { getByName("debug").assets.srcDirs(files("$projectDir/schemas")) }
|
||||||
|
|
||||||
buildConfigField(
|
val languagesArray = buildLanguagesArray(languageList())
|
||||||
"String[]",
|
buildConfigField("String[]", "LANGUAGES", "new String[]{ $languagesArray }")
|
||||||
"LANGUAGES",
|
|
||||||
"new String[]{ ${languageList().joinToString(separator = ", ") { "\"$it\"" }} }",
|
|
||||||
)
|
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables { useSupportLibrary = true }
|
vectorDrawables { useSupportLibrary = true }
|
||||||
@@ -73,22 +72,15 @@ android {
|
|||||||
|
|
||||||
debug {
|
debug {
|
||||||
applicationIdSuffix = ".debug"
|
applicationIdSuffix = ".debug"
|
||||||
resValue("string", "app_name", "WG Tunnel - Debug")
|
resValue("string", "app_name", "WG Tunnel Debug")
|
||||||
isDebuggable = true
|
isDebuggable = true
|
||||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.debug\"")
|
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.debug\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
create(Constants.PRERELEASE) {
|
|
||||||
initWith(buildTypes.getByName(Constants.RELEASE))
|
|
||||||
applicationIdSuffix = ".prerelease"
|
|
||||||
resValue("string", "app_name", "WG Tunnel - Pre")
|
|
||||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.pre\"")
|
|
||||||
}
|
|
||||||
|
|
||||||
create(Constants.NIGHTLY) {
|
create(Constants.NIGHTLY) {
|
||||||
initWith(buildTypes.getByName(Constants.RELEASE))
|
initWith(buildTypes.getByName(Constants.RELEASE))
|
||||||
applicationIdSuffix = ".nightly"
|
applicationIdSuffix = ".nightly"
|
||||||
resValue("string", "app_name", "WG Tunnel - Nightly")
|
resValue("string", "app_name", "WG Tunnel Nightly")
|
||||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.nightly\"")
|
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.nightly\"")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,15 +95,25 @@ android {
|
|||||||
dimension = "type"
|
dimension = "type"
|
||||||
buildConfigField("String", "FLAVOR", "\"google\"")
|
buildConfigField("String", "FLAVOR", "\"google\"")
|
||||||
}
|
}
|
||||||
create("full") { dimension = "type" }
|
create("standalone") {
|
||||||
|
dimension = "type"
|
||||||
|
buildConfigField("String", "FLAVOR", "\"standalone\"")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
isCoreLibraryDesugaringEnabled = true
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
isCoreLibraryDesugaringEnabled = true
|
|
||||||
}
|
}
|
||||||
kotlinOptions { jvmTarget = Constants.JVM_TARGET }
|
|
||||||
|
kotlin {
|
||||||
|
compilerOptions {
|
||||||
|
jvmTarget = JvmTarget.JVM_17
|
||||||
|
freeCompilerArgs = listOf("-XXLanguage:+PropertyParamAnnotationDefaultTargetMode")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
compose = true
|
compose = true
|
||||||
buildConfig = true
|
buildConfig = true
|
||||||
@@ -119,9 +121,8 @@ android {
|
|||||||
packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } }
|
packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } }
|
||||||
|
|
||||||
licensee {
|
licensee {
|
||||||
Constants.allowedLicenses.forEach { allow(it) }
|
allowedLicenses().forEach { allow(it) }
|
||||||
allowUrl(Constants.XZING_LICENSE_URL)
|
allowedLicenseUrls().forEach { allowUrl(it) }
|
||||||
allowUrl("https://rafaellins.mit-license.org/2021/")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationVariants.all {
|
applicationVariants.all {
|
||||||
@@ -195,6 +196,7 @@ dependencies {
|
|||||||
implementation(libs.kotlinx.serialization.json)
|
implementation(libs.kotlinx.serialization.json)
|
||||||
|
|
||||||
implementation(libs.zxing.android.embedded)
|
implementation(libs.zxing.android.embedded)
|
||||||
|
|
||||||
implementation(libs.material.icons.extended)
|
implementation(libs.material.icons.extended)
|
||||||
|
|
||||||
implementation(libs.androidx.biometric.ktx)
|
implementation(libs.androidx.biometric.ktx)
|
||||||
@@ -207,7 +209,7 @@ dependencies {
|
|||||||
implementation(libs.androidx.work.runtime)
|
implementation(libs.androidx.work.runtime)
|
||||||
implementation(libs.androidx.hilt.work)
|
implementation(libs.androidx.hilt.work)
|
||||||
|
|
||||||
implementation(libs.qrcode.kotlin)
|
implementation(libs.qrose)
|
||||||
implementation(libs.semver4j)
|
implementation(libs.semver4j)
|
||||||
|
|
||||||
implementation(libs.ktor.client.core)
|
implementation(libs.ktor.client.core)
|
||||||
@@ -216,6 +218,16 @@ dependencies {
|
|||||||
implementation(libs.ktor.client.content.negotiation)
|
implementation(libs.ktor.client.content.negotiation)
|
||||||
implementation(libs.ktor.serialization.kotlinx.json)
|
implementation(libs.ktor.serialization.kotlinx.json)
|
||||||
implementation(libs.slf4j.android)
|
implementation(libs.slf4j.android)
|
||||||
|
implementation(libs.icmp4a)
|
||||||
|
|
||||||
|
// shizuku
|
||||||
|
implementation(libs.shizuku.api)
|
||||||
|
implementation(libs.shizuku.provider)
|
||||||
|
|
||||||
|
implementation(libs.reorderable)
|
||||||
|
implementation(libs.roomdatabasebackup) {
|
||||||
|
exclude(group = "org.reactivestreams", module = "reactive-streams")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
||||||
@@ -228,3 +240,10 @@ tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.named("preBuild") { dependsOn("copyLicenseeJsonToAssets") }
|
tasks.named("preBuild") { dependsOn("copyLicenseeJsonToAssets") }
|
||||||
|
|
||||||
|
// https://gist.github.com/obfusk/61046e09cee352ae6dd109911534b12e#fix-proposed-by-linsui-disable-baseline-profiles
|
||||||
|
tasks.whenTaskAdded {
|
||||||
|
if (name.contains("ArtProfile")) {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -155,9 +155,7 @@
|
|||||||
"columnNames": [
|
"columnNames": [
|
||||||
"id"
|
"id"
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
"indices": [],
|
|
||||||
"foreignKeys": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tableName": "TunnelConfig",
|
"tableName": "TunnelConfig",
|
||||||
@@ -227,21 +225,18 @@
|
|||||||
"fieldPath": "pingInterval",
|
"fieldPath": "pingInterval",
|
||||||
"columnName": "ping_interval",
|
"columnName": "ping_interval",
|
||||||
"affinity": "INTEGER",
|
"affinity": "INTEGER",
|
||||||
"notNull": false,
|
|
||||||
"defaultValue": "null"
|
"defaultValue": "null"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldPath": "pingCooldown",
|
"fieldPath": "pingCooldown",
|
||||||
"columnName": "ping_cooldown",
|
"columnName": "ping_cooldown",
|
||||||
"affinity": "INTEGER",
|
"affinity": "INTEGER",
|
||||||
"notNull": false,
|
|
||||||
"defaultValue": "null"
|
"defaultValue": "null"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldPath": "pingIp",
|
"fieldPath": "pingIp",
|
||||||
"columnName": "ping_ip",
|
"columnName": "ping_ip",
|
||||||
"affinity": "TEXT",
|
"affinity": "TEXT",
|
||||||
"notNull": false,
|
|
||||||
"defaultValue": "null"
|
"defaultValue": "null"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -275,11 +270,9 @@
|
|||||||
"orders": [],
|
"orders": [],
|
||||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"foreignKeys": []
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"views": [],
|
|
||||||
"setupQueries": [
|
"setupQueries": [
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ae51793c4d09ea3194ecd26f0606f35c')"
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ae51793c4d09ea3194ecd26f0606f35c')"
|
||||||
|
|||||||
@@ -0,0 +1,295 @@
|
|||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 17,
|
||||||
|
"identityHash": "380d82359c99933cc9ce783347c4ec31",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "Settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL, `trusted_network_ssids` TEXT NOT NULL, `is_always_on_vpn_enabled` INTEGER NOT NULL, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_enabled` INTEGER NOT NULL DEFAULT false, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT false, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_amnezia_enabled` INTEGER NOT NULL DEFAULT false, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT false, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT false, `is_vpn_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT false, `split_tunnel_apps` TEXT NOT NULL DEFAULT '', `wifi_detection_method` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAutoTunnelEnabled",
|
||||||
|
"columnName": "is_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||||
|
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "trustedNetworkSSIDs",
|
||||||
|
"columnName": "trusted_network_ssids",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||||
|
"columnName": "is_always_on_vpn_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||||
|
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isShortcutsEnabled",
|
||||||
|
"columnName": "is_shortcuts_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnWifiEnabled",
|
||||||
|
"columnName": "is_tunnel_on_wifi_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isKernelEnabled",
|
||||||
|
"columnName": "is_kernel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRestoreOnBootEnabled",
|
||||||
|
"columnName": "is_restore_on_boot_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMultiTunnelEnabled",
|
||||||
|
"columnName": "is_multi_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingEnabled",
|
||||||
|
"columnName": "is_ping_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAmneziaEnabled",
|
||||||
|
"columnName": "is_amnezia_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isWildcardsEnabled",
|
||||||
|
"columnName": "is_wildcards_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isStopOnNoInternetEnabled",
|
||||||
|
"columnName": "is_stop_on_no_internet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isVpnKillSwitchEnabled",
|
||||||
|
"columnName": "is_vpn_kill_switch_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isKernelKillSwitchEnabled",
|
||||||
|
"columnName": "is_kernel_kill_switch_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isLanOnKillSwitchEnabled",
|
||||||
|
"columnName": "is_lan_on_kill_switch_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "debounceDelaySeconds",
|
||||||
|
"columnName": "debounce_delay_seconds",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
||||||
|
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||||
|
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "splitTunnelApps",
|
||||||
|
"columnName": "split_tunnel_apps",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wifiDetectionMethod",
|
||||||
|
"columnName": "wifi_detection_method",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "TunnelConfig",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `ping_interval` INTEGER DEFAULT null, `ping_cooldown` INTEGER DEFAULT null, `ping_ip` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "name",
|
||||||
|
"columnName": "name",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wgQuick",
|
||||||
|
"columnName": "wg_quick",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "tunnelNetworks",
|
||||||
|
"columnName": "tunnel_networks",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMobileDataTunnel",
|
||||||
|
"columnName": "is_mobile_data_tunnel",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPrimaryTunnel",
|
||||||
|
"columnName": "is_primary_tunnel",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "amQuick",
|
||||||
|
"columnName": "am_quick",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isActive",
|
||||||
|
"columnName": "is_Active",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingEnabled",
|
||||||
|
"columnName": "is_ping_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pingInterval",
|
||||||
|
"columnName": "ping_interval",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"defaultValue": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pingCooldown",
|
||||||
|
"columnName": "ping_cooldown",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"defaultValue": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pingIp",
|
||||||
|
"columnName": "ping_ip",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"defaultValue": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isEthernetTunnel",
|
||||||
|
"columnName": "is_ethernet_tunnel",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isIpv4Preferred",
|
||||||
|
"columnName": "is_ipv4_preferred",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "true"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_TunnelConfig_name",
|
||||||
|
"unique": true,
|
||||||
|
"columnNames": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"setupQueries": [
|
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '380d82359c99933cc9ce783347c4ec31')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,302 @@
|
|||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 18,
|
||||||
|
"identityHash": "505728bad740c12bab998a066b569333",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "Settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL, `trusted_network_ssids` TEXT NOT NULL, `is_always_on_vpn_enabled` INTEGER NOT NULL, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_enabled` INTEGER NOT NULL DEFAULT false, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT false, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_amnezia_enabled` INTEGER NOT NULL DEFAULT false, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT false, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT false, `is_vpn_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT false, `split_tunnel_apps` TEXT NOT NULL DEFAULT '', `wifi_detection_method` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAutoTunnelEnabled",
|
||||||
|
"columnName": "is_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||||
|
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "trustedNetworkSSIDs",
|
||||||
|
"columnName": "trusted_network_ssids",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||||
|
"columnName": "is_always_on_vpn_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||||
|
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isShortcutsEnabled",
|
||||||
|
"columnName": "is_shortcuts_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnWifiEnabled",
|
||||||
|
"columnName": "is_tunnel_on_wifi_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isKernelEnabled",
|
||||||
|
"columnName": "is_kernel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRestoreOnBootEnabled",
|
||||||
|
"columnName": "is_restore_on_boot_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMultiTunnelEnabled",
|
||||||
|
"columnName": "is_multi_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingEnabled",
|
||||||
|
"columnName": "is_ping_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAmneziaEnabled",
|
||||||
|
"columnName": "is_amnezia_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isWildcardsEnabled",
|
||||||
|
"columnName": "is_wildcards_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isStopOnNoInternetEnabled",
|
||||||
|
"columnName": "is_stop_on_no_internet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isVpnKillSwitchEnabled",
|
||||||
|
"columnName": "is_vpn_kill_switch_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isKernelKillSwitchEnabled",
|
||||||
|
"columnName": "is_kernel_kill_switch_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isLanOnKillSwitchEnabled",
|
||||||
|
"columnName": "is_lan_on_kill_switch_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "debounceDelaySeconds",
|
||||||
|
"columnName": "debounce_delay_seconds",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
||||||
|
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||||
|
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "splitTunnelApps",
|
||||||
|
"columnName": "split_tunnel_apps",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wifiDetectionMethod",
|
||||||
|
"columnName": "wifi_detection_method",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "TunnelConfig",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `ping_interval` INTEGER DEFAULT null, `ping_cooldown` INTEGER DEFAULT null, `ping_ip` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true, `position` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "name",
|
||||||
|
"columnName": "name",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wgQuick",
|
||||||
|
"columnName": "wg_quick",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "tunnelNetworks",
|
||||||
|
"columnName": "tunnel_networks",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMobileDataTunnel",
|
||||||
|
"columnName": "is_mobile_data_tunnel",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPrimaryTunnel",
|
||||||
|
"columnName": "is_primary_tunnel",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "amQuick",
|
||||||
|
"columnName": "am_quick",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isActive",
|
||||||
|
"columnName": "is_Active",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingEnabled",
|
||||||
|
"columnName": "is_ping_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pingInterval",
|
||||||
|
"columnName": "ping_interval",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"defaultValue": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pingCooldown",
|
||||||
|
"columnName": "ping_cooldown",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"defaultValue": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pingIp",
|
||||||
|
"columnName": "ping_ip",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"defaultValue": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isEthernetTunnel",
|
||||||
|
"columnName": "is_ethernet_tunnel",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isIpv4Preferred",
|
||||||
|
"columnName": "is_ipv4_preferred",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "position",
|
||||||
|
"columnName": "position",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_TunnelConfig_name",
|
||||||
|
"unique": true,
|
||||||
|
"columnNames": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"setupQueries": [
|
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '505728bad740c12bab998a066b569333')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,316 @@
|
|||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 19,
|
||||||
|
"identityHash": "82bdb96b7a9f8695a34ad1ec21d9aea8",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "Settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL, `trusted_network_ssids` TEXT NOT NULL, `is_always_on_vpn_enabled` INTEGER NOT NULL, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_enabled` INTEGER NOT NULL DEFAULT false, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT false, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_amnezia_enabled` INTEGER NOT NULL DEFAULT false, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT false, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT false, `is_vpn_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT false, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT true, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAutoTunnelEnabled",
|
||||||
|
"columnName": "is_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||||
|
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "trustedNetworkSSIDs",
|
||||||
|
"columnName": "trusted_network_ssids",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||||
|
"columnName": "is_always_on_vpn_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||||
|
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isShortcutsEnabled",
|
||||||
|
"columnName": "is_shortcuts_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnWifiEnabled",
|
||||||
|
"columnName": "is_tunnel_on_wifi_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isKernelEnabled",
|
||||||
|
"columnName": "is_kernel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRestoreOnBootEnabled",
|
||||||
|
"columnName": "is_restore_on_boot_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMultiTunnelEnabled",
|
||||||
|
"columnName": "is_multi_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingEnabled",
|
||||||
|
"columnName": "is_ping_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAmneziaEnabled",
|
||||||
|
"columnName": "is_amnezia_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isWildcardsEnabled",
|
||||||
|
"columnName": "is_wildcards_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isStopOnNoInternetEnabled",
|
||||||
|
"columnName": "is_stop_on_no_internet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isVpnKillSwitchEnabled",
|
||||||
|
"columnName": "is_vpn_kill_switch_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isKernelKillSwitchEnabled",
|
||||||
|
"columnName": "is_kernel_kill_switch_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isLanOnKillSwitchEnabled",
|
||||||
|
"columnName": "is_lan_on_kill_switch_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "debounceDelaySeconds",
|
||||||
|
"columnName": "debounce_delay_seconds",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
||||||
|
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||||
|
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wifiDetectionMethod",
|
||||||
|
"columnName": "wifi_detection_method",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingMonitoringEnabled",
|
||||||
|
"columnName": "is_ping_monitoring_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "tunnelPingIntervalSeconds",
|
||||||
|
"columnName": "tunnel_ping_interval_sec",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "30"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "tunnelPingAttempts",
|
||||||
|
"columnName": "tunnel_ping_attempts",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "tunnelPingTimeoutSeconds",
|
||||||
|
"columnName": "tunnel_ping_timeout_sec",
|
||||||
|
"affinity": "INTEGER"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "TunnelConfig",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `restart_on_ping_failure` INTEGER NOT NULL DEFAULT false, `ping_target` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true, `position` INTEGER NOT NULL DEFAULT 0, `auto_tunnel_apps` TEXT NOT NULL DEFAULT '[]')",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "name",
|
||||||
|
"columnName": "name",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wgQuick",
|
||||||
|
"columnName": "wg_quick",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "tunnelNetworks",
|
||||||
|
"columnName": "tunnel_networks",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMobileDataTunnel",
|
||||||
|
"columnName": "is_mobile_data_tunnel",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPrimaryTunnel",
|
||||||
|
"columnName": "is_primary_tunnel",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "amQuick",
|
||||||
|
"columnName": "am_quick",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isActive",
|
||||||
|
"columnName": "is_Active",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "restartOnPingFailure",
|
||||||
|
"columnName": "restart_on_ping_failure",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pingTarget",
|
||||||
|
"columnName": "ping_target",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"defaultValue": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isEthernetTunnel",
|
||||||
|
"columnName": "is_ethernet_tunnel",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isIpv4Preferred",
|
||||||
|
"columnName": "is_ipv4_preferred",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "position",
|
||||||
|
"columnName": "position",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "autoTunnelApps",
|
||||||
|
"columnName": "auto_tunnel_apps",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "'[]'"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_TunnelConfig_name",
|
||||||
|
"unique": true,
|
||||||
|
"columnNames": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"setupQueries": [
|
||||||
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '82bdb96b7a9f8695a34ad1ec21d9aea8')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="ic_launcher_background">#648DB3</color>
|
||||||
|
</resources>
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
<!--foreground service permissions-->
|
<!--foreground service permissions-->
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
||||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||||
<!--start service on boot permission-->
|
<!--start service on boot permission-->
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
@@ -48,6 +47,10 @@
|
|||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent>
|
</intent>
|
||||||
|
<intent>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||||
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
<application
|
<application
|
||||||
android:name=".WireGuardAutoTunnel"
|
android:name=".WireGuardAutoTunnel"
|
||||||
@@ -62,6 +65,10 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.App.Start"
|
android:theme="@style/Theme.App.Start"
|
||||||
tools:targetApi="tiramisu">
|
tools:targetApi="tiramisu">
|
||||||
|
<activity
|
||||||
|
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
|
tools:replace="screenOrientation" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
@@ -78,10 +85,6 @@
|
|||||||
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
|
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
|
||||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
|
||||||
android:screenOrientation="portrait"
|
|
||||||
tools:replace="screenOrientation" />
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".core.shortcut.ShortcutsActivity"
|
android:name=".core.shortcut.ShortcutsActivity"
|
||||||
@@ -168,7 +171,6 @@
|
|||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.USER_PRESENT" />
|
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||||
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel
|
package com.zaneschepke.wireguardautotunnel
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -22,16 +20,15 @@ import androidx.compose.animation.slideOutVertically
|
|||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material.icons.rounded.Settings
|
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
@@ -39,6 +36,9 @@ import androidx.navigation.compose.rememberNavController
|
|||||||
import androidx.navigation.toRoute
|
import androidx.navigation.toRoute
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
||||||
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
|
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
||||||
@@ -50,11 +50,12 @@ import com.zaneschepke.wireguardautotunnel.ui.navigation.components.DynamicTopAp
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.currentNavBackStackEntryAsNavBarState
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.currentNavBackStackEntryAsNavBarState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.AutoTunnelScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.AutoTunnelScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.AutoTunnelAdvancedScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.AutoTunnelAdvancedScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.detection.WifiDetectionMethodScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.LocationDisclosureScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.LocationDisclosureScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.TunnelAutoTunnelScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.TunnelAutoTunnelScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.ConfigScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.ConfigScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.scanner.ScannerScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.sort.SortScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel.SplitTunnelScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel.SplitTunnelScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.TunnelOptionsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.TunnelOptionsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.pin.PinLockScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.pin.PinLockScreen
|
||||||
@@ -65,17 +66,22 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.displa
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.LanguageScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.LanguageScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.killswitch.KillSwitchScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.killswitch.KillSwitchScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.logs.LogsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.logs.LogsScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.monitoring.TunnelMonitoringScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.license.LicenseScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.license.LicenseScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.restartApp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.showToast
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import de.raphaelebner.roomdatabasebackup.core.RoomBackup
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.amnezia.awg.backend.GoBackend.VpnService
|
import org.amnezia.awg.backend.GoBackend.VpnService
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
@@ -86,8 +92,18 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
@Inject lateinit var networkMonitor: NetworkMonitor
|
@Inject lateinit var networkMonitor: NetworkMonitor
|
||||||
|
|
||||||
|
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
|
@Inject @MainDispatcher lateinit var mainDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
|
@Inject lateinit var appDatabase: AppDatabase
|
||||||
|
|
||||||
private var lastLocationPermissionState: Boolean? = null
|
private var lastLocationPermissionState: Boolean? = null
|
||||||
|
|
||||||
|
private lateinit var roomBackup: RoomBackup
|
||||||
|
|
||||||
|
val REQUEST_CODE = 123
|
||||||
|
|
||||||
@SuppressLint("BatteryLife")
|
@SuppressLint("BatteryLife")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
enableEdgeToEdge(
|
enableEdgeToEdge(
|
||||||
@@ -98,6 +114,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
window.isNavigationBarContrastEnforced = false
|
window.isNavigationBarContrastEnforced = false
|
||||||
}
|
}
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
roomBackup = RoomBackup(this)
|
||||||
|
|
||||||
val viewModel by viewModels<AppViewModel>()
|
val viewModel by viewModels<AppViewModel>()
|
||||||
|
|
||||||
@@ -109,7 +126,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val isTv = isRunningOnTv()
|
val isTv = isRunningOnTv()
|
||||||
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
||||||
val tunnelError by viewModel.tunnelManager.errorEvents.collectAsStateWithLifecycle(null)
|
|
||||||
|
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val backStackEntry by navController.currentBackStackEntryAsState()
|
val backStackEntry by navController.currentBackStackEntryAsState()
|
||||||
@@ -134,6 +150,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
vpnPermissionDenied = true
|
vpnPermissionDenied = true
|
||||||
} else {
|
} else {
|
||||||
vpnPermissionDenied = false
|
vpnPermissionDenied = false
|
||||||
|
showVpnPermissionDialog = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -151,15 +168,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
viewModel.handleEvent(AppEvent.SetBatteryOptimizeDisableShown)
|
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) {
|
with(appViewState) {
|
||||||
LaunchedEffect(isConfigChanged) {
|
LaunchedEffect(isConfigChanged) {
|
||||||
if (isConfigChanged) {
|
if (isConfigChanged) {
|
||||||
@@ -208,7 +216,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||||
VpnDeniedDialog(
|
VpnDeniedDialog(
|
||||||
showVpnPermissionDialog,
|
showVpnPermissionDialog,
|
||||||
onDismiss = { showVpnPermissionDialog = false },
|
onDismiss = {
|
||||||
|
showVpnPermissionDialog = false
|
||||||
|
vpnPermissionDenied = false
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
@@ -257,13 +268,13 @@ class MainActivity : AppCompatActivity() {
|
|||||||
MainScreen(appUiState, appViewState, viewModel)
|
MainScreen(appUiState, appViewState, viewModel)
|
||||||
}
|
}
|
||||||
composable<Route.Settings> {
|
composable<Route.Settings> {
|
||||||
SettingsScreen(appUiState, viewModel)
|
SettingsScreen(appUiState, appViewState, viewModel)
|
||||||
}
|
}
|
||||||
composable<Route.SettingsAdvanced> {
|
composable<Route.SettingsAdvanced> {
|
||||||
SettingsAdvancedScreen(appUiState, viewModel)
|
SettingsAdvancedScreen(appUiState, viewModel)
|
||||||
}
|
}
|
||||||
composable<Route.LocationDisclosure> {
|
composable<Route.LocationDisclosure> {
|
||||||
LocationDisclosureScreen(appUiState, viewModel)
|
LocationDisclosureScreen(viewModel)
|
||||||
}
|
}
|
||||||
composable<Route.AutoTunnel> {
|
composable<Route.AutoTunnel> {
|
||||||
AutoTunnelScreen(appUiState, viewModel)
|
AutoTunnelScreen(appUiState, viewModel)
|
||||||
@@ -282,23 +293,30 @@ class MainActivity : AppCompatActivity() {
|
|||||||
composable<Route.AutoTunnelAdvanced> {
|
composable<Route.AutoTunnelAdvanced> {
|
||||||
AutoTunnelAdvancedScreen(appUiState, viewModel)
|
AutoTunnelAdvancedScreen(appUiState, viewModel)
|
||||||
}
|
}
|
||||||
|
composable<Route.WifiDetectionMethod> {
|
||||||
|
WifiDetectionMethodScreen(appUiState, viewModel)
|
||||||
|
}
|
||||||
composable<Route.Logs> { LogsScreen(appViewState, viewModel) }
|
composable<Route.Logs> { LogsScreen(appViewState, viewModel) }
|
||||||
composable<Route.Config> { backStack ->
|
composable<Route.Config> { backStack ->
|
||||||
val args = backStack.toRoute<Route.Config>()
|
val args = backStack.toRoute<Route.Config>()
|
||||||
val config =
|
val config =
|
||||||
appUiState.tunnels.firstOrNull { it.id == args.id }
|
appUiState.tunnels.firstOrNull { it.id == args.id }
|
||||||
ConfigScreen(config, viewModel)
|
ConfigScreen(config, appUiState, viewModel)
|
||||||
}
|
}
|
||||||
composable<Route.TunnelOptions> { backStack ->
|
composable<Route.TunnelOptions> { backStack ->
|
||||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||||
appUiState.tunnels
|
appUiState.tunnels
|
||||||
.firstOrNull { it.id == args.id }
|
.firstOrNull { it.id == args.id }
|
||||||
?.let { config ->
|
?.let { config ->
|
||||||
TunnelOptionsScreen(config, viewModel)
|
TunnelOptionsScreen(
|
||||||
|
config,
|
||||||
|
viewModel,
|
||||||
|
appViewState,
|
||||||
|
appUiState.appSettings,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
composable<Route.Lock> { PinLockScreen(viewModel) }
|
composable<Route.Lock> { PinLockScreen(viewModel) }
|
||||||
composable<Route.Scanner> { ScannerScreen(viewModel) }
|
|
||||||
composable<Route.KillSwitch> {
|
composable<Route.KillSwitch> {
|
||||||
KillSwitchScreen(appUiState, viewModel)
|
KillSwitchScreen(appUiState, viewModel)
|
||||||
}
|
}
|
||||||
@@ -315,6 +333,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
composable<Route.Sort> { SortScreen(appUiState, viewModel) }
|
||||||
|
composable<Route.TunnelMonitoring> {
|
||||||
|
TunnelMonitoringScreen(appUiState, viewModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -326,19 +348,61 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
checkPermissionAndNotify()
|
WireGuardAutoTunnel.setUiActive(true)
|
||||||
|
networkMonitor.checkPermissionsAndUpdateState()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkPermissionAndNotify() {
|
override fun onPause() {
|
||||||
val hasLocation =
|
super.onPause()
|
||||||
ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) ==
|
WireGuardAutoTunnel.setUiActive(false)
|
||||||
PackageManager.PERMISSION_GRANTED
|
|
||||||
if (lastLocationPermissionState != hasLocation) {
|
|
||||||
Timber.d("Location permission changed to: $hasLocation")
|
|
||||||
if (hasLocation) {
|
|
||||||
networkMonitor.sendLocationPermissionsGrantedBroadcast()
|
|
||||||
}
|
|
||||||
lastLocationPermissionState = hasLocation
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun performBackup() =
|
||||||
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
|
roomBackup
|
||||||
|
.database(appDatabase)
|
||||||
|
.backupLocation(RoomBackup.BACKUP_FILE_LOCATION_CUSTOM_DIALOG)
|
||||||
|
.enableLogDebug(true)
|
||||||
|
.maxFileCount(5)
|
||||||
|
.apply {
|
||||||
|
onCompleteListener { success, message, exitCode ->
|
||||||
|
lifecycleScope.launch(mainDispatcher) {
|
||||||
|
if (success) {
|
||||||
|
showToast(
|
||||||
|
getString(
|
||||||
|
R.string.backup_success,
|
||||||
|
getString(R.string.restarting_app),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
restartApp()
|
||||||
|
} else showToast(R.string.backup_failed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.backup()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun performRestore() =
|
||||||
|
lifecycleScope.launch {
|
||||||
|
roomBackup
|
||||||
|
.database(appDatabase)
|
||||||
|
.enableLogDebug(true)
|
||||||
|
.backupLocation(RoomBackup.BACKUP_FILE_LOCATION_CUSTOM_DIALOG)
|
||||||
|
.apply {
|
||||||
|
onCompleteListener { success, message, exitCode ->
|
||||||
|
lifecycleScope.launch(mainDispatcher) {
|
||||||
|
if (success) {
|
||||||
|
showToast(
|
||||||
|
getString(
|
||||||
|
R.string.restore_success,
|
||||||
|
getString(R.string.restarting_app),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
restartApp()
|
||||||
|
} else showToast(R.string.restore_failed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.restore()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,27 +4,25 @@ import android.app.Application
|
|||||||
import android.os.StrictMode
|
import android.os.StrictMode
|
||||||
import android.os.StrictMode.ThreadPolicy
|
import android.os.StrictMode.ThreadPolicy
|
||||||
import androidx.hilt.work.HiltWorkerFactory
|
import androidx.hilt.work.HiltWorkerFactory
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
|
||||||
import androidx.lifecycle.LifecycleOwner
|
|
||||||
import androidx.lifecycle.ProcessLifecycleOwner
|
|
||||||
import androidx.work.Configuration
|
import androidx.work.Configuration
|
||||||
import com.wireguard.android.backend.GoBackend
|
import com.wireguard.android.backend.GoBackend
|
||||||
import com.zaneschepke.logcatter.LogReader
|
import com.zaneschepke.logcatter.LogReader
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.worker.ServiceWorker
|
import com.zaneschepke.wireguardautotunnel.core.worker.ServiceWorker
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
||||||
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.flow.update
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@HiltAndroidApp
|
@HiltAndroidApp
|
||||||
@@ -45,12 +43,13 @@ class WireGuardAutoTunnel : Application(), Configuration.Provider {
|
|||||||
|
|
||||||
@Inject @MainDispatcher lateinit var mainDispatcher: CoroutineDispatcher
|
@Inject @MainDispatcher lateinit var mainDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
|
@Inject lateinit var notificationMonitor: NotificationMonitor
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
instance = this
|
instance = this
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifecycleObserver())
|
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Timber.plant(Timber.DebugTree())
|
Timber.plant(Timber.DebugTree())
|
||||||
StrictMode.setThreadPolicy(
|
StrictMode.setThreadPolicy(
|
||||||
@@ -80,6 +79,7 @@ class WireGuardAutoTunnel : Application(), Configuration.Provider {
|
|||||||
ServiceWorker.start(this)
|
ServiceWorker.start(this)
|
||||||
|
|
||||||
applicationScope.launch {
|
applicationScope.launch {
|
||||||
|
launch { notificationMonitor.handleApplicationNotifications() }
|
||||||
appDataRepository.appState.getLocale()?.let {
|
appDataRepository.appState.getLocale()?.let {
|
||||||
withContext(mainDispatcher) { LocaleUtil.changeLocale(it) }
|
withContext(mainDispatcher) { LocaleUtil.changeLocale(it) }
|
||||||
}
|
}
|
||||||
@@ -90,30 +90,20 @@ class WireGuardAutoTunnel : Application(), Configuration.Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onTerminate() {
|
override fun onTerminate() {
|
||||||
applicationScope.launch {
|
applicationScope.cancel()
|
||||||
tunnelManager.setBackendState(BackendState.INACTIVE, emptyList())
|
tunnelManager.setBackendStatus(BackendStatus.Inactive)
|
||||||
}
|
|
||||||
super.onTerminate()
|
super.onTerminate()
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppLifecycleObserver : DefaultLifecycleObserver {
|
|
||||||
|
|
||||||
override fun onStart(owner: LifecycleOwner) {
|
|
||||||
Timber.d("Application entered foreground")
|
|
||||||
foreground = true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPause(owner: LifecycleOwner) {
|
|
||||||
Timber.d("Application entered background")
|
|
||||||
foreground = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var foreground = false
|
|
||||||
|
|
||||||
fun isForeground(): Boolean {
|
private val _uiActive = MutableStateFlow(false)
|
||||||
return foreground
|
|
||||||
|
val uiActive: StateFlow<Boolean>
|
||||||
|
get() = _uiActive
|
||||||
|
|
||||||
|
fun setUiActive(active: Boolean) {
|
||||||
|
_uiActive.update { active }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Volatile private var lastActiveTunnels: List<Int> = emptyList()
|
@Volatile private var lastActiveTunnels: List<Int> = emptyList()
|
||||||
|
|||||||
+4
-4
@@ -3,12 +3,12 @@ package com.zaneschepke.wireguardautotunnel.core.broadcast
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -26,13 +26,12 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
|
@Inject lateinit var logReader: LogReader
|
||||||
|
|
||||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
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_USER_PRESENT && !isTv) return
|
|
||||||
serviceManager.updateTunnelTile()
|
serviceManager.updateTunnelTile()
|
||||||
serviceManager.updateAutoTunnelTile()
|
serviceManager.updateAutoTunnelTile()
|
||||||
applicationScope.launch(ioDispatcher) {
|
applicationScope.launch(ioDispatcher) {
|
||||||
@@ -50,6 +49,7 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
} else {
|
} else {
|
||||||
Timber.d("Restore on boot disabled, skipping")
|
Timber.d("Restore on boot disabled, skipping")
|
||||||
}
|
}
|
||||||
|
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) logReader.deleteAndClearLogs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -43,8 +43,14 @@ interface NotificationManager {
|
|||||||
fun show(notificationId: Int, notification: Notification)
|
fun show(notificationId: Int, notification: Notification)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val AUTO_TUNNEL_LOCATION_PERMISSION_ID = 123
|
||||||
|
const val AUTO_TUNNEL_LOCATION_SERVICES_ID = 124
|
||||||
|
// For auto tunnel foreground notification
|
||||||
const val AUTO_TUNNEL_NOTIFICATION_ID = 122
|
const val AUTO_TUNNEL_NOTIFICATION_ID = 122
|
||||||
|
// for tunnel foreground notification
|
||||||
const val VPN_NOTIFICATION_ID = 100
|
const val VPN_NOTIFICATION_ID = 100
|
||||||
|
const val TUNNEL_ERROR_NOTIFICATION_ID = 101
|
||||||
|
const val TUNNEL_MESSAGES_NOTIFICATION_ID = 102
|
||||||
const val EXTRA_ID = "id"
|
const val EXTRA_ID = "id"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+63
@@ -0,0 +1,63 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.core.notification
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
|
import jakarta.inject.Inject
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class NotificationMonitor
|
||||||
|
@Inject
|
||||||
|
constructor(
|
||||||
|
private val tunnelManager: TunnelManager,
|
||||||
|
private val notificationManager: NotificationManager,
|
||||||
|
) {
|
||||||
|
suspend fun handleApplicationNotifications() = coroutineScope {
|
||||||
|
launch { handleTunnelErrors() }
|
||||||
|
launch { handleTunnelMessages() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun handleTunnelErrors() =
|
||||||
|
tunnelManager.errorEvents.collectLatest { (tunnelConf, error) ->
|
||||||
|
if (!WireGuardAutoTunnel.uiActive.value) {
|
||||||
|
val notification =
|
||||||
|
notificationManager.createNotification(
|
||||||
|
WireGuardNotification.NotificationChannels.VPN,
|
||||||
|
title = StringValue.DynamicString(tunnelConf.name),
|
||||||
|
description =
|
||||||
|
when (error) {
|
||||||
|
is BackendError.BounceFailed -> error.toStringValue()
|
||||||
|
else ->
|
||||||
|
StringValue.StringResource(
|
||||||
|
R.string.tunnel_error_template,
|
||||||
|
error.toStringRes(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
notificationManager.show(
|
||||||
|
NotificationManager.TUNNEL_ERROR_NOTIFICATION_ID,
|
||||||
|
notification,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun handleTunnelMessages() =
|
||||||
|
tunnelManager.messageEvents.collectLatest { (tunnelConf, message) ->
|
||||||
|
if (!WireGuardAutoTunnel.uiActive.value) {
|
||||||
|
val notification =
|
||||||
|
notificationManager.createNotification(
|
||||||
|
WireGuardNotification.NotificationChannels.VPN,
|
||||||
|
title = StringValue.DynamicString(tunnelConf.name),
|
||||||
|
description = message.toStringValue(),
|
||||||
|
)
|
||||||
|
notificationManager.show(
|
||||||
|
NotificationManager.TUNNEL_MESSAGES_NOTIFICATION_ID,
|
||||||
|
notification,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-6
@@ -7,9 +7,6 @@ import android.content.ServiceConnection
|
|||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
||||||
@@ -29,9 +26,9 @@ class ServiceManager
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
private val applicationScope: CoroutineScope,
|
||||||
@MainDispatcher private val mainDispatcher: CoroutineDispatcher,
|
private val mainDispatcher: CoroutineDispatcher,
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -96,6 +93,8 @@ constructor(
|
|||||||
service.stop()
|
service.stop()
|
||||||
try {
|
try {
|
||||||
context.unbindService(autoTunnelServiceConnection)
|
context.unbindService(autoTunnelServiceConnection)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e, "Failed to unbind AutoTunnelService")
|
||||||
} finally {
|
} finally {
|
||||||
_tunnelService.value = null
|
_tunnelService.value = null
|
||||||
}
|
}
|
||||||
@@ -120,6 +119,8 @@ constructor(
|
|||||||
service.stop()
|
service.stop()
|
||||||
try {
|
try {
|
||||||
context.unbindService(tunnelServiceConnection)
|
context.unbindService(tunnelServiceConnection)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e, "Failed to stop TunnelForegroundService")
|
||||||
} finally {
|
} finally {
|
||||||
_tunnelService.value = null
|
_tunnelService.value = null
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-194
@@ -7,39 +7,24 @@ import android.os.IBinder
|
|||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
|
||||||
import com.zaneschepke.networkmonitor.NetworkStatus
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import io.ktor.util.collections.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.NonCancellable
|
|
||||||
import kotlinx.coroutines.coroutineScope
|
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
|
||||||
import kotlinx.coroutines.flow.filterNotNull
|
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import kotlinx.coroutines.isActive
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.sync.Mutex
|
|
||||||
import kotlinx.coroutines.sync.withLock
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -49,23 +34,18 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
|
|
||||||
@Inject lateinit var serviceManager: ServiceManager
|
@Inject lateinit var serviceManager: ServiceManager
|
||||||
|
|
||||||
@Inject lateinit var networkMonitor: NetworkMonitor
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
|
@Inject lateinit var tunnelMonitor: TunnelMonitor
|
||||||
|
|
||||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
@Inject lateinit var tunnelRepo: TunnelRepository
|
@Inject lateinit var appDataRepository: AppDataRepository
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
|
||||||
|
|
||||||
private val isNetworkConnected = MutableStateFlow(true)
|
|
||||||
|
|
||||||
private val tunnelJobs = ConcurrentHashMap<TunnelConf, Job>()
|
|
||||||
private val pingJobs = ConcurrentHashMap<TunnelConf, Job>()
|
|
||||||
|
|
||||||
private val jobsMutex = Mutex()
|
|
||||||
|
|
||||||
class LocalBinder(val service: TunnelForegroundService) : Binder()
|
class LocalBinder(val service: TunnelForegroundService) : Binder()
|
||||||
|
|
||||||
|
private val tunnelJobs = ConcurrentMap<TunnelConf, Job>()
|
||||||
|
|
||||||
private val binder = LocalBinder(this)
|
private val binder = LocalBinder(this)
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
@@ -98,90 +78,23 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
fun start() =
|
fun start() =
|
||||||
lifecycleScope.launch(ioDispatcher) {
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
tunnelManager.activeTunnels.distinctByKeys().collect { activeTunnels ->
|
tunnelManager.activeTunnels.distinctByKeys().collect { activeTunnels ->
|
||||||
// No active tunnels and no jobs: nothing to do
|
val activeTunConfigs = activeTunnels.keys
|
||||||
if (activeTunnels.isEmpty() && tunnelJobs.isEmpty()) return@collect
|
val obsoleteJobs = tunnelJobs.keys - activeTunConfigs
|
||||||
|
obsoleteJobs.forEach { tunnelConf -> tunnelJobs[tunnelConf]?.cancel() }
|
||||||
// Synchronize jobs with active tunnels
|
activeTunConfigs.forEach { tun ->
|
||||||
synchronizeJobs(activeTunnels)
|
if (tunnelJobs.containsKey(tun)) return@forEach
|
||||||
updateServiceNotification()
|
tunnelJobs[tun] = launch { tunnelMonitor.startMonitoring(tun, true) }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun synchronizeJobs(activeTunnels: Map<TunnelConf, TunnelState>) {
|
|
||||||
jobsMutex.withLock {
|
|
||||||
// Stop jobs for tunnels that are no longer active
|
|
||||||
stopInactiveJobs(activeTunnels)
|
|
||||||
// Start jobs for new tunnels
|
|
||||||
startNewJobs(activeTunnels)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun stopInactiveJobs(activeTunnels: Map<TunnelConf, TunnelState>) {
|
|
||||||
// If no active tunnels, clear all jobs
|
|
||||||
if (activeTunnels.isEmpty()) {
|
|
||||||
clearAllJobs()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Stop jobs for tunnels not in activeTunnels
|
|
||||||
val tunnelsToStop = tunnelJobs.keys - activeTunnels.keys
|
|
||||||
tunnelsToStop.forEach { tun -> stopTunnelJobs(tun) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun clearAllJobs() {
|
|
||||||
tunnelJobs.forEach { (tun, job) ->
|
|
||||||
Timber.d("Stopping tunnel job for ${tun.tunName}")
|
|
||||||
job.cancel()
|
|
||||||
}
|
|
||||||
tunnelJobs.clear()
|
|
||||||
|
|
||||||
pingJobs.forEach { (tun, job) ->
|
|
||||||
if (isPingBounce(tun)) {
|
|
||||||
Timber.d("Preserving ping job for ${tun.tunName} due to PING bounce")
|
|
||||||
return@forEach
|
|
||||||
}
|
|
||||||
Timber.d("Stopping ping job for ${tun.tunName}")
|
|
||||||
job.cancel()
|
|
||||||
}
|
|
||||||
pingJobs.entries.removeIf { (tun, _) -> !isPingBounce(tun) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun stopTunnelJobs(tun: TunnelConf) {
|
|
||||||
tunnelJobs.remove(tun)?.cancel()
|
|
||||||
Timber.d("Stopped tunnel job for ${tun.tunName}")
|
|
||||||
if (isPingBounce(tun))
|
|
||||||
return Timber.d("Preserving ${tun.tunName} ping job due to ping bounce")
|
|
||||||
pingJobs.remove(tun)?.cancel()
|
|
||||||
Timber.d("Stopped ping job for ${tun.tunName}")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startNewJobs(activeTunnels: Map<TunnelConf, TunnelState>) {
|
|
||||||
val tunnelsToStart = activeTunnels.keys - tunnelJobs.keys
|
|
||||||
tunnelsToStart.forEach { tun ->
|
|
||||||
tunnelJobs[tun] = startTunnelJobs(tun)
|
|
||||||
Timber.d("Started tunnel job for ${tun.tunName}")
|
|
||||||
|
|
||||||
if (pingJobs[tun]?.isActive == true) {
|
|
||||||
Timber.d("Reusing active ping job for ${tun.tunName}")
|
|
||||||
} else {
|
|
||||||
pingJobs[tun]?.cancel() // Cancel any stale job
|
|
||||||
if (tun.isPingEnabled) {
|
|
||||||
pingJobs[tun] = startPingJob(tun)
|
|
||||||
Timber.d("Started ping job for ${tun.tunName}")
|
|
||||||
}
|
}
|
||||||
|
updateServiceNotification(activeTunnels)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun isPingBounce(tun: TunnelConf): Boolean =
|
|
||||||
tunnelManager.bouncingTunnelIds[tun.id] == TunnelStatus.StopReason.PING
|
|
||||||
|
|
||||||
// TODO Would be cool to have this include kill switch
|
// TODO Would be cool to have this include kill switch
|
||||||
// TODO also we need to include errors
|
private fun updateServiceNotification(activeTunnels: Map<TunnelConf, TunnelState>) {
|
||||||
private fun updateServiceNotification() {
|
|
||||||
val notification =
|
val notification =
|
||||||
when (tunnelJobs.size) {
|
when (activeTunnels.size) {
|
||||||
0 -> onCreateNotification()
|
0 -> onCreateNotification()
|
||||||
1 -> createTunnelNotification(tunnelJobs.keys.first())
|
1 -> createTunnelNotification(activeTunnels.keys.first())
|
||||||
else -> createTunnelsNotification()
|
else -> createTunnelsNotification()
|
||||||
}
|
}
|
||||||
ServiceCompat.startForeground(
|
ServiceCompat.startForeground(
|
||||||
@@ -192,91 +105,18 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// use same scope so we can cancel all of these
|
|
||||||
private fun startTunnelJobs(tunnelConf: TunnelConf) =
|
|
||||||
lifecycleScope.launch(ioDispatcher) {
|
|
||||||
// monitor if we have internet connectivity
|
|
||||||
launch { startNetworkMonitorJob() }
|
|
||||||
// job to trigger stats emit on interval
|
|
||||||
launch { startTunnelStatsJob(tunnelConf) }
|
|
||||||
// monitor changes to the tunnel config
|
|
||||||
launch { startTunnelConfChangesJob(tunnelConf) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun startTunnelConfChangesJob(tunnelConf: TunnelConf) {
|
|
||||||
tunnelRepo.flow
|
|
||||||
.flowOn(ioDispatcher)
|
|
||||||
.map { storedTunnels -> storedTunnels.firstOrNull { it.id == tunnelConf.id } }
|
|
||||||
.filterNotNull()
|
|
||||||
// only emit when one of these 3 values change
|
|
||||||
.distinctUntilChanged { old, new -> old == new }
|
|
||||||
.collect { storedTunnel ->
|
|
||||||
if (tunnelConf != storedTunnel) {
|
|
||||||
Timber.d("Config changed for ${storedTunnel.tunName}, bouncing")
|
|
||||||
// let this complete, even after cancel
|
|
||||||
withContext(NonCancellable) {
|
|
||||||
tunnelManager.bounceTunnel(
|
|
||||||
storedTunnel,
|
|
||||||
TunnelStatus.StopReason.CONFIG_CHANGED,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun startNetworkMonitorJob() {
|
|
||||||
networkMonitor.networkStatusFlow.flowOn(ioDispatcher).collectLatest { status ->
|
|
||||||
val isAvailable = status !is NetworkStatus.Disconnected
|
|
||||||
isNetworkConnected.value = isAvailable
|
|
||||||
Timber.d("Network available: $status")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun startTunnelStatsJob(tunnel: TunnelConf) = coroutineScope {
|
|
||||||
while (isActive) {
|
|
||||||
tunnelManager.updateTunnelStatistics(tunnel)
|
|
||||||
delay(STATS_DELAY)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startPingJob(tunnel: TunnelConf) =
|
|
||||||
lifecycleScope.launch(ioDispatcher) {
|
|
||||||
// delay for initial duration
|
|
||||||
delay(tunnel.pingInterval ?: Constants.PING_INTERVAL)
|
|
||||||
while (isActive) {
|
|
||||||
val shouldBounce = shouldBounceTunnel(tunnel)
|
|
||||||
val delayMs =
|
|
||||||
if (shouldBounce) {
|
|
||||||
// let this complete, even after cancel
|
|
||||||
withContext(NonCancellable) {
|
|
||||||
tunnelManager.bounceTunnel(tunnel, TunnelStatus.StopReason.PING)
|
|
||||||
}
|
|
||||||
tunnel.pingCooldown ?: Constants.PING_COOLDOWN
|
|
||||||
} else {
|
|
||||||
tunnel.pingInterval ?: Constants.PING_INTERVAL
|
|
||||||
}
|
|
||||||
delay(delayMs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun shouldBounceTunnel(tunnel: TunnelConf): Boolean {
|
|
||||||
if (!isNetworkConnected.value) {
|
|
||||||
Timber.d("Network disconnected, skipping ping for ${tunnel.tunName}")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return runCatching { !tunnel.isTunnelPingable(ioDispatcher) }
|
|
||||||
.onFailure { e -> Timber.e(e, "Ping check failed for ${tunnel.tunName}") }
|
|
||||||
.getOrDefault(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
Timber.d("Stop called")
|
||||||
|
tunnelJobs.forEach { it.value.cancel() }
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
tunnelJobs.forEach { it.value.cancel() }
|
||||||
serviceManager.handleTunnelServiceDestroy()
|
serviceManager.handleTunnelServiceDestroy()
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
|
Timber.d("onDestroy")
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,14 +151,4 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
title = getString(R.string.tunnel_starting),
|
title = getString(R.string.tunnel_starting),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add notification handling and optional log reading for restart on handshake failures
|
|
||||||
companion object {
|
|
||||||
const val STATS_DELAY = 1_000L
|
|
||||||
// ipv6 disabled or block on network
|
|
||||||
// Failed to send handshake initiation: write udp [::]"
|
|
||||||
// Failed to send data packets: write udp [::]
|
|
||||||
// Failed to send data packets: write udp 0.0.0.0:51820
|
|
||||||
// Handshake did not complete after 5 seconds, retrying
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+314
-130
@@ -3,46 +3,39 @@ package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.PowerManager
|
|
||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||||
|
import com.zaneschepke.networkmonitor.ConnectivityState
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
import com.zaneschepke.networkmonitor.NetworkStatus
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus.StopReason.Ping
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.KillSwitchEvent
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.AutoTunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.AutoTunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.NetworkState
|
import com.zaneschepke.wireguardautotunnel.domain.state.NetworkState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toMillis
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Provider
|
import javax.inject.Provider
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlin.math.pow
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.FlowPreview
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
|
||||||
import kotlinx.coroutines.flow.combine
|
|
||||||
import kotlinx.coroutines.flow.debounce
|
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
|
||||||
import kotlinx.coroutines.flow.flatMapLatest
|
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -60,13 +53,19 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
|
@Inject lateinit var tunnelMonitor: TunnelMonitor
|
||||||
|
|
||||||
private val defaultState = AutoTunnelState()
|
private val defaultState = AutoTunnelState()
|
||||||
|
|
||||||
|
private val autoTunMutex = Mutex()
|
||||||
|
|
||||||
private val autoTunnelStateFlow = MutableStateFlow(defaultState)
|
private val autoTunnelStateFlow = MutableStateFlow(defaultState)
|
||||||
|
|
||||||
private var wakeLock: PowerManager.WakeLock? = null
|
private val bounceCounts = MutableStateFlow<Map<Int, Int>>(emptyMap())
|
||||||
|
|
||||||
private var killSwitchJob: Job? = null
|
private var eventHandlerJob: Job? = null
|
||||||
|
|
||||||
|
private val lastBounceTimes = mutableMapOf<Int, Long>()
|
||||||
|
|
||||||
class LocalBinder(val service: AutoTunnelService) : Binder()
|
class LocalBinder(val service: AutoTunnelService) : Binder()
|
||||||
|
|
||||||
@@ -90,25 +89,19 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
kotlin
|
launchWatcherNotification()
|
||||||
.runCatching {
|
startAutoTunnelStateJob()
|
||||||
launchWatcherNotification()
|
startLocationPermissionsNotificationJob()
|
||||||
initWakeLock()
|
|
||||||
startAutoTunnelJob()
|
|
||||||
startAutoTunnelStateJob()
|
|
||||||
killSwitchJob = startKillSwitchJob()
|
|
||||||
}
|
|
||||||
.onFailure { Timber.e(it) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
wakeLock?.let { if (it.isHeld) it.release() }
|
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
serviceManager.handleAutoTunnelServiceDestroy()
|
serviceManager.handleAutoTunnelServiceDestroy()
|
||||||
restoreVpnKillSwitch()
|
restoreVpnKillSwitch()
|
||||||
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,13 +109,13 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
with(autoTunnelStateFlow.value) {
|
with(autoTunnelStateFlow.value) {
|
||||||
if (
|
if (
|
||||||
settings.isVpnKillSwitchEnabled &&
|
settings.isVpnKillSwitchEnabled &&
|
||||||
tunnelManager.getBackendState() != BackendState.KILL_SWITCH_ACTIVE
|
tunnelManager.getBackendStatus() !is BackendStatus.KillSwitch
|
||||||
) {
|
) {
|
||||||
killSwitchJob?.cancel()
|
eventHandlerJob?.cancel()
|
||||||
val allowedIps =
|
val allowedIps =
|
||||||
if (settings.isLanOnKillSwitchEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS
|
if (settings.isLanOnKillSwitchEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS
|
||||||
else emptyList()
|
else emptyList()
|
||||||
tunnelManager.setBackendState(BackendState.KILL_SWITCH_ACTIVE, allowedIps)
|
tunnelManager.setBackendStatus(BackendStatus.KillSwitch(allowedIps))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,80 +143,141 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initWakeLock() {
|
|
||||||
wakeLock =
|
|
||||||
(getSystemService(POWER_SERVICE) as PowerManager).run {
|
|
||||||
val tag = this.javaClass.name
|
|
||||||
newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "$tag::lock").apply {
|
|
||||||
try {
|
|
||||||
Timber.i("Initiating wakelock with 10 min timeout")
|
|
||||||
acquire(Constants.BATTERY_SAVER_WATCHER_WAKE_LOCK_TIMEOUT)
|
|
||||||
} finally {
|
|
||||||
release()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildNetworkState(networkStatus: NetworkStatus): NetworkState {
|
|
||||||
return with(autoTunnelStateFlow.value.networkState) {
|
|
||||||
val wifiName =
|
|
||||||
when (networkStatus) {
|
|
||||||
is NetworkStatus.Connected -> {
|
|
||||||
networkStatus.wifiSsid
|
|
||||||
}
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
copy(
|
|
||||||
isWifiConnected = networkStatus.wifiConnected,
|
|
||||||
isMobileDataConnected = networkStatus.cellularConnected,
|
|
||||||
isEthernetConnected = networkStatus.ethernetConnected,
|
|
||||||
wifiName = wifiName,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
|
||||||
private fun startAutoTunnelStateJob() =
|
private fun startAutoTunnelStateJob() =
|
||||||
lifecycleScope.launch(ioDispatcher) {
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
combine(
|
val networkFlow =
|
||||||
combineSettings(),
|
debouncedConnectivityStateFlow
|
||||||
appDataRepository
|
.flowOn(ioDispatcher)
|
||||||
.get()
|
.map(NetworkState::from)
|
||||||
.settings
|
.map { StateChange.NetworkChange(it) }
|
||||||
.flow
|
.distinctUntilChanged()
|
||||||
.distinctUntilChanged { old, new ->
|
|
||||||
old.isKernelEnabled == new.isKernelEnabled
|
val settingsFlow =
|
||||||
} // Only emit when isKernelEnabled changes
|
combineSettings().map { StateChange.SettingsChange(it.first, it.second) }
|
||||||
.flatMapLatest {
|
|
||||||
networkMonitor.networkStatusFlow.flowOn(ioDispatcher).map {
|
val tunnelsFlow =
|
||||||
buildNetworkState(it)
|
tunnelManager.activeTunnels.map { StateChange.ActiveTunnelsChange(it) }
|
||||||
}
|
|
||||||
}
|
val monitoringFlow =
|
||||||
.distinctUntilChanged(),
|
tunnelManager.activeTunnels
|
||||||
) { double, networkState ->
|
.map { map -> map.mapValues { (_, state) -> state.pingStates } }
|
||||||
AutoTunnelState(
|
.distinctUntilChanged()
|
||||||
tunnelManager.activeTunnels.value,
|
.map { StateChange.MonitoringChange(it) }
|
||||||
networkState,
|
|
||||||
double.first,
|
var reevaluationJob: Job? = null
|
||||||
double.second,
|
|
||||||
)
|
// get everything in sync before we use merge
|
||||||
}
|
combine(networkFlow, settingsFlow, tunnelsFlow, monitoringFlow) {
|
||||||
.collect { state ->
|
network,
|
||||||
|
settings,
|
||||||
|
tunnels,
|
||||||
|
monitoring ->
|
||||||
autoTunnelStateFlow.update {
|
autoTunnelStateFlow.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
activeTunnels = state.activeTunnels,
|
activeTunnels = tunnels.activeTunnels,
|
||||||
networkState = state.networkState,
|
networkState = network.networkState,
|
||||||
settings = state.settings,
|
settings = settings.settings,
|
||||||
tunnels = state.tunnels,
|
tunnels = settings.tunnels,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.first()
|
||||||
|
|
||||||
|
// use merge to limit the noise of a combine and also increase the scalability of auto
|
||||||
|
// tunnel handling new states
|
||||||
|
merge(networkFlow, settingsFlow, tunnelsFlow, monitoringFlow).collect { change ->
|
||||||
|
if (change !is StateChange.ActiveTunnelsChange) {
|
||||||
|
Timber.d("New state changed to ${change.javaClass.simpleName}")
|
||||||
|
}
|
||||||
|
|
||||||
|
when (change) {
|
||||||
|
is StateChange.NetworkChange -> {
|
||||||
|
reevaluationJob?.cancel()
|
||||||
|
val previousState = autoTunnelStateFlow.value
|
||||||
|
autoTunnelStateFlow.update { it.copy(networkState = change.networkState) }
|
||||||
|
// Android late mobile data state change, we can ignore handling this
|
||||||
|
if (
|
||||||
|
isAndroidLateCellularActiveChange(
|
||||||
|
previousState.networkState,
|
||||||
|
change.networkState,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Timber.d("Android late cellular active state change")
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is StateChange.SettingsChange -> {
|
||||||
|
reevaluationJob?.cancel()
|
||||||
|
autoTunnelStateFlow.update {
|
||||||
|
it.copy(settings = change.settings, tunnels = change.tunnels)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is StateChange.ActiveTunnelsChange -> {
|
||||||
|
autoTunnelStateFlow.update { it.copy(activeTunnels = change.activeTunnels) }
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
is StateChange.MonitoringChange -> {
|
||||||
|
change.pingStates.forEach { (config, pingState) ->
|
||||||
|
Timber.d("Ping state $pingState")
|
||||||
|
if (pingState?.all { it.value.isReachable } == true) {
|
||||||
|
Timber.d("Clearing bounce count on success")
|
||||||
|
bounceCounts.update { current ->
|
||||||
|
current.toMutableMap().apply { remove(config.id) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@collect handleAutoTunnelEvent(
|
||||||
|
autoTunnelStateFlow.value.determineAutoTunnelEvent(
|
||||||
|
StateChange.MonitoringChange(change.pingStates)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleAutoTunnelEvent(autoTunnelStateFlow.value.determineAutoTunnelEvent(change))
|
||||||
|
|
||||||
|
reevaluationJob = launch {
|
||||||
|
delay(REEVALUATE_CHECK_DELAY)
|
||||||
|
val currentState = autoTunnelStateFlow.value
|
||||||
|
if (currentState != defaultState) {
|
||||||
|
Timber.d("Re-evaluating auto-tunnel state..")
|
||||||
|
handleAutoTunnelEvent(currentState.determineAutoTunnelEvent(change))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isAndroidLateCellularActiveChange(
|
||||||
|
previous: NetworkState,
|
||||||
|
new: NetworkState,
|
||||||
|
): Boolean {
|
||||||
|
return (previous.isWifiConnected != new.isWifiConnected &&
|
||||||
|
previous.wifiName == new.wifiName &&
|
||||||
|
previous.isMobileDataConnected != new.isMobileDataConnected)
|
||||||
|
}
|
||||||
|
|
||||||
|
// all relevant settings to auto tunnel
|
||||||
|
private fun areAutoTunnelSettingsTheSame(old: AppSettings, new: AppSettings): Boolean {
|
||||||
|
return (old.isTunnelOnWifiEnabled == new.isTunnelOnWifiEnabled &&
|
||||||
|
old.isTunnelOnMobileDataEnabled == new.isTunnelOnMobileDataEnabled &&
|
||||||
|
old.isTunnelOnEthernetEnabled == new.isTunnelOnEthernetEnabled &&
|
||||||
|
old.trustedNetworkSSIDs == new.trustedNetworkSSIDs &&
|
||||||
|
old.isPingEnabled == new.isPingEnabled &&
|
||||||
|
old.debounceDelaySeconds == new.debounceDelaySeconds &&
|
||||||
|
old.wifiDetectionMethod == new.wifiDetectionMethod &&
|
||||||
|
old.isVpnKillSwitchEnabled == new.isVpnKillSwitchEnabled &&
|
||||||
|
old.isLanOnKillSwitchEnabled == new.isLanOnKillSwitchEnabled &&
|
||||||
|
old.isDisableKillSwitchOnTrustedEnabled == new.isDisableKillSwitchOnTrustedEnabled &&
|
||||||
|
old.isStopOnNoInternetEnabled == new.isStopOnNoInternetEnabled)
|
||||||
|
}
|
||||||
|
|
||||||
private fun combineSettings(): Flow<Pair<AppSettings, Tunnels>> {
|
private fun combineSettings(): Flow<Pair<AppSettings, Tunnels>> {
|
||||||
return combine(
|
return combine(
|
||||||
appDataRepository.get().settings.flow,
|
appDataRepository
|
||||||
|
.get()
|
||||||
|
.settings
|
||||||
|
.flow
|
||||||
|
.distinctUntilChanged(::areAutoTunnelSettingsTheSame),
|
||||||
appDataRepository.get().tunnels.flow.map { tunnels ->
|
appDataRepository.get().tunnels.flow.map { tunnels ->
|
||||||
// isActive is ignored for equality checks so user can manually toggle off
|
// isActive is ignored for equality checks so user can manually toggle off
|
||||||
// tunnel with auto-tunnel
|
// tunnel with auto-tunnel
|
||||||
@@ -235,44 +289,174 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startKillSwitchJob() =
|
private fun areAutoTunnelPermissionsRequiredTheSame(
|
||||||
|
old: AutoTunnelState,
|
||||||
|
new: AutoTunnelState,
|
||||||
|
): Boolean {
|
||||||
|
return (old.settings.wifiDetectionMethod == new.settings.wifiDetectionMethod &&
|
||||||
|
old.networkState.locationPermissionGranted ==
|
||||||
|
new.networkState.locationPermissionGranted &&
|
||||||
|
old.networkState.locationServicesEnabled == new.networkState.locationServicesEnabled &&
|
||||||
|
old.tunnels == new.tunnels &&
|
||||||
|
old.settings.trustedNetworkSSIDs == new.settings.trustedNetworkSSIDs)
|
||||||
|
}
|
||||||
|
|
||||||
|
// watch for changes to location permission and notify user it will impact auto-tunneling
|
||||||
|
// TODO or a recheck button for location permission so we dont have to poll it
|
||||||
|
private fun startLocationPermissionsNotificationJob(): Job =
|
||||||
lifecycleScope.launch(ioDispatcher) {
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
autoTunnelStateFlow.collect {
|
var locationServicesShown = false
|
||||||
if (it == defaultState) return@collect
|
var locationPermissionsShown = false
|
||||||
when (val event = it.asKillSwitchEvent()) {
|
|
||||||
KillSwitchEvent.DoNothing -> Unit
|
data class NetworkPermissionState(
|
||||||
is KillSwitchEvent.Start -> {
|
val detectionMethod: AndroidNetworkMonitor.WifiDetectionMethod,
|
||||||
Timber.d("Starting kill switch")
|
val locationServicesEnabled: Boolean,
|
||||||
tunnelManager.setBackendState(
|
val locationPermissionsEnabled: Boolean,
|
||||||
BackendState.KILL_SWITCH_ACTIVE,
|
val ssidReadRequired: Boolean,
|
||||||
event.allowedIps,
|
)
|
||||||
)
|
|
||||||
}
|
autoTunnelStateFlow
|
||||||
KillSwitchEvent.Stop -> {
|
.distinctUntilChanged(::areAutoTunnelPermissionsRequiredTheSame)
|
||||||
Timber.d("Stopping kill switch")
|
.map {
|
||||||
tunnelManager.setBackendState(BackendState.SERVICE_ACTIVE, emptySet())
|
NetworkPermissionState(
|
||||||
|
it.settings.wifiDetectionMethod,
|
||||||
|
it.networkState.locationServicesEnabled == true,
|
||||||
|
it.networkState.locationPermissionGranted == true,
|
||||||
|
(it.tunnels.any { tunnel -> tunnel.tunnelNetworks.isNotEmpty() } ||
|
||||||
|
it.settings.trustedNetworkSSIDs.isNotEmpty()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.collect { state ->
|
||||||
|
when (state.detectionMethod) {
|
||||||
|
AndroidNetworkMonitor.WifiDetectionMethod.DEFAULT,
|
||||||
|
AndroidNetworkMonitor.WifiDetectionMethod.LEGACY -> {
|
||||||
|
if (
|
||||||
|
!state.locationPermissionsEnabled &&
|
||||||
|
!locationPermissionsShown &&
|
||||||
|
state.ssidReadRequired
|
||||||
|
) {
|
||||||
|
locationPermissionsShown = true
|
||||||
|
val notification =
|
||||||
|
notificationManager.createNotification(
|
||||||
|
WireGuardNotification.NotificationChannels.AUTO_TUNNEL,
|
||||||
|
title = getString(R.string.warning),
|
||||||
|
description =
|
||||||
|
getString(R.string.location_permissions_missing),
|
||||||
|
)
|
||||||
|
notificationManager.show(
|
||||||
|
NotificationManager.AUTO_TUNNEL_LOCATION_PERMISSION_ID,
|
||||||
|
notification,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!state.locationServicesEnabled &&
|
||||||
|
!locationServicesShown &&
|
||||||
|
state.ssidReadRequired
|
||||||
|
) {
|
||||||
|
locationServicesShown = true
|
||||||
|
val notification =
|
||||||
|
notificationManager.createNotification(
|
||||||
|
WireGuardNotification.NotificationChannels.AUTO_TUNNEL,
|
||||||
|
title = getString(R.string.warning),
|
||||||
|
description =
|
||||||
|
getString(R.string.location_services_not_detected),
|
||||||
|
)
|
||||||
|
notificationManager.show(
|
||||||
|
NotificationManager.AUTO_TUNNEL_LOCATION_SERVICES_ID,
|
||||||
|
notification,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (state.locationServicesEnabled || !state.ssidReadRequired) {
|
||||||
|
notificationManager.remove(
|
||||||
|
NotificationManager.AUTO_TUNNEL_LOCATION_SERVICES_ID
|
||||||
|
)
|
||||||
|
locationServicesShown = false
|
||||||
|
}
|
||||||
|
if (state.locationPermissionsEnabled || !state.ssidReadRequired) {
|
||||||
|
notificationManager.remove(
|
||||||
|
NotificationManager.AUTO_TUNNEL_LOCATION_PERMISSION_ID
|
||||||
|
)
|
||||||
|
locationPermissionsShown = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(FlowPreview::class)
|
private suspend fun handleAutoTunnelEvent(autoTunnelEvent: AutoTunnelEvent) {
|
||||||
private fun startAutoTunnelJob() =
|
autoTunMutex.withLock {
|
||||||
lifecycleScope.launch(ioDispatcher) {
|
when (
|
||||||
Timber.i("Starting auto-tunnel network event watcher")
|
val event =
|
||||||
val settings = appDataRepository.get().settings.get()
|
autoTunnelEvent.also {
|
||||||
Timber.d("Starting with debounce delay of: ${settings.debounceDelaySeconds} seconds")
|
Timber.i("Auto tunnel event: ${it.javaClass.simpleName}")
|
||||||
autoTunnelStateFlow.debounce(settings.debounceDelayMillis()).collect { watcherState ->
|
}
|
||||||
if (watcherState == defaultState) return@collect
|
) {
|
||||||
Timber.d("New auto tunnel state emitted ${watcherState.networkState}")
|
is AutoTunnelEvent.Start ->
|
||||||
when (val event = watcherState.asAutoTunnelEvent()) {
|
(event.tunnelConf ?: appDataRepository.get().getPrimaryOrFirstTunnel())?.let {
|
||||||
is AutoTunnelEvent.Start ->
|
tunnelManager.startTunnel(it)
|
||||||
(event.tunnelConf ?: appDataRepository.get().getPrimaryOrFirstTunnel())
|
}
|
||||||
?.let { tunnelManager.startTunnel(it) }
|
is AutoTunnelEvent.Stop -> tunnelManager.stopTunnel()
|
||||||
// TODO improve this to target specific tunnels to better support multi-tunnel
|
AutoTunnelEvent.DoNothing -> Timber.i("Auto-tunneling: nothing to do")
|
||||||
is AutoTunnelEvent.Stop -> tunnelManager.stopTunnel()
|
is AutoTunnelEvent.Bounce ->
|
||||||
AutoTunnelEvent.DoNothing -> Timber.i("Auto-tunneling: no condition met")
|
handleBounceWithBackoff(event.configsPeerKeyResolvedMap)
|
||||||
|
is AutoTunnelEvent.StartKillSwitch -> {
|
||||||
|
Timber.d("Starting kill switch")
|
||||||
|
tunnelManager.setBackendStatus(BackendStatus.KillSwitch(event.allowedIps))
|
||||||
|
}
|
||||||
|
AutoTunnelEvent.StopKillSwitch -> {
|
||||||
|
Timber.d("Stopping kill switch")
|
||||||
|
tunnelManager.setBackendStatus(BackendStatus.Active)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun handleBounceWithBackoff(
|
||||||
|
configsPeerKeyResolvedMap: List<Pair<TunnelConf, Map<String, String?>>>
|
||||||
|
) { // Simplified param: no failureCount
|
||||||
|
val settings = appDataRepository.get().settings.get()
|
||||||
|
val pingIntervalMillis = settings.tunnelPingIntervalSeconds.toMillis()
|
||||||
|
configsPeerKeyResolvedMap.forEach { (config, peerMap) ->
|
||||||
|
val bounceCount = bounceCounts.value.getOrDefault(config.id, 0)
|
||||||
|
val exponent = bounceCount.toDouble()
|
||||||
|
val backoffDelay =
|
||||||
|
(pingIntervalMillis * 2.0.pow(exponent)).toLong().coerceAtMost(MAX_BACKOFF_MS)
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
val lastTime = lastBounceTimes.getOrDefault(config.id, 0L)
|
||||||
|
if (currentTime - lastTime >= backoffDelay) {
|
||||||
|
Timber.d(
|
||||||
|
"Bouncing tunnel ${config.name} after detecting failure, with bounce count $bounceCount and calculated backoff delay $backoffDelay ms"
|
||||||
|
)
|
||||||
|
tunnelManager.bounceTunnel(config, Ping(peerMap))
|
||||||
|
lastBounceTimes[config.id] = currentTime
|
||||||
|
bounceCounts.update { current ->
|
||||||
|
current.toMutableMap().apply { this[config.id] = (this[config.id] ?: 0) + 1 }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Timber.d(
|
||||||
|
"Backoff in progress for tunnel ${config.name}, skipping bounce (required delay: $backoffDelay ms)"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
|
||||||
|
private val debouncedConnectivityStateFlow: Flow<ConnectivityState> by lazy {
|
||||||
|
appDataRepository
|
||||||
|
.get()
|
||||||
|
.settings
|
||||||
|
.flow
|
||||||
|
.map { it.debounceDelaySeconds.toMillis() }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.flatMapLatest { debounceMillis ->
|
||||||
|
networkMonitor.connectivityStateFlow.debounce(debounceMillis)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
// try to keep this window short as it will interrupt manual overrides
|
||||||
|
const val REEVALUATE_CHECK_DELAY = 2_000L
|
||||||
|
const val MAX_BACKOFF_MS = 300_000L // 5 minutes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.NetworkState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
||||||
|
import org.amnezia.awg.crypto.Key
|
||||||
|
|
||||||
|
sealed class StateChange {
|
||||||
|
data class NetworkChange(val networkState: NetworkState) : StateChange()
|
||||||
|
|
||||||
|
data class SettingsChange(val settings: AppSettings, val tunnels: Tunnels) : StateChange()
|
||||||
|
|
||||||
|
data class ActiveTunnelsChange(val activeTunnels: Map<TunnelConf, TunnelState>) : StateChange()
|
||||||
|
|
||||||
|
data class MonitoringChange(val pingStates: Map<TunnelConf, Map<Key, PingState>?>) :
|
||||||
|
StateChange()
|
||||||
|
}
|
||||||
+1
-1
@@ -13,7 +13,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|||||||
@@ -2,37 +2,42 @@ package com.zaneschepke.wireguardautotunnel.core.tunnel
|
|||||||
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.state.ConfigProxy
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import kotlin.concurrent.thread
|
import kotlin.coroutines.cancellation.CancellationException
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import org.amnezia.awg.crypto.Key
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
abstract class BaseTunnel(
|
abstract class BaseTunnel(
|
||||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
private val applicationScope: CoroutineScope,
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
) : TunnelProvider {
|
) : TunnelProvider {
|
||||||
|
|
||||||
private val _errorEvents =
|
private val _errorEvents = MutableSharedFlow<Pair<TunnelConf, BackendError>>()
|
||||||
MutableSharedFlow<Pair<TunnelConf, BackendError>>(replay = 0, extraBufferCapacity = 1)
|
|
||||||
override val errorEvents = _errorEvents.asSharedFlow()
|
override val errorEvents = _errorEvents.asSharedFlow()
|
||||||
|
|
||||||
|
private val _messageEvents = MutableSharedFlow<Pair<TunnelConf, BackendMessage>>()
|
||||||
|
override val messageEvents = _messageEvents.asSharedFlow()
|
||||||
|
|
||||||
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
||||||
private val tunThreads = ConcurrentHashMap<Int, Thread>()
|
private val tunJobs = ConcurrentHashMap<Int, Job>()
|
||||||
override val activeTunnels = activeTuns.asStateFlow()
|
override val activeTunnels = activeTuns.asStateFlow()
|
||||||
|
|
||||||
private val tunMutex = Mutex()
|
private val tunMutex = Mutex()
|
||||||
@@ -49,32 +54,43 @@ abstract class BaseTunnel(
|
|||||||
return serviceManager.hasVpnPermission()
|
return serviceManager.hasVpnPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected suspend fun updateTunnelStatus(
|
override suspend fun updateTunnelStatus(
|
||||||
tunnelConf: TunnelConf,
|
tunnelConf: TunnelConf,
|
||||||
status: TunnelStatus? = null,
|
status: TunnelStatus?,
|
||||||
stats: TunnelStatistics? = null,
|
stats: TunnelStatistics?,
|
||||||
|
pingStates: Map<Key, PingState>?,
|
||||||
|
handshakeSuccessLogs: Boolean?,
|
||||||
) {
|
) {
|
||||||
tunStatusMutex.withLock {
|
tunStatusMutex.withLock {
|
||||||
activeTuns.update { currentTuns ->
|
activeTuns.update { currentTuns ->
|
||||||
val originalConf = currentTuns.getKeyById(tunnelConf.id) ?: tunnelConf
|
val originalConf = currentTuns.getKeyById(tunnelConf.id) ?: tunnelConf
|
||||||
val existingState = currentTuns.getValueById(tunnelConf.id) ?: TunnelState()
|
val existingState = currentTuns.getValueById(tunnelConf.id) ?: TunnelState()
|
||||||
val newState = status ?: existingState.status
|
val newStatus = status ?: existingState.status
|
||||||
if (newState == TunnelStatus.Down) {
|
if (newStatus == TunnelStatus.Down) {
|
||||||
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
||||||
cleanUpTunThread(tunnelConf)
|
cleanUpTunJob(tunnelConf)
|
||||||
currentTuns - originalConf
|
currentTuns - originalConf
|
||||||
} else if (existingState.status == newState && stats == null) {
|
} else if (
|
||||||
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
existingState.status == newStatus &&
|
||||||
|
stats == null &&
|
||||||
|
pingStates == null &&
|
||||||
|
handshakeSuccessLogs == null
|
||||||
|
) {
|
||||||
|
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newStatus")
|
||||||
currentTuns
|
currentTuns
|
||||||
} else {
|
} else {
|
||||||
val updated =
|
val updated =
|
||||||
existingState.copy(
|
existingState.copy(
|
||||||
status = newState,
|
status = newStatus,
|
||||||
statistics = stats ?: existingState.statistics,
|
statistics = stats ?: existingState.statistics,
|
||||||
|
pingStates = pingStates ?: existingState.pingStates,
|
||||||
|
handshakeSuccessLogs =
|
||||||
|
handshakeSuccessLogs ?: existingState.handshakeSuccessLogs,
|
||||||
)
|
)
|
||||||
currentTuns + (originalConf to updated)
|
currentTuns + (originalConf to updated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
handleServiceStateOnChange()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,44 +120,100 @@ abstract class BaseTunnel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
|
||||||
val stats = getStatistics(tunnel)
|
|
||||||
updateTunnelStatus(tunnel, null, stats)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun startTunnel(tunnelConf: TunnelConf) {
|
override suspend fun startTunnel(tunnelConf: TunnelConf) {
|
||||||
if (activeTuns.exists(tunnelConf.id) || tunThreads.containsKey(tunnelConf.id)) return
|
if (activeTuns.exists(tunnelConf.id) || tunJobs.containsKey(tunnelConf.id))
|
||||||
|
return Timber.w("Tunnel is already running ${tunnelConf.name}")
|
||||||
|
// For userspace, we need to make sure all previous tunnels are down
|
||||||
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
||||||
tunMutex.withLock {
|
tunMutex.withLock {
|
||||||
tunThreads[tunnelConf.id] = thread {
|
val job =
|
||||||
runBlocking {
|
applicationScope.launch {
|
||||||
try {
|
try {
|
||||||
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
||||||
startTunnelInner(tunnelConf)
|
startTunnelInner(tunnelConf)
|
||||||
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
||||||
} catch (e: InterruptedException) {
|
// catch cancellation that could occur before and during startTunnelInner
|
||||||
|
// and trigger at that suspend point
|
||||||
|
} catch (e: CancellationException) {
|
||||||
Timber.w(
|
Timber.w(
|
||||||
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
"Tunnel start has been cancelled as ${tunnelConf.name} failed to start"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tunJobs[tunnelConf.id] = job
|
||||||
|
job.invokeOnCompletion {
|
||||||
|
tunJobs.remove(tunnelConf.id)
|
||||||
|
Timber.d("Start job completed for tunnel ${tunnelConf.id}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun startTunnelInner(tunnelConf: TunnelConf) {
|
private suspend fun startTunnelInner(tunnelConf: TunnelConf) {
|
||||||
configureTunnelCallbacks(tunnelConf)
|
configureTunnelCallbacks(tunnelConf)
|
||||||
Timber.d("Starting backend for tunnel ${tunnelConf.id}...")
|
Timber.d("Starting backend for tunnel ${tunnelConf.id}...")
|
||||||
try {
|
|
||||||
startBackend(tunnelConf)
|
var currentConf = tunnelConf
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Up)
|
var restoreAttempted = false
|
||||||
Timber.d("Started for tun ${tunnelConf.id}...")
|
var originalError: BackendError? = null
|
||||||
saveTunnelActiveState(tunnelConf, true)
|
|
||||||
serviceManager.startTunnelForegroundService()
|
while (true) {
|
||||||
} catch (e: BackendError) {
|
try {
|
||||||
Timber.e(e, "Failed to start backend for ${tunnelConf.name}")
|
startBackend(currentConf)
|
||||||
_errorEvents.emit(tunnelConf to e)
|
updateTunnelStatus(currentConf, TunnelStatus.Up)
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
Timber.d("Started for tun ${currentConf.id}...")
|
||||||
|
saveTunnelActiveState(currentConf, true)
|
||||||
|
serviceManager.startTunnelForegroundService()
|
||||||
|
if (restoreAttempted)
|
||||||
|
_messageEvents.emit(tunnelConf to BackendMessage.BounceRecovery)
|
||||||
|
if (bouncingTunnelIds[currentConf.id] is TunnelStatus.StopReason.Ping) {
|
||||||
|
_messageEvents.emit(tunnelConf to BackendMessage.BounceSuccess)
|
||||||
|
}
|
||||||
|
return // Success, return
|
||||||
|
} catch (e: BackendError) {
|
||||||
|
originalError = originalError ?: e
|
||||||
|
val bounceReason = bouncingTunnelIds[currentConf.id]
|
||||||
|
if (!restoreAttempted && bounceReason is TunnelStatus.StopReason.Ping) {
|
||||||
|
Timber.i(
|
||||||
|
"Attempting to recover bounce failure with previously resolved endpoints for ${currentConf.name}"
|
||||||
|
)
|
||||||
|
try {
|
||||||
|
val previouslyResolved = bounceReason.previouslyResolvedEndpoints
|
||||||
|
val configProxy = ConfigProxy.from(currentConf.toAmConfig())
|
||||||
|
val updatedConfigProxy =
|
||||||
|
configProxy.copy(
|
||||||
|
peers =
|
||||||
|
configProxy.peers.map {
|
||||||
|
it.copy(
|
||||||
|
endpoint =
|
||||||
|
previouslyResolved[it.publicKey] ?: it.endpoint
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val (wg, amnezia) = updatedConfigProxy.buildConfigs()
|
||||||
|
currentConf =
|
||||||
|
currentConf.copyWithCallback(
|
||||||
|
amQuick = amnezia.toAwgQuickString(true),
|
||||||
|
wgQuick = wg.toWgQuickString(true),
|
||||||
|
)
|
||||||
|
bouncingTunnelIds.remove(currentConf.id)
|
||||||
|
restoreAttempted = true
|
||||||
|
continue // Retry
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(
|
||||||
|
e,
|
||||||
|
"Failed to update config with resolved endpoints for ${currentConf.name}",
|
||||||
|
)
|
||||||
|
// Fall through to failure (will emit BounceFailed since
|
||||||
|
// retryAttempted=true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Timber.e(e, "Failed to start backend for ${currentConf.name}")
|
||||||
|
val emitError =
|
||||||
|
if (restoreAttempted) BackendError.BounceFailed(originalError) else e
|
||||||
|
_errorEvents.emit(currentConf to emitError)
|
||||||
|
updateTunnelStatus(currentConf, TunnelStatus.Down)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,30 +246,23 @@ abstract class BaseTunnel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleServiceStateOnChange() {
|
private fun handleServiceStateOnChange() {
|
||||||
if (activeTuns.value.isEmpty() && bouncingTunnelIds.isEmpty())
|
if (activeTuns.value.isEmpty()) serviceManager.stopTunnelForegroundService()
|
||||||
serviceManager.stopTunnelForegroundService()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleStuckStartingTunnelShutdown(tunnel: TunnelConf) {
|
private suspend fun handleStuckStartingTunnelShutdown(tunnel: TunnelConf) {
|
||||||
Timber.d("Stuck in starting state so shutting down tunnel thread for tunnel ${tunnel.name}")
|
Timber.d("Stuck in starting state so cancelling job for tunnel ${tunnel.name}")
|
||||||
try {
|
try {
|
||||||
tunThreads[tunnel.id]?.let {
|
tunJobs[tunnel.id]?.cancel() ?: Timber.d("No job found for ${tunnel.name}")
|
||||||
if (it.state != Thread.State.TERMINATED) {
|
|
||||||
it.interrupt()
|
|
||||||
} else {
|
|
||||||
Timber.d("Thread already terminated")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Failed to stop tunnel thread for ${tunnel.name}")
|
Timber.e(e, "Failed to cancel job for ${tunnel.name}")
|
||||||
} finally {
|
} finally {
|
||||||
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
private fun cleanUpTunJob(tunnel: TunnelConf) {
|
||||||
Timber.d("Removing thread for ${tunnel.name}")
|
Timber.d("Removing job for ${tunnel.name}")
|
||||||
tunThreads -= tunnel.id
|
tunJobs -= tunnel.id
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeActiveTunnel(tunnelConf: TunnelConf) {
|
private fun removeActiveTunnel(tunnelConf: TunnelConf) {
|
||||||
@@ -210,16 +275,10 @@ abstract class BaseTunnel(
|
|||||||
"Bounce tunnel ${tunnelConf.name} for reason: $reason, current bouncing: ${bouncingTunnelIds.size}"
|
"Bounce tunnel ${tunnelConf.name} for reason: $reason, current bouncing: ${bouncingTunnelIds.size}"
|
||||||
)
|
)
|
||||||
bouncingTunnelIds[tunnelConf.id] = reason
|
bouncingTunnelIds[tunnelConf.id] = reason
|
||||||
try {
|
runCatching {
|
||||||
stopTunnel(tunnelConf, reason)
|
stopTunnel(tunnelConf, reason)
|
||||||
delay(BOUNCE_DELAY)
|
delay(BOUNCE_DELAY)
|
||||||
startTunnel(tunnelConf)
|
startTunnel(tunnelConf)
|
||||||
} finally {
|
|
||||||
bouncingTunnelIds.remove(tunnelConf.id)
|
|
||||||
handleServiceStateOnChange()
|
|
||||||
Timber.d(
|
|
||||||
"Cleared bounce state for ${tunnelConf.name}, remaining: ${bouncingTunnelIds.size}"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import com.wireguard.android.backend.BackendException
|
|||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.WireGuardStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.WireGuardStatistics
|
||||||
@@ -35,11 +36,17 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun startBackend(tunnel: TunnelConf) {
|
override suspend fun startBackend(tunnel: TunnelConf) {
|
||||||
|
// name too long for kernel mode
|
||||||
|
if (!tunnel.isNameKernelCompatible) throw BackendError.TunnelNameTooLong
|
||||||
try {
|
try {
|
||||||
updateTunnelStatus(tunnel, TunnelStatus.Starting)
|
updateTunnelStatus(tunnel, TunnelStatus.Starting)
|
||||||
backend.setState(tunnel, Tunnel.State.UP, tunnel.toWgConfig())
|
backend.setState(tunnel, Tunnel.State.UP, tunnel.toWgConfig())
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
|
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
||||||
throw e.toBackendError()
|
throw e.toBackendError()
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
||||||
|
throw BackendError.Config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,12 +59,12 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setBackendState(backendState: BackendState, allowedIps: Collection<String>) {
|
override fun setBackendStatus(backendStatus: BackendStatus) {
|
||||||
Timber.w("Not yet implemented for kernel")
|
Timber.w("Not yet implemented for kernel")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBackendState(): BackendState {
|
override fun getBackendStatus(): BackendStatus {
|
||||||
return BackendState.INACTIVE
|
return BackendStatus.Inactive
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> {
|
override suspend fun runningTunnelNames(): Set<String> {
|
||||||
|
|||||||
+65
-54
@@ -1,37 +1,32 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||||
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.enums.TunnelStatus
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
|
||||||
import kotlinx.coroutines.flow.filterNotNull
|
|
||||||
import kotlinx.coroutines.flow.flatMapLatest
|
|
||||||
import kotlinx.coroutines.flow.stateIn
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.plus
|
import kotlinx.coroutines.plus
|
||||||
|
import org.amnezia.awg.crypto.Key
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
class TunnelManager
|
class TunnelManager
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
@Kernel private val kernelTunnel: TunnelProvider,
|
private val kernelTunnel: TunnelProvider,
|
||||||
@Userspace private val userspaceTunnel: TunnelProvider,
|
private val userspaceTunnel: TunnelProvider,
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
applicationScope: CoroutineScope,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
ioDispatcher: CoroutineDispatcher,
|
||||||
) : TunnelProvider {
|
) : TunnelProvider {
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
@@ -39,7 +34,8 @@ constructor(
|
|||||||
appDataRepository.settings.flow
|
appDataRepository.settings.flow
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.flatMapLatest { settings ->
|
.flatMapLatest { settings ->
|
||||||
MutableStateFlow(if (settings.isKernelEnabled) kernelTunnel else userspaceTunnel)
|
val backend = if (settings.isKernelEnabled) kernelTunnel else userspaceTunnel
|
||||||
|
MutableStateFlow(backend)
|
||||||
}
|
}
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope = applicationScope.plus(ioDispatcher),
|
scope = applicationScope.plus(ioDispatcher),
|
||||||
@@ -47,25 +43,29 @@ constructor(
|
|||||||
initialValue = userspaceTunnel,
|
initialValue = userspaceTunnel,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>> =
|
||||||
|
tunnelProviderFlow.value.activeTunnels
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
override val activeTunnels =
|
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>> =
|
||||||
appDataRepository.settings.flow
|
tunnelProviderFlow
|
||||||
.filterNotNull()
|
.flatMapLatest { it.errorEvents }
|
||||||
.flatMapLatest { settings ->
|
.shareIn(
|
||||||
if (settings.isKernelEnabled) {
|
|
||||||
kernelTunnel.activeTunnels
|
|
||||||
} else {
|
|
||||||
userspaceTunnel.activeTunnels
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.stateIn(
|
|
||||||
scope = applicationScope.plus(ioDispatcher),
|
scope = applicationScope.plus(ioDispatcher),
|
||||||
started = SharingStarted.Eagerly,
|
started = SharingStarted.Eagerly,
|
||||||
initialValue = emptyMap(),
|
replay = 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
get() = tunnelProviderFlow.value.errorEvents
|
override val messageEvents: SharedFlow<Pair<TunnelConf, BackendMessage>> =
|
||||||
|
tunnelProviderFlow
|
||||||
|
.flatMapLatest { it.messageEvents }
|
||||||
|
.filterNotNull()
|
||||||
|
.shareIn(
|
||||||
|
scope = applicationScope.plus(ioDispatcher),
|
||||||
|
started = SharingStarted.Eagerly,
|
||||||
|
replay = 0,
|
||||||
|
)
|
||||||
|
|
||||||
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
||||||
tunnelProviderFlow.value.bouncingTunnelIds
|
tunnelProviderFlow.value.bouncingTunnelIds
|
||||||
@@ -74,8 +74,8 @@ constructor(
|
|||||||
return userspaceTunnel.hasVpnPermission()
|
return userspaceTunnel.hasVpnPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
override fun getStatistics(tunnelConf: TunnelConf): TunnelStatistics? {
|
||||||
tunnelProviderFlow.value.updateTunnelStatistics(tunnel)
|
return tunnelProviderFlow.value.getStatistics(tunnelConf)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun startTunnel(tunnelConf: TunnelConf) {
|
override suspend fun startTunnel(tunnelConf: TunnelConf) {
|
||||||
@@ -90,36 +90,47 @@ constructor(
|
|||||||
tunnelProviderFlow.value.bounceTunnel(tunnelConf, reason)
|
tunnelProviderFlow.value.bounceTunnel(tunnelConf, reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setBackendState(backendState: BackendState, allowedIps: Collection<String>) {
|
override fun setBackendStatus(backendStatus: BackendStatus) {
|
||||||
tunnelProviderFlow.value.setBackendState(backendState, allowedIps)
|
tunnelProviderFlow.value.setBackendStatus(backendStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBackendState(): BackendState {
|
override fun getBackendStatus(): BackendStatus {
|
||||||
return tunnelProviderFlow.value.getBackendState()
|
return tunnelProviderFlow.value.getBackendStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> {
|
override suspend fun runningTunnelNames(): Set<String> {
|
||||||
return tunnelProviderFlow.value.runningTunnelNames()
|
return tunnelProviderFlow.value.runningTunnelNames()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getStatistics(tunnelConf: TunnelConf): TunnelStatistics? {
|
override suspend fun updateTunnelStatus(
|
||||||
return tunnelProviderFlow.value.getStatistics(tunnelConf)
|
tunnelConf: TunnelConf,
|
||||||
|
status: TunnelStatus?,
|
||||||
|
stats: TunnelStatistics?,
|
||||||
|
pingStates: Map<Key, PingState>?,
|
||||||
|
handshakeSuccessLogs: Boolean?,
|
||||||
|
) {
|
||||||
|
tunnelProviderFlow.value.updateTunnelStatus(
|
||||||
|
tunnelConf,
|
||||||
|
status,
|
||||||
|
stats,
|
||||||
|
pingStates,
|
||||||
|
handshakeSuccessLogs,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun restorePreviousState() =
|
suspend fun restorePreviousState() {
|
||||||
applicationScope.launch(ioDispatcher) {
|
val settings = appDataRepository.settings.get()
|
||||||
val settings = appDataRepository.settings.get()
|
if (settings.isRestoreOnBootEnabled) {
|
||||||
if (settings.isRestoreOnBootEnabled) {
|
val previouslyActiveTuns = appDataRepository.tunnels.getActive()
|
||||||
val previouslyActiveTuns = appDataRepository.tunnels.getActive()
|
val tunsToStart =
|
||||||
val tunsToStart =
|
previouslyActiveTuns.filterNot { tun ->
|
||||||
previouslyActiveTuns.filterNot { tun ->
|
activeTunnels.value.any { tun.id == it.key.id }
|
||||||
activeTunnels.value.any { tun.id == it.key.id }
|
|
||||||
}
|
|
||||||
if (settings.isKernelEnabled) {
|
|
||||||
return@launch tunsToStart.forEach { startTunnel(it) }
|
|
||||||
} else {
|
|
||||||
tunsToStart.firstOrNull()?.let { startTunnel(it) }
|
|
||||||
}
|
}
|
||||||
|
if (settings.isKernelEnabled) {
|
||||||
|
return tunsToStart.forEach { startTunnel(it) }
|
||||||
|
} else {
|
||||||
|
tunsToStart.firstOrNull()?.let { startTunnel(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,269 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
|
import com.zaneschepke.logcatter.LogReader
|
||||||
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.FailureReason
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toMillis
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
||||||
|
import dagger.hilt.android.scopes.ServiceScoped
|
||||||
|
import io.ktor.util.collections.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.flow.*
|
||||||
|
import org.amnezia.awg.crypto.Key
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
@ServiceScoped
|
||||||
|
class TunnelMonitor
|
||||||
|
@Inject
|
||||||
|
constructor(
|
||||||
|
private val appDataRepository: AppDataRepository,
|
||||||
|
private val tunnelManager: TunnelManager,
|
||||||
|
private val networkMonitor: NetworkMonitor,
|
||||||
|
private val networkUtils: NetworkUtils,
|
||||||
|
private val logReader: LogReader,
|
||||||
|
) {
|
||||||
|
|
||||||
|
@OptIn(FlowPreview::class)
|
||||||
|
suspend fun startMonitoring(tunnelConf: TunnelConf, withLogs: Boolean): Job = coroutineScope {
|
||||||
|
launch {
|
||||||
|
launch { startTunnelConfChangesJob(tunnelConf) }
|
||||||
|
launch { startPingMonitor(tunnelConf) }
|
||||||
|
launch { startWgStatsPoll(tunnelConf) }
|
||||||
|
if (withLogs) launch { startLogsMonitor(tunnelConf) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun startTunnelConfChangesJob(tunnelConf: TunnelConf) {
|
||||||
|
appDataRepository.tunnels.flow
|
||||||
|
.map { storedTunnels -> storedTunnels.firstOrNull { it.id == tunnelConf.id } }
|
||||||
|
.filterNotNull()
|
||||||
|
.distinctUntilChanged { old, new -> old == new }
|
||||||
|
.collect { storedTunnel ->
|
||||||
|
if (tunnelConf != storedTunnel) {
|
||||||
|
Timber.d("Config changed for ${storedTunnel.tunName}, bouncing")
|
||||||
|
withContext(NonCancellable) {
|
||||||
|
tunnelManager.bounceTunnel(
|
||||||
|
storedTunnel,
|
||||||
|
TunnelStatus.StopReason.ConfigChanged,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun startLogsMonitor(tunnelConf: TunnelConf) {
|
||||||
|
logReader.liveLogs.collect { log ->
|
||||||
|
val healthLogs =
|
||||||
|
when {
|
||||||
|
log.message.contains(HANDSHAKE_RESPONSE_TEXT, true) ||
|
||||||
|
log.message.contains(KEEPALIVE_RESPONSE_TEXT, true) -> true
|
||||||
|
log.message.contains(HANDSHAKE_INIT_FAILED_TEXT, true) ||
|
||||||
|
log.message.contains(HANDSHAKE_NOT_COMPLETED_TEXT) ||
|
||||||
|
log.message.contains(DATA_PACKET_FAILED_TEXT) -> false
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
healthLogs?.let { healthy ->
|
||||||
|
tunnelManager.updateTunnelStatus(tunnelConf, null, null, null, healthy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun startPingMonitor(tunnelConf: TunnelConf) = coroutineScope {
|
||||||
|
val pingStatsFlow = MutableStateFlow<Map<Key, PingState>>(emptyMap())
|
||||||
|
|
||||||
|
val tunStateFlow =
|
||||||
|
tunnelManager.activeTunnels.mapNotNull { it.getValueById(tunnelConf.id) }.stateIn(this)
|
||||||
|
|
||||||
|
val connectivityStateFlow = networkMonitor.connectivityStateFlow.stateIn(this)
|
||||||
|
|
||||||
|
val isNetworkConnected = connectivityStateFlow.map { it.hasConnectivity() }.stateIn(this)
|
||||||
|
|
||||||
|
data class NetworkChangeKey(
|
||||||
|
val ethernetConnected: Boolean,
|
||||||
|
val wifiConnected: Boolean,
|
||||||
|
val cellularConnected: Boolean,
|
||||||
|
val wifiSsid: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
connectivityStateFlow
|
||||||
|
.map {
|
||||||
|
NetworkChangeKey(
|
||||||
|
ethernetConnected = it.ethernetConnected,
|
||||||
|
wifiConnected = it.wifiState.connected,
|
||||||
|
cellularConnected = it.cellularConnected,
|
||||||
|
wifiSsid = if (it.wifiState.connected) it.wifiState.ssid else null,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.stateIn(this)
|
||||||
|
|
||||||
|
appDataRepository.settings.flow
|
||||||
|
.distinctUntilChanged { old, new ->
|
||||||
|
old.isPingEnabled == new.isPingEnabled &&
|
||||||
|
old.tunnelPingIntervalSeconds == new.tunnelPingIntervalSeconds &&
|
||||||
|
old.tunnelPingAttempts == new.tunnelPingAttempts &&
|
||||||
|
old.tunnelPingTimeoutSeconds == new.tunnelPingTimeoutSeconds
|
||||||
|
}
|
||||||
|
.collectLatest { settings ->
|
||||||
|
if (!settings.isPingEnabled) return@collectLatest
|
||||||
|
|
||||||
|
Timber.d("Starting pinger for ${tunnelConf.tunName} with settings")
|
||||||
|
|
||||||
|
val config = tunnelConf.toAmConfig()
|
||||||
|
|
||||||
|
val pingablePeers = config.peers.filter { it.allowedIps.isNotEmpty() }
|
||||||
|
if (pingablePeers.isEmpty()) return@collectLatest
|
||||||
|
|
||||||
|
suspend fun performPing() {
|
||||||
|
val updates = ConcurrentMap<Key, PingState>()
|
||||||
|
|
||||||
|
pingablePeers.forEach { peer ->
|
||||||
|
val previousState = pingStatsFlow.value[peer.publicKey] ?: PingState()
|
||||||
|
|
||||||
|
val allowedIpStr = peer.allowedIps.firstOrNull()?.toString()
|
||||||
|
if (allowedIpStr == null) {
|
||||||
|
updates[peer.publicKey] =
|
||||||
|
previousState.copy(
|
||||||
|
isReachable = false,
|
||||||
|
failureReason = FailureReason.NoResolvedEndpoint,
|
||||||
|
lastPingAttemptMillis = System.currentTimeMillis(),
|
||||||
|
)
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
|
||||||
|
val host =
|
||||||
|
tunnelConf.pingTarget
|
||||||
|
?: {
|
||||||
|
val parts = allowedIpStr.split("/")
|
||||||
|
val internalIp =
|
||||||
|
if (parts.size == 2) parts[0] else allowedIpStr
|
||||||
|
|
||||||
|
val prefix =
|
||||||
|
if (parts.size == 2) parts[1].toIntOrNull() ?: 32
|
||||||
|
else 32
|
||||||
|
if (prefix <= 1) {
|
||||||
|
CLOUDFLARE_IPV4_IP
|
||||||
|
} else {
|
||||||
|
internalIp.removeSurrounding("[", "]")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.invoke()
|
||||||
|
|
||||||
|
val attemptTime = System.currentTimeMillis()
|
||||||
|
runCatching {
|
||||||
|
val pingStats =
|
||||||
|
settings.tunnelPingTimeoutSeconds?.let {
|
||||||
|
networkUtils.pingWithStats(
|
||||||
|
host,
|
||||||
|
settings.tunnelPingAttempts,
|
||||||
|
it.toMillis(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
?: networkUtils.pingWithStats(
|
||||||
|
host,
|
||||||
|
settings.tunnelPingAttempts,
|
||||||
|
)
|
||||||
|
|
||||||
|
updates[peer.publicKey] =
|
||||||
|
previousState.copy(
|
||||||
|
transmitted = pingStats.transmitted,
|
||||||
|
received = pingStats.received,
|
||||||
|
packetLoss = pingStats.packetLoss,
|
||||||
|
rttMin = pingStats.rttMin,
|
||||||
|
rttMax = pingStats.rttMax,
|
||||||
|
rttAvg = pingStats.rttAvg,
|
||||||
|
rttStddev = pingStats.rttStddev,
|
||||||
|
isReachable = pingStats.isReachable,
|
||||||
|
failureReason =
|
||||||
|
if (pingStats.isReachable) null
|
||||||
|
else FailureReason.PingFailed,
|
||||||
|
lastSuccessfulPingMillis =
|
||||||
|
pingStats.lastSuccessfulPingMillis
|
||||||
|
?: previousState.lastSuccessfulPingMillis,
|
||||||
|
pingTarget = host,
|
||||||
|
lastPingAttemptMillis = attemptTime,
|
||||||
|
)
|
||||||
|
Timber.d(
|
||||||
|
"Ping completed for peer ${peer.publicKey.toBase64().substring(0, 5)}.. to host $host with stats: $pingStats"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.onFailure {
|
||||||
|
Timber.e(
|
||||||
|
it,
|
||||||
|
"Ping failed for peer ${peer.publicKey} in ${tunnelConf.tunName} to host $host",
|
||||||
|
)
|
||||||
|
updates[peer.publicKey] =
|
||||||
|
previousState.copy(
|
||||||
|
isReachable = false,
|
||||||
|
failureReason = FailureReason.PingFailed,
|
||||||
|
pingTarget = host,
|
||||||
|
lastPingAttemptMillis = attemptTime,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updates.isNotEmpty()) {
|
||||||
|
pingStatsFlow.update { updates }
|
||||||
|
tunnelManager.updateTunnelStatus(tunnelConf, null, null, updates)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the tunnel to be fully active
|
||||||
|
tunStateFlow.filter { state -> state.status == TunnelStatus.Up }.first()
|
||||||
|
|
||||||
|
// small delay to make sure tunnel is fully up before we actively monitor
|
||||||
|
delay(3_000L)
|
||||||
|
|
||||||
|
while (isActive) {
|
||||||
|
if (isNetworkConnected.value) {
|
||||||
|
performPing()
|
||||||
|
} else {
|
||||||
|
pingStatsFlow.update { current ->
|
||||||
|
current.mapValues { entry ->
|
||||||
|
entry.value.copy(
|
||||||
|
isReachable = false,
|
||||||
|
failureReason = FailureReason.NoConnectivity,
|
||||||
|
lastPingAttemptMillis = System.currentTimeMillis(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tunnelManager.updateTunnelStatus(
|
||||||
|
tunnelConf,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
pingStatsFlow.value,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
delay(settings.tunnelPingIntervalSeconds.toMillis())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun startWgStatsPoll(tunnelConf: TunnelConf) = coroutineScope {
|
||||||
|
while (isActive) {
|
||||||
|
val stats = tunnelManager.getStatistics(tunnelConf)
|
||||||
|
tunnelManager.updateTunnelStatus(tunnelConf, null, stats, null)
|
||||||
|
delay(STATS_DELAY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val CLOUDFLARE_IPV6_IP = "2606:4700:4700::1111"
|
||||||
|
const val CLOUDFLARE_IPV4_IP = "1.1.1.1"
|
||||||
|
|
||||||
|
const val STATS_DELAY = 1_000L
|
||||||
|
|
||||||
|
const val KEEPALIVE_RESPONSE_TEXT = "Receiving keepalive packet"
|
||||||
|
const val HANDSHAKE_RESPONSE_TEXT = "Received handshake response"
|
||||||
|
const val HANDSHAKE_INIT_FAILED_TEXT = "Failed to send handshake initiation: write udp"
|
||||||
|
const val DATA_PACKET_FAILED_TEXT = "Failed to send data packets"
|
||||||
|
const val HANDSHAKE_NOT_COMPLETED_TEXT =
|
||||||
|
"Handshake did not complete after 5 seconds, retrying"
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
-10
@@ -1,14 +1,17 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||||
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.enums.TunnelStatus
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import org.amnezia.awg.crypto.Key
|
||||||
|
|
||||||
interface TunnelProvider {
|
interface TunnelProvider {
|
||||||
/** Starts the specified tunnel configuration. */
|
/** Starts the specified tunnel configuration. */
|
||||||
@@ -23,24 +26,24 @@ interface TunnelProvider {
|
|||||||
*/
|
*/
|
||||||
suspend fun stopTunnel(
|
suspend fun stopTunnel(
|
||||||
tunnelConf: TunnelConf? = null,
|
tunnelConf: TunnelConf? = null,
|
||||||
reason: TunnelStatus.StopReason = TunnelStatus.StopReason.USER,
|
reason: TunnelStatus.StopReason = TunnelStatus.StopReason.User,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bounces (stops and restarts) the specified tunnel.
|
* Bounces (stops and restarts) the specified tunnel.
|
||||||
*
|
*
|
||||||
* @param tunnelConf The tunnel to bounce.
|
* @param tunnelConf The tunnel to bounce.
|
||||||
* @param reason The reason for bouncing, defaults to USER for manual actions. Callers should
|
* @param reason The reason for bouncing, defaults to User for manual actions. Callers should
|
||||||
* override with specific reasons (e.g., PING, CONFIG_CHANGED) when applicable.
|
* override with specific reasons (e.g., Ping, ConfigChanged) when applicable.
|
||||||
*/
|
*/
|
||||||
suspend fun bounceTunnel(
|
suspend fun bounceTunnel(
|
||||||
tunnelConf: TunnelConf,
|
tunnelConf: TunnelConf,
|
||||||
reason: TunnelStatus.StopReason = TunnelStatus.StopReason.USER,
|
reason: TunnelStatus.StopReason = TunnelStatus.StopReason.User,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun setBackendState(backendState: BackendState, allowedIps: Collection<String>)
|
fun setBackendStatus(backendStatus: BackendStatus)
|
||||||
|
|
||||||
fun getBackendState(): BackendState
|
fun getBackendStatus(): BackendStatus
|
||||||
|
|
||||||
suspend fun runningTunnelNames(): Set<String>
|
suspend fun runningTunnelNames(): Set<String>
|
||||||
|
|
||||||
@@ -50,9 +53,17 @@ interface TunnelProvider {
|
|||||||
|
|
||||||
val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||||
|
|
||||||
|
val messageEvents: SharedFlow<Pair<TunnelConf, BackendMessage>>
|
||||||
|
|
||||||
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
||||||
|
|
||||||
fun hasVpnPermission(): Boolean
|
fun hasVpnPermission(): Boolean
|
||||||
|
|
||||||
suspend fun updateTunnelStatistics(tunnel: TunnelConf)
|
suspend fun updateTunnelStatus(
|
||||||
|
tunnelConf: TunnelConf,
|
||||||
|
status: TunnelStatus? = null,
|
||||||
|
stats: TunnelStatistics? = null,
|
||||||
|
pingStates: Map<Key, PingState>? = null,
|
||||||
|
handshakeSuccessLogs: Boolean? = null,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-42
@@ -1,15 +1,15 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.AmneziaStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.AmneziaStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asAmBackendState
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asAmBackendStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asBackendState
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asBackendStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.jvm.optionals.getOrNull
|
import kotlin.jvm.optionals.getOrNull
|
||||||
@@ -17,29 +17,38 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import org.amnezia.awg.backend.Backend
|
import org.amnezia.awg.backend.Backend
|
||||||
import org.amnezia.awg.backend.BackendException
|
import org.amnezia.awg.backend.BackendException
|
||||||
import org.amnezia.awg.backend.Tunnel
|
import org.amnezia.awg.backend.Tunnel
|
||||||
import org.amnezia.awg.config.Config
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class UserspaceTunnel
|
class UserspaceTunnel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
applicationScope: CoroutineScope,
|
||||||
val serviceManager: ServiceManager,
|
val serviceManager: ServiceManager,
|
||||||
val appDataRepository: AppDataRepository,
|
val appDataRepository: AppDataRepository,
|
||||||
private val backend: Backend,
|
private val backend: Backend,
|
||||||
) : BaseTunnel(applicationScope, appDataRepository, serviceManager) {
|
) : BaseTunnel(applicationScope, appDataRepository, serviceManager) {
|
||||||
|
|
||||||
private var previousBackendState: Pair<BackendState, Boolean>? = null
|
|
||||||
|
|
||||||
override suspend fun startBackend(tunnel: TunnelConf) {
|
override suspend fun startBackend(tunnel: TunnelConf) {
|
||||||
try {
|
try {
|
||||||
updateTunnelStatus(tunnel, TunnelStatus.Starting)
|
updateTunnelStatus(tunnel, TunnelStatus.Starting)
|
||||||
val amConfig = tunnel.toAmConfig()
|
val amConfig = tunnel.toAmConfig()
|
||||||
handleVpnKillSwitchWithDomainEndpoints(amConfig)
|
var previousKillSwitch: Backend.BackendStatus? = null
|
||||||
|
// prevent dns failures from bringing tuns up when vpn kill switch active
|
||||||
|
if (
|
||||||
|
amConfig.peers.any { it.endpoint.getOrNull()?.toString()?.isUrl() == true } &&
|
||||||
|
backend.backendStatus is Backend.BackendStatus.KillSwitchActive
|
||||||
|
) {
|
||||||
|
previousKillSwitch = backend.backendStatus
|
||||||
|
setBackendStatus(BackendStatus.Active)
|
||||||
|
}
|
||||||
backend.setState(tunnel, Tunnel.State.UP, amConfig)
|
backend.setState(tunnel, Tunnel.State.UP, amConfig)
|
||||||
|
previousKillSwitch?.let { backend.backendStatus = it }
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
||||||
throw e.toBackendError()
|
throw e.toBackendError()
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
||||||
|
throw BackendError.Config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,47 +59,20 @@ constructor(
|
|||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
||||||
throw e.toBackendError()
|
throw e.toBackendError()
|
||||||
} finally {
|
|
||||||
handlePreviouslyEnabledVpnKillSwitch()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop vpn kill switch if we need to resolve DNS for peer endpoints
|
override fun setBackendStatus(backendStatus: BackendStatus) {
|
||||||
private suspend fun handleVpnKillSwitchWithDomainEndpoints(config: Config) {
|
Timber.d("Setting backend state: $backendStatus")
|
||||||
if (
|
|
||||||
config.peers.any { it.endpoint.getOrNull()?.toString()?.isUrl() == true } &&
|
|
||||||
backend.backendState.asBackendState() == BackendState.KILL_SWITCH_ACTIVE
|
|
||||||
) {
|
|
||||||
val bypassLan = appDataRepository.settings.get().isLanOnKillSwitchEnabled
|
|
||||||
previousBackendState = Pair(BackendState.KILL_SWITCH_ACTIVE, bypassLan)
|
|
||||||
setBackendState(BackendState.SERVICE_ACTIVE, emptyList())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// restore vpn kill switch if needed
|
|
||||||
private fun handlePreviouslyEnabledVpnKillSwitch() {
|
|
||||||
// let auto tunnel handle this if it is active
|
|
||||||
if (serviceManager.autoTunnelService.value == null) {
|
|
||||||
previousBackendState?.let { (state, lanEnabled) ->
|
|
||||||
Timber.d("Restoring kill switch configuration")
|
|
||||||
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
|
|
||||||
backend.setBackendState(state.asAmBackendState(), lan)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
previousBackendState = null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setBackendState(backendState: BackendState, allowedIps: Collection<String>) {
|
|
||||||
Timber.d("Setting backend state: $backendState with allowedIps: $allowedIps")
|
|
||||||
try {
|
try {
|
||||||
backend.setBackendState(backendState.asAmBackendState(), allowedIps)
|
backend.backendStatus = backendStatus.asAmBackendStatus()
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
throw e.toBackendError()
|
throw e.toBackendError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBackendState(): BackendState {
|
override fun getBackendStatus(): BackendStatus {
|
||||||
return backend.backendState.asBackendState()
|
return backend.backendStatus.asBackendStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> {
|
override suspend fun runningTunnelNames(): Set<String> {
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ package com.zaneschepke.wireguardautotunnel.core.worker
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.hilt.work.HiltWorker
|
import androidx.hilt.work.HiltWorker
|
||||||
import androidx.work.CoroutineWorker
|
import androidx.work.*
|
||||||
import androidx.work.ExistingPeriodicWorkPolicy
|
|
||||||
import androidx.work.PeriodicWorkRequestBuilder
|
|
||||||
import androidx.work.WorkManager
|
|
||||||
import androidx.work.WorkerParameters
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data
|
package com.zaneschepke.wireguardautotunnel.data
|
||||||
|
|
||||||
import androidx.room.AutoMigration
|
import androidx.room.*
|
||||||
import androidx.room.Database
|
|
||||||
import androidx.room.DeleteColumn
|
|
||||||
import androidx.room.RoomDatabase
|
|
||||||
import androidx.room.TypeConverters
|
|
||||||
import androidx.room.migration.AutoMigrationSpec
|
import androidx.room.migration.AutoMigrationSpec
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities = [Settings::class, TunnelConfig::class],
|
entities = [Settings::class, TunnelConfig::class],
|
||||||
version = 16,
|
version = 19,
|
||||||
autoMigrations =
|
autoMigrations =
|
||||||
[
|
[
|
||||||
AutoMigration(from = 1, to = 2),
|
AutoMigration(from = 1, to = 2),
|
||||||
@@ -31,10 +27,13 @@ import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
|||||||
AutoMigration(from = 13, to = 14),
|
AutoMigration(from = 13, to = 14),
|
||||||
AutoMigration(from = 14, to = 15),
|
AutoMigration(from = 14, to = 15),
|
||||||
AutoMigration(from = 15, to = 16),
|
AutoMigration(from = 15, to = 16),
|
||||||
|
AutoMigration(from = 16, to = 17, spec = WifiDetectionMigration::class),
|
||||||
|
AutoMigration(from = 17, to = 18),
|
||||||
|
AutoMigration(from = 18, to = 19, spec = PingMigration::class),
|
||||||
],
|
],
|
||||||
exportSchema = true,
|
exportSchema = true,
|
||||||
)
|
)
|
||||||
@TypeConverters(DatabaseListConverters::class)
|
@TypeConverters(DatabaseConverters::class)
|
||||||
abstract class AppDatabase : RoomDatabase() {
|
abstract class AppDatabase : RoomDatabase() {
|
||||||
abstract fun settingDao(): SettingsDao
|
abstract fun settingDao(): SettingsDao
|
||||||
|
|
||||||
@@ -47,3 +46,25 @@ class RemoveLegacySettingColumnsMigration : AutoMigrationSpec
|
|||||||
|
|
||||||
@DeleteColumn(tableName = "Settings", columnName = "is_auto_tunnel_paused")
|
@DeleteColumn(tableName = "Settings", columnName = "is_auto_tunnel_paused")
|
||||||
class RemoveTunnelPauseMigration : AutoMigrationSpec
|
class RemoveTunnelPauseMigration : AutoMigrationSpec
|
||||||
|
|
||||||
|
@DeleteColumn(tableName = "Settings", columnName = "is_wifi_by_shell_enabled")
|
||||||
|
class WifiDetectionMigration : AutoMigrationSpec
|
||||||
|
|
||||||
|
@DeleteColumn.Entries(
|
||||||
|
DeleteColumn(tableName = "TunnelConfig", columnName = "ping_interval"),
|
||||||
|
DeleteColumn(tableName = "TunnelConfig", columnName = "ping_cooldown"),
|
||||||
|
DeleteColumn(tableName = "Settings", columnName = "split_tunnel_apps"),
|
||||||
|
)
|
||||||
|
@RenameColumn.Entries(
|
||||||
|
RenameColumn(
|
||||||
|
tableName = "TunnelConfig",
|
||||||
|
fromColumnName = "is_ping_enabled",
|
||||||
|
toColumnName = "restart_on_ping_failure",
|
||||||
|
),
|
||||||
|
RenameColumn(
|
||||||
|
tableName = "TunnelConfig",
|
||||||
|
fromColumnName = "ping_ip",
|
||||||
|
toColumnName = "ping_target",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
class PingMigration : AutoMigrationSpec
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class DataStoreManager(
|
|||||||
val theme = stringPreferencesKey("THEME")
|
val theme = stringPreferencesKey("THEME")
|
||||||
val isRemoteControlEnabled = booleanPreferencesKey("IS_REMOTE_CONTROL_ENABLED")
|
val isRemoteControlEnabled = booleanPreferencesKey("IS_REMOTE_CONTROL_ENABLED")
|
||||||
val remoteKey = stringPreferencesKey("REMOTE_KEY")
|
val remoteKey = stringPreferencesKey("REMOTE_KEY")
|
||||||
|
val showDetailedPingStats = booleanPreferencesKey("SHOW_DETAILED_PING_STATS")
|
||||||
}
|
}
|
||||||
|
|
||||||
// preferences
|
// preferences
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data
|
||||||
|
|
||||||
|
import androidx.room.TypeConverter
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
|
class DatabaseConverters {
|
||||||
|
@TypeConverter
|
||||||
|
fun listToString(value: List<String>): String {
|
||||||
|
return Json.encodeToString(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun stringToList(value: String): List<String> {
|
||||||
|
if (value.isBlank() || value.isEmpty()) return mutableListOf()
|
||||||
|
return try {
|
||||||
|
Json.decodeFromString<List<String>>(value)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
val list = value.split(",").toMutableList()
|
||||||
|
val json = listToString(list)
|
||||||
|
Json.decodeFromString<List<String>>(json)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TypeConverter fun fromStatus(status: Settings.WifiDetectionMethod): Int = status.value
|
||||||
|
|
||||||
|
@TypeConverter
|
||||||
|
fun toStatus(value: Int): Settings.WifiDetectionMethod =
|
||||||
|
Settings.WifiDetectionMethod.fromValue(value)
|
||||||
|
}
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data
|
|
||||||
|
|
||||||
import androidx.room.TypeConverter
|
|
||||||
import kotlinx.serialization.json.Json
|
|
||||||
|
|
||||||
class DatabaseListConverters {
|
|
||||||
@TypeConverter
|
|
||||||
fun listToString(value: MutableList<String>): String {
|
|
||||||
return Json.encodeToString(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
fun stringToList(value: String): MutableList<String> {
|
|
||||||
if (value.isBlank() || value.isEmpty()) return mutableListOf()
|
|
||||||
return try {
|
|
||||||
Json.decodeFromString<MutableList<String>>(value)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
val list = value.split(",").toMutableList()
|
|
||||||
val json = listToString(list)
|
|
||||||
Json.decodeFromString<MutableList<String>>(json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.dao
|
package com.zaneschepke.wireguardautotunnel.data.dao
|
||||||
|
|
||||||
import androidx.room.Dao
|
import androidx.room.*
|
||||||
import androidx.room.Delete
|
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.dao
|
package com.zaneschepke.wireguardautotunnel.data.dao
|
||||||
|
|
||||||
import androidx.room.Dao
|
import androidx.room.*
|
||||||
import androidx.room.Delete
|
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@@ -46,5 +42,6 @@ interface TunnelConfigDao {
|
|||||||
@Query("SELECT * FROM TUNNELCONFIG WHERE is_mobile_data_tunnel=1")
|
@Query("SELECT * FROM TUNNELCONFIG WHERE is_mobile_data_tunnel=1")
|
||||||
suspend fun findByMobileDataTunnel(): TunnelConfigs
|
suspend fun findByMobileDataTunnel(): TunnelConfigs
|
||||||
|
|
||||||
@Query("SELECT * FROM tunnelconfig") fun getAllFlow(): Flow<MutableList<TunnelConfig>>
|
@Query("SELECT * FROM tunnelconfig ORDER BY position")
|
||||||
|
fun getAllFlow(): Flow<List<TunnelConfig>>
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.model
|
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||||
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||||
|
|
||||||
|
data class GeneralState(
|
||||||
|
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
||||||
|
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
||||||
|
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
||||||
|
val expandedTunnelIds: List<Int> = emptyList(),
|
||||||
|
val isLocalLogsEnabled: Boolean = IS_LOGS_ENABLED_DEFAULT,
|
||||||
|
val isRemoteControlEnabled: Boolean = IS_REMOTE_CONTROL_ENABLED,
|
||||||
|
val showDetailedPingStats: Boolean = SHOW_DETAILED_PING_STATS_DEFAULT,
|
||||||
|
val remoteKey: String? = null,
|
||||||
|
val locale: String? = null,
|
||||||
|
val theme: Theme = Theme.AUTOMATIC,
|
||||||
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
||||||
|
const val BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT = false
|
||||||
|
const val PIN_LOCK_ENABLED_DEFAULT = false
|
||||||
|
const val IS_LOGS_ENABLED_DEFAULT = false
|
||||||
|
const val IS_REMOTE_CONTROL_ENABLED = false
|
||||||
|
const val SHOW_DETAILED_PING_STATS_DEFAULT = false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||||
|
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class GitHubRelease(
|
||||||
|
@SerialName("tag_name") val tagName: String,
|
||||||
|
val name: String?,
|
||||||
|
val body: String?,
|
||||||
|
val assets: List<Asset>,
|
||||||
|
)
|
||||||
+20
-59
@@ -1,9 +1,8 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.model
|
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
data class Settings(
|
data class Settings(
|
||||||
@@ -11,8 +10,7 @@ data class Settings(
|
|||||||
@ColumnInfo(name = "is_tunnel_enabled") val isAutoTunnelEnabled: Boolean = false,
|
@ColumnInfo(name = "is_tunnel_enabled") val isAutoTunnelEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_tunnel_on_mobile_data_enabled")
|
@ColumnInfo(name = "is_tunnel_on_mobile_data_enabled")
|
||||||
val isTunnelOnMobileDataEnabled: Boolean = false,
|
val isTunnelOnMobileDataEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "trusted_network_ssids")
|
@ColumnInfo(name = "trusted_network_ssids") val trustedNetworkSSIDs: List<String> = emptyList(),
|
||||||
val trustedNetworkSSIDs: MutableList<String> = mutableListOf(),
|
|
||||||
@ColumnInfo(name = "is_always_on_vpn_enabled") val isAlwaysOnVpnEnabled: Boolean = false,
|
@ColumnInfo(name = "is_always_on_vpn_enabled") val isAlwaysOnVpnEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_tunnel_on_ethernet_enabled")
|
@ColumnInfo(name = "is_tunnel_on_ethernet_enabled")
|
||||||
val isTunnelOnEthernetEnabled: Boolean = false,
|
val isTunnelOnEthernetEnabled: Boolean = false,
|
||||||
@@ -32,8 +30,6 @@ data class Settings(
|
|||||||
val isAmneziaEnabled: Boolean = false,
|
val isAmneziaEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_wildcards_enabled", defaultValue = "false")
|
@ColumnInfo(name = "is_wildcards_enabled", defaultValue = "false")
|
||||||
val isWildcardsEnabled: Boolean = false,
|
val isWildcardsEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_wifi_by_shell_enabled", defaultValue = "false")
|
|
||||||
val isWifiNameByShellEnabled: Boolean = false,
|
|
||||||
@ColumnInfo(name = "is_stop_on_no_internet_enabled", defaultValue = "false")
|
@ColumnInfo(name = "is_stop_on_no_internet_enabled", defaultValue = "false")
|
||||||
val isStopOnNoInternetEnabled: Boolean = false,
|
val isStopOnNoInternetEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_vpn_kill_switch_enabled", defaultValue = "false")
|
@ColumnInfo(name = "is_vpn_kill_switch_enabled", defaultValue = "false")
|
||||||
@@ -46,61 +42,26 @@ data class Settings(
|
|||||||
val debounceDelaySeconds: Int = 3,
|
val debounceDelaySeconds: Int = 3,
|
||||||
@ColumnInfo(name = "is_disable_kill_switch_on_trusted_enabled", defaultValue = "false")
|
@ColumnInfo(name = "is_disable_kill_switch_on_trusted_enabled", defaultValue = "false")
|
||||||
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
||||||
|
@ColumnInfo(name = "is_tunnel_on_unsecure_enabled", defaultValue = "false")
|
||||||
|
val isTunnelOnUnsecureEnabled: Boolean = false,
|
||||||
|
@ColumnInfo(name = "wifi_detection_method", defaultValue = "0")
|
||||||
|
val wifiDetectionMethod: WifiDetectionMethod = WifiDetectionMethod.fromValue(0),
|
||||||
|
@ColumnInfo(name = "is_ping_monitoring_enabled", defaultValue = "true")
|
||||||
|
val isPingMonitoringEnabled: Boolean = true,
|
||||||
|
@ColumnInfo(name = "tunnel_ping_interval_sec", defaultValue = "30")
|
||||||
|
val tunnelPingIntervalSeconds: Int = 30,
|
||||||
|
@ColumnInfo(name = "tunnel_ping_attempts", defaultValue = "3") val tunnelPingAttempts: Int = 3,
|
||||||
|
@ColumnInfo(name = "tunnel_ping_timeout_sec") val tunnelPingTimeoutSeconds: Int? = null,
|
||||||
) {
|
) {
|
||||||
|
enum class WifiDetectionMethod(val value: Int) {
|
||||||
|
DEFAULT(0),
|
||||||
|
LEGACY(1),
|
||||||
|
ROOT(2),
|
||||||
|
SHIZUKU(3);
|
||||||
|
|
||||||
fun toAppSettings(): AppSettings {
|
companion object {
|
||||||
return AppSettings(
|
fun fromValue(value: Int): WifiDetectionMethod =
|
||||||
id,
|
entries.find { it.value == value } ?: DEFAULT
|
||||||
isAutoTunnelEnabled,
|
|
||||||
isTunnelOnMobileDataEnabled,
|
|
||||||
trustedNetworkSSIDs,
|
|
||||||
isAlwaysOnVpnEnabled,
|
|
||||||
isTunnelOnEthernetEnabled,
|
|
||||||
isShortcutsEnabled,
|
|
||||||
isTunnelOnWifiEnabled,
|
|
||||||
isKernelEnabled,
|
|
||||||
isRestoreOnBootEnabled,
|
|
||||||
isMultiTunnelEnabled,
|
|
||||||
isPingEnabled,
|
|
||||||
isAmneziaEnabled,
|
|
||||||
isWildcardsEnabled,
|
|
||||||
isWifiNameByShellEnabled,
|
|
||||||
isStopOnNoInternetEnabled,
|
|
||||||
isVpnKillSwitchEnabled,
|
|
||||||
isKernelKillSwitchEnabled,
|
|
||||||
isLanOnKillSwitchEnabled,
|
|
||||||
debounceDelaySeconds,
|
|
||||||
isDisableKillSwitchOnTrustedEnabled,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun from(appSettings: AppSettings): Settings {
|
|
||||||
return with(appSettings) {
|
|
||||||
Settings(
|
|
||||||
id,
|
|
||||||
isAutoTunnelEnabled,
|
|
||||||
isTunnelOnMobileDataEnabled,
|
|
||||||
trustedNetworkSSIDs.toMutableList(),
|
|
||||||
isAlwaysOnVpnEnabled,
|
|
||||||
isTunnelOnEthernetEnabled,
|
|
||||||
isShortcutsEnabled,
|
|
||||||
isTunnelOnWifiEnabled,
|
|
||||||
isKernelEnabled,
|
|
||||||
isRestoreOnBootEnabled,
|
|
||||||
isMultiTunnelEnabled,
|
|
||||||
isPingEnabled,
|
|
||||||
isAmneziaEnabled,
|
|
||||||
isWildcardsEnabled,
|
|
||||||
isWifiNameByShellEnabled,
|
|
||||||
isStopOnNoInternetEnabled,
|
|
||||||
isVpnKillSwitchEnabled,
|
|
||||||
isKernelKillSwitchEnabled,
|
|
||||||
isLanOnKillSwitchEnabled,
|
|
||||||
debounceDelaySeconds,
|
|
||||||
isDisableKillSwitchOnTrustedEnabled,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(indices = [Index(value = ["name"], unique = true)])
|
||||||
|
data class TunnelConfig(
|
||||||
|
@PrimaryKey(autoGenerate = true) val id: Int = 0,
|
||||||
|
@ColumnInfo(name = "name") val name: String,
|
||||||
|
@ColumnInfo(name = "wg_quick") val wgQuick: String,
|
||||||
|
@ColumnInfo(name = "tunnel_networks", defaultValue = "")
|
||||||
|
val tunnelNetworks: List<String> = listOf(),
|
||||||
|
@ColumnInfo(name = "is_mobile_data_tunnel", defaultValue = "false")
|
||||||
|
val isMobileDataTunnel: Boolean = false,
|
||||||
|
@ColumnInfo(name = "is_primary_tunnel", defaultValue = "false")
|
||||||
|
val isPrimaryTunnel: Boolean = false,
|
||||||
|
@ColumnInfo(name = "am_quick", defaultValue = "") val amQuick: String = AM_QUICK_DEFAULT,
|
||||||
|
@ColumnInfo(name = "is_Active", defaultValue = "false") val isActive: Boolean = false,
|
||||||
|
@ColumnInfo(name = "restart_on_ping_failure", defaultValue = "false")
|
||||||
|
val restartOnPingFailure: Boolean = false,
|
||||||
|
@ColumnInfo(name = "ping_target", defaultValue = "null") var pingTarget: String? = null,
|
||||||
|
@ColumnInfo(name = "is_ethernet_tunnel", defaultValue = "false")
|
||||||
|
val isEthernetTunnel: Boolean = false,
|
||||||
|
@ColumnInfo(name = "is_ipv4_preferred", defaultValue = "true")
|
||||||
|
val isIpv4Preferred: Boolean = true,
|
||||||
|
@ColumnInfo(name = "position", defaultValue = "0") val position: Int = 0,
|
||||||
|
@ColumnInfo(name = "auto_tunnel_apps", defaultValue = "[]")
|
||||||
|
val autoTunnelApps: List<String> = listOf(),
|
||||||
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val AM_QUICK_DEFAULT = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppState
|
||||||
|
|
||||||
|
object GeneralStateMapper {
|
||||||
|
fun toAppState(generalState: GeneralState): AppState =
|
||||||
|
with(generalState) {
|
||||||
|
AppState(
|
||||||
|
isLocationDisclosureShown,
|
||||||
|
isBatteryOptimizationDisableShown,
|
||||||
|
isPinLockEnabled,
|
||||||
|
expandedTunnelIds,
|
||||||
|
isLocalLogsEnabled,
|
||||||
|
isRemoteControlEnabled,
|
||||||
|
showDetailedPingStats,
|
||||||
|
remoteKey,
|
||||||
|
locale,
|
||||||
|
theme,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toGeneralState(appState: AppState): GeneralState {
|
||||||
|
return with(appState) {
|
||||||
|
GeneralState(
|
||||||
|
isLocationDisclosureShown,
|
||||||
|
isBatteryOptimizationDisableShown,
|
||||||
|
isPinLockEnabled,
|
||||||
|
expandedTunnelIds,
|
||||||
|
isLocalLogsEnabled,
|
||||||
|
isRemoteControlEnabled,
|
||||||
|
showDetailedPingStats,
|
||||||
|
remoteKey,
|
||||||
|
locale,
|
||||||
|
theme,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.entity.GitHubRelease
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppUpdate
|
||||||
|
|
||||||
|
object GitHubReleaseMapper {
|
||||||
|
fun toAppUpdate(gitHubRelease: GitHubRelease, newVersion: String): AppUpdate {
|
||||||
|
with(gitHubRelease) {
|
||||||
|
val apkAsset = assets.firstOrNull { it.name.endsWith(".apk") }
|
||||||
|
return AppUpdate(
|
||||||
|
version = newVersion,
|
||||||
|
title = name ?: "Update $tagName",
|
||||||
|
releaseNotes = body ?: "No release notes provided",
|
||||||
|
apkUrl = apkAsset?.browserDownloadUrl,
|
||||||
|
apkFileName = apkAsset?.name,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||||
|
|
||||||
|
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
|
|
||||||
|
object SettingsMapper {
|
||||||
|
fun toAppSettings(settings: Settings): AppSettings {
|
||||||
|
return AppSettings(
|
||||||
|
id = settings.id,
|
||||||
|
isAutoTunnelEnabled = settings.isAutoTunnelEnabled,
|
||||||
|
isTunnelOnMobileDataEnabled = settings.isTunnelOnMobileDataEnabled,
|
||||||
|
trustedNetworkSSIDs = settings.trustedNetworkSSIDs,
|
||||||
|
isAlwaysOnVpnEnabled = settings.isAlwaysOnVpnEnabled,
|
||||||
|
isTunnelOnEthernetEnabled = settings.isTunnelOnEthernetEnabled,
|
||||||
|
isShortcutsEnabled = settings.isShortcutsEnabled,
|
||||||
|
isTunnelOnWifiEnabled = settings.isTunnelOnWifiEnabled,
|
||||||
|
isKernelEnabled = settings.isKernelEnabled,
|
||||||
|
isRestoreOnBootEnabled = settings.isRestoreOnBootEnabled,
|
||||||
|
isMultiTunnelEnabled = settings.isMultiTunnelEnabled,
|
||||||
|
isPingEnabled = settings.isPingEnabled,
|
||||||
|
isAmneziaEnabled = settings.isAmneziaEnabled,
|
||||||
|
isWildcardsEnabled = settings.isWildcardsEnabled,
|
||||||
|
isStopOnNoInternetEnabled = settings.isStopOnNoInternetEnabled,
|
||||||
|
isVpnKillSwitchEnabled = settings.isVpnKillSwitchEnabled,
|
||||||
|
isKernelKillSwitchEnabled = settings.isKernelKillSwitchEnabled,
|
||||||
|
isLanOnKillSwitchEnabled = settings.isLanOnKillSwitchEnabled,
|
||||||
|
debounceDelaySeconds = settings.debounceDelaySeconds,
|
||||||
|
isDisableKillSwitchOnTrustedEnabled = settings.isDisableKillSwitchOnTrustedEnabled,
|
||||||
|
isTunnelOnUnsecureEnabled = settings.isTunnelOnUnsecureEnabled,
|
||||||
|
wifiDetectionMethod =
|
||||||
|
AndroidNetworkMonitor.WifiDetectionMethod.fromValue(
|
||||||
|
settings.wifiDetectionMethod.value
|
||||||
|
),
|
||||||
|
tunnelPingIntervalSeconds = settings.tunnelPingIntervalSeconds,
|
||||||
|
tunnelPingAttempts = settings.tunnelPingAttempts,
|
||||||
|
tunnelPingTimeoutSeconds = settings.tunnelPingTimeoutSeconds,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toSettings(appSettings: AppSettings): Settings {
|
||||||
|
return Settings(
|
||||||
|
id = appSettings.id,
|
||||||
|
isAutoTunnelEnabled = appSettings.isAutoTunnelEnabled,
|
||||||
|
isTunnelOnMobileDataEnabled = appSettings.isTunnelOnMobileDataEnabled,
|
||||||
|
trustedNetworkSSIDs = appSettings.trustedNetworkSSIDs,
|
||||||
|
isAlwaysOnVpnEnabled = appSettings.isAlwaysOnVpnEnabled,
|
||||||
|
isTunnelOnEthernetEnabled = appSettings.isTunnelOnEthernetEnabled,
|
||||||
|
isShortcutsEnabled = appSettings.isShortcutsEnabled,
|
||||||
|
isTunnelOnWifiEnabled = appSettings.isTunnelOnWifiEnabled,
|
||||||
|
isKernelEnabled = appSettings.isKernelEnabled,
|
||||||
|
isRestoreOnBootEnabled = appSettings.isRestoreOnBootEnabled,
|
||||||
|
isMultiTunnelEnabled = appSettings.isMultiTunnelEnabled,
|
||||||
|
isPingEnabled = appSettings.isPingEnabled,
|
||||||
|
isAmneziaEnabled = appSettings.isAmneziaEnabled,
|
||||||
|
isWildcardsEnabled = appSettings.isWildcardsEnabled,
|
||||||
|
isStopOnNoInternetEnabled = appSettings.isStopOnNoInternetEnabled,
|
||||||
|
isVpnKillSwitchEnabled = appSettings.isVpnKillSwitchEnabled,
|
||||||
|
isKernelKillSwitchEnabled = appSettings.isKernelKillSwitchEnabled,
|
||||||
|
isLanOnKillSwitchEnabled = appSettings.isLanOnKillSwitchEnabled,
|
||||||
|
debounceDelaySeconds = appSettings.debounceDelaySeconds,
|
||||||
|
isDisableKillSwitchOnTrustedEnabled = appSettings.isDisableKillSwitchOnTrustedEnabled,
|
||||||
|
isTunnelOnUnsecureEnabled = appSettings.isTunnelOnUnsecureEnabled,
|
||||||
|
wifiDetectionMethod =
|
||||||
|
Settings.WifiDetectionMethod.fromValue(appSettings.wifiDetectionMethod.value),
|
||||||
|
tunnelPingIntervalSeconds = appSettings.tunnelPingIntervalSeconds,
|
||||||
|
tunnelPingAttempts = appSettings.tunnelPingAttempts,
|
||||||
|
tunnelPingTimeoutSeconds = appSettings.tunnelPingTimeoutSeconds,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
|
|
||||||
|
object TunnelConfigMapper {
|
||||||
|
fun toTunnelConf(tunnelConfig: TunnelConfig): TunnelConf {
|
||||||
|
return with(tunnelConfig) {
|
||||||
|
TunnelConf(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
wgQuick,
|
||||||
|
tunnelNetworks,
|
||||||
|
isMobileDataTunnel,
|
||||||
|
isPrimaryTunnel,
|
||||||
|
amQuick,
|
||||||
|
isActive,
|
||||||
|
pingTarget,
|
||||||
|
restartOnPingFailure,
|
||||||
|
isEthernetTunnel,
|
||||||
|
isIpv4Preferred,
|
||||||
|
position,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toTunnelConfig(tunnelConf: TunnelConf): TunnelConfig {
|
||||||
|
return with(tunnelConf) {
|
||||||
|
TunnelConfig(
|
||||||
|
id,
|
||||||
|
tunName,
|
||||||
|
wgQuick,
|
||||||
|
tunnelNetworks,
|
||||||
|
isMobileDataTunnel,
|
||||||
|
isPrimaryTunnel,
|
||||||
|
amQuick,
|
||||||
|
isActive,
|
||||||
|
restartOnPingFailure,
|
||||||
|
pingTarget,
|
||||||
|
isEthernetTunnel,
|
||||||
|
isIpv4Preferred,
|
||||||
|
position,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.model
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
|
||||||
|
|
||||||
data class GeneralState(
|
|
||||||
val isLocationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
|
||||||
val isBatteryOptimizationDisableShown: Boolean = BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT,
|
|
||||||
val isPinLockEnabled: Boolean = PIN_LOCK_ENABLED_DEFAULT,
|
|
||||||
val expandedTunnelIds: List<Int> = emptyList(),
|
|
||||||
val isLocalLogsEnabled: Boolean = IS_LOGS_ENABLED_DEFAULT,
|
|
||||||
val isRemoteControlEnabled: Boolean = IS_REMOTE_CONTROL_ENABLED,
|
|
||||||
val remoteKey: String? = null,
|
|
||||||
val locale: String? = null,
|
|
||||||
val theme: Theme = Theme.AUTOMATIC,
|
|
||||||
) {
|
|
||||||
|
|
||||||
fun toAppState(): AppState =
|
|
||||||
AppState(
|
|
||||||
isLocationDisclosureShown,
|
|
||||||
isBatteryOptimizationDisableShown,
|
|
||||||
isPinLockEnabled,
|
|
||||||
expandedTunnelIds,
|
|
||||||
isLocalLogsEnabled,
|
|
||||||
isRemoteControlEnabled,
|
|
||||||
remoteKey,
|
|
||||||
locale,
|
|
||||||
theme,
|
|
||||||
)
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun from(appState: AppState): GeneralState {
|
|
||||||
return with(appState) {
|
|
||||||
GeneralState(
|
|
||||||
isLocationDisclosureShown,
|
|
||||||
isBatteryOptimizationDisableShown,
|
|
||||||
isPinLockEnabled,
|
|
||||||
expandedTunnelIds,
|
|
||||||
isLocalLogsEnabled,
|
|
||||||
isRemoteControlEnabled,
|
|
||||||
remoteKey,
|
|
||||||
locale,
|
|
||||||
theme,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const val LOCATION_DISCLOSURE_SHOWN_DEFAULT = false
|
|
||||||
const val BATTERY_OPTIMIZATION_DISABLE_SHOWN_DEFAULT = false
|
|
||||||
const val PIN_LOCK_ENABLED_DEFAULT = false
|
|
||||||
const val IS_LOGS_ENABLED_DEFAULT = false
|
|
||||||
const val IS_REMOTE_CONTROL_ENABLED = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.model
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
|
||||||
import kotlinx.serialization.SerialName
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class GitHubRelease(
|
|
||||||
@SerialName("tag_name") val tagName: String,
|
|
||||||
val name: String?,
|
|
||||||
val body: String?,
|
|
||||||
val assets: List<Asset>,
|
|
||||||
) {
|
|
||||||
fun toAppUpdate(): AppUpdate {
|
|
||||||
val apkAsset = assets.firstOrNull { it.name.endsWith(".apk") }
|
|
||||||
return AppUpdate(
|
|
||||||
version = tagName.removePrefix("v"),
|
|
||||||
title = name ?: "Update $tagName",
|
|
||||||
releaseNotes = body ?: "No release notes provided",
|
|
||||||
apkUrl = apkAsset?.browserDownloadUrl,
|
|
||||||
apkFileName = apkAsset?.name,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.model
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.Index
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|
||||||
|
|
||||||
@Entity(indices = [Index(value = ["name"], unique = true)])
|
|
||||||
data class TunnelConfig(
|
|
||||||
@PrimaryKey(autoGenerate = true) val id: Int = 0,
|
|
||||||
@ColumnInfo(name = "name") val name: String,
|
|
||||||
@ColumnInfo(name = "wg_quick") val wgQuick: String,
|
|
||||||
@ColumnInfo(name = "tunnel_networks", defaultValue = "")
|
|
||||||
val tunnelNetworks: MutableList<String> = mutableListOf(),
|
|
||||||
@ColumnInfo(name = "is_mobile_data_tunnel", defaultValue = "false")
|
|
||||||
val isMobileDataTunnel: Boolean = false,
|
|
||||||
@ColumnInfo(name = "is_primary_tunnel", defaultValue = "false")
|
|
||||||
val isPrimaryTunnel: Boolean = false,
|
|
||||||
@ColumnInfo(name = "am_quick", defaultValue = "") val amQuick: String = AM_QUICK_DEFAULT,
|
|
||||||
@ColumnInfo(name = "is_Active", defaultValue = "false") val isActive: Boolean = false,
|
|
||||||
@ColumnInfo(name = "is_ping_enabled", defaultValue = "false")
|
|
||||||
val isPingEnabled: Boolean = false,
|
|
||||||
@ColumnInfo(name = "ping_interval", defaultValue = "null") val pingInterval: Long? = null,
|
|
||||||
@ColumnInfo(name = "ping_cooldown", defaultValue = "null") val pingCooldown: Long? = null,
|
|
||||||
@ColumnInfo(name = "ping_ip", defaultValue = "null") var pingIp: String? = null,
|
|
||||||
@ColumnInfo(name = "is_ethernet_tunnel", defaultValue = "false")
|
|
||||||
var isEthernetTunnel: Boolean = false,
|
|
||||||
@ColumnInfo(name = "is_ipv4_preferred", defaultValue = "true")
|
|
||||||
var isIpv4Preferred: Boolean = true,
|
|
||||||
) {
|
|
||||||
|
|
||||||
fun toTunnel(): TunnelConf {
|
|
||||||
return TunnelConf(
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
wgQuick,
|
|
||||||
tunnelNetworks,
|
|
||||||
isMobileDataTunnel,
|
|
||||||
isPrimaryTunnel,
|
|
||||||
amQuick,
|
|
||||||
isActive,
|
|
||||||
isPingEnabled,
|
|
||||||
pingInterval,
|
|
||||||
pingCooldown,
|
|
||||||
pingIp,
|
|
||||||
isEthernetTunnel,
|
|
||||||
isIpv4Preferred,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
const val AM_QUICK_DEFAULT = ""
|
|
||||||
|
|
||||||
fun from(tunnelConf: TunnelConf): TunnelConfig {
|
|
||||||
return with(tunnelConf) {
|
|
||||||
return TunnelConfig(
|
|
||||||
id,
|
|
||||||
tunName,
|
|
||||||
wgQuick,
|
|
||||||
tunnelNetworks.toMutableList(),
|
|
||||||
isMobileDataTunnel,
|
|
||||||
isPrimaryTunnel,
|
|
||||||
amQuick,
|
|
||||||
isActive,
|
|
||||||
isPingEnabled,
|
|
||||||
pingInterval,
|
|
||||||
pingCooldown,
|
|
||||||
pingIp,
|
|
||||||
isEthernetTunnel,
|
|
||||||
isIpv4Preferred,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.network
|
package com.zaneschepke.wireguardautotunnel.data.network
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.GitHubRelease
|
import com.zaneschepke.wireguardautotunnel.data.entity.GitHubRelease
|
||||||
|
|
||||||
interface GitHubApi {
|
interface GitHubApi {
|
||||||
suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease>
|
suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.network
|
package com.zaneschepke.wireguardautotunnel.data.network
|
||||||
|
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.*
|
||||||
import io.ktor.client.engine.okhttp.OkHttp
|
import io.ktor.client.engine.okhttp.*
|
||||||
import io.ktor.client.plugins.HttpTimeout
|
import io.ktor.client.plugins.*
|
||||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
import io.ktor.client.plugins.contentnegotiation.*
|
||||||
import io.ktor.serialization.kotlinx.json.json
|
import io.ktor.serialization.kotlinx.json.*
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
object KtorClient {
|
object KtorClient {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.network
|
package com.zaneschepke.wireguardautotunnel.data.network
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.GitHubRelease
|
import com.zaneschepke.wireguardautotunnel.data.entity.GitHubRelease
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.*
|
||||||
import io.ktor.client.call.body
|
import io.ktor.client.call.*
|
||||||
import io.ktor.client.plugins.ClientRequestException
|
import io.ktor.client.plugins.*
|
||||||
import io.ktor.client.request.get
|
import io.ktor.client.request.*
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.*
|
||||||
|
|
||||||
class KtorGitHubApi(private val client: HttpClient) : GitHubApi {
|
class KtorGitHubApi(private val client: HttpClient) : GitHubApi {
|
||||||
override suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease> {
|
override suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease> {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
|
|||||||
+16
-3
@@ -1,8 +1,9 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.GeneralState
|
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppState
|
import com.zaneschepke.wireguardautotunnel.data.mapper.GeneralStateMapper
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@@ -118,6 +119,15 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
|||||||
return dataStoreManager.getFromStore(DataStoreManager.remoteKey)
|
return dataStoreManager.getFromStore(DataStoreManager.remoteKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun setShowDetailedPingStats(showDetailedPing: Boolean) {
|
||||||
|
dataStoreManager.saveToDataStore(DataStoreManager.showDetailedPingStats, showDetailedPing)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getShowDetailedPing(): Boolean {
|
||||||
|
return dataStoreManager.getFromStore(DataStoreManager.showDetailedPingStats)
|
||||||
|
?: GeneralState.SHOW_DETAILED_PING_STATS_DEFAULT
|
||||||
|
}
|
||||||
|
|
||||||
override val flow: Flow<AppState> =
|
override val flow: Flow<AppState> =
|
||||||
dataStoreManager.preferencesFlow
|
dataStoreManager.preferencesFlow
|
||||||
.map { prefs ->
|
.map { prefs ->
|
||||||
@@ -143,6 +153,9 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
|||||||
isRemoteControlEnabled =
|
isRemoteControlEnabled =
|
||||||
pref[DataStoreManager.isRemoteControlEnabled]
|
pref[DataStoreManager.isRemoteControlEnabled]
|
||||||
?: GeneralState.IS_REMOTE_CONTROL_ENABLED,
|
?: GeneralState.IS_REMOTE_CONTROL_ENABLED,
|
||||||
|
showDetailedPingStats =
|
||||||
|
pref[DataStoreManager.showDetailedPingStats]
|
||||||
|
?: GeneralState.SHOW_DETAILED_PING_STATS_DEFAULT,
|
||||||
remoteKey = pref[DataStoreManager.remoteKey],
|
remoteKey = pref[DataStoreManager.remoteKey],
|
||||||
locale = pref[DataStoreManager.locale],
|
locale = pref[DataStoreManager.locale],
|
||||||
theme = getTheme(),
|
theme = getTheme(),
|
||||||
@@ -153,5 +166,5 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
|||||||
}
|
}
|
||||||
} ?: GeneralState()
|
} ?: GeneralState()
|
||||||
}
|
}
|
||||||
.map { it.toAppState() }
|
.map(GeneralStateMapper::toAppState)
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-18
@@ -2,18 +2,18 @@ package com.zaneschepke.wireguardautotunnel.data.repository
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
import com.zaneschepke.wireguardautotunnel.BuildConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.mapper.GitHubReleaseMapper
|
||||||
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppUpdate
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.*
|
||||||
import io.ktor.client.request.get
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.HttpResponse
|
import io.ktor.client.statement.*
|
||||||
import io.ktor.client.statement.bodyAsChannel
|
import io.ktor.http.*
|
||||||
import io.ktor.http.contentLength
|
import io.ktor.utils.io.*
|
||||||
import io.ktor.utils.io.ByteReadChannel
|
|
||||||
import io.ktor.utils.io.readAvailable
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -30,24 +30,32 @@ class GitHubUpdateRepository(
|
|||||||
override suspend fun checkForUpdate(currentVersion: String): Result<AppUpdate?> =
|
override suspend fun checkForUpdate(currentVersion: String): Result<AppUpdate?> =
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
Timber.i("Checking for update")
|
Timber.i("Checking for update")
|
||||||
|
val isNightly = BuildConfig.VERSION_NAME.contains("nightly")
|
||||||
val release =
|
val release =
|
||||||
if (BuildConfig.VERSION_NAME.contains("nightly")) {
|
if (isNightly) {
|
||||||
gitHubApi.getNightlyRelease(githubOwner, githubRepo)
|
gitHubApi.getNightlyRelease(githubOwner, githubRepo).onFailure(Timber::e)
|
||||||
} else {
|
} else {
|
||||||
gitHubApi.getLatestRelease(githubOwner, githubRepo)
|
gitHubApi.getLatestRelease(githubOwner, githubRepo).onFailure(Timber::e)
|
||||||
}
|
}
|
||||||
release.map { release ->
|
release.map { release ->
|
||||||
val apkAsset =
|
val standaloneApkAsset =
|
||||||
release.assets.find { asset ->
|
release.assets.find { asset ->
|
||||||
asset.name.startsWith("wgtunnel-full-v") && asset.name.endsWith(".apk")
|
asset.name.startsWith("wgtunnel-${Constants.STANDALONE_FLAVOR}-v") &&
|
||||||
|
asset.name.endsWith(".apk")
|
||||||
}
|
}
|
||||||
val newVersion =
|
val newVersion =
|
||||||
apkAsset?.name?.removePrefix("wgtunnel-full-v")?.removeSuffix(".apk")
|
standaloneApkAsset
|
||||||
?: return@map null
|
?.name
|
||||||
|
?.removePrefix("wgtunnel-${Constants.STANDALONE_FLAVOR}-v")
|
||||||
|
?.removeSuffix(".apk") ?: return@map null
|
||||||
|
|
||||||
Timber.i("Latest version: $newVersion, current version: $currentVersion")
|
Timber.i("Latest version: $newVersion, current version: $currentVersion")
|
||||||
|
if (isNightly && newVersion != currentVersion)
|
||||||
|
return@map GitHubReleaseMapper.toAppUpdate(release, newVersion)
|
||||||
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
||||||
release.toAppUpdate()
|
GitHubReleaseMapper.toAppUpdate(release.copy(
|
||||||
|
assets = listOf(standaloneApkAsset)
|
||||||
|
), newVersion)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@@ -57,7 +65,7 @@ class GitHubUpdateRepository(
|
|||||||
override suspend fun downloadApk(
|
override suspend fun downloadApk(
|
||||||
apkUrl: String,
|
apkUrl: String,
|
||||||
fileName: String,
|
fileName: String,
|
||||||
onProgress: (Float) -> Unit,
|
onProgress: suspend (Float) -> Unit,
|
||||||
): Result<File> =
|
): Result<File> =
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
try {
|
try {
|
||||||
@@ -95,4 +103,4 @@ class GitHubUpdateRepository(
|
|||||||
Result.failure(e)
|
Result.failure(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-5
@@ -1,9 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.mapper.SettingsMapper
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
@@ -16,15 +17,15 @@ class RoomSettingsRepository(
|
|||||||
) : AppSettingRepository {
|
) : AppSettingRepository {
|
||||||
|
|
||||||
override suspend fun save(appSettings: AppSettings) {
|
override suspend fun save(appSettings: AppSettings) {
|
||||||
withContext(ioDispatcher) { settingsDoa.save(Settings.from(appSettings)) }
|
withContext(ioDispatcher) { settingsDoa.save(SettingsMapper.toSettings(appSettings)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override val flow =
|
override val flow =
|
||||||
settingsDoa.getSettingsFlow().flowOn(ioDispatcher).map { it.toAppSettings() }
|
settingsDoa.getSettingsFlow().flowOn(ioDispatcher).map(SettingsMapper::toAppSettings)
|
||||||
|
|
||||||
override suspend fun get(): AppSettings {
|
override suspend fun get(): AppSettings {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
(settingsDoa.getAll().firstOrNull() ?: Settings()).toAppSettings()
|
SettingsMapper.toAppSettings(settingsDoa.getAll().firstOrNull() ?: Settings())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-13
@@ -1,9 +1,9 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.mapper.TunnelConfigMapper
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -17,19 +17,25 @@ class RoomTunnelRepository(
|
|||||||
) : TunnelRepository {
|
) : TunnelRepository {
|
||||||
|
|
||||||
override val flow =
|
override val flow =
|
||||||
tunnelConfigDao.getAllFlow().flowOn(ioDispatcher).map { it.map { it.toTunnel() } }
|
tunnelConfigDao.getAllFlow().flowOn(ioDispatcher).map {
|
||||||
|
it.map(TunnelConfigMapper::toTunnelConf)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getAll(): Tunnels {
|
override suspend fun getAll(): Tunnels {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.getAll().map { it.toTunnel() } }
|
return withContext(ioDispatcher) {
|
||||||
|
tunnelConfigDao.getAll().map(TunnelConfigMapper::toTunnelConf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun save(tunnelConf: TunnelConf) {
|
override suspend fun save(tunnelConf: TunnelConf) {
|
||||||
withContext(ioDispatcher) { tunnelConfigDao.save(TunnelConfig.from(tunnelConf)) }
|
withContext(ioDispatcher) {
|
||||||
|
tunnelConfigDao.save(TunnelConfigMapper.toTunnelConfig(tunnelConf))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun saveAll(tunnelConfList: List<TunnelConf>) {
|
override suspend fun saveAll(tunnelConfList: List<TunnelConf>) {
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
tunnelConfigDao.saveAll(tunnelConfList.map(TunnelConfig::from))
|
tunnelConfigDao.saveAll(tunnelConfList.map(TunnelConfigMapper::toTunnelConfig))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,15 +61,21 @@ class RoomTunnelRepository(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun delete(tunnelConf: TunnelConf) {
|
override suspend fun delete(tunnelConf: TunnelConf) {
|
||||||
withContext(ioDispatcher) { tunnelConfigDao.delete(TunnelConfig.from(tunnelConf)) }
|
withContext(ioDispatcher) {
|
||||||
|
tunnelConfigDao.delete(TunnelConfigMapper.toTunnelConfig(tunnelConf))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getById(id: Int): TunnelConf? {
|
override suspend fun getById(id: Int): TunnelConf? {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.getById(id.toLong())?.toTunnel() }
|
return withContext(ioDispatcher) {
|
||||||
|
tunnelConfigDao.getById(id.toLong())?.let(TunnelConfigMapper::toTunnelConf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getActive(): Tunnels {
|
override suspend fun getActive(): Tunnels {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.getActive().map { it.toTunnel() } }
|
return withContext(ioDispatcher) {
|
||||||
|
tunnelConfigDao.getActive().map(TunnelConfigMapper::toTunnelConf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun count(): Int {
|
override suspend fun count(): Int {
|
||||||
@@ -71,22 +83,26 @@ class RoomTunnelRepository(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByTunnelName(name: String): TunnelConf? {
|
override suspend fun findByTunnelName(name: String): TunnelConf? {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.getByName(name)?.toTunnel() }
|
return withContext(ioDispatcher) {
|
||||||
|
tunnelConfigDao.getByName(name)?.let(TunnelConfigMapper::toTunnelConf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByTunnelNetworksName(name: String): Tunnels {
|
override suspend fun findByTunnelNetworksName(name: String): Tunnels {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
tunnelConfigDao.findByTunnelNetworkName(name).map { it.toTunnel() }
|
tunnelConfigDao.findByTunnelNetworkName(name).map(TunnelConfigMapper::toTunnelConf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByMobileDataTunnel(): Tunnels {
|
override suspend fun findByMobileDataTunnel(): Tunnels {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
tunnelConfigDao.findByMobileDataTunnel().map { it.toTunnel() }
|
tunnelConfigDao.findByMobileDataTunnel().map(TunnelConfigMapper::toTunnelConf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findPrimary(): Tunnels {
|
override suspend fun findPrimary(): Tunnels {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.findByPrimary().map { it.toTunnel() } }
|
return withContext(ioDispatcher) {
|
||||||
|
tunnelConfigDao.findByPrimary().map(TunnelConfigMapper::toTunnelConf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ import android.content.Context
|
|||||||
import com.zaneschepke.logcatter.LogReader
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.logcatter.LogcatReader
|
import com.zaneschepke.logcatter.LogcatReader
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
||||||
import com.zaneschepke.wireguardautotunnel.core.shortcut.DynamicShortcutManager
|
import com.zaneschepke.wireguardautotunnel.core.shortcut.DynamicShortcutManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.shortcut.ShortcutManager
|
import com.zaneschepke.wireguardautotunnel.core.shortcut.ShortcutManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
@@ -47,4 +50,19 @@ class AppModule {
|
|||||||
): ShortcutManager {
|
): ShortcutManager {
|
||||||
return DynamicShortcutManager(context, ioDispatcher)
|
return DynamicShortcutManager(context, ioDispatcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideNetworkUtils(@IoDispatcher ioDispatcher: CoroutineDispatcher): NetworkUtils {
|
||||||
|
return NetworkUtils(ioDispatcher)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideNotificationMonitor(
|
||||||
|
tunnelManager: TunnelManager,
|
||||||
|
notificationManager: NotificationManager,
|
||||||
|
): NotificationMonitor {
|
||||||
|
return NotificationMonitor(tunnelManager, notificationManager)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,22 +11,14 @@ import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||||
import com.zaneschepke.wireguardautotunnel.data.network.KtorClient
|
import com.zaneschepke.wireguardautotunnel.data.network.KtorClient
|
||||||
import com.zaneschepke.wireguardautotunnel.data.network.KtorGitHubApi
|
import com.zaneschepke.wireguardautotunnel.data.network.KtorGitHubApi
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRoomRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.*
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.DataStoreAppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.*
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.GitHubUpdateRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.RoomSettingsRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.RoomTunnelRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.*
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import android.content.Context
|
|||||||
import com.wireguard.android.backend.WgQuickBackend
|
import com.wireguard.android.backend.WgQuickBackend
|
||||||
import com.wireguard.android.util.RootShell
|
import com.wireguard.android.util.RootShell
|
||||||
import com.wireguard.android.util.ToolsInstaller
|
import com.wireguard.android.util.ToolsInstaller
|
||||||
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.KernelTunnel
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.*
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelProvider
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.UserspaceTunnel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
@@ -21,7 +21,9 @@ import dagger.hilt.components.SingletonComponent
|
|||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import org.amnezia.awg.backend.Backend
|
import org.amnezia.awg.backend.Backend
|
||||||
import org.amnezia.awg.backend.GoBackend
|
import org.amnezia.awg.backend.GoBackend
|
||||||
import org.amnezia.awg.backend.RootTunnelActionHandler
|
import org.amnezia.awg.backend.RootTunnelActionHandler
|
||||||
@@ -97,6 +99,7 @@ class TunnelModule {
|
|||||||
appDataRepository: AppDataRepository,
|
appDataRepository: AppDataRepository,
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
@ApplicationScope applicationScope: CoroutineScope,
|
||||||
|
notificationManager: NotificationManager,
|
||||||
): TunnelManager {
|
): TunnelManager {
|
||||||
return TunnelManager(
|
return TunnelManager(
|
||||||
kernelTunnel,
|
kernelTunnel,
|
||||||
@@ -112,10 +115,23 @@ class TunnelModule {
|
|||||||
fun provideNetworkMonitor(
|
fun provideNetworkMonitor(
|
||||||
@ApplicationContext context: Context,
|
@ApplicationContext context: Context,
|
||||||
settingsRepository: AppSettingRepository,
|
settingsRepository: AppSettingRepository,
|
||||||
|
@ApplicationScope applicationScope: CoroutineScope,
|
||||||
|
@AppShell appShell: RootShell,
|
||||||
): NetworkMonitor {
|
): NetworkMonitor {
|
||||||
return AndroidNetworkMonitor(context) {
|
return AndroidNetworkMonitor(
|
||||||
runBlocking { settingsRepository.get().isWifiNameByShellEnabled }
|
context,
|
||||||
}
|
object : AndroidNetworkMonitor.ConfigurationListener {
|
||||||
|
override val detectionMethod: Flow<AndroidNetworkMonitor.WifiDetectionMethod>
|
||||||
|
get() =
|
||||||
|
settingsRepository.flow
|
||||||
|
.distinctUntilChangedBy { it.wifiDetectionMethod }
|
||||||
|
.map { it.wifiDetectionMethod }
|
||||||
|
|
||||||
|
override val rootShell: RootShell
|
||||||
|
get() = appShell
|
||||||
|
},
|
||||||
|
applicationScope,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -135,4 +151,23 @@ class TunnelModule {
|
|||||||
appDataRepository,
|
appDataRepository,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideTunnelMonitor(
|
||||||
|
@ApplicationContext context: Context,
|
||||||
|
tunnelManager: TunnelManager,
|
||||||
|
networkMonitor: NetworkMonitor,
|
||||||
|
networkUtils: NetworkUtils,
|
||||||
|
logReader: LogReader,
|
||||||
|
appDataRepository: AppDataRepository,
|
||||||
|
): TunnelMonitor {
|
||||||
|
return TunnelMonitor(
|
||||||
|
appDataRepository,
|
||||||
|
tunnelManager,
|
||||||
|
networkMonitor,
|
||||||
|
networkUtils,
|
||||||
|
logReader,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||||
|
|
||||||
enum class BackendState {
|
sealed class BackendStatus {
|
||||||
KILL_SWITCH_ACTIVE,
|
data object Inactive : BackendStatus()
|
||||||
SERVICE_ACTIVE,
|
|
||||||
INACTIVE,
|
data object Active : BackendStatus()
|
||||||
|
|
||||||
|
data class KillSwitch(val allowedIps: List<String>) : BackendStatus()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||||
|
|
||||||
enum class ConfigType {
|
enum class ConfigType {
|
||||||
AMNEZIA,
|
AM,
|
||||||
WG,
|
WG,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ sealed class TunnelStatus {
|
|||||||
|
|
||||||
data object Starting : TunnelStatus()
|
data object Starting : TunnelStatus()
|
||||||
|
|
||||||
enum class StopReason {
|
sealed class StopReason {
|
||||||
USER,
|
data object User : StopReason()
|
||||||
PING,
|
|
||||||
CONFIG_CHANGED,
|
data class Ping(val previouslyResolvedEndpoints: Map<String, String?>) : StopReason()
|
||||||
|
|
||||||
|
data object ConfigChanged : StopReason()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isDown(): Boolean {
|
fun isDown(): Boolean {
|
||||||
|
|||||||
+8
-1
@@ -1,11 +1,18 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.events
|
package com.zaneschepke.wireguardautotunnel.domain.events
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
|
|
||||||
sealed class AutoTunnelEvent {
|
sealed class AutoTunnelEvent {
|
||||||
data class Start(val tunnelConf: TunnelConf? = null) : AutoTunnelEvent()
|
data class Start(val tunnelConf: TunnelConf? = null) : AutoTunnelEvent()
|
||||||
|
|
||||||
|
data class Bounce(val configsPeerKeyResolvedMap: List<Pair<TunnelConf, Map<String, String?>>>) :
|
||||||
|
AutoTunnelEvent()
|
||||||
|
|
||||||
data object Stop : AutoTunnelEvent()
|
data object Stop : AutoTunnelEvent()
|
||||||
|
|
||||||
data object DoNothing : AutoTunnelEvent()
|
data object DoNothing : AutoTunnelEvent()
|
||||||
|
|
||||||
|
data class StartKillSwitch(val allowedIps: List<String>) : AutoTunnelEvent()
|
||||||
|
|
||||||
|
data object StopKillSwitch : AutoTunnelEvent()
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-4
@@ -1,6 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
package com.zaneschepke.wireguardautotunnel.domain.events
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
|
|
||||||
sealed class BackendError : Exception() {
|
sealed class BackendError : Exception() {
|
||||||
data object DNS : BackendError()
|
data object DNS : BackendError()
|
||||||
@@ -11,23 +12,37 @@ sealed class BackendError : Exception() {
|
|||||||
|
|
||||||
data object KernelModuleName : BackendError()
|
data object KernelModuleName : BackendError()
|
||||||
|
|
||||||
data object InvalidConfig : BackendError()
|
|
||||||
|
|
||||||
data object NotAuthorized : BackendError()
|
data object NotAuthorized : BackendError()
|
||||||
|
|
||||||
data object ServiceNotRunning : BackendError()
|
data object ServiceNotRunning : BackendError()
|
||||||
|
|
||||||
data object Unknown : BackendError()
|
data object Unknown : BackendError()
|
||||||
|
|
||||||
|
data object TunnelNameTooLong : BackendError()
|
||||||
|
|
||||||
|
data class BounceFailed(val error: BackendError) : BackendError()
|
||||||
|
|
||||||
fun toStringRes() =
|
fun toStringRes() =
|
||||||
when (this) {
|
when (this) {
|
||||||
Config -> R.string.config_error
|
Config -> R.string.config_error
|
||||||
DNS -> R.string.dns_resolve_error
|
DNS -> R.string.dns_resolve_error
|
||||||
InvalidConfig -> R.string.invalid_config_error
|
|
||||||
KernelModuleName -> R.string.kernel_name_error
|
KernelModuleName -> R.string.kernel_name_error
|
||||||
NotAuthorized,
|
NotAuthorized,
|
||||||
Unauthorized -> R.string.auth_error
|
Unauthorized -> R.string.auth_error
|
||||||
ServiceNotRunning -> R.string.service_running_error
|
ServiceNotRunning -> R.string.service_running_error
|
||||||
Unknown -> R.string.unknown_error
|
Unknown -> R.string.unknown_error
|
||||||
|
TunnelNameTooLong -> R.string.error_tunnel_name
|
||||||
|
is BounceFailed -> R.string.bounce_failed_template
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun toStringValue(): StringValue {
|
||||||
|
return when (val backendError = this) {
|
||||||
|
is BounceFailed ->
|
||||||
|
StringValue.StringResource(
|
||||||
|
backendError.toStringRes(),
|
||||||
|
backendError.error.toStringRes(),
|
||||||
|
)
|
||||||
|
else -> StringValue.StringResource(backendError.toStringRes())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.domain.events
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
|
|
||||||
|
sealed class BackendMessage {
|
||||||
|
|
||||||
|
data object BounceSuccess : BackendMessage()
|
||||||
|
|
||||||
|
data object BounceRecovery : BackendMessage()
|
||||||
|
|
||||||
|
fun toStringRes() =
|
||||||
|
when (this) {
|
||||||
|
BounceRecovery -> R.string.pinger_bounce_recovery
|
||||||
|
BounceSuccess -> R.string.pinger_bounce_successful
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toStringValue() = StringValue.StringResource(this.toStringRes())
|
||||||
|
}
|
||||||
+19
-4
@@ -1,4 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.entity
|
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||||
|
|
||||||
|
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||||
|
|
||||||
data class AppSettings(
|
data class AppSettings(
|
||||||
val id: Int = 0,
|
val id: Int = 0,
|
||||||
@@ -15,15 +17,28 @@ data class AppSettings(
|
|||||||
val isPingEnabled: Boolean = false,
|
val isPingEnabled: Boolean = false,
|
||||||
val isAmneziaEnabled: Boolean = false,
|
val isAmneziaEnabled: Boolean = false,
|
||||||
val isWildcardsEnabled: Boolean = false,
|
val isWildcardsEnabled: Boolean = false,
|
||||||
val isWifiNameByShellEnabled: Boolean = false,
|
|
||||||
val isStopOnNoInternetEnabled: Boolean = false,
|
val isStopOnNoInternetEnabled: Boolean = false,
|
||||||
val isVpnKillSwitchEnabled: Boolean = false,
|
val isVpnKillSwitchEnabled: Boolean = false,
|
||||||
val isKernelKillSwitchEnabled: Boolean = false,
|
val isKernelKillSwitchEnabled: Boolean = false,
|
||||||
val isLanOnKillSwitchEnabled: Boolean = false,
|
val isLanOnKillSwitchEnabled: Boolean = false,
|
||||||
val debounceDelaySeconds: Int = 3,
|
val debounceDelaySeconds: Int = 3,
|
||||||
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
||||||
|
val isTunnelOnUnsecureEnabled: Boolean = false,
|
||||||
|
val wifiDetectionMethod: AndroidNetworkMonitor.WifiDetectionMethod =
|
||||||
|
AndroidNetworkMonitor.WifiDetectionMethod.DEFAULT,
|
||||||
|
val tunnelPingIntervalSeconds: Int = 30,
|
||||||
|
val tunnelPingAttempts: Int = 3,
|
||||||
|
val tunnelPingTimeoutSeconds: Int? = null,
|
||||||
) {
|
) {
|
||||||
fun debounceDelayMillis(): Long {
|
fun toAutoTunnelStateString(): String {
|
||||||
return debounceDelaySeconds * 1000L
|
return """
|
||||||
|
TunnelOnWifi: $isTunnelOnWifiEnabled
|
||||||
|
TunnelOnMobileData: $isTunnelOnMobileDataEnabled
|
||||||
|
TunnelOnEthernet: $isTunnelOnEthernetEnabled
|
||||||
|
Wildcards: $isWildcardsEnabled
|
||||||
|
StopOnNoInternet: $isStopOnNoInternetEnabled
|
||||||
|
Trusted Networks: $trustedNetworkSSIDs
|
||||||
|
"""
|
||||||
|
.trimIndent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.entity
|
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ data class AppState(
|
|||||||
val expandedTunnelIds: List<Int>,
|
val expandedTunnelIds: List<Int>,
|
||||||
val isLocalLogsEnabled: Boolean,
|
val isLocalLogsEnabled: Boolean,
|
||||||
val isRemoteControlEnabled: Boolean,
|
val isRemoteControlEnabled: Boolean,
|
||||||
|
val showDetailedPingStats: Boolean,
|
||||||
val remoteKey: String?,
|
val remoteKey: String?,
|
||||||
val locale: String?,
|
val locale: String?,
|
||||||
val theme: Theme,
|
val theme: Theme,
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.entity
|
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||||
|
|
||||||
data class AppUpdate(
|
data class AppUpdate(
|
||||||
val version: String,
|
val version: String,
|
||||||
+16
-39
@@ -1,15 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.entity
|
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||||
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.wireguard.config.Config
|
import com.wireguard.config.Config
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.net.InetAddress
|
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import kotlin.coroutines.CoroutineContext
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
data class TunnelConf(
|
data class TunnelConf(
|
||||||
val id: Int = 0,
|
val id: Int = 0,
|
||||||
@@ -20,16 +15,16 @@ data class TunnelConf(
|
|||||||
val isPrimaryTunnel: Boolean = false,
|
val isPrimaryTunnel: Boolean = false,
|
||||||
val amQuick: String,
|
val amQuick: String,
|
||||||
val isActive: Boolean = false,
|
val isActive: Boolean = false,
|
||||||
val isPingEnabled: Boolean = false,
|
val pingTarget: String? = null,
|
||||||
val pingInterval: Long? = null,
|
val restartOnPingFailure: Boolean = false,
|
||||||
val pingCooldown: Long? = null,
|
|
||||||
val pingIp: String? = null,
|
|
||||||
val isEthernetTunnel: Boolean = false,
|
val isEthernetTunnel: Boolean = false,
|
||||||
val isIpv4Preferred: Boolean = true,
|
val isIpv4Preferred: Boolean = true,
|
||||||
val useCache: Boolean = false,
|
val position: Int = 0,
|
||||||
@Transient private var stateChangeCallback: ((Any) -> Unit)? = null,
|
@Transient private var stateChangeCallback: ((Any) -> Unit)? = null,
|
||||||
) : Tunnel, org.amnezia.awg.backend.Tunnel {
|
) : Tunnel, org.amnezia.awg.backend.Tunnel {
|
||||||
|
|
||||||
|
val isNameKernelCompatible: Boolean = (name.length <= 15)
|
||||||
|
|
||||||
fun setStateChangeCallback(callback: (Any) -> Unit) {
|
fun setStateChangeCallback(callback: (Any) -> Unit) {
|
||||||
stateChangeCallback = callback
|
stateChangeCallback = callback
|
||||||
}
|
}
|
||||||
@@ -44,10 +39,8 @@ data class TunnelConf(
|
|||||||
isPrimaryTunnel == other.isPrimaryTunnel &&
|
isPrimaryTunnel == other.isPrimaryTunnel &&
|
||||||
isMobileDataTunnel == other.isMobileDataTunnel &&
|
isMobileDataTunnel == other.isMobileDataTunnel &&
|
||||||
isEthernetTunnel == other.isEthernetTunnel &&
|
isEthernetTunnel == other.isEthernetTunnel &&
|
||||||
isPingEnabled == other.isPingEnabled &&
|
pingTarget == other.pingTarget &&
|
||||||
pingIp == other.pingIp &&
|
restartOnPingFailure == other.restartOnPingFailure &&
|
||||||
pingCooldown == other.pingCooldown &&
|
|
||||||
pingInterval == other.pingInterval &&
|
|
||||||
tunnelNetworks == other.tunnelNetworks &&
|
tunnelNetworks == other.tunnelNetworks &&
|
||||||
isIpv4Preferred == other.isIpv4Preferred
|
isIpv4Preferred == other.isIpv4Preferred
|
||||||
}
|
}
|
||||||
@@ -60,6 +53,10 @@ data class TunnelConf(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isStaticallyConfigured(): Boolean {
|
||||||
|
return toAmConfig().peers.all { it.endpoint.get().host.isValidIpv4orIpv6Address() }
|
||||||
|
}
|
||||||
|
|
||||||
fun copyWithCallback(
|
fun copyWithCallback(
|
||||||
id: Int = this.id,
|
id: Int = this.id,
|
||||||
tunName: String = this.tunName,
|
tunName: String = this.tunName,
|
||||||
@@ -69,10 +66,8 @@ data class TunnelConf(
|
|||||||
isPrimaryTunnel: Boolean = this.isPrimaryTunnel,
|
isPrimaryTunnel: Boolean = this.isPrimaryTunnel,
|
||||||
amQuick: String = this.amQuick,
|
amQuick: String = this.amQuick,
|
||||||
isActive: Boolean = this.isActive,
|
isActive: Boolean = this.isActive,
|
||||||
isPingEnabled: Boolean = this.isPingEnabled,
|
restartOnPingFailure: Boolean = this.restartOnPingFailure,
|
||||||
pingInterval: Long? = this.pingInterval,
|
pingIp: String? = this.pingTarget,
|
||||||
pingCooldown: Long? = this.pingCooldown,
|
|
||||||
pingIp: String? = this.pingIp,
|
|
||||||
isEthernetTunnel: Boolean = this.isEthernetTunnel,
|
isEthernetTunnel: Boolean = this.isEthernetTunnel,
|
||||||
isIpv4Preferred: Boolean = this.isIpv4Preferred,
|
isIpv4Preferred: Boolean = this.isIpv4Preferred,
|
||||||
): TunnelConf {
|
): TunnelConf {
|
||||||
@@ -85,12 +80,11 @@ data class TunnelConf(
|
|||||||
isPrimaryTunnel,
|
isPrimaryTunnel,
|
||||||
amQuick,
|
amQuick,
|
||||||
isActive,
|
isActive,
|
||||||
isPingEnabled,
|
|
||||||
pingInterval,
|
|
||||||
pingCooldown,
|
|
||||||
pingIp,
|
pingIp,
|
||||||
|
restartOnPingFailure,
|
||||||
isEthernetTunnel,
|
isEthernetTunnel,
|
||||||
isIpv4Preferred,
|
isIpv4Preferred,
|
||||||
|
position,
|
||||||
)
|
)
|
||||||
.apply { stateChangeCallback = this@TunnelConf.stateChangeCallback }
|
.apply { stateChangeCallback = this@TunnelConf.stateChangeCallback }
|
||||||
}
|
}
|
||||||
@@ -107,8 +101,6 @@ data class TunnelConf(
|
|||||||
|
|
||||||
override fun isIpv4ResolutionPreferred(): Boolean = isIpv4Preferred
|
override fun isIpv4ResolutionPreferred(): Boolean = isIpv4Preferred
|
||||||
|
|
||||||
override fun useCache(): Boolean = useCache
|
|
||||||
|
|
||||||
override fun onStateChange(newState: org.amnezia.awg.backend.Tunnel.State) {
|
override fun onStateChange(newState: org.amnezia.awg.backend.Tunnel.State) {
|
||||||
stateChangeCallback?.invoke(newState)
|
stateChangeCallback?.invoke(newState)
|
||||||
}
|
}
|
||||||
@@ -133,21 +125,6 @@ data class TunnelConf(
|
|||||||
return tunnelName
|
return tunnelName
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun isTunnelPingable(context: CoroutineContext): Boolean {
|
|
||||||
return withContext(context) {
|
|
||||||
val config = toWgConfig()
|
|
||||||
if (pingIp != null) {
|
|
||||||
return@withContext InetAddress.getByName(pingIp)
|
|
||||||
.isReachable(Constants.PING_TIMEOUT.toInt())
|
|
||||||
.also { Timber.i("Ping reachable $pingIp: $it") }
|
|
||||||
}
|
|
||||||
config.peers
|
|
||||||
.map { peer -> peer.isReachable() }
|
|
||||||
.all { true }
|
|
||||||
.also { Timber.i("Ping of all peers reachable: $it") }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun configFromWgQuick(wgQuick: String): Config {
|
fun configFromWgQuick(wgQuick: String): Config {
|
||||||
val inputStream: InputStream = wgQuick.byteInputStream()
|
val inputStream: InputStream = wgQuick.byteInputStream()
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
|
|
||||||
interface AppDataRepository {
|
interface AppDataRepository {
|
||||||
suspend fun getPrimaryOrFirstTunnel(): TunnelConf?
|
suspend fun getPrimaryOrFirstTunnel(): TunnelConf?
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface AppSettingRepository {
|
interface AppSettingRepository {
|
||||||
|
|||||||
+5
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppState
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@@ -41,5 +41,9 @@ interface AppStateRepository {
|
|||||||
|
|
||||||
suspend fun getRemoteKey(): String?
|
suspend fun getRemoteKey(): String?
|
||||||
|
|
||||||
|
suspend fun setShowDetailedPingStats(showDetailedPing: Boolean)
|
||||||
|
|
||||||
|
suspend fun getShowDetailedPing(): Boolean
|
||||||
|
|
||||||
val flow: Flow<AppState>
|
val flow: Flow<AppState>
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppUpdate
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppUpdate
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
interface UpdateRepository {
|
interface UpdateRepository {
|
||||||
@@ -9,6 +9,6 @@ interface UpdateRepository {
|
|||||||
suspend fun downloadApk(
|
suspend fun downloadApk(
|
||||||
apkUrl: String,
|
apkUrl: String,
|
||||||
fileName: String,
|
fileName: String,
|
||||||
onProgress: (Float) -> Unit,
|
onProgress: suspend (Float) -> Unit,
|
||||||
): Result<File>
|
): Result<File>
|
||||||
}
|
}
|
||||||
|
|||||||
+87
-121
@@ -1,12 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.state
|
package com.zaneschepke.wireguardautotunnel.domain.state
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.allDown
|
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.StateChange
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.hasActive
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.isUp
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.AppSettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.entity.TunnelConf
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.KillSwitchEvent
|
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent.*
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isMatchingToWildcardList
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isMatchingToWildcardList
|
||||||
|
|
||||||
data class AutoTunnelState(
|
data class AutoTunnelState(
|
||||||
@@ -16,57 +14,98 @@ data class AutoTunnelState(
|
|||||||
val tunnels: List<TunnelConf> = emptyList(),
|
val tunnels: List<TunnelConf> = emptyList(),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
fun determineAutoTunnelEvent(stateChange: StateChange): AutoTunnelEvent {
|
||||||
|
when (val change = stateChange) {
|
||||||
|
is StateChange.NetworkChange,
|
||||||
|
is StateChange.SettingsChange -> {
|
||||||
|
// Compute desired tunnel based on network conditions
|
||||||
|
var desiredTunnel: TunnelConf? = null
|
||||||
|
if (networkState.isEthernetConnected && settings.isTunnelOnEthernetEnabled) {
|
||||||
|
desiredTunnel = preferredEthernetTunnel()
|
||||||
|
} else if (isMobileDataActive() && settings.isTunnelOnMobileDataEnabled) {
|
||||||
|
desiredTunnel = preferredMobileDataTunnel()
|
||||||
|
} else if (
|
||||||
|
isWifiActive() && settings.isTunnelOnWifiEnabled && !isCurrentSSIDTrusted()
|
||||||
|
) {
|
||||||
|
desiredTunnel = preferredWifiTunnel()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override for no connectivity if enabled
|
||||||
|
if (isNoConnectivity() && settings.isStopOnNoInternetEnabled) {
|
||||||
|
desiredTunnel = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine current active tunnel (assuming only one can be active)
|
||||||
|
val currentTunnel = activeTunnels.entries.firstOrNull()?.key
|
||||||
|
|
||||||
|
// Handle tunnel start/stop/change
|
||||||
|
if (desiredTunnel != null) {
|
||||||
|
if (currentTunnel != desiredTunnel) {
|
||||||
|
// Start or switch to the desired tunnel (overrides any kill switch)
|
||||||
|
return Start(desiredTunnel)
|
||||||
|
}
|
||||||
|
// If already active and matching, fall through to kill switch check (though
|
||||||
|
// unlikely needed)
|
||||||
|
} else {
|
||||||
|
if (currentTunnel != null) {
|
||||||
|
// Stop the active tunnel (then next emission can handle kill switch if
|
||||||
|
// needed)
|
||||||
|
return AutoTunnelEvent.Stop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Handle kill switch only if no user tunnel is or will be active
|
||||||
|
if (stopKillSwitchOnTrusted()) {
|
||||||
|
return AutoTunnelEvent.StopKillSwitch
|
||||||
|
}
|
||||||
|
if (startKillSwitch()) {
|
||||||
|
val allowedIps =
|
||||||
|
if (settings.isLanOnKillSwitchEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS
|
||||||
|
else emptyList()
|
||||||
|
return StartKillSwitch(allowedIps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is StateChange.MonitoringChange -> {
|
||||||
|
val bounceTunnels = bounceOnPingFailed()
|
||||||
|
if (bounceTunnels.isNotEmpty()) {
|
||||||
|
return Bounce(bounceTunnels)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is StateChange.ActiveTunnelsChange -> Unit
|
||||||
|
}
|
||||||
|
return DoNothing
|
||||||
|
}
|
||||||
|
|
||||||
|
// also need to check for Wi-Fi state as there is some overlap when they are both connected
|
||||||
private fun isMobileDataActive(): Boolean {
|
private fun isMobileDataActive(): Boolean {
|
||||||
return !networkState.isEthernetConnected &&
|
return !networkState.isEthernetConnected &&
|
||||||
!networkState.isWifiConnected &&
|
!networkState.isWifiConnected &&
|
||||||
networkState.isMobileDataConnected
|
networkState.isMobileDataConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isMobileTunnelDataChangeNeeded(): Boolean {
|
|
||||||
val preferredTunnel = preferredMobileDataTunnel()
|
|
||||||
return preferredTunnel != null &&
|
|
||||||
activeTunnels.isNotEmpty() &&
|
|
||||||
!activeTunnels.isUp(preferredTunnel)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isEthernetTunnelChangeNeeded(): Boolean {
|
|
||||||
val preferredTunnel = preferredEthernetTunnel()
|
|
||||||
return preferredTunnel != null &&
|
|
||||||
activeTunnels.isNotEmpty() &&
|
|
||||||
!activeTunnels.isUp(preferredTunnel)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun preferredMobileDataTunnel(): TunnelConf? {
|
private fun preferredMobileDataTunnel(): TunnelConf? {
|
||||||
return tunnels.firstOrNull { it.isMobileDataTunnel }
|
return tunnels.firstOrNull { it.isMobileDataTunnel }
|
||||||
?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
||||||
|
?: tunnels.firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun preferredEthernetTunnel(): TunnelConf? {
|
private fun preferredEthernetTunnel(): TunnelConf? {
|
||||||
return tunnels.firstOrNull { it.isEthernetTunnel }
|
return tunnels.firstOrNull { it.isEthernetTunnel }
|
||||||
?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
||||||
|
?: tunnels.firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun preferredWifiTunnel(): TunnelConf? {
|
private fun preferredWifiTunnel(): TunnelConf? {
|
||||||
return getTunnelWithMatchingTunnelNetwork() ?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
return getTunnelWithMatchingTunnelNetwork()
|
||||||
|
?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
||||||
|
?: tunnels.firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ignore cellular state as there is overlap where it may still be active, but not prioritized
|
||||||
private fun isWifiActive(): Boolean {
|
private fun isWifiActive(): Boolean {
|
||||||
return !networkState.isEthernetConnected && networkState.isWifiConnected
|
return !networkState.isEthernetConnected && networkState.isWifiConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startOnEthernet(): Boolean {
|
|
||||||
return networkState.isEthernetConnected &&
|
|
||||||
settings.isTunnelOnEthernetEnabled &&
|
|
||||||
activeTunnels.allDown()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun stopOnEthernet(): Boolean {
|
|
||||||
return networkState.isEthernetConnected &&
|
|
||||||
!settings.isTunnelOnEthernetEnabled &&
|
|
||||||
activeTunnels.hasActive()
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO test removed kill switch state check
|
|
||||||
private fun stopKillSwitchOnTrusted(): Boolean {
|
private fun stopKillSwitchOnTrusted(): Boolean {
|
||||||
return networkState.isWifiConnected &&
|
return networkState.isWifiConnected &&
|
||||||
settings.isVpnKillSwitchEnabled &&
|
settings.isVpnKillSwitchEnabled &&
|
||||||
@@ -74,7 +113,6 @@ data class AutoTunnelState(
|
|||||||
isCurrentSSIDTrusted()
|
isCurrentSSIDTrusted()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO test, removed kill switch state check
|
|
||||||
private fun startKillSwitch(): Boolean {
|
private fun startKillSwitch(): Boolean {
|
||||||
return settings.isVpnKillSwitchEnabled &&
|
return settings.isVpnKillSwitchEnabled &&
|
||||||
(!settings.isDisableKillSwitchOnTrustedEnabled || !isCurrentSSIDTrusted())
|
(!settings.isDisableKillSwitchOnTrustedEnabled || !isCurrentSSIDTrusted())
|
||||||
@@ -86,93 +124,21 @@ data class AutoTunnelState(
|
|||||||
!networkState.isMobileDataConnected
|
!networkState.isMobileDataConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopOnMobileData(): Boolean {
|
private fun bounceOnPingFailed(): List<Pair<TunnelConf, Map<String, String?>>> {
|
||||||
return isMobileDataActive() &&
|
return activeTunnels.entries
|
||||||
!settings.isTunnelOnMobileDataEnabled &&
|
.filter { (tunnel, state) ->
|
||||||
activeTunnels.hasActive()
|
tunnel.restartOnPingFailure &&
|
||||||
}
|
(state.pingStates?.any { (key, pingState) ->
|
||||||
|
pingState.failureReason == FailureReason.PingFailed
|
||||||
private fun startOnMobileData(): Boolean {
|
} ?: false)
|
||||||
return isMobileDataActive() &&
|
}
|
||||||
settings.isTunnelOnMobileDataEnabled &&
|
.map { (tunnel, state) ->
|
||||||
activeTunnels.allDown()
|
val peerMap =
|
||||||
}
|
(state.statistics?.getPeers()?.associate { peerKey ->
|
||||||
|
peerKey.toBase64() to state.statistics.peerStats(peerKey)?.resolvedEndpoint
|
||||||
private fun changeOnMobileData(): Boolean {
|
} ?: emptyMap())
|
||||||
return isMobileDataActive() &&
|
Pair(tunnel, peerMap)
|
||||||
settings.isTunnelOnMobileDataEnabled &&
|
|
||||||
isMobileTunnelDataChangeNeeded()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun changeOnEthernet(): Boolean {
|
|
||||||
return networkState.isEthernetConnected &&
|
|
||||||
settings.isTunnelOnEthernetEnabled &&
|
|
||||||
isEthernetTunnelChangeNeeded()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun stopOnWifi(): Boolean {
|
|
||||||
return isWifiActive() && !settings.isTunnelOnWifiEnabled && activeTunnels.hasActive()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun stopOnTrustedWifi(): Boolean {
|
|
||||||
return isWifiActive() &&
|
|
||||||
settings.isTunnelOnWifiEnabled &&
|
|
||||||
activeTunnels.hasActive() &&
|
|
||||||
isCurrentSSIDTrusted()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startOnUntrustedWifi(): Boolean {
|
|
||||||
return isWifiActive() &&
|
|
||||||
settings.isTunnelOnWifiEnabled &&
|
|
||||||
activeTunnels.allDown() &&
|
|
||||||
!isCurrentSSIDTrusted()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun changeOnUntrustedWifi(): Boolean {
|
|
||||||
return isWifiActive() &&
|
|
||||||
settings.isTunnelOnWifiEnabled &&
|
|
||||||
activeTunnels.hasActive() &&
|
|
||||||
!isCurrentSSIDTrusted() &&
|
|
||||||
!isWifiTunnelPreferred()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isWifiTunnelPreferred(): Boolean {
|
|
||||||
val preferred = preferredWifiTunnel()
|
|
||||||
return preferred?.let { activeTunnels.isUp(it) } ?: true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun asAutoTunnelEvent(): AutoTunnelEvent {
|
|
||||||
return when {
|
|
||||||
// ethernet scenarios
|
|
||||||
stopOnEthernet() -> AutoTunnelEvent.Stop
|
|
||||||
startOnEthernet() || changeOnEthernet() ->
|
|
||||||
AutoTunnelEvent.Start(preferredEthernetTunnel())
|
|
||||||
// mobile data scenarios
|
|
||||||
stopOnMobileData() -> AutoTunnelEvent.Stop
|
|
||||||
startOnMobileData() || changeOnMobileData() ->
|
|
||||||
AutoTunnelEvent.Start(preferredMobileDataTunnel())
|
|
||||||
// wifi scenarios
|
|
||||||
stopOnWifi() -> AutoTunnelEvent.Stop
|
|
||||||
stopOnTrustedWifi() -> AutoTunnelEvent.Stop
|
|
||||||
startOnUntrustedWifi() || changeOnUntrustedWifi() ->
|
|
||||||
AutoTunnelEvent.Start(preferredWifiTunnel())
|
|
||||||
// no connectivity
|
|
||||||
isNoConnectivity() && settings.isStopOnNoInternetEnabled -> AutoTunnelEvent.Stop
|
|
||||||
else -> AutoTunnelEvent.DoNothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun asKillSwitchEvent(): KillSwitchEvent {
|
|
||||||
return when {
|
|
||||||
stopKillSwitchOnTrusted() -> KillSwitchEvent.Stop
|
|
||||||
startKillSwitch() -> {
|
|
||||||
val allowedIps =
|
|
||||||
if (settings.isLanOnKillSwitchEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS
|
|
||||||
else emptyList()
|
|
||||||
KillSwitchEvent.Start(allowedIps)
|
|
||||||
}
|
}
|
||||||
else -> KillSwitchEvent.DoNothing
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isCurrentSSIDTrusted(): Boolean {
|
private fun isCurrentSSIDTrusted(): Boolean {
|
||||||
|
|||||||
@@ -1,12 +1,38 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.state
|
package com.zaneschepke.wireguardautotunnel.domain.state
|
||||||
|
|
||||||
|
import com.zaneschepke.networkmonitor.ConnectivityState
|
||||||
|
import com.zaneschepke.networkmonitor.util.WifiSecurityType
|
||||||
|
|
||||||
data class NetworkState(
|
data class NetworkState(
|
||||||
val isWifiConnected: Boolean = false,
|
val isWifiConnected: Boolean = false,
|
||||||
val isMobileDataConnected: Boolean = false,
|
val isMobileDataConnected: Boolean = false,
|
||||||
val isEthernetConnected: Boolean = false,
|
val isEthernetConnected: Boolean = false,
|
||||||
val wifiName: String? = null,
|
val wifiName: String? = null,
|
||||||
|
val isWifiSecure: Boolean? = null,
|
||||||
|
val locationServicesEnabled: Boolean? = null,
|
||||||
|
val locationPermissionGranted: Boolean? = null,
|
||||||
) {
|
) {
|
||||||
fun hasNoCapabilities(): Boolean {
|
fun hasNoCapabilities(): Boolean {
|
||||||
return !isWifiConnected && !isMobileDataConnected && !isEthernetConnected
|
return !isWifiConnected && !isMobileDataConnected && !isEthernetConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun from(connectivityState: ConnectivityState): NetworkState {
|
||||||
|
return NetworkState(
|
||||||
|
isWifiSecure =
|
||||||
|
when (connectivityState.wifiState.securityType) {
|
||||||
|
WifiSecurityType.OPEN,
|
||||||
|
WifiSecurityType.UNKNOWN -> false
|
||||||
|
null -> null
|
||||||
|
else -> true
|
||||||
|
},
|
||||||
|
isWifiConnected = connectivityState.wifiState.connected,
|
||||||
|
isMobileDataConnected = connectivityState.cellularConnected,
|
||||||
|
isEthernetConnected = connectivityState.ethernetConnected,
|
||||||
|
wifiName = connectivityState.wifiState.ssid,
|
||||||
|
locationPermissionGranted = connectivityState.wifiState.locationPermissionsGranted,
|
||||||
|
locationServicesEnabled = connectivityState.wifiState.locationServicesEnabled,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.domain.state
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelMonitor.Companion.CLOUDFLARE_IPV4_IP
|
||||||
|
|
||||||
|
enum class FailureReason {
|
||||||
|
NoConnectivity,
|
||||||
|
PingFailed,
|
||||||
|
NoResolvedEndpoint,
|
||||||
|
Timeout,
|
||||||
|
Unknown,
|
||||||
|
}
|
||||||
|
|
||||||
|
data class PingState(
|
||||||
|
val transmitted: Int = 0,
|
||||||
|
val received: Int = 0,
|
||||||
|
val packetLoss: Double = 0.0,
|
||||||
|
val rttMin: Double = 0.0,
|
||||||
|
val rttMax: Double = 0.0,
|
||||||
|
val rttAvg: Double = 0.0,
|
||||||
|
val rttStddev: Double = 0.0,
|
||||||
|
val isReachable: Boolean = false,
|
||||||
|
val lastSuccessfulPingMillis: Long? = null,
|
||||||
|
val lastPingAttemptMillis: Long? = null,
|
||||||
|
val failureReason: FailureReason? = null,
|
||||||
|
val pingTarget: String = CLOUDFLARE_IPV4_IP,
|
||||||
|
)
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.state
|
package com.zaneschepke.wireguardautotunnel.domain.state
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
|
import org.amnezia.awg.crypto.Key
|
||||||
|
|
||||||
data class TunnelState(
|
data class TunnelState(
|
||||||
val status: TunnelStatus = TunnelStatus.Down,
|
val status: TunnelStatus = TunnelStatus.Down,
|
||||||
val backendState: BackendState = BackendState.INACTIVE,
|
val backendState: BackendStatus = BackendStatus.Inactive,
|
||||||
val statistics: TunnelStatistics? = null,
|
val statistics: TunnelStatistics? = null,
|
||||||
|
val pingStates: Map<Key, PingState>? = null,
|
||||||
|
val handshakeSuccessLogs: Boolean? = null,
|
||||||
)
|
)
|
||||||
|
|||||||
+14
-3
@@ -3,13 +3,24 @@ package com.zaneschepke.wireguardautotunnel.domain.state
|
|||||||
import org.amnezia.awg.crypto.Key
|
import org.amnezia.awg.crypto.Key
|
||||||
|
|
||||||
abstract class TunnelStatistics {
|
abstract class TunnelStatistics {
|
||||||
@JvmRecord
|
open class PeerStats(
|
||||||
data class PeerStats(
|
|
||||||
val rxBytes: Long,
|
val rxBytes: Long,
|
||||||
val txBytes: Long,
|
val txBytes: Long,
|
||||||
val latestHandshakeEpochMillis: Long,
|
val latestHandshakeEpochMillis: Long,
|
||||||
val resolvedEndpoint: String,
|
val resolvedEndpoint: String,
|
||||||
)
|
) {
|
||||||
|
// mimic data class copy
|
||||||
|
open fun copy(
|
||||||
|
rxBytes: Long = this.rxBytes,
|
||||||
|
txBytes: Long = this.txBytes,
|
||||||
|
latestHandshakeEpochMillis: Long = this.latestHandshakeEpochMillis,
|
||||||
|
resolvedEndpoint: String = this.resolvedEndpoint,
|
||||||
|
): PeerStats = PeerStats(rxBytes, txBytes, latestHandshakeEpochMillis, resolvedEndpoint)
|
||||||
|
|
||||||
|
// Manual toString: Format like data class
|
||||||
|
override fun toString(): String =
|
||||||
|
"PeerStats(rxBytes=$rxBytes, txBytes=$txBytes, latestHandshakeEpochMillis=$latestHandshakeEpochMillis, resolvedEndpoint=$resolvedEndpoint)"
|
||||||
|
}
|
||||||
|
|
||||||
abstract fun peerStats(peer: Key): PeerStats?
|
abstract fun peerStats(peer: Key): PeerStats?
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ sealed class Route {
|
|||||||
|
|
||||||
@Serializable data object AutoTunnelAdvanced : Route()
|
@Serializable data object AutoTunnelAdvanced : Route()
|
||||||
|
|
||||||
|
@Serializable data object WifiDetectionMethod : Route()
|
||||||
|
|
||||||
@Serializable data object LocationDisclosure : Route()
|
@Serializable data object LocationDisclosure : Route()
|
||||||
|
|
||||||
@Serializable data object Appearance : Route()
|
@Serializable data object Appearance : Route()
|
||||||
@@ -29,8 +31,6 @@ sealed class Route {
|
|||||||
|
|
||||||
@Serializable data object Lock : Route()
|
@Serializable data object Lock : Route()
|
||||||
|
|
||||||
@Serializable data object Scanner : Route()
|
|
||||||
|
|
||||||
@Serializable data object License : Route()
|
@Serializable data object License : Route()
|
||||||
|
|
||||||
@Serializable data class Config(val id: Int) : Route()
|
@Serializable data class Config(val id: Int) : Route()
|
||||||
@@ -45,4 +45,8 @@ sealed class Route {
|
|||||||
@Serializable data class TunnelAutoTunnel(val id: Int) : Route()
|
@Serializable data class TunnelAutoTunnel(val id: Int) : Route()
|
||||||
|
|
||||||
@Serializable data object Logs : Route()
|
@Serializable data object Logs : Route()
|
||||||
|
|
||||||
|
@Serializable data object Sort : Route()
|
||||||
|
|
||||||
|
@Serializable data object TunnelMonitoring : Route()
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-33
@@ -3,68 +3,41 @@ package com.zaneschepke.wireguardautotunnel.ui.common
|
|||||||
import androidx.compose.animation.animateContentSize
|
import androidx.compose.animation.animateContentSize
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
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.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.ripple
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ExpandingRowListItem(
|
fun ExpandingRowListItem(
|
||||||
leading: @Composable () -> Unit,
|
leading: @Composable () -> Unit,
|
||||||
text: String,
|
text: String,
|
||||||
onHold: () -> Unit,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
onDoubleClick: () -> Unit,
|
|
||||||
trailing: @Composable () -> Unit,
|
trailing: @Composable () -> Unit,
|
||||||
isSelected: Boolean,
|
isSelected: Boolean,
|
||||||
expanded: (@Composable () -> Unit)?,
|
expanded: @Composable () -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val isTv = LocalIsAndroidTV.current
|
|
||||||
val haptic = LocalHapticFeedback.current
|
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.animateContentSize()
|
modifier
|
||||||
|
.animateContentSize()
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.clip(RoundedCornerShape(8.dp))
|
||||||
.background(
|
.background(
|
||||||
if (isSelected) MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
|
if (isSelected) MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
|
||||||
else Color.Transparent
|
else Color.Transparent
|
||||||
)
|
)
|
||||||
.then(
|
|
||||||
if (!isTv) {
|
|
||||||
Modifier.combinedClickable(
|
|
||||||
interactionSource = interactionSource,
|
|
||||||
indication = ripple(),
|
|
||||||
onClick = onClick,
|
|
||||||
onLongClick = {
|
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
|
||||||
onHold()
|
|
||||||
},
|
|
||||||
onDoubleClick = onDoubleClick,
|
|
||||||
)
|
|
||||||
} else Modifier
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
Column {
|
Column {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp).height(48.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
) {
|
) {
|
||||||
@@ -84,7 +57,7 @@ fun ExpandingRowListItem(
|
|||||||
}
|
}
|
||||||
trailing()
|
trailing()
|
||||||
}
|
}
|
||||||
expanded?.invoke()
|
expanded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -1,10 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.animation
|
package com.zaneschepke.wireguardautotunnel.ui.common.animation
|
||||||
|
|
||||||
import androidx.compose.animation.core.LinearEasing
|
import androidx.compose.animation.core.*
|
||||||
import androidx.compose.animation.core.animateFloat
|
|
||||||
import androidx.compose.animation.core.infiniteRepeatable
|
|
||||||
import androidx.compose.animation.core.rememberInfiniteTransition
|
|
||||||
import androidx.compose.animation.core.tween
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
|||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common.banner
|
||||||
|
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.expandVertically
|
||||||
|
import androidx.compose.animation.shrinkVertically
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.Warning
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
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.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.theme.Straw
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun WarningBanner(
|
||||||
|
title: String,
|
||||||
|
visible: Boolean,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
trailing: (@Composable () -> Unit)? = null,
|
||||||
|
) {
|
||||||
|
AnimatedVisibility(visible = visible, enter = expandVertically(), exit = shrinkVertically()) {
|
||||||
|
Surface(
|
||||||
|
color = MaterialTheme.colorScheme.secondary,
|
||||||
|
modifier = modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)),
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp).padding(start = 2.dp),
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.Start),
|
||||||
|
modifier = Modifier.weight(4f, false).fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Outlined.Warning,
|
||||||
|
stringResource(R.string.warning),
|
||||||
|
Modifier.size(18.dp),
|
||||||
|
tint = Straw,
|
||||||
|
)
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.Start,
|
||||||
|
verticalArrangement =
|
||||||
|
Arrangement.spacedBy(2.dp, Alignment.CenterVertically),
|
||||||
|
modifier = Modifier.fillMaxWidth().weight(1f).padding(start = 6.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
title,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trailing?.let {
|
||||||
|
Box(
|
||||||
|
contentAlignment = Alignment.CenterEnd,
|
||||||
|
modifier = Modifier.padding(start = 16.dp),
|
||||||
|
) {
|
||||||
|
it()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-5
@@ -3,11 +3,7 @@ package com.zaneschepke.wireguardautotunnel.ui.common.button
|
|||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.TextButton
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
|||||||
+5
-24
@@ -2,34 +2,23 @@ package com.zaneschepke.wireguardautotunnel.ui.common.button
|
|||||||
|
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.IntrinsicSize
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
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.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
|
||||||
|
|
||||||
@androidx.compose.runtime.Composable
|
@androidx.compose.runtime.Composable
|
||||||
fun IconSurfaceButton(
|
fun IconSurfaceButton(
|
||||||
title: String,
|
title: String,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
selected: Boolean,
|
selected: Boolean,
|
||||||
leadingIcon: ImageVector? = null,
|
leading: (@Composable () -> Unit)? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
) {
|
) {
|
||||||
val border: BorderStroke? =
|
val border: BorderStroke? =
|
||||||
@@ -64,16 +53,8 @@ fun IconSurfaceButton(
|
|||||||
modifier =
|
modifier =
|
||||||
Modifier.padding(vertical = if (description == null) 10.dp else 0.dp),
|
Modifier.padding(vertical = if (description == null) 10.dp else 0.dp),
|
||||||
) {
|
) {
|
||||||
leadingIcon?.let {
|
leading?.invoke()
|
||||||
Icon(
|
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||||
leadingIcon,
|
|
||||||
leadingIcon.name,
|
|
||||||
Modifier.size(iconSize),
|
|
||||||
if (selected) MaterialTheme.colorScheme.primary
|
|
||||||
else MaterialTheme.colorScheme.onSurface,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Column {
|
|
||||||
Text(title, style = MaterialTheme.typography.titleMedium)
|
Text(title, style = MaterialTheme.typography.titleMedium)
|
||||||
description?.let {
|
description?.let {
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
+2
-11
@@ -2,18 +2,9 @@ package com.zaneschepke.wireguardautotunnel.ui.common.button
|
|||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.material3.CardDefaults
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.ripple
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
|
|||||||
+5
-3
@@ -1,13 +1,15 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.button.surface
|
package com.zaneschepke.wireguardautotunnel.ui.common.button.surface
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
data class SelectionItem(
|
data class SelectionItem(
|
||||||
val leadingIcon: ImageVector? = null,
|
val leading: (@Composable () -> Unit)? = null,
|
||||||
val trailing: (@Composable () -> Unit)? = null,
|
val trailing: (@Composable () -> Unit)? = null,
|
||||||
val title: (@Composable () -> Unit),
|
val title: (@Composable () -> Unit),
|
||||||
val description: (@Composable () -> Unit)? = null,
|
val description: (@Composable () -> Unit)? = null,
|
||||||
val onClick: (() -> Unit)? = null,
|
val onClick: (() -> Unit)? = null,
|
||||||
val height: Int = 64,
|
val modifier: Modifier = Modifier.height(64.dp),
|
||||||
)
|
)
|
||||||
|
|||||||
+8
-15
@@ -5,19 +5,18 @@ import androidx.compose.foundation.layout.*
|
|||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SurfaceSelectionGroupButton(items: List<SelectionItem>) {
|
fun SurfaceSelectionGroupButton(items: List<SelectionItem>, modifier: Modifier = Modifier) {
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
shape = RoundedCornerShape(8.dp),
|
shape = RoundedCornerShape(8.dp),
|
||||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),
|
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||||
) {
|
) {
|
||||||
@@ -25,9 +24,10 @@ fun SurfaceSelectionGroupButton(items: List<SelectionItem>) {
|
|||||||
Box(
|
Box(
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.fillMaxWidth()
|
modifier
|
||||||
|
.fillMaxWidth()
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.clip(RoundedCornerShape(8.dp))
|
||||||
.then(item.onClick?.let { Modifier.clickable { it() } } ?: Modifier),
|
.then(item.onClick?.let { modifier.clickable { it() } } ?: modifier),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
@@ -37,21 +37,14 @@ fun SurfaceSelectionGroupButton(items: List<SelectionItem>) {
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.weight(4f, false).fillMaxWidth(),
|
modifier = Modifier.weight(4f, false).fillMaxWidth(),
|
||||||
) {
|
) {
|
||||||
item.leadingIcon?.let { icon ->
|
item.leading?.invoke()
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
icon.name,
|
|
||||||
modifier = Modifier.size(iconSize),
|
|
||||||
tint = MaterialTheme.colorScheme.onSurface,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.Start,
|
||||||
verticalArrangement =
|
verticalArrangement =
|
||||||
Arrangement.spacedBy(2.dp, Alignment.CenterVertically),
|
Arrangement.spacedBy(2.dp, Alignment.CenterVertically),
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.fillMaxWidth()
|
Modifier.fillMaxWidth()
|
||||||
.padding(start = if (item.leadingIcon != null) 16.dp else 0.dp)
|
.padding(start = if (item.leading != null) 16.dp else 0.dp)
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(
|
.padding(
|
||||||
vertical = if (item.description == null) 16.dp else 6.dp
|
vertical = if (item.description == null) 16.dp else 6.dp
|
||||||
|
|||||||
+3
-5
@@ -12,11 +12,7 @@ import androidx.compose.material3.Icon
|
|||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalFocusManager
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
@@ -32,6 +28,7 @@ fun SubmitConfigurationTextBox(
|
|||||||
hint: String,
|
hint: String,
|
||||||
isErrorValue: (value: String?) -> Boolean,
|
isErrorValue: (value: String?) -> Boolean,
|
||||||
onSubmit: (value: String) -> Unit,
|
onSubmit: (value: String) -> Unit,
|
||||||
|
supportingText: @Composable (() -> Unit)? = null,
|
||||||
keyboardOptions: KeyboardOptions =
|
keyboardOptions: KeyboardOptions =
|
||||||
KeyboardOptions(capitalization = KeyboardCapitalization.None, imeAction = ImeAction.Done),
|
KeyboardOptions(capitalization = KeyboardCapitalization.None, imeAction = ImeAction.Done),
|
||||||
) {
|
) {
|
||||||
@@ -49,6 +46,7 @@ fun SubmitConfigurationTextBox(
|
|||||||
value = stateValue,
|
value = stateValue,
|
||||||
onValueChange = { stateValue = it },
|
onValueChange = { stateValue = it },
|
||||||
interactionSource = interactionSource,
|
interactionSource = interactionSource,
|
||||||
|
supportingText = supportingText,
|
||||||
label = {
|
label = {
|
||||||
Text(
|
Text(
|
||||||
label,
|
label,
|
||||||
|
|||||||
+1
-5
@@ -1,10 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.dialog
|
package com.zaneschepke.wireguardautotunnel.ui.common.dialog
|
||||||
|
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Surface
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.TextButton
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|||||||
+19
-11
@@ -1,4 +1,4 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common
|
package com.zaneschepke.wireguardautotunnel.ui.common.dropdown
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
@@ -6,11 +6,7 @@ import androidx.compose.foundation.layout.height
|
|||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@@ -20,9 +16,9 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun <T> DropdownSelector(
|
fun <T> DropdownSelector(
|
||||||
currentValue: T,
|
currentValue: T?,
|
||||||
options: List<T>,
|
options: List<T?>,
|
||||||
onValueSelected: (T) -> Unit,
|
onValueSelected: (T?) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
label: @Composable (() -> Unit)? = null,
|
label: @Composable (() -> Unit)? = null,
|
||||||
isExpanded: Boolean = false,
|
isExpanded: Boolean = false,
|
||||||
@@ -33,7 +29,10 @@ fun <T> DropdownSelector(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
if (label != null) label()
|
if (label != null) label()
|
||||||
Text(text = currentValue.toString(), style = MaterialTheme.typography.bodyMedium)
|
Text(
|
||||||
|
text = currentValue?.toString() ?: stringResource(R.string._default),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
)
|
||||||
Icon(Icons.Default.ArrowDropDown, contentDescription = stringResource(R.string.dropdown))
|
Icon(Icons.Default.ArrowDropDown, contentDescription = stringResource(R.string.dropdown))
|
||||||
}
|
}
|
||||||
DropdownMenu(
|
DropdownMenu(
|
||||||
@@ -44,11 +43,20 @@ fun <T> DropdownSelector(
|
|||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
) {
|
) {
|
||||||
options.forEach { option ->
|
options.forEach { option ->
|
||||||
|
if (option == null) {
|
||||||
|
return@forEach DropdownMenuItem(
|
||||||
|
text = { Text(text = stringResource(R.string._default)) },
|
||||||
|
onClick = {
|
||||||
|
onValueSelected(null)
|
||||||
|
onDismiss()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(text = option.toString()) },
|
text = { Text(text = option.toString()) },
|
||||||
onClick = {
|
onClick = {
|
||||||
onValueSelected(option)
|
onValueSelected(option)
|
||||||
onDismiss() // Close dropdown after selection
|
onDismiss()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common.dropdown
|
||||||
|
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LabelledNumberDropdown(
|
||||||
|
title: @Composable () -> Unit,
|
||||||
|
description: (@Composable () -> Unit)? = null,
|
||||||
|
leading: @Composable () -> Unit,
|
||||||
|
onSelected: (Int?) -> Unit,
|
||||||
|
options: List<Int?>,
|
||||||
|
currentValue: Int?,
|
||||||
|
) {
|
||||||
|
var isDropDownExpanded by remember { mutableStateOf(false) }
|
||||||
|
SurfaceSelectionGroupButton(
|
||||||
|
listOf(
|
||||||
|
SelectionItem(
|
||||||
|
leading = leading,
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
onClick = { isDropDownExpanded = true },
|
||||||
|
trailing = {
|
||||||
|
DropdownSelector(
|
||||||
|
currentValue = currentValue,
|
||||||
|
options = options,
|
||||||
|
onValueSelected = { num -> onSelected(num) },
|
||||||
|
isExpanded = isDropDownExpanded,
|
||||||
|
onDismiss = { isDropDownExpanded = false },
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
+1
-7
@@ -1,12 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.snackbar
|
package com.zaneschepke.wireguardautotunnel.ui.common.snackbar
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.IntrinsicSize
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.Info
|
import androidx.compose.material.icons.rounded.Info
|
||||||
|
|||||||
+34
-47
@@ -10,7 +10,6 @@ import androidx.compose.material.icons.rounded.QuestionMark
|
|||||||
import androidx.compose.material.icons.rounded.Settings
|
import androidx.compose.material.icons.rounded.Settings
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@@ -21,7 +20,6 @@ import androidx.navigation.compose.currentBackStackEntryAsState
|
|||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.BottomNavItem
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.BottomNavItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
@@ -32,7 +30,6 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot
|
|||||||
@Composable
|
@Composable
|
||||||
fun BottomNavbar(appUiState: AppUiState) {
|
fun BottomNavbar(appUiState: AppUiState) {
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val isTv = LocalIsAndroidTV.current
|
|
||||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||||
|
|
||||||
val items =
|
val items =
|
||||||
@@ -49,8 +46,9 @@ fun BottomNavbar(appUiState: AppUiState) {
|
|||||||
icon = Icons.Rounded.Bolt,
|
icon = Icons.Rounded.Bolt,
|
||||||
onClick = {
|
onClick = {
|
||||||
val route =
|
val route =
|
||||||
if (appUiState.appState.isLocationDisclosureShown) Route.AutoTunnel
|
if (appUiState.appState.isLocationDisclosureShown) {
|
||||||
else Route.LocationDisclosure
|
Route.AutoTunnel
|
||||||
|
} else Route.LocationDisclosure
|
||||||
navController.goFromRoot(route)
|
navController.goFromRoot(route)
|
||||||
},
|
},
|
||||||
active = appUiState.isAutoTunnelActive,
|
active = appUiState.isAutoTunnelActive,
|
||||||
@@ -68,53 +66,42 @@ fun BottomNavbar(appUiState: AppUiState) {
|
|||||||
onClick = { navController.goFromRoot(Route.Support) },
|
onClick = { navController.goFromRoot(Route.Support) },
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
// Define ripple configuration based on platform
|
|
||||||
val rippleConfiguration =
|
|
||||||
if (isTv) {
|
|
||||||
RippleConfiguration()
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply ripple configuration only if needed
|
NavigationBar(containerColor = MaterialTheme.colorScheme.surface) {
|
||||||
CompositionLocalProvider(LocalRippleConfiguration provides rippleConfiguration) {
|
items.forEach { item ->
|
||||||
NavigationBar(containerColor = MaterialTheme.colorScheme.surface) {
|
val isSelected = navBackStackEntry.isCurrentRoute(item.route::class)
|
||||||
items.forEach { item ->
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
val isSelected = navBackStackEntry.isCurrentRoute(item.route::class)
|
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
|
||||||
|
|
||||||
NavigationBarItem(
|
NavigationBarItem(
|
||||||
icon = {
|
icon = {
|
||||||
if (item.active) {
|
if (item.active) {
|
||||||
BadgedBox(
|
BadgedBox(
|
||||||
badge = {
|
badge = {
|
||||||
Badge(
|
Badge(
|
||||||
modifier =
|
modifier = Modifier.offset(x = 8.dp, y = (-8).dp).size(6.dp),
|
||||||
Modifier.offset(x = 8.dp, y = (-8).dp).size(6.dp),
|
containerColor = SilverTree,
|
||||||
containerColor = SilverTree,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Icon(imageVector = item.icon, contentDescription = item.name)
|
|
||||||
}
|
}
|
||||||
} else {
|
) {
|
||||||
Icon(imageVector = item.icon, contentDescription = item.name)
|
Icon(imageVector = item.icon, contentDescription = item.name)
|
||||||
}
|
}
|
||||||
},
|
} else {
|
||||||
onClick = { navController.goFromRoot(item.route) },
|
Icon(imageVector = item.icon, contentDescription = item.name)
|
||||||
selected = isSelected,
|
}
|
||||||
enabled = true,
|
},
|
||||||
label = null,
|
onClick = item.onClick,
|
||||||
alwaysShowLabel = false,
|
selected = isSelected,
|
||||||
colors =
|
enabled = true,
|
||||||
NavigationBarItemDefaults.colors(
|
label = null,
|
||||||
selectedIconColor = MaterialTheme.colorScheme.primary,
|
alwaysShowLabel = false,
|
||||||
unselectedIconColor = MaterialTheme.colorScheme.onBackground,
|
colors =
|
||||||
indicatorColor = Color.Transparent,
|
NavigationBarItemDefaults.colors(
|
||||||
),
|
selectedIconColor = MaterialTheme.colorScheme.primary,
|
||||||
interactionSource = interactionSource,
|
unselectedIconColor = MaterialTheme.colorScheme.onBackground,
|
||||||
)
|
indicatorColor = Color.Transparent,
|
||||||
}
|
),
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+80
-69
@@ -4,22 +4,15 @@ import android.os.Build
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.Add
|
import androidx.compose.material.icons.automirrored.rounded.Sort
|
||||||
import androidx.compose.material.icons.rounded.CopyAll
|
import androidx.compose.material.icons.rounded.*
|
||||||
import androidx.compose.material.icons.rounded.Delete
|
|
||||||
import androidx.compose.material.icons.rounded.Download
|
|
||||||
import androidx.compose.material.icons.rounded.Edit
|
|
||||||
import androidx.compose.material.icons.rounded.Menu
|
|
||||||
import androidx.compose.material.icons.rounded.PlayArrow
|
|
||||||
import androidx.compose.material.icons.rounded.Save
|
|
||||||
import androidx.compose.material.icons.rounded.SelectAll
|
|
||||||
import androidx.compose.material.icons.rounded.Stop
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.produceState
|
import androidx.compose.runtime.produceState
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@@ -32,11 +25,10 @@ import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavBarState
|
import com.zaneschepke.wireguardautotunnel.ui.state.NavBarState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Brick
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.UiEvent
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun currentNavBackStackEntryAsNavBarState(
|
fun currentNavBackStackEntryAsNavBarState(
|
||||||
@@ -69,35 +61,40 @@ fun currentNavBackStackEntryAsNavBarState(
|
|||||||
|
|
||||||
Row {
|
Row {
|
||||||
if (selectedCount == 0) {
|
if (selectedCount == 0) {
|
||||||
|
val showSort = remember(uiState.tunnels) { uiState.tunnels.size > 1 }
|
||||||
|
if (showSort)
|
||||||
|
ActionIconButton(Icons.AutoMirrored.Rounded.Sort, R.string.sort) {
|
||||||
|
navController.navigate(Route.Sort)
|
||||||
|
}
|
||||||
ActionIconButton(Icons.Rounded.Add, R.string.add_tunnel) {
|
ActionIconButton(Icons.Rounded.Add, R.string.add_tunnel) {
|
||||||
viewModel.handleEvent(
|
viewModel.handleEvent(
|
||||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.IMPORT_TUNNELS)
|
AppEvent.SetBottomSheet(AppViewState.BottomSheet.IMPORT_TUNNELS)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
return@Row
|
||||||
ActionIconButton(Icons.Rounded.SelectAll, R.string.select_all) {
|
}
|
||||||
viewModel.handleEvent(AppEvent.ToggleSelectAllTunnels)
|
ActionIconButton(Icons.Rounded.SelectAll, R.string.select_all) {
|
||||||
}
|
viewModel.handleEvent(AppEvent.ToggleSelectAllTunnels)
|
||||||
// due to permissions, and SAF issues on TV, not support less than Android 10 on
|
}
|
||||||
// Android TV for file exports
|
// due to permissions, and SAF issues on TV, not support less than Android 10 on
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
// Android TV for file exports
|
||||||
ActionIconButton(Icons.Rounded.Download, R.string.download) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
viewModel.handleEvent(
|
ActionIconButton(Icons.Rounded.Download, R.string.download) {
|
||||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.EXPORT_TUNNELS)
|
viewModel.handleEvent(
|
||||||
)
|
AppEvent.SetBottomSheet(AppViewState.BottomSheet.EXPORT_TUNNELS)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedCount == 1) {
|
if (selectedCount == 1) {
|
||||||
ActionIconButton(Icons.Rounded.CopyAll, R.string.copy) {
|
ActionIconButton(Icons.Rounded.CopyAll, R.string.copy) {
|
||||||
viewModel.handleEvent(AppEvent.CopySelectedTunnel)
|
viewModel.handleEvent(AppEvent.CopySelectedTunnel)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (showDelete) {
|
if (showDelete) {
|
||||||
ActionIconButton(Icons.Rounded.Delete, R.string.delete_tunnel) {
|
ActionIconButton(Icons.Rounded.Delete, R.string.delete_tunnel) {
|
||||||
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.DELETE))
|
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.DELETE))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,8 +110,6 @@ fun currentNavBackStackEntryAsNavBarState(
|
|||||||
when {
|
when {
|
||||||
backStackEntry.isCurrentRoute(Route.Main::class) -> {
|
backStackEntry.isCurrentRoute(Route.Main::class) -> {
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
|
||||||
showBottom = true,
|
|
||||||
topTitle = { Text(stringResource(R.string.tunnels)) },
|
topTitle = { Text(stringResource(R.string.tunnels)) },
|
||||||
topTrailing = { TunnelActionBar() },
|
topTrailing = { TunnelActionBar() },
|
||||||
route = Route.Main,
|
route = Route.Main,
|
||||||
@@ -122,36 +117,15 @@ fun currentNavBackStackEntryAsNavBarState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.AutoTunnel::class) -> {
|
backStackEntry.isCurrentRoute(Route.AutoTunnel::class) -> {
|
||||||
val (icon, label, tint) =
|
|
||||||
if (uiState.appSettings.isAutoTunnelEnabled) {
|
|
||||||
Triple(Icons.Rounded.Stop, R.string.stop_auto, Brick)
|
|
||||||
} else {
|
|
||||||
Triple(Icons.Rounded.PlayArrow, R.string.start_auto, SilverTree)
|
|
||||||
}
|
|
||||||
|
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
|
||||||
showBottom = true,
|
|
||||||
topTitle = { Text(stringResource(R.string.auto_tunnel)) },
|
topTitle = { Text(stringResource(R.string.auto_tunnel)) },
|
||||||
topTrailing = {
|
|
||||||
IconButton(
|
|
||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnel) }
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
stringResource(label),
|
|
||||||
tint = tint,
|
|
||||||
modifier = Modifier.size(iconSize),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
route = Route.AutoTunnel,
|
route = Route.AutoTunnel,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.Logs::class) -> {
|
backStackEntry.isCurrentRoute(Route.Logs::class) -> {
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
|
||||||
showBottom = false,
|
showBottom = false,
|
||||||
topTitle = { Text(stringResource(R.string.logs)) },
|
topTitle = { Text(stringResource(R.string.logs)) },
|
||||||
topTrailing = {
|
topTrailing = {
|
||||||
@@ -167,52 +141,80 @@ fun currentNavBackStackEntryAsNavBarState(
|
|||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.Settings::class) ->
|
backStackEntry.isCurrentRoute(Route.Settings::class) ->
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
|
||||||
showBottom = true,
|
|
||||||
topTitle = { Text(stringResource(R.string.settings)) },
|
topTitle = { Text(stringResource(R.string.settings)) },
|
||||||
route = Route.Settings,
|
route = Route.Settings,
|
||||||
|
topTrailing = {
|
||||||
|
ActionIconButton(Icons.Rounded.Menu, R.string.quick_actions) {
|
||||||
|
viewModel.handleEvent(
|
||||||
|
AppEvent.SetBottomSheet(
|
||||||
|
AppViewState.BottomSheet.BACKUP_AND_RESTORE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.Appearance::class) ->
|
backStackEntry.isCurrentRoute(Route.Appearance::class) ->
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
|
||||||
showBottom = true,
|
|
||||||
topTitle = { Text(stringResource(R.string.appearance)) },
|
topTitle = { Text(stringResource(R.string.appearance)) },
|
||||||
route = Route.Appearance,
|
route = Route.Appearance,
|
||||||
)
|
)
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.Language::class) ->
|
backStackEntry.isCurrentRoute(Route.Language::class) ->
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
|
||||||
showBottom = true,
|
|
||||||
topTitle = { Text(stringResource(R.string.language)) },
|
topTitle = { Text(stringResource(R.string.language)) },
|
||||||
route = Route.Language,
|
route = Route.Language,
|
||||||
)
|
)
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.Display::class) ->
|
backStackEntry.isCurrentRoute(Route.Display::class) ->
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
|
||||||
showBottom = true,
|
|
||||||
topTitle = { Text(stringResource(R.string.display_theme)) },
|
topTitle = { Text(stringResource(R.string.display_theme)) },
|
||||||
route = Route.Display,
|
route = Route.Display,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
backStackEntry.isCurrentRoute(Route.TunnelMonitoring::class) ->
|
||||||
|
NavBarState(
|
||||||
|
topTitle = { Text(stringResource(R.string.tunnel_monitoring)) },
|
||||||
|
route = Route.TunnelMonitoring,
|
||||||
|
)
|
||||||
|
|
||||||
|
backStackEntry.isCurrentRoute(Route.WifiDetectionMethod::class) ->
|
||||||
|
NavBarState(
|
||||||
|
topTitle = { Text(stringResource(R.string.wifi_detection_method)) },
|
||||||
|
route = Route.WifiDetectionMethod,
|
||||||
|
)
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.KillSwitch::class) ->
|
backStackEntry.isCurrentRoute(Route.KillSwitch::class) ->
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
|
||||||
showBottom = true,
|
|
||||||
topTitle = { Text(stringResource(R.string.kill_switch)) },
|
topTitle = { Text(stringResource(R.string.kill_switch)) },
|
||||||
route = Route.KillSwitch,
|
route = Route.KillSwitch,
|
||||||
)
|
)
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.Support::class) ->
|
backStackEntry.isCurrentRoute(Route.Support::class) ->
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
|
||||||
showBottom = true,
|
|
||||||
topTitle = { Text(stringResource(R.string.support)) },
|
topTitle = { Text(stringResource(R.string.support)) },
|
||||||
route = Route.Support,
|
route = Route.Support,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
backStackEntry.isCurrentRoute(Route.Sort::class) -> {
|
||||||
|
NavBarState(
|
||||||
|
showTop = true,
|
||||||
|
showBottom = true,
|
||||||
|
topTitle = { Text(stringResource(R.string.sort)) },
|
||||||
|
topTrailing = {
|
||||||
|
Row {
|
||||||
|
ActionIconButton(Icons.Rounded.SortByAlpha, R.string.sort) {
|
||||||
|
viewModel.handleUiEvent(UiEvent.SortTunnels)
|
||||||
|
}
|
||||||
|
ActionIconButton(Icons.Rounded.Save, R.string.save) {
|
||||||
|
viewModel.handleEvent(AppEvent.InvokeScreenAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
route = Route.Sort,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
backStackEntry.isCurrentRoute(Route.License::class) -> {
|
backStackEntry.isCurrentRoute(Route.License::class) -> {
|
||||||
NavBarState(
|
NavBarState(
|
||||||
showTop = true,
|
showTop = true,
|
||||||
@@ -240,8 +242,17 @@ fun currentNavBackStackEntryAsNavBarState(
|
|||||||
showBottom = true,
|
showBottom = true,
|
||||||
topTitle = { tunnel?.name?.let { Text(it) } },
|
topTitle = { tunnel?.name?.let { Text(it) } },
|
||||||
topTrailing = {
|
topTrailing = {
|
||||||
ActionIconButton(Icons.Rounded.Edit, R.string.edit_tunnel) {
|
Row {
|
||||||
tunnel?.id?.let { navController.navigate(Route.Config(it)) }
|
ActionIconButton(Icons.Rounded.QrCode2, R.string.show_qr) {
|
||||||
|
tunnel?.id?.let {
|
||||||
|
viewModel.handleEvent(
|
||||||
|
AppEvent.SetShowModal(AppViewState.ModalType.QR)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ActionIconButton(Icons.Rounded.Edit, R.string.edit_tunnel) {
|
||||||
|
tunnel?.id?.let { navController.navigate(Route.Config(it)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
route = args?.let { Route.TunnelOptions(it.id) },
|
route = args?.let { Route.TunnelOptions(it.id) },
|
||||||
|
|||||||
+105
-59
@@ -1,93 +1,89 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel
|
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
import android.os.Build
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.material.icons.outlined.CheckCircle
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.material.icons.outlined.Info
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||||
import com.google.accompanist.permissions.isGranted
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.google.accompanist.permissions.rememberPermissionState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.banner.WarningBanner
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.AdvancedSettingsItem
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.AdvancedSettingsItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.NetworkTunnelingItems
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.NetworkTunnelingItems
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.WifiTunnelingItems
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.WifiTunnelingItems
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.BackgroundLocationDialog
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LocationServicesDialog
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isLocationServicesEnabled
|
import com.zaneschepke.wireguardautotunnel.util.extensions.launchAppSettings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.launchLocationServicesSettings
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
|
|
||||||
@OptIn(ExperimentalPermissionsApi::class)
|
@OptIn(ExperimentalPermissionsApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||||
val context = LocalContext.current
|
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val isTv = LocalIsAndroidTV.current
|
val context = LocalContext.current
|
||||||
val fineLocationState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
|
|
||||||
var currentText by remember { mutableStateOf("") }
|
var currentText by remember { mutableStateOf("") }
|
||||||
var isBackgroundLocationGranted by remember { mutableStateOf(true) }
|
|
||||||
var showLocationServicesAlertDialog by remember { mutableStateOf(false) }
|
|
||||||
var showLocationDialog by remember { mutableStateOf(false) }
|
var showLocationDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
fun checkFineLocationGranted() {
|
val showLocationServicesWarning by
|
||||||
isBackgroundLocationGranted = fineLocationState.status.isGranted
|
remember(
|
||||||
}
|
uiState.connectivityState?.wifiState,
|
||||||
|
uiState.appSettings.trustedNetworkSSIDs,
|
||||||
fun isWifiNameReadable(): Boolean {
|
uiState.appSettings.wifiDetectionMethod,
|
||||||
return when {
|
) {
|
||||||
!isBackgroundLocationGranted || !fineLocationState.status.isGranted -> {
|
derivedStateOf {
|
||||||
showLocationDialog = true
|
uiState.connectivityState?.wifiState?.locationServicesEnabled == false &&
|
||||||
false
|
uiState.appSettings.wifiDetectionMethod.needsLocationPermissions() &&
|
||||||
|
uiState.appSettings.trustedNetworkSSIDs.isNotEmpty()
|
||||||
}
|
}
|
||||||
!context.isLocationServicesEnabled() -> {
|
|
||||||
showLocationServicesAlertDialog = true
|
|
||||||
false
|
|
||||||
}
|
|
||||||
else -> true
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) checkFineLocationGranted()
|
val showLocationPermissionsWarning by
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
remember(
|
||||||
if (isTv && Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
|
uiState.connectivityState?.wifiState,
|
||||||
checkFineLocationGranted()
|
uiState.appSettings.trustedNetworkSSIDs,
|
||||||
} else {
|
uiState.appSettings.wifiDetectionMethod,
|
||||||
val backgroundLocationState =
|
) {
|
||||||
rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
derivedStateOf {
|
||||||
|
uiState.connectivityState?.wifiState?.locationPermissionsGranted == false &&
|
||||||
|
uiState.appSettings.wifiDetectionMethod.needsLocationPermissions() &&
|
||||||
|
uiState.appSettings.trustedNetworkSSIDs.isNotEmpty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
LaunchedEffect(uiState.appSettings.trustedNetworkSSIDs) { currentText = "" }
|
LaunchedEffect(uiState.appSettings.trustedNetworkSSIDs) { currentText = "" }
|
||||||
|
|
||||||
LocationServicesDialog(
|
if (showLocationDialog) {
|
||||||
showLocationServicesAlertDialog,
|
InfoDialog(
|
||||||
onDismiss = { showLocationServicesAlertDialog = false },
|
onAttest = {
|
||||||
onAttest = { showLocationServicesAlertDialog = false },
|
context.launchAppSettings()
|
||||||
)
|
showLocationDialog = false
|
||||||
|
},
|
||||||
BackgroundLocationDialog(
|
onDismiss = { showLocationDialog = false },
|
||||||
showLocationDialog,
|
title = { Text(stringResource(R.string.location_permissions)) },
|
||||||
onDismiss = { showLocationDialog = false },
|
body = { Text(stringResource(R.string.location_justification)) },
|
||||||
onAttest = { showLocationDialog = false },
|
confirmText = { Text(stringResource(R.string.open_settings)) },
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.Start,
|
||||||
@@ -98,16 +94,66 @@ fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
|||||||
.padding(vertical = 24.dp)
|
.padding(vertical = 24.dp)
|
||||||
.padding(horizontal = 12.dp),
|
.padding(horizontal = 12.dp),
|
||||||
) {
|
) {
|
||||||
|
WarningBanner(
|
||||||
|
stringResource(R.string.location_services_not_detected),
|
||||||
|
showLocationServicesWarning,
|
||||||
|
trailing = {
|
||||||
|
TextButton({ context.launchLocationServicesSettings() }) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.fix),
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
WarningBanner(
|
||||||
|
stringResource(R.string.location_permissions_missing),
|
||||||
|
showLocationPermissionsWarning,
|
||||||
|
trailing = {
|
||||||
|
TextButton({ showLocationDialog = true }) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.fix),
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
val (title, buttonText, icon) =
|
||||||
|
remember(uiState.isAutoTunnelActive) {
|
||||||
|
when (uiState.isAutoTunnelActive) {
|
||||||
|
true ->
|
||||||
|
Triple(
|
||||||
|
context.getString(R.string.auto_tunnel_running),
|
||||||
|
context.getString(R.string.stop),
|
||||||
|
Icons.Outlined.CheckCircle,
|
||||||
|
)
|
||||||
|
false ->
|
||||||
|
Triple(
|
||||||
|
context.getString(R.string.auto_tunnel_not_running),
|
||||||
|
context.getString(R.string.start),
|
||||||
|
Icons.Outlined.Info,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
SurfaceSelectionGroupButton(
|
SurfaceSelectionGroupButton(
|
||||||
items =
|
items =
|
||||||
WifiTunnelingItems(
|
listOf(
|
||||||
uiState,
|
SelectionItem(
|
||||||
viewModel,
|
leading = { Icon(icon, null) },
|
||||||
currentText,
|
title = { Text(title) },
|
||||||
{ currentText = it },
|
trailing = {
|
||||||
{ isWifiNameReadable() },
|
Button({ viewModel.handleEvent(AppEvent.ToggleAutoTunnel) }) {
|
||||||
|
Text(buttonText, fontWeight = FontWeight.Bold)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
SurfaceSelectionGroupButton(
|
||||||
|
items = WifiTunnelingItems(uiState, viewModel, currentText) { currentText = it }
|
||||||
|
)
|
||||||
SectionDivider()
|
SectionDivider()
|
||||||
SurfaceSelectionGroupButton(items = NetworkTunnelingItems(uiState, viewModel))
|
SurfaceSelectionGroupButton(items = NetworkTunnelingItems(uiState, viewModel))
|
||||||
SectionDivider()
|
SectionDivider()
|
||||||
|
|||||||
+25
-4
@@ -6,13 +6,21 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.PauseCircle
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.components.DebounceDelaySelector
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.dropdown.LabelledNumberDropdown
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AutoTunnelAdvancedScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
fun AutoTunnelAdvancedScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
||||||
@@ -25,9 +33,22 @@ fun AutoTunnelAdvancedScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
|||||||
.padding(vertical = 24.dp)
|
.padding(vertical = 24.dp)
|
||||||
.padding(horizontal = 12.dp),
|
.padding(horizontal = 12.dp),
|
||||||
) {
|
) {
|
||||||
DebounceDelaySelector(
|
LabelledNumberDropdown(
|
||||||
currentDelay = appUiState.appSettings.debounceDelaySeconds,
|
title = {
|
||||||
onEvent = viewModel::handleEvent,
|
Text(
|
||||||
|
stringResource(R.string.debounce_delay),
|
||||||
|
style =
|
||||||
|
MaterialTheme.typography.bodyMedium.copy(
|
||||||
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
|
),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leading = { Icon(Icons.Outlined.PauseCircle, null) },
|
||||||
|
onSelected = { selected ->
|
||||||
|
viewModel.handleEvent(AppEvent.SetDebounceDelay(selected!!))
|
||||||
|
},
|
||||||
|
options = (0..10).toList(),
|
||||||
|
currentValue = appUiState.appSettings.debounceDelaySeconds,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-49
@@ -1,49 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.components
|
|
||||||
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.outlined.PauseCircle
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.DropdownSelector
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun DebounceDelaySelector(currentDelay: Int, onEvent: (AppEvent) -> Unit) {
|
|
||||||
var isDropDownExpanded by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
SurfaceSelectionGroupButton(
|
|
||||||
listOf(
|
|
||||||
SelectionItem(
|
|
||||||
leadingIcon = Icons.Outlined.PauseCircle,
|
|
||||||
title = {
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.debounce_delay),
|
|
||||||
style =
|
|
||||||
MaterialTheme.typography.bodyMedium.copy(
|
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
|
||||||
),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onClick = { isDropDownExpanded = true },
|
|
||||||
trailing = {
|
|
||||||
DropdownSelector(
|
|
||||||
currentValue = currentDelay,
|
|
||||||
options = (0..10).toList(),
|
|
||||||
onValueSelected = { num -> onEvent(AppEvent.SetDebounceDelay(num)) },
|
|
||||||
isExpanded = isDropDownExpanded,
|
|
||||||
onDismiss = { isDropDownExpanded = false },
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
+2
-1
@@ -2,6 +2,7 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
|||||||
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Settings
|
import androidx.compose.material.icons.outlined.Settings
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -13,7 +14,7 @@ import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionIte
|
|||||||
@Composable
|
@Composable
|
||||||
fun AdvancedSettingsItem(onClick: () -> Unit): SelectionItem {
|
fun AdvancedSettingsItem(onClick: () -> Unit): SelectionItem {
|
||||||
return SelectionItem(
|
return SelectionItem(
|
||||||
leadingIcon = Icons.Outlined.Settings,
|
leading = { Icon(Icons.Outlined.Settings, contentDescription = null) },
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.advanced_settings),
|
stringResource(R.string.advanced_settings),
|
||||||
|
|||||||
+8
-7
@@ -4,6 +4,7 @@ import androidx.compose.material.icons.Icons
|
|||||||
import androidx.compose.material.icons.outlined.PublicOff
|
import androidx.compose.material.icons.outlined.PublicOff
|
||||||
import androidx.compose.material.icons.outlined.SettingsEthernet
|
import androidx.compose.material.icons.outlined.SettingsEthernet
|
||||||
import androidx.compose.material.icons.outlined.SignalCellular4Bar
|
import androidx.compose.material.icons.outlined.SignalCellular4Bar
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -21,7 +22,7 @@ import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
|||||||
fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<SelectionItem> {
|
fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<SelectionItem> {
|
||||||
return listOf(
|
return listOf(
|
||||||
SelectionItem(
|
SelectionItem(
|
||||||
leadingIcon = Icons.Outlined.SignalCellular4Bar,
|
leading = { Icon(Icons.Outlined.SignalCellular4Bar, contentDescription = null) },
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.tunnel_mobile_data),
|
stringResource(R.string.tunnel_mobile_data),
|
||||||
@@ -40,8 +41,8 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
|||||||
},
|
},
|
||||||
description = {
|
description = {
|
||||||
val cellularActive =
|
val cellularActive =
|
||||||
remember(uiState.networkStatus) {
|
remember(uiState.connectivityState) {
|
||||||
uiState.networkStatus?.cellularConnected ?: false
|
uiState.connectivityState?.cellularConnected ?: false
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
@@ -58,7 +59,7 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
|||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnCellular) },
|
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnCellular) },
|
||||||
),
|
),
|
||||||
SelectionItem(
|
SelectionItem(
|
||||||
leadingIcon = Icons.Outlined.SettingsEthernet,
|
leading = { Icon(Icons.Outlined.SettingsEthernet, contentDescription = null) },
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.tunnel_on_ethernet),
|
stringResource(R.string.tunnel_on_ethernet),
|
||||||
@@ -77,8 +78,8 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
|||||||
},
|
},
|
||||||
description = {
|
description = {
|
||||||
val ethernetActive =
|
val ethernetActive =
|
||||||
remember(uiState.networkStatus) {
|
remember(uiState.connectivityState) {
|
||||||
uiState.networkStatus?.ethernetConnected ?: false
|
uiState.connectivityState?.ethernetConnected ?: false
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
@@ -95,7 +96,7 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
|||||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
||||||
),
|
),
|
||||||
SelectionItem(
|
SelectionItem(
|
||||||
leadingIcon = Icons.Outlined.PublicOff,
|
leading = { Icon(Icons.Outlined.PublicOff, contentDescription = null) },
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.stop_on_no_internet),
|
stringResource(R.string.stop_on_no_internet),
|
||||||
|
|||||||
+1
-6
@@ -1,12 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
||||||
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
|
||||||
import androidx.compose.foundation.layout.FlowRow
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user