mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
97 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b641539af8 | |||
| 9f9a15a97c | |||
| eeeec5613f | |||
| af21a6a3cf | |||
| 0bf52ad378 | |||
| 0cf39fed68 | |||
| 590985d5cd | |||
| c16a1b9b55 | |||
| 679f6abbcb | |||
| bbc62a26e7 | |||
| e475fd27d9 | |||
| e2dd27e70c | |||
| a994e8e2c1 | |||
| 16d0642a51 | |||
| eac674c996 | |||
| 394188b55f | |||
| d61a4213cf | |||
| 90a693abb4 | |||
| 05b950fbb3 | |||
| 5310cf17e6 | |||
| 3ffc8c5e39 | |||
| e538ec80d0 | |||
| 6b24cca551 | |||
| f0c885708b | |||
| c028b9b5b6 | |||
| de8b39d848 | |||
| a573208db6 | |||
| 0e9a63c850 | |||
| 341a806f29 | |||
| 8d257a604c | |||
| 0b674684ba | |||
| 85a27f48a2 | |||
| 1f978cdf96 | |||
| 4f816fa175 | |||
| ee4ac4e968 | |||
| ff53454966 | |||
| 22c17ef66b | |||
| 7a60b90d2b | |||
| 5fd3f89a59 | |||
| 9510f43252 | |||
| 064aa6aa74 | |||
| 0c09add0e4 | |||
| fd0fd33f71 | |||
| aaeb251bbf | |||
| e563608e49 | |||
| 584f0386b6 | |||
| cf49c34bff | |||
| a0f89d40f5 | |||
| 4da05e23f1 | |||
| 6749719e21 | |||
| 1c160ff5f9 | |||
| 861440b7db | |||
| bdb0d27b53 | |||
| 9b3283a2b1 | |||
| 78def29980 | |||
| e83bbdf23a | |||
| 4beeb4e01e | |||
| 4bcd810b38 | |||
| e71174995b | |||
| f256a32bda | |||
| c49666303a | |||
| 3a9b435e50 | |||
| 0993f60977 | |||
| 3d88feb97c | |||
| f61e6d6c6e | |||
| df864ade95 | |||
| 0abe3f67ef | |||
| 880d30fdfa | |||
| 765785ff41 | |||
| 9991e06c44 | |||
| 433d383b0b | |||
| 041f12dc77 | |||
| afdc49629c | |||
| f846d54d78 | |||
| ffd9c4192a | |||
| d6138b80eb | |||
| 0874db8bbf | |||
| 6d483459a6 | |||
| 7e4f055833 | |||
| 8ea432b4f6 | |||
| 6637539d1f | |||
| bfe3533030 | |||
| b61d49469f | |||
| 349b56b2e2 | |||
| 42aa378938 | |||
| 062f59aa33 | |||
| 883b9f7dae | |||
| 1f8d24c704 | |||
| 68ab3fdc52 | |||
| b4b96a7e77 | |||
| 59a70e53ff | |||
| 170b12ab79 | |||
| 0f365e2ef8 | |||
| 950d75b57f | |||
| ea90896061 | |||
| c62b328187 | |||
| 46a962a730 |
@@ -1,22 +0,0 @@
|
|||||||
# Contributor Code of Conduct
|
|
||||||
|
|
||||||
## Pledge
|
|
||||||
|
|
||||||
We as individuals involved in this project, pledge to participate in this
|
|
||||||
community in a respectful, constructive, and civil manner as we work towards a common goal
|
|
||||||
of delivering free, open source, and value adding software for all.
|
|
||||||
|
|
||||||
## Standard
|
|
||||||
|
|
||||||
The standard for this community is the Golden Rule.
|
|
||||||
|
|
||||||
> “Do unto others as you would have them do unto you.”
|
|
||||||
|
|
||||||
## Scope
|
|
||||||
|
|
||||||
This Code of Conduct applies to all spaces related to WG Tunnel.
|
|
||||||
|
|
||||||
## Incidents or Concerns
|
|
||||||
|
|
||||||
For any incidents or concerns, reach out to Zane at
|
|
||||||
<support@zaneschepke.com>.
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
ko_fi: zaneschepke
|
ko_fi: zaneschepke
|
||||||
liberapay: zaneschepke
|
liberapay: zaneschepke
|
||||||
github: zaneschepke
|
github: zaneschepke
|
||||||
|
custom: ["https://wgtunnel.com/donate/"]
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
name: build-aab
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
build_type:
|
||||||
|
type: choice
|
||||||
|
description: "Build type"
|
||||||
|
required: true
|
||||||
|
default: release
|
||||||
|
options:
|
||||||
|
- release
|
||||||
|
flavor:
|
||||||
|
type: choice
|
||||||
|
description: "Product flavor"
|
||||||
|
required: true
|
||||||
|
default: google
|
||||||
|
options:
|
||||||
|
- google
|
||||||
|
secrets:
|
||||||
|
SIGNING_KEY_ALIAS:
|
||||||
|
required: false
|
||||||
|
SIGNING_KEY_PASSWORD:
|
||||||
|
required: false
|
||||||
|
SIGNING_STORE_PASSWORD:
|
||||||
|
required: false
|
||||||
|
SERVICE_ACCOUNT_JSON:
|
||||||
|
required: false
|
||||||
|
KEYSTORE:
|
||||||
|
required: false
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
build_type:
|
||||||
|
type: string
|
||||||
|
description: "Build type"
|
||||||
|
required: true
|
||||||
|
default: release
|
||||||
|
flavor:
|
||||||
|
type: string
|
||||||
|
description: "Product flavor"
|
||||||
|
required: false
|
||||||
|
default: google
|
||||||
|
secrets:
|
||||||
|
SIGNING_KEY_ALIAS:
|
||||||
|
required: false
|
||||||
|
SIGNING_KEY_PASSWORD:
|
||||||
|
required: false
|
||||||
|
SIGNING_STORE_PASSWORD:
|
||||||
|
required: false
|
||||||
|
SERVICE_ACCOUNT_JSON:
|
||||||
|
required: false
|
||||||
|
KEYSTORE:
|
||||||
|
required: false
|
||||||
|
|
||||||
|
env:
|
||||||
|
UPLOAD_DIR_ANDROID: android_artifacts
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
|
||||||
|
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
|
||||||
|
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
|
||||||
|
KEY_STORE_FILE: 'android_keystore.jks'
|
||||||
|
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
||||||
|
outputs:
|
||||||
|
UPLOAD_DIR_ANDROID: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up JDK 17
|
||||||
|
uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '17'
|
||||||
|
cache: gradle
|
||||||
|
|
||||||
|
- name: Grant execute permission for gradlew
|
||||||
|
run: chmod +x gradlew
|
||||||
|
|
||||||
|
- name: Decode Keystore
|
||||||
|
id: decode_keystore
|
||||||
|
uses: timheuer/base64-to-file@v1.2
|
||||||
|
with:
|
||||||
|
fileName: ${{ env.KEY_STORE_FILE }}
|
||||||
|
fileDir: ${{ env.KEY_STORE_LOCATION }}
|
||||||
|
encodedString: ${{ secrets.KEYSTORE }}
|
||||||
|
|
||||||
|
- name: Create keystore path env var
|
||||||
|
if: ${{ inputs.build_type != 'debug' }}
|
||||||
|
run: |
|
||||||
|
store_path=${{ env.KEY_STORE_LOCATION }}${{ env.KEY_STORE_FILE }}
|
||||||
|
echo "KEY_STORE_PATH=$store_path" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Build AAB (noSplits=true)
|
||||||
|
run: |
|
||||||
|
flavor=${{ inputs.flavor }}
|
||||||
|
build_type=${{ inputs.build_type }}
|
||||||
|
case $build_type in
|
||||||
|
"release")
|
||||||
|
./gradlew :app:bundle${flavor^}Release \
|
||||||
|
-PnoSplits=true \
|
||||||
|
--info
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
- name: Get release AAB path
|
||||||
|
id: aab-path
|
||||||
|
run: |
|
||||||
|
AAB_PATH=$(find app/build/outputs/bundle -iname "*google*release*.aab" -type f | head -1)
|
||||||
|
if [ -z "$AAB_PATH" ]; then
|
||||||
|
echo "Error: AAB not found!" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Found AAB: $AAB_PATH"
|
||||||
|
echo "path=$AAB_PATH" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Upload AAB Artifact
|
||||||
|
uses: actions/upload-artifact@v6
|
||||||
|
with:
|
||||||
|
name: google-play-aab
|
||||||
|
path: ${{ steps.aab-path.outputs.path }}
|
||||||
|
retention-days: 7
|
||||||
|
if-no-files-found: error
|
||||||
@@ -72,7 +72,7 @@ jobs:
|
|||||||
outputs:
|
outputs:
|
||||||
UPLOAD_DIR_ANDROID: ${{ env.UPLOAD_DIR_ANDROID }}
|
UPLOAD_DIR_ANDROID: ${{ env.UPLOAD_DIR_ANDROID }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 17
|
||||||
@@ -114,15 +114,11 @@ jobs:
|
|||||||
- name: Get release apk path
|
- name: Get release apk path
|
||||||
id: apk-path
|
id: apk-path
|
||||||
run: echo "path=$(find . -regex '^.*/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/.*\.apk$' -type f | head -1 | tail -c+2)" >> $GITHUB_OUTPUT
|
run: echo "path=$(find . -regex '^.*/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/.*\.apk$' -type f | head -1 | tail -c+2)" >> $GITHUB_OUTPUT
|
||||||
- name: Upload APK
|
- name: Upload All APK Artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v6
|
||||||
with:
|
with:
|
||||||
name: android_artifacts_${{ inputs.flavor }}
|
name: android_artifacts_${{ inputs.flavor }}
|
||||||
path: >-
|
path: >-
|
||||||
app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/${{
|
app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/*.apk
|
||||||
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
|
||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
has_new_commits: ${{ steps.check.outputs.new_commits }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v6
|
||||||
- name: Check for new commits
|
- name: Check for new commits
|
||||||
id: check
|
id: check
|
||||||
env:
|
env:
|
||||||
@@ -26,6 +26,9 @@ jobs:
|
|||||||
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
echo "new_commits=$NEW_COMMITS" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
build-standalone-nightly:
|
build-standalone-nightly:
|
||||||
|
needs:
|
||||||
|
- check_commits
|
||||||
|
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
@@ -34,14 +37,13 @@ jobs:
|
|||||||
|
|
||||||
publish:
|
publish:
|
||||||
needs:
|
needs:
|
||||||
- check_commits
|
|
||||||
- build-standalone-nightly
|
- build-standalone-nightly
|
||||||
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
if: ${{ needs.check_commits.outputs.has_new_commits > 0 && inputs.release_type != 'none' }}
|
||||||
name: publish-nightly
|
name: publish-nightly
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: |
|
run: |
|
||||||
@@ -69,7 +71,7 @@ jobs:
|
|||||||
run: mkdir ${{ github.workspace }}/temp
|
run: mkdir ${{ github.workspace }}/temp
|
||||||
|
|
||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: actions/download-artifact@v5
|
uses: actions/download-artifact@v7
|
||||||
with:
|
with:
|
||||||
pattern: android_artifacts_*
|
pattern: android_artifacts_*
|
||||||
path: ${{ github.workspace }}/temp
|
path: ${{ github.workspace }}/temp
|
||||||
@@ -124,4 +126,4 @@ jobs:
|
|||||||
files: |
|
files: |
|
||||||
${{ github.workspace }}/temp/**/*.apk
|
${{ github.workspace }}/temp/**/*.apk
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
name: notifications
|
name: notifications
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
on:
|
on:
|
||||||
issues:
|
issues:
|
||||||
types: [opened, closed]
|
types: [opened, closed]
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published, prereleased]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
notify:
|
notify:
|
||||||
@@ -43,15 +46,23 @@ jobs:
|
|||||||
--data-urlencode "text=$TEXT"
|
--data-urlencode "text=$TEXT"
|
||||||
|
|
||||||
- name: Send to Telegram - New Release
|
- name: Send to Telegram - New Release
|
||||||
if: github.event_name == 'release' && github.event.action == 'published'
|
if: github.event_name == 'release' && ((github.event.action == 'published' && !github.event.release.prerelease) || (github.event.action == 'prereleased' && github.event.release.prerelease && github.event.release.name == 'nightly'))
|
||||||
env:
|
env:
|
||||||
NAME: ${{ github.event.release.name }}
|
NAME: ${{ github.event.release.name }}
|
||||||
TAG: ${{ github.event.release.tag_name }}
|
TAG: ${{ github.event.release.tag_name }}
|
||||||
BODY: ${{ github.event.release.body || 'No notes provided' }}
|
BODY: ${{ github.event.release.body || 'No notes provided' }}
|
||||||
URL: ${{ github.event.release.html_url }}
|
URL: ${{ github.event.release.html_url }}
|
||||||
|
ACTION: ${{ github.event.action }}
|
||||||
run: |
|
run: |
|
||||||
BODY_TRUNC="${BODY:0:200}" # Truncate to avoid spam
|
BODY_TRUNC="${BODY:0:200}" # Truncate to avoid spam
|
||||||
TEXT=$(echo -e "🚀 New Release *$NAME* ($TAG)\n\n$BODY_TRUNC\n\n[View Release]($URL)")
|
if [ "$ACTION" == "prereleased" ]; then
|
||||||
|
ICON="🌙"
|
||||||
|
PREFIX="New Nightly Release"
|
||||||
|
else
|
||||||
|
ICON="🚀"
|
||||||
|
PREFIX="New Release"
|
||||||
|
fi
|
||||||
|
TEXT=$(echo -e "$ICON $PREFIX *$NAME* ($TAG)\n\n$BODY_TRUNC\n\n[View Release]($URL)")
|
||||||
curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage" \
|
curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage" \
|
||||||
-d chat_id="${{ vars.TELEGRAM_CHAT_ID }}" \
|
-d chat_id="${{ vars.TELEGRAM_CHAT_ID }}" \
|
||||||
${{ vars.TELEGRAM_THREAD_ID && format('-d message_thread_id="{0}"', vars.TELEGRAM_THREAD_ID) || '' }} \
|
${{ vars.TELEGRAM_THREAD_ID && format('-d message_thread_id="{0}"', vars.TELEGRAM_THREAD_ID) || '' }} \
|
||||||
@@ -106,15 +117,23 @@ jobs:
|
|||||||
-d "$PAYLOAD"
|
-d "$PAYLOAD"
|
||||||
|
|
||||||
- name: Send to Matrix - New Release
|
- name: Send to Matrix - New Release
|
||||||
if: github.event_name == 'release' && github.event.action == 'published'
|
if: github.event_name == 'release' && ((github.event.action == 'published' && !github.event.release.prerelease) || (github.event.action == 'prereleased' && github.event.release.prerelease && github.event.release.name == 'nightly'))
|
||||||
env:
|
env:
|
||||||
NAME: ${{ github.event.release.name }}
|
NAME: ${{ github.event.release.name }}
|
||||||
TAG: ${{ github.event.release.tag_name }}
|
TAG: ${{ github.event.release.tag_name }}
|
||||||
BODY: ${{ github.event.release.body || 'No notes provided' }}
|
BODY: ${{ github.event.release.body || 'No notes provided' }}
|
||||||
URL: ${{ github.event.release.html_url }}
|
URL: ${{ github.event.release.html_url }}
|
||||||
|
ACTION: ${{ github.event.action }}
|
||||||
run: |
|
run: |
|
||||||
PLAIN_MESSAGE=$(echo -e "🚀 New Release $NAME ($TAG)\n\n$BODY\n\nView Release: $URL")
|
if [ "$ACTION" == "prereleased" ]; then
|
||||||
HTML_MESSAGE=$(echo -e "<p>🚀 New Release <strong>$NAME</strong> ($TAG)</p><p>$BODY</p><p><a href=\"$URL\">View Release</a></p>")
|
ICON="🌙"
|
||||||
|
PREFIX="New Nightly Release"
|
||||||
|
else
|
||||||
|
ICON="🚀"
|
||||||
|
PREFIX="New Release"
|
||||||
|
fi
|
||||||
|
PLAIN_MESSAGE=$(echo -e "$ICON $PREFIX $NAME ($TAG)\n\n$BODY\n\nView Release: $URL")
|
||||||
|
HTML_MESSAGE=$(echo -e "<p>$ICON $PREFIX <strong>$NAME</strong> ($TAG)</p><p>$BODY</p><p><a href=\"$URL\">View Release</a></p>")
|
||||||
PLAIN_MESSAGE="${PLAIN_MESSAGE:0:220}"
|
PLAIN_MESSAGE="${PLAIN_MESSAGE:0:220}"
|
||||||
PAYLOAD=$(jq -n --arg body "$PLAIN_MESSAGE" --arg formatted "$HTML_MESSAGE" '{
|
PAYLOAD=$(jq -n --arg body "$PLAIN_MESSAGE" --arg formatted "$HTML_MESSAGE" '{
|
||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ jobs:
|
|||||||
format_check:
|
format_check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v5
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -32,14 +32,6 @@ on:
|
|||||||
description: "Tag name for release"
|
description: "Tag name for release"
|
||||||
required: false
|
required: false
|
||||||
default: 1.1.1
|
default: 1.1.1
|
||||||
flavor:
|
|
||||||
type: choice
|
|
||||||
description: "Product flavor"
|
|
||||||
required: true
|
|
||||||
default: standalone
|
|
||||||
options:
|
|
||||||
- fdroid
|
|
||||||
- standalone
|
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
flavor:
|
flavor:
|
||||||
@@ -51,7 +43,11 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build-fdroid:
|
build-fdroid:
|
||||||
if: ${{ github.event_name == 'push' || inputs.release_type == 'release' || inputs.flavor == 'fdroid' }}
|
if: >-
|
||||||
|
${{
|
||||||
|
github.event_name == 'push' ||
|
||||||
|
inputs.release_type != 'none'
|
||||||
|
}}
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
@@ -59,20 +55,30 @@ jobs:
|
|||||||
flavor: fdroid
|
flavor: fdroid
|
||||||
|
|
||||||
build-standalone:
|
build-standalone:
|
||||||
if: ${{ github.event_name == 'push' || inputs.release_type == 'release' || inputs.release_type == 'debug' || inputs.flavor == 'standalone' }}
|
if: >-
|
||||||
|
${{
|
||||||
|
github.event_name == 'push' ||
|
||||||
|
inputs.release_type != 'none'
|
||||||
|
}}
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
build_type: ${{ github.event_name == 'push' && 'release' || inputs.release_type }}
|
build_type: ${{ github.event_name == 'push' && 'release' || inputs.release_type }}
|
||||||
flavor: standalone
|
flavor: standalone
|
||||||
|
|
||||||
publish:
|
publish-github:
|
||||||
|
if: >-
|
||||||
|
${{
|
||||||
|
github.event_name == 'push' ||
|
||||||
|
inputs.release_type != 'none'
|
||||||
|
}}
|
||||||
needs:
|
needs:
|
||||||
- build-standalone
|
- build-fdroid
|
||||||
|
- build-standalone
|
||||||
name: publish-github
|
name: publish-github
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event_name == 'push' && github.ref || 'master' }}
|
ref: ${{ github.event_name == 'push' && github.ref || 'master' }}
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
@@ -109,7 +115,7 @@ jobs:
|
|||||||
run: mkdir ${{ github.workspace }}/temp
|
run: mkdir ${{ github.workspace }}/temp
|
||||||
|
|
||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
uses: actions/download-artifact@v5
|
uses: actions/download-artifact@v7
|
||||||
with:
|
with:
|
||||||
pattern: android_artifacts_*
|
pattern: android_artifacts_*
|
||||||
path: ${{ github.workspace }}/temp
|
path: ${{ github.workspace }}/temp
|
||||||
@@ -118,8 +124,8 @@ jobs:
|
|||||||
- name: Set version release notes
|
- name: Set version release notes
|
||||||
if: ${{ github.event_name == 'push' || 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_CODE=$(sed -nE 's/.*const val VERSION_CODE[[:space:]]*=[[:space:]]*([0-9]+).*/\1/p' buildSrc/src/main/kotlin/Constants.kt)
|
||||||
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_CODE}.txt || echo "No changelog found for ${VERSION_CODE}")"
|
||||||
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
|
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
|
||||||
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
||||||
echo "EOF" >> $GITHUB_ENV
|
echo "EOF" >> $GITHUB_ENV
|
||||||
@@ -162,13 +168,17 @@ jobs:
|
|||||||
files: |
|
files: |
|
||||||
${{ github.workspace }}/temp/**/*.apk
|
${{ github.workspace }}/temp/**/*.apk
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||||
|
|
||||||
publish-fdroid-public:
|
publish-fdroid-public:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: >-
|
||||||
|
${{
|
||||||
|
github.event_name == 'push' ||
|
||||||
|
inputs.release_type != 'none'
|
||||||
|
}}
|
||||||
needs:
|
needs:
|
||||||
- build-fdroid
|
- publish-github
|
||||||
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@v4
|
uses: peter-evans/repository-dispatch@v4
|
||||||
@@ -190,7 +200,7 @@ jobs:
|
|||||||
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
KEY_STORE_LOCATION: ${{ github.workspace }}/app/keystore/
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v5
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ and [AmneziaWG](https://docs.amnezia.org/documentation/amnezia-wg/)
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
[](https://play.google.com/store/apps/details?id=com.zaneschepke.wireguardautotunnel)
|
[](https://play.google.com/store/apps/details?id=com.zaneschepke.wireguardautotunnel)
|
||||||
[](https://f-droid.org/packages/com.zaneschepke.wireguardautotunnel/)
|
[](https://github.com/zaneschepke/fdroid)
|
||||||
[](https://github.com/zaneschepke/fdroid)
|
|
||||||
[](https://apps.obtainium.imranr.dev/redirect?r=obtainium://app/%7B%22id%22%3A%22com.zaneschepke.wireguardautotunnel%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.com%2Fzaneschepke%2Fwgtunnel%22%2C%22author%22%3A%22zaneschepke%22%2C%22name%22%3A%22WG%20Tunnel%22%2C%22preferredApkIndex%22%3A0%2C%22additionalSettings%22%3A%22%7B%5C%22includePrereleases%5C%22%3Afalse%2C%5C%22fallbackToOlderReleases%5C%22%3Atrue%2C%5C%22filterReleaseTitlesByRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22filterReleaseNotesByRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22verifyLatestTag%5C%22%3Atrue%2C%5C%22sortMethodChoice%5C%22%3A%5C%22date%5C%22%2C%5C%22useLatestAssetDateAsReleaseDate%5C%22%3Afalse%2C%5C%22releaseTitleAsVersion%5C%22%3Afalse%2C%5C%22trackOnly%5C%22%3Afalse%2C%5C%22versionExtractionRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22matchGroupToUse%5C%22%3A%5C%22%5C%22%2C%5C%22versionDetection%5C%22%3Atrue%2C%5C%22releaseDateAsVersion%5C%22%3Afalse%2C%5C%22useVersionCodeAsOSVersion%5C%22%3Afalse%2C%5C%22apkFilterRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22invertAPKFilter%5C%22%3Afalse%2C%5C%22autoApkFilterByArch%5C%22%3Atrue%2C%5C%22appName%5C%22%3A%5C%22WG%20Tunnel%5C%22%2C%5C%22appAuthor%5C%22%3A%5C%22Zane%20Schepke%5C%22%2C%5C%22shizukuPretendToBeGooglePlay%5C%22%3Afalse%2C%5C%22allowInsecure%5C%22%3Afalse%2C%5C%22exemptFromBackgroundUpdates%5C%22%3Afalse%2C%5C%22skipUpdateNotifications%5C%22%3Afalse%2C%5C%22about%5C%22%3A%5C%22%5C%22%2C%5C%22refreshBeforeDownload%5C%22%3Afalse%7D%22%2C%22overrideSource%22%3Anull%7D)
|
[](https://apps.obtainium.imranr.dev/redirect?r=obtainium://app/%7B%22id%22%3A%22com.zaneschepke.wireguardautotunnel%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.com%2Fzaneschepke%2Fwgtunnel%22%2C%22author%22%3A%22zaneschepke%22%2C%22name%22%3A%22WG%20Tunnel%22%2C%22preferredApkIndex%22%3A0%2C%22additionalSettings%22%3A%22%7B%5C%22includePrereleases%5C%22%3Afalse%2C%5C%22fallbackToOlderReleases%5C%22%3Atrue%2C%5C%22filterReleaseTitlesByRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22filterReleaseNotesByRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22verifyLatestTag%5C%22%3Atrue%2C%5C%22sortMethodChoice%5C%22%3A%5C%22date%5C%22%2C%5C%22useLatestAssetDateAsReleaseDate%5C%22%3Afalse%2C%5C%22releaseTitleAsVersion%5C%22%3Afalse%2C%5C%22trackOnly%5C%22%3Afalse%2C%5C%22versionExtractionRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22matchGroupToUse%5C%22%3A%5C%22%5C%22%2C%5C%22versionDetection%5C%22%3Atrue%2C%5C%22releaseDateAsVersion%5C%22%3Afalse%2C%5C%22useVersionCodeAsOSVersion%5C%22%3Afalse%2C%5C%22apkFilterRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22invertAPKFilter%5C%22%3Afalse%2C%5C%22autoApkFilterByArch%5C%22%3Atrue%2C%5C%22appName%5C%22%3A%5C%22WG%20Tunnel%5C%22%2C%5C%22appAuthor%5C%22%3A%5C%22Zane%20Schepke%5C%22%2C%5C%22shizukuPretendToBeGooglePlay%5C%22%3Afalse%2C%5C%22allowInsecure%5C%22%3Afalse%2C%5C%22exemptFromBackgroundUpdates%5C%22%3Afalse%2C%5C%22skipUpdateNotifications%5C%22%3Afalse%2C%5C%22about%5C%22%3A%5C%22%5C%22%2C%5C%22refreshBeforeDownload%5C%22%3Afalse%7D%22%2C%22overrideSource%22%3Anull%7D)
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -60,14 +59,12 @@ WG Tunnel is an alternative Android client for WireGuard and AmneziaWG, inspired
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex; flex-wrap: wrap; justify-content: left; gap: 10px;">
|
<div style="display: flex; flex-wrap: wrap; justify-content: left; gap: 10px;">
|
||||||
<img label="Main" src="fastlane/metadata/android/en-US/images/phoneScreenshots/main_screen.png" width="200" />
|
<img label="Main" src="fastlane/metadata/android/en-US/images/phoneScreenshots/main_screen.png" width="200" alt="Main"/>
|
||||||
<img label="Settings" src="fastlane/metadata/android/en-US/images/phoneScreenshots/settings_screen.png" width="200" />
|
<img label="Config" src="fastlane/metadata/android/en-US/images/phoneScreenshots/config_screen.png" width="200" alt="Config"/>
|
||||||
<img label="Auto" src="fastlane/metadata/android/en-US/images/phoneScreenshots/auto_screen.png" width="200" />
|
<img label="Settings" src="fastlane/metadata/android/en-US/images/phoneScreenshots/settings_screen.png" width="200" alt="Settings"/>
|
||||||
<img label="Config" src="fastlane/metadata/android/en-US/images/phoneScreenshots/config_screen.png" width="200" />
|
<img label="Auto-tunnel" src="fastlane/metadata/android/en-US/images/phoneScreenshots/auto_screen.png" width="200" alt="Auto-tunnel"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="text-align: left;">
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Tunnel Import Methods**: Easily add tunnels using .conf files, ZIP archives, manual entry, or QR code scanning.
|
- **Tunnel Import Methods**: Easily add tunnels using .conf files, ZIP archives, manual entry, or QR code scanning.
|
||||||
|
|||||||
+50
-18
@@ -1,9 +1,9 @@
|
|||||||
|
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
|
||||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
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)
|
||||||
alias(libs.plugins.hilt.android)
|
|
||||||
alias(libs.plugins.kotlinxSerialization)
|
alias(libs.plugins.kotlinxSerialization)
|
||||||
alias(libs.plugins.ksp)
|
alias(libs.plugins.ksp)
|
||||||
alias(libs.plugins.compose.compiler)
|
alias(libs.plugins.compose.compiler)
|
||||||
@@ -27,6 +27,15 @@ android {
|
|||||||
// fix okhttp proguard issue
|
// fix okhttp proguard issue
|
||||||
packaging { resources { pickFirsts.add("okhttp3/internal/publicsuffix/publicsuffixes.gz") } }
|
packaging { resources { pickFirsts.add("okhttp3/internal/publicsuffix/publicsuffixes.gz") } }
|
||||||
|
|
||||||
|
splits {
|
||||||
|
abi {
|
||||||
|
isEnable = !project.hasProperty("noSplits")
|
||||||
|
reset()
|
||||||
|
include("armeabi-v7a", "arm64-v8a")
|
||||||
|
isUniversalApk = !project.hasProperty("noSplits")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = Constants.APP_ID
|
applicationId = Constants.APP_ID
|
||||||
minSdk = Constants.MIN_SDK
|
minSdk = Constants.MIN_SDK
|
||||||
@@ -126,21 +135,37 @@ android {
|
|||||||
licensee {
|
licensee {
|
||||||
allowedLicenses().forEach { allow(it) }
|
allowedLicenses().forEach { allow(it) }
|
||||||
allowedLicenseUrls().forEach { allowUrl(it) }
|
allowedLicenseUrls().forEach { allowUrl(it) }
|
||||||
|
// foss, but missing license
|
||||||
|
ignoreDependencies("com.github.T8RIN.QuickieExtended")
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationVariants.all {
|
android.applicationVariants.all {
|
||||||
val variant = this
|
val variant = this
|
||||||
variant.outputs
|
|
||||||
.map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl }
|
val abiNameMap =
|
||||||
.forEach { output ->
|
mapOf(
|
||||||
val outputFileName =
|
"armeabi-v7a" to "armv7",
|
||||||
if (variant.flavorName == "fdroid" && variant.buildType.name == "release") {
|
"arm64-v8a" to "arm64",
|
||||||
"${Constants.APP_NAME}-fdroid-release-${variant.versionName}.apk"
|
"x86" to "x86",
|
||||||
} else {
|
"x86_64" to "x64",
|
||||||
"${Constants.APP_NAME}-${variant.flavorName}-v${variant.versionName}.apk"
|
)
|
||||||
}
|
|
||||||
output.outputFileName = outputFileName
|
variant.outputs.all {
|
||||||
}
|
val output = this as BaseVariantOutputImpl
|
||||||
|
val abi = output.getFilter("ABI")
|
||||||
|
|
||||||
|
val baseFileName = "${Constants.APP_NAME}-${variant.flavorName}-v${variant.versionName}"
|
||||||
|
|
||||||
|
val outputFileName =
|
||||||
|
if (!abi.isNullOrEmpty()) {
|
||||||
|
val shortAbiName = abiNameMap.getOrDefault(abi, abi)
|
||||||
|
"${baseFileName}-${shortAbiName}.apk"
|
||||||
|
} else {
|
||||||
|
"${baseFileName}.apk"
|
||||||
|
}
|
||||||
|
|
||||||
|
output.outputFileName = outputFileName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +188,6 @@ dependencies {
|
|||||||
// Navigation
|
// Navigation
|
||||||
implementation(libs.bundles.androidx.navigation3)
|
implementation(libs.bundles.androidx.navigation3)
|
||||||
implementation(libs.bundles.navigation.lifecycle)
|
implementation(libs.bundles.navigation.lifecycle)
|
||||||
implementation(libs.bundles.androidx.hilt)
|
|
||||||
|
|
||||||
// Material and icons
|
// Material and icons
|
||||||
implementation(libs.bundles.google.material)
|
implementation(libs.bundles.google.material)
|
||||||
@@ -174,11 +198,7 @@ dependencies {
|
|||||||
implementation(libs.bundles.androidx.datastore)
|
implementation(libs.bundles.androidx.datastore)
|
||||||
ksp(libs.androidx.room.compiler)
|
ksp(libs.androidx.room.compiler)
|
||||||
|
|
||||||
// DI and work
|
|
||||||
implementation(libs.bundles.hilt.android)
|
|
||||||
implementation(libs.bundles.androidx.work)
|
implementation(libs.bundles.androidx.work)
|
||||||
ksp(libs.hilt.android.compiler)
|
|
||||||
ksp(libs.androidx.hilt.compiler)
|
|
||||||
|
|
||||||
// Networking and serialization
|
// Networking and serialization
|
||||||
implementation(libs.bundles.ktor.client)
|
implementation(libs.bundles.ktor.client)
|
||||||
@@ -218,10 +238,22 @@ dependencies {
|
|||||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||||
debugImplementation(libs.androidx.compose.manifest)
|
debugImplementation(libs.androidx.compose.manifest)
|
||||||
|
|
||||||
|
debugImplementation(libs.leakcanary.android)
|
||||||
|
|
||||||
// Room database backup
|
// Room database backup
|
||||||
implementation(libs.roomdatabasebackup) {
|
implementation(libs.roomdatabasebackup) {
|
||||||
exclude(group = "org.reactivestreams", module = "reactive-streams")
|
exclude(group = "org.reactivestreams", module = "reactive-streams")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DI
|
||||||
|
implementation(platform(libs.koin.bom))
|
||||||
|
implementation(libs.koin.core)
|
||||||
|
implementation(libs.koin.android)
|
||||||
|
implementation(libs.koin.compose.viewmodel)
|
||||||
|
implementation(libs.koin.androidx.compose)
|
||||||
|
implementation(libs.koin.androidx.navigation)
|
||||||
|
implementation(libs.koin.lazy)
|
||||||
|
implementation(libs.koin.worker)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
||||||
|
|||||||
@@ -0,0 +1,509 @@
|
|||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 26,
|
||||||
|
"identityHash": "a420594a08fff58ecda3e0424fb43e47",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "tunnel_config",
|
||||||
|
"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_tunnel_config_name",
|
||||||
|
"unique": true,
|
||||||
|
"columnNames": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_tunnel_config_name` ON `${TABLE_NAME}` (`name`)"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "proxy_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `socks5_proxy_enabled` INTEGER NOT NULL DEFAULT 0, `socks5_proxy_bind_address` TEXT, `http_proxy_enable` INTEGER NOT NULL DEFAULT 0, `http_proxy_bind_address` TEXT, `proxy_username` TEXT, `proxy_password` TEXT)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "socks5ProxyEnabled",
|
||||||
|
"columnName": "socks5_proxy_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "socks5ProxyBindAddress",
|
||||||
|
"columnName": "socks5_proxy_bind_address",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "httpProxyEnabled",
|
||||||
|
"columnName": "http_proxy_enable",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "httpProxyBindAddress",
|
||||||
|
"columnName": "http_proxy_bind_address",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "proxyUsername",
|
||||||
|
"columnName": "proxy_username",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "proxyPassword",
|
||||||
|
"columnName": "proxy_password",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "general_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT 0, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT 0, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_globals_enabled` INTEGER NOT NULL DEFAULT 0, `app_mode` INTEGER NOT NULL DEFAULT 0, `theme` TEXT NOT NULL DEFAULT 'AUTOMATIC', `locale` TEXT, `remote_key` TEXT, `is_remote_control_enabled` INTEGER NOT NULL DEFAULT 0, `is_pin_lock_enabled` INTEGER NOT NULL DEFAULT 0, `is_always_on_vpn_enabled` INTEGER NOT NULL DEFAULT 0, `custom_split_packages` TEXT NOT NULL DEFAULT '{}')",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isShortcutsEnabled",
|
||||||
|
"columnName": "is_shortcuts_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRestoreOnBootEnabled",
|
||||||
|
"columnName": "is_restore_on_boot_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMultiTunnelEnabled",
|
||||||
|
"columnName": "is_multi_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelGlobalsEnabled",
|
||||||
|
"columnName": "is_tunnel_globals_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "appMode",
|
||||||
|
"columnName": "app_mode",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "theme",
|
||||||
|
"columnName": "theme",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "'AUTOMATIC'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "locale",
|
||||||
|
"columnName": "locale",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "remoteKey",
|
||||||
|
"columnName": "remote_key",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRemoteControlEnabled",
|
||||||
|
"columnName": "is_remote_control_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPinLockEnabled",
|
||||||
|
"columnName": "is_pin_lock_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||||
|
"columnName": "is_always_on_vpn_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "customSplitPackages",
|
||||||
|
"columnName": "custom_split_packages",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "'{}'"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "auto_tunnel_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL DEFAULT 0, `trusted_network_ssids` TEXT NOT NULL DEFAULT '', `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT 0, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT 0, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT 0, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT 0, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `start_on_boot` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAutoTunnelEnabled",
|
||||||
|
"columnName": "is_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||||
|
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "trustedNetworkSSIDs",
|
||||||
|
"columnName": "trusted_network_ssids",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||||
|
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnWifiEnabled",
|
||||||
|
"columnName": "is_tunnel_on_wifi_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isWildcardsEnabled",
|
||||||
|
"columnName": "is_wildcards_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isStopOnNoInternetEnabled",
|
||||||
|
"columnName": "is_stop_on_no_internet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "debounceDelaySeconds",
|
||||||
|
"columnName": "debounce_delay_seconds",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||||
|
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wifiDetectionMethod",
|
||||||
|
"columnName": "wifi_detection_method",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "startOnBoot",
|
||||||
|
"columnName": "start_on_boot",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "monitoring_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_ping_enabled` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT 1, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER, `show_detailed_ping_stats` INTEGER NOT NULL DEFAULT 0, `is_local_logs_enabled` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingEnabled",
|
||||||
|
"columnName": "is_ping_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingMonitoringEnabled",
|
||||||
|
"columnName": "is_ping_monitoring_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "showDetailedPingStats",
|
||||||
|
"columnName": "show_detailed_ping_stats",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isLocalLogsEnabled",
|
||||||
|
"columnName": "is_local_logs_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "dns_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `dns_protocol` INTEGER NOT NULL DEFAULT 0, `dns_endpoint` TEXT)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dnsProtocol",
|
||||||
|
"columnName": "dns_protocol",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dnsEndpoint",
|
||||||
|
"columnName": "dns_endpoint",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "lockdown_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `bypass_lan` INTEGER NOT NULL DEFAULT 0, `metered` INTEGER NOT NULL DEFAULT 0, `dual_stack` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "bypassLan",
|
||||||
|
"columnName": "bypass_lan",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "metered",
|
||||||
|
"columnName": "metered",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dualStack",
|
||||||
|
"columnName": "dual_stack",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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, 'a420594a08fff58ecda3e0424fb43e47')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,523 @@
|
|||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 27,
|
||||||
|
"identityHash": "98452d8160a1ae66c852ec8cd739e675",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "tunnel_config",
|
||||||
|
"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 '[]', `is_metered` 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": "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": "'[]'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMetered",
|
||||||
|
"columnName": "is_metered",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "true"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_tunnel_config_name",
|
||||||
|
"unique": true,
|
||||||
|
"columnNames": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_tunnel_config_name` ON `${TABLE_NAME}` (`name`)"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "proxy_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `socks5_proxy_enabled` INTEGER NOT NULL DEFAULT 0, `socks5_proxy_bind_address` TEXT, `http_proxy_enable` INTEGER NOT NULL DEFAULT 0, `http_proxy_bind_address` TEXT, `proxy_username` TEXT, `proxy_password` TEXT)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "socks5ProxyEnabled",
|
||||||
|
"columnName": "socks5_proxy_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "socks5ProxyBindAddress",
|
||||||
|
"columnName": "socks5_proxy_bind_address",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "httpProxyEnabled",
|
||||||
|
"columnName": "http_proxy_enable",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "httpProxyBindAddress",
|
||||||
|
"columnName": "http_proxy_bind_address",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "proxyUsername",
|
||||||
|
"columnName": "proxy_username",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "proxyPassword",
|
||||||
|
"columnName": "proxy_password",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "general_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT 0, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT 0, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `global_split_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `app_mode` INTEGER NOT NULL DEFAULT 0, `theme` TEXT NOT NULL DEFAULT 'AUTOMATIC', `locale` TEXT, `remote_key` TEXT, `is_remote_control_enabled` INTEGER NOT NULL DEFAULT 0, `is_pin_lock_enabled` INTEGER NOT NULL DEFAULT 0, `is_always_on_vpn_enabled` INTEGER NOT NULL DEFAULT 0, `custom_split_packages` TEXT NOT NULL DEFAULT '{}')",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isShortcutsEnabled",
|
||||||
|
"columnName": "is_shortcuts_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRestoreOnBootEnabled",
|
||||||
|
"columnName": "is_restore_on_boot_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMultiTunnelEnabled",
|
||||||
|
"columnName": "is_multi_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isGlobalSplitTunnelEnabled",
|
||||||
|
"columnName": "global_split_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "appMode",
|
||||||
|
"columnName": "app_mode",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "theme",
|
||||||
|
"columnName": "theme",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "'AUTOMATIC'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "locale",
|
||||||
|
"columnName": "locale",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "remoteKey",
|
||||||
|
"columnName": "remote_key",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRemoteControlEnabled",
|
||||||
|
"columnName": "is_remote_control_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPinLockEnabled",
|
||||||
|
"columnName": "is_pin_lock_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||||
|
"columnName": "is_always_on_vpn_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "customSplitPackages",
|
||||||
|
"columnName": "custom_split_packages",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "'{}'"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "auto_tunnel_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL DEFAULT 0, `trusted_network_ssids` TEXT NOT NULL DEFAULT '', `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT 0, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT 0, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT 0, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT 0, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `start_on_boot` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAutoTunnelEnabled",
|
||||||
|
"columnName": "is_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||||
|
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "trustedNetworkSSIDs",
|
||||||
|
"columnName": "trusted_network_ssids",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||||
|
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnWifiEnabled",
|
||||||
|
"columnName": "is_tunnel_on_wifi_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isWildcardsEnabled",
|
||||||
|
"columnName": "is_wildcards_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isStopOnNoInternetEnabled",
|
||||||
|
"columnName": "is_stop_on_no_internet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "debounceDelaySeconds",
|
||||||
|
"columnName": "debounce_delay_seconds",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||||
|
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wifiDetectionMethod",
|
||||||
|
"columnName": "wifi_detection_method",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "startOnBoot",
|
||||||
|
"columnName": "start_on_boot",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "monitoring_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_ping_enabled` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT 1, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER, `show_detailed_ping_stats` INTEGER NOT NULL DEFAULT 0, `is_local_logs_enabled` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingEnabled",
|
||||||
|
"columnName": "is_ping_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingMonitoringEnabled",
|
||||||
|
"columnName": "is_ping_monitoring_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "showDetailedPingStats",
|
||||||
|
"columnName": "show_detailed_ping_stats",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isLocalLogsEnabled",
|
||||||
|
"columnName": "is_local_logs_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "dns_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `dns_protocol` INTEGER NOT NULL DEFAULT 0, `dns_endpoint` TEXT, `global_tunnel_dns_enabled` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dnsProtocol",
|
||||||
|
"columnName": "dns_protocol",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dnsEndpoint",
|
||||||
|
"columnName": "dns_endpoint",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isGlobalTunnelDnsEnabled",
|
||||||
|
"columnName": "global_tunnel_dns_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "lockdown_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `bypass_lan` INTEGER NOT NULL DEFAULT 0, `metered` INTEGER NOT NULL DEFAULT 0, `dual_stack` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "bypassLan",
|
||||||
|
"columnName": "bypass_lan",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "metered",
|
||||||
|
"columnName": "metered",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dualStack",
|
||||||
|
"columnName": "dual_stack",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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, '98452d8160a1ae66c852ec8cd739e675')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,523 @@
|
|||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 28,
|
||||||
|
"identityHash": "4792d0cc61a527c69962b5e58463e6da",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "tunnel_config",
|
||||||
|
"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 '[]', `is_metered` 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": "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": "'[]'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMetered",
|
||||||
|
"columnName": "is_metered",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "true"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_tunnel_config_name",
|
||||||
|
"unique": true,
|
||||||
|
"columnNames": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_tunnel_config_name` ON `${TABLE_NAME}` (`name`)"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "proxy_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `socks5_proxy_enabled` INTEGER NOT NULL DEFAULT 0, `socks5_proxy_bind_address` TEXT, `http_proxy_enable` INTEGER NOT NULL DEFAULT 0, `http_proxy_bind_address` TEXT, `proxy_username` TEXT, `proxy_password` TEXT)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "socks5ProxyEnabled",
|
||||||
|
"columnName": "socks5_proxy_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "socks5ProxyBindAddress",
|
||||||
|
"columnName": "socks5_proxy_bind_address",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "httpProxyEnabled",
|
||||||
|
"columnName": "http_proxy_enable",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "httpProxyBindAddress",
|
||||||
|
"columnName": "http_proxy_bind_address",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "proxyUsername",
|
||||||
|
"columnName": "proxy_username",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "proxyPassword",
|
||||||
|
"columnName": "proxy_password",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "general_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT 0, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT 0, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `global_split_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `app_mode` INTEGER NOT NULL DEFAULT 0, `theme` TEXT NOT NULL DEFAULT 'AUTOMATIC', `locale` TEXT, `remote_key` TEXT, `is_remote_control_enabled` INTEGER NOT NULL DEFAULT 0, `is_pin_lock_enabled` INTEGER NOT NULL DEFAULT 0, `is_always_on_vpn_enabled` INTEGER NOT NULL DEFAULT 0, `already_donated` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isShortcutsEnabled",
|
||||||
|
"columnName": "is_shortcuts_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRestoreOnBootEnabled",
|
||||||
|
"columnName": "is_restore_on_boot_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMultiTunnelEnabled",
|
||||||
|
"columnName": "is_multi_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isGlobalSplitTunnelEnabled",
|
||||||
|
"columnName": "global_split_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "appMode",
|
||||||
|
"columnName": "app_mode",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "theme",
|
||||||
|
"columnName": "theme",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "'AUTOMATIC'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "locale",
|
||||||
|
"columnName": "locale",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "remoteKey",
|
||||||
|
"columnName": "remote_key",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRemoteControlEnabled",
|
||||||
|
"columnName": "is_remote_control_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPinLockEnabled",
|
||||||
|
"columnName": "is_pin_lock_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||||
|
"columnName": "is_always_on_vpn_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "alreadyDonated",
|
||||||
|
"columnName": "already_donated",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "auto_tunnel_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL DEFAULT 0, `trusted_network_ssids` TEXT NOT NULL DEFAULT '', `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT 0, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT 0, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT 0, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT 0, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `start_on_boot` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAutoTunnelEnabled",
|
||||||
|
"columnName": "is_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||||
|
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "trustedNetworkSSIDs",
|
||||||
|
"columnName": "trusted_network_ssids",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||||
|
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnWifiEnabled",
|
||||||
|
"columnName": "is_tunnel_on_wifi_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isWildcardsEnabled",
|
||||||
|
"columnName": "is_wildcards_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isStopOnNoInternetEnabled",
|
||||||
|
"columnName": "is_stop_on_no_internet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "debounceDelaySeconds",
|
||||||
|
"columnName": "debounce_delay_seconds",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||||
|
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wifiDetectionMethod",
|
||||||
|
"columnName": "wifi_detection_method",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "startOnBoot",
|
||||||
|
"columnName": "start_on_boot",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "monitoring_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_ping_enabled` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT 1, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER, `show_detailed_ping_stats` INTEGER NOT NULL DEFAULT 0, `is_local_logs_enabled` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingEnabled",
|
||||||
|
"columnName": "is_ping_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingMonitoringEnabled",
|
||||||
|
"columnName": "is_ping_monitoring_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "showDetailedPingStats",
|
||||||
|
"columnName": "show_detailed_ping_stats",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isLocalLogsEnabled",
|
||||||
|
"columnName": "is_local_logs_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "dns_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `dns_protocol` INTEGER NOT NULL DEFAULT 0, `dns_endpoint` TEXT, `global_tunnel_dns_enabled` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dnsProtocol",
|
||||||
|
"columnName": "dns_protocol",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dnsEndpoint",
|
||||||
|
"columnName": "dns_endpoint",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isGlobalTunnelDnsEnabled",
|
||||||
|
"columnName": "global_tunnel_dns_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "lockdown_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `bypass_lan` INTEGER NOT NULL DEFAULT 0, `metered` INTEGER NOT NULL DEFAULT 0, `dual_stack` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "bypassLan",
|
||||||
|
"columnName": "bypass_lan",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "metered",
|
||||||
|
"columnName": "metered",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dualStack",
|
||||||
|
"columnName": "dual_stack",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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, '4792d0cc61a527c69962b5e58463e6da')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,523 @@
|
|||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 29,
|
||||||
|
"identityHash": "345471c118dee1b7688afa81d835e62c",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "tunnel_config",
|
||||||
|
"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 '[]', `is_metered` INTEGER NOT NULL DEFAULT false)",
|
||||||
|
"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": "'[]'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMetered",
|
||||||
|
"columnName": "is_metered",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "false"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_tunnel_config_name",
|
||||||
|
"unique": true,
|
||||||
|
"columnNames": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_tunnel_config_name` ON `${TABLE_NAME}` (`name`)"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "proxy_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `socks5_proxy_enabled` INTEGER NOT NULL DEFAULT 0, `socks5_proxy_bind_address` TEXT, `http_proxy_enable` INTEGER NOT NULL DEFAULT 0, `http_proxy_bind_address` TEXT, `proxy_username` TEXT, `proxy_password` TEXT)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "socks5ProxyEnabled",
|
||||||
|
"columnName": "socks5_proxy_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "socks5ProxyBindAddress",
|
||||||
|
"columnName": "socks5_proxy_bind_address",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "httpProxyEnabled",
|
||||||
|
"columnName": "http_proxy_enable",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "httpProxyBindAddress",
|
||||||
|
"columnName": "http_proxy_bind_address",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "proxyUsername",
|
||||||
|
"columnName": "proxy_username",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "proxyPassword",
|
||||||
|
"columnName": "proxy_password",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "general_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT 0, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT 0, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `global_split_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `app_mode` INTEGER NOT NULL DEFAULT 0, `theme` TEXT NOT NULL DEFAULT 'AUTOMATIC', `locale` TEXT, `remote_key` TEXT, `is_remote_control_enabled` INTEGER NOT NULL DEFAULT 0, `is_pin_lock_enabled` INTEGER NOT NULL DEFAULT 0, `is_always_on_vpn_enabled` INTEGER NOT NULL DEFAULT 0, `already_donated` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isShortcutsEnabled",
|
||||||
|
"columnName": "is_shortcuts_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRestoreOnBootEnabled",
|
||||||
|
"columnName": "is_restore_on_boot_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isMultiTunnelEnabled",
|
||||||
|
"columnName": "is_multi_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isGlobalSplitTunnelEnabled",
|
||||||
|
"columnName": "global_split_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "appMode",
|
||||||
|
"columnName": "app_mode",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "theme",
|
||||||
|
"columnName": "theme",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "'AUTOMATIC'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "locale",
|
||||||
|
"columnName": "locale",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "remoteKey",
|
||||||
|
"columnName": "remote_key",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isRemoteControlEnabled",
|
||||||
|
"columnName": "is_remote_control_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPinLockEnabled",
|
||||||
|
"columnName": "is_pin_lock_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||||
|
"columnName": "is_always_on_vpn_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "alreadyDonated",
|
||||||
|
"columnName": "already_donated",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "auto_tunnel_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL DEFAULT 0, `trusted_network_ssids` TEXT NOT NULL DEFAULT '', `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT 0, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT 0, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT 0, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT 0, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `start_on_boot` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isAutoTunnelEnabled",
|
||||||
|
"columnName": "is_tunnel_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||||
|
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "trustedNetworkSSIDs",
|
||||||
|
"columnName": "trusted_network_ssids",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "''"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||||
|
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnWifiEnabled",
|
||||||
|
"columnName": "is_tunnel_on_wifi_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isWildcardsEnabled",
|
||||||
|
"columnName": "is_wildcards_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isStopOnNoInternetEnabled",
|
||||||
|
"columnName": "is_stop_on_no_internet_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "debounceDelaySeconds",
|
||||||
|
"columnName": "debounce_delay_seconds",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||||
|
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "wifiDetectionMethod",
|
||||||
|
"columnName": "wifi_detection_method",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "startOnBoot",
|
||||||
|
"columnName": "start_on_boot",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "monitoring_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_ping_enabled` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT 1, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER, `show_detailed_ping_stats` INTEGER NOT NULL DEFAULT 0, `is_local_logs_enabled` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingEnabled",
|
||||||
|
"columnName": "is_ping_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isPingMonitoringEnabled",
|
||||||
|
"columnName": "is_ping_monitoring_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "showDetailedPingStats",
|
||||||
|
"columnName": "show_detailed_ping_stats",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isLocalLogsEnabled",
|
||||||
|
"columnName": "is_local_logs_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "dns_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `dns_protocol` INTEGER NOT NULL DEFAULT 0, `dns_endpoint` TEXT, `global_tunnel_dns_enabled` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dnsProtocol",
|
||||||
|
"columnName": "dns_protocol",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dnsEndpoint",
|
||||||
|
"columnName": "dns_endpoint",
|
||||||
|
"affinity": "TEXT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isGlobalTunnelDnsEnabled",
|
||||||
|
"columnName": "global_tunnel_dns_enabled",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "lockdown_settings",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `bypass_lan` INTEGER NOT NULL DEFAULT 0, `metered` INTEGER NOT NULL DEFAULT 0, `dual_stack` INTEGER NOT NULL DEFAULT 0)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "id",
|
||||||
|
"columnName": "id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "bypassLan",
|
||||||
|
"columnName": "bypass_lan",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "metered",
|
||||||
|
"columnName": "metered",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dualStack",
|
||||||
|
"columnName": "dual_stack",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true,
|
||||||
|
"defaultValue": "0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"autoGenerate": true,
|
||||||
|
"columnNames": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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, '345471c118dee1b7688afa81d835e62c')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,9 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
|
||||||
|
<!--for split tunneling-->
|
||||||
|
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
|
||||||
|
|
||||||
<!--foreground service special use for non VPN service tunnels, android 14-->
|
<!--foreground service special use for non VPN service tunnels, android 14-->
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||||
<!--foreground service special use for VPN service tunnels, android 14-->
|
<!--foreground service special use for VPN service tunnels, android 14-->
|
||||||
@@ -14,6 +17,7 @@
|
|||||||
<!--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.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" />
|
||||||
|
|
||||||
@@ -42,17 +46,6 @@
|
|||||||
|
|
||||||
<uses-feature android:name="android.hardware.wifi"
|
<uses-feature android:name="android.hardware.wifi"
|
||||||
android:required="false"/>
|
android:required="false"/>
|
||||||
|
|
||||||
<queries>
|
|
||||||
<intent>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent>
|
|
||||||
<intent>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
|
||||||
</intent>
|
|
||||||
</queries>
|
|
||||||
<application
|
<application
|
||||||
android:name=".WireGuardAutoTunnel"
|
android:name=".WireGuardAutoTunnel"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
@@ -66,10 +59,7 @@
|
|||||||
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"
|
||||||
@@ -113,13 +103,50 @@
|
|||||||
android:resource="@xml/file_paths" />
|
android:resource="@xml/file_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="androidx.startup.InitializationProvider"
|
android:name="androidx.startup.InitializationProvider"
|
||||||
android:authorities="${applicationId}.androidx-startup"
|
android:authorities="${applicationId}.androidx-startup"
|
||||||
android:multiprocess="true"
|
android:exported="false"
|
||||||
tools:node="remove">
|
tools:node="merge">
|
||||||
</provider>
|
<meta-data
|
||||||
|
android:name="androidx.work.WorkManagerInitializer"
|
||||||
|
android:value="androidx.startup"
|
||||||
|
tools:node="remove" />
|
||||||
|
</provider>
|
||||||
|
<service
|
||||||
|
android:name=".core.service.tile.TunnelControlTile"
|
||||||
|
android:exported="true"
|
||||||
|
android:icon="@drawable/ic_notification"
|
||||||
|
android:label="@string/tunnel_control"
|
||||||
|
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.service.quicksettings.ACTIVE_TILE"
|
||||||
|
android:value="true" />
|
||||||
|
<meta-data
|
||||||
|
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
|
||||||
|
android:value="true" />
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
<service
|
||||||
|
android:name=".core.service.tile.AutoTunnelControlTile"
|
||||||
|
android:exported="true"
|
||||||
|
android:icon="@drawable/ic_notification"
|
||||||
|
android:label="@string/auto_tunnel"
|
||||||
|
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.service.quicksettings.ACTIVE_TILE"
|
||||||
|
android:value="true" />
|
||||||
|
<meta-data
|
||||||
|
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
|
||||||
|
android:value="true" />
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
<service
|
<service
|
||||||
android:name=".core.service.tile.TunnelControlTile"
|
android:name=".core.service.tile.TunnelControlTile"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
@@ -205,7 +232,10 @@
|
|||||||
<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" />
|
||||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<receiver
|
<receiver
|
||||||
|
|||||||
@@ -11,41 +11,69 @@ import androidx.activity.compose.rememberLauncherForActivityResult
|
|||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.activity.viewModels
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.compose.animation.*
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
|
import androidx.compose.animation.slideInHorizontally
|
||||||
|
import androidx.compose.animation.slideOutHorizontally
|
||||||
|
import androidx.compose.animation.togetherWith
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.foundation.layout.consumeWindowInsets
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.imePadding
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.wrapContentHeight
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.derivedStateOf
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
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.res.stringResource
|
||||||
|
import androidx.compose.ui.text.LinkAnnotation
|
||||||
|
import androidx.compose.ui.text.SpanStyle
|
||||||
|
import androidx.compose.ui.text.TextLinkStyles
|
||||||
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
|
import androidx.compose.ui.text.intl.Locale
|
||||||
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
|
import androidx.compose.ui.text.withLink
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
|
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
|
||||||
import androidx.navigation3.runtime.NavKey
|
|
||||||
import androidx.navigation3.runtime.entryProvider
|
import androidx.navigation3.runtime.entryProvider
|
||||||
import androidx.navigation3.runtime.rememberNavBackStack
|
import androidx.navigation3.runtime.rememberNavBackStack
|
||||||
import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator
|
import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator
|
||||||
import androidx.navigation3.ui.NavDisplay
|
import androidx.navigation3.ui.NavDisplay
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.sideeffect.GlobalSideEffect
|
import com.zaneschepke.wireguardautotunnel.domain.sideeffect.GlobalSideEffect
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.LocalIsAndroidTV
|
import com.zaneschepke.wireguardautotunnel.ui.LocalIsAndroidTV
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.LocalNavController
|
import com.zaneschepke.wireguardautotunnel.ui.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.LocalSharedVm
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.banner.AppAlertBanner
|
import com.zaneschepke.wireguardautotunnel.ui.common.banner.AppAlertBanner
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.CustomSnackBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.CustomSnackBar
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarInfo
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarType
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.rememberCustomSnackbarState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.Route
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.Tab
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.Tab
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.BottomNavbar
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.BottomNavbar
|
||||||
@@ -64,8 +92,8 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.Appear
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.display.DisplayScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.display.DisplayScreen
|
||||||
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.dns.DnsSettingsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.dns.DnsSettingsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.globals.TunnelGlobalsScreen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.integrations.AndroidIntegrationsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.integrations.AndroidIntegrationsScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.lockdown.LockdownSettingsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.monitoring.TunnelMonitoringScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.monitoring.TunnelMonitoringScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.monitoring.logs.LogsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.monitoring.logs.LogsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.monitoring.ping.PingTargetScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.monitoring.ping.PingTargetScreen
|
||||||
@@ -75,34 +103,39 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.support.donate.crypto.Addr
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.license.LicenseScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.license.LicenseScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.TunnelsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.TunnelsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.config.ConfigScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.config.ConfigScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.settings.TunnelSettingsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.sort.SortScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.sort.SortScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.splittunnel.SplitTunnelScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.splittunnel.SplitTunnelScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.tunneloptions.TunnelOptionsScreen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.AlertRed
|
import com.zaneschepke.wireguardautotunnel.ui.theme.AlertRed
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.OffWhite
|
import com.zaneschepke.wireguardautotunnel.ui.theme.OffWhite
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
||||||
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
import com.zaneschepke.wireguardautotunnel.util.extensions.installApk
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.restartApp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.showToast
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.ConfigViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.ConfigViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.SharedAppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.SharedAppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.SplitTunnelViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.SplitTunnelViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.TunnelViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.TunnelViewModel
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import de.raphaelebner.roomdatabasebackup.core.RoomBackup
|
import de.raphaelebner.roomdatabasebackup.core.RoomBackup
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
|
import org.koin.androidx.compose.koinViewModel
|
||||||
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||||
|
import org.koin.core.parameter.parametersOf
|
||||||
import xyz.teamgravity.pin_lock_compose.PinManager
|
import xyz.teamgravity.pin_lock_compose.PinManager
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@Inject lateinit var appStateRepository: AppStateRepository
|
private val appStateRepository: AppStateRepository by inject()
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
private val tunnelRepository: TunnelRepository by inject()
|
||||||
@Inject lateinit var networkMonitor: NetworkMonitor
|
private val appDatabase: AppDatabase by inject()
|
||||||
@Inject lateinit var appDatabase: AppDatabase
|
private val networkMonitor: NetworkMonitor by inject()
|
||||||
|
|
||||||
|
val viewModel by viewModel<SharedAppViewModel>()
|
||||||
private lateinit var roomBackup: RoomBackup
|
private lateinit var roomBackup: RoomBackup
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@@ -118,8 +151,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
roomBackup = RoomBackup(this)
|
roomBackup = RoomBackup(this)
|
||||||
|
|
||||||
val viewModel by viewModels<SharedAppViewModel>()
|
|
||||||
|
|
||||||
installSplashScreen().apply {
|
installSplashScreen().apply {
|
||||||
setKeepOnScreenCondition { !viewModel.container.stateFlow.value.isAppLoaded }
|
setKeepOnScreenCondition { !viewModel.container.stateFlow.value.isAppLoaded }
|
||||||
}
|
}
|
||||||
@@ -127,16 +158,16 @@ class MainActivity : AppCompatActivity() {
|
|||||||
setContent {
|
setContent {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val isTv = isRunningOnTv()
|
val isTv = isRunningOnTv()
|
||||||
val appState by viewModel.container.stateFlow.collectAsStateWithLifecycle()
|
val uiState by viewModel.container.stateFlow.collectAsStateWithLifecycle()
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
LaunchedEffect(appState.isAppLoaded) {
|
LaunchedEffect(uiState.isAppLoaded) {
|
||||||
if (appState.isAppLoaded) {
|
if (uiState.isAppLoaded) {
|
||||||
appState.locale.let { LocaleUtil.changeLocale(it) }
|
uiState.locale.let { LocaleUtil.changeLocale(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val snackbar = remember { SnackbarHostState() }
|
val snackbarState = rememberCustomSnackbarState()
|
||||||
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
||||||
var vpnPermissionDenied by remember { mutableStateOf(false) }
|
var vpnPermissionDenied by remember { mutableStateOf(false) }
|
||||||
var requestingAppMode by remember {
|
var requestingAppMode by remember {
|
||||||
@@ -146,17 +177,19 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val startingStack = buildList {
|
val startingStack = buildList {
|
||||||
add(Route.Tunnels)
|
add(Route.Tunnels)
|
||||||
if (intent?.action == Intent.ACTION_APPLICATION_PREFERENCES) add(Route.Settings)
|
if (intent?.action == Intent.ACTION_APPLICATION_PREFERENCES) add(Route.Settings)
|
||||||
if (appState.pinLockEnabled) add(Route.Lock)
|
if (uiState.pinLockEnabled) add(Route.Lock)
|
||||||
}
|
}
|
||||||
|
|
||||||
val backStack = rememberNavBackStack(*startingStack.toTypedArray())
|
val backStack = rememberNavBackStack(*startingStack.toTypedArray())
|
||||||
var previousRoute by remember { mutableStateOf<Route?>(null) }
|
var previousRoute by remember { mutableStateOf<Route?>(null) }
|
||||||
|
|
||||||
val navController =
|
val navController =
|
||||||
rememberNavController<NavKey>(backStack, appState.isLocationDisclosureShown) {
|
rememberNavController(
|
||||||
previousKey ->
|
backStack,
|
||||||
previousRoute = previousKey as? Route
|
uiState.isLocationDisclosureShown,
|
||||||
}
|
onChange = { previousKey -> previousRoute = previousKey as? Route },
|
||||||
|
onExitApp = { finish() },
|
||||||
|
)
|
||||||
|
|
||||||
val vpnActivity =
|
val vpnActivity =
|
||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
@@ -189,10 +222,20 @@ class MainActivity : AppCompatActivity() {
|
|||||||
vpnActivity.launch(VpnService.prepare(this@MainActivity))
|
vpnActivity.launch(VpnService.prepare(this@MainActivity))
|
||||||
}
|
}
|
||||||
|
|
||||||
is GlobalSideEffect.Snackbar ->
|
is GlobalSideEffect.Snackbar -> {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
snackbar.showSnackbar(sideEffect.message.asString(context))
|
snackbarState.showSnackbar(
|
||||||
|
SnackbarInfo(
|
||||||
|
message =
|
||||||
|
buildAnnotatedString {
|
||||||
|
append(sideEffect.message.asString(context))
|
||||||
|
},
|
||||||
|
type = sideEffect.type ?: SnackbarType.INFO,
|
||||||
|
durationMs = sideEffect.durationMs ?: 4000L,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
is GlobalSideEffect.Toast ->
|
is GlobalSideEffect.Toast ->
|
||||||
scope.launch { context.showToast(sideEffect.message.asString(context)) }
|
scope.launch { context.showToast(sideEffect.message.asString(context)) }
|
||||||
@@ -203,19 +246,18 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!appState.isAppLoaded) return@setContent
|
if (!uiState.isAppLoaded) return@setContent
|
||||||
|
|
||||||
var showLock by remember {
|
var showLock by remember {
|
||||||
mutableStateOf(appState.pinLockEnabled && !appState.isPinVerified)
|
mutableStateOf(uiState.pinLockEnabled && !uiState.isPinVerified)
|
||||||
}
|
}
|
||||||
LaunchedEffect(appState.isPinVerified) { if (appState.isPinVerified) showLock = false }
|
LaunchedEffect(uiState.isPinVerified) { if (uiState.isPinVerified) showLock = false }
|
||||||
|
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
LocalIsAndroidTV provides isTv,
|
LocalIsAndroidTV provides isTv,
|
||||||
LocalSharedVm provides viewModel,
|
|
||||||
LocalNavController provides navController,
|
LocalNavController provides navController,
|
||||||
) {
|
) {
|
||||||
WireguardAutoTunnelTheme(theme = appState.theme) {
|
WireguardAutoTunnelTheme(theme = uiState.theme) {
|
||||||
VpnDeniedDialog(
|
VpnDeniedDialog(
|
||||||
showVpnPermissionDialog,
|
showVpnPermissionDialog,
|
||||||
onDismiss = {
|
onDismiss = {
|
||||||
@@ -224,6 +266,53 @@ class MainActivity : AppCompatActivity() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val annotatedMessage = buildAnnotatedString {
|
||||||
|
append(context.getString(R.string.donation_prompt_prefix))
|
||||||
|
append(" ")
|
||||||
|
withLink(
|
||||||
|
LinkAnnotation.Clickable(
|
||||||
|
tag = context.getString(R.string.support),
|
||||||
|
styles =
|
||||||
|
TextLinkStyles(
|
||||||
|
style =
|
||||||
|
SpanStyle(
|
||||||
|
textDecoration = TextDecoration.Underline,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
),
|
||||||
|
focusedStyle =
|
||||||
|
SpanStyle(
|
||||||
|
textDecoration = TextDecoration.Underline,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
background =
|
||||||
|
MaterialTheme.colorScheme.primary.copy(
|
||||||
|
alpha = 0.2f
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
snackbarState.dismissCurrent()
|
||||||
|
navController.push(Route.Donate)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
append(context.getString(R.string.donation_prompt_link))
|
||||||
|
}
|
||||||
|
append(" ")
|
||||||
|
append(context.getString(R.string.donation_prompt_suffix))
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
if (uiState.shouldShowDonationSnackbar && !uiState.alreadyDonated) {
|
||||||
|
viewModel.setShouldShowDonationSnackbar(false)
|
||||||
|
snackbarState.showSnackbar(
|
||||||
|
SnackbarInfo(
|
||||||
|
message = annotatedMessage,
|
||||||
|
type = SnackbarType.THANK_YOU,
|
||||||
|
durationMs = 30_000L,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (showLock) {
|
if (showLock) {
|
||||||
PinManager.initialize(context = this@MainActivity)
|
PinManager.initialize(context = this@MainActivity)
|
||||||
PinLockScreen()
|
PinLockScreen()
|
||||||
@@ -236,17 +325,17 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
val navState by
|
val navState by
|
||||||
currentRouteAsNavbarState(
|
currentRouteAsNavbarState(
|
||||||
appState,
|
uiState,
|
||||||
viewModel,
|
viewModel,
|
||||||
currentRoute,
|
currentRoute,
|
||||||
navController,
|
navController,
|
||||||
)
|
)
|
||||||
|
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
if (appState.settings.appMode == AppMode.LOCK_DOWN) {
|
if (uiState.appMode == AppMode.LOCK_DOWN) {
|
||||||
AppAlertBanner(
|
AppAlertBanner(
|
||||||
stringResource(R.string.locked_down)
|
stringResource(R.string.locked_down)
|
||||||
.uppercase(Locale.getDefault()),
|
.uppercase(Locale.current.platformLocale),
|
||||||
OffWhite,
|
OffWhite,
|
||||||
AlertRed,
|
AlertRed,
|
||||||
modifier = Modifier.fillMaxWidth().zIndex(2f),
|
modifier = Modifier.fillMaxWidth().zIndex(2f),
|
||||||
@@ -254,14 +343,25 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
Scaffold(
|
Scaffold(
|
||||||
snackbarHost = {
|
snackbarHost = {
|
||||||
SnackbarHost(snackbar) { snackbarData ->
|
snackbarState.SnackbarHost(
|
||||||
|
modifier =
|
||||||
|
Modifier.align(Alignment.BottomCenter)
|
||||||
|
.padding(
|
||||||
|
bottom =
|
||||||
|
if (LocalIsAndroidTV.current) 120.dp
|
||||||
|
else 80.dp
|
||||||
|
)
|
||||||
|
) { info ->
|
||||||
CustomSnackBar(
|
CustomSnackBar(
|
||||||
snackbarData.visuals.message,
|
message = info.message,
|
||||||
isRtl = false,
|
type = info.type,
|
||||||
|
onDismiss = { snackbarState.dismissCurrent() },
|
||||||
containerColor =
|
containerColor =
|
||||||
MaterialTheme.colorScheme.surfaceColorAtElevation(
|
MaterialTheme.colorScheme.surfaceColorAtElevation(
|
||||||
2.dp
|
2.dp
|
||||||
),
|
),
|
||||||
|
modifier =
|
||||||
|
Modifier.wrapContentHeight(align = Alignment.Top),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -269,7 +369,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
bottomBar = {
|
bottomBar = {
|
||||||
if (navState.showBottomItems) {
|
if (navState.showBottomItems) {
|
||||||
BottomNavbar(
|
BottomNavbar(
|
||||||
appState.isAutoTunnelActive,
|
uiState.isAutoTunnelActive,
|
||||||
currentTab,
|
currentTab,
|
||||||
onTabSelected = { tab ->
|
onTabSelected = { tab ->
|
||||||
navController.popUpTo(tab.startRoute)
|
navController.popUpTo(tab.startRoute)
|
||||||
@@ -331,39 +431,24 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
entry<Route.Tunnels> { TunnelsScreen() }
|
entry<Route.Tunnels> { TunnelsScreen() }
|
||||||
entry<Route.Sort> { SortScreen() }
|
entry<Route.Sort> { SortScreen() }
|
||||||
entry<Route.TunnelOptions> { key ->
|
entry<Route.TunnelSettings> { key ->
|
||||||
val viewModel =
|
val viewModel: TunnelViewModel =
|
||||||
hiltViewModel<
|
koinViewModel(
|
||||||
TunnelViewModel,
|
parameters = { parametersOf(key.id) }
|
||||||
TunnelViewModel.Factory,
|
|
||||||
>(
|
|
||||||
creationCallback = { factory ->
|
|
||||||
factory.create(key.id)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
TunnelOptionsScreen(viewModel)
|
TunnelSettingsScreen(viewModel)
|
||||||
}
|
}
|
||||||
entry<Route.SplitTunnel> { key ->
|
entry<Route.SplitTunnel> { key ->
|
||||||
val viewModel =
|
val viewModel: SplitTunnelViewModel =
|
||||||
hiltViewModel<
|
koinViewModel(
|
||||||
SplitTunnelViewModel,
|
parameters = { parametersOf(key.id) }
|
||||||
SplitTunnelViewModel.Factory,
|
|
||||||
>(
|
|
||||||
creationCallback = { factory ->
|
|
||||||
factory.create(key.id)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
SplitTunnelScreen(viewModel)
|
SplitTunnelScreen(viewModel)
|
||||||
}
|
}
|
||||||
entry<Route.Config> { key ->
|
entry<Route.Config> { key ->
|
||||||
val viewModel =
|
val viewModel: ConfigViewModel =
|
||||||
hiltViewModel<
|
koinViewModel(
|
||||||
ConfigViewModel,
|
parameters = { parametersOf(key.id) }
|
||||||
ConfigViewModel.Factory,
|
|
||||||
>(
|
|
||||||
creationCallback = { factory ->
|
|
||||||
factory.create(key.id)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
ConfigScreen(viewModel)
|
ConfigScreen(viewModel)
|
||||||
}
|
}
|
||||||
@@ -388,33 +473,23 @@ class MainActivity : AppCompatActivity() {
|
|||||||
AndroidIntegrationsScreen()
|
AndroidIntegrationsScreen()
|
||||||
}
|
}
|
||||||
entry<Route.Dns> { DnsSettingsScreen() }
|
entry<Route.Dns> { DnsSettingsScreen() }
|
||||||
entry<Route.TunnelGlobals> { key ->
|
|
||||||
TunnelGlobalsScreen(key.id)
|
|
||||||
}
|
|
||||||
entry<Route.ConfigGlobal> { key ->
|
entry<Route.ConfigGlobal> { key ->
|
||||||
val viewModel =
|
val viewModel: ConfigViewModel =
|
||||||
hiltViewModel<
|
koinViewModel(
|
||||||
ConfigViewModel,
|
parameters = { parametersOf(key.id) }
|
||||||
ConfigViewModel.Factory,
|
|
||||||
>(
|
|
||||||
creationCallback = { factory ->
|
|
||||||
factory.create(key.id)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
ConfigScreen(viewModel)
|
ConfigScreen(viewModel)
|
||||||
}
|
}
|
||||||
entry<Route.SplitTunnelGlobal> { key ->
|
entry<Route.SplitTunnelGlobal> { key ->
|
||||||
val viewModel =
|
val viewModel: SplitTunnelViewModel =
|
||||||
hiltViewModel<
|
koinViewModel(
|
||||||
SplitTunnelViewModel,
|
parameters = { parametersOf(key.id) }
|
||||||
SplitTunnelViewModel.Factory,
|
|
||||||
>(
|
|
||||||
creationCallback = { factory ->
|
|
||||||
factory.create(key.id)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
SplitTunnelScreen(viewModel)
|
SplitTunnelScreen(viewModel)
|
||||||
}
|
}
|
||||||
|
entry<Route.LockdownSettings> {
|
||||||
|
LockdownSettingsScreen()
|
||||||
|
}
|
||||||
entry<Route.ProxySettings> { ProxySettingsScreen() }
|
entry<Route.ProxySettings> { ProxySettingsScreen() }
|
||||||
entry<Route.Appearance> { AppearanceScreen() }
|
entry<Route.Appearance> { AppearanceScreen() }
|
||||||
entry<Route.Language> { LanguageScreen() }
|
entry<Route.Language> { LanguageScreen() }
|
||||||
@@ -441,8 +516,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
WireGuardAutoTunnel.setUiActive(true)
|
|
||||||
networkMonitor.checkPermissionsAndUpdateState()
|
networkMonitor.checkPermissionsAndUpdateState()
|
||||||
|
WireGuardAutoTunnel.setUiActive(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
@@ -452,6 +527,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
fun performBackup() =
|
fun performBackup() =
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
|
// reset active tuns before backup to prevent trying to start them without permission on
|
||||||
|
// restore
|
||||||
|
tunnelRepository.resetActiveTunnels()
|
||||||
roomBackup
|
roomBackup
|
||||||
.database(appDatabase)
|
.database(appDatabase)
|
||||||
.backupLocation(RoomBackup.BACKUP_FILE_LOCATION_CUSTOM_DIALOG)
|
.backupLocation(RoomBackup.BACKUP_FILE_LOCATION_CUSTOM_DIALOG)
|
||||||
|
|||||||
@@ -2,85 +2,87 @@ package com.zaneschepke.wireguardautotunnel
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.os.StrictMode
|
import android.os.StrictMode
|
||||||
import android.os.StrictMode.ThreadPolicy
|
|
||||||
import androidx.hilt.work.HiltWorkerFactory
|
|
||||||
import androidx.work.Configuration
|
|
||||||
import com.zaneschepke.logcatter.LogReader
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationMonitor
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.di.Dispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.core.worker.ServiceWorker
|
import com.zaneschepke.wireguardautotunnel.di.Scope
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.appModule
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.databaseModule
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
import com.zaneschepke.wireguardautotunnel.di.dispatchersModule
|
||||||
|
import com.zaneschepke.wireguardautotunnel.di.networkModule
|
||||||
|
import com.zaneschepke.wireguardautotunnel.di.tunnelModule
|
||||||
|
import com.zaneschepke.wireguardautotunnel.di.workerModule
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.MonitoringSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.MonitoringSettingsRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.cancel
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.android.ext.koin.androidLogger
|
||||||
|
import org.koin.androidx.workmanager.koin.workManagerFactory
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.context.GlobalContext.startKoin
|
||||||
|
import org.koin.core.lazyModules
|
||||||
|
import org.koin.core.option.viewModelScopeFactory
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@HiltAndroidApp
|
class WireGuardAutoTunnel : Application(), KoinComponent {
|
||||||
class WireGuardAutoTunnel : Application(), Configuration.Provider {
|
|
||||||
|
|
||||||
@Inject lateinit var workerFactory: HiltWorkerFactory
|
private val applicationScope: CoroutineScope by inject(named(Scope.APPLICATION))
|
||||||
|
private val ioDispatcher: CoroutineDispatcher by inject(named(Dispatcher.IO))
|
||||||
|
private val logReader: LogReader by inject()
|
||||||
|
|
||||||
override val workManagerConfiguration: Configuration
|
private val monitoringRepository: MonitoringSettingsRepository by inject()
|
||||||
get() = Configuration.Builder().setWorkerFactory(workerFactory).build()
|
private val notificationMonitor: NotificationMonitor by inject()
|
||||||
|
|
||||||
@Inject @ApplicationScope lateinit var applicationScope: CoroutineScope
|
|
||||||
|
|
||||||
@Inject lateinit var logReader: LogReader
|
|
||||||
|
|
||||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
|
||||||
|
|
||||||
@Inject lateinit var monitoringRepository: MonitoringSettingsRepository
|
|
||||||
|
|
||||||
@Inject lateinit var notificationMonitor: NotificationMonitor
|
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
startKoin {
|
||||||
|
androidContext(this@WireGuardAutoTunnel)
|
||||||
|
if (BuildConfig.DEBUG) androidLogger()
|
||||||
|
workManagerFactory()
|
||||||
|
modules(dispatchersModule, appModule, databaseModule, tunnelModule, workerModule)
|
||||||
|
options(viewModelScopeFactory())
|
||||||
|
lazyModules(networkModule)
|
||||||
|
}
|
||||||
instance = this
|
instance = this
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Timber.plant(Timber.DebugTree())
|
Timber.plant(Timber.DebugTree())
|
||||||
StrictMode.setThreadPolicy(
|
StrictMode.setThreadPolicy(
|
||||||
ThreadPolicy.Builder()
|
StrictMode.ThreadPolicy.Builder()
|
||||||
.detectDiskReads()
|
.detectAll()
|
||||||
.detectDiskWrites()
|
|
||||||
.detectNetwork()
|
|
||||||
.penaltyLog()
|
.penaltyLog()
|
||||||
|
.penaltyFlashScreen()
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
|
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build())
|
||||||
} else {
|
} else {
|
||||||
Timber.plant(ReleaseTree())
|
Timber.plant(ReleaseTree())
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationScope.launch(ioDispatcher) {
|
applicationScope.launch(ioDispatcher) {
|
||||||
launch {
|
launch {
|
||||||
val monitoringSettings = monitoringRepository.getMonitoringSettings()
|
monitoringRepository.flow
|
||||||
if (monitoringSettings.isLocalLogsEnabled) logReader.start()
|
.distinctUntilChangedBy { it.isLocalLogsEnabled }
|
||||||
|
.collect { settings ->
|
||||||
|
if (settings.isLocalLogsEnabled) {
|
||||||
|
logReader.start()
|
||||||
|
} else {
|
||||||
|
logReader.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
launch { notificationMonitor.handleApplicationNotifications() }
|
launch { notificationMonitor.handleApplicationNotifications() }
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceWorker.start(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTerminate() {
|
|
||||||
applicationScope.cancel()
|
|
||||||
tunnelManager.setBackendMode(BackendMode.Inactive)
|
|
||||||
super.onTerminate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val _uiActive = MutableStateFlow(false)
|
private val _uiActive = MutableStateFlow(false)
|
||||||
|
|
||||||
val uiActive: StateFlow<Boolean>
|
val uiActive: StateFlow<Boolean>
|
||||||
|
|||||||
+8
-10
@@ -4,21 +4,19 @@ import android.content.BroadcastReceiver
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
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.Scope
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
|
|
||||||
@AndroidEntryPoint
|
class KernelReceiver : BroadcastReceiver(), KoinComponent {
|
||||||
class KernelReceiver : BroadcastReceiver() {
|
|
||||||
|
|
||||||
@Inject @ApplicationScope lateinit var applicationScope: CoroutineScope
|
private val applicationScope: CoroutineScope by inject(named(Scope.APPLICATION))
|
||||||
|
private val tunnelRepository: TunnelRepository by inject()
|
||||||
@Inject lateinit var tunnelRepository: TunnelRepository
|
private val tunnelManager: TunnelManager by inject()
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
val action = intent.action ?: return
|
val action = intent.action ?: return
|
||||||
|
|||||||
+9
-13
@@ -5,25 +5,21 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
||||||
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.Scope
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.get
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
|
|
||||||
@AndroidEntryPoint
|
class NotificationActionReceiver : BroadcastReceiver(), KoinComponent {
|
||||||
class NotificationActionReceiver : BroadcastReceiver() {
|
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
private val tunnelManager: TunnelManager by inject()
|
||||||
|
private val autoTunnelRepository: AutoTunnelSettingsRepository by inject()
|
||||||
@Inject lateinit var tunnelRepository: TunnelRepository
|
private val applicationScope: CoroutineScope = get(named(Scope.APPLICATION))
|
||||||
|
|
||||||
@Inject lateinit var autoTunnelRepository: AutoTunnelSettingsRepository
|
|
||||||
|
|
||||||
@Inject @ApplicationScope lateinit var applicationScope: CoroutineScope
|
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
applicationScope.launch {
|
applicationScope.launch {
|
||||||
|
|||||||
+10
-12
@@ -4,27 +4,25 @@ import android.content.BroadcastReceiver
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
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.Scope
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
class RemoteControlReceiver : BroadcastReceiver(), KoinComponent {
|
||||||
class RemoteControlReceiver : BroadcastReceiver() {
|
|
||||||
|
|
||||||
@Inject @ApplicationScope lateinit var applicationScope: CoroutineScope
|
private val applicationScope: CoroutineScope by inject(named(Scope.APPLICATION))
|
||||||
|
private val settingsRepository: GeneralSettingRepository by inject()
|
||||||
@Inject lateinit var settingsRepository: GeneralSettingRepository
|
private val tunnelsRepository: TunnelRepository by inject()
|
||||||
@Inject lateinit var tunnelsRepository: TunnelRepository
|
private val autoTunnelSettingsRepository: AutoTunnelSettingsRepository by inject()
|
||||||
@Inject lateinit var autoTunnelSettingsRepository: AutoTunnelSettingsRepository
|
private val tunnelManager: TunnelManager by inject()
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
|
||||||
|
|
||||||
enum class Action(private val suffix: String) {
|
enum class Action(private val suffix: String) {
|
||||||
START_TUNNEL("START_TUNNEL"),
|
START_TUNNEL("START_TUNNEL"),
|
||||||
|
|||||||
+14
-8
@@ -5,21 +5,25 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.zaneschepke.logcatter.LogReader
|
import com.zaneschepke.logcatter.LogReader
|
||||||
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.Scope
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.get
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
class RestartReceiver : BroadcastReceiver(), KoinComponent {
|
||||||
class RestartReceiver : BroadcastReceiver() {
|
|
||||||
|
|
||||||
@Inject @ApplicationScope lateinit var applicationScope: CoroutineScope
|
private val applicationScope: CoroutineScope = get(named(Scope.APPLICATION))
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
private val tunnelManager: TunnelManager by inject()
|
||||||
|
|
||||||
@Inject lateinit var logReader: LogReader
|
private val appStateRepository: AppStateRepository by inject()
|
||||||
|
|
||||||
|
private val logReader: LogReader by inject()
|
||||||
|
|
||||||
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}")
|
||||||
@@ -31,8 +35,10 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
tunnelManager.handleReboot()
|
tunnelManager.handleReboot()
|
||||||
}
|
}
|
||||||
Intent.ACTION_MY_PACKAGE_REPLACED -> {
|
Intent.ACTION_MY_PACKAGE_REPLACED -> {
|
||||||
|
Timber.i("Restoring state on package upgrade")
|
||||||
tunnelManager.handleRestore()
|
tunnelManager.handleRestore()
|
||||||
logReader.deleteAndClearLogs()
|
logReader.deleteAndClearLogs()
|
||||||
|
appStateRepository.setShouldShowDonationSnackbar(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -4,14 +4,11 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
import jakarta.inject.Inject
|
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class NotificationMonitor
|
class NotificationMonitor(
|
||||||
@Inject
|
|
||||||
constructor(
|
|
||||||
private val tunnelManager: TunnelManager,
|
private val tunnelManager: TunnelManager,
|
||||||
private val notificationManager: NotificationManager,
|
private val notificationManager: NotificationManager,
|
||||||
) {
|
) {
|
||||||
@@ -32,7 +29,7 @@ constructor(
|
|||||||
description =
|
description =
|
||||||
StringValue.StringResource(
|
StringValue.StringResource(
|
||||||
R.string.tunnel_error_template,
|
R.string.tunnel_error_template,
|
||||||
error.toStringRes(),
|
error.stringRes,
|
||||||
),
|
),
|
||||||
groupKey = NotificationManager.VPN_GROUP_KEY,
|
groupKey = NotificationManager.VPN_GROUP_KEY,
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-4
@@ -16,11 +16,8 @@ import com.zaneschepke.wireguardautotunnel.core.broadcast.NotificationActionRece
|
|||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager.Companion.EXTRA_ID
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager.Companion.EXTRA_ID
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class WireGuardNotification @Inject constructor(@ApplicationContext override val context: Context) :
|
class WireGuardNotification(override val context: Context) : NotificationManager {
|
||||||
NotificationManager {
|
|
||||||
|
|
||||||
enum class NotificationChannels {
|
enum class NotificationChannels {
|
||||||
VPN,
|
VPN,
|
||||||
|
|||||||
+9
-13
@@ -10,35 +10,31 @@ 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.Dispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
abstract class BaseTunnelForegroundService : LifecycleService(), TunnelService {
|
abstract class BaseTunnelForegroundService : LifecycleService(), TunnelService {
|
||||||
|
|
||||||
@Inject lateinit var notificationManager: NotificationManager
|
private val notificationManager: NotificationManager by inject()
|
||||||
|
|
||||||
@Inject lateinit var serviceManager: ServiceManager
|
private val serviceManager: ServiceManager by inject()
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
private val tunnelManager: TunnelManager by inject()
|
||||||
|
|
||||||
@Inject lateinit var tunnelMonitor: TunnelMonitor
|
private val ioDispatcher: CoroutineDispatcher by inject(named(Dispatcher.IO))
|
||||||
|
|
||||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
private val settingsRepository: GeneralSettingRepository by inject()
|
||||||
|
|
||||||
@Inject lateinit var settingsRepository: GeneralSettingRepository
|
private val tunnelsRepository: TunnelRepository by inject()
|
||||||
|
|
||||||
@Inject lateinit var tunnelsRepository: TunnelRepository
|
|
||||||
|
|
||||||
protected abstract val fgsType: Int
|
protected abstract val fgsType: Int
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.service
|
package com.zaneschepke.wireguardautotunnel.core.service
|
||||||
|
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
class LocalBinder(val service: TunnelService) : Binder()
|
class LocalBinder(service: TunnelService) : Binder() {
|
||||||
|
private val serviceRef = WeakReference(service)
|
||||||
|
|
||||||
|
val service: TunnelService?
|
||||||
|
get() = serviceRef.get()
|
||||||
|
}
|
||||||
|
|||||||
+33
-21
@@ -8,27 +8,31 @@ 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.data.model.AppMode
|
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
||||||
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
|
||||||
import jakarta.inject.Inject
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class ServiceManager
|
class ServiceManager(
|
||||||
@Inject
|
|
||||||
constructor(
|
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
ioDispatcher: CoroutineDispatcher,
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
applicationScope: CoroutineScope,
|
||||||
private val mainDispatcher: CoroutineDispatcher,
|
private val mainDispatcher: CoroutineDispatcher,
|
||||||
private val autoTunnelSettingsRepository: AutoTunnelSettingsRepository,
|
private val autoTunnelSettingsRepository: AutoTunnelSettingsRepository,
|
||||||
) {
|
) {
|
||||||
@@ -137,17 +141,25 @@ constructor(
|
|||||||
|
|
||||||
suspend fun startTunnelService(appMode: AppMode) =
|
suspend fun startTunnelService(appMode: AppMode) =
|
||||||
tunnelMutex.withLock {
|
tunnelMutex.withLock {
|
||||||
if (_tunnelService.value != null) return@withLock
|
if (_tunnelService.value != null) {
|
||||||
val serviceClass =
|
Timber.d("Service already exists, waiting for disconnect")
|
||||||
when (appMode) {
|
withTimeoutOrNull(2000L) { _tunnelService.first { it == null } }
|
||||||
AppMode.VPN,
|
?: Timber.w("Timeout waiting for existing service to disconnect")
|
||||||
AppMode.LOCK_DOWN -> VpnForegroundService::class.java
|
}
|
||||||
AppMode.KERNEL,
|
if (_tunnelService.value == null) {
|
||||||
AppMode.PROXY -> TunnelForegroundService::class.java
|
val serviceClass =
|
||||||
}
|
when (appMode) {
|
||||||
val intent = Intent(context, serviceClass)
|
AppMode.VPN,
|
||||||
context.startForegroundService(intent)
|
AppMode.LOCK_DOWN -> VpnForegroundService::class.java
|
||||||
context.bindService(intent, tunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
AppMode.KERNEL,
|
||||||
|
AppMode.PROXY -> TunnelForegroundService::class.java
|
||||||
|
}
|
||||||
|
val intent = Intent(context, serviceClass)
|
||||||
|
context.startForegroundService(intent)
|
||||||
|
context.bindService(intent, tunnelServiceConnection, Context.BIND_AUTO_CREATE)
|
||||||
|
} else {
|
||||||
|
Timber.e("Service still not null after timeout")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun stopTunnelService() =
|
suspend fun stopTunnelService() =
|
||||||
@@ -157,7 +169,7 @@ constructor(
|
|||||||
try {
|
try {
|
||||||
context.unbindService(tunnelServiceConnection)
|
context.unbindService(tunnelServiceConnection)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Failed to stop Tunnel Service")
|
Timber.e(e, "Failed to unbind Tunnel Service")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-2
@@ -1,8 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.service
|
package com.zaneschepke.wireguardautotunnel.core.service
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class TunnelForegroundService(override val fgsType: Int = Constants.SPECIAL_USE_SERVICE_TYPE_ID) :
|
class TunnelForegroundService(override val fgsType: Int = Constants.SPECIAL_USE_SERVICE_TYPE_ID) :
|
||||||
BaseTunnelForegroundService()
|
BaseTunnelForegroundService()
|
||||||
|
|||||||
-2
@@ -1,8 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.service
|
package com.zaneschepke.wireguardautotunnel.core.service
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class VpnForegroundService(override val fgsType: Int = Constants.SYSTEM_EXEMPT_SERVICE_TYPE_ID) :
|
class VpnForegroundService(override val fgsType: Int = Constants.SYSTEM_EXEMPT_SERVICE_TYPE_ID) :
|
||||||
BaseTunnelForegroundService()
|
BaseTunnelForegroundService()
|
||||||
|
|||||||
+57
-29
@@ -15,7 +15,7 @@ import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotificati
|
|||||||
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.data.model.AppMode
|
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.Dispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.AutoTunnelSettings
|
import com.zaneschepke.wireguardautotunnel.domain.model.AutoTunnelSettings
|
||||||
@@ -24,35 +24,49 @@ import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsR
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
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.toDomain
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.to
|
import com.zaneschepke.wireguardautotunnel.util.extensions.to
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toMillis
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toMillis
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import java.lang.ref.WeakReference
|
||||||
import javax.inject.Inject
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import javax.inject.Provider
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.FlowPreview
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.debounce
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.merge
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class AutoTunnelService : LifecycleService() {
|
class AutoTunnelService : LifecycleService() {
|
||||||
|
|
||||||
@Inject lateinit var networkMonitor: NetworkMonitor
|
private val networkMonitor: NetworkMonitor by inject()
|
||||||
|
|
||||||
@Inject lateinit var notificationManager: NotificationManager
|
private val notificationManager: NotificationManager by inject()
|
||||||
|
|
||||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
private val ioDispatcher: CoroutineDispatcher by inject(named(Dispatcher.IO))
|
||||||
|
|
||||||
@Inject lateinit var serviceManager: ServiceManager
|
private val serviceManager: ServiceManager by inject()
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
private val tunnelManager: TunnelManager by inject()
|
||||||
|
|
||||||
@Inject lateinit var autoTunnelRepository: Provider<AutoTunnelSettingsRepository>
|
private val autoTunnelRepository: AutoTunnelSettingsRepository by inject()
|
||||||
@Inject lateinit var settingsRepository: GeneralSettingRepository
|
private val settingsRepository: GeneralSettingRepository by inject()
|
||||||
@Inject lateinit var tunnelsRepository: TunnelRepository
|
private val tunnelsRepository: TunnelRepository by inject()
|
||||||
|
|
||||||
private val defaultState = AutoTunnelState()
|
private val defaultState = AutoTunnelState()
|
||||||
|
|
||||||
@@ -60,7 +74,16 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
|
|
||||||
private val autoTunnelStateFlow = MutableStateFlow(defaultState)
|
private val autoTunnelStateFlow = MutableStateFlow(defaultState)
|
||||||
|
|
||||||
class LocalBinder(val service: AutoTunnelService) : Binder()
|
private var autoTunnelJob: Job? = null
|
||||||
|
private var permissionsJob: Job? = null
|
||||||
|
private var autoTunnelFailoverJob: Job? = null
|
||||||
|
|
||||||
|
class LocalBinder(service: AutoTunnelService) : Binder() {
|
||||||
|
private val serviceRef = WeakReference(service)
|
||||||
|
|
||||||
|
val service: AutoTunnelService?
|
||||||
|
get() = serviceRef.get()
|
||||||
|
}
|
||||||
|
|
||||||
private val binder = LocalBinder(this)
|
private val binder = LocalBinder(this)
|
||||||
|
|
||||||
@@ -83,8 +106,10 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
launchWatcherNotification()
|
launchWatcherNotification()
|
||||||
startAutoTunnelStateJob()
|
autoTunnelJob?.cancel()
|
||||||
startLocationPermissionsNotificationJob()
|
autoTunnelJob = startAutoTunnelStateJob()
|
||||||
|
permissionsJob?.cancel()
|
||||||
|
permissionsJob = startLocationPermissionsNotificationJob()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
@@ -123,12 +148,12 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startAutoTunnelStateJob() =
|
private fun startAutoTunnelStateJob(): Job =
|
||||||
lifecycleScope.launch(ioDispatcher) {
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
val networkFlow =
|
val networkFlow =
|
||||||
debouncedConnectivityStateFlow
|
debouncedConnectivityStateFlow
|
||||||
.flowOn(ioDispatcher)
|
.flowOn(ioDispatcher)
|
||||||
.map(NetworkState::from)
|
.map { it.toDomain() }
|
||||||
.map(::NetworkChange)
|
.map(::NetworkChange)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
@@ -201,6 +226,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
|
|
||||||
handleAutoTunnelEvent(autoTunnelStateFlow.value.determineAutoTunnelEvent(change))
|
handleAutoTunnelEvent(autoTunnelStateFlow.value.determineAutoTunnelEvent(change))
|
||||||
|
|
||||||
|
// re-evaluate network state after a short duration to prevent missed state changes
|
||||||
reevaluationJob = launch {
|
reevaluationJob = launch {
|
||||||
val snapshotNetwork = autoTunnelStateFlow.value.networkState
|
val snapshotNetwork = autoTunnelStateFlow.value.networkState
|
||||||
delay(REEVALUATE_CHECK_DELAY)
|
delay(REEVALUATE_CHECK_DELAY)
|
||||||
@@ -222,8 +248,8 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
private fun combineSettings(): Flow<Triple<AppMode, AutoTunnelSettings, List<TunnelConfig>>> {
|
private fun combineSettings(): Flow<Triple<AppMode, AutoTunnelSettings, List<TunnelConfig>>> {
|
||||||
return combine(
|
return combine(
|
||||||
settingsRepository.flow.map { it.appMode }.distinctUntilChanged(),
|
settingsRepository.flow.map { it.appMode }.distinctUntilChanged(),
|
||||||
autoTunnelRepository.get().flow,
|
autoTunnelRepository.flow,
|
||||||
tunnelsRepository.flow.map { tunnels ->
|
tunnelsRepository.userTunnelsFlow.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
|
||||||
tunnels.map { it.copy(isActive = false) }
|
tunnels.map { it.copy(isActive = false) }
|
||||||
@@ -265,8 +291,8 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
.map {
|
.map {
|
||||||
NetworkPermissionState(
|
NetworkPermissionState(
|
||||||
it.settings.wifiDetectionMethod.to(),
|
it.settings.wifiDetectionMethod.to(),
|
||||||
it.networkState.locationServicesEnabled == true,
|
it.networkState.locationServicesEnabled,
|
||||||
it.networkState.locationPermissionGranted == true,
|
it.networkState.locationPermissionGranted,
|
||||||
(it.tunnels.any { tunnel -> tunnel.tunnelNetworks.isNotEmpty() } ||
|
(it.tunnels.any { tunnel -> tunnel.tunnelNetworks.isNotEmpty() } ||
|
||||||
it.settings.trustedNetworkSSIDs.isNotEmpty()),
|
it.settings.trustedNetworkSSIDs.isNotEmpty()),
|
||||||
)
|
)
|
||||||
@@ -339,7 +365,10 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
) {
|
) {
|
||||||
is AutoTunnelEvent.Start ->
|
is AutoTunnelEvent.Start ->
|
||||||
(event.tunnelConfig ?: tunnelsRepository.getDefaultTunnel())?.let {
|
(event.tunnelConfig ?: tunnelsRepository.getDefaultTunnel())?.let {
|
||||||
tunnelManager.startTunnel(it)
|
tunnelManager.startTunnel(it).onFailure { e ->
|
||||||
|
Timber.e(e, "Auto-tunnel start failed for ${it.name}")
|
||||||
|
// TODO notify or retry
|
||||||
|
}
|
||||||
}
|
}
|
||||||
is AutoTunnelEvent.Stop -> tunnelManager.stopActiveTunnels()
|
is AutoTunnelEvent.Stop -> tunnelManager.stopActiveTunnels()
|
||||||
AutoTunnelEvent.DoNothing -> Timber.i("Auto-tunneling: nothing to do")
|
AutoTunnelEvent.DoNothing -> Timber.i("Auto-tunneling: nothing to do")
|
||||||
@@ -347,11 +376,10 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restart network flow on debounce changes
|
||||||
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
|
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
|
||||||
private val debouncedConnectivityStateFlow: Flow<ConnectivityState> by lazy {
|
private val debouncedConnectivityStateFlow: Flow<ConnectivityState> by lazy {
|
||||||
autoTunnelRepository
|
autoTunnelRepository.flow
|
||||||
.get()
|
|
||||||
.flow
|
|
||||||
.map { it.debounceDelaySeconds.toMillis() }
|
.map { it.debounceDelaySeconds.toMillis() }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.flatMapLatest { debounceMillis ->
|
.flatMapLatest { debounceMillis ->
|
||||||
|
|||||||
+38
-36
@@ -4,25 +4,22 @@ import android.content.Intent
|
|||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.service.quicksettings.Tile
|
import android.service.quicksettings.Tile
|
||||||
import android.service.quicksettings.TileService
|
import android.service.quicksettings.TileService
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.*
|
||||||
import androidx.lifecycle.LifecycleOwner
|
|
||||||
import androidx.lifecycle.LifecycleRegistry
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import kotlin.concurrent.atomics.AtomicBoolean
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import kotlin.concurrent.atomics.ExperimentalAtomicApi
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
||||||
|
|
||||||
@Inject lateinit var autoTunnelSettingsRepository: AutoTunnelSettingsRepository
|
private val autoTunnelSettingsRepository: AutoTunnelSettingsRepository by inject()
|
||||||
@Inject lateinit var tunnelsRepository: TunnelRepository
|
|
||||||
|
|
||||||
@Inject lateinit var serviceManager: ServiceManager
|
private val serviceManager: ServiceManager by inject()
|
||||||
|
|
||||||
|
@OptIn(ExperimentalAtomicApi::class) val isCollecting = AtomicBoolean(false)
|
||||||
|
|
||||||
private val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this)
|
private val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this)
|
||||||
|
|
||||||
@@ -36,25 +33,37 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartListening() {
|
override fun onTileAdded() {
|
||||||
super.onStartListening()
|
super.onTileAdded()
|
||||||
|
initTileState()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStopListening() {
|
||||||
|
super.onStopListening()
|
||||||
|
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalAtomicApi::class)
|
||||||
|
private fun initTileState() {
|
||||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
Timber.d("Start listening called for auto tunnel tile")
|
Timber.d("Start listening called for auto tunnel tile")
|
||||||
lifecycleScope.launch {
|
if (isCollecting.compareAndSet(expectedValue = false, newValue = true)) {
|
||||||
serviceManager.autoTunnelService.collect {
|
lifecycleScope.launch {
|
||||||
if (it != null) return@collect setActive()
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
setInactive()
|
serviceManager.autoTunnelService.collect {
|
||||||
}
|
if (it != null) return@collect setActive()
|
||||||
}
|
setInactive()
|
||||||
lifecycleScope.launch {
|
}
|
||||||
tunnelsRepository.flow.collect {
|
|
||||||
if (it.isEmpty()) {
|
|
||||||
setUnavailable()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStartListening() {
|
||||||
|
super.onStartListening()
|
||||||
|
initTileState()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onClick() {
|
override fun onClick() {
|
||||||
super.onClick()
|
super.onClick()
|
||||||
unlockAndRun {
|
unlockAndRun {
|
||||||
@@ -71,23 +80,16 @@ class AutoTunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setActive() {
|
private fun setActive() {
|
||||||
runCatching {
|
qsTile?.let {
|
||||||
qsTile.state = Tile.STATE_ACTIVE
|
it.state = Tile.STATE_ACTIVE
|
||||||
qsTile.updateTile()
|
it.updateTile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setInactive() {
|
private fun setInactive() {
|
||||||
runCatching {
|
qsTile?.let {
|
||||||
qsTile.state = Tile.STATE_INACTIVE
|
it.state = Tile.STATE_INACTIVE
|
||||||
qsTile.updateTile()
|
it.updateTile()
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setUnavailable() {
|
|
||||||
runCatching {
|
|
||||||
qsTile.state = Tile.STATE_UNAVAILABLE
|
|
||||||
qsTile.updateTile()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+65
-36
@@ -9,29 +9,35 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.LifecycleRegistry
|
import androidx.lifecycle.LifecycleRegistry
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
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.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import kotlin.concurrent.atomics.AtomicBoolean
|
||||||
import javax.inject.Inject
|
import kotlin.concurrent.atomics.ExperimentalAtomicApi
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class TunnelControlTile : TileService(), LifecycleOwner {
|
class TunnelControlTile : TileService(), LifecycleOwner {
|
||||||
|
|
||||||
@Inject lateinit var tunnelsRepository: TunnelRepository
|
private val tunnelsRepository: TunnelRepository by inject()
|
||||||
|
|
||||||
@Inject lateinit var serviceManager: ServiceManager
|
private val serviceManager: ServiceManager by inject()
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
private val tunnelManager: TunnelManager by inject()
|
||||||
|
|
||||||
|
@OptIn(ExperimentalAtomicApi::class) val isCollecting = AtomicBoolean(false)
|
||||||
|
|
||||||
|
private val startLock = Mutex()
|
||||||
|
|
||||||
private val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this)
|
private val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this)
|
||||||
|
|
||||||
private var isCollecting = false
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
||||||
@@ -42,13 +48,34 @@ class TunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartListening() {
|
override fun onTileAdded() {
|
||||||
super.onStartListening()
|
super.onTileAdded()
|
||||||
|
initTileState()
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalAtomicApi::class)
|
||||||
|
private fun initTileState() {
|
||||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
Timber.d("Start listening called for tunnel tile")
|
Timber.d("Start listening called for tunnel tile")
|
||||||
if (isCollecting) return
|
if (isCollecting.compareAndSet(expectedValue = false, newValue = true)) {
|
||||||
isCollecting = true
|
lifecycleScope.launch {
|
||||||
lifecycleScope.launch { tunnelManager.activeTunnels.collect { updateTileState() } }
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
|
tunnelManager.activeTunnels
|
||||||
|
.distinctUntilChangedBy { it.size }
|
||||||
|
.collect { updateTileState() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartListening() {
|
||||||
|
super.onStartListening()
|
||||||
|
initTileState()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStopListening() {
|
||||||
|
super.onStopListening()
|
||||||
|
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun updateTileState() {
|
private suspend fun updateTileState() {
|
||||||
@@ -76,6 +103,7 @@ class TunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
else -> updateTileForLastActiveTunnels()
|
else -> updateTileForLastActiveTunnels()
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e, "Failed to update tunnel state")
|
||||||
setUnavailable()
|
setUnavailable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,14 +138,16 @@ class TunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
super.onClick()
|
super.onClick()
|
||||||
unlockAndRun {
|
unlockAndRun {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
if (tunnelManager.activeTunnels.value.isNotEmpty())
|
startLock.withLock {
|
||||||
return@launch tunnelManager.stopActiveTunnels()
|
if (tunnelManager.activeTunnels.value.isNotEmpty())
|
||||||
val lastActive = WireGuardAutoTunnel.getLastActiveTunnels()
|
return@launch tunnelManager.stopActiveTunnels()
|
||||||
if (lastActive.isEmpty()) {
|
val lastActive = WireGuardAutoTunnel.getLastActiveTunnels()
|
||||||
tunnelsRepository.getStartTunnel()?.let { tunnelManager.startTunnel(it) }
|
if (lastActive.isEmpty()) {
|
||||||
} else {
|
tunnelsRepository.getStartTunnel()?.let { tunnelManager.startTunnel(it) }
|
||||||
lastActive.forEach { id ->
|
} else {
|
||||||
tunnelsRepository.getById(id)?.let { tunnelManager.startTunnel(it) }
|
lastActive.forEach { id ->
|
||||||
|
tunnelsRepository.getById(id)?.let { tunnelManager.startTunnel(it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,37 +155,36 @@ class TunnelControlTile : TileService(), LifecycleOwner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setActive() {
|
private fun setActive() {
|
||||||
runCatching {
|
qsTile?.let {
|
||||||
qsTile.state = Tile.STATE_ACTIVE
|
it.state = Tile.STATE_ACTIVE
|
||||||
qsTile.updateTile()
|
it.updateTile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setInactive() {
|
private fun setInactive() {
|
||||||
runCatching {
|
qsTile?.let {
|
||||||
qsTile.state = Tile.STATE_INACTIVE
|
it.state = Tile.STATE_INACTIVE
|
||||||
qsTile.updateTile()
|
it.updateTile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setUnavailable() {
|
private fun setUnavailable() {
|
||||||
runCatching {
|
qsTile?.let {
|
||||||
qsTile.state = Tile.STATE_UNAVAILABLE
|
it.state = Tile.STATE_UNAVAILABLE
|
||||||
setTileDescription("")
|
setTileDescription("")
|
||||||
qsTile.updateTile()
|
it.updateTile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setTileDescription(description: String) {
|
private fun setTileDescription(description: String) {
|
||||||
runCatching {
|
qsTile?.let {
|
||||||
if (qsTile == null) return@runCatching
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
qsTile.subtitle = description
|
it.subtitle = description
|
||||||
qsTile.stateDescription = description
|
it.stateDescription = description
|
||||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
qsTile.subtitle = description
|
it.subtitle = description
|
||||||
}
|
}
|
||||||
qsTile.updateTile()
|
it.updateTile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -6,13 +6,12 @@ import androidx.core.content.pm.ShortcutInfoCompat
|
|||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
import androidx.core.content.pm.ShortcutManagerCompat
|
||||||
import androidx.core.graphics.drawable.IconCompat
|
import androidx.core.graphics.drawable.IconCompat
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class DynamicShortcutManager(
|
class DynamicShortcutManager(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : ShortcutManager {
|
) : ShortcutManager {
|
||||||
override suspend fun addShortcuts() {
|
override suspend fun addShortcuts() {
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
|
|||||||
+8
-11
@@ -5,26 +5,23 @@ import androidx.activity.ComponentActivity
|
|||||||
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelProvider
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelProvider
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.Scope
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class ShortcutsActivity : ComponentActivity() {
|
class ShortcutsActivity : ComponentActivity() {
|
||||||
|
|
||||||
@Inject lateinit var settingsRepository: GeneralSettingRepository
|
private val settingsRepository: GeneralSettingRepository by inject()
|
||||||
@Inject lateinit var autoTunnelSettingsRepository: AutoTunnelSettingsRepository
|
private val autoTunnelSettingsRepository: AutoTunnelSettingsRepository by inject()
|
||||||
@Inject lateinit var tunnelsRepository: TunnelRepository
|
private val tunnelsRepository: TunnelRepository by inject()
|
||||||
|
private val tunnelManager: TunnelManager by inject()
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
private val applicationScope: CoroutineScope by inject(named(Scope.APPLICATION))
|
||||||
|
|
||||||
@Inject @ApplicationScope lateinit var applicationScope: CoroutineScope
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|||||||
@@ -1,158 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.LogHealthState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
|
||||||
import kotlin.coroutines.cancellation.CancellationException
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import kotlinx.coroutines.flow.*
|
|
||||||
import kotlinx.coroutines.sync.Mutex
|
|
||||||
import kotlinx.coroutines.sync.withLock
|
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
abstract class BaseTunnel(
|
|
||||||
@ApplicationScope protected val applicationScope: CoroutineScope,
|
|
||||||
@IoDispatcher protected val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : TunnelProvider {
|
|
||||||
|
|
||||||
protected val errors = MutableSharedFlow<Pair<String, BackendCoreException>>()
|
|
||||||
override val errorEvents = errors.asSharedFlow()
|
|
||||||
|
|
||||||
private val _messageEvents = MutableSharedFlow<Pair<String, BackendMessage>>()
|
|
||||||
override val messageEvents = _messageEvents.asSharedFlow()
|
|
||||||
|
|
||||||
protected val activeTuns = MutableStateFlow<Map<Int, TunnelState>>(emptyMap())
|
|
||||||
override val activeTunnels = activeTuns.asStateFlow()
|
|
||||||
|
|
||||||
protected val tunJobs = ConcurrentHashMap<Int, Job>()
|
|
||||||
private val tunMutex = Mutex()
|
|
||||||
private val tunStatusMutex = Mutex()
|
|
||||||
|
|
||||||
abstract fun tunnelStateFlow(tunnelConfig: TunnelConfig): Flow<TunnelStatus>
|
|
||||||
|
|
||||||
abstract override fun setBackendMode(backendMode: BackendMode)
|
|
||||||
|
|
||||||
abstract override fun getBackendMode(): BackendMode
|
|
||||||
|
|
||||||
abstract override suspend fun forceStopTunnel(tunnelId: Int)
|
|
||||||
|
|
||||||
abstract override fun handleDnsReresolve(tunnelConfig: TunnelConfig): Boolean
|
|
||||||
|
|
||||||
abstract override fun getStatistics(tunnelId: Int): TunnelStatistics?
|
|
||||||
|
|
||||||
override suspend fun updateTunnelStatus(
|
|
||||||
tunnelId: Int,
|
|
||||||
status: TunnelStatus?,
|
|
||||||
stats: TunnelStatistics?,
|
|
||||||
pingStates: Map<String, PingState>?,
|
|
||||||
logHealthState: LogHealthState?,
|
|
||||||
) {
|
|
||||||
tunStatusMutex.withLock {
|
|
||||||
activeTuns.update { currentTuns ->
|
|
||||||
if (!currentTuns.containsKey(tunnelId) && status != TunnelStatus.Starting) {
|
|
||||||
Timber.d("Ignoring update for inactive tunnel $tunnelId")
|
|
||||||
return@update currentTuns
|
|
||||||
}
|
|
||||||
val existingState = currentTuns[tunnelId] ?: TunnelState()
|
|
||||||
val newStatus = status ?: existingState.status
|
|
||||||
if (newStatus == TunnelStatus.Down) {
|
|
||||||
Timber.d("Removing tunnel $tunnelId from activeTunnels as state is DOWN")
|
|
||||||
cleanUpTunJob(tunnelId)
|
|
||||||
currentTuns - tunnelId
|
|
||||||
} else if (
|
|
||||||
existingState.status == newStatus &&
|
|
||||||
stats == null &&
|
|
||||||
pingStates == null &&
|
|
||||||
logHealthState == null
|
|
||||||
) {
|
|
||||||
Timber.d("Skipping redundant state update for ${tunnelId}: $newStatus")
|
|
||||||
currentTuns
|
|
||||||
} else {
|
|
||||||
val updated =
|
|
||||||
existingState.copy(
|
|
||||||
status = newStatus,
|
|
||||||
statistics = stats ?: existingState.statistics,
|
|
||||||
pingStates = pingStates ?: existingState.pingStates,
|
|
||||||
logHealthState = logHealthState ?: existingState.logHealthState,
|
|
||||||
)
|
|
||||||
currentTuns + (tunnelId to updated)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun stopActiveTunnels() {
|
|
||||||
activeTunnels.value.forEach { (config, state) ->
|
|
||||||
if (state.status.isUpOrStarting()) {
|
|
||||||
stopTunnel(config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun startTunnel(tunnelConfig: TunnelConfig) {
|
|
||||||
tunMutex.withLock {
|
|
||||||
if (
|
|
||||||
activeTuns.value.containsKey(tunnelConfig.id) ||
|
|
||||||
tunJobs.containsKey(tunnelConfig.id)
|
|
||||||
) {
|
|
||||||
return Timber.w("Tunnel is already running: ${tunnelConfig.name}")
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTunnelStatus(tunnelConfig.id, TunnelStatus.Starting)
|
|
||||||
|
|
||||||
val job =
|
|
||||||
applicationScope.launch(ioDispatcher) {
|
|
||||||
try {
|
|
||||||
tunnelStateFlow(tunnelConfig).collect { status ->
|
|
||||||
updateTunnelStatus(tunnelConfig.id, status)
|
|
||||||
}
|
|
||||||
} catch (e: BackendCoreException) {
|
|
||||||
errors.emit(tunnelConfig.name to e)
|
|
||||||
updateTunnelStatus(tunnelConfig.id, TunnelStatus.Down)
|
|
||||||
} catch (_: CancellationException) {}
|
|
||||||
}
|
|
||||||
tunJobs[tunnelConfig.id] = job
|
|
||||||
job.invokeOnCompletion {
|
|
||||||
tunJobs.remove(tunnelConfig.id)
|
|
||||||
activeTuns.update { it - tunnelConfig.id }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun stopTunnel(tunnelId: Int) {
|
|
||||||
tunMutex.withLock {
|
|
||||||
val currentState = activeTuns.value[tunnelId]?.status ?: return@withLock
|
|
||||||
updateTunnelStatus(tunnelId, TunnelStatus.Stopping)
|
|
||||||
tunJobs[tunnelId]?.cancel()
|
|
||||||
|
|
||||||
withTimeoutOrNull(STOP_TIMEOUT_MS) {
|
|
||||||
activeTunnels.first {
|
|
||||||
!it.containsKey(tunnelId) || it[tunnelId]!!.status == TunnelStatus.Down
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?: run {
|
|
||||||
Timber.w("Stop timeout for $tunnelId (was $currentState); forcing kill")
|
|
||||||
forceStopTunnel(tunnelId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun cleanUpTunJob(tunnelId: Int) {
|
|
||||||
Timber.d("Removing job for $tunnelId")
|
|
||||||
tunJobs -= tunnelId
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val STARTUP_TIMEOUT_MS: Long = 15_000L
|
|
||||||
const val STOP_TIMEOUT_MS: Long = 5_000L
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -31,7 +31,7 @@ fun MutableStateFlow<Map<TunnelConfig, TunnelState>>.exists(id: Int): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun MutableStateFlow<Map<TunnelConfig, TunnelState>>.isUp(id: Int): Boolean {
|
fun MutableStateFlow<Map<TunnelConfig, TunnelState>>.isUp(id: Int): Boolean {
|
||||||
return this.value.any { it.key.id == id && it.value.status == TunnelStatus.Up }
|
return this.value.any { it.key.id == id && it.value.status is TunnelStatus.Up }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun MutableStateFlow<Map<TunnelConfig, TunnelState>>.isStarting(id: Int): Boolean {
|
fun MutableStateFlow<Map<TunnelConfig, TunnelState>>.isStarting(id: Int): Boolean {
|
||||||
|
|||||||
+187
@@ -0,0 +1,187 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.backend.TunnelBackend
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.UnknownError
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.LogHealthState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import kotlinx.coroutines.CancellationException
|
||||||
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
class TunnelLifecycleManager(
|
||||||
|
private val backend: TunnelBackend,
|
||||||
|
private val applicationScope: CoroutineScope,
|
||||||
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
|
private val sharedActiveTunnels: MutableStateFlow<Map<Int, TunnelState>>,
|
||||||
|
) : TunnelProvider {
|
||||||
|
|
||||||
|
override val activeTunnels: StateFlow<Map<Int, TunnelState>> = sharedActiveTunnels.asStateFlow()
|
||||||
|
|
||||||
|
private val _errorEvents = MutableSharedFlow<Pair<String?, BackendCoreException>>()
|
||||||
|
override val errorEvents: SharedFlow<Pair<String?, BackendCoreException>> =
|
||||||
|
_errorEvents.asSharedFlow()
|
||||||
|
|
||||||
|
private val _messageEvents = MutableSharedFlow<Pair<String?, BackendMessage>>()
|
||||||
|
override val messageEvents: SharedFlow<Pair<String?, BackendMessage>> =
|
||||||
|
_messageEvents.asSharedFlow()
|
||||||
|
|
||||||
|
private val tunnelJobs = ConcurrentHashMap<Int, Job>()
|
||||||
|
private val tunMutex = Mutex()
|
||||||
|
private val tunStatusMutex = Mutex()
|
||||||
|
|
||||||
|
override suspend fun startTunnel(tunnelConfig: TunnelConfig): Result<Unit> =
|
||||||
|
tunMutex.withLock {
|
||||||
|
val id = tunnelConfig.id
|
||||||
|
if (sharedActiveTunnels.value.containsKey(id)) {
|
||||||
|
Timber.w("Tunnel is already running: ${tunnelConfig.name}")
|
||||||
|
return Result.failure(IllegalStateException("Tunnel already running"))
|
||||||
|
}
|
||||||
|
|
||||||
|
val startupCompleted = CompletableDeferred<Result<Unit>>()
|
||||||
|
|
||||||
|
val job =
|
||||||
|
applicationScope.launch(ioDispatcher) {
|
||||||
|
try {
|
||||||
|
updateTunnelStatus(id, TunnelStatus.Starting)
|
||||||
|
backend.tunnelStateFlow(tunnelConfig).collect { status ->
|
||||||
|
updateTunnelStatus(id, status)
|
||||||
|
|
||||||
|
if (status != TunnelStatus.Starting && !startupCompleted.isCompleted) {
|
||||||
|
if (status is TunnelStatus.Up) {
|
||||||
|
startupCompleted.complete(Result.success(Unit))
|
||||||
|
} else {
|
||||||
|
startupCompleted.complete(Result.failure(UnknownError()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: BackendCoreException) {
|
||||||
|
_errorEvents.emit(tunnelConfig.name to e)
|
||||||
|
updateTunnelStatus(id, TunnelStatus.Down)
|
||||||
|
startupCompleted.complete(Result.failure(e))
|
||||||
|
} catch (_: CancellationException) {} finally {
|
||||||
|
tunnelJobs.remove(id)
|
||||||
|
sharedActiveTunnels.update { it - id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tunnelJobs[id] = job
|
||||||
|
job.invokeOnCompletion { tunnelJobs.remove(id) }
|
||||||
|
|
||||||
|
try {
|
||||||
|
startupCompleted.await()
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
job.cancel()
|
||||||
|
Result.failure(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun stopTunnel(tunnelId: Int) =
|
||||||
|
tunMutex.withLock {
|
||||||
|
val currentState = sharedActiveTunnels.value[tunnelId]?.status ?: return@withLock
|
||||||
|
updateTunnelStatus(tunnelId, TunnelStatus.Stopping)
|
||||||
|
tunnelJobs[tunnelId]?.cancel()
|
||||||
|
|
||||||
|
withTimeoutOrNull(STOP_TIMEOUT_MS) {
|
||||||
|
activeTunnels.first {
|
||||||
|
!it.containsKey(tunnelId) || it[tunnelId]!!.status == TunnelStatus.Down
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?: run {
|
||||||
|
Timber.w("Stop timeout for $tunnelId (was $currentState); forcing kill")
|
||||||
|
forceStopTunnel(tunnelId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun forceStopTunnel(tunnelId: Int) {
|
||||||
|
backend.forceStopTunnel(tunnelId)
|
||||||
|
tunnelJobs[tunnelId]?.cancel()
|
||||||
|
tunnelJobs.remove(tunnelId)
|
||||||
|
sharedActiveTunnels.update { it - tunnelId }
|
||||||
|
updateTunnelStatus(tunnelId, TunnelStatus.Down)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun stopActiveTunnels() {
|
||||||
|
sharedActiveTunnels.value.forEach { (id, state) ->
|
||||||
|
if (state.status.isUpOrStarting()) {
|
||||||
|
stopTunnel(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateTunnelStatus(
|
||||||
|
tunnelId: Int,
|
||||||
|
status: TunnelStatus?,
|
||||||
|
stats: TunnelStatistics?,
|
||||||
|
pingStates: Map<String, PingState>?,
|
||||||
|
logHealthState: LogHealthState?,
|
||||||
|
) =
|
||||||
|
tunStatusMutex.withLock {
|
||||||
|
sharedActiveTunnels.update { currentTuns ->
|
||||||
|
if (!currentTuns.containsKey(tunnelId) && status != TunnelStatus.Starting) {
|
||||||
|
Timber.d("Ignoring update for inactive tunnel $tunnelId")
|
||||||
|
return@update currentTuns
|
||||||
|
}
|
||||||
|
val existingState = currentTuns[tunnelId] ?: TunnelState()
|
||||||
|
val newStatus = status ?: existingState.status
|
||||||
|
if (newStatus == TunnelStatus.Down) {
|
||||||
|
Timber.d("Removing tunnel $tunnelId from activeTunnels as state is DOWN")
|
||||||
|
currentTuns - tunnelId
|
||||||
|
} else if (
|
||||||
|
existingState.status == newStatus &&
|
||||||
|
stats == null &&
|
||||||
|
pingStates == null &&
|
||||||
|
logHealthState == null
|
||||||
|
) {
|
||||||
|
Timber.d("Skipping redundant state update for ${tunnelId}: $newStatus")
|
||||||
|
currentTuns
|
||||||
|
} else {
|
||||||
|
val updated =
|
||||||
|
existingState.copy(
|
||||||
|
status = newStatus,
|
||||||
|
statistics = stats ?: existingState.statistics,
|
||||||
|
pingStates = pingStates ?: existingState.pingStates,
|
||||||
|
logHealthState = logHealthState ?: existingState.logHealthState,
|
||||||
|
)
|
||||||
|
currentTuns + (tunnelId to updated)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setBackendMode(backendMode: BackendMode) = backend.setBackendMode(backendMode)
|
||||||
|
|
||||||
|
override fun getBackendMode(): BackendMode = backend.getBackendMode()
|
||||||
|
|
||||||
|
override suspend fun runningTunnelNames(): Set<String> = backend.runningTunnelNames()
|
||||||
|
|
||||||
|
override fun handleDnsReresolve(tunnelConfig: TunnelConfig): Boolean =
|
||||||
|
backend.handleDnsReresolve(tunnelConfig)
|
||||||
|
|
||||||
|
override fun getStatistics(tunnelId: Int): TunnelStatistics? = backend.getStatistics(tunnelId)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val STOP_TIMEOUT_MS: Long = 5_000L
|
||||||
|
}
|
||||||
|
}
|
||||||
+247
-428
@@ -1,280 +1,137 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
|
import android.os.PowerManager
|
||||||
|
import com.zaneschepke.logcatter.LogReader
|
||||||
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig as Entity
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.backend.TunnelBackend
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.handler.DynamicDnsHandler
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.handler.TunnelActiveStatePersister
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.handler.TunnelMonitorHandler
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.handler.TunnelServiceHandler
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||||
import com.zaneschepke.wireguardautotunnel.di.*
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.NotAuthorized
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.AutoTunnelSettings
|
import com.zaneschepke.wireguardautotunnel.domain.model.AutoTunnelSettings
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.LockdownSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.MonitoringSettingsRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.LogHealthState
|
import com.zaneschepke.wireguardautotunnel.domain.state.LogHealthState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
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 com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.concurrent.atomics.AtomicBoolean
|
import kotlin.concurrent.atomics.AtomicBoolean
|
||||||
import kotlin.concurrent.atomics.AtomicReference
|
import kotlin.concurrent.atomics.AtomicReference
|
||||||
import kotlin.concurrent.atomics.ExperimentalAtomicApi
|
import kotlin.concurrent.atomics.ExperimentalAtomicApi
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||||
|
import kotlinx.coroutines.flow.filterNot
|
||||||
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
|
import kotlinx.coroutines.flow.merge
|
||||||
|
import kotlinx.coroutines.flow.shareIn
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
|
import kotlinx.coroutines.supervisorScope
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class, ExperimentalAtomicApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class, ExperimentalAtomicApi::class)
|
||||||
class TunnelManager
|
class TunnelManager(
|
||||||
@Inject
|
kernelBackend: TunnelBackend,
|
||||||
constructor(
|
userspaceBackend: TunnelBackend,
|
||||||
@Kernel private val kernelTunnel: TunnelProvider,
|
proxyUserspaceBackend: TunnelBackend,
|
||||||
@Userspace private val userspaceTunnel: TunnelProvider,
|
networkMonitor: NetworkMonitor,
|
||||||
@ProxyUserspace private val proxyUserspaceTunnel: TunnelProvider,
|
networkUtils: NetworkUtils,
|
||||||
|
powerManager: PowerManager,
|
||||||
|
logReader: LogReader,
|
||||||
|
monitoringSettingsRepository: MonitoringSettingsRepository,
|
||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
private val settingsRepository: GeneralSettingRepository,
|
private val settingsRepository: GeneralSettingRepository,
|
||||||
private val autoTunnelSettingsRepository: AutoTunnelSettingsRepository,
|
private val autoTunnelSettingsRepository: AutoTunnelSettingsRepository,
|
||||||
|
private val lockdownSettingsRepository: LockdownSettingsRepository,
|
||||||
private val tunnelsRepository: TunnelRepository,
|
private val tunnelsRepository: TunnelRepository,
|
||||||
private val tunnelMonitor: TunnelMonitor,
|
private val applicationScope: CoroutineScope,
|
||||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : TunnelProvider {
|
) : TunnelProvider {
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
private val _activeTunnels = MutableStateFlow<Map<Int, TunnelState>>(emptyMap())
|
||||||
private val localErrorEvents = MutableSharedFlow<Pair<String?, BackendCoreException>>()
|
override val activeTunnels: StateFlow<Map<Int, TunnelState>> = _activeTunnels.asStateFlow()
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalAtomicApi::class) val currentAppMode = AtomicReference(AppMode.VPN)
|
||||||
private val localMessageEvents = MutableSharedFlow<Pair<String?, BackendMessage>>()
|
|
||||||
|
|
||||||
private val monitoringMutex = Mutex()
|
private val defaultManager =
|
||||||
private val monitoringJobs = ConcurrentHashMap<Int, Job>()
|
TunnelLifecycleManager(userspaceBackend, applicationScope, ioDispatcher, _activeTunnels)
|
||||||
|
|
||||||
private val ddnsMutex = Mutex()
|
private val lifecycleManagers: Map<AppMode, TunnelLifecycleManager> =
|
||||||
private val ddnsJobs = ConcurrentHashMap<Int, Job>()
|
mapOf(
|
||||||
|
AppMode.KERNEL to
|
||||||
|
TunnelLifecycleManager(
|
||||||
|
kernelBackend,
|
||||||
|
applicationScope,
|
||||||
|
ioDispatcher,
|
||||||
|
_activeTunnels,
|
||||||
|
),
|
||||||
|
AppMode.VPN to defaultManager,
|
||||||
|
AppMode.PROXY to
|
||||||
|
TunnelLifecycleManager(
|
||||||
|
proxyUserspaceBackend,
|
||||||
|
applicationScope,
|
||||||
|
ioDispatcher,
|
||||||
|
_activeTunnels,
|
||||||
|
),
|
||||||
|
AppMode.LOCK_DOWN to
|
||||||
|
TunnelLifecycleManager(
|
||||||
|
proxyUserspaceBackend,
|
||||||
|
applicationScope,
|
||||||
|
ioDispatcher,
|
||||||
|
_activeTunnels,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
private data class SideEffectState(
|
@OptIn(ExperimentalAtomicApi::class)
|
||||||
val activeTuns: Map<Int, TunnelState>,
|
private fun getProvider(): TunnelProvider {
|
||||||
val tuns: List<TunnelConfig>,
|
return lifecycleManagers[currentAppMode.load()] ?: defaultManager
|
||||||
val settings: GeneralSettings,
|
|
||||||
val previouslyActive: Map<Int, TunnelState>,
|
|
||||||
)
|
|
||||||
|
|
||||||
private data class SideEffectWithCondition(
|
|
||||||
val effect: suspend (SideEffectState) -> Unit,
|
|
||||||
val condition: (SideEffectState) -> Boolean,
|
|
||||||
)
|
|
||||||
|
|
||||||
private suspend fun getSettings(): GeneralSettings =
|
|
||||||
settingsRepository.flow.filterNotNull().first { it != GeneralSettings() }
|
|
||||||
|
|
||||||
private suspend fun getTunnels(): List<TunnelConfig> =
|
|
||||||
tunnelsRepository.flow.first { it.isNotEmpty() }
|
|
||||||
|
|
||||||
private val tunnelProviderFlow: StateFlow<TunnelProvider> = run {
|
|
||||||
val currentBackend = AtomicReference(userspaceTunnel)
|
|
||||||
val currentSettings = AtomicReference(GeneralSettings())
|
|
||||||
val initialEmit = AtomicBoolean(true)
|
|
||||||
|
|
||||||
settingsRepository.flow
|
|
||||||
.filterNotNull()
|
|
||||||
// ignore default state
|
|
||||||
.filterNot { it == GeneralSettings() }
|
|
||||||
.distinctUntilChanged { old, new ->
|
|
||||||
old.appMode == new.appMode &&
|
|
||||||
old.isLanOnKillSwitchEnabled == new.isLanOnKillSwitchEnabled
|
|
||||||
}
|
|
||||||
.map { settings ->
|
|
||||||
Timber.d("App mode changes with ${settings.appMode}")
|
|
||||||
val backend =
|
|
||||||
when (settings.appMode) {
|
|
||||||
AppMode.VPN -> userspaceTunnel
|
|
||||||
AppMode.PROXY -> proxyUserspaceTunnel
|
|
||||||
AppMode.LOCK_DOWN -> proxyUserspaceTunnel
|
|
||||||
AppMode.KERNEL -> kernelTunnel
|
|
||||||
}
|
|
||||||
settings to backend
|
|
||||||
}
|
|
||||||
.onEach { (settings, newBackend) ->
|
|
||||||
val isInitialEmit = initialEmit.exchange(false)
|
|
||||||
val previousBackend = currentBackend.exchange(newBackend)
|
|
||||||
val previousSettings = currentSettings.exchange(settings)
|
|
||||||
|
|
||||||
if ((previousSettings.appMode != settings.appMode) && !isInitialEmit) {
|
|
||||||
handleModeChangeCleanup(previousBackend, previousSettings.appMode)
|
|
||||||
}
|
|
||||||
if (settings.appMode == AppMode.LOCK_DOWN) {
|
|
||||||
handleLockDownModeInit(settings.isLanOnKillSwitchEnabled)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.map { (_, backend) -> backend }
|
|
||||||
.stateIn(
|
|
||||||
scope = applicationScope.plus(ioDispatcher),
|
|
||||||
started = SharingStarted.Eagerly,
|
|
||||||
initialValue = userspaceTunnel,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override val activeTunnels: StateFlow<Map<Int, TunnelState>> = run {
|
override suspend fun startTunnel(tunnelConfig: TunnelConfig): Result<Unit> =
|
||||||
val activeTunsReference: AtomicReference<Map<Int, TunnelState>> =
|
getProvider().startTunnel(tunnelConfig)
|
||||||
AtomicReference(emptyMap())
|
|
||||||
|
|
||||||
tunnelProviderFlow
|
override suspend fun stopTunnel(tunnelId: Int) = getProvider().stopTunnel(tunnelId)
|
||||||
.flatMapLatest { backend ->
|
|
||||||
combine(
|
|
||||||
backend.activeTunnels,
|
|
||||||
tunnelsRepository.flow,
|
|
||||||
settingsRepository.flow.filterNotNull(),
|
|
||||||
) { activeTuns, tuns, settings ->
|
|
||||||
Triple(activeTuns, tuns, settings)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onStart { handleRestore() }
|
|
||||||
.onEach { (activeTuns, tuns, settings) ->
|
|
||||||
val previouslyActive = activeTunsReference.exchange(activeTuns)
|
|
||||||
val state = SideEffectState(activeTuns, tuns, settings, previouslyActive)
|
|
||||||
|
|
||||||
applicationScope.launch(ioDispatcher) {
|
override suspend fun forceStopTunnel(tunnelId: Int) = getProvider().forceStopTunnel(tunnelId)
|
||||||
supervisorScope {
|
|
||||||
val sideEffects =
|
|
||||||
listOf(
|
|
||||||
SideEffectWithCondition(
|
|
||||||
effect = { s ->
|
|
||||||
handleTunnelServiceChange(s.settings.appMode, s.activeTuns)
|
|
||||||
},
|
|
||||||
condition = { s ->
|
|
||||||
s.activeTuns.size != s.previouslyActive.size
|
|
||||||
},
|
|
||||||
),
|
|
||||||
SideEffectWithCondition(
|
|
||||||
effect = { s ->
|
|
||||||
handleTunnelsActiveChange(
|
|
||||||
s.previouslyActive,
|
|
||||||
s.activeTuns,
|
|
||||||
s.tuns,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
condition = { s ->
|
|
||||||
s.activeTuns.size != s.previouslyActive.size
|
|
||||||
},
|
|
||||||
),
|
|
||||||
SideEffectWithCondition(
|
|
||||||
effect = { s ->
|
|
||||||
handleDynamicDnsMonitoring(s.activeTuns, s.tuns, s.settings)
|
|
||||||
},
|
|
||||||
condition = { s ->
|
|
||||||
s.activeTuns.keys != s.previouslyActive.keys
|
|
||||||
},
|
|
||||||
),
|
|
||||||
SideEffectWithCondition(
|
|
||||||
effect = { s ->
|
|
||||||
handleFullTunnelMonitoring(s.activeTuns, s.tuns, s.settings)
|
|
||||||
},
|
|
||||||
condition = { s ->
|
|
||||||
s.activeTuns.keys != s.previouslyActive.keys
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
sideEffects
|
override suspend fun stopActiveTunnels() = getProvider().stopActiveTunnels()
|
||||||
.filter { it.condition(state) }
|
|
||||||
.forEach { sideEffect ->
|
|
||||||
launch {
|
|
||||||
try {
|
|
||||||
sideEffect.effect(state)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e, "Side effect failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.map { (activeTuns, _, _) -> activeTuns }
|
|
||||||
.stateIn(
|
|
||||||
scope = applicationScope,
|
|
||||||
started = SharingStarted.Eagerly,
|
|
||||||
initialValue = emptyMap(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
override fun setBackendMode(backendMode: BackendMode) =
|
||||||
override val errorEvents: SharedFlow<Pair<String?, BackendCoreException>> =
|
getProvider().setBackendMode(backendMode)
|
||||||
merge(localErrorEvents, tunnelProviderFlow.flatMapLatest { it.errorEvents })
|
|
||||||
.shareIn(
|
|
||||||
scope = applicationScope + ioDispatcher,
|
|
||||||
started = SharingStarted.Eagerly,
|
|
||||||
replay = 0,
|
|
||||||
)
|
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
override fun getBackendMode(): BackendMode = getProvider().getBackendMode()
|
||||||
override val messageEvents: SharedFlow<Pair<String?, BackendMessage>> =
|
|
||||||
merge(localMessageEvents, tunnelProviderFlow.flatMapLatest { it.messageEvents })
|
|
||||||
.shareIn(
|
|
||||||
scope = applicationScope.plus(ioDispatcher),
|
|
||||||
started = SharingStarted.Eagerly,
|
|
||||||
replay = 0,
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun getStatistics(tunnelId: Int): TunnelStatistics? {
|
override suspend fun runningTunnelNames(): Set<String> = getProvider().runningTunnelNames()
|
||||||
return tunnelProviderFlow.value.getStatistics(tunnelId)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun startTunnel(tunnelConfig: TunnelConfig) {
|
override fun handleDnsReresolve(tunnelConfig: TunnelConfig): Boolean =
|
||||||
if (activeTunnels.value.containsKey(tunnelConfig.id)) return
|
getProvider().handleDnsReresolve(tunnelConfig)
|
||||||
val provider = tunnelProviderFlow.value
|
|
||||||
val isKernel = provider is KernelTunnel
|
|
||||||
|
|
||||||
if (!isKernel && activeTunnels.value.isNotEmpty()) {
|
override fun getStatistics(tunnelId: Int): TunnelStatistics? =
|
||||||
stopActiveTunnels()
|
getProvider().getStatistics(tunnelId)
|
||||||
withTimeoutOrNull(BaseTunnel.STARTUP_TIMEOUT_MS) {
|
|
||||||
activeTunnels.first { it.isEmpty() }
|
|
||||||
} ?: run { activeTunnels.value.keys.forEach { id -> provider.forceStopTunnel(id) } }
|
|
||||||
}
|
|
||||||
val runConfig =
|
|
||||||
tunnelConfig.run {
|
|
||||||
if (getSettings().isTunnelGlobalsEnabled) {
|
|
||||||
val globalTunnel =
|
|
||||||
getTunnels().firstOrNull { it.name == Entity.GLOBAL_CONFIG_NAME }
|
|
||||||
?: return@run this
|
|
||||||
return@run copyWithGlobalValues(globalTunnel)
|
|
||||||
}
|
|
||||||
this
|
|
||||||
}
|
|
||||||
tunnelProviderFlow.value.startTunnel(runConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun stopTunnel(tunnelId: Int) {
|
|
||||||
tunnelProviderFlow.value.stopTunnel(tunnelId)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun forceStopTunnel(tunnelId: Int) {
|
|
||||||
tunnelProviderFlow.value.forceStopTunnel(tunnelId)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun stopActiveTunnels() {
|
|
||||||
tunnelProviderFlow.value.stopActiveTunnels()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setBackendMode(backendMode: BackendMode) {
|
|
||||||
tunnelProviderFlow.value.setBackendMode(backendMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getBackendMode(): BackendMode {
|
|
||||||
return tunnelProviderFlow.value.getBackendMode()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> {
|
|
||||||
return tunnelProviderFlow.value.runningTunnelNames()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun handleDnsReresolve(tunnelConfig: TunnelConfig): Boolean {
|
|
||||||
return tunnelProviderFlow.value.handleDnsReresolve(tunnelConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun updateTunnelStatus(
|
override suspend fun updateTunnelStatus(
|
||||||
tunnelId: Int,
|
tunnelId: Int,
|
||||||
@@ -282,82 +139,151 @@ constructor(
|
|||||||
stats: TunnelStatistics?,
|
stats: TunnelStatistics?,
|
||||||
pingStates: Map<String, PingState>?,
|
pingStates: Map<String, PingState>?,
|
||||||
logHealthState: LogHealthState?,
|
logHealthState: LogHealthState?,
|
||||||
) {
|
) = getProvider().updateTunnelStatus(tunnelId, status, stats, pingStates, logHealthState)
|
||||||
tunnelProviderFlow.value.updateTunnelStatus(
|
|
||||||
tunnelId,
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
status,
|
private val localErrorEvents = MutableSharedFlow<Pair<String?, BackendCoreException>>()
|
||||||
stats,
|
|
||||||
pingStates,
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
logHealthState,
|
private val localMessageEvents = MutableSharedFlow<Pair<String?, BackendMessage>>()
|
||||||
|
|
||||||
|
override val errorEvents: SharedFlow<Pair<String?, BackendCoreException>> =
|
||||||
|
merge(localErrorEvents, *lifecycleManagers.values.map { it.errorEvents }.toTypedArray())
|
||||||
|
.shareIn(
|
||||||
|
scope = applicationScope + ioDispatcher,
|
||||||
|
started = SharingStarted.Eagerly,
|
||||||
|
replay = 0,
|
||||||
|
)
|
||||||
|
|
||||||
|
override val messageEvents: SharedFlow<Pair<String?, BackendMessage>> =
|
||||||
|
merge(localMessageEvents, *lifecycleManagers.values.map { it.messageEvents }.toTypedArray())
|
||||||
|
.shareIn(
|
||||||
|
scope = applicationScope.plus(ioDispatcher),
|
||||||
|
started = SharingStarted.Eagerly,
|
||||||
|
replay = 0,
|
||||||
|
)
|
||||||
|
|
||||||
|
private val tunnelServiceHandler =
|
||||||
|
TunnelServiceHandler(
|
||||||
|
activeTunnels = activeTunnels,
|
||||||
|
settingsRepository = settingsRepository,
|
||||||
|
serviceManager = serviceManager,
|
||||||
|
applicationScope = applicationScope,
|
||||||
|
ioDispatcher = ioDispatcher,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val tunnelActiveStatePersister =
|
||||||
|
TunnelActiveStatePersister(
|
||||||
|
activeTunnels = activeTunnels,
|
||||||
|
tunnelsRepository = tunnelsRepository,
|
||||||
|
applicationScope = applicationScope,
|
||||||
|
ioDispatcher = ioDispatcher,
|
||||||
|
)
|
||||||
|
|
||||||
|
private val dynamicDnsHandler =
|
||||||
|
DynamicDnsHandler(
|
||||||
|
activeTunnels = activeTunnels,
|
||||||
|
tunnelsRepository = tunnelsRepository,
|
||||||
|
settingsRepository = settingsRepository,
|
||||||
|
localMessageEvents = localMessageEvents,
|
||||||
|
handleDnsReresolve = { config -> handleDnsReresolve(config) },
|
||||||
|
applicationScope = applicationScope,
|
||||||
|
ioDispatcher = ioDispatcher,
|
||||||
|
)
|
||||||
|
|
||||||
|
private val fullTunnelMonitorHandler =
|
||||||
|
TunnelMonitorHandler(
|
||||||
|
activeTunnels = activeTunnels,
|
||||||
|
tunnelsRepository = tunnelsRepository,
|
||||||
|
settingsRepository = settingsRepository,
|
||||||
|
monitoringSettingsRepository = monitoringSettingsRepository,
|
||||||
|
networkMonitor = networkMonitor,
|
||||||
|
networkUtils = networkUtils,
|
||||||
|
powerManager = powerManager,
|
||||||
|
logReader = logReader,
|
||||||
|
getStatistics = { id -> getStatistics(id) },
|
||||||
|
updateTunnelStatus = { id, status, stats, pings, logHealth ->
|
||||||
|
updateTunnelStatus(id, status, stats, pings, logHealth)
|
||||||
|
},
|
||||||
|
applicationScope = applicationScope,
|
||||||
|
ioDispatcher = ioDispatcher,
|
||||||
|
)
|
||||||
|
|
||||||
|
init {
|
||||||
|
applicationScope.launch(ioDispatcher) {
|
||||||
|
val initialEmit = AtomicBoolean(true)
|
||||||
|
settingsRepository.flow
|
||||||
|
.filterNotNull()
|
||||||
|
.filterNot { it == GeneralSettings() }
|
||||||
|
.distinctUntilChangedBy { it.appMode }
|
||||||
|
.collect { settings ->
|
||||||
|
val isInitialEmit = initialEmit.exchange(false)
|
||||||
|
val previousMode = currentAppMode.exchange(settings.appMode)
|
||||||
|
|
||||||
|
if (isInitialEmit) {
|
||||||
|
return@collect handleRestore(settings)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previousMode != settings.appMode) {
|
||||||
|
handleModeChangeCleanup(previousMode)
|
||||||
|
}
|
||||||
|
if (settings.appMode == AppMode.LOCK_DOWN) {
|
||||||
|
handleLockDownModeInit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleTunnelServiceChange(
|
// TODO this can crash if we haven't started foreground service yet, especially for
|
||||||
appMode: AppMode,
|
// workerManager
|
||||||
activeTuns: Map<Int, TunnelState>,
|
private suspend fun handleLockDownModeInit() {
|
||||||
) {
|
val lockdownSettings = lockdownSettingsRepository.getLockdownSettings()
|
||||||
if (activeTuns.isEmpty()) serviceManager.stopTunnelService()
|
val allowedIps =
|
||||||
if (activeTuns.isNotEmpty() && serviceManager.tunnelService.value == null)
|
if (lockdownSettings.bypassLan) TunnelConfig.IPV4_PUBLIC_NETWORKS else emptySet()
|
||||||
serviceManager.startTunnelService(appMode)
|
|
||||||
serviceManager.updateTunnelTile()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleLockDownModeInit(withLanBypass: Boolean) {
|
|
||||||
val allowedIps = if (withLanBypass) TunnelConfig.IPV4_PUBLIC_NETWORKS else emptySet()
|
|
||||||
try {
|
try {
|
||||||
if (serviceManager.hasVpnPermission()) {
|
if (serviceManager.hasVpnPermission()) {
|
||||||
proxyUserspaceTunnel.setBackendMode(BackendMode.KillSwitch(allowedIps))
|
setBackendMode(
|
||||||
|
BackendMode.KillSwitch(
|
||||||
|
allowedIps,
|
||||||
|
lockdownSettings.metered,
|
||||||
|
lockdownSettings.dualStack,
|
||||||
|
)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
throw BackendCoreException.NotAuthorized
|
throw NotAuthorized()
|
||||||
}
|
}
|
||||||
} catch (e: BackendCoreException) {
|
} catch (e: BackendCoreException) {
|
||||||
localErrorEvents.tryEmit(null to e)
|
localErrorEvents.tryEmit(null to e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleModeChangeCleanup(
|
private suspend fun handleModeChangeCleanup(previousAppMode: AppMode) {
|
||||||
previousBackend: TunnelProvider,
|
lifecycleManagers[previousAppMode]?.stopActiveTunnels()
|
||||||
previousAppMode: AppMode,
|
if (previousAppMode == AppMode.LOCK_DOWN) {
|
||||||
) {
|
lifecycleManagers[previousAppMode]?.setBackendMode(BackendMode.Inactive)
|
||||||
previousBackend.stopActiveTunnels()
|
|
||||||
// stop lockdown if we switch from that mode
|
|
||||||
if (previousAppMode == AppMode.LOCK_DOWN)
|
|
||||||
proxyUserspaceTunnel.setBackendMode(BackendMode.Inactive)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isVpnAuthorized(
|
|
||||||
mode: AppMode,
|
|
||||||
hasVpnPermission: () -> Boolean = { serviceManager.hasVpnPermission() },
|
|
||||||
): Boolean {
|
|
||||||
return when (mode) {
|
|
||||||
AppMode.VPN,
|
|
||||||
AppMode.LOCK_DOWN -> hasVpnPermission()
|
|
||||||
AppMode.KERNEL,
|
|
||||||
AppMode.PROXY -> true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun handleRestore() =
|
suspend fun handleRestore(settings: GeneralSettings? = null) =
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
val settings = settingsRepository.getGeneralSettings()
|
val currentSettings = settings ?: settingsRepository.getGeneralSettings()
|
||||||
val autoTunnelSettings = autoTunnelSettingsRepository.getAutoTunnelSettings()
|
val autoTunnelSettings = autoTunnelSettingsRepository.getAutoTunnelSettings()
|
||||||
val tunnels = tunnelsRepository.getAll()
|
val tunnels = tunnelsRepository.userTunnelsFlow.firstOrNull()
|
||||||
if (autoTunnelSettings.isAutoTunnelEnabled)
|
if (autoTunnelSettings.isAutoTunnelEnabled)
|
||||||
return@withContext restoreAutoTunnel(autoTunnelSettings)
|
return@withContext restoreAutoTunnel(autoTunnelSettings)
|
||||||
if (isVpnAuthorized(settings.appMode)) {
|
if (currentSettings.appMode == AppMode.LOCK_DOWN) handleLockDownModeInit()
|
||||||
when (val mode = settings.appMode) {
|
if (tunnels?.any { it.isActive } == true) {
|
||||||
|
if (currentSettings.appMode == AppMode.VPN && !serviceManager.hasVpnPermission())
|
||||||
|
return@withContext localErrorEvents.emit(null to NotAuthorized())
|
||||||
|
when (currentSettings.appMode) {
|
||||||
AppMode.VPN,
|
AppMode.VPN,
|
||||||
AppMode.PROXY,
|
AppMode.PROXY,
|
||||||
AppMode.LOCK_DOWN -> {
|
AppMode.LOCK_DOWN -> {
|
||||||
if (mode == AppMode.LOCK_DOWN)
|
|
||||||
handleLockDownModeInit(settings.isLanOnKillSwitchEnabled)
|
|
||||||
tunnels.firstOrNull { it.isActive }?.let { startTunnel(it) }
|
tunnels.firstOrNull { it.isActive }?.let { startTunnel(it) }
|
||||||
}
|
}
|
||||||
AppMode.KERNEL ->
|
AppMode.KERNEL ->
|
||||||
tunnels.filter { it.isActive }.forEach { conf -> startTunnel(conf) }
|
tunnels.filter { it.isActive }.forEach { conf -> startTunnel(conf) }
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
localErrorEvents.emit(null to BackendCoreException.NotAuthorized)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,171 +296,64 @@ constructor(
|
|||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
val settings = settingsRepository.getGeneralSettings()
|
val settings = settingsRepository.getGeneralSettings()
|
||||||
val autoTunnelSettings = autoTunnelSettingsRepository.getAutoTunnelSettings()
|
val autoTunnelSettings = autoTunnelSettingsRepository.getAutoTunnelSettings()
|
||||||
val defaultTunnel = tunnelsRepository.getStartTunnel()
|
val defaultTunnel = tunnelsRepository.getDefaultTunnel()
|
||||||
if (autoTunnelSettings.startOnBoot)
|
if (autoTunnelSettings.startOnBoot)
|
||||||
return@withContext restoreAutoTunnel(autoTunnelSettings)
|
return@withContext restoreAutoTunnel(autoTunnelSettings)
|
||||||
if (settings.isRestoreOnBootEnabled) {
|
if (settings.isRestoreOnBootEnabled) {
|
||||||
tunnelsRepository.resetActiveTunnels()
|
tunnelsRepository.resetActiveTunnels()
|
||||||
if (isVpnAuthorized(settings.appMode)) {
|
when (settings.appMode) {
|
||||||
when (val mode = settings.appMode) {
|
AppMode.LOCK_DOWN -> handleLockDownModeInit()
|
||||||
AppMode.LOCK_DOWN ->
|
AppMode.VPN ->
|
||||||
handleLockDownModeInit(settings.isLanOnKillSwitchEnabled)
|
if (!serviceManager.hasVpnPermission())
|
||||||
AppMode.KERNEL,
|
return@withContext localErrorEvents.emit(null to NotAuthorized())
|
||||||
AppMode.VPN,
|
AppMode.KERNEL,
|
||||||
AppMode.PROXY -> Unit
|
AppMode.PROXY -> Unit
|
||||||
}
|
|
||||||
defaultTunnel?.let { startTunnel(it) }
|
|
||||||
} else {
|
|
||||||
localErrorEvents.emit(null to BackendCoreException.NotAuthorized)
|
|
||||||
}
|
}
|
||||||
|
defaultTunnel?.let { startTunnel(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleTunnelsActiveChange(
|
suspend fun restartActiveTunnel(id: Int) =
|
||||||
previousActiveTuns: Map<Int, TunnelState>,
|
withContext(ioDispatcher) {
|
||||||
activeTuns: Map<Int, TunnelState>,
|
val activeIds = activeTunnels.value.keys.toList()
|
||||||
tuns: List<TunnelConfig>,
|
if (activeIds.isEmpty()) return@withContext
|
||||||
) {
|
if (!activeIds.contains(id)) return@withContext
|
||||||
val relevantTunnels = previousActiveTuns.keys + activeTuns.keys
|
val tunnel = tunnelsRepository.getById(id) ?: return@withContext
|
||||||
|
restartTunnel(tunnel)
|
||||||
relevantTunnels.forEach { tunnelId ->
|
|
||||||
val wasActive = previousActiveTuns.containsKey(tunnelId)
|
|
||||||
val isActiveNow = activeTuns.containsKey(tunnelId)
|
|
||||||
|
|
||||||
when {
|
|
||||||
!wasActive && isActiveNow -> {
|
|
||||||
tuns
|
|
||||||
.find { it.id == tunnelId }
|
|
||||||
?.let { dbTunnelConf ->
|
|
||||||
tunnelsRepository.save(dbTunnelConf.copy(isActive = true))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wasActive && !isActiveNow -> {
|
|
||||||
tuns
|
|
||||||
.find { it.id == tunnelId }
|
|
||||||
?.let { dbTunnelConf ->
|
|
||||||
tunnelsRepository.save(dbTunnelConf.copy(isActive = false))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun handleDynamicDnsMonitoring(
|
suspend fun restartActiveTunnels() =
|
||||||
activeTuns: Map<Int, TunnelState>,
|
withContext(ioDispatcher) {
|
||||||
configs: List<TunnelConfig>,
|
val activeIds = activeTunnels.value.keys.toList()
|
||||||
settings: GeneralSettings,
|
if (activeIds.isEmpty()) return@withContext
|
||||||
) =
|
|
||||||
ddnsMutex.withLock {
|
|
||||||
val activeIds =
|
|
||||||
activeTuns.keys
|
|
||||||
.filter { id ->
|
|
||||||
configs.find { it.id == id }?.restartOnPingFailure == true &&
|
|
||||||
settings.appMode != AppMode.KERNEL
|
|
||||||
}
|
|
||||||
.toSet()
|
|
||||||
|
|
||||||
val currentJobs = ddnsJobs.keys.toSet()
|
val tunnels = tunnelsRepository.getAll()
|
||||||
val obsoleteIds = currentJobs - activeIds
|
if (tunnels.isEmpty()) return@withContext
|
||||||
|
|
||||||
Timber.d(
|
supervisorScope {
|
||||||
"DDNS Monitoring: Active IDs: $activeIds, Obsolete IDs: $obsoleteIds, Total jobs before: ${ddnsJobs.size}"
|
activeIds.forEach { id ->
|
||||||
)
|
val tunnel =
|
||||||
|
tunnels.find { it.id == id }
|
||||||
obsoleteIds.forEach { id ->
|
?: run {
|
||||||
ddnsJobs[id]?.cancel()
|
Timber.w("Tunnel config $id not found; skipping restart")
|
||||||
ddnsJobs.remove(id)
|
return@forEach
|
||||||
}
|
|
||||||
|
|
||||||
activeIds.forEach { id ->
|
|
||||||
if (ddnsJobs.containsKey(id)) return@forEach // Skip if already monitored
|
|
||||||
val conf = configs.find { it.id == id } ?: return@forEach
|
|
||||||
val tunStateFlow =
|
|
||||||
activeTunnels.map { it[id] }.stateIn(applicationScope + ioDispatcher)
|
|
||||||
|
|
||||||
val newJob =
|
|
||||||
applicationScope.launch(ioDispatcher) {
|
|
||||||
var backoff = 30_000L
|
|
||||||
while (isActive) {
|
|
||||||
val state = tunStateFlow.value ?: break
|
|
||||||
if (state.health() != TunnelState.Health.UNHEALTHY) {
|
|
||||||
backoff = BASE_BACKOFF
|
|
||||||
tunStateFlow.first {
|
|
||||||
it?.health() == TunnelState.Health.UNHEALTHY || it == null
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
restartTunnel(tunnel)
|
||||||
runCatching {
|
}
|
||||||
val updated = handleDnsReresolve(conf)
|
|
||||||
if (updated) {
|
|
||||||
localMessageEvents.emit(
|
|
||||||
conf.name to BackendMessage.DynamicDnsSuccess
|
|
||||||
)
|
|
||||||
backoff = BASE_BACKOFF
|
|
||||||
} else {
|
|
||||||
Timber.i(
|
|
||||||
"Dynamic DNS check completed, current endpoint address is already up to date."
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onFailure {
|
|
||||||
Timber.e(
|
|
||||||
it,
|
|
||||||
"Failed to handle dns re-resolution for ${conf.name}",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
delay(backoff)
|
|
||||||
backoff = (backoff * 1.5).toLong().coerceAtMost(MAX_BACKOFF_TIME)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ddnsJobs[id] = newJob
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleFullTunnelMonitoring(
|
private suspend fun restartTunnel(tunnel: TunnelConfig) {
|
||||||
activeTuns: Map<Int, TunnelState>,
|
runCatching { stopTunnel(tunnel.id) }
|
||||||
configs: List<TunnelConfig>,
|
.onFailure { e -> Timber.e(e, "Failed to stop tunnel ${tunnel.id} during restart") }
|
||||||
settings: GeneralSettings,
|
|
||||||
) =
|
|
||||||
monitoringMutex.withLock {
|
|
||||||
val activeIds = activeTuns.keys.toSet()
|
|
||||||
val currentJobs = monitoringJobs.keys.toSet()
|
|
||||||
val obsoleteIds = currentJobs - activeIds
|
|
||||||
|
|
||||||
Timber.d(
|
delay(RESTART_TUNNEL_DELAY)
|
||||||
"Monitoring: Active IDs: $activeIds, Obsolete IDs: $obsoleteIds, Total jobs before: ${monitoringJobs.size}"
|
|
||||||
)
|
|
||||||
|
|
||||||
obsoleteIds.forEach { id ->
|
runCatching { startTunnel(tunnel) }
|
||||||
monitoringJobs[id]?.cancel()
|
.onFailure { e -> Timber.e(e, "Failed to restart tunnel ${tunnel.id}") }
|
||||||
monitoringJobs.remove(id)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
activeIds.forEach { id ->
|
|
||||||
if (monitoringJobs.containsKey(id)) return@forEach // Skip if already monitored
|
|
||||||
configs.find { it.id == id } ?: return@forEach
|
|
||||||
val tunStateFlow =
|
|
||||||
activeTunnels.map { it[id] }.stateIn(applicationScope + ioDispatcher)
|
|
||||||
val newJob =
|
|
||||||
applicationScope.launch(ioDispatcher) {
|
|
||||||
tunnelMonitor.startMonitoring(
|
|
||||||
id,
|
|
||||||
withLogs = settings.appMode != AppMode.KERNEL,
|
|
||||||
tunStateFlow = tunStateFlow,
|
|
||||||
getStatistics = { tunnelId -> getStatistics(tunnelId) },
|
|
||||||
updateTunnelStatus = { tid, _, stats, pings, logHealth ->
|
|
||||||
updateTunnelStatus(tid, null, stats, pings, logHealth)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
monitoringJobs[id] = newJob
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val BASE_BACKOFF = 30_000L
|
const val RESTART_TUNNEL_DELAY = 300L
|
||||||
const val MAX_BACKOFF_TIME = 300_000L
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-10
@@ -13,19 +13,12 @@ import kotlinx.coroutines.flow.SharedFlow
|
|||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
interface TunnelProvider {
|
interface TunnelProvider {
|
||||||
/** Starts the specified tunnel configuration. */
|
suspend fun startTunnel(tunnelConfig: TunnelConfig): Result<Unit>
|
||||||
suspend fun startTunnel(tunnelConfig: TunnelConfig)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the specified tunnel.
|
|
||||||
*
|
|
||||||
* @param tunnelId The tunnelConf to stop.
|
|
||||||
*/
|
|
||||||
suspend fun stopTunnel(tunnelId: Int)
|
suspend fun stopTunnel(tunnelId: Int)
|
||||||
|
|
||||||
suspend fun forceStopTunnel(tunnelId: Int)
|
suspend fun forceStopTunnel(tunnelId: Int)
|
||||||
|
|
||||||
/** Stops all active tunnels. */
|
|
||||||
suspend fun stopActiveTunnels()
|
suspend fun stopActiveTunnels()
|
||||||
|
|
||||||
fun setBackendMode(backendMode: BackendMode)
|
fun setBackendMode(backendMode: BackendMode)
|
||||||
@@ -39,9 +32,7 @@ interface TunnelProvider {
|
|||||||
fun getStatistics(tunnelId: Int): TunnelStatistics?
|
fun getStatistics(tunnelId: Int): TunnelStatistics?
|
||||||
|
|
||||||
val activeTunnels: StateFlow<Map<Int, TunnelState>>
|
val activeTunnels: StateFlow<Map<Int, TunnelState>>
|
||||||
|
|
||||||
val errorEvents: SharedFlow<Pair<String?, BackendCoreException>>
|
val errorEvents: SharedFlow<Pair<String?, BackendCoreException>>
|
||||||
|
|
||||||
val messageEvents: SharedFlow<Pair<String?, BackendMessage>>
|
val messageEvents: SharedFlow<Pair<String?, BackendMessage>>
|
||||||
|
|
||||||
suspend fun updateTunnelStatus(
|
suspend fun updateTunnelStatus(
|
||||||
|
|||||||
@@ -1,193 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.ProxySettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.DnsSettingsRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.ProxySettingsRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.AmneziaStatistics
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asAmBackendMode
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asBackendMode
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendCoreException
|
|
||||||
import java.io.IOException
|
|
||||||
import java.util.*
|
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import kotlinx.coroutines.channels.Channel
|
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import kotlinx.coroutines.flow.callbackFlow
|
|
||||||
import kotlinx.coroutines.flow.consumeAsFlow
|
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import org.amnezia.awg.backend.Backend
|
|
||||||
import org.amnezia.awg.backend.BackendException
|
|
||||||
import org.amnezia.awg.backend.ProxyGoBackend
|
|
||||||
import org.amnezia.awg.backend.Tunnel as AwgTunnel
|
|
||||||
import org.amnezia.awg.config.Config
|
|
||||||
import org.amnezia.awg.config.DnsSettings
|
|
||||||
import org.amnezia.awg.config.proxy.HttpProxy
|
|
||||||
import org.amnezia.awg.config.proxy.Proxy
|
|
||||||
import org.amnezia.awg.config.proxy.Socks5Proxy
|
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
class UserspaceTunnel
|
|
||||||
@Inject
|
|
||||||
constructor(
|
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
private val proxySettingsRepository: ProxySettingsRepository,
|
|
||||||
private val dnsSettingsRepository: DnsSettingsRepository,
|
|
||||||
private val backend: Backend,
|
|
||||||
) : BaseTunnel(applicationScope, ioDispatcher) {
|
|
||||||
|
|
||||||
private val runtimeTunnels = ConcurrentHashMap<Int, AwgTunnel>()
|
|
||||||
|
|
||||||
override fun tunnelStateFlow(tunnelConfig: TunnelConfig): Flow<TunnelStatus> = callbackFlow {
|
|
||||||
val stateChannel = Channel<AwgTunnel.State>()
|
|
||||||
|
|
||||||
val runtimeTunnel = RuntimeAwgTunnel(tunnelConfig, stateChannel)
|
|
||||||
runtimeTunnels[tunnelConfig.id] = runtimeTunnel
|
|
||||||
|
|
||||||
val consumerJob = launch {
|
|
||||||
stateChannel.consumeAsFlow().collect { awgState -> trySend(awgState.asTunnelState()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
withTimeout(STARTUP_TIMEOUT_MS) {
|
|
||||||
updateTunnelStatus(tunnelConfig.id, TunnelStatus.Starting)
|
|
||||||
|
|
||||||
val proxies: List<Proxy> =
|
|
||||||
when (backend) {
|
|
||||||
is ProxyGoBackend -> {
|
|
||||||
val proxySettings = proxySettingsRepository.getProxySettings()
|
|
||||||
Timber.d("Adding proxy configs")
|
|
||||||
buildList {
|
|
||||||
if (proxySettings.socks5ProxyEnabled) {
|
|
||||||
add(
|
|
||||||
Socks5Proxy(
|
|
||||||
proxySettings.socks5ProxyBindAddress
|
|
||||||
?: ProxySettings.DEFAULT_SOCKS_BIND_ADDRESS,
|
|
||||||
proxySettings.proxyUsername,
|
|
||||||
proxySettings.proxyPassword,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (proxySettings.httpProxyEnabled) {
|
|
||||||
add(
|
|
||||||
HttpProxy(
|
|
||||||
proxySettings.httpProxyBindAddress
|
|
||||||
?: ProxySettings.DEFAULT_HTTP_BIND_ADDRESS,
|
|
||||||
proxySettings.proxyUsername,
|
|
||||||
proxySettings.proxyPassword,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> emptyList()
|
|
||||||
}
|
|
||||||
val setting = dnsSettingsRepository.getDnsSettings()
|
|
||||||
val config = tunnelConfig.toAmConfig()
|
|
||||||
val updatedConfig =
|
|
||||||
Config.Builder()
|
|
||||||
.apply {
|
|
||||||
setInterface(config.`interface`)
|
|
||||||
addPeers(config.peers)
|
|
||||||
addProxies(proxies)
|
|
||||||
setDnsSettings(
|
|
||||||
DnsSettings(
|
|
||||||
setting.dnsProtocol == DnsProtocol.DOH,
|
|
||||||
Optional.ofNullable(setting.dnsEndpoint),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.build()
|
|
||||||
backend.setState(runtimeTunnel, AwgTunnel.State.UP, updatedConfig)
|
|
||||||
}
|
|
||||||
} catch (e: TimeoutCancellationException) {
|
|
||||||
Timber.e("Startup timed out for ${tunnelConfig.name} (likely DNS hang)")
|
|
||||||
errors.emit(tunnelConfig.name to BackendCoreException.DNS)
|
|
||||||
forceStopTunnel(tunnelConfig.id)
|
|
||||||
close()
|
|
||||||
} catch (e: BackendException) {
|
|
||||||
close(e.toBackendCoreException())
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
close(BackendCoreException.Config)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e, "Error while setting tunnel state")
|
|
||||||
close(BackendCoreException.Unknown)
|
|
||||||
}
|
|
||||||
|
|
||||||
awaitClose {
|
|
||||||
try {
|
|
||||||
backend.setState(runtimeTunnel, AwgTunnel.State.DOWN, null)
|
|
||||||
} catch (e: BackendException) {
|
|
||||||
errors.tryEmit(tunnelConfig.name to e.toBackendCoreException())
|
|
||||||
} finally {
|
|
||||||
consumerJob.cancel()
|
|
||||||
stateChannel.close()
|
|
||||||
runtimeTunnels.remove(tunnelConfig.id)
|
|
||||||
trySend(TunnelStatus.Down)
|
|
||||||
close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setBackendMode(backendMode: BackendMode) {
|
|
||||||
Timber.d("Setting backend mode: $backendMode")
|
|
||||||
try {
|
|
||||||
backend.backendMode = backendMode.asAmBackendMode()
|
|
||||||
} catch (e: BackendException) {
|
|
||||||
throw e.toBackendCoreException()
|
|
||||||
// TODO this should be mapped to BackendException in the lib
|
|
||||||
} catch (e: IOException) {
|
|
||||||
throw BackendCoreException.NotAuthorized
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getBackendMode(): BackendMode {
|
|
||||||
return backend.backendMode.asBackendMode()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun handleDnsReresolve(tunnelConfig: TunnelConfig): Boolean {
|
|
||||||
val tunnel = runtimeTunnels[tunnelConfig.id] ?: throw BackendCoreException.ServiceNotRunning
|
|
||||||
return backend.resolveDDNS(tunnelConfig.toAmConfig(), tunnel.isIpv4ResolutionPreferred)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> {
|
|
||||||
return backend.runningTunnelNames
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getStatistics(tunnelId: Int): TunnelStatistics? {
|
|
||||||
return try {
|
|
||||||
val runtimeTunnel = runtimeTunnels[tunnelId] ?: return null
|
|
||||||
AmneziaStatistics(backend.getStatistics(runtimeTunnel))
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e, "Failed to get stats for $tunnelId")
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun forceStopTunnel(tunnelId: Int) {
|
|
||||||
val runtimeTunnel = runtimeTunnels[tunnelId] ?: return
|
|
||||||
try {
|
|
||||||
backend.setState(runtimeTunnel, AwgTunnel.State.DOWN, null)
|
|
||||||
} catch (e: BackendException) {
|
|
||||||
Timber.e(e, "Force stop failed for $tunnelId")
|
|
||||||
} finally {
|
|
||||||
tunJobs[tunnelId]?.cancel()
|
|
||||||
runtimeTunnels.remove(tunnelId)
|
|
||||||
tunJobs.remove(tunnelId)
|
|
||||||
activeTuns.update { it - tunnelId }
|
|
||||||
updateTunnelStatus(tunnelId, TunnelStatus.Down)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+46
-44
@@ -1,45 +1,56 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel.backend
|
||||||
|
|
||||||
import com.wireguard.android.backend.Backend
|
import com.wireguard.android.backend.Backend
|
||||||
import com.wireguard.android.backend.BackendException
|
import com.wireguard.android.backend.BackendException
|
||||||
import com.wireguard.android.backend.Tunnel as WgTunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.wireguard.android.backend.WgQuickBackend
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
import com.zaneschepke.wireguardautotunnel.domain.events.DnsFailure
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.InvalidConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.KernelTunnelName
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.KernelWireguardNotSupported
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.UnknownError
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
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
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendCoreException
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendCoreException
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import javax.inject.Inject
|
import java.util.regex.Pattern
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.TimeoutCancellationException
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.callbackFlow
|
import kotlinx.coroutines.flow.callbackFlow
|
||||||
import kotlinx.coroutines.flow.consumeAsFlow
|
import kotlinx.coroutines.flow.consumeAsFlow
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class KernelTunnel
|
class KernelTunnel(private val runConfigHelper: RunConfigHelper, private val backend: Backend) :
|
||||||
@Inject
|
TunnelBackend {
|
||||||
constructor(
|
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
@Kernel private val backend: Backend,
|
|
||||||
) : BaseTunnel(applicationScope, ioDispatcher) {
|
|
||||||
|
|
||||||
private val runtimeTunnels = ConcurrentHashMap<Int, WgTunnel>()
|
private val runtimeTunnels = ConcurrentHashMap<Int, Tunnel>()
|
||||||
|
|
||||||
|
private fun validateWireGuardInterfaceName(name: String): Result<Unit> {
|
||||||
|
if (name.isEmpty() || name.length > 15)
|
||||||
|
return Result.failure(KernelTunnelName(R.string.kernel_name_error))
|
||||||
|
if (name == "." || name == "..") {
|
||||||
|
return Result.failure(KernelTunnelName(R.string.kernel_name_dots))
|
||||||
|
}
|
||||||
|
val pattern = Pattern.compile("^[a-zA-Z0-9_=+.-]{1,15}$")
|
||||||
|
if (!pattern.matcher(name).matches()) {
|
||||||
|
return Result.failure(KernelTunnelName(R.string.kernel_name_special_characters))
|
||||||
|
}
|
||||||
|
return Result.success(Unit)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO Add DNS settings
|
|
||||||
override fun tunnelStateFlow(tunnelConfig: TunnelConfig): Flow<TunnelStatus> = callbackFlow {
|
override fun tunnelStateFlow(tunnelConfig: TunnelConfig): Flow<TunnelStatus> = callbackFlow {
|
||||||
if (!tunnelConfig.isNameKernelCompatible) close(BackendCoreException.TunnelNameTooLong)
|
if (!WgQuickBackend.hasKernelSupport()) throw KernelWireguardNotSupported()
|
||||||
|
validateWireGuardInterfaceName(tunnelConfig.name).onFailure { throw it }
|
||||||
|
|
||||||
val stateChannel = Channel<WgTunnel.State>()
|
val stateChannel = Channel<Tunnel.State>()
|
||||||
|
|
||||||
val runtimeTunnel = RuntimeWgTunnel(tunnelConfig, stateChannel)
|
val runtimeTunnel = RuntimeWgTunnel(tunnelConfig, stateChannel)
|
||||||
runtimeTunnels[tunnelConfig.id] = runtimeTunnel
|
runtimeTunnels[tunnelConfig.id] = runtimeTunnel
|
||||||
@@ -49,36 +60,31 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
withTimeout(STARTUP_TIMEOUT_MS) {
|
val runConfig = runConfigHelper.buildWgRunConfig(tunnelConfig)
|
||||||
updateTunnelStatus(tunnelConfig.id, TunnelStatus.Starting)
|
backend.setState(runtimeTunnel, Tunnel.State.UP, runConfig)
|
||||||
backend.setState(runtimeTunnel, WgTunnel.State.UP, tunnelConfig.toWgConfig())
|
|
||||||
}
|
|
||||||
} catch (e: TimeoutCancellationException) {
|
} catch (e: TimeoutCancellationException) {
|
||||||
Timber.e("Startup timed out for ${tunnelConfig.name}")
|
Timber.Forest.e("Startup timed out for ${tunnelConfig.name}")
|
||||||
errors.emit(tunnelConfig.name to BackendCoreException.DNS)
|
throw DnsFailure()
|
||||||
forceStopTunnel(tunnelConfig.id)
|
|
||||||
close()
|
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
close(e.toBackendCoreException())
|
throw e.toBackendCoreException()
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
Timber.e(e, "Invalid backend arguments")
|
Timber.Forest.e(e, "Invalid backend arguments")
|
||||||
close(BackendCoreException.Config)
|
throw InvalidConfig()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Error while setting tunnel state")
|
Timber.Forest.e(e, "Error while setting tunnel state")
|
||||||
close(BackendCoreException.Unknown)
|
throw UnknownError()
|
||||||
}
|
}
|
||||||
|
|
||||||
awaitClose {
|
awaitClose {
|
||||||
try {
|
try {
|
||||||
backend.setState(runtimeTunnel, WgTunnel.State.DOWN, null)
|
backend.setState(runtimeTunnel, Tunnel.State.DOWN, null)
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
errors.tryEmit(tunnelConfig.name to e.toBackendCoreException())
|
// Errors are emitted by caller (lifecycle manager)
|
||||||
} finally {
|
} finally {
|
||||||
consumerJob.cancel()
|
consumerJob.cancel()
|
||||||
stateChannel.close()
|
stateChannel.close()
|
||||||
runtimeTunnels.remove(tunnelConfig.id)
|
runtimeTunnels.remove(tunnelConfig.id)
|
||||||
trySend(TunnelStatus.Down)
|
trySend(TunnelStatus.Down)
|
||||||
close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,13 +94,13 @@ constructor(
|
|||||||
val runtimeTunnel = runtimeTunnels[tunnelId] ?: return null
|
val runtimeTunnel = runtimeTunnels[tunnelId] ?: return null
|
||||||
WireGuardStatistics(backend.getStatistics(runtimeTunnel))
|
WireGuardStatistics(backend.getStatistics(runtimeTunnel))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Failed to get stats for $tunnelId")
|
Timber.Forest.e(e, "Failed to get stats for $tunnelId")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setBackendMode(backendMode: BackendMode) {
|
override fun setBackendMode(backendMode: BackendMode) {
|
||||||
Timber.w("Not yet implemented for kernel")
|
Timber.Forest.w("Not yet implemented for kernel")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBackendMode(): BackendMode {
|
override fun getBackendMode(): BackendMode {
|
||||||
@@ -112,15 +118,11 @@ constructor(
|
|||||||
override suspend fun forceStopTunnel(tunnelId: Int) {
|
override suspend fun forceStopTunnel(tunnelId: Int) {
|
||||||
val runtimeTunnel = runtimeTunnels[tunnelId] ?: return
|
val runtimeTunnel = runtimeTunnels[tunnelId] ?: return
|
||||||
try {
|
try {
|
||||||
backend.setState(runtimeTunnel, WgTunnel.State.DOWN, null)
|
backend.setState(runtimeTunnel, Tunnel.State.DOWN, null)
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e(e, "Force stop failed for $tunnelId")
|
Timber.Forest.e(e, "Force stop failed for $tunnelId")
|
||||||
} finally {
|
} finally {
|
||||||
tunJobs[tunnelId]?.cancel()
|
|
||||||
runtimeTunnels.remove(tunnelId)
|
runtimeTunnels.remove(tunnelId)
|
||||||
tunJobs.remove(tunnelId)
|
|
||||||
activeTuns.update { it - tunnelId }
|
|
||||||
updateTunnelStatus(tunnelId, TunnelStatus.Down)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+101
@@ -0,0 +1,101 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.core.tunnel.backend
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.InvalidConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.DnsSettings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.ProxySettings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.DnsSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.ProxySettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
|
import java.util.Optional
|
||||||
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
|
import org.amnezia.awg.config.Config
|
||||||
|
import org.amnezia.awg.config.proxy.HttpProxy
|
||||||
|
import org.amnezia.awg.config.proxy.Socks5Proxy
|
||||||
|
|
||||||
|
class RunConfigHelper(
|
||||||
|
private val settingsRepository: GeneralSettingRepository,
|
||||||
|
private val proxySettingsRepository: ProxySettingsRepository,
|
||||||
|
private val dnsSettingsRepository: DnsSettingsRepository,
|
||||||
|
private val tunnelsRepository: TunnelRepository,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private data class PrepResult(
|
||||||
|
val effectiveConfig: TunnelConfig,
|
||||||
|
val generalSettings: GeneralSettings,
|
||||||
|
val dnsSettings: DnsSettings,
|
||||||
|
)
|
||||||
|
|
||||||
|
private suspend fun prepare(tunnelConfig: TunnelConfig): PrepResult {
|
||||||
|
val generalSettings = settingsRepository.getGeneralSettings()
|
||||||
|
val dnsSettings = dnsSettingsRepository.getDnsSettings()
|
||||||
|
val effectiveConfig =
|
||||||
|
if (
|
||||||
|
generalSettings.isGlobalSplitTunnelEnabled || dnsSettings.isGlobalTunnelDnsEnabled
|
||||||
|
) {
|
||||||
|
val globalConfig =
|
||||||
|
tunnelsRepository.globalTunnelFlow.firstOrNull() ?: throw InvalidConfig()
|
||||||
|
tunnelConfig.copyWithGlobalValues(
|
||||||
|
globalConfig,
|
||||||
|
dnsSettings.isGlobalTunnelDnsEnabled,
|
||||||
|
generalSettings.isGlobalSplitTunnelEnabled,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
tunnelConfig
|
||||||
|
}
|
||||||
|
return PrepResult(effectiveConfig, generalSettings, dnsSettings)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun buildAmRunConfig(tunnelConfig: TunnelConfig): Config {
|
||||||
|
val prep = prepare(tunnelConfig)
|
||||||
|
val proxies =
|
||||||
|
if (prep.generalSettings.appMode == AppMode.PROXY) {
|
||||||
|
val proxySettings = proxySettingsRepository.getProxySettings()
|
||||||
|
buildList {
|
||||||
|
if (proxySettings.socks5ProxyEnabled) {
|
||||||
|
add(
|
||||||
|
Socks5Proxy(
|
||||||
|
proxySettings.socks5ProxyBindAddress
|
||||||
|
?: ProxySettings.DEFAULT_SOCKS_BIND_ADDRESS,
|
||||||
|
proxySettings.proxyUsername,
|
||||||
|
proxySettings.proxyPassword,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (proxySettings.httpProxyEnabled) {
|
||||||
|
add(
|
||||||
|
HttpProxy(
|
||||||
|
proxySettings.httpProxyBindAddress
|
||||||
|
?: ProxySettings.DEFAULT_HTTP_BIND_ADDRESS,
|
||||||
|
proxySettings.proxyUsername,
|
||||||
|
proxySettings.proxyPassword,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
val amConfig = prep.effectiveConfig.toAmConfig()
|
||||||
|
return Config.Builder()
|
||||||
|
.setInterface(amConfig.`interface`)
|
||||||
|
.addPeers(amConfig.peers)
|
||||||
|
.addProxies(proxies)
|
||||||
|
.setDnsSettings(
|
||||||
|
org.amnezia.awg.config.DnsSettings(
|
||||||
|
prep.dnsSettings.dnsProtocol == DnsProtocol.DOH,
|
||||||
|
Optional.ofNullable(prep.dnsSettings.dnsEndpoint),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun buildWgRunConfig(tunnelConfig: TunnelConfig): com.wireguard.config.Config {
|
||||||
|
val prep = prepare(tunnelConfig)
|
||||||
|
return prep.effectiveConfig.toWgConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel.backend
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
@@ -16,4 +16,6 @@ class RuntimeAwgTunnel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun isIpv4ResolutionPreferred() = tunnelConfig.isIpv4Preferred
|
override fun isIpv4ResolutionPreferred() = tunnelConfig.isIpv4Preferred
|
||||||
|
|
||||||
|
override fun isMetered() = tunnelConfig.isMetered
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel.backend
|
||||||
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.core.tunnel.backend
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface TunnelBackend {
|
||||||
|
fun tunnelStateFlow(tunnelConfig: TunnelConfig): Flow<TunnelStatus>
|
||||||
|
|
||||||
|
fun getStatistics(tunnelId: Int): TunnelStatistics?
|
||||||
|
|
||||||
|
fun setBackendMode(backendMode: BackendMode)
|
||||||
|
|
||||||
|
fun getBackendMode(): BackendMode
|
||||||
|
|
||||||
|
fun handleDnsReresolve(tunnelConfig: TunnelConfig): Boolean
|
||||||
|
|
||||||
|
suspend fun runningTunnelNames(): Set<String>
|
||||||
|
|
||||||
|
suspend fun forceStopTunnel(tunnelId: Int)
|
||||||
|
}
|
||||||
+119
@@ -0,0 +1,119 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.core.tunnel.backend
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.DnsFailure
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.InvalidConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.ServiceNotRunning
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.UnknownError
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.VpnUnauthorized
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.AmneziaStatistics
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asAmBackendMode
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asBackendMode
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendCoreException
|
||||||
|
import java.io.IOException
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import kotlinx.coroutines.TimeoutCancellationException
|
||||||
|
import kotlinx.coroutines.channels.Channel
|
||||||
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.callbackFlow
|
||||||
|
import kotlinx.coroutines.flow.consumeAsFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.amnezia.awg.backend.Backend
|
||||||
|
import org.amnezia.awg.backend.BackendException
|
||||||
|
import org.amnezia.awg.backend.Tunnel
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
class UserspaceTunnel(private val backend: Backend, private val runConfigHelper: RunConfigHelper) :
|
||||||
|
TunnelBackend {
|
||||||
|
|
||||||
|
private val runtimeTunnels = ConcurrentHashMap<Int, Tunnel>()
|
||||||
|
|
||||||
|
override fun tunnelStateFlow(tunnelConfig: TunnelConfig): Flow<TunnelStatus> = callbackFlow {
|
||||||
|
val stateChannel = Channel<Tunnel.State>()
|
||||||
|
|
||||||
|
val runtimeTunnel = RuntimeAwgTunnel(tunnelConfig, stateChannel)
|
||||||
|
runtimeTunnels[tunnelConfig.id] = runtimeTunnel
|
||||||
|
|
||||||
|
val consumerJob = launch {
|
||||||
|
stateChannel.consumeAsFlow().collect { awgState -> trySend(awgState.asTunnelState()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val runConfig = runConfigHelper.buildAmRunConfig(tunnelConfig)
|
||||||
|
backend.setState(runtimeTunnel, Tunnel.State.UP, runConfig)
|
||||||
|
} catch (_: TimeoutCancellationException) {
|
||||||
|
Timber.e("Startup timed out for ${tunnelConfig.name} (likely DNS hang)")
|
||||||
|
throw DnsFailure()
|
||||||
|
} catch (e: BackendException) {
|
||||||
|
throw e.toBackendCoreException()
|
||||||
|
} catch (_: IllegalArgumentException) {
|
||||||
|
throw InvalidConfig()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e, "Error while setting tunnel state")
|
||||||
|
throw UnknownError()
|
||||||
|
}
|
||||||
|
|
||||||
|
awaitClose {
|
||||||
|
try {
|
||||||
|
backend.setState(runtimeTunnel, Tunnel.State.DOWN, null)
|
||||||
|
} catch (e: BackendException) {
|
||||||
|
// Errors emitted by caller
|
||||||
|
} finally {
|
||||||
|
consumerJob.cancel()
|
||||||
|
stateChannel.close()
|
||||||
|
runtimeTunnels.remove(tunnelConfig.id)
|
||||||
|
trySend(TunnelStatus.Down)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setBackendMode(backendMode: BackendMode) {
|
||||||
|
Timber.d("Setting backend mode: $backendMode")
|
||||||
|
try {
|
||||||
|
backend.backendMode = backendMode.asAmBackendMode()
|
||||||
|
} catch (e: BackendException) {
|
||||||
|
throw e.toBackendCoreException()
|
||||||
|
} catch (_: IOException) {
|
||||||
|
throw VpnUnauthorized()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getBackendMode(): BackendMode {
|
||||||
|
return backend.backendMode.asBackendMode()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun handleDnsReresolve(tunnelConfig: TunnelConfig): Boolean {
|
||||||
|
val tunnel = runtimeTunnels[tunnelConfig.id] ?: throw ServiceNotRunning()
|
||||||
|
return backend.resolveDDNS(tunnelConfig.toAmConfig(), tunnel.isIpv4ResolutionPreferred)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun runningTunnelNames(): Set<String> {
|
||||||
|
return backend.runningTunnelNames
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getStatistics(tunnelId: Int): TunnelStatistics? {
|
||||||
|
return try {
|
||||||
|
val runtimeTunnel = runtimeTunnels[tunnelId] ?: return null
|
||||||
|
AmneziaStatistics(backend.getStatistics(runtimeTunnel))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e, "Failed to get stats for $tunnelId")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun forceStopTunnel(tunnelId: Int) {
|
||||||
|
val runtimeTunnel = runtimeTunnels[tunnelId] ?: return
|
||||||
|
try {
|
||||||
|
backend.setState(runtimeTunnel, Tunnel.State.DOWN, null)
|
||||||
|
} catch (e: BackendException) {
|
||||||
|
Timber.e(e, "Force stop failed for $tunnelId")
|
||||||
|
} finally {
|
||||||
|
runtimeTunnels.remove(tunnelId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+114
@@ -0,0 +1,114 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.core.tunnel.handler
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
class DynamicDnsHandler(
|
||||||
|
private val activeTunnels: StateFlow<Map<Int, TunnelState>>,
|
||||||
|
private val tunnelsRepository: TunnelRepository,
|
||||||
|
private val settingsRepository: GeneralSettingRepository,
|
||||||
|
private val localMessageEvents: MutableSharedFlow<Pair<String?, BackendMessage>>,
|
||||||
|
private val handleDnsReresolve: (TunnelConfig) -> Boolean,
|
||||||
|
private val applicationScope: CoroutineScope,
|
||||||
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
|
) {
|
||||||
|
private val mutex = Mutex()
|
||||||
|
private val jobs = ConcurrentHashMap<Int, Job>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
applicationScope.launch(ioDispatcher) {
|
||||||
|
combine(activeTunnels, settingsRepository.flow.filterNotNull()) { active, settings ->
|
||||||
|
active to settings
|
||||||
|
}
|
||||||
|
.collect { (activeTuns, settings) ->
|
||||||
|
mutex.withLock {
|
||||||
|
val activeIds =
|
||||||
|
activeTuns.keys
|
||||||
|
.filter { id ->
|
||||||
|
val config =
|
||||||
|
tunnelsRepository.getById(id) ?: return@filter false
|
||||||
|
config.restartOnPingFailure &&
|
||||||
|
settings.appMode != AppMode.KERNEL
|
||||||
|
}
|
||||||
|
.toSet()
|
||||||
|
|
||||||
|
(jobs.keys - activeIds).forEach { id ->
|
||||||
|
Timber.d("Shutting down Dynamic DNS monitoring job for tunnelId: $id")
|
||||||
|
jobs.remove(id)?.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
activeIds.forEach { id ->
|
||||||
|
if (jobs.containsKey(id)) return@forEach
|
||||||
|
val config = tunnelsRepository.getById(id) ?: return@forEach
|
||||||
|
val tunStateFlow =
|
||||||
|
activeTunnels
|
||||||
|
.map { it[id] }
|
||||||
|
.stateIn(applicationScope + ioDispatcher)
|
||||||
|
Timber.d("Starting Dynamic DNS monitoring job for tunnelId: $id")
|
||||||
|
jobs[id] =
|
||||||
|
applicationScope.launch(ioDispatcher) {
|
||||||
|
monitorDynamicDns(config, tunStateFlow)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun monitorDynamicDns(
|
||||||
|
config: TunnelConfig,
|
||||||
|
tunStateFlow: StateFlow<TunnelState?>,
|
||||||
|
) {
|
||||||
|
var backoff = BASE_BACKOFF
|
||||||
|
while (true) {
|
||||||
|
val state = tunStateFlow.value ?: break
|
||||||
|
if (state.health() != TunnelState.Health.UNHEALTHY) {
|
||||||
|
backoff = BASE_BACKOFF
|
||||||
|
tunStateFlow.first { it?.health() == TunnelState.Health.UNHEALTHY || it == null }
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
runCatching {
|
||||||
|
val updated = handleDnsReresolve(config)
|
||||||
|
if (updated) {
|
||||||
|
localMessageEvents.emit(config.name to BackendMessage.DynamicDnsSuccess)
|
||||||
|
backoff = BASE_BACKOFF
|
||||||
|
} else {
|
||||||
|
Timber.i(
|
||||||
|
"Dynamic DNS check completed, current endpoint address is already up to date."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onFailure { Timber.e(it, "Failed to handle dns re-resolution for ${config.name}") }
|
||||||
|
|
||||||
|
delay(backoff)
|
||||||
|
backoff = (backoff * 1.5).toLong().coerceAtMost(MAX_BACKOFF_TIME)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val BASE_BACKOFF = 30_000L
|
||||||
|
const val MAX_BACKOFF_TIME = 300_000L
|
||||||
|
}
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.core.tunnel.handler
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.supervisorScope
|
||||||
|
|
||||||
|
class TunnelActiveStatePersister(
|
||||||
|
private val activeTunnels: StateFlow<Map<Int, TunnelState>>,
|
||||||
|
private val tunnelsRepository: TunnelRepository,
|
||||||
|
applicationScope: CoroutineScope,
|
||||||
|
ioDispatcher: CoroutineDispatcher,
|
||||||
|
) {
|
||||||
|
private var previousActiveIds: Set<Int> = emptySet()
|
||||||
|
|
||||||
|
init {
|
||||||
|
applicationScope.launch(ioDispatcher) {
|
||||||
|
activeTunnels.collect { currentActive ->
|
||||||
|
val currentActiveIds = currentActive.keys
|
||||||
|
if (currentActiveIds == previousActiveIds) return@collect
|
||||||
|
|
||||||
|
val tunnels = tunnelsRepository.userTunnelsFlow.firstOrNull() ?: return@collect
|
||||||
|
val tunnelsById = tunnels.associateBy { it.id }
|
||||||
|
|
||||||
|
val relevantIds = previousActiveIds + currentActiveIds
|
||||||
|
|
||||||
|
supervisorScope {
|
||||||
|
relevantIds.forEach { id ->
|
||||||
|
launch {
|
||||||
|
val config = tunnelsById[id] ?: return@launch
|
||||||
|
val wasActive = previousActiveIds.contains(id)
|
||||||
|
val isActive = currentActiveIds.contains(id)
|
||||||
|
if (wasActive != isActive) {
|
||||||
|
tunnelsRepository.save(config.copy(isActive = isActive))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
previousActiveIds = currentActiveIds.toSet()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+123
-60
@@ -1,5 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel.handler
|
||||||
|
|
||||||
|
import android.os.PowerManager
|
||||||
import com.zaneschepke.logcatter.LogReader
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||||
@@ -8,34 +9,107 @@ import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.MonitoringSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.MonitoringSettingsRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.*
|
import com.zaneschepke.wireguardautotunnel.domain.state.FailureReason
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.LogHealthState
|
||||||
|
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.util.extensions.toMillis
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toMillis
|
||||||
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
||||||
import dagger.hilt.android.scopes.ServiceScoped
|
|
||||||
import inet.ipaddr.AddressValueException
|
import inet.ipaddr.AddressValueException
|
||||||
import inet.ipaddr.IPAddress
|
import inet.ipaddr.IPAddress
|
||||||
import inet.ipaddr.IPAddressString
|
import inet.ipaddr.IPAddressString
|
||||||
import io.ktor.util.collections.*
|
import io.ktor.util.collections.ConcurrentMap
|
||||||
import javax.inject.Inject
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.FlowPreview
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.ensureActive
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
|
import kotlinx.coroutines.isActive
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import kotlinx.coroutines.withTimeout
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@ServiceScoped
|
class TunnelMonitorHandler(
|
||||||
class TunnelMonitor
|
private val activeTunnels: StateFlow<Map<Int, TunnelState>>,
|
||||||
@Inject
|
|
||||||
constructor(
|
|
||||||
private val settingsRepository: GeneralSettingRepository,
|
|
||||||
private val tunnelsRepository: TunnelRepository,
|
private val tunnelsRepository: TunnelRepository,
|
||||||
|
private val settingsRepository: GeneralSettingRepository,
|
||||||
private val monitoringSettingsRepository: MonitoringSettingsRepository,
|
private val monitoringSettingsRepository: MonitoringSettingsRepository,
|
||||||
private val networkMonitor: NetworkMonitor,
|
private val networkMonitor: NetworkMonitor,
|
||||||
private val networkUtils: NetworkUtils,
|
private val networkUtils: NetworkUtils,
|
||||||
private val logReader: LogReader,
|
private val logReader: LogReader,
|
||||||
|
private val powerManager: PowerManager,
|
||||||
|
private val getStatistics: (Int) -> TunnelStatistics?,
|
||||||
|
private val updateTunnelStatus:
|
||||||
|
suspend (
|
||||||
|
Int, TunnelStatus?, TunnelStatistics?, Map<String, PingState>?, LogHealthState?,
|
||||||
|
) -> Unit,
|
||||||
|
private val applicationScope: CoroutineScope,
|
||||||
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
) {
|
) {
|
||||||
|
private val mutex = Mutex()
|
||||||
|
private val jobs = ConcurrentHashMap<Int, Job>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
applicationScope.launch(ioDispatcher) {
|
||||||
|
activeTunnels.collect { activeTuns ->
|
||||||
|
mutex.withLock {
|
||||||
|
val activeIds = activeTuns.keys.toSet()
|
||||||
|
(jobs.keys - activeIds).forEach { id ->
|
||||||
|
Timber.d("Shutting down tunnel monitoring job for tunnelId: $id")
|
||||||
|
jobs.remove(id)?.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
val tunnels = tunnelsRepository.flow.firstOrNull() ?: return@collect
|
||||||
|
val tunnelsById = tunnels.associateBy { it.id }
|
||||||
|
|
||||||
|
activeIds.forEach { id ->
|
||||||
|
if (jobs.containsKey(id)) return@forEach
|
||||||
|
val config = tunnelsById[id] ?: return@forEach
|
||||||
|
val settings = settingsRepository.flow.filterNotNull().first()
|
||||||
|
val tunStateFlow =
|
||||||
|
activeTunnels.map { it[id] }.stateIn(applicationScope + ioDispatcher)
|
||||||
|
jobs[id] =
|
||||||
|
applicationScope.launch(ioDispatcher) {
|
||||||
|
Timber.d("Starting tunnel monitoring job for tunnelId: $id")
|
||||||
|
startMonitoring(
|
||||||
|
config = config,
|
||||||
|
withLogs = settings.appMode != AppMode.KERNEL,
|
||||||
|
tunStateFlow = tunStateFlow,
|
||||||
|
getStatistics = { tunnelId -> getStatistics(tunnelId) },
|
||||||
|
updateTunnelStatus = { tid, _, stats, pings, logHealth ->
|
||||||
|
updateTunnelStatus(tid, null, stats, pings, logHealth)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(FlowPreview::class)
|
@OptIn(FlowPreview::class)
|
||||||
suspend fun startMonitoring(
|
private suspend fun startMonitoring(
|
||||||
tunnelId: Int,
|
config: TunnelConfig,
|
||||||
withLogs: Boolean,
|
withLogs: Boolean,
|
||||||
tunStateFlow: StateFlow<TunnelState?>,
|
tunStateFlow: StateFlow<TunnelState?>,
|
||||||
getStatistics: suspend (Int) -> TunnelStatistics?,
|
getStatistics: suspend (Int) -> TunnelStatistics?,
|
||||||
@@ -43,13 +117,10 @@ constructor(
|
|||||||
suspend (
|
suspend (
|
||||||
Int, TunnelStatus?, TunnelStatistics?, Map<String, PingState>?, LogHealthState?,
|
Int, TunnelStatus?, TunnelStatistics?, Map<String, PingState>?, LogHealthState?,
|
||||||
) -> Unit,
|
) -> Unit,
|
||||||
): Job = coroutineScope {
|
) = coroutineScope {
|
||||||
launch {
|
launch { startPingMonitor(config, tunStateFlow, updateTunnelStatus) }
|
||||||
val config = tunnelsRepository.getById(tunnelId) ?: return@launch
|
launch { startWgStatsPoll(config.id, getStatistics, updateTunnelStatus) }
|
||||||
launch { startPingMonitor(config, tunStateFlow, updateTunnelStatus) }
|
if (withLogs) launch { startLogsMonitor(config, updateTunnelStatus) }
|
||||||
launch { startWgStatsPoll(tunnelId, getStatistics, updateTunnelStatus) }
|
|
||||||
if (withLogs) launch { startLogsMonitor(config, updateTunnelStatus) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun startLogsMonitor(
|
private suspend fun startLogsMonitor(
|
||||||
@@ -74,7 +145,7 @@ constructor(
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.distinctUntilChangedBy { it.isHealthy } // Only emit when health changes
|
.distinctUntilChangedBy { it.isHealthy }
|
||||||
.collect { logHealthState ->
|
.collect { logHealthState ->
|
||||||
Timber.d("Tunnel log health updated for ${tunnelConfig.name}: $logHealthState")
|
Timber.d("Tunnel log health updated for ${tunnelConfig.name}: $logHealthState")
|
||||||
updateTunnelStatus(tunnelConfig.id, null, null, null, logHealthState)
|
updateTunnelStatus(tunnelConfig.id, null, null, null, logHealthState)
|
||||||
@@ -93,26 +164,7 @@ constructor(
|
|||||||
|
|
||||||
val connectivityStateFlow = networkMonitor.connectivityStateFlow.stateIn(this)
|
val connectivityStateFlow = networkMonitor.connectivityStateFlow.stateIn(this)
|
||||||
|
|
||||||
val isNetworkConnected = connectivityStateFlow.map { it.hasConnectivity() }.stateIn(this)
|
val isNetworkConnected = connectivityStateFlow.map { it.hasInternet() }.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)
|
|
||||||
|
|
||||||
combine(
|
combine(
|
||||||
settingsRepository.flow.distinctUntilChangedBy { it.appMode },
|
settingsRepository.flow.distinctUntilChangedBy { it.appMode },
|
||||||
@@ -199,6 +251,7 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val attemptTime = System.currentTimeMillis()
|
val attemptTime = System.currentTimeMillis()
|
||||||
|
val timeout = settings.tunnelPingTimeoutSeconds?.toMillis() ?: 5000L
|
||||||
runCatching {
|
runCatching {
|
||||||
withTimeout(
|
withTimeout(
|
||||||
settings.tunnelPingTimeoutSeconds?.toMillis() ?: 5000L
|
settings.tunnelPingTimeoutSeconds?.toMillis() ?: 5000L
|
||||||
@@ -263,27 +316,35 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the tunnel to be fully active
|
// Wait for the tunnel to be fully active
|
||||||
tunStateFlow.filter { state -> state?.status == TunnelStatus.Up }.first()
|
tunStateFlow.filter { state -> state?.status is TunnelStatus.Up }.first()
|
||||||
|
|
||||||
// small delay to make sure tunnel is fully up before we actively monitor
|
// small delay to make sure tunnel is fully up before we actively monitor
|
||||||
delay(3_000L)
|
delay(PING_MONITOR_START_DELAY)
|
||||||
|
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
ensureActive()
|
ensureActive()
|
||||||
if (isNetworkConnected.value) {
|
if (!powerManager.isDeviceIdleMode) {
|
||||||
performPing()
|
if (isNetworkConnected.value) {
|
||||||
} else {
|
performPing()
|
||||||
pingStatsFlow.update { current ->
|
} else {
|
||||||
current.mapValues { entry ->
|
pingStatsFlow.update { current ->
|
||||||
entry.value.copy(
|
current.mapValues { entry ->
|
||||||
isReachable = false,
|
entry.value.copy(
|
||||||
failureReason = FailureReason.NoConnectivity,
|
isReachable = false,
|
||||||
lastPingAttemptMillis = System.currentTimeMillis(),
|
failureReason = FailureReason.NoConnectivity,
|
||||||
)
|
lastPingAttemptMillis = System.currentTimeMillis(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ensureActive()
|
||||||
|
updateTunnelStatus(
|
||||||
|
tunnelConfig.id,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
pingStatsFlow.value,
|
||||||
|
null,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
ensureActive()
|
|
||||||
updateTunnelStatus(tunnelConfig.id, null, null, pingStatsFlow.value, null)
|
|
||||||
}
|
}
|
||||||
delay(settings.tunnelPingIntervalSeconds.toMillis())
|
delay(settings.tunnelPingIntervalSeconds.toMillis())
|
||||||
}
|
}
|
||||||
@@ -300,15 +361,16 @@ constructor(
|
|||||||
) = coroutineScope {
|
) = coroutineScope {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
ensureActive()
|
ensureActive()
|
||||||
val stats = getStatistics(tunnelId)
|
if (!powerManager.isDeviceIdleMode) {
|
||||||
ensureActive()
|
val stats = getStatistics(tunnelId)
|
||||||
updateTunnelStatus(tunnelId, null, stats, null, null)
|
ensureActive()
|
||||||
|
updateTunnelStatus(tunnelId, null, stats, null, null)
|
||||||
|
}
|
||||||
delay(STATS_DELAY)
|
delay(STATS_DELAY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val successLogRegex =
|
private val successLogRegex =
|
||||||
Regex("Received handshake response|Receiving keepalive packet", RegexOption.IGNORE_CASE)
|
Regex("Received handshake response|Receiving keepalive packet", RegexOption.IGNORE_CASE)
|
||||||
|
|
||||||
@@ -323,5 +385,6 @@ constructor(
|
|||||||
const val CLOUDFLARE_IPV6_IP = "2606:4700:4700::1111"
|
const val CLOUDFLARE_IPV6_IP = "2606:4700:4700::1111"
|
||||||
const val CLOUDFLARE_IPV4_IP = "1.1.1.1"
|
const val CLOUDFLARE_IPV4_IP = "1.1.1.1"
|
||||||
const val STATS_DELAY = 1_000L
|
const val STATS_DELAY = 1_000L
|
||||||
|
const val PING_MONITOR_START_DELAY = 5_000L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.core.tunnel.handler
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
class TunnelServiceHandler(
|
||||||
|
private val activeTunnels: StateFlow<Map<Int, TunnelState>>,
|
||||||
|
private val settingsRepository: GeneralSettingRepository,
|
||||||
|
private val serviceManager: ServiceManager,
|
||||||
|
applicationScope: CoroutineScope,
|
||||||
|
ioDispatcher: CoroutineDispatcher,
|
||||||
|
) {
|
||||||
|
init {
|
||||||
|
applicationScope.launch(ioDispatcher) {
|
||||||
|
activeTunnels.collect { activeTuns ->
|
||||||
|
if (activeTuns.isEmpty()) {
|
||||||
|
Timber.d("Stopping tunnel service, no tunnels active.")
|
||||||
|
serviceManager.stopTunnelService()
|
||||||
|
} else if (serviceManager.tunnelService.value == null) {
|
||||||
|
val settings = settingsRepository.flow.firstOrNull() ?: GeneralSettings()
|
||||||
|
Timber.d("Starting tunnel foreground service for active tunnel.")
|
||||||
|
serviceManager.startTunnelService(settings.appMode)
|
||||||
|
}
|
||||||
|
serviceManager.updateTunnelTile()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
-25
@@ -1,31 +1,25 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.worker
|
package com.zaneschepke.wireguardautotunnel.core.worker
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
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.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
||||||
import dagger.assisted.Assisted
|
|
||||||
import dagger.assisted.AssistedInject
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@HiltWorker
|
class ServiceWorker(
|
||||||
class ServiceWorker
|
context: Context,
|
||||||
@AssistedInject
|
params: WorkerParameters,
|
||||||
constructor(
|
|
||||||
@Assisted private val context: Context,
|
|
||||||
@Assisted private val params: WorkerParameters,
|
|
||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
private val autoTunnelSettingsRepository: AutoTunnelSettingsRepository,
|
private val autoTunnelSettingsRepository: AutoTunnelSettingsRepository,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : CoroutineWorker(context, params) {
|
) : CoroutineWorker(context, params) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "service_worker"
|
private const val TAG = "auto_tunnel_service_monitor"
|
||||||
|
|
||||||
fun stop(context: Context) {
|
fun stop(context: Context) {
|
||||||
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
|
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
|
||||||
@@ -47,16 +41,15 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun doWork(): Result =
|
override suspend fun doWork(): Result {
|
||||||
withContext(ioDispatcher) {
|
Timber.i("Service worker started")
|
||||||
Timber.i("Service worker started")
|
with(autoTunnelSettingsRepository.getAutoTunnelSettings()) {
|
||||||
with(autoTunnelSettingsRepository.getAutoTunnelSettings()) {
|
Timber.i("Checking to see if auto-tunnel has been killed by system")
|
||||||
Timber.i("Checking to see if auto-tunnel has been killed by system")
|
if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null) {
|
||||||
if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null) {
|
Timber.i("Service has been killed by system, restoring.")
|
||||||
Timber.i("Service has been killed by system, restoring.")
|
serviceManager.startAutoTunnelService()
|
||||||
serviceManager.startAutoTunnelService()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ import com.zaneschepke.wireguardautotunnel.data.entity.*
|
|||||||
AutoTunnelSettings::class,
|
AutoTunnelSettings::class,
|
||||||
MonitoringSettings::class,
|
MonitoringSettings::class,
|
||||||
DnsSettings::class,
|
DnsSettings::class,
|
||||||
|
LockdownSettings::class,
|
||||||
],
|
],
|
||||||
version = 25,
|
version = 29,
|
||||||
autoMigrations =
|
autoMigrations =
|
||||||
[
|
[
|
||||||
AutoMigration(from = 1, to = 2),
|
AutoMigration(from = 1, to = 2),
|
||||||
@@ -42,6 +43,8 @@ import com.zaneschepke.wireguardautotunnel.data.entity.*
|
|||||||
AutoMigration(from = 21, to = 22),
|
AutoMigration(from = 21, to = 22),
|
||||||
AutoMigration(from = 22, to = 23),
|
AutoMigration(from = 22, to = 23),
|
||||||
AutoMigration(from = 24, to = 25),
|
AutoMigration(from = 24, to = 25),
|
||||||
|
AutoMigration(from = 26, to = 27, spec = GlobalsMigration::class),
|
||||||
|
AutoMigration(from = 27, to = 28, spec = DonationMigration::class),
|
||||||
],
|
],
|
||||||
exportSchema = true,
|
exportSchema = true,
|
||||||
)
|
)
|
||||||
@@ -57,6 +60,8 @@ abstract class AppDatabase : RoomDatabase() {
|
|||||||
|
|
||||||
abstract fun monitoringSettingsDao(): MonitoringSettingsDao
|
abstract fun monitoringSettingsDao(): MonitoringSettingsDao
|
||||||
|
|
||||||
|
abstract fun lockdownSettingsDao(): LockdownSettingsDao
|
||||||
|
|
||||||
abstract fun dnsSettingsDao(): DnsSettingsDao
|
abstract fun dnsSettingsDao(): DnsSettingsDao
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,3 +117,15 @@ class FixProxySettingsMigration : AutoMigrationSpec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RenameColumn.Entries(
|
||||||
|
RenameColumn(
|
||||||
|
tableName = "general_settings",
|
||||||
|
fromColumnName = "is_tunnel_globals_enabled",
|
||||||
|
toColumnName = "global_split_tunnel_enabled",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
class GlobalsMigration : AutoMigrationSpec
|
||||||
|
|
||||||
|
@DeleteColumn(tableName = "general_settings", columnName = "custom_split_packages")
|
||||||
|
class DonationMigration : AutoMigrationSpec
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import androidx.datastore.preferences.core.Preferences
|
|||||||
import androidx.datastore.preferences.core.booleanPreferencesKey
|
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||||
import androidx.datastore.preferences.core.edit
|
import androidx.datastore.preferences.core.edit
|
||||||
import androidx.datastore.preferences.preferencesDataStore
|
import androidx.datastore.preferences.preferencesDataStore
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@@ -17,7 +16,7 @@ import timber.log.Timber
|
|||||||
|
|
||||||
class DataStoreManager(
|
class DataStoreManager(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
) {
|
) {
|
||||||
private val preferencesKey = "preferences"
|
private val preferencesKey = "preferences"
|
||||||
val Context.dataStore by preferencesDataStore(name = preferencesKey)
|
val Context.dataStore by preferencesDataStore(name = preferencesKey)
|
||||||
@@ -26,6 +25,7 @@ class DataStoreManager(
|
|||||||
companion object {
|
companion object {
|
||||||
val locationDisclosureShown = booleanPreferencesKey("LOCATION_DISCLOSURE_SHOWN")
|
val locationDisclosureShown = booleanPreferencesKey("LOCATION_DISCLOSURE_SHOWN")
|
||||||
val batteryDisableShown = booleanPreferencesKey("BATTERY_OPTIMIZE_DISABLE_SHOWN")
|
val batteryDisableShown = booleanPreferencesKey("BATTERY_OPTIMIZE_DISABLE_SHOWN")
|
||||||
|
val shouldShowDonationSnackbar = booleanPreferencesKey("SHOW_DONATION_SNACK")
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun init() {
|
suspend fun init() {
|
||||||
|
|||||||
@@ -2,12 +2,9 @@ package com.zaneschepke.wireguardautotunnel.data
|
|||||||
|
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Provider
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class DatabaseCallback @Inject constructor(private val databaseProvider: Provider<AppDatabase>) :
|
class DatabaseCallback(private val databaseProvider: Lazy<AppDatabase>) : RoomDatabase.Callback() {
|
||||||
RoomDatabase.Callback() {
|
|
||||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||||
super.onCreate(db)
|
super.onCreate(db)
|
||||||
Timber.d("Database created, inserting default rows")
|
Timber.d("Database created, inserting default rows")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import androidx.room.Dao
|
|||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import androidx.room.Upsert
|
import androidx.room.Upsert
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralSettings
|
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralSettings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@@ -15,4 +16,16 @@ interface GeneralSettingsDao {
|
|||||||
|
|
||||||
@Query("SELECT * FROM general_settings LIMIT 1")
|
@Query("SELECT * FROM general_settings LIMIT 1")
|
||||||
fun getGeneralSettingsFlow(): Flow<GeneralSettings?>
|
fun getGeneralSettingsFlow(): Flow<GeneralSettings?>
|
||||||
|
|
||||||
|
@Query("UPDATE general_settings SET theme = :theme WHERE id = 1")
|
||||||
|
suspend fun updateTheme(theme: String)
|
||||||
|
|
||||||
|
@Query("UPDATE general_settings SET locale = :locale WHERE id = 1")
|
||||||
|
suspend fun updateLocale(locale: String)
|
||||||
|
|
||||||
|
@Query("UPDATE general_settings SET is_pin_lock_enabled = :enabled WHERE id = 1")
|
||||||
|
suspend fun updatePinLockEnabled(enabled: Boolean)
|
||||||
|
|
||||||
|
@Query("UPDATE general_settings SET app_mode = :appMode WHERE id = 1")
|
||||||
|
suspend fun updateAppMode(appMode: AppMode)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
import androidx.room.Upsert
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.entity.LockdownSettings
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface LockdownSettingsDao {
|
||||||
|
@Query("SELECT * FROM lockdown_settings LIMIT 1")
|
||||||
|
suspend fun getLockdownSettings(): LockdownSettings?
|
||||||
|
|
||||||
|
@Upsert suspend fun upsert(lockdownSettings: LockdownSettings)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM lockdown_settings LIMIT 1")
|
||||||
|
fun getLockdownSettingsFlow(): Flow<LockdownSettings?>
|
||||||
|
}
|
||||||
@@ -50,23 +50,27 @@ interface TunnelConfigDao {
|
|||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""
|
"""
|
||||||
SELECT * FROM tunnel_config
|
SELECT * FROM tunnel_config
|
||||||
ORDER BY
|
WHERE name != '${TunnelConfig.GLOBAL_CONFIG_NAME}'
|
||||||
CASE WHEN is_primary_tunnel = 1 THEN 0 ELSE 1 END,
|
ORDER BY
|
||||||
position ASC
|
CASE WHEN is_primary_tunnel = 1 THEN 0 ELSE 1 END,
|
||||||
LIMIT 1"""
|
position ASC
|
||||||
|
LIMIT 1
|
||||||
|
"""
|
||||||
)
|
)
|
||||||
suspend fun getDefaultTunnel(): TunnelConfig?
|
suspend fun getDefaultTunnel(): TunnelConfig?
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""
|
"""
|
||||||
SELECT * FROM tunnel_config
|
SELECT * FROM tunnel_config
|
||||||
ORDER BY
|
WHERE name != '${TunnelConfig.GLOBAL_CONFIG_NAME}'
|
||||||
CASE WHEN is_Active = 1 THEN 0
|
ORDER BY
|
||||||
WHEN is_primary_tunnel = 1 THEN 1
|
CASE WHEN is_Active = 1 THEN 0
|
||||||
ELSE 2 END,
|
WHEN is_primary_tunnel = 1 THEN 1
|
||||||
position ASC
|
ELSE 2 END,
|
||||||
LIMIT 1"""
|
position ASC
|
||||||
|
LIMIT 1
|
||||||
|
"""
|
||||||
)
|
)
|
||||||
suspend fun getStartTunnel(): TunnelConfig?
|
suspend fun getStartTunnel(): TunnelConfig?
|
||||||
|
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ package com.zaneschepke.wireguardautotunnel.data.entity
|
|||||||
data class AppState(
|
data class AppState(
|
||||||
val isLocationDisclosureShown: Boolean = false,
|
val isLocationDisclosureShown: Boolean = false,
|
||||||
val isBatteryOptimizationDisableShown: Boolean = false,
|
val isBatteryOptimizationDisableShown: Boolean = false,
|
||||||
|
val shouldShowDonationSnackbar: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ data class DnsSettings(
|
|||||||
@ColumnInfo(name = "dns_protocol", defaultValue = "0")
|
@ColumnInfo(name = "dns_protocol", defaultValue = "0")
|
||||||
val dnsProtocol: DnsProtocol = DnsProtocol.fromValue(0),
|
val dnsProtocol: DnsProtocol = DnsProtocol.fromValue(0),
|
||||||
@ColumnInfo(name = "dns_endpoint") val dnsEndpoint: String? = null,
|
@ColumnInfo(name = "dns_endpoint") val dnsEndpoint: String? = null,
|
||||||
|
@ColumnInfo(name = "global_tunnel_dns_enabled", defaultValue = "0")
|
||||||
|
val isGlobalTunnelDnsEnabled: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-6
@@ -14,8 +14,8 @@ data class GeneralSettings(
|
|||||||
val isRestoreOnBootEnabled: Boolean = false,
|
val isRestoreOnBootEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_multi_tunnel_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_multi_tunnel_enabled", defaultValue = "0")
|
||||||
val isMultiTunnelEnabled: Boolean = false,
|
val isMultiTunnelEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_tunnel_globals_enabled", defaultValue = "0")
|
@ColumnInfo(name = "global_split_tunnel_enabled", defaultValue = "0")
|
||||||
val isTunnelGlobalsEnabled: Boolean = false,
|
val isGlobalSplitTunnelEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "app_mode", defaultValue = "0") val appMode: AppMode = AppMode.fromValue(0),
|
@ColumnInfo(name = "app_mode", defaultValue = "0") val appMode: AppMode = AppMode.fromValue(0),
|
||||||
@ColumnInfo(name = "theme", defaultValue = "AUTOMATIC") val theme: String = "AUTOMATIC",
|
@ColumnInfo(name = "theme", defaultValue = "AUTOMATIC") val theme: String = "AUTOMATIC",
|
||||||
@ColumnInfo(name = "locale") val locale: String? = null,
|
@ColumnInfo(name = "locale") val locale: String? = null,
|
||||||
@@ -26,8 +26,5 @@ data class GeneralSettings(
|
|||||||
val isPinLockEnabled: Boolean = false,
|
val isPinLockEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_always_on_vpn_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_always_on_vpn_enabled", defaultValue = "0")
|
||||||
val isAlwaysOnVpnEnabled: Boolean = false,
|
val isAlwaysOnVpnEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_lan_on_kill_switch_enabled", defaultValue = "0")
|
@ColumnInfo(name = "already_donated", defaultValue = "0") val alreadyDonated: Boolean = false,
|
||||||
val isLanOnKillSwitchEnabled: Boolean = false,
|
|
||||||
@ColumnInfo(name = "custom_split_packages", defaultValue = "{}")
|
|
||||||
val customSplitPackages: Map<String, String> = emptyMap(),
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity(tableName = "lockdown_settings")
|
||||||
|
data class LockdownSettings(
|
||||||
|
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||||
|
@ColumnInfo(name = "bypass_lan", defaultValue = "0") val bypassLan: Boolean = false,
|
||||||
|
@ColumnInfo(name = "metered", defaultValue = "0") val metered: Boolean = false,
|
||||||
|
@ColumnInfo(name = "dual_stack", defaultValue = "0") val dualStack: Boolean = false,
|
||||||
|
)
|
||||||
@@ -28,8 +28,8 @@ data class TunnelConfig(
|
|||||||
@ColumnInfo(name = "position", defaultValue = "0") val position: Int = 0,
|
@ColumnInfo(name = "position", defaultValue = "0") val position: Int = 0,
|
||||||
@ColumnInfo(name = "auto_tunnel_apps", defaultValue = "[]")
|
@ColumnInfo(name = "auto_tunnel_apps", defaultValue = "[]")
|
||||||
val autoTunnelApps: Set<String> = emptySet(),
|
val autoTunnelApps: Set<String> = emptySet(),
|
||||||
|
@ColumnInfo(name = "is_metered", defaultValue = "false") val isMetered: Boolean = false,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val GLOBAL_CONFIG_NAME = "4675ab06-903a-438b-8485-6ea4187a9512"
|
const val GLOBAL_CONFIG_NAME = "4675ab06-903a-438b-8485-6ea4187a9512"
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-2
@@ -4,7 +4,17 @@ import com.zaneschepke.wireguardautotunnel.data.entity.DnsSettings as Entity
|
|||||||
import com.zaneschepke.wireguardautotunnel.domain.model.DnsSettings as Domain
|
import com.zaneschepke.wireguardautotunnel.domain.model.DnsSettings as Domain
|
||||||
|
|
||||||
fun Entity.toDomain(): Domain =
|
fun Entity.toDomain(): Domain =
|
||||||
Domain(id = id, dnsProtocol = dnsProtocol, dnsEndpoint = dnsEndpoint)
|
Domain(
|
||||||
|
id = id,
|
||||||
|
dnsProtocol = dnsProtocol,
|
||||||
|
dnsEndpoint = dnsEndpoint,
|
||||||
|
isGlobalTunnelDnsEnabled = isGlobalTunnelDnsEnabled,
|
||||||
|
)
|
||||||
|
|
||||||
fun Domain.toEntity(): Entity =
|
fun Domain.toEntity(): Entity =
|
||||||
Entity(id = id, dnsProtocol = dnsProtocol, dnsEndpoint = dnsEndpoint)
|
Entity(
|
||||||
|
id = id,
|
||||||
|
dnsProtocol = dnsProtocol,
|
||||||
|
dnsEndpoint = dnsEndpoint,
|
||||||
|
isGlobalTunnelDnsEnabled = isGlobalTunnelDnsEnabled,
|
||||||
|
)
|
||||||
|
|||||||
+1
@@ -7,4 +7,5 @@ fun Entity.toDomain(): Domain =
|
|||||||
Domain(
|
Domain(
|
||||||
isLocationDisclosureShown = isLocationDisclosureShown,
|
isLocationDisclosureShown = isLocationDisclosureShown,
|
||||||
isBatteryOptimizationDisableShown = isBatteryOptimizationDisableShown,
|
isBatteryOptimizationDisableShown = isBatteryOptimizationDisableShown,
|
||||||
|
shouldShowDonationSnackbar = shouldShowDonationSnackbar,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.entity.LockdownSettings as Entity
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.LockdownSettings as Domain
|
||||||
|
|
||||||
|
fun Entity.toDomain(): Domain =
|
||||||
|
Domain(id = id, bypassLan = bypassLan, metered = metered, dualStack = dualStack)
|
||||||
|
|
||||||
|
fun Domain.toEntity(): Entity =
|
||||||
|
Entity(id = id, bypassLan = bypassLan, metered = metered, dualStack = dualStack)
|
||||||
@@ -10,7 +10,7 @@ fun Entity.toDomain(): Domain =
|
|||||||
isShortcutsEnabled = isShortcutsEnabled,
|
isShortcutsEnabled = isShortcutsEnabled,
|
||||||
isRestoreOnBootEnabled = isRestoreOnBootEnabled,
|
isRestoreOnBootEnabled = isRestoreOnBootEnabled,
|
||||||
isMultiTunnelEnabled = isMultiTunnelEnabled,
|
isMultiTunnelEnabled = isMultiTunnelEnabled,
|
||||||
isTunnelGlobalsEnabled = isTunnelGlobalsEnabled,
|
isGlobalSplitTunnelEnabled = isGlobalSplitTunnelEnabled,
|
||||||
appMode = appMode,
|
appMode = appMode,
|
||||||
theme = Theme.valueOf(theme.uppercase()),
|
theme = Theme.valueOf(theme.uppercase()),
|
||||||
locale = locale,
|
locale = locale,
|
||||||
@@ -18,8 +18,7 @@ fun Entity.toDomain(): Domain =
|
|||||||
isRemoteControlEnabled = isRemoteControlEnabled,
|
isRemoteControlEnabled = isRemoteControlEnabled,
|
||||||
isPinLockEnabled = isPinLockEnabled,
|
isPinLockEnabled = isPinLockEnabled,
|
||||||
isAlwaysOnVpnEnabled = isAlwaysOnVpnEnabled,
|
isAlwaysOnVpnEnabled = isAlwaysOnVpnEnabled,
|
||||||
isLanOnKillSwitchEnabled = isLanOnKillSwitchEnabled,
|
alreadyDonated = alreadyDonated,
|
||||||
customSplitPackages = customSplitPackages,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Domain.toEntity(): Entity =
|
fun Domain.toEntity(): Entity =
|
||||||
@@ -28,7 +27,7 @@ fun Domain.toEntity(): Entity =
|
|||||||
isShortcutsEnabled = isShortcutsEnabled,
|
isShortcutsEnabled = isShortcutsEnabled,
|
||||||
isRestoreOnBootEnabled = isRestoreOnBootEnabled,
|
isRestoreOnBootEnabled = isRestoreOnBootEnabled,
|
||||||
isMultiTunnelEnabled = isMultiTunnelEnabled,
|
isMultiTunnelEnabled = isMultiTunnelEnabled,
|
||||||
isTunnelGlobalsEnabled = isTunnelGlobalsEnabled,
|
isGlobalSplitTunnelEnabled = isGlobalSplitTunnelEnabled,
|
||||||
appMode = appMode,
|
appMode = appMode,
|
||||||
theme = theme.name,
|
theme = theme.name,
|
||||||
locale = locale,
|
locale = locale,
|
||||||
@@ -36,6 +35,5 @@ fun Domain.toEntity(): Entity =
|
|||||||
isRemoteControlEnabled = isRemoteControlEnabled,
|
isRemoteControlEnabled = isRemoteControlEnabled,
|
||||||
isPinLockEnabled = isPinLockEnabled,
|
isPinLockEnabled = isPinLockEnabled,
|
||||||
isAlwaysOnVpnEnabled = isAlwaysOnVpnEnabled,
|
isAlwaysOnVpnEnabled = isAlwaysOnVpnEnabled,
|
||||||
isLanOnKillSwitchEnabled = isLanOnKillSwitchEnabled,
|
alreadyDonated = alreadyDonated,
|
||||||
customSplitPackages = customSplitPackages,
|
|
||||||
)
|
)
|
||||||
|
|||||||
+2
@@ -19,6 +19,7 @@ fun Entity.toDomain(): Domain =
|
|||||||
isIpv4Preferred = isIpv4Preferred,
|
isIpv4Preferred = isIpv4Preferred,
|
||||||
position = position,
|
position = position,
|
||||||
autoTunnelApps = autoTunnelApps,
|
autoTunnelApps = autoTunnelApps,
|
||||||
|
isMetered = isMetered,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun Domain.toEntity(): Entity =
|
fun Domain.toEntity(): Entity =
|
||||||
@@ -37,4 +38,5 @@ fun Domain.toEntity(): Entity =
|
|||||||
isIpv4Preferred = isIpv4Preferred,
|
isIpv4Preferred = isIpv4Preferred,
|
||||||
position = position,
|
position = position,
|
||||||
autoTunnelApps = autoTunnelApps,
|
autoTunnelApps = autoTunnelApps,
|
||||||
|
isMetered = isMetered,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -316,3 +316,151 @@ val MIGRATION_23_24 =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val MIGRATION_25_26 =
|
||||||
|
object : Migration(25, 26) {
|
||||||
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
|
db.execSQL(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS `lockdown_settings` (
|
||||||
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
`bypass_lan` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`metered` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`dual_stack` INTEGER NOT NULL DEFAULT 0
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
.trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
val cursor =
|
||||||
|
db.query("SELECT `is_lan_on_kill_switch_enabled` FROM `general_settings` LIMIT 1")
|
||||||
|
var bypassLan = 0
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
bypassLan = if (cursor.getInt(0) != 0) 1 else 0
|
||||||
|
}
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
db.execSQL(
|
||||||
|
"""
|
||||||
|
INSERT INTO `lockdown_settings` (`bypass_lan`, `metered`, `dual_stack`)
|
||||||
|
VALUES (?, 0, 0)
|
||||||
|
"""
|
||||||
|
.trimIndent(),
|
||||||
|
arrayOf(bypassLan),
|
||||||
|
)
|
||||||
|
|
||||||
|
db.execSQL(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS `general_settings_new` (
|
||||||
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
`is_shortcuts_enabled` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`is_tunnel_globals_enabled` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`app_mode` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`theme` TEXT NOT NULL DEFAULT 'AUTOMATIC',
|
||||||
|
`locale` TEXT,
|
||||||
|
`remote_key` TEXT,
|
||||||
|
`is_remote_control_enabled` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`is_pin_lock_enabled` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`is_always_on_vpn_enabled` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
`custom_split_packages` TEXT NOT NULL DEFAULT '{}'
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
.trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
db.execSQL(
|
||||||
|
"""
|
||||||
|
INSERT INTO `general_settings_new` (
|
||||||
|
`id`,
|
||||||
|
`is_shortcuts_enabled`,
|
||||||
|
`is_restore_on_boot_enabled`,
|
||||||
|
`is_multi_tunnel_enabled`,
|
||||||
|
`is_tunnel_globals_enabled`,
|
||||||
|
`app_mode`,
|
||||||
|
`theme`,
|
||||||
|
`locale`,
|
||||||
|
`remote_key`,
|
||||||
|
`is_remote_control_enabled`,
|
||||||
|
`is_pin_lock_enabled`,
|
||||||
|
`is_always_on_vpn_enabled`,
|
||||||
|
`custom_split_packages`
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
`id`,
|
||||||
|
`is_shortcuts_enabled`,
|
||||||
|
`is_restore_on_boot_enabled`,
|
||||||
|
`is_multi_tunnel_enabled`,
|
||||||
|
`is_tunnel_globals_enabled`,
|
||||||
|
`app_mode`,
|
||||||
|
`theme`,
|
||||||
|
`locale`,
|
||||||
|
`remote_key`,
|
||||||
|
`is_remote_control_enabled`,
|
||||||
|
`is_pin_lock_enabled`,
|
||||||
|
`is_always_on_vpn_enabled`,
|
||||||
|
`custom_split_packages`
|
||||||
|
FROM `general_settings`
|
||||||
|
"""
|
||||||
|
.trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
db.execSQL("DROP TABLE `general_settings`")
|
||||||
|
|
||||||
|
db.execSQL("ALTER TABLE `general_settings_new` RENAME TO `general_settings`")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val MIGRATION_28_29 =
|
||||||
|
object : Migration(28, 29) {
|
||||||
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
// Migrate tunnel_config table
|
||||||
|
database.execSQL(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS `tunnel_config_new` (
|
||||||
|
`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 '[]',
|
||||||
|
`is_metered` INTEGER NOT NULL DEFAULT false
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
.trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
database.execSQL(
|
||||||
|
"""
|
||||||
|
INSERT INTO `tunnel_config_new` (
|
||||||
|
`id`, `name`, `wg_quick`, `tunnel_networks`, `is_mobile_data_tunnel`,
|
||||||
|
`is_primary_tunnel`, `am_quick`, `is_Active`, `restart_on_ping_failure`,
|
||||||
|
`ping_target`, `is_ethernet_tunnel`, `is_ipv4_preferred`, `position`,
|
||||||
|
`auto_tunnel_apps`, `is_metered`
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
`id`, `name`, `wg_quick`, `tunnel_networks`, `is_mobile_data_tunnel`,
|
||||||
|
`is_primary_tunnel`, `am_quick`, `is_Active`, `restart_on_ping_failure`,
|
||||||
|
`ping_target`, `is_ethernet_tunnel`, `is_ipv4_preferred`, `position`,
|
||||||
|
`auto_tunnel_apps`, 0 AS `is_metered`
|
||||||
|
FROM `tunnel_config`
|
||||||
|
"""
|
||||||
|
.trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
database.execSQL("DROP TABLE `tunnel_config`")
|
||||||
|
database.execSQL("ALTER TABLE `tunnel_config_new` RENAME TO `tunnel_config`")
|
||||||
|
database.execSQL(
|
||||||
|
"CREATE UNIQUE INDEX IF NOT EXISTS `index_tunnel_config_name` ON `tunnel_config` (`name`)"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ enum class DnsProtocol(val value: Int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class DnsSettings(
|
data class DnsSettings(val protocol: DnsProtocol = DnsProtocol.SYSTEM, val endpoint: String? = null)
|
||||||
val protocol: DnsProtocol = DnsProtocol.SYSTEM,
|
|
||||||
val endpoint: String? = null,
|
|
||||||
)
|
|
||||||
|
|
||||||
enum class DnsProvider(private val systemAddress: String, private val dohAddress: String) {
|
enum class DnsProvider(private val systemAddress: String, private val dohAddress: String) {
|
||||||
CLOUDFLARE("1.1.1.1", "https://1.1.1.1/dns-query"),
|
CLOUDFLARE("1.1.1.1", "https://1.1.1.1/dns-query"),
|
||||||
|
|||||||
+12
-4
@@ -3,8 +3,6 @@ package com.zaneschepke.wireguardautotunnel.data.repository
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.AppState as Entity
|
import com.zaneschepke.wireguardautotunnel.data.entity.AppState as Entity
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppState as Domain
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppState as Domain
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -18,8 +16,8 @@ import timber.log.Timber
|
|||||||
|
|
||||||
class DataStoreAppStateRepository(
|
class DataStoreAppStateRepository(
|
||||||
private val dataStoreManager: DataStoreManager,
|
private val dataStoreManager: DataStoreManager,
|
||||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
applicationScope: CoroutineScope,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
ioDispatcher: CoroutineDispatcher,
|
||||||
) : AppStateRepository {
|
) : AppStateRepository {
|
||||||
override suspend fun isLocationDisclosureShown(): Boolean {
|
override suspend fun isLocationDisclosureShown(): Boolean {
|
||||||
return dataStoreManager.getFromStore(DataStoreManager.locationDisclosureShown) ?: false
|
return dataStoreManager.getFromStore(DataStoreManager.locationDisclosureShown) ?: false
|
||||||
@@ -37,6 +35,14 @@ class DataStoreAppStateRepository(
|
|||||||
dataStoreManager.saveToDataStore(DataStoreManager.batteryDisableShown, shown)
|
dataStoreManager.saveToDataStore(DataStoreManager.batteryDisableShown, shown)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun setShouldShowDonationSnackbar(show: Boolean) {
|
||||||
|
dataStoreManager.saveToDataStore(DataStoreManager.shouldShowDonationSnackbar, show)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun shouldShowDonationSnackbar(): Boolean {
|
||||||
|
return dataStoreManager.getFromStore(DataStoreManager.shouldShowDonationSnackbar) ?: false
|
||||||
|
}
|
||||||
|
|
||||||
override val flow: Flow<Domain> =
|
override val flow: Flow<Domain> =
|
||||||
dataStoreManager.preferencesFlow
|
dataStoreManager.preferencesFlow
|
||||||
.map { prefs ->
|
.map { prefs ->
|
||||||
@@ -47,6 +53,8 @@ class DataStoreAppStateRepository(
|
|||||||
pref[DataStoreManager.locationDisclosureShown] ?: false,
|
pref[DataStoreManager.locationDisclosureShown] ?: false,
|
||||||
isBatteryOptimizationDisableShown =
|
isBatteryOptimizationDisableShown =
|
||||||
pref[DataStoreManager.batteryDisableShown] ?: false,
|
pref[DataStoreManager.batteryDisableShown] ?: false,
|
||||||
|
shouldShowDonationSnackbar =
|
||||||
|
pref[DataStoreManager.shouldShowDonationSnackbar] ?: false,
|
||||||
)
|
)
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
|
|||||||
+34
-19
@@ -4,16 +4,17 @@ 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.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.domain.model.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.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import io.ktor.client.*
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.get
|
||||||
import io.ktor.client.statement.*
|
import io.ktor.client.statement.HttpResponse
|
||||||
import io.ktor.http.*
|
import io.ktor.client.statement.bodyAsChannel
|
||||||
import io.ktor.utils.io.*
|
import io.ktor.http.contentLength
|
||||||
|
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
|
||||||
@@ -25,8 +26,9 @@ class GitHubUpdateRepository(
|
|||||||
private val githubOwner: String,
|
private val githubOwner: String,
|
||||||
private val githubRepo: String,
|
private val githubRepo: String,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : UpdateRepository {
|
) : UpdateRepository {
|
||||||
|
|
||||||
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")
|
||||||
@@ -38,27 +40,40 @@ class GitHubUpdateRepository(
|
|||||||
gitHubApi.getLatestRelease(githubOwner, githubRepo).onFailure(Timber::e)
|
gitHubApi.getLatestRelease(githubOwner, githubRepo).onFailure(Timber::e)
|
||||||
}
|
}
|
||||||
release.map { release ->
|
release.map { release ->
|
||||||
val standaloneApkAsset =
|
val universalApkAsset =
|
||||||
release.assets.find { asset ->
|
release.assets.find { asset ->
|
||||||
asset.name.startsWith("wgtunnel-${Constants.STANDALONE_FLAVOR}-v") &&
|
val prefix = "wgtunnel-${Constants.STANDALONE_FLAVOR}-v"
|
||||||
asset.name.endsWith(".apk")
|
val apkSuffix = ".apk"
|
||||||
|
asset.name.startsWith(prefix) &&
|
||||||
|
asset.name.endsWith(apkSuffix) &&
|
||||||
|
!asset.name.endsWith("-arm64$apkSuffix") &&
|
||||||
|
!asset.name.endsWith("-armv7$apkSuffix")
|
||||||
}
|
}
|
||||||
val newVersion =
|
val newVersion =
|
||||||
standaloneApkAsset
|
universalApkAsset
|
||||||
?.name
|
?.name
|
||||||
?.removePrefix("wgtunnel-${Constants.STANDALONE_FLAVOR}-v")
|
?.removePrefix("wgtunnel-${Constants.STANDALONE_FLAVOR}-v")
|
||||||
?.removeSuffix(".apk") ?: return@map null
|
?.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)
|
if (isNightly) {
|
||||||
return@map GitHubReleaseMapper.toAppUpdate(release, newVersion)
|
if (newVersion != currentVersion) {
|
||||||
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
GitHubReleaseMapper.toAppUpdate(
|
||||||
GitHubReleaseMapper.toAppUpdate(
|
release.copy(assets = listOf(universalApkAsset)),
|
||||||
release.copy(assets = listOf(standaloneApkAsset)),
|
newVersion,
|
||||||
newVersion,
|
)
|
||||||
)
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
null
|
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
||||||
|
GitHubReleaseMapper.toAppUpdate(
|
||||||
|
release.copy(assets = listOf(universalApkAsset)),
|
||||||
|
newVersion,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-39
@@ -1,58 +1,21 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import android.content.IntentFilter
|
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.InstalledPackage
|
import com.zaneschepke.wireguardautotunnel.domain.model.InstalledPackage
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.InstalledPackageRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.InstalledPackageRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.getAllInternetCapablePackages
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.getFriendlyAppName
|
import com.zaneschepke.wireguardautotunnel.util.extensions.getFriendlyAppName
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@Singleton
|
|
||||||
class InstalledAndroidPackageRepository(
|
class InstalledAndroidPackageRepository(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@ApplicationScope val applicationScope: CoroutineScope,
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : InstalledPackageRepository {
|
) : InstalledPackageRepository {
|
||||||
|
|
||||||
private var cachedPackages: List<InstalledPackage>? = null
|
private var cachedPackages: List<InstalledPackage>? = null
|
||||||
|
|
||||||
init {
|
|
||||||
val receiver =
|
|
||||||
object : BroadcastReceiver() {
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
|
||||||
when (intent.action) {
|
|
||||||
Intent.ACTION_PACKAGE_ADDED,
|
|
||||||
Intent.ACTION_PACKAGE_REMOVED,
|
|
||||||
Intent.ACTION_PACKAGE_CHANGED -> {
|
|
||||||
// don't update if we have nothing cached
|
|
||||||
if (cachedPackages == null) return
|
|
||||||
Timber.d("Updating installed packages cache")
|
|
||||||
applicationScope.launch { refreshInstalledPackages() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val filter =
|
|
||||||
IntentFilter().apply {
|
|
||||||
addAction(Intent.ACTION_PACKAGE_ADDED)
|
|
||||||
addAction(Intent.ACTION_PACKAGE_REMOVED)
|
|
||||||
addAction(Intent.ACTION_PACKAGE_CHANGED)
|
|
||||||
addDataScheme("package")
|
|
||||||
}
|
|
||||||
context.registerReceiver(receiver, filter)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getInstalledPackages(): List<InstalledPackage> =
|
override suspend fun getInstalledPackages(): List<InstalledPackage> =
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
cachedPackages?.let {
|
cachedPackages?.let {
|
||||||
@@ -63,7 +26,7 @@ class InstalledAndroidPackageRepository(
|
|||||||
|
|
||||||
override suspend fun refreshInstalledPackages(): List<InstalledPackage> =
|
override suspend fun refreshInstalledPackages(): List<InstalledPackage> =
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
val packages = context.getAllInternetCapablePackages()
|
val packages = context.packageManager.getInstalledPackages(0)
|
||||||
|
|
||||||
val installedPackages =
|
val installedPackages =
|
||||||
packages.mapNotNull { packageInfo ->
|
packages.mapNotNull { packageInfo ->
|
||||||
|
|||||||
+3
-11
@@ -4,28 +4,20 @@ import com.zaneschepke.wireguardautotunnel.data.dao.AutoTunnelSettingsDao
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.entity.AutoTunnelSettings as Entity
|
import com.zaneschepke.wireguardautotunnel.data.entity.AutoTunnelSettings as Entity
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.AutoTunnelSettings as Domain
|
import com.zaneschepke.wireguardautotunnel.domain.model.AutoTunnelSettings as Domain
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
class RoomAutoTunnelSettingsRepository(
|
class RoomAutoTunnelSettingsRepository(private val autoTunnelSettingsDao: AutoTunnelSettingsDao) :
|
||||||
private val autoTunnelSettingsDao: AutoTunnelSettingsDao,
|
AutoTunnelSettingsRepository {
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : AutoTunnelSettingsRepository {
|
|
||||||
override suspend fun upsert(autoTunnelSettings: Domain) {
|
override suspend fun upsert(autoTunnelSettings: Domain) {
|
||||||
autoTunnelSettingsDao.upsert(autoTunnelSettings.toEntity())
|
autoTunnelSettingsDao.upsert(autoTunnelSettings.toEntity())
|
||||||
}
|
}
|
||||||
|
|
||||||
override val flow: Flow<Domain>
|
override val flow: Flow<Domain>
|
||||||
get() =
|
get() =
|
||||||
autoTunnelSettingsDao
|
autoTunnelSettingsDao.getAutoTunnelSettingsFlow().map { (it ?: Entity()).toDomain() }
|
||||||
.getAutoTunnelSettingsFlow()
|
|
||||||
.map { (it ?: Entity()).toDomain() }
|
|
||||||
.flowOn(ioDispatcher)
|
|
||||||
|
|
||||||
override suspend fun getAutoTunnelSettings(): Domain {
|
override suspend fun getAutoTunnelSettings(): Domain {
|
||||||
return (autoTunnelSettingsDao.getAutoTunnelSettings() ?: Entity()).toDomain()
|
return (autoTunnelSettingsDao.getAutoTunnelSettings() ?: Entity()).toDomain()
|
||||||
|
|||||||
+3
-12
@@ -4,28 +4,19 @@ import com.zaneschepke.wireguardautotunnel.data.dao.DnsSettingsDao
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.entity.DnsSettings as Entity
|
import com.zaneschepke.wireguardautotunnel.data.entity.DnsSettings as Entity
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.DnsSettings as Domain
|
import com.zaneschepke.wireguardautotunnel.domain.model.DnsSettings as Domain
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.DnsSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.DnsSettingsRepository
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
class RoomDnsSettingsRepository(
|
class RoomDnsSettingsRepository(private val dnsSettingsDao: DnsSettingsDao) :
|
||||||
private val dnsSettingsDao: DnsSettingsDao,
|
DnsSettingsRepository {
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : DnsSettingsRepository {
|
|
||||||
override suspend fun upsert(dnsSettings: Domain) {
|
override suspend fun upsert(dnsSettings: Domain) {
|
||||||
dnsSettingsDao.upsert(dnsSettings.toEntity())
|
dnsSettingsDao.upsert(dnsSettings.toEntity())
|
||||||
}
|
}
|
||||||
|
|
||||||
override val flow: Flow<Domain>
|
override val flow: Flow<Domain>
|
||||||
get() =
|
get() = dnsSettingsDao.getDnsSettingsFlow().map { (it ?: Entity()).toDomain() }
|
||||||
dnsSettingsDao
|
|
||||||
.getDnsSettingsFlow()
|
|
||||||
.map { (it ?: Entity()).toDomain() }
|
|
||||||
.flowOn(ioDispatcher)
|
|
||||||
|
|
||||||
override suspend fun getDnsSettings(): Domain {
|
override suspend fun getDnsSettings(): Domain {
|
||||||
return (dnsSettingsDao.getDnsSettings() ?: Entity()).toDomain()
|
return (dnsSettingsDao.getDnsSettings() ?: Entity()).toDomain()
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.dao.LockdownSettingsDao
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.entity.LockdownSettings as Entity
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.LockdownSettings as Domain
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.LockdownSettingsRepository
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
|
class RoomLockdownSettingsRepository(private val lockdownSettingsDao: LockdownSettingsDao) :
|
||||||
|
LockdownSettingsRepository {
|
||||||
|
override suspend fun upsert(lockdownSettings: Domain) {
|
||||||
|
lockdownSettingsDao.upsert(lockdownSettings.toEntity())
|
||||||
|
}
|
||||||
|
|
||||||
|
override val flow =
|
||||||
|
lockdownSettingsDao.getLockdownSettingsFlow().map { (it ?: Entity()).toDomain() }
|
||||||
|
|
||||||
|
override suspend fun getLockdownSettings(): Domain {
|
||||||
|
return (lockdownSettingsDao.getLockdownSettings() ?: Entity()).toDomain()
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-11
@@ -4,28 +4,20 @@ import com.zaneschepke.wireguardautotunnel.data.dao.MonitoringSettingsDao
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.entity.MonitoringSettings as Entity
|
import com.zaneschepke.wireguardautotunnel.data.entity.MonitoringSettings as Entity
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.MonitoringSettings as Domain
|
import com.zaneschepke.wireguardautotunnel.domain.model.MonitoringSettings as Domain
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.MonitoringSettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.MonitoringSettingsRepository
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
class RoomMonitoringSettingsRepository(
|
class RoomMonitoringSettingsRepository(private val monitoringSettingsDao: MonitoringSettingsDao) :
|
||||||
private val monitoringSettingsDao: MonitoringSettingsDao,
|
MonitoringSettingsRepository {
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : MonitoringSettingsRepository {
|
|
||||||
override suspend fun upsert(monitoringSettings: Domain) {
|
override suspend fun upsert(monitoringSettings: Domain) {
|
||||||
monitoringSettingsDao.upsert(monitoringSettings.toEntity())
|
monitoringSettingsDao.upsert(monitoringSettings.toEntity())
|
||||||
}
|
}
|
||||||
|
|
||||||
override val flow: Flow<Domain>
|
override val flow: Flow<Domain>
|
||||||
get() =
|
get() =
|
||||||
monitoringSettingsDao
|
monitoringSettingsDao.getMonitoringSettingsFlow().map { (it ?: Entity()).toDomain() }
|
||||||
.getMonitoringSettingsFlow()
|
|
||||||
.map { (it ?: Entity()).toDomain() }
|
|
||||||
.flowOn(ioDispatcher)
|
|
||||||
|
|
||||||
override suspend fun getMonitoringSettings(): Domain {
|
override suspend fun getMonitoringSettings(): Domain {
|
||||||
return (monitoringSettingsDao.getMonitoringSettings() ?: Entity()).toDomain()
|
return (monitoringSettingsDao.getMonitoringSettings() ?: Entity()).toDomain()
|
||||||
|
|||||||
+6
-18
@@ -4,32 +4,20 @@ import com.zaneschepke.wireguardautotunnel.data.dao.ProxySettingsDao
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.entity.ProxySettings as Entity
|
import com.zaneschepke.wireguardautotunnel.data.entity.ProxySettings as Entity
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.ProxySettings as Domain
|
import com.zaneschepke.wireguardautotunnel.domain.model.ProxySettings as Domain
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.ProxySettingsRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.ProxySettingsRepository
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
class RoomProxySettingsRepository(
|
class RoomProxySettingsRepository(private val proxySettingsDao: ProxySettingsDao) :
|
||||||
private val proxySettingsDao: ProxySettingsDao,
|
ProxySettingsRepository {
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : ProxySettingsRepository {
|
|
||||||
override suspend fun upsert(proxySettings: Domain) {
|
override suspend fun upsert(proxySettings: Domain) {
|
||||||
withContext(ioDispatcher) { proxySettingsDao.upsert(proxySettings.toEntity()) }
|
proxySettingsDao.upsert(proxySettings.toEntity())
|
||||||
}
|
}
|
||||||
|
|
||||||
override val flow =
|
override val flow = proxySettingsDao.getProxySettingsFlow().map { (it ?: Entity()).toDomain() }
|
||||||
proxySettingsDao
|
|
||||||
.getProxySettingsFlow()
|
|
||||||
.flowOn(ioDispatcher)
|
|
||||||
.map { (it ?: Entity()).toDomain() }
|
|
||||||
.flowOn(ioDispatcher)
|
|
||||||
|
|
||||||
override suspend fun getProxySettings(): Domain {
|
override suspend fun getProxySettings(): Domain {
|
||||||
return withContext(ioDispatcher) {
|
return (proxySettingsDao.getProxySettings() ?: Entity()).toDomain()
|
||||||
(proxySettingsDao.getProxySettings() ?: Entity()).toDomain()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-18
@@ -4,32 +4,37 @@ import com.zaneschepke.wireguardautotunnel.data.dao.GeneralSettingsDao
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralSettings as Entity
|
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralSettings as Entity
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings as Domain
|
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings as Domain
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
class RoomSettingsRepository(
|
|
||||||
private val settingsDoa: GeneralSettingsDao,
|
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : GeneralSettingRepository {
|
|
||||||
|
|
||||||
|
class RoomSettingsRepository(private val settingsDao: GeneralSettingsDao) :
|
||||||
|
GeneralSettingRepository {
|
||||||
override suspend fun upsert(generalSettings: Domain) {
|
override suspend fun upsert(generalSettings: Domain) {
|
||||||
withContext(ioDispatcher) { settingsDoa.upsert(generalSettings.toEntity()) }
|
settingsDao.upsert(generalSettings.toEntity())
|
||||||
}
|
}
|
||||||
|
|
||||||
override val flow =
|
override val flow = settingsDao.getGeneralSettingsFlow().map { (it ?: Entity()).toDomain() }
|
||||||
settingsDoa
|
|
||||||
.getGeneralSettingsFlow()
|
|
||||||
.map { (it ?: Entity()).toDomain() }
|
|
||||||
.flowOn(ioDispatcher)
|
|
||||||
|
|
||||||
override suspend fun getGeneralSettings(): Domain {
|
override suspend fun getGeneralSettings(): Domain {
|
||||||
return withContext(ioDispatcher) {
|
return (settingsDao.getGeneralSettings() ?: Entity()).toDomain()
|
||||||
(settingsDoa.getGeneralSettings() ?: Entity()).toDomain()
|
}
|
||||||
}
|
|
||||||
|
override suspend fun updateTheme(theme: Theme) {
|
||||||
|
settingsDao.updateTheme(theme.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateLocale(locale: String) {
|
||||||
|
settingsDao.updateLocale(locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updatePinLockEnabled(enabled: Boolean) {
|
||||||
|
settingsDao.updatePinLockEnabled(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateAppMode(appMode: AppMode) {
|
||||||
|
settingsDao.updateAppMode(appMode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-48
@@ -3,119 +3,96 @@ 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.mapper.toDomain
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toDomain
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
import com.zaneschepke.wireguardautotunnel.data.mapper.toEntity
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig as Domain
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig as Domain
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
class RoomTunnelRepository(
|
class RoomTunnelRepository(private val tunnelConfigDao: TunnelConfigDao) : TunnelRepository {
|
||||||
private val tunnelConfigDao: TunnelConfigDao,
|
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : TunnelRepository {
|
|
||||||
|
|
||||||
override val flow =
|
override val flow =
|
||||||
tunnelConfigDao.getAllFlow().flowOn(ioDispatcher).map {
|
tunnelConfigDao.getAllFlow().map { it.map { tunnelConfig -> tunnelConfig.toDomain() } }
|
||||||
it.map { tunnelConfig -> tunnelConfig.toDomain() }
|
|
||||||
}
|
|
||||||
|
|
||||||
override val userTunnelsFlow =
|
override val userTunnelsFlow =
|
||||||
tunnelConfigDao.getAllTunnelsExceptGlobal().flowOn(ioDispatcher).map {
|
tunnelConfigDao.getAllTunnelsExceptGlobal().map {
|
||||||
it.map { tunnelConfig -> tunnelConfig.toDomain() }
|
it.map { tunnelConfig -> tunnelConfig.toDomain() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override val globalTunnelFlow: Flow<Domain?> =
|
override val globalTunnelFlow: Flow<Domain?> =
|
||||||
tunnelConfigDao.getGlobalTunnel().flowOn(ioDispatcher).map { it?.toDomain() }
|
tunnelConfigDao.getGlobalTunnel().map { it?.toDomain() }
|
||||||
|
|
||||||
override suspend fun getAll(): List<Domain> {
|
override suspend fun getAll(): List<Domain> {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.getAll().map { it.toDomain() } }
|
return tunnelConfigDao.getAll().map { it.toDomain() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun save(tunnelConfig: Domain) {
|
override suspend fun save(tunnelConfig: Domain) {
|
||||||
withContext(ioDispatcher) { tunnelConfigDao.upsert(tunnelConfig.toEntity()) }
|
tunnelConfigDao.upsert(tunnelConfig.toEntity())
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun saveAll(tunnelConfigList: List<Domain>) {
|
override suspend fun saveAll(tunnelConfigList: List<Domain>) {
|
||||||
withContext(ioDispatcher) {
|
tunnelConfigDao.saveAll(tunnelConfigList.map { tunnelConfig -> tunnelConfig.toEntity() })
|
||||||
tunnelConfigDao.saveAll(
|
|
||||||
tunnelConfigList.map { tunnelConfig -> tunnelConfig.toEntity() }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updatePrimaryTunnel(tunnelConfig: Domain?) {
|
override suspend fun updatePrimaryTunnel(tunnelConfig: Domain?) {
|
||||||
withContext(ioDispatcher) {
|
tunnelConfigDao.resetPrimaryTunnel()
|
||||||
tunnelConfigDao.resetPrimaryTunnel()
|
tunnelConfig?.let { save(it.copy(isPrimaryTunnel = true)) }
|
||||||
tunnelConfig?.let { save(it.copy(isPrimaryTunnel = true)) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resetActiveTunnels() {
|
override suspend fun resetActiveTunnels() {
|
||||||
withContext(ioDispatcher) { tunnelConfigDao.resetActiveTunnels() }
|
tunnelConfigDao.resetActiveTunnels()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateMobileDataTunnel(tunnelConfig: Domain?) {
|
override suspend fun updateMobileDataTunnel(tunnelConfig: Domain?) {
|
||||||
withContext(ioDispatcher) {
|
tunnelConfigDao.resetMobileDataTunnel()
|
||||||
tunnelConfigDao.resetMobileDataTunnel()
|
tunnelConfig?.let { save(it.copy(isMobileDataTunnel = true)) }
|
||||||
tunnelConfig?.let { save(it.copy(isMobileDataTunnel = true)) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateEthernetTunnel(tunnelConfig: Domain?) {
|
override suspend fun updateEthernetTunnel(tunnelConfig: Domain?) {
|
||||||
withContext(ioDispatcher) {
|
tunnelConfigDao.resetEthernetTunnel()
|
||||||
tunnelConfigDao.resetEthernetTunnel()
|
tunnelConfig?.let { save(it.copy(isEthernetTunnel = true)) }
|
||||||
tunnelConfig?.let { save(it.copy(isEthernetTunnel = true)) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun delete(tunnelConfig: Domain) {
|
override suspend fun delete(tunnelConfig: Domain) {
|
||||||
withContext(ioDispatcher) { tunnelConfigDao.delete(tunnelConfig.toEntity()) }
|
tunnelConfigDao.delete(tunnelConfig.toEntity())
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getById(id: Int): Domain? {
|
override suspend fun getById(id: Int): Domain? {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.getById(id.toLong())?.toDomain() }
|
return tunnelConfigDao.getById(id.toLong())?.toDomain()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getActive(): List<Domain> {
|
override suspend fun getActive(): List<Domain> {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.getActive().map { it.toDomain() } }
|
return tunnelConfigDao.getActive().map { it.toDomain() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getDefaultTunnel(): Domain? {
|
override suspend fun getDefaultTunnel(): Domain? {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.getDefaultTunnel()?.toDomain() }
|
return tunnelConfigDao.getDefaultTunnel()?.toDomain()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getStartTunnel(): Domain? {
|
override suspend fun getStartTunnel(): Domain? {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.getStartTunnel()?.toDomain() }
|
return tunnelConfigDao.getStartTunnel()?.toDomain()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun count(): Int {
|
override suspend fun count(): Int {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.count().toInt() }
|
return tunnelConfigDao.count().toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByTunnelName(name: String): Domain? {
|
override suspend fun findByTunnelName(name: String): Domain? {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.getByName(name)?.toDomain() }
|
return tunnelConfigDao.getByName(name)?.toDomain()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByTunnelNetworksName(name: String): List<Domain> {
|
override suspend fun findByTunnelNetworksName(name: String): List<Domain> {
|
||||||
return withContext(ioDispatcher) {
|
return tunnelConfigDao.findByTunnelNetworkName(name).map { it.toDomain() }
|
||||||
tunnelConfigDao.findByTunnelNetworkName(name).map { it.toDomain() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByMobileDataTunnel(): List<Domain> {
|
override suspend fun findByMobileDataTunnel(): List<Domain> {
|
||||||
return withContext(ioDispatcher) {
|
return tunnelConfigDao.findByMobileDataTunnel().map { it.toDomain() }
|
||||||
tunnelConfigDao.findByMobileDataTunnel().map { it.toDomain() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findPrimary(): List<Domain> {
|
override suspend fun findPrimary(): List<Domain> {
|
||||||
return withContext(ioDispatcher) { tunnelConfigDao.findByPrimary().map { it.toDomain() } }
|
return tunnelConfigDao.findByPrimary().map { it.toDomain() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun delete(tunnels: List<Domain>) {
|
override suspend fun delete(tunnels: List<Domain>) {
|
||||||
withContext(ioDispatcher) { tunnelConfigDao.delete(tunnels.map { it.toEntity() }) }
|
tunnelConfigDao.delete(tunnels.map { it.toEntity() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,69 +1,92 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.di
|
package com.zaneschepke.wireguardautotunnel.di
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.PowerManager
|
||||||
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.NotificationMonitor
|
||||||
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.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.domain.repository.GlobalEffectRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.SelectedTunnelsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.FileUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
||||||
import dagger.Module
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AutoTunnelViewModel
|
||||||
import dagger.Provides
|
import com.zaneschepke.wireguardautotunnel.viewmodel.ConfigViewModel
|
||||||
import dagger.hilt.InstallIn
|
import com.zaneschepke.wireguardautotunnel.viewmodel.DnsViewModel
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import com.zaneschepke.wireguardautotunnel.viewmodel.LicenseViewModel
|
||||||
import dagger.hilt.components.SingletonComponent
|
import com.zaneschepke.wireguardautotunnel.viewmodel.LockdownViewModel
|
||||||
import javax.inject.Singleton
|
import com.zaneschepke.wireguardautotunnel.viewmodel.LoggerViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.MonitoringViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.ProxySettingsViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.SettingsViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.SharedAppViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.SplitTunnelViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.SupportViewModel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.viewmodel.TunnelViewModel
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.core.annotation.KoinExperimentalAPI
|
||||||
|
import org.koin.core.module.dsl.scopedOf
|
||||||
|
import org.koin.core.module.dsl.singleOf
|
||||||
|
import org.koin.core.module.dsl.viewModel
|
||||||
|
import org.koin.core.module.dsl.viewModelOf
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
|
import org.koin.dsl.bind
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import org.koin.viewmodel.scope.viewModelScope
|
||||||
|
|
||||||
@Module
|
@OptIn(KoinExperimentalAPI::class)
|
||||||
@InstallIn(SingletonComponent::class)
|
val appModule = module {
|
||||||
class AppModule {
|
single<CoroutineScope>(named(Scope.APPLICATION)) {
|
||||||
|
CoroutineScope(SupervisorJob() + get<CoroutineDispatcher>(named(Dispatcher.DEFAULT)))
|
||||||
@Singleton
|
|
||||||
@ApplicationScope
|
|
||||||
@Provides
|
|
||||||
fun providesApplicationScope(
|
|
||||||
@DefaultDispatcher defaultDispatcher: CoroutineDispatcher
|
|
||||||
): CoroutineScope = CoroutineScope(SupervisorJob() + defaultDispatcher)
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideLogCollect(@ApplicationContext context: Context): LogReader {
|
|
||||||
return LogcatReader.init(storageDir = context.filesDir.absolutePath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
single<LogReader> { LogcatReader.init(storageDir = androidContext().filesDir.absolutePath) }
|
||||||
@Provides
|
|
||||||
fun provideNotificationService(@ApplicationContext context: Context): NotificationManager {
|
single<PowerManager> {
|
||||||
return WireGuardNotification(context)
|
androidContext().getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
|
}
|
||||||
|
singleOf(::NotificationMonitor)
|
||||||
|
singleOf(::WireGuardNotification) bind NotificationManager::class
|
||||||
|
single {
|
||||||
|
ServiceManager(
|
||||||
|
androidContext(),
|
||||||
|
get(named(Dispatcher.IO)),
|
||||||
|
get(named(Scope.APPLICATION)),
|
||||||
|
get(named(Dispatcher.MAIN)),
|
||||||
|
get(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
singleOf(::GlobalEffectRepository)
|
||||||
@Provides
|
|
||||||
fun provideShortcutManager(
|
viewModelScope {
|
||||||
@ApplicationContext context: Context,
|
scoped { FileUtils(androidContext(), get(named(Dispatcher.IO))) }
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
scoped<ShortcutManager> {
|
||||||
): ShortcutManager {
|
DynamicShortcutManager(androidContext(), get(named(Dispatcher.IO)))
|
||||||
return DynamicShortcutManager(context, ioDispatcher)
|
}
|
||||||
|
scopedOf(::SelectedTunnelsRepository)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
single { NetworkUtils(get(named(Dispatcher.IO))) }
|
||||||
@Provides
|
|
||||||
fun provideNetworkUtils(@IoDispatcher ioDispatcher: CoroutineDispatcher): NetworkUtils {
|
|
||||||
return NetworkUtils(ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
viewModelOf(::AutoTunnelViewModel)
|
||||||
@Provides
|
viewModel { (id: Int) -> ConfigViewModel(get(), get(), get(), id) }
|
||||||
fun provideNotificationMonitor(
|
viewModelOf(::DnsViewModel)
|
||||||
tunnelManager: TunnelManager,
|
viewModelOf(::LicenseViewModel)
|
||||||
notificationManager: NotificationManager,
|
viewModelOf(::LockdownViewModel)
|
||||||
): NotificationMonitor {
|
viewModelOf(::LoggerViewModel)
|
||||||
return NotificationMonitor(tunnelManager, notificationManager)
|
viewModelOf(::MonitoringViewModel)
|
||||||
}
|
viewModelOf(::ProxySettingsViewModel)
|
||||||
|
viewModelOf(::SettingsViewModel)
|
||||||
|
viewModelOf(::SharedAppViewModel)
|
||||||
|
viewModel { (id: Int) -> SplitTunnelViewModel(get(), get(), get(), id) }
|
||||||
|
viewModel { SupportViewModel(get(), get(named(Dispatcher.MAIN)), get()) }
|
||||||
|
viewModel { (id: Int) -> TunnelViewModel(get(), get(), id) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.di
|
|
||||||
|
|
||||||
import javax.inject.Qualifier
|
|
||||||
|
|
||||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class TunnelShell
|
|
||||||
|
|
||||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class AppShell
|
|
||||||
|
|
||||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class Kernel
|
|
||||||
|
|
||||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class Userspace
|
|
||||||
|
|
||||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class ProxyUserspace
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.di
|
|
||||||
|
|
||||||
import javax.inject.Qualifier
|
|
||||||
|
|
||||||
@Retention(AnnotationRetention.BINARY) @Qualifier annotation class DefaultDispatcher
|
|
||||||
|
|
||||||
@Retention(AnnotationRetention.BINARY) @Qualifier annotation class IoDispatcher
|
|
||||||
|
|
||||||
@Retention(AnnotationRetention.BINARY) @Qualifier annotation class MainDispatcher
|
|
||||||
|
|
||||||
@Retention(AnnotationRetention.BINARY) @Qualifier annotation class MainImmediateDispatcher
|
|
||||||
|
|
||||||
@Retention(AnnotationRetention.BINARY) @Qualifier annotation class ApplicationScope
|
|
||||||
|
|
||||||
@Retention(AnnotationRetention.BINARY) @Qualifier annotation class ServiceScope
|
|
||||||
-24
@@ -1,24 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.di
|
|
||||||
|
|
||||||
import dagger.Module
|
|
||||||
import dagger.Provides
|
|
||||||
import dagger.hilt.InstallIn
|
|
||||||
import dagger.hilt.components.SingletonComponent
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
|
|
||||||
@Module
|
|
||||||
@InstallIn(SingletonComponent::class)
|
|
||||||
object CoroutinesDispatchersModule {
|
|
||||||
@DefaultDispatcher
|
|
||||||
@Provides
|
|
||||||
fun providesDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default
|
|
||||||
|
|
||||||
@IoDispatcher @Provides fun providesIoDispatcher(): CoroutineDispatcher = Dispatchers.IO
|
|
||||||
|
|
||||||
@MainDispatcher @Provides fun providesMainDispatcher(): CoroutineDispatcher = Dispatchers.Main
|
|
||||||
|
|
||||||
@MainImmediateDispatcher
|
|
||||||
@Provides
|
|
||||||
fun providesMainImmediateDispatcher(): CoroutineDispatcher = Dispatchers.Main.immediate
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.DatabaseCallback
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.migrations.MIGRATION_23_24
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.migrations.MIGRATION_25_26
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.migrations.MIGRATION_28_29
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.DataStoreAppStateRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.InstalledAndroidPackageRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.RoomAutoTunnelSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.RoomDnsSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.RoomLockdownSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.RoomMonitoringSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.RoomProxySettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.RoomSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.RoomTunnelRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.DnsSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.InstalledPackageRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.LockdownSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.MonitoringSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.ProxySettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.core.module.dsl.singleOf
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
|
import org.koin.dsl.bind
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val databaseModule = module {
|
||||||
|
single<RoomDatabase.Callback> { DatabaseCallback(lazy { get() }) }
|
||||||
|
|
||||||
|
single {
|
||||||
|
Room.databaseBuilder(
|
||||||
|
androidContext(),
|
||||||
|
AppDatabase::class.java,
|
||||||
|
get<Context>().getString(R.string.db_name),
|
||||||
|
)
|
||||||
|
.addMigrations(
|
||||||
|
MIGRATION_23_24(get<DataStoreManager>().dataStore),
|
||||||
|
MIGRATION_25_26,
|
||||||
|
MIGRATION_28_29,
|
||||||
|
)
|
||||||
|
.fallbackToDestructiveMigration(true)
|
||||||
|
.addCallback(get())
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
single { get<AppDatabase>().generalSettingsDao() }
|
||||||
|
single { get<AppDatabase>().lockdownSettingsDao() }
|
||||||
|
single { get<AppDatabase>().dnsSettingsDao() }
|
||||||
|
single { get<AppDatabase>().autoTunnelSettingsDao() }
|
||||||
|
single { get<AppDatabase>().monitoringSettingsDao() }
|
||||||
|
single { get<AppDatabase>().proxySettingsDoa() }
|
||||||
|
single { get<AppDatabase>().tunnelConfigDoa() }
|
||||||
|
|
||||||
|
single { DataStoreManager(androidContext(), get(named(Dispatcher.IO))) }
|
||||||
|
|
||||||
|
single<AppStateRepository> {
|
||||||
|
DataStoreAppStateRepository(get(), get(named(Scope.APPLICATION)), get(named(Dispatcher.IO)))
|
||||||
|
}
|
||||||
|
singleOf(::RoomAutoTunnelSettingsRepository) bind AutoTunnelSettingsRepository::class
|
||||||
|
singleOf(::RoomDnsSettingsRepository) bind DnsSettingsRepository::class
|
||||||
|
singleOf(::RoomLockdownSettingsRepository) bind LockdownSettingsRepository::class
|
||||||
|
singleOf(::RoomMonitoringSettingsRepository) bind MonitoringSettingsRepository::class
|
||||||
|
singleOf(::RoomProxySettingsRepository) bind ProxySettingsRepository::class
|
||||||
|
singleOf(::RoomSettingsRepository) bind GeneralSettingRepository::class
|
||||||
|
singleOf(::RoomTunnelRepository) bind TunnelRepository::class
|
||||||
|
single<InstalledPackageRepository> {
|
||||||
|
InstalledAndroidPackageRepository(androidContext(), get(named(Dispatcher.IO)))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.di
|
||||||
|
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val dispatchersModule = module {
|
||||||
|
single<CoroutineDispatcher>(named(Dispatcher.DEFAULT)) { Dispatchers.Default }
|
||||||
|
single<CoroutineDispatcher>(named(Dispatcher.IO)) { Dispatchers.IO }
|
||||||
|
single<CoroutineDispatcher>(named(Dispatcher.MAIN)) { Dispatchers.Main }
|
||||||
|
single<CoroutineDispatcher>(named(Dispatcher.MAIN_IMMEDIATE)) { Dispatchers.Main.immediate }
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.di
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.network.KtorClient
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.network.KtorGitHubApi
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.GitHubUpdateRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.core.module.dsl.singleOf
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
|
import org.koin.dsl.bind
|
||||||
|
import org.koin.dsl.lazyModule
|
||||||
|
|
||||||
|
val networkModule = lazyModule {
|
||||||
|
single { KtorClient.create() }
|
||||||
|
singleOf(::KtorGitHubApi) bind GitHubApi::class
|
||||||
|
|
||||||
|
single<UpdateRepository> {
|
||||||
|
val appName = "wgtunnel"
|
||||||
|
GitHubUpdateRepository(
|
||||||
|
get(),
|
||||||
|
get(),
|
||||||
|
appName,
|
||||||
|
appName,
|
||||||
|
androidContext(),
|
||||||
|
get(named(Dispatcher.IO)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.di
|
||||||
|
|
||||||
|
// Dispatchers
|
||||||
|
enum class Dispatcher {
|
||||||
|
MAIN,
|
||||||
|
IO,
|
||||||
|
DEFAULT,
|
||||||
|
MAIN_IMMEDIATE,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scopes
|
||||||
|
enum class Scope {
|
||||||
|
APPLICATION
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Shell {
|
||||||
|
APP,
|
||||||
|
TUNNEL,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Core {
|
||||||
|
KERNEL,
|
||||||
|
PROXY_USERSPACE,
|
||||||
|
USERSPACE,
|
||||||
|
}
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.di
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.room.Room
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.DatabaseCallback
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.*
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.migrations.MIGRATION_23_24
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.network.KtorClient
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.network.KtorGitHubApi
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.*
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.*
|
|
||||||
import dagger.Module
|
|
||||||
import dagger.Provides
|
|
||||||
import dagger.hilt.InstallIn
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import dagger.hilt.components.SingletonComponent
|
|
||||||
import io.ktor.client.*
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
|
|
||||||
@Module
|
|
||||||
@InstallIn(SingletonComponent::class)
|
|
||||||
class RepositoryModule {
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideGlobalEffectRepository(): GlobalEffectRepository {
|
|
||||||
return GlobalEffectRepository()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideInstalledPackageRepository(
|
|
||||||
@ApplicationContext context: Context,
|
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): InstalledPackageRepository {
|
|
||||||
return InstalledAndroidPackageRepository(context, applicationScope, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideDatabase(
|
|
||||||
@ApplicationContext context: Context,
|
|
||||||
callback: DatabaseCallback,
|
|
||||||
dataStoreManager: DataStoreManager,
|
|
||||||
): AppDatabase {
|
|
||||||
return Room.databaseBuilder(
|
|
||||||
context,
|
|
||||||
AppDatabase::class.java,
|
|
||||||
context.getString(R.string.db_name),
|
|
||||||
)
|
|
||||||
.addMigrations(MIGRATION_23_24(dataStoreManager.dataStore))
|
|
||||||
.fallbackToDestructiveMigration(true)
|
|
||||||
.addCallback(callback)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideSettingsDoa(appDatabase: AppDatabase): GeneralSettingsDao {
|
|
||||||
return appDatabase.generalSettingsDao()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideDnsSettingsDao(appDatabase: AppDatabase): DnsSettingsDao {
|
|
||||||
return appDatabase.dnsSettingsDao()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideAutoTunnelDao(appDatabase: AppDatabase): AutoTunnelSettingsDao {
|
|
||||||
return appDatabase.autoTunnelSettingsDao()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideMonitoringDao(appDatabase: AppDatabase): MonitoringSettingsDao {
|
|
||||||
return appDatabase.monitoringSettingsDao()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideProxyDoa(appDatabase: AppDatabase): ProxySettingsDao {
|
|
||||||
return appDatabase.proxySettingsDoa()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideTunnelConfigDoa(appDatabase: AppDatabase): TunnelConfigDao {
|
|
||||||
return appDatabase.tunnelConfigDoa()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideTunnelConfigRepository(
|
|
||||||
tunnelConfigDao: TunnelConfigDao,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): TunnelRepository {
|
|
||||||
return RoomTunnelRepository(tunnelConfigDao, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideGeneralSettingsRepository(
|
|
||||||
settingsDao: GeneralSettingsDao,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): GeneralSettingRepository {
|
|
||||||
return RoomSettingsRepository(settingsDao, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideMonitoringSettingsRepository(
|
|
||||||
monitoringSettingsDao: MonitoringSettingsDao,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): MonitoringSettingsRepository {
|
|
||||||
return RoomMonitoringSettingsRepository(monitoringSettingsDao, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideDnsSettingsRepository(
|
|
||||||
dnsSettingsDao: DnsSettingsDao,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): DnsSettingsRepository {
|
|
||||||
return RoomDnsSettingsRepository(dnsSettingsDao, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideAutoTunnelSettingsRepository(
|
|
||||||
autoTunnelSettingsDao: AutoTunnelSettingsDao,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): AutoTunnelSettingsRepository {
|
|
||||||
return RoomAutoTunnelSettingsRepository(autoTunnelSettingsDao, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideProxySettingsRepository(
|
|
||||||
proxySettingsDao: ProxySettingsDao,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): ProxySettingsRepository {
|
|
||||||
return RoomProxySettingsRepository(proxySettingsDao, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun providePreferencesDataStore(
|
|
||||||
@ApplicationContext context: Context,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): DataStoreManager {
|
|
||||||
return DataStoreManager(context, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideGeneralStateRepository(
|
|
||||||
dataStoreManager: DataStoreManager,
|
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): AppStateRepository {
|
|
||||||
return DataStoreAppStateRepository(dataStoreManager, applicationScope, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideHttpClient(): HttpClient {
|
|
||||||
return KtorClient.create()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideGitHubApi(client: HttpClient): GitHubApi {
|
|
||||||
return KtorGitHubApi(client)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideUpdateRepository(
|
|
||||||
gitHubApi: GitHubApi,
|
|
||||||
client: HttpClient,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
@ApplicationContext context: Context,
|
|
||||||
): UpdateRepository {
|
|
||||||
return GitHubUpdateRepository(
|
|
||||||
gitHubApi,
|
|
||||||
client,
|
|
||||||
"wgtunnel",
|
|
||||||
"wgtunnel",
|
|
||||||
context,
|
|
||||||
ioDispatcher,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,219 +1,108 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.di
|
package com.zaneschepke.wireguardautotunnel.di
|
||||||
|
|
||||||
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.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.*
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.backend.KernelTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.*
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.backend.RunConfigHelper
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.backend.TunnelBackend
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.backend.UserspaceTunnel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AutoTunnelSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.RootShellUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.to
|
import com.zaneschepke.wireguardautotunnel.util.extensions.to
|
||||||
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
|
||||||
import dagger.Module
|
|
||||||
import dagger.Provides
|
|
||||||
import dagger.hilt.InstallIn
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import dagger.hilt.components.SingletonComponent
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||||
import kotlinx.coroutines.flow.map
|
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.ProxyGoBackend
|
import org.amnezia.awg.backend.ProxyGoBackend
|
||||||
import org.amnezia.awg.backend.RootTunnelActionHandler
|
import org.amnezia.awg.backend.RootTunnelActionHandler
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.core.module.dsl.singleOf
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
@Module
|
val tunnelModule = module {
|
||||||
@InstallIn(SingletonComponent::class)
|
single(named(Shell.TUNNEL)) { RootShell(androidContext()) }
|
||||||
class TunnelModule {
|
single(named(Shell.APP)) { RootShell(androidContext()) }
|
||||||
|
|
||||||
@Provides
|
single { RootShellUtils(get(named(Shell.APP)), get(named(Dispatcher.IO))) }
|
||||||
@Singleton
|
|
||||||
@TunnelShell
|
|
||||||
fun provideTunnelRootShell(@ApplicationContext context: Context): RootShell {
|
|
||||||
return RootShell(context)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
singleOf(::RunConfigHelper)
|
||||||
@Singleton
|
|
||||||
@AppShell
|
|
||||||
fun provideAppRootShell(@ApplicationContext context: Context): RootShell {
|
|
||||||
return RootShell(context)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
single<Backend>(named(Core.USERSPACE)) {
|
||||||
@Singleton
|
GoBackend(
|
||||||
@Userspace
|
androidContext(),
|
||||||
fun provideAmneziaBackend(@ApplicationContext context: Context): Backend {
|
RootTunnelActionHandler(org.amnezia.awg.util.RootShell(androidContext())),
|
||||||
return GoBackend(context, RootTunnelActionHandler(org.amnezia.awg.util.RootShell(context)))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@ProxyUserspace
|
|
||||||
fun provideAmneziaProxyBackend(@ApplicationContext context: Context): Backend {
|
|
||||||
return ProxyGoBackend(
|
|
||||||
context,
|
|
||||||
RootTunnelActionHandler(org.amnezia.awg.util.RootShell(context)),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
single<Backend>(named(Core.PROXY_USERSPACE)) {
|
||||||
@Singleton
|
ProxyGoBackend(
|
||||||
fun provideKernelBackend(
|
androidContext(),
|
||||||
@ApplicationContext context: Context,
|
RootTunnelActionHandler(org.amnezia.awg.util.RootShell(androidContext())),
|
||||||
@TunnelShell shell: RootShell,
|
)
|
||||||
): com.wireguard.android.backend.Backend {
|
}
|
||||||
return WgQuickBackend(
|
|
||||||
context,
|
single<com.wireguard.android.backend.Backend> {
|
||||||
|
val shell = get<RootShell>(named(Shell.TUNNEL))
|
||||||
|
WgQuickBackend(
|
||||||
|
androidContext(),
|
||||||
shell,
|
shell,
|
||||||
ToolsInstaller(context, shell),
|
ToolsInstaller(androidContext(), shell),
|
||||||
com.wireguard.android.backend.RootTunnelActionHandler(shell),
|
com.wireguard.android.backend.RootTunnelActionHandler(shell),
|
||||||
)
|
)
|
||||||
.also { it.setMultipleTunnels(true) }
|
.apply { setMultipleTunnels(true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
single<TunnelBackend>(named(Core.KERNEL)) {
|
||||||
@Singleton
|
KernelTunnel(get(), get<com.wireguard.android.backend.Backend>())
|
||||||
@Kernel
|
|
||||||
fun provideKernelProvider(
|
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
backend: com.wireguard.android.backend.Backend,
|
|
||||||
): TunnelProvider {
|
|
||||||
return KernelTunnel(applicationScope, ioDispatcher, backend)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
single<TunnelBackend>(qualifier = named(Core.USERSPACE)) {
|
||||||
@Singleton
|
UserspaceTunnel(get<Backend>(named(Core.USERSPACE)), get())
|
||||||
@Userspace
|
|
||||||
fun provideUserspaceProvider(
|
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
proxySettingsRepository: ProxySettingsRepository,
|
|
||||||
dnsSettingsRepository: DnsSettingsRepository,
|
|
||||||
@Userspace backend: Backend,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): TunnelProvider {
|
|
||||||
return UserspaceTunnel(
|
|
||||||
applicationScope,
|
|
||||||
ioDispatcher,
|
|
||||||
proxySettingsRepository,
|
|
||||||
dnsSettingsRepository,
|
|
||||||
backend,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
single<TunnelBackend>(qualifier = named(Core.PROXY_USERSPACE)) {
|
||||||
@Singleton
|
UserspaceTunnel(get<Backend>(named(Core.PROXY_USERSPACE)), get())
|
||||||
@ProxyUserspace
|
|
||||||
fun provideProxyUserspaceProvider(
|
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
dnsSettingsRepository: DnsSettingsRepository,
|
|
||||||
proxySettingsRepository: ProxySettingsRepository,
|
|
||||||
@ProxyUserspace backend: Backend,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): TunnelProvider {
|
|
||||||
return UserspaceTunnel(
|
|
||||||
applicationScope,
|
|
||||||
ioDispatcher,
|
|
||||||
proxySettingsRepository,
|
|
||||||
dnsSettingsRepository,
|
|
||||||
backend,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
single<NetworkMonitor> {
|
||||||
@Singleton
|
AndroidNetworkMonitor(
|
||||||
fun provideTunnelManager(
|
androidContext(),
|
||||||
@Kernel kernelTunnel: TunnelProvider,
|
|
||||||
@Userspace userspaceTunnel: TunnelProvider,
|
|
||||||
@ProxyUserspace proxyTunnel: TunnelProvider,
|
|
||||||
serviceManager: ServiceManager,
|
|
||||||
tunnelRepository: TunnelRepository,
|
|
||||||
settingsRepository: GeneralSettingRepository,
|
|
||||||
autoTunnelSettingsRepository: AutoTunnelSettingsRepository,
|
|
||||||
tunnelMonitor: TunnelMonitor,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
): TunnelManager {
|
|
||||||
return TunnelManager(
|
|
||||||
kernelTunnel,
|
|
||||||
userspaceTunnel,
|
|
||||||
proxyTunnel,
|
|
||||||
serviceManager,
|
|
||||||
settingsRepository,
|
|
||||||
autoTunnelSettingsRepository,
|
|
||||||
tunnelRepository,
|
|
||||||
tunnelMonitor,
|
|
||||||
applicationScope,
|
|
||||||
ioDispatcher,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideNetworkMonitor(
|
|
||||||
@ApplicationContext context: Context,
|
|
||||||
autoTunnelSettingsRepository: AutoTunnelSettingsRepository,
|
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
@AppShell appShell: RootShell,
|
|
||||||
): NetworkMonitor {
|
|
||||||
return AndroidNetworkMonitor(
|
|
||||||
context,
|
|
||||||
object : AndroidNetworkMonitor.ConfigurationListener {
|
object : AndroidNetworkMonitor.ConfigurationListener {
|
||||||
override val detectionMethod: Flow<AndroidNetworkMonitor.WifiDetectionMethod>
|
override val detectionMethod =
|
||||||
get() =
|
get<AutoTunnelSettingsRepository>()
|
||||||
autoTunnelSettingsRepository.flow
|
.flow
|
||||||
.distinctUntilChangedBy { it.wifiDetectionMethod }
|
.distinctUntilChangedBy { it.wifiDetectionMethod }
|
||||||
.map { it.wifiDetectionMethod.to() }
|
.map { it.wifiDetectionMethod.to() }
|
||||||
|
|
||||||
override val rootShell: RootShell
|
override val rootShell = get<RootShell>(named(Shell.APP))
|
||||||
get() = appShell
|
|
||||||
},
|
},
|
||||||
applicationScope,
|
get<CoroutineScope>(named(Scope.APPLICATION)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
single {
|
||||||
@Provides
|
TunnelManager(
|
||||||
fun provideServiceManager(
|
get(named(Core.KERNEL)),
|
||||||
@ApplicationContext context: Context,
|
get(named(Core.USERSPACE)),
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
get(named(Core.PROXY_USERSPACE)),
|
||||||
@MainDispatcher mainCoroutineDispatcher: CoroutineDispatcher,
|
get(),
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
get(),
|
||||||
autoTunnelSettingsRepository: AutoTunnelSettingsRepository,
|
get(),
|
||||||
): ServiceManager {
|
get(),
|
||||||
return ServiceManager(
|
get(),
|
||||||
context,
|
get(),
|
||||||
ioDispatcher,
|
get(),
|
||||||
applicationScope,
|
get(),
|
||||||
mainCoroutineDispatcher,
|
get(),
|
||||||
autoTunnelSettingsRepository,
|
get(),
|
||||||
)
|
get(named(Scope.APPLICATION)),
|
||||||
}
|
get(named(Dispatcher.IO)),
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideTunnelMonitor(
|
|
||||||
networkMonitor: NetworkMonitor,
|
|
||||||
networkUtils: NetworkUtils,
|
|
||||||
logReader: LogReader,
|
|
||||||
tunnelsRepository: TunnelRepository,
|
|
||||||
settingsRepository: GeneralSettingRepository,
|
|
||||||
monitoringSettingsRepository: MonitoringSettingsRepository,
|
|
||||||
): TunnelMonitor {
|
|
||||||
return TunnelMonitor(
|
|
||||||
settingsRepository,
|
|
||||||
tunnelsRepository,
|
|
||||||
monitoringSettingsRepository,
|
|
||||||
networkMonitor,
|
|
||||||
networkUtils,
|
|
||||||
logReader,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.di
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.wireguard.android.util.RootShell
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.FileUtils
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.RootShellUtils
|
|
||||||
import dagger.Module
|
|
||||||
import dagger.Provides
|
|
||||||
import dagger.hilt.InstallIn
|
|
||||||
import dagger.hilt.android.components.ViewModelComponent
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import dagger.hilt.android.scopes.ViewModelScoped
|
|
||||||
import javax.inject.Provider
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
|
|
||||||
@Module
|
|
||||||
@InstallIn(ViewModelComponent::class)
|
|
||||||
class ViewModelModule {
|
|
||||||
@ViewModelScoped
|
|
||||||
@Provides
|
|
||||||
fun provideFileUtils(
|
|
||||||
@ApplicationContext context: Context,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): FileUtils {
|
|
||||||
return FileUtils(context, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@ViewModelScoped
|
|
||||||
@Provides
|
|
||||||
fun provideRootShellUtils(
|
|
||||||
@AppShell rootShell: Provider<RootShell>,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): RootShellUtils {
|
|
||||||
return RootShellUtils(rootShell, ioDispatcher)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.di
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.worker.ServiceWorker
|
||||||
|
import org.koin.androidx.workmanager.dsl.workerOf
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val workerModule = module { workerOf(::ServiceWorker) }
|
||||||
@@ -3,5 +3,9 @@ package com.zaneschepke.wireguardautotunnel.domain.enums
|
|||||||
sealed class BackendMode {
|
sealed class BackendMode {
|
||||||
data object Inactive : BackendMode()
|
data object Inactive : BackendMode()
|
||||||
|
|
||||||
data class KillSwitch(val allowedIps: Set<String>) : BackendMode()
|
data class KillSwitch(
|
||||||
|
val allowedIps: Set<String>,
|
||||||
|
val isMetered: Boolean,
|
||||||
|
val dualStack: Boolean,
|
||||||
|
) : BackendMode()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
|
||||||
|
|
||||||
enum class NetworkType {
|
|
||||||
WIFI,
|
|
||||||
ETHERNET,
|
|
||||||
MOBILE_DATA,
|
|
||||||
NONE,
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ package com.zaneschepke.wireguardautotunnel.domain.enums
|
|||||||
|
|
||||||
sealed class TunnelStatus {
|
sealed class TunnelStatus {
|
||||||
|
|
||||||
data object Up : TunnelStatus()
|
data class Up(val startTime: Long) : TunnelStatus()
|
||||||
|
|
||||||
data object Down : TunnelStatus()
|
data object Down : TunnelStatus()
|
||||||
|
|
||||||
@@ -15,11 +15,11 @@ sealed class TunnelStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isUp(): Boolean {
|
fun isUp(): Boolean {
|
||||||
return this == Up
|
return this is Up
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isUpOrStarting(): Boolean {
|
fun isUpOrStarting(): Boolean {
|
||||||
return this == Up || this == Starting
|
return this is Up || this == Starting
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isDownOrStopping(): Boolean {
|
fun isDownOrStopping(): Boolean {
|
||||||
|
|||||||
+4
-3
@@ -1,11 +1,12 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.events
|
package com.zaneschepke.wireguardautotunnel.domain.events
|
||||||
|
|
||||||
|
import androidx.annotation.Keep
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConfig
|
||||||
|
|
||||||
sealed class AutoTunnelEvent {
|
sealed class AutoTunnelEvent {
|
||||||
data class Start(val tunnelConfig: TunnelConfig? = null) : AutoTunnelEvent()
|
@Keep data class Start(val tunnelConfig: TunnelConfig? = null) : AutoTunnelEvent()
|
||||||
|
|
||||||
data object Stop : AutoTunnelEvent()
|
@Keep data object Stop : AutoTunnelEvent()
|
||||||
|
|
||||||
data object DoNothing : AutoTunnelEvent()
|
@Keep data object DoNothing : AutoTunnelEvent()
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-31
@@ -4,38 +4,43 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
|
|
||||||
sealed class BackendCoreException : Exception() {
|
sealed class BackendCoreException : Exception() {
|
||||||
data object DNS : BackendCoreException()
|
abstract val stringRes: Int
|
||||||
|
|
||||||
data object Unauthorized : BackendCoreException()
|
|
||||||
|
|
||||||
data object Config : BackendCoreException()
|
|
||||||
|
|
||||||
data object KernelModuleName : BackendCoreException()
|
|
||||||
|
|
||||||
data object NotAuthorized : BackendCoreException()
|
|
||||||
|
|
||||||
data object ServiceNotRunning : BackendCoreException()
|
|
||||||
|
|
||||||
data object Unknown : BackendCoreException()
|
|
||||||
|
|
||||||
data object TunnelNameTooLong : BackendCoreException()
|
|
||||||
|
|
||||||
data object UapiUpdateFailed : BackendCoreException()
|
|
||||||
|
|
||||||
fun toStringRes() =
|
|
||||||
when (this) {
|
|
||||||
Config -> R.string.config_error
|
|
||||||
DNS -> R.string.dns_resolve_error
|
|
||||||
KernelModuleName -> R.string.kernel_name_error
|
|
||||||
NotAuthorized,
|
|
||||||
Unauthorized -> R.string.auth_error
|
|
||||||
ServiceNotRunning -> R.string.service_running_error
|
|
||||||
Unknown -> R.string.unknown_error
|
|
||||||
TunnelNameTooLong -> R.string.error_tunnel_name
|
|
||||||
UapiUpdateFailed -> R.string.active_tunnel_update_failed
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toStringValue(): StringValue {
|
fun toStringValue(): StringValue {
|
||||||
return StringValue.StringResource(toStringRes())
|
return StringValue.StringResource(stringRes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DnsFailure : BackendCoreException() {
|
||||||
|
override val stringRes = R.string.dns_resolve_error
|
||||||
|
}
|
||||||
|
|
||||||
|
class VpnUnauthorized : BackendCoreException() {
|
||||||
|
override val stringRes = R.string.auth_error
|
||||||
|
}
|
||||||
|
|
||||||
|
class InvalidConfig : BackendCoreException() {
|
||||||
|
override val stringRes = R.string.config_error
|
||||||
|
}
|
||||||
|
|
||||||
|
class KernelTunnelName(override val stringRes: Int) : BackendCoreException() {}
|
||||||
|
|
||||||
|
class NotAuthorized : BackendCoreException() {
|
||||||
|
override val stringRes = R.string.auth_error
|
||||||
|
}
|
||||||
|
|
||||||
|
class ServiceNotRunning : BackendCoreException() {
|
||||||
|
override val stringRes = R.string.service_running_error
|
||||||
|
}
|
||||||
|
|
||||||
|
class UnknownError : BackendCoreException() {
|
||||||
|
override val stringRes = R.string.unknown_error
|
||||||
|
}
|
||||||
|
|
||||||
|
class UapiUpdateFailed : BackendCoreException() {
|
||||||
|
override val stringRes = R.string.active_tunnel_update_failed
|
||||||
|
}
|
||||||
|
|
||||||
|
class KernelWireguardNotSupported : BackendCoreException() {
|
||||||
|
override val stringRes = R.string.kernel_wireguard_unsupported
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ package com.zaneschepke.wireguardautotunnel.domain.model
|
|||||||
data class AppState(
|
data class AppState(
|
||||||
val isLocationDisclosureShown: Boolean = false,
|
val isLocationDisclosureShown: Boolean = false,
|
||||||
val isBatteryOptimizationDisableShown: Boolean = false,
|
val isBatteryOptimizationDisableShown: Boolean = false,
|
||||||
|
val shouldShowDonationSnackbar: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ data class DnsSettings(
|
|||||||
val id: Int = 0,
|
val id: Int = 0,
|
||||||
val dnsProtocol: DnsProtocol = DnsProtocol.fromValue(0),
|
val dnsProtocol: DnsProtocol = DnsProtocol.fromValue(0),
|
||||||
val dnsEndpoint: String? = null,
|
val dnsEndpoint: String? = null,
|
||||||
|
val isGlobalTunnelDnsEnabled: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-3
@@ -8,7 +8,7 @@ data class GeneralSettings(
|
|||||||
val isShortcutsEnabled: Boolean = false,
|
val isShortcutsEnabled: Boolean = false,
|
||||||
val isRestoreOnBootEnabled: Boolean = false,
|
val isRestoreOnBootEnabled: Boolean = false,
|
||||||
val isMultiTunnelEnabled: Boolean = false,
|
val isMultiTunnelEnabled: Boolean = false,
|
||||||
val isTunnelGlobalsEnabled: Boolean = false,
|
val isGlobalSplitTunnelEnabled: Boolean = false,
|
||||||
val appMode: AppMode = AppMode.fromValue(0),
|
val appMode: AppMode = AppMode.fromValue(0),
|
||||||
val theme: Theme = Theme.AUTOMATIC,
|
val theme: Theme = Theme.AUTOMATIC,
|
||||||
val locale: String? = null,
|
val locale: String? = null,
|
||||||
@@ -16,6 +16,6 @@ data class GeneralSettings(
|
|||||||
val isRemoteControlEnabled: Boolean = false,
|
val isRemoteControlEnabled: Boolean = false,
|
||||||
val isPinLockEnabled: Boolean = false,
|
val isPinLockEnabled: Boolean = false,
|
||||||
val isAlwaysOnVpnEnabled: Boolean = false,
|
val isAlwaysOnVpnEnabled: Boolean = false,
|
||||||
val isLanOnKillSwitchEnabled: Boolean = false,
|
val isKillSwitchMetered: Boolean = true,
|
||||||
val customSplitPackages: Map<String, String> = emptyMap(),
|
val alreadyDonated: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||||
|
|
||||||
|
data class LockdownSettings(
|
||||||
|
val id: Long = 0L,
|
||||||
|
val bypassLan: Boolean = false,
|
||||||
|
val metered: Boolean = false,
|
||||||
|
val dualStack: Boolean = false,
|
||||||
|
)
|
||||||
+21
-62
@@ -27,8 +27,8 @@ data class TunnelConfig(
|
|||||||
val isIpv4Preferred: Boolean = true,
|
val isIpv4Preferred: Boolean = true,
|
||||||
val position: Int = 0,
|
val position: Int = 0,
|
||||||
val autoTunnelApps: Set<String> = setOf(),
|
val autoTunnelApps: Set<String> = setOf(),
|
||||||
|
val isMetered: Boolean = false,
|
||||||
) {
|
) {
|
||||||
val isNameKernelCompatible: Boolean = (name.length <= 15)
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
@@ -43,7 +43,8 @@ data class TunnelConfig(
|
|||||||
pingTarget == other.pingTarget &&
|
pingTarget == other.pingTarget &&
|
||||||
restartOnPingFailure == other.restartOnPingFailure &&
|
restartOnPingFailure == other.restartOnPingFailure &&
|
||||||
tunnelNetworks == other.tunnelNetworks &&
|
tunnelNetworks == other.tunnelNetworks &&
|
||||||
isIpv4Preferred == other.isIpv4Preferred
|
isIpv4Preferred == other.isIpv4Preferred &&
|
||||||
|
isMetered == other.isMetered
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
@@ -66,7 +67,11 @@ data class TunnelConfig(
|
|||||||
return configFromWgQuick(wgQuick)
|
return configFromWgQuick(wgQuick)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun copyWithGlobalValues(globalTunnel: TunnelConfig): TunnelConfig {
|
fun copyWithGlobalValues(
|
||||||
|
globalTunnel: TunnelConfig,
|
||||||
|
includeDns: Boolean,
|
||||||
|
includeSpitTunneling: Boolean,
|
||||||
|
): TunnelConfig {
|
||||||
val existingConfig = toAmConfig()
|
val existingConfig = toAmConfig()
|
||||||
val globalConfig = globalTunnel.toAmConfig()
|
val globalConfig = globalTunnel.toAmConfig()
|
||||||
|
|
||||||
@@ -101,76 +106,30 @@ data class TunnelConfig(
|
|||||||
existingConfig.`interface`.transportPacketMagicHeader.ifPresent {
|
existingConfig.`interface`.transportPacketMagicHeader.ifPresent {
|
||||||
setTransportPacketMagicHeader(it)
|
setTransportPacketMagicHeader(it)
|
||||||
}
|
}
|
||||||
existingConfig.`interface`.i1.ifPresent { setI1(it) }
|
existingConfig.`interface`.cookieReplyPacketJunkSize.ifPresent {
|
||||||
existingConfig.`interface`.i2.ifPresent { setI2(it) }
|
setCookieReplyPacketJunkSize(it)
|
||||||
existingConfig.`interface`.i3.ifPresent { setI3(it) }
|
}
|
||||||
existingConfig.`interface`.i4.ifPresent { setI4(it) }
|
existingConfig.`interface`.transportPacketJunkSize.ifPresent {
|
||||||
existingConfig.`interface`.i5.ifPresent { setI5(it) }
|
setTransportPacketJunkSize(it)
|
||||||
existingConfig.`interface`.j1.ifPresent { setJ1(it) }
|
}
|
||||||
existingConfig.`interface`.j2.ifPresent { setJ2(it) }
|
existingConfig.`interface`.specialJunkI1.ifPresent { setSpecialJunkI1(it) }
|
||||||
existingConfig.`interface`.j3.ifPresent { setJ3(it) }
|
existingConfig.`interface`.specialJunkI2.ifPresent { setSpecialJunkI2(it) }
|
||||||
existingConfig.`interface`.itime.ifPresent { setItime(it) }
|
existingConfig.`interface`.specialJunkI3.ifPresent { setSpecialJunkI3(it) }
|
||||||
|
existingConfig.`interface`.specialJunkI4.ifPresent { setSpecialJunkI4(it) }
|
||||||
|
existingConfig.`interface`.specialJunkI5.ifPresent { setSpecialJunkI5(it) }
|
||||||
setPreUp(existingConfig.`interface`.preUp)
|
setPreUp(existingConfig.`interface`.preUp)
|
||||||
setPostUp(existingConfig.`interface`.postUp)
|
setPostUp(existingConfig.`interface`.postUp)
|
||||||
setPreDown(existingConfig.`interface`.preDown)
|
setPreDown(existingConfig.`interface`.preDown)
|
||||||
setPostDown(existingConfig.`interface`.postDown)
|
setPostDown(existingConfig.`interface`.postDown)
|
||||||
|
|
||||||
globalConfig.`interface`.mtu.ifPresent { setMtu(it) }
|
if (includeDns) {
|
||||||
if (globalConfig.`interface`.dnsServers.isNotEmpty()) {
|
|
||||||
setDnsServers(globalConfig.`interface`.dnsServers)
|
setDnsServers(globalConfig.`interface`.dnsServers)
|
||||||
}
|
|
||||||
if (globalConfig.`interface`.dnsSearchDomains.isNotEmpty()) {
|
|
||||||
setDnsSearchDomains(globalConfig.`interface`.dnsSearchDomains)
|
setDnsSearchDomains(globalConfig.`interface`.dnsSearchDomains)
|
||||||
}
|
}
|
||||||
|
if (includeSpitTunneling) {
|
||||||
if (globalConfig.`interface`.excludedApplications.isNotEmpty()) {
|
|
||||||
setExcludedApplications(globalConfig.`interface`.excludedApplications)
|
setExcludedApplications(globalConfig.`interface`.excludedApplications)
|
||||||
}
|
|
||||||
if (!globalConfig.`interface`.includedApplications.isEmpty()) {
|
|
||||||
setIncludedApplications(globalConfig.`interface`.includedApplications)
|
setIncludedApplications(globalConfig.`interface`.includedApplications)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalConfig.`interface`.preUp.isNotEmpty()) {
|
|
||||||
setPreUp(globalConfig.`interface`.preUp)
|
|
||||||
}
|
|
||||||
if (globalConfig.`interface`.postUp.isNotEmpty()) {
|
|
||||||
setPostUp(globalConfig.`interface`.postUp)
|
|
||||||
}
|
|
||||||
if (globalConfig.`interface`.preDown.isNotEmpty()) {
|
|
||||||
setPreDown(globalConfig.`interface`.preDown)
|
|
||||||
}
|
|
||||||
if (globalConfig.`interface`.postDown.isNotEmpty()) {
|
|
||||||
setPostDown(globalConfig.`interface`.postDown)
|
|
||||||
}
|
|
||||||
|
|
||||||
globalConfig.`interface`.junkPacketCount.ifPresent { setJunkPacketCount(it) }
|
|
||||||
globalConfig.`interface`.junkPacketMinSize.ifPresent { setJunkPacketMinSize(it) }
|
|
||||||
globalConfig.`interface`.junkPacketMaxSize.ifPresent { setJunkPacketMaxSize(it) }
|
|
||||||
globalConfig.`interface`.initPacketJunkSize.ifPresent { setInitPacketJunkSize(it) }
|
|
||||||
globalConfig.`interface`.responsePacketJunkSize.ifPresent {
|
|
||||||
setResponsePacketJunkSize(it)
|
|
||||||
}
|
|
||||||
globalConfig.`interface`.initPacketMagicHeader.ifPresent {
|
|
||||||
setInitPacketMagicHeader(it)
|
|
||||||
}
|
|
||||||
globalConfig.`interface`.responsePacketMagicHeader.ifPresent {
|
|
||||||
setResponsePacketMagicHeader(it)
|
|
||||||
}
|
|
||||||
globalConfig.`interface`.underloadPacketMagicHeader.ifPresent {
|
|
||||||
setUnderloadPacketMagicHeader(it)
|
|
||||||
}
|
|
||||||
globalConfig.`interface`.transportPacketMagicHeader.ifPresent {
|
|
||||||
setTransportPacketMagicHeader(it)
|
|
||||||
}
|
|
||||||
globalConfig.`interface`.i1.ifPresent { setI1(it) }
|
|
||||||
globalConfig.`interface`.i2.ifPresent { setI2(it) }
|
|
||||||
globalConfig.`interface`.i3.ifPresent { setI3(it) }
|
|
||||||
globalConfig.`interface`.i4.ifPresent { setI4(it) }
|
|
||||||
globalConfig.`interface`.i5.ifPresent { setI5(it) }
|
|
||||||
globalConfig.`interface`.j1.ifPresent { setJ1(it) }
|
|
||||||
globalConfig.`interface`.j2.ifPresent { setJ2(it) }
|
|
||||||
globalConfig.`interface`.j3.ifPresent { setJ3(it) }
|
|
||||||
globalConfig.`interface`.itime.ifPresent { setItime(it) }
|
|
||||||
}
|
}
|
||||||
val newInterface = newInterfaceBuilder.build()
|
val newInterface = newInterfaceBuilder.build()
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user