mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
107 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1952ff1b02 | |||
| 99f6c0bda5 | |||
| 28b77d33ca | |||
| b0b070f6aa | |||
| 89b1f314b1 | |||
| 020263eba6 | |||
| d359215b20 | |||
| a6a0bba569 | |||
| f729e924cd | |||
| 3c1d0f893a | |||
| b184331258 | |||
| 36603ab542 | |||
| d0e21247b5 | |||
| 786a8b54ce | |||
| d762fe7283 | |||
| ed9cab3251 | |||
| 8e1e754a87 | |||
| c6eaaa1f37 | |||
| 5077ec9a46 | |||
| e4a808c6ce | |||
| 52efdfa288 | |||
| a4f413e79e | |||
| 71ae3864fc | |||
| 008bc476e0 | |||
| 3947b04e21 | |||
| acef2637c8 | |||
| ba8b09cdc9 | |||
| 79e5ba0cb0 | |||
| 165fda0352 | |||
| c4dfb4d591 | |||
| e80e0b7f94 | |||
| b856fc2230 | |||
| 202ac52e25 | |||
| 2b1a8af998 | |||
| b924845835 | |||
| 0f8d7fed97 | |||
| 20ff172055 | |||
| 42671f616f | |||
| ecca99828f | |||
| 7f40df9d36 | |||
| 9a497f7892 | |||
| dc5a10ebc9 | |||
| d1a4c7f133 | |||
| 93ebf299e6 | |||
| 1d83da9d44 | |||
| d2abaad5b4 | |||
| 8bf88a89bd | |||
| 96cfd04450 | |||
| c5f39ec906 | |||
| 5cd8f9c2f2 | |||
| 2d11712fdc | |||
| 9528850873 | |||
| a0d5647f23 | |||
| 5ff810a6ef | |||
| 3dc314d79a | |||
| 466a5cecbe | |||
| a13d70227f | |||
| 519981d681 | |||
| 0d17bf28e0 | |||
| fc1d4b22a6 | |||
| d2f5be6e19 | |||
| 27a5b6b9f2 | |||
| 2ae048b1de | |||
| a890c83088 | |||
| 3eedbdccba | |||
| 73b3d03a25 | |||
| b74f84abc2 | |||
| bbb056e9d1 | |||
| 0d953a32be | |||
| 3383bb6b45 | |||
| afcb801806 | |||
| 494835a5a4 | |||
| 2f784f563f | |||
| 11d6fd2ed9 | |||
| 0e8138ba6b | |||
| 0eb3719972 | |||
| 196cd34ef7 | |||
| ed42a2f7df | |||
| 9b944bf51e | |||
| b8c792418d | |||
| 6d8a38c65b | |||
| 09c1c68aad | |||
| 36b8353b07 | |||
| f10ed1269e | |||
| e6e35f01d7 | |||
| 35737bdd84 | |||
| 5a6960bffd | |||
| 10cefe2ab0 | |||
| add53834e7 | |||
| f740ec57ea | |||
| 7eadfe2af2 | |||
| 001a4358e1 | |||
| 31abe64513 | |||
| 900aa86c29 | |||
| 264e17f30b | |||
| fbc3ff3276 | |||
| 151cdd4e03 | |||
| f0deb1294a | |||
| 19efb08cb9 | |||
| 9f4b9ca771 | |||
| a60e480be0 | |||
| f28e21ef79 | |||
| b4ca1e63c4 | |||
| e35f4bbb52 | |||
| f0e575da69 | |||
| a6b7d2091a | |||
| 324a1a66c5 |
@@ -12,6 +12,7 @@ on:
|
|||||||
default: debug
|
default: debug
|
||||||
options:
|
options:
|
||||||
- debug
|
- debug
|
||||||
|
- prerelease
|
||||||
- nightly
|
- nightly
|
||||||
- release
|
- release
|
||||||
flavor:
|
flavor:
|
||||||
@@ -104,6 +105,9 @@ jobs:
|
|||||||
"release")
|
"release")
|
||||||
./gradlew :app:assemble${flavor^}Release --info
|
./gradlew :app:assemble${flavor^}Release --info
|
||||||
;;
|
;;
|
||||||
|
"prerelease")
|
||||||
|
./gradlew :app:assemble${flavor^}Prerelease --info
|
||||||
|
;;
|
||||||
"nightly")
|
"nightly")
|
||||||
./gradlew :app:assemble${flavor^}Nightly --info
|
./gradlew :app:assemble${flavor^}Nightly --info
|
||||||
;;
|
;;
|
||||||
@@ -118,11 +122,6 @@ jobs:
|
|||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: android_artifacts_${{ inputs.flavor }}
|
name: android_artifacts_${{ inputs.flavor }}
|
||||||
path: >-
|
path: app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/wgtunnel-${{ inputs.flavor }}${{ inputs.flavor == 'fdroid' && '-release' || '' }}-*.apk
|
||||||
app/build/outputs/apk/${{ inputs.flavor }}/${{ inputs.build_type }}/${{
|
|
||||||
inputs.flavor == 'fdroid' && inputs.build_type == 'release'
|
|
||||||
&& 'wgtunnel-fdroid-release-*.apk'
|
|
||||||
|| format('wgtunnel-{0}-v*.apk', inputs.flavor)
|
|
||||||
}}
|
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
if-no-files-found: warn
|
if-no-files-found: warn
|
||||||
@@ -69,7 +69,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@v4
|
||||||
with:
|
with:
|
||||||
pattern: android_artifacts_*
|
pattern: android_artifacts_*
|
||||||
path: ${{ github.workspace }}/temp
|
path: ${{ github.workspace }}/temp
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ on:
|
|||||||
description: "GitHub release type"
|
description: "GitHub release type"
|
||||||
options:
|
options:
|
||||||
- none
|
- none
|
||||||
|
- prerelease
|
||||||
- release
|
- release
|
||||||
default: release
|
default: release
|
||||||
required: true
|
required: true
|
||||||
@@ -59,7 +60,7 @@ 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 == 'release' || inputs.release_type == 'prerelease' || inputs.flavor == 'standalone' }}
|
||||||
uses: ./.github/workflows/build.yml
|
uses: ./.github/workflows/build.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
@@ -108,7 +109,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@v4
|
||||||
with:
|
with:
|
||||||
pattern: android_artifacts_*
|
pattern: android_artifacts_*
|
||||||
path: ${{ github.workspace }}/temp
|
path: ${{ github.workspace }}/temp
|
||||||
@@ -123,6 +124,11 @@ jobs:
|
|||||||
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
echo "$RELEASE_NOTES" >> $GITHUB_ENV
|
||||||
echo "EOF" >> $GITHUB_ENV
|
echo "EOF" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: On prerelease release notes
|
||||||
|
if: ${{ github.event_name != 'push' && inputs.release_type == 'prerelease' }}
|
||||||
|
run: |
|
||||||
|
echo "RELEASE_NOTES=Testing version of app for specific feature." >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Get checksum
|
- name: Get checksum
|
||||||
id: checksum
|
id: checksum
|
||||||
run: |
|
run: |
|
||||||
@@ -156,8 +162,8 @@ jobs:
|
|||||||
tag_name: ${{ github.event_name == 'push' && github.ref_name || github.event.inputs.tag_name }}
|
tag_name: ${{ github.event_name == 'push' && github.ref_name || github.event.inputs.tag_name }}
|
||||||
name: ${{ github.event_name == 'push' && github.ref_name || github.event.inputs.tag_name }}
|
name: ${{ github.event_name == 'push' && github.ref_name || github.event.inputs.tag_name }}
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: false
|
prerelease: ${{ github.event_name != 'push' && inputs.release_type == 'prerelease' }}
|
||||||
make_latest: true
|
make_latest: ${{ github.event_name == 'push' || inputs.release_type == 'release' }}
|
||||||
files: |
|
files: |
|
||||||
${{ github.workspace }}/temp/**/*.apk
|
${{ github.workspace }}/temp/**/*.apk
|
||||||
env:
|
env:
|
||||||
|
|||||||
+19
-31
@@ -1,5 +1,3 @@
|
|||||||
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)
|
||||||
@@ -9,7 +7,6 @@ plugins {
|
|||||||
alias(libs.plugins.compose.compiler)
|
alias(libs.plugins.compose.compiler)
|
||||||
alias(libs.plugins.grgit)
|
alias(libs.plugins.grgit)
|
||||||
alias(libs.plugins.licensee)
|
alias(libs.plugins.licensee)
|
||||||
id("kotlin-parcelize")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -23,8 +20,6 @@ android {
|
|||||||
includeInBundle = false
|
includeInBundle = false
|
||||||
}
|
}
|
||||||
|
|
||||||
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
|
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = Constants.APP_ID
|
applicationId = Constants.APP_ID
|
||||||
minSdk = Constants.MIN_SDK
|
minSdk = Constants.MIN_SDK
|
||||||
@@ -32,10 +27,15 @@ android {
|
|||||||
versionCode = computeVersionCode()
|
versionCode = computeVersionCode()
|
||||||
versionName = computeVersionName()
|
versionName = computeVersionName()
|
||||||
|
|
||||||
|
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
|
||||||
|
|
||||||
sourceSets { getByName("debug").assets.srcDirs(files("$projectDir/schemas")) }
|
sourceSets { getByName("debug").assets.srcDirs(files("$projectDir/schemas")) }
|
||||||
|
|
||||||
val languagesArray = buildLanguagesArray(languageList())
|
buildConfigField(
|
||||||
buildConfigField("String[]", "LANGUAGES", "new String[]{ $languagesArray }")
|
"String[]",
|
||||||
|
"LANGUAGES",
|
||||||
|
"new String[]{ ${languageList().joinToString(separator = ", ") { "\"$it\"" }} }",
|
||||||
|
)
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables { useSupportLibrary = true }
|
vectorDrawables { useSupportLibrary = true }
|
||||||
@@ -73,15 +73,22 @@ android {
|
|||||||
|
|
||||||
debug {
|
debug {
|
||||||
applicationIdSuffix = ".debug"
|
applicationIdSuffix = ".debug"
|
||||||
resValue("string", "app_name", "WG Tunnel Debug")
|
resValue("string", "app_name", "WG Tunnel - Debug")
|
||||||
isDebuggable = true
|
isDebuggable = true
|
||||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.debug\"")
|
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.debug\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create(Constants.PRERELEASE) {
|
||||||
|
initWith(buildTypes.getByName(Constants.RELEASE))
|
||||||
|
applicationIdSuffix = ".prerelease"
|
||||||
|
resValue("string", "app_name", "WG Tunnel - Pre")
|
||||||
|
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.pre\"")
|
||||||
|
}
|
||||||
|
|
||||||
create(Constants.NIGHTLY) {
|
create(Constants.NIGHTLY) {
|
||||||
initWith(buildTypes.getByName(Constants.RELEASE))
|
initWith(buildTypes.getByName(Constants.RELEASE))
|
||||||
applicationIdSuffix = ".nightly"
|
applicationIdSuffix = ".nightly"
|
||||||
resValue("string", "app_name", "WG Tunnel Nightly")
|
resValue("string", "app_name", "WG Tunnel - Nightly")
|
||||||
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.nightly\"")
|
resValue("string", "provider", "\"${Constants.APP_NAME}.provider.nightly\"")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,14 +114,7 @@ android {
|
|||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
kotlinOptions { jvmTarget = Constants.JVM_TARGET }
|
||||||
kotlin {
|
|
||||||
compilerOptions {
|
|
||||||
jvmTarget = JvmTarget.JVM_17
|
|
||||||
freeCompilerArgs = listOf("-XXLanguage:+PropertyParamAnnotationDefaultTargetMode")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
compose = true
|
compose = true
|
||||||
buildConfig = true
|
buildConfig = true
|
||||||
@@ -122,8 +122,8 @@ android {
|
|||||||
packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } }
|
packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } }
|
||||||
|
|
||||||
licensee {
|
licensee {
|
||||||
allowedLicenses().forEach { allow(it) }
|
Constants.allowedLicenses.forEach { allow(it) }
|
||||||
allowedLicenseUrls().forEach { allowUrl(it) }
|
Constants.allowedLicenseUrls.forEach { allowUrl(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationVariants.all {
|
applicationVariants.all {
|
||||||
@@ -198,7 +198,6 @@ dependencies {
|
|||||||
|
|
||||||
implementation(libs.zxing.android.embedded)
|
implementation(libs.zxing.android.embedded)
|
||||||
|
|
||||||
implementation(libs.material.icons.core)
|
|
||||||
implementation(libs.material.icons.extended)
|
implementation(libs.material.icons.extended)
|
||||||
|
|
||||||
implementation(libs.androidx.biometric.ktx)
|
implementation(libs.androidx.biometric.ktx)
|
||||||
@@ -220,21 +219,10 @@ dependencies {
|
|||||||
implementation(libs.ktor.client.content.negotiation)
|
implementation(libs.ktor.client.content.negotiation)
|
||||||
implementation(libs.ktor.serialization.kotlinx.json)
|
implementation(libs.ktor.serialization.kotlinx.json)
|
||||||
implementation(libs.slf4j.android)
|
implementation(libs.slf4j.android)
|
||||||
implementation(libs.icmp4a)
|
|
||||||
|
|
||||||
// shizuku
|
// shizuku
|
||||||
implementation(libs.shizuku.api)
|
implementation(libs.shizuku.api)
|
||||||
implementation(libs.shizuku.provider)
|
implementation(libs.shizuku.provider)
|
||||||
|
|
||||||
implementation(libs.reorderable)
|
|
||||||
implementation(libs.roomdatabasebackup) {
|
|
||||||
exclude(group = "org.reactivestreams", module = "reactive-streams")
|
|
||||||
}
|
|
||||||
|
|
||||||
// state management
|
|
||||||
implementation(libs.orbit.compose)
|
|
||||||
implementation(libs.orbit.viewmodel)
|
|
||||||
implementation(libs.orbit.core)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
||||||
|
|||||||
Vendored
-3
@@ -1,3 +0,0 @@
|
|||||||
-keep class com.zaneschepke.wireguardautotunnel.ui.navigation.Route { *; }
|
|
||||||
-keep class com.zaneschepke.wireguardautotunnel.ui.navigation.Route$** { *; }
|
|
||||||
-keepclassmembers class com.zaneschepke.wireguardautotunnel.ui.navigation.Route$** { *; }
|
|
||||||
@@ -1,302 +0,0 @@
|
|||||||
{
|
|
||||||
"formatVersion": 1,
|
|
||||||
"database": {
|
|
||||||
"version": 18,
|
|
||||||
"identityHash": "505728bad740c12bab998a066b569333",
|
|
||||||
"entities": [
|
|
||||||
{
|
|
||||||
"tableName": "Settings",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL, `trusted_network_ssids` TEXT NOT NULL, `is_always_on_vpn_enabled` INTEGER NOT NULL, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_enabled` INTEGER NOT NULL DEFAULT false, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT false, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_amnezia_enabled` INTEGER NOT NULL DEFAULT false, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT false, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT false, `is_vpn_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT false, `split_tunnel_apps` TEXT NOT NULL DEFAULT '', `wifi_detection_method` INTEGER NOT NULL DEFAULT 0)",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isAutoTunnelEnabled",
|
|
||||||
"columnName": "is_tunnel_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnMobileDataEnabled",
|
|
||||||
"columnName": "is_tunnel_on_mobile_data_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "trustedNetworkSSIDs",
|
|
||||||
"columnName": "trusted_network_ssids",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isAlwaysOnVpnEnabled",
|
|
||||||
"columnName": "is_always_on_vpn_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnEthernetEnabled",
|
|
||||||
"columnName": "is_tunnel_on_ethernet_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isShortcutsEnabled",
|
|
||||||
"columnName": "is_shortcuts_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnWifiEnabled",
|
|
||||||
"columnName": "is_tunnel_on_wifi_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isKernelEnabled",
|
|
||||||
"columnName": "is_kernel_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isRestoreOnBootEnabled",
|
|
||||||
"columnName": "is_restore_on_boot_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isMultiTunnelEnabled",
|
|
||||||
"columnName": "is_multi_tunnel_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPingEnabled",
|
|
||||||
"columnName": "is_ping_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isAmneziaEnabled",
|
|
||||||
"columnName": "is_amnezia_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isWildcardsEnabled",
|
|
||||||
"columnName": "is_wildcards_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isStopOnNoInternetEnabled",
|
|
||||||
"columnName": "is_stop_on_no_internet_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isVpnKillSwitchEnabled",
|
|
||||||
"columnName": "is_vpn_kill_switch_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isKernelKillSwitchEnabled",
|
|
||||||
"columnName": "is_kernel_kill_switch_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isLanOnKillSwitchEnabled",
|
|
||||||
"columnName": "is_lan_on_kill_switch_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "debounceDelaySeconds",
|
|
||||||
"columnName": "debounce_delay_seconds",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
|
||||||
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnUnsecureEnabled",
|
|
||||||
"columnName": "is_tunnel_on_unsecure_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "splitTunnelApps",
|
|
||||||
"columnName": "split_tunnel_apps",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "wifiDetectionMethod",
|
|
||||||
"columnName": "wifi_detection_method",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"tableName": "TunnelConfig",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `ping_interval` INTEGER DEFAULT null, `ping_cooldown` INTEGER DEFAULT null, `ping_ip` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true, `position` INTEGER NOT NULL DEFAULT 0)",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "name",
|
|
||||||
"columnName": "name",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "wgQuick",
|
|
||||||
"columnName": "wg_quick",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelNetworks",
|
|
||||||
"columnName": "tunnel_networks",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isMobileDataTunnel",
|
|
||||||
"columnName": "is_mobile_data_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPrimaryTunnel",
|
|
||||||
"columnName": "is_primary_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "amQuick",
|
|
||||||
"columnName": "am_quick",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isActive",
|
|
||||||
"columnName": "is_Active",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPingEnabled",
|
|
||||||
"columnName": "is_ping_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "pingInterval",
|
|
||||||
"columnName": "ping_interval",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"defaultValue": "null"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "pingCooldown",
|
|
||||||
"columnName": "ping_cooldown",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"defaultValue": "null"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "pingIp",
|
|
||||||
"columnName": "ping_ip",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"defaultValue": "null"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isEthernetTunnel",
|
|
||||||
"columnName": "is_ethernet_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isIpv4Preferred",
|
|
||||||
"columnName": "is_ipv4_preferred",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "position",
|
|
||||||
"columnName": "position",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [
|
|
||||||
{
|
|
||||||
"name": "index_TunnelConfig_name",
|
|
||||||
"unique": true,
|
|
||||||
"columnNames": [
|
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"orders": [],
|
|
||||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"setupQueries": [
|
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
|
||||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '505728bad740c12bab998a066b569333')"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,316 +0,0 @@
|
|||||||
{
|
|
||||||
"formatVersion": 1,
|
|
||||||
"database": {
|
|
||||||
"version": 19,
|
|
||||||
"identityHash": "82bdb96b7a9f8695a34ad1ec21d9aea8",
|
|
||||||
"entities": [
|
|
||||||
{
|
|
||||||
"tableName": "Settings",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL, `trusted_network_ssids` TEXT NOT NULL, `is_always_on_vpn_enabled` INTEGER NOT NULL, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_enabled` INTEGER NOT NULL DEFAULT false, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT false, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_amnezia_enabled` INTEGER NOT NULL DEFAULT false, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT false, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT false, `is_vpn_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_kernel_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT false, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT true, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER)",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isAutoTunnelEnabled",
|
|
||||||
"columnName": "is_tunnel_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnMobileDataEnabled",
|
|
||||||
"columnName": "is_tunnel_on_mobile_data_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "trustedNetworkSSIDs",
|
|
||||||
"columnName": "trusted_network_ssids",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isAlwaysOnVpnEnabled",
|
|
||||||
"columnName": "is_always_on_vpn_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnEthernetEnabled",
|
|
||||||
"columnName": "is_tunnel_on_ethernet_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isShortcutsEnabled",
|
|
||||||
"columnName": "is_shortcuts_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnWifiEnabled",
|
|
||||||
"columnName": "is_tunnel_on_wifi_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isKernelEnabled",
|
|
||||||
"columnName": "is_kernel_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isRestoreOnBootEnabled",
|
|
||||||
"columnName": "is_restore_on_boot_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isMultiTunnelEnabled",
|
|
||||||
"columnName": "is_multi_tunnel_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPingEnabled",
|
|
||||||
"columnName": "is_ping_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isAmneziaEnabled",
|
|
||||||
"columnName": "is_amnezia_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isWildcardsEnabled",
|
|
||||||
"columnName": "is_wildcards_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isStopOnNoInternetEnabled",
|
|
||||||
"columnName": "is_stop_on_no_internet_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isVpnKillSwitchEnabled",
|
|
||||||
"columnName": "is_vpn_kill_switch_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isKernelKillSwitchEnabled",
|
|
||||||
"columnName": "is_kernel_kill_switch_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isLanOnKillSwitchEnabled",
|
|
||||||
"columnName": "is_lan_on_kill_switch_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "debounceDelaySeconds",
|
|
||||||
"columnName": "debounce_delay_seconds",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
|
||||||
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnUnsecureEnabled",
|
|
||||||
"columnName": "is_tunnel_on_unsecure_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "wifiDetectionMethod",
|
|
||||||
"columnName": "wifi_detection_method",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPingMonitoringEnabled",
|
|
||||||
"columnName": "is_ping_monitoring_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelPingIntervalSeconds",
|
|
||||||
"columnName": "tunnel_ping_interval_sec",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "30"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelPingAttempts",
|
|
||||||
"columnName": "tunnel_ping_attempts",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelPingTimeoutSeconds",
|
|
||||||
"columnName": "tunnel_ping_timeout_sec",
|
|
||||||
"affinity": "INTEGER"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"tableName": "TunnelConfig",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `restart_on_ping_failure` INTEGER NOT NULL DEFAULT false, `ping_target` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true, `position` INTEGER NOT NULL DEFAULT 0, `auto_tunnel_apps` TEXT NOT NULL DEFAULT '[]')",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "name",
|
|
||||||
"columnName": "name",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "wgQuick",
|
|
||||||
"columnName": "wg_quick",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelNetworks",
|
|
||||||
"columnName": "tunnel_networks",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isMobileDataTunnel",
|
|
||||||
"columnName": "is_mobile_data_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPrimaryTunnel",
|
|
||||||
"columnName": "is_primary_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "amQuick",
|
|
||||||
"columnName": "am_quick",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isActive",
|
|
||||||
"columnName": "is_Active",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "restartOnPingFailure",
|
|
||||||
"columnName": "restart_on_ping_failure",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "pingTarget",
|
|
||||||
"columnName": "ping_target",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"defaultValue": "null"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isEthernetTunnel",
|
|
||||||
"columnName": "is_ethernet_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isIpv4Preferred",
|
|
||||||
"columnName": "is_ipv4_preferred",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "position",
|
|
||||||
"columnName": "position",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "autoTunnelApps",
|
|
||||||
"columnName": "auto_tunnel_apps",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "'[]'"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [
|
|
||||||
{
|
|
||||||
"name": "index_TunnelConfig_name",
|
|
||||||
"unique": true,
|
|
||||||
"columnNames": [
|
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"orders": [],
|
|
||||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"setupQueries": [
|
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
|
||||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '82bdb96b7a9f8695a34ad1ec21d9aea8')"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,359 +0,0 @@
|
|||||||
{
|
|
||||||
"formatVersion": 1,
|
|
||||||
"database": {
|
|
||||||
"version": 20,
|
|
||||||
"identityHash": "51f828868c0ea2f0f5c987410ff5c5a1",
|
|
||||||
"entities": [
|
|
||||||
{
|
|
||||||
"tableName": "Settings",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL, `trusted_network_ssids` TEXT NOT NULL, `is_always_on_vpn_enabled` INTEGER NOT NULL, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT false, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT false, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT false, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT false, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT false, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT true, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER, `app_mode` INTEGER NOT NULL DEFAULT 0, `dns_protocol` INTEGER NOT NULL DEFAULT 0, `dns_endpoint` TEXT)",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isAutoTunnelEnabled",
|
|
||||||
"columnName": "is_tunnel_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnMobileDataEnabled",
|
|
||||||
"columnName": "is_tunnel_on_mobile_data_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "trustedNetworkSSIDs",
|
|
||||||
"columnName": "trusted_network_ssids",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isAlwaysOnVpnEnabled",
|
|
||||||
"columnName": "is_always_on_vpn_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnEthernetEnabled",
|
|
||||||
"columnName": "is_tunnel_on_ethernet_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isShortcutsEnabled",
|
|
||||||
"columnName": "is_shortcuts_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnWifiEnabled",
|
|
||||||
"columnName": "is_tunnel_on_wifi_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isRestoreOnBootEnabled",
|
|
||||||
"columnName": "is_restore_on_boot_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isMultiTunnelEnabled",
|
|
||||||
"columnName": "is_multi_tunnel_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPingEnabled",
|
|
||||||
"columnName": "is_ping_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isWildcardsEnabled",
|
|
||||||
"columnName": "is_wildcards_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isStopOnNoInternetEnabled",
|
|
||||||
"columnName": "is_stop_on_no_internet_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isLanOnKillSwitchEnabled",
|
|
||||||
"columnName": "is_lan_on_kill_switch_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "debounceDelaySeconds",
|
|
||||||
"columnName": "debounce_delay_seconds",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
|
||||||
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnUnsecureEnabled",
|
|
||||||
"columnName": "is_tunnel_on_unsecure_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "wifiDetectionMethod",
|
|
||||||
"columnName": "wifi_detection_method",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPingMonitoringEnabled",
|
|
||||||
"columnName": "is_ping_monitoring_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelPingIntervalSeconds",
|
|
||||||
"columnName": "tunnel_ping_interval_sec",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "30"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelPingAttempts",
|
|
||||||
"columnName": "tunnel_ping_attempts",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelPingTimeoutSeconds",
|
|
||||||
"columnName": "tunnel_ping_timeout_sec",
|
|
||||||
"affinity": "INTEGER"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "appMode",
|
|
||||||
"columnName": "app_mode",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "dnsProtocol",
|
|
||||||
"columnName": "dns_protocol",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "dnsEndpoint",
|
|
||||||
"columnName": "dns_endpoint",
|
|
||||||
"affinity": "TEXT"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"tableName": "TunnelConfig",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `restart_on_ping_failure` INTEGER NOT NULL DEFAULT false, `ping_target` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true, `position` INTEGER NOT NULL DEFAULT 0, `auto_tunnel_apps` TEXT NOT NULL DEFAULT '[]')",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "name",
|
|
||||||
"columnName": "name",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "wgQuick",
|
|
||||||
"columnName": "wg_quick",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelNetworks",
|
|
||||||
"columnName": "tunnel_networks",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isMobileDataTunnel",
|
|
||||||
"columnName": "is_mobile_data_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPrimaryTunnel",
|
|
||||||
"columnName": "is_primary_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "amQuick",
|
|
||||||
"columnName": "am_quick",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isActive",
|
|
||||||
"columnName": "is_Active",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "restartOnPingFailure",
|
|
||||||
"columnName": "restart_on_ping_failure",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "pingTarget",
|
|
||||||
"columnName": "ping_target",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"defaultValue": "null"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isEthernetTunnel",
|
|
||||||
"columnName": "is_ethernet_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isIpv4Preferred",
|
|
||||||
"columnName": "is_ipv4_preferred",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "position",
|
|
||||||
"columnName": "position",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "autoTunnelApps",
|
|
||||||
"columnName": "auto_tunnel_apps",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "'[]'"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [
|
|
||||||
{
|
|
||||||
"name": "index_TunnelConfig_name",
|
|
||||||
"unique": true,
|
|
||||||
"columnNames": [
|
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"orders": [],
|
|
||||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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 false, `socks5_proxy_bind_address` TEXT, `http_proxy_enable` INTEGER NOT NULL DEFAULT false, `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": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "socks5ProxyBindAddress",
|
|
||||||
"columnName": "socks5_proxy_bind_address",
|
|
||||||
"affinity": "TEXT"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "httpProxyEnabled",
|
|
||||||
"columnName": "http_proxy_enable",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"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, '51f828868c0ea2f0f5c987410ff5c5a1')"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,359 +0,0 @@
|
|||||||
{
|
|
||||||
"formatVersion": 1,
|
|
||||||
"database": {
|
|
||||||
"version": 21,
|
|
||||||
"identityHash": "51f828868c0ea2f0f5c987410ff5c5a1",
|
|
||||||
"entities": [
|
|
||||||
{
|
|
||||||
"tableName": "Settings",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL, `trusted_network_ssids` TEXT NOT NULL, `is_always_on_vpn_enabled` INTEGER NOT NULL, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT false, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT false, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT false, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT false, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT false, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT true, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER, `app_mode` INTEGER NOT NULL DEFAULT 0, `dns_protocol` INTEGER NOT NULL DEFAULT 0, `dns_endpoint` TEXT)",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isAutoTunnelEnabled",
|
|
||||||
"columnName": "is_tunnel_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnMobileDataEnabled",
|
|
||||||
"columnName": "is_tunnel_on_mobile_data_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "trustedNetworkSSIDs",
|
|
||||||
"columnName": "trusted_network_ssids",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isAlwaysOnVpnEnabled",
|
|
||||||
"columnName": "is_always_on_vpn_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnEthernetEnabled",
|
|
||||||
"columnName": "is_tunnel_on_ethernet_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isShortcutsEnabled",
|
|
||||||
"columnName": "is_shortcuts_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnWifiEnabled",
|
|
||||||
"columnName": "is_tunnel_on_wifi_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isRestoreOnBootEnabled",
|
|
||||||
"columnName": "is_restore_on_boot_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isMultiTunnelEnabled",
|
|
||||||
"columnName": "is_multi_tunnel_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPingEnabled",
|
|
||||||
"columnName": "is_ping_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isWildcardsEnabled",
|
|
||||||
"columnName": "is_wildcards_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isStopOnNoInternetEnabled",
|
|
||||||
"columnName": "is_stop_on_no_internet_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isLanOnKillSwitchEnabled",
|
|
||||||
"columnName": "is_lan_on_kill_switch_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "debounceDelaySeconds",
|
|
||||||
"columnName": "debounce_delay_seconds",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
|
||||||
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnUnsecureEnabled",
|
|
||||||
"columnName": "is_tunnel_on_unsecure_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "wifiDetectionMethod",
|
|
||||||
"columnName": "wifi_detection_method",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPingMonitoringEnabled",
|
|
||||||
"columnName": "is_ping_monitoring_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelPingIntervalSeconds",
|
|
||||||
"columnName": "tunnel_ping_interval_sec",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "30"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelPingAttempts",
|
|
||||||
"columnName": "tunnel_ping_attempts",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelPingTimeoutSeconds",
|
|
||||||
"columnName": "tunnel_ping_timeout_sec",
|
|
||||||
"affinity": "INTEGER"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "appMode",
|
|
||||||
"columnName": "app_mode",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "dnsProtocol",
|
|
||||||
"columnName": "dns_protocol",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "dnsEndpoint",
|
|
||||||
"columnName": "dns_endpoint",
|
|
||||||
"affinity": "TEXT"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"tableName": "TunnelConfig",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `restart_on_ping_failure` INTEGER NOT NULL DEFAULT false, `ping_target` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true, `position` INTEGER NOT NULL DEFAULT 0, `auto_tunnel_apps` TEXT NOT NULL DEFAULT '[]')",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "name",
|
|
||||||
"columnName": "name",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "wgQuick",
|
|
||||||
"columnName": "wg_quick",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelNetworks",
|
|
||||||
"columnName": "tunnel_networks",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isMobileDataTunnel",
|
|
||||||
"columnName": "is_mobile_data_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPrimaryTunnel",
|
|
||||||
"columnName": "is_primary_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "amQuick",
|
|
||||||
"columnName": "am_quick",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isActive",
|
|
||||||
"columnName": "is_Active",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "restartOnPingFailure",
|
|
||||||
"columnName": "restart_on_ping_failure",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "pingTarget",
|
|
||||||
"columnName": "ping_target",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"defaultValue": "null"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isEthernetTunnel",
|
|
||||||
"columnName": "is_ethernet_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isIpv4Preferred",
|
|
||||||
"columnName": "is_ipv4_preferred",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "position",
|
|
||||||
"columnName": "position",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "autoTunnelApps",
|
|
||||||
"columnName": "auto_tunnel_apps",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "'[]'"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [
|
|
||||||
{
|
|
||||||
"name": "index_TunnelConfig_name",
|
|
||||||
"unique": true,
|
|
||||||
"columnNames": [
|
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"orders": [],
|
|
||||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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 false, `socks5_proxy_bind_address` TEXT, `http_proxy_enable` INTEGER NOT NULL DEFAULT false, `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": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "socks5ProxyBindAddress",
|
|
||||||
"columnName": "socks5_proxy_bind_address",
|
|
||||||
"affinity": "TEXT"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "httpProxyEnabled",
|
|
||||||
"columnName": "http_proxy_enable",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"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, '51f828868c0ea2f0f5c987410ff5c5a1')"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,364 +0,0 @@
|
|||||||
{
|
|
||||||
"formatVersion": 1,
|
|
||||||
"database": {
|
|
||||||
"version": 22,
|
|
||||||
"identityHash": "db93d0490401ccbef25ca39f27bafa29",
|
|
||||||
"entities": [
|
|
||||||
{
|
|
||||||
"tableName": "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_always_on_vpn_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL DEFAULT 0, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_wifi_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_ping_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, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT 0, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT 0, `wifi_detection_method` 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, `app_mode` INTEGER NOT NULL DEFAULT 0, `dns_protocol` INTEGER NOT NULL DEFAULT 0, `dns_endpoint` TEXT)",
|
|
||||||
"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": "isAlwaysOnVpnEnabled",
|
|
||||||
"columnName": "is_always_on_vpn_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnEthernetEnabled",
|
|
||||||
"columnName": "is_tunnel_on_ethernet_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isShortcutsEnabled",
|
|
||||||
"columnName": "is_shortcuts_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isTunnelOnWifiEnabled",
|
|
||||||
"columnName": "is_tunnel_on_wifi_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": "isPingEnabled",
|
|
||||||
"columnName": "is_ping_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": "isLanOnKillSwitchEnabled",
|
|
||||||
"columnName": "is_lan_on_kill_switch_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "debounceDelaySeconds",
|
|
||||||
"columnName": "debounce_delay_seconds",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "3"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
|
||||||
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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": "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": "appMode",
|
|
||||||
"columnName": "app_mode",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "dnsProtocol",
|
|
||||||
"columnName": "dns_protocol",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "dnsEndpoint",
|
|
||||||
"columnName": "dns_endpoint",
|
|
||||||
"affinity": "TEXT"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"tableName": "TunnelConfig",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `restart_on_ping_failure` INTEGER NOT NULL DEFAULT false, `ping_target` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true, `position` INTEGER NOT NULL DEFAULT 0, `auto_tunnel_apps` TEXT NOT NULL DEFAULT '[]')",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "name",
|
|
||||||
"columnName": "name",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "wgQuick",
|
|
||||||
"columnName": "wg_quick",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "tunnelNetworks",
|
|
||||||
"columnName": "tunnel_networks",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isMobileDataTunnel",
|
|
||||||
"columnName": "is_mobile_data_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPrimaryTunnel",
|
|
||||||
"columnName": "is_primary_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "amQuick",
|
|
||||||
"columnName": "am_quick",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "''"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isActive",
|
|
||||||
"columnName": "is_Active",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "restartOnPingFailure",
|
|
||||||
"columnName": "restart_on_ping_failure",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "pingTarget",
|
|
||||||
"columnName": "ping_target",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"defaultValue": "null"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isEthernetTunnel",
|
|
||||||
"columnName": "is_ethernet_tunnel",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isIpv4Preferred",
|
|
||||||
"columnName": "is_ipv4_preferred",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "true"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "position",
|
|
||||||
"columnName": "position",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "autoTunnelApps",
|
|
||||||
"columnName": "auto_tunnel_apps",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true,
|
|
||||||
"defaultValue": "'[]'"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [
|
|
||||||
{
|
|
||||||
"name": "index_TunnelConfig_name",
|
|
||||||
"unique": true,
|
|
||||||
"columnNames": [
|
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"orders": [],
|
|
||||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"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, 'db93d0490401ccbef25ca39f27bafa29')"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@ import androidx.room.testing.MigrationTestHelper
|
|||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.Queries
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@@ -23,6 +24,8 @@ class MigrationTest {
|
|||||||
helper.createDatabase(dbName, 6).apply {
|
helper.createDatabase(dbName, 6).apply {
|
||||||
// Database has schema version 1. Insert some data using SQL queries.
|
// Database has schema version 1. Insert some data using SQL queries.
|
||||||
// You can't use DAO classes because they expect the latest schema.
|
// You can't use DAO classes because they expect the latest schema.
|
||||||
|
execSQL(Queries.createDefaultSettings())
|
||||||
|
execSQL(Queries.createTunnelConfig())
|
||||||
// Prepare for the next version.
|
// Prepare for the next version.
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<color name="ic_launcher_background">#648DB3</color>
|
|
||||||
</resources>
|
|
||||||
@@ -12,6 +12,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.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||||
<!--start service on boot permission-->
|
<!--start service on boot permission-->
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
@@ -47,10 +48,6 @@
|
|||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent>
|
</intent>
|
||||||
<intent>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
|
||||||
</intent>
|
|
||||||
</queries>
|
</queries>
|
||||||
<application
|
<application
|
||||||
android:name=".WireGuardAutoTunnel"
|
android:name=".WireGuardAutoTunnel"
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel
|
package com.zaneschepke.wireguardautotunnel
|
||||||
|
|
||||||
import ProxySettingsScreen
|
import android.Manifest
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.net.VpnService
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
@@ -16,83 +16,78 @@ import androidx.activity.result.ActivityResult
|
|||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.slideInVertically
|
||||||
|
import androidx.compose.animation.slideOutVertically
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import androidx.navigation.navigation
|
|
||||||
import androidx.navigation.toRoute
|
import androidx.navigation.toRoute
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.sideeffect.GlobalSideEffect
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.LocalIsAndroidTV
|
|
||||||
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.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.navigation.Route
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.BottomNavbar
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.BottomNavbar
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.DynamicTopAppBar
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.DynamicTopAppBar
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.currentNavBackStackEntryAsNavBarState
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.AutoTunnelScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.AutoTunnelScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.AutoTunnelAdvancedScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.AutoTunnelAdvancedScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.detection.WifiDetectionMethodScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.detection.WifiDetectionMethodScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.LocationDisclosureScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.LocationDisclosureScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.TunnelAutoTunnelScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.ConfigScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel.SplitTunnelScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.TunnelOptionsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.pin.PinLockScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.pin.PinLockScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.SettingsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.SettingsScreen
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.advanced.SettingsAdvancedScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.AppearanceScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.AppearanceScreen
|
||||||
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.killswitch.KillSwitchScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.logs.LogsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.logs.LogsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.monitoring.TunnelMonitoringScreen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.system.SystemFeaturesScreen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.license.LicenseScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.license.LicenseScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.TunnelsScreen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.autotunnel.TunnelAutoTunnelScreen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.config.ConfigScreen
|
|
||||||
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.tunneloptions.TunnelOptionsScreen
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.AlertRed
|
|
||||||
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.extensions.isRunningOnTv
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.*
|
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import de.raphaelebner.roomdatabasebackup.core.RoomBackup
|
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.launch
|
import kotlin.system.exitProcess
|
||||||
import xyz.teamgravity.pin_lock_compose.PinManager
|
import org.amnezia.awg.backend.GoBackend.VpnService
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@Inject lateinit var appStateRepository: AppStateRepository
|
@Inject lateinit var appStateRepository: AppStateRepository
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
|
||||||
@Inject lateinit var networkMonitor: NetworkMonitor
|
|
||||||
@Inject lateinit var appDatabase: AppDatabase
|
|
||||||
|
|
||||||
private lateinit var roomBackup: RoomBackup
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
|
@Inject lateinit var networkMonitor: NetworkMonitor
|
||||||
|
|
||||||
|
private var lastLocationPermissionState: Boolean? = null
|
||||||
|
|
||||||
|
val REQUEST_CODE = 123
|
||||||
|
|
||||||
@SuppressLint("BatteryLife")
|
@SuppressLint("BatteryLife")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@@ -105,39 +100,31 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
roomBackup = RoomBackup(this)
|
val viewModel by viewModels<AppViewModel>()
|
||||||
|
|
||||||
val viewModel by viewModels<SharedAppViewModel>()
|
|
||||||
|
|
||||||
installSplashScreen().apply {
|
installSplashScreen().apply {
|
||||||
setKeepOnScreenCondition { !viewModel.container.stateFlow.value.isAppLoaded }
|
setKeepOnScreenCondition { !viewModel.appViewState.value.isAppReady }
|
||||||
}
|
}
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
val context = LocalContext.current
|
|
||||||
val isTv = isRunningOnTv()
|
val isTv = isRunningOnTv()
|
||||||
val appState by viewModel.container.stateFlow.collectAsStateWithLifecycle()
|
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
|
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
||||||
|
val tunnelError by viewModel.tunnelManager.errorEvents.collectAsStateWithLifecycle(null)
|
||||||
|
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val scope = rememberCoroutineScope()
|
val backStackEntry by navController.currentBackStackEntryAsState()
|
||||||
|
val navBarState by
|
||||||
var pinManagerInitialized by remember { mutableStateOf(false) }
|
currentNavBackStackEntryAsNavBarState(
|
||||||
|
navController,
|
||||||
LaunchedEffect(appState.isAppLoaded) {
|
backStackEntry,
|
||||||
if (appState.isAppLoaded) {
|
viewModel,
|
||||||
if (appState.pinLockEnabled && !pinManagerInitialized) {
|
appUiState,
|
||||||
PinManager.initialize(this@MainActivity)
|
appViewState,
|
||||||
pinManagerInitialized = true
|
)
|
||||||
}
|
|
||||||
appState.locale.let { LocaleUtil.changeLocale(it) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val snackbar = remember { SnackbarHostState() }
|
val snackbar = remember { SnackbarHostState() }
|
||||||
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 {
|
|
||||||
mutableStateOf<Pair<AppMode?, TunnelConf?>>(Pair(null, null))
|
|
||||||
}
|
|
||||||
|
|
||||||
val vpnActivity =
|
val vpnActivity =
|
||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
@@ -149,86 +136,95 @@ class MainActivity : AppCompatActivity() {
|
|||||||
} else {
|
} else {
|
||||||
vpnPermissionDenied = false
|
vpnPermissionDenied = false
|
||||||
showVpnPermissionDialog = false
|
showVpnPermissionDialog = false
|
||||||
val (appMode, config) = requestingAppMode
|
|
||||||
when (appMode) {
|
|
||||||
AppMode.VPN -> if (config != null) viewModel.startTunnel(config)
|
|
||||||
AppMode.LOCK_DOWN -> viewModel.setAppMode(AppMode.LOCK_DOWN)
|
|
||||||
else -> Unit
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
requestingAppMode = Pair(null, null)
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
LaunchedEffect(appUiState.tunnels) {
|
||||||
|
if (!appViewState.isAppReady) {
|
||||||
|
viewModel.handleEvent(AppEvent.AppReadyCheck(appUiState.tunnels))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val batteryActivity =
|
val batteryActivity =
|
||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.StartActivityForResult()
|
||||||
) { _: ActivityResult ->
|
) { _: ActivityResult ->
|
||||||
viewModel.disableBatteryOptimizationsShown()
|
viewModel.handleEvent(AppEvent.SetBatteryOptimizeDisableShown)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requestDisableBatteryOptimizations() {
|
LaunchedEffect(tunnelError) {
|
||||||
batteryActivity.launch(
|
if (tunnelError == null) return@LaunchedEffect
|
||||||
Intent().apply {
|
val message = tunnelError!!.second.toStringRes()
|
||||||
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
val context = this@MainActivity
|
||||||
data = "package:${this@MainActivity.packageName}".toUri()
|
snackbar.showSnackbar(
|
||||||
}
|
context.getString(R.string.tunnel_error_template, context.getString(message))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
with(appViewState) {
|
||||||
viewModel.globalSideEffect.collect { sideEffect ->
|
LaunchedEffect(isConfigChanged) {
|
||||||
when (sideEffect) {
|
if (isConfigChanged) {
|
||||||
GlobalSideEffect.ConfigChanged -> restartApp()
|
Intent(this@MainActivity, MainActivity::class.java).also {
|
||||||
GlobalSideEffect.PopBackStack -> navController.popBackStack()
|
startActivity(it)
|
||||||
GlobalSideEffect.RequestBatteryOptimizationDisabled ->
|
exitProcess(0)
|
||||||
requestDisableBatteryOptimizations()
|
|
||||||
is GlobalSideEffect.RequestVpnPermission -> {
|
|
||||||
requestingAppMode = Pair(sideEffect.requestingMode, sideEffect.config)
|
|
||||||
vpnActivity.launch(VpnService.prepare(this@MainActivity))
|
|
||||||
}
|
}
|
||||||
is GlobalSideEffect.ShareFile -> context.launchShareFile(sideEffect.file)
|
}
|
||||||
is GlobalSideEffect.Snackbar ->
|
}
|
||||||
scope.launch {
|
LaunchedEffect(errorMessage) {
|
||||||
snackbar.showSnackbar(sideEffect.message.asString(context))
|
errorMessage?.let {
|
||||||
|
snackbar.showSnackbar(it.asString(this@MainActivity))
|
||||||
|
viewModel.handleEvent(AppEvent.MessageShown)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LaunchedEffect(popBackStack) {
|
||||||
|
if (popBackStack) {
|
||||||
|
navController.popBackStack()
|
||||||
|
viewModel.handleEvent(AppEvent.PopBackStack(false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LaunchedEffect(requestVpnPermission) {
|
||||||
|
if (requestVpnPermission) {
|
||||||
|
if (!vpnPermissionDenied) {
|
||||||
|
vpnActivity.launch(VpnService.prepare(this@MainActivity))
|
||||||
|
} else {
|
||||||
|
showVpnPermissionDialog = true
|
||||||
|
}
|
||||||
|
viewModel.handleEvent(AppEvent.VpnPermissionRequested)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LaunchedEffect(requestBatteryPermission) {
|
||||||
|
if (requestBatteryPermission) {
|
||||||
|
batteryActivity.launch(
|
||||||
|
Intent().apply {
|
||||||
|
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||||
|
data = "package:${this@MainActivity.packageName}".toUri()
|
||||||
}
|
}
|
||||||
is GlobalSideEffect.Toast ->
|
)
|
||||||
scope.launch { context.showToast(sideEffect.message.asString(context)) }
|
|
||||||
is GlobalSideEffect.LaunchUrl -> context.openWebUrl(sideEffect.url)
|
|
||||||
is GlobalSideEffect.InstallApk -> context.installApk(sideEffect.apk)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!appState.isAppLoaded) return@setContent
|
CompositionLocalProvider(LocalIsAndroidTV provides isTv) {
|
||||||
|
CompositionLocalProvider(LocalNavController provides navController) {
|
||||||
CompositionLocalProvider(
|
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||||
LocalIsAndroidTV provides isTv,
|
VpnDeniedDialog(
|
||||||
LocalSharedVm provides viewModel,
|
showVpnPermissionDialog,
|
||||||
LocalNavController provides navController,
|
onDismiss = {
|
||||||
) {
|
showVpnPermissionDialog = false
|
||||||
WireguardAutoTunnelTheme(theme = appState.theme) {
|
vpnPermissionDenied = false
|
||||||
VpnDeniedDialog(
|
},
|
||||||
showVpnPermissionDialog,
|
)
|
||||||
onDismiss = {
|
|
||||||
showVpnPermissionDialog = false
|
|
||||||
vpnPermissionDenied = false
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
|
||||||
if (appState.settings.appMode == AppMode.LOCK_DOWN) {
|
|
||||||
AppAlertBanner(
|
|
||||||
stringResource(R.string.locked_down).uppercase(Locale.getDefault()),
|
|
||||||
OffWhite,
|
|
||||||
AlertRed,
|
|
||||||
modifier = Modifier.fillMaxWidth().zIndex(2f),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
modifier =
|
||||||
|
Modifier.pointerInput(Unit) {
|
||||||
|
detectTapGestures {
|
||||||
|
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||||
|
}
|
||||||
|
},
|
||||||
snackbarHost = {
|
snackbarHost = {
|
||||||
SnackbarHost(snackbar) { snackbarData ->
|
SnackbarHost(snackbar) { snackbarData: SnackbarData ->
|
||||||
CustomSnackBar(
|
CustomSnackBar(
|
||||||
snackbarData.visuals.message,
|
snackbarData.visuals.message,
|
||||||
isRtl = false,
|
isRtl = false,
|
||||||
@@ -237,13 +233,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
topBar = { DynamicTopAppBar(appState.navBarState) },
|
topBar = { DynamicTopAppBar(navBarState) },
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
BottomNavbar(
|
AnimatedVisibility(
|
||||||
appState.isAutoTunnelActive,
|
visible = navBarState.showBottom,
|
||||||
appState.navBarState,
|
enter = slideInVertically(initialOffsetY = { it }),
|
||||||
navController,
|
exit = slideOutVertically(targetOffsetY = { it }),
|
||||||
)
|
) {
|
||||||
|
BottomNavbar(appUiState = appUiState)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
) { padding ->
|
) { padding ->
|
||||||
Box(
|
Box(
|
||||||
@@ -255,131 +253,74 @@ class MainActivity : AppCompatActivity() {
|
|||||||
.imePadding()
|
.imePadding()
|
||||||
) {
|
) {
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController,
|
||||||
startDestination =
|
startDestination =
|
||||||
if (appState.pinLockEnabled && !appState.isAuthorized)
|
(if (appUiState.appState.isPinLockEnabled) Route.Lock
|
||||||
Route.Lock
|
else Route.Main),
|
||||||
else Route.TunnelsGraph,
|
|
||||||
) {
|
) {
|
||||||
composable<Route.Lock> { PinLockScreen() }
|
composable<Route.Main> {
|
||||||
navigation<Route.TunnelsGraph>(
|
MainScreen(appUiState, appViewState, viewModel)
|
||||||
startDestination = Route.Tunnels
|
|
||||||
) {
|
|
||||||
composable<Route.Tunnels> {
|
|
||||||
val viewModel =
|
|
||||||
it.sharedViewModel<TunnelsViewModel>(navController)
|
|
||||||
TunnelsScreen(viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.Sort> {
|
|
||||||
val viewModel =
|
|
||||||
it.sharedViewModel<TunnelsViewModel>(navController)
|
|
||||||
SortScreen(viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.TunnelOptions> { backStackEntry ->
|
|
||||||
val args = backStackEntry.toRoute<Route.TunnelOptions>()
|
|
||||||
val viewModel =
|
|
||||||
backStackEntry.sharedViewModel<TunnelsViewModel>(
|
|
||||||
navController
|
|
||||||
)
|
|
||||||
TunnelOptionsScreen(args.id, viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.SplitTunnel> { backStackEntry ->
|
|
||||||
val args = backStackEntry.toRoute<Route.SplitTunnel>()
|
|
||||||
SplitTunnelScreen(args.id)
|
|
||||||
}
|
|
||||||
composable<Route.TunnelAutoTunnel> { backStackEntry ->
|
|
||||||
val args =
|
|
||||||
backStackEntry.toRoute<Route.TunnelAutoTunnel>()
|
|
||||||
val viewModel =
|
|
||||||
backStackEntry.sharedViewModel<TunnelsViewModel>(
|
|
||||||
navController
|
|
||||||
)
|
|
||||||
TunnelAutoTunnelScreen(args.id, viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.Config> { backStackEntry ->
|
|
||||||
val args = backStackEntry.toRoute<Route.Config>()
|
|
||||||
val viewModel =
|
|
||||||
backStackEntry.sharedViewModel<TunnelsViewModel>(
|
|
||||||
navController
|
|
||||||
)
|
|
||||||
ConfigScreen(args.id, viewModel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
composable<Route.Settings> {
|
||||||
navigation<Route.AutoTunnelGraph>(
|
SettingsScreen(appUiState, viewModel)
|
||||||
startDestination =
|
|
||||||
if (appState.isLocationDisclosureShown) Route.AutoTunnel
|
|
||||||
else Route.LocationDisclosure
|
|
||||||
) {
|
|
||||||
composable<Route.LocationDisclosure> {
|
|
||||||
val viewModel =
|
|
||||||
it.sharedViewModel<AutoTunnelViewModel>(
|
|
||||||
navController
|
|
||||||
)
|
|
||||||
LocationDisclosureScreen(viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.AutoTunnel> {
|
|
||||||
val viewModel =
|
|
||||||
it.sharedViewModel<AutoTunnelViewModel>(
|
|
||||||
navController
|
|
||||||
)
|
|
||||||
AutoTunnelScreen(viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.AdvancedAutoTunnel> {
|
|
||||||
val viewModel =
|
|
||||||
it.sharedViewModel<AutoTunnelViewModel>(
|
|
||||||
navController
|
|
||||||
)
|
|
||||||
AutoTunnelAdvancedScreen(viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.WifiDetectionMethod> {
|
|
||||||
val viewModel =
|
|
||||||
it.sharedViewModel<AutoTunnelViewModel>(
|
|
||||||
navController
|
|
||||||
)
|
|
||||||
WifiDetectionMethodScreen(viewModel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
composable<Route.SettingsAdvanced> {
|
||||||
navigation<Route.SettingsGraph>(
|
SettingsAdvancedScreen(appUiState, viewModel)
|
||||||
startDestination = Route.Settings
|
|
||||||
) {
|
|
||||||
composable<Route.Settings> {
|
|
||||||
val viewModel =
|
|
||||||
it.sharedViewModel<SettingsViewModel>(navController)
|
|
||||||
SettingsScreen(viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.TunnelMonitoring> {
|
|
||||||
val viewModel =
|
|
||||||
it.sharedViewModel<SettingsViewModel>(navController)
|
|
||||||
TunnelMonitoringScreen(viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.SystemFeatures> {
|
|
||||||
val viewModel =
|
|
||||||
it.sharedViewModel<SettingsViewModel>(navController)
|
|
||||||
SystemFeaturesScreen(viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.Dns> {
|
|
||||||
val viewModel =
|
|
||||||
it.sharedViewModel<SettingsViewModel>(navController)
|
|
||||||
DnsSettingsScreen(viewModel)
|
|
||||||
}
|
|
||||||
composable<Route.ProxySettings> { ProxySettingsScreen() }
|
|
||||||
composable<Route.Appearance> { AppearanceScreen() }
|
|
||||||
composable<Route.Language> { LanguageScreen() }
|
|
||||||
composable<Route.Display> { DisplayScreen() }
|
|
||||||
composable<Route.Logs> { LogsScreen() }
|
|
||||||
}
|
}
|
||||||
|
composable<Route.LocationDisclosure> {
|
||||||
navigation<Route.SupportGraph>(
|
LocationDisclosureScreen(appUiState, viewModel)
|
||||||
startDestination = Route.Support
|
}
|
||||||
) {
|
composable<Route.AutoTunnel> {
|
||||||
composable<Route.Support> {
|
AutoTunnelScreen(appUiState, viewModel)
|
||||||
val viewModel =
|
}
|
||||||
it.sharedViewModel<SupportViewModel>(navController)
|
composable<Route.Appearance> { AppearanceScreen() }
|
||||||
SupportScreen(viewModel)
|
composable<Route.Language> {
|
||||||
}
|
LanguageScreen(appUiState, viewModel)
|
||||||
composable<Route.License> { LicenseScreen() }
|
}
|
||||||
|
composable<Route.Display> {
|
||||||
|
DisplayScreen(appUiState, viewModel)
|
||||||
|
}
|
||||||
|
composable<Route.Support> {
|
||||||
|
SupportScreen(appViewModel = viewModel)
|
||||||
|
}
|
||||||
|
composable<Route.License> { LicenseScreen() }
|
||||||
|
composable<Route.AutoTunnelAdvanced> {
|
||||||
|
AutoTunnelAdvancedScreen(appUiState, viewModel)
|
||||||
|
}
|
||||||
|
composable<Route.WifiDetectionMethod> {
|
||||||
|
WifiDetectionMethodScreen(appUiState, viewModel)
|
||||||
|
}
|
||||||
|
composable<Route.Logs> { LogsScreen(appViewState, viewModel) }
|
||||||
|
composable<Route.Config> { backStack ->
|
||||||
|
val args = backStack.toRoute<Route.Config>()
|
||||||
|
val config =
|
||||||
|
appUiState.tunnels.firstOrNull { it.id == args.id }
|
||||||
|
ConfigScreen(config, viewModel)
|
||||||
|
}
|
||||||
|
composable<Route.TunnelOptions> { backStack ->
|
||||||
|
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||||
|
appUiState.tunnels
|
||||||
|
.firstOrNull { it.id == args.id }
|
||||||
|
?.let { config ->
|
||||||
|
TunnelOptionsScreen(config, viewModel, appViewState)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
composable<Route.Lock> { PinLockScreen(viewModel) }
|
||||||
|
composable<Route.KillSwitch> {
|
||||||
|
KillSwitchScreen(appUiState, viewModel)
|
||||||
|
}
|
||||||
|
composable<Route.SplitTunnel> { SplitTunnelScreen(viewModel) }
|
||||||
|
composable<Route.TunnelAutoTunnel> { backStack ->
|
||||||
|
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||||
|
appUiState.tunnels
|
||||||
|
.firstOrNull { it.id == args.id }
|
||||||
|
?.let {
|
||||||
|
TunnelAutoTunnelScreen(
|
||||||
|
it,
|
||||||
|
appUiState.appSettings,
|
||||||
|
viewModel,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,65 +333,19 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
WireGuardAutoTunnel.setUiActive(true)
|
checkPermissionAndNotify()
|
||||||
networkMonitor.checkPermissionsAndUpdateState()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
private fun checkPermissionAndNotify() {
|
||||||
super.onPause()
|
val hasLocation =
|
||||||
WireGuardAutoTunnel.setUiActive(false)
|
ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) ==
|
||||||
|
PackageManager.PERMISSION_GRANTED
|
||||||
|
if (lastLocationPermissionState != hasLocation) {
|
||||||
|
Timber.d("Location permission changed to: $hasLocation")
|
||||||
|
if (hasLocation) {
|
||||||
|
networkMonitor.sendLocationPermissionsGrantedBroadcast()
|
||||||
|
}
|
||||||
|
lastLocationPermissionState = hasLocation
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun performBackup() =
|
|
||||||
lifecycleScope.launch {
|
|
||||||
roomBackup
|
|
||||||
.database(appDatabase)
|
|
||||||
.backupLocation(RoomBackup.BACKUP_FILE_LOCATION_CUSTOM_DIALOG)
|
|
||||||
.enableLogDebug(true)
|
|
||||||
.maxFileCount(5)
|
|
||||||
.apply {
|
|
||||||
onCompleteListener { success, _, _ ->
|
|
||||||
lifecycleScope.launch {
|
|
||||||
if (success) {
|
|
||||||
showToast(
|
|
||||||
getString(
|
|
||||||
R.string.backup_success,
|
|
||||||
getString(R.string.restarting_app),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
restartApp()
|
|
||||||
} else {
|
|
||||||
showToast(R.string.backup_failed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.backup()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun performRestore() =
|
|
||||||
lifecycleScope.launch {
|
|
||||||
roomBackup
|
|
||||||
.database(appDatabase)
|
|
||||||
.enableLogDebug(true)
|
|
||||||
.backupLocation(RoomBackup.BACKUP_FILE_LOCATION_CUSTOM_DIALOG)
|
|
||||||
.apply {
|
|
||||||
onCompleteListener { success, _, _ ->
|
|
||||||
lifecycleScope.launch {
|
|
||||||
if (success) {
|
|
||||||
showToast(
|
|
||||||
getString(
|
|
||||||
R.string.restore_success,
|
|
||||||
getString(R.string.restarting_app),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
restartApp()
|
|
||||||
} else {
|
|
||||||
showToast(R.string.restore_failed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.restore()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,27 +4,27 @@ import android.app.Application
|
|||||||
import android.os.StrictMode
|
import android.os.StrictMode
|
||||||
import android.os.StrictMode.ThreadPolicy
|
import android.os.StrictMode.ThreadPolicy
|
||||||
import androidx.hilt.work.HiltWorkerFactory
|
import androidx.hilt.work.HiltWorkerFactory
|
||||||
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.lifecycle.ProcessLifecycleOwner
|
||||||
import androidx.work.Configuration
|
import androidx.work.Configuration
|
||||||
import com.wireguard.android.backend.GoBackend
|
import com.wireguard.android.backend.GoBackend
|
||||||
import com.zaneschepke.logcatter.LogReader
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationMonitor
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.worker.ServiceWorker
|
import com.zaneschepke.wireguardautotunnel.core.worker.ServiceWorker
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
||||||
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.cancel
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@HiltAndroidApp
|
@HiltAndroidApp
|
||||||
@@ -45,13 +45,12 @@ class WireGuardAutoTunnel : Application(), Configuration.Provider {
|
|||||||
|
|
||||||
@Inject @MainDispatcher lateinit var mainDispatcher: CoroutineDispatcher
|
@Inject @MainDispatcher lateinit var mainDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
@Inject lateinit var notificationMonitor: NotificationMonitor
|
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
instance = this
|
instance = this
|
||||||
|
ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifecycleObserver())
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
Timber.plant(Timber.DebugTree())
|
Timber.plant(Timber.DebugTree())
|
||||||
StrictMode.setThreadPolicy(
|
StrictMode.setThreadPolicy(
|
||||||
@@ -66,11 +65,6 @@ class WireGuardAutoTunnel : Application(), Configuration.Provider {
|
|||||||
Timber.plant(ReleaseTree())
|
Timber.plant(ReleaseTree())
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationScope.launch(ioDispatcher) {
|
|
||||||
launch { if (appDataRepository.appState.isLocalLogsEnabled()) logReader.start() }
|
|
||||||
launch { notificationMonitor.handleApplicationNotifications() }
|
|
||||||
}
|
|
||||||
|
|
||||||
GoBackend.setAlwaysOnCallback {
|
GoBackend.setAlwaysOnCallback {
|
||||||
applicationScope.launch {
|
applicationScope.launch {
|
||||||
val settings = appDataRepository.settings.get()
|
val settings = appDataRepository.settings.get()
|
||||||
@@ -84,23 +78,42 @@ class WireGuardAutoTunnel : Application(), Configuration.Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServiceWorker.start(this)
|
ServiceWorker.start(this)
|
||||||
|
|
||||||
|
applicationScope.launch {
|
||||||
|
appDataRepository.appState.getLocale()?.let {
|
||||||
|
withContext(mainDispatcher) { LocaleUtil.changeLocale(it) }
|
||||||
|
}
|
||||||
|
appDataRepository.appState.isLocalLogsEnabled().let { enabled ->
|
||||||
|
if (enabled) logReader.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTerminate() {
|
override fun onTerminate() {
|
||||||
applicationScope.cancel()
|
applicationScope.launch {
|
||||||
tunnelManager.setBackendMode(BackendMode.Inactive)
|
tunnelManager.setBackendState(BackendState.INACTIVE, emptyList())
|
||||||
|
}
|
||||||
super.onTerminate()
|
super.onTerminate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AppLifecycleObserver : DefaultLifecycleObserver {
|
||||||
|
|
||||||
|
override fun onStart(owner: LifecycleOwner) {
|
||||||
|
Timber.d("Application entered foreground")
|
||||||
|
foreground = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause(owner: LifecycleOwner) {
|
||||||
|
Timber.d("Application entered background")
|
||||||
|
foreground = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private var foreground = false
|
||||||
|
|
||||||
private val _uiActive = MutableStateFlow(false)
|
fun isForeground(): Boolean {
|
||||||
|
return foreground
|
||||||
val uiActive: StateFlow<Boolean>
|
|
||||||
get() = _uiActive
|
|
||||||
|
|
||||||
fun setUiActive(active: Boolean) {
|
|
||||||
_uiActive.update { active }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Volatile private var lastActiveTunnels: List<Int> = emptyList()
|
@Volatile private var lastActiveTunnels: List<Int> = emptyList()
|
||||||
|
|||||||
+17
-3
@@ -24,7 +24,6 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
|
|
||||||
@Inject lateinit var serviceManager: ServiceManager
|
@Inject lateinit var serviceManager: ServiceManager
|
||||||
|
|
||||||
// injecting this should let tunnelManger handle clean startup
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
@Inject lateinit var logReader: LogReader
|
@Inject lateinit var logReader: LogReader
|
||||||
@@ -35,7 +34,22 @@ class RestartReceiver : BroadcastReceiver() {
|
|||||||
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
||||||
serviceManager.updateTunnelTile()
|
serviceManager.updateTunnelTile()
|
||||||
serviceManager.updateAutoTunnelTile()
|
serviceManager.updateAutoTunnelTile()
|
||||||
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED)
|
applicationScope.launch(ioDispatcher) {
|
||||||
applicationScope.launch(ioDispatcher) { logReader.deleteAndClearLogs() }
|
val settings = appDataRepository.settings.get()
|
||||||
|
if (settings.isRestoreOnBootEnabled) {
|
||||||
|
if (
|
||||||
|
settings.isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null
|
||||||
|
) {
|
||||||
|
Timber.d("Starting auto-tunnel on boot/update")
|
||||||
|
serviceManager.startAutoTunnel()
|
||||||
|
} else {
|
||||||
|
Timber.d("Restoring previous tunnel state")
|
||||||
|
tunnelManager.restorePreviousState()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Timber.d("Restore on boot disabled, skipping")
|
||||||
|
}
|
||||||
|
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) logReader.deleteAndClearLogs()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-10
@@ -16,9 +16,9 @@ interface NotificationManager {
|
|||||||
title: String = "",
|
title: String = "",
|
||||||
actions: Collection<NotificationCompat.Action> = emptyList(),
|
actions: Collection<NotificationCompat.Action> = emptyList(),
|
||||||
description: String = "",
|
description: String = "",
|
||||||
showTimestamp: Boolean = true,
|
showTimestamp: Boolean = false,
|
||||||
importance: Int = NotificationManager.IMPORTANCE_HIGH,
|
importance: Int = NotificationManager.IMPORTANCE_HIGH,
|
||||||
onGoing: Boolean = false,
|
onGoing: Boolean = true,
|
||||||
onlyAlertOnce: Boolean = true,
|
onlyAlertOnce: Boolean = true,
|
||||||
): Notification
|
): Notification
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ interface NotificationManager {
|
|||||||
title: StringValue,
|
title: StringValue,
|
||||||
actions: Collection<NotificationCompat.Action> = emptyList(),
|
actions: Collection<NotificationCompat.Action> = emptyList(),
|
||||||
description: StringValue,
|
description: StringValue,
|
||||||
showTimestamp: Boolean = true,
|
showTimestamp: Boolean = false,
|
||||||
importance: Int = NotificationManager.IMPORTANCE_HIGH,
|
importance: Int = NotificationManager.IMPORTANCE_HIGH,
|
||||||
onGoing: Boolean = false,
|
onGoing: Boolean = true,
|
||||||
onlyAlertOnce: Boolean = true,
|
onlyAlertOnce: Boolean = true,
|
||||||
): Notification
|
): Notification
|
||||||
|
|
||||||
@@ -43,14 +43,8 @@ interface NotificationManager {
|
|||||||
fun show(notificationId: Int, notification: Notification)
|
fun show(notificationId: Int, notification: Notification)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val AUTO_TUNNEL_LOCATION_PERMISSION_ID = 123
|
|
||||||
const val AUTO_TUNNEL_LOCATION_SERVICES_ID = 124
|
|
||||||
// For auto tunnel foreground notification
|
|
||||||
const val AUTO_TUNNEL_NOTIFICATION_ID = 122
|
const val AUTO_TUNNEL_NOTIFICATION_ID = 122
|
||||||
// for tunnel foreground notification
|
|
||||||
const val VPN_NOTIFICATION_ID = 100
|
const val VPN_NOTIFICATION_ID = 100
|
||||||
const val TUNNEL_ERROR_NOTIFICATION_ID = 101
|
|
||||||
const val TUNNEL_MESSAGES_NOTIFICATION_ID = 102
|
|
||||||
const val EXTRA_ID = "id"
|
const val EXTRA_ID = "id"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-63
@@ -1,63 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.notification
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
|
||||||
import jakarta.inject.Inject
|
|
||||||
import kotlinx.coroutines.coroutineScope
|
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
class NotificationMonitor
|
|
||||||
@Inject
|
|
||||||
constructor(
|
|
||||||
private val tunnelManager: TunnelManager,
|
|
||||||
private val notificationManager: NotificationManager,
|
|
||||||
) {
|
|
||||||
suspend fun handleApplicationNotifications() = coroutineScope {
|
|
||||||
launch { handleTunnelErrors() }
|
|
||||||
launch { handleTunnelMessages() }
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun handleTunnelErrors() =
|
|
||||||
tunnelManager.errorEvents.collectLatest { (tunnelConf, error) ->
|
|
||||||
if (!WireGuardAutoTunnel.uiActive.value) {
|
|
||||||
val notification =
|
|
||||||
notificationManager.createNotification(
|
|
||||||
WireGuardNotification.NotificationChannels.VPN,
|
|
||||||
title = StringValue.DynamicString(tunnelConf.name),
|
|
||||||
description =
|
|
||||||
when (error) {
|
|
||||||
is BackendCoreException.BounceFailed -> error.toStringValue()
|
|
||||||
else ->
|
|
||||||
StringValue.StringResource(
|
|
||||||
R.string.tunnel_error_template,
|
|
||||||
error.toStringRes(),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
notificationManager.show(
|
|
||||||
NotificationManager.TUNNEL_ERROR_NOTIFICATION_ID,
|
|
||||||
notification,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun handleTunnelMessages() =
|
|
||||||
tunnelManager.messageEvents.collectLatest { (tunnelConf, message) ->
|
|
||||||
if (!WireGuardAutoTunnel.uiActive.value) {
|
|
||||||
val notification =
|
|
||||||
notificationManager.createNotification(
|
|
||||||
WireGuardNotification.NotificationChannels.VPN,
|
|
||||||
title = StringValue.DynamicString(tunnelConf.name),
|
|
||||||
description = message.toStringValue(),
|
|
||||||
)
|
|
||||||
notificationManager.show(
|
|
||||||
NotificationManager.TUNNEL_MESSAGES_NOTIFICATION_ID,
|
|
||||||
notification,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+6
-7
@@ -7,6 +7,9 @@ import android.content.ServiceConnection
|
|||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.AutoTunnelService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
|
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
||||||
@@ -26,9 +29,9 @@ class ServiceManager
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
private val applicationScope: CoroutineScope,
|
@ApplicationScope private val applicationScope: CoroutineScope,
|
||||||
private val mainDispatcher: CoroutineDispatcher,
|
@MainDispatcher private val mainDispatcher: CoroutineDispatcher,
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -93,8 +96,6 @@ constructor(
|
|||||||
service.stop()
|
service.stop()
|
||||||
try {
|
try {
|
||||||
context.unbindService(autoTunnelServiceConnection)
|
context.unbindService(autoTunnelServiceConnection)
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e, "Failed to unbind AutoTunnelService")
|
|
||||||
} finally {
|
} finally {
|
||||||
_tunnelService.value = null
|
_tunnelService.value = null
|
||||||
}
|
}
|
||||||
@@ -119,8 +120,6 @@ constructor(
|
|||||||
service.stop()
|
service.stop()
|
||||||
try {
|
try {
|
||||||
context.unbindService(tunnelServiceConnection)
|
context.unbindService(tunnelServiceConnection)
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e, "Failed to stop TunnelForegroundService")
|
|
||||||
} finally {
|
} finally {
|
||||||
_tunnelService.value = null
|
_tunnelService.value = null
|
||||||
}
|
}
|
||||||
|
|||||||
+189
-28
@@ -7,24 +7,27 @@ import android.os.IBinder
|
|||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
|
import com.zaneschepke.networkmonitor.NetworkStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelMonitor
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
import com.zaneschepke.wireguardautotunnel.util.extensions.distinctByKeys
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import io.ktor.util.collections.*
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -34,18 +37,23 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
|
|
||||||
@Inject lateinit var serviceManager: ServiceManager
|
@Inject lateinit var serviceManager: ServiceManager
|
||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
@Inject lateinit var networkMonitor: NetworkMonitor
|
||||||
|
|
||||||
@Inject lateinit var tunnelMonitor: TunnelMonitor
|
|
||||||
|
|
||||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
||||||
|
|
||||||
@Inject lateinit var appDataRepository: AppDataRepository
|
@Inject lateinit var tunnelRepo: TunnelRepository
|
||||||
|
|
||||||
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
|
private val isNetworkConnected = MutableStateFlow(true)
|
||||||
|
|
||||||
|
private val tunnelJobs = ConcurrentHashMap<TunnelConf, Job>()
|
||||||
|
private val pingJobs = ConcurrentHashMap<TunnelConf, Job>()
|
||||||
|
|
||||||
|
private val jobsMutex = Mutex()
|
||||||
|
|
||||||
class LocalBinder(val service: TunnelForegroundService) : Binder()
|
class LocalBinder(val service: TunnelForegroundService) : Binder()
|
||||||
|
|
||||||
private val tunnelJobs = ConcurrentMap<TunnelConf, Job>()
|
|
||||||
|
|
||||||
private val binder = LocalBinder(this)
|
private val binder = LocalBinder(this)
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
@@ -78,23 +86,94 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
fun start() =
|
fun start() =
|
||||||
lifecycleScope.launch(ioDispatcher) {
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
tunnelManager.activeTunnels.distinctByKeys().collect { activeTunnels ->
|
tunnelManager.activeTunnels.distinctByKeys().collect { activeTunnels ->
|
||||||
val activeTunConfigs = activeTunnels.keys
|
// No active tunnels and no jobs: nothing to do
|
||||||
val obsoleteJobs = tunnelJobs.keys - activeTunConfigs
|
if (activeTunnels.isEmpty() && tunnelJobs.isEmpty()) return@collect
|
||||||
obsoleteJobs.forEach { tunnelConf -> tunnelJobs[tunnelConf]?.cancel() }
|
|
||||||
activeTunConfigs.forEach { tun ->
|
// Synchronize jobs with active tunnels
|
||||||
if (tunnelJobs.containsKey(tun)) return@forEach
|
synchronizeJobs(activeTunnels)
|
||||||
tunnelJobs[tun] = launch { tunnelMonitor.startMonitoring(tun, true) }
|
updateServiceNotification()
|
||||||
}
|
|
||||||
updateServiceNotification(activeTunnels)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun synchronizeJobs(activeTunnels: Map<TunnelConf, TunnelState>) {
|
||||||
|
jobsMutex.withLock {
|
||||||
|
// Stop jobs for tunnels that are no longer active
|
||||||
|
stopInactiveJobs(activeTunnels)
|
||||||
|
// Start jobs for new tunnels
|
||||||
|
startNewJobs(activeTunnels)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopInactiveJobs(activeTunnels: Map<TunnelConf, TunnelState>) {
|
||||||
|
// If no active tunnels, clear all jobs
|
||||||
|
if (activeTunnels.isEmpty()) {
|
||||||
|
clearAllJobs()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Stop jobs for tunnels not in activeTunnels
|
||||||
|
val tunnelsToStop = tunnelJobs.keys - activeTunnels.keys
|
||||||
|
tunnelsToStop.forEach { tun -> stopTunnelJobs(tun) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun clearAllJobs() {
|
||||||
|
tunnelJobs.forEach { (tun, job) ->
|
||||||
|
Timber.d("Stopping tunnel job for ${tun.tunName}")
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
tunnelJobs.clear()
|
||||||
|
|
||||||
|
pingJobs.forEach { (tun, job) ->
|
||||||
|
if (isPingBounce(tun)) {
|
||||||
|
Timber.d("Preserving ping job for ${tun.tunName} due to PING bounce")
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
Timber.d("Stopping ping job for ${tun.tunName}")
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
pingJobs.entries.removeIf { (tun, _) -> !isPingBounce(tun) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopTunnelJobs(tun: TunnelConf) {
|
||||||
|
tunnelJobs.remove(tun)?.cancel()
|
||||||
|
Timber.d("Stopped tunnel job for ${tun.tunName}")
|
||||||
|
if (isPingBounce(tun))
|
||||||
|
return Timber.d("Preserving ${tun.tunName} ping job due to ping bounce")
|
||||||
|
pingJobs.remove(tun)?.cancel()
|
||||||
|
Timber.d("Stopped ping job for ${tun.tunName}")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startNewJobs(activeTunnels: Map<TunnelConf, TunnelState>) {
|
||||||
|
val tunnelsToStart = activeTunnels.keys - tunnelJobs.keys
|
||||||
|
tunnelsToStart.forEach { tun ->
|
||||||
|
tunnelJobs[tun] = startTunnelJobs(tun)
|
||||||
|
Timber.d("Started tunnel job for ${tun.tunName}")
|
||||||
|
|
||||||
|
if (pingJobs[tun]?.isActive == true) {
|
||||||
|
Timber.d("Reusing active ping job for ${tun.tunName}")
|
||||||
|
} else {
|
||||||
|
pingJobs[tun]?.cancel() // Cancel any stale job
|
||||||
|
if (tun.isPingEnabled) {
|
||||||
|
if (tun.isStaticallyConfigured()) {
|
||||||
|
Timber.d("Skipping ping for statically configured tunnel")
|
||||||
|
} else {
|
||||||
|
pingJobs[tun] = startPingJob(tun)
|
||||||
|
Timber.d("Started ping job for ${tun.tunName}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isPingBounce(tun: TunnelConf): Boolean =
|
||||||
|
tunnelManager.bouncingTunnelIds[tun.id] == TunnelStatus.StopReason.PING
|
||||||
|
|
||||||
// TODO Would be cool to have this include kill switch
|
// TODO Would be cool to have this include kill switch
|
||||||
private fun updateServiceNotification(activeTunnels: Map<TunnelConf, TunnelState>) {
|
// TODO also we need to include errors
|
||||||
|
private fun updateServiceNotification() {
|
||||||
val notification =
|
val notification =
|
||||||
when (activeTunnels.size) {
|
when (tunnelJobs.size) {
|
||||||
0 -> onCreateNotification()
|
0 -> onCreateNotification()
|
||||||
1 -> createTunnelNotification(activeTunnels.keys.first())
|
1 -> createTunnelNotification(tunnelJobs.keys.first())
|
||||||
else -> createTunnelsNotification()
|
else -> createTunnelsNotification()
|
||||||
}
|
}
|
||||||
ServiceCompat.startForeground(
|
ServiceCompat.startForeground(
|
||||||
@@ -105,18 +184,91 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use same scope so we can cancel all of these
|
||||||
|
private fun startTunnelJobs(tunnelConf: TunnelConf) =
|
||||||
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
|
// monitor if we have internet connectivity
|
||||||
|
launch { startNetworkMonitorJob() }
|
||||||
|
// job to trigger stats emit on interval
|
||||||
|
launch { startTunnelStatsJob(tunnelConf) }
|
||||||
|
// monitor changes to the tunnel config
|
||||||
|
launch { startTunnelConfChangesJob(tunnelConf) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun startTunnelConfChangesJob(tunnelConf: TunnelConf) {
|
||||||
|
tunnelRepo.flow
|
||||||
|
.flowOn(ioDispatcher)
|
||||||
|
.map { storedTunnels -> storedTunnels.firstOrNull { it.id == tunnelConf.id } }
|
||||||
|
.filterNotNull()
|
||||||
|
// only emit when one of these 3 values change
|
||||||
|
.distinctUntilChanged { old, new -> old == new }
|
||||||
|
.collect { storedTunnel ->
|
||||||
|
if (tunnelConf != storedTunnel) {
|
||||||
|
Timber.d("Config changed for ${storedTunnel.tunName}, bouncing")
|
||||||
|
// let this complete, even after cancel
|
||||||
|
withContext(NonCancellable) {
|
||||||
|
tunnelManager.bounceTunnel(
|
||||||
|
storedTunnel,
|
||||||
|
TunnelStatus.StopReason.CONFIG_CHANGED,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun startNetworkMonitorJob() {
|
||||||
|
networkMonitor.networkStatusFlow.flowOn(ioDispatcher).collectLatest { status ->
|
||||||
|
val isAvailable = status !is NetworkStatus.Disconnected
|
||||||
|
isNetworkConnected.value = isAvailable
|
||||||
|
Timber.d("Network available: $status")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun startTunnelStatsJob(tunnel: TunnelConf) = coroutineScope {
|
||||||
|
while (isActive) {
|
||||||
|
tunnelManager.updateTunnelStatistics(tunnel)
|
||||||
|
delay(STATS_DELAY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startPingJob(tunnel: TunnelConf) =
|
||||||
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
|
// delay for initial duration
|
||||||
|
delay(tunnel.pingInterval ?: Constants.PING_INTERVAL)
|
||||||
|
while (isActive) {
|
||||||
|
val shouldBounce = shouldBounceTunnel(tunnel)
|
||||||
|
val delayMs =
|
||||||
|
if (shouldBounce) {
|
||||||
|
// let this complete, even after cancel
|
||||||
|
withContext(NonCancellable) {
|
||||||
|
tunnelManager.bounceTunnel(tunnel, TunnelStatus.StopReason.PING)
|
||||||
|
}
|
||||||
|
tunnel.pingCooldown ?: Constants.PING_COOLDOWN
|
||||||
|
} else {
|
||||||
|
tunnel.pingInterval ?: Constants.PING_INTERVAL
|
||||||
|
}
|
||||||
|
delay(delayMs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun shouldBounceTunnel(tunnel: TunnelConf): Boolean {
|
||||||
|
if (!isNetworkConnected.value) {
|
||||||
|
Timber.d("Network disconnected, skipping ping for ${tunnel.tunName}")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return runCatching { !tunnel.isTunnelPingable(ioDispatcher) }
|
||||||
|
.onFailure { e -> Timber.e(e, "Ping check failed for ${tunnel.tunName}") }
|
||||||
|
.getOrDefault(true)
|
||||||
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
Timber.d("Stop called")
|
|
||||||
tunnelJobs.forEach { it.value.cancel() }
|
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
tunnelJobs.forEach { it.value.cancel() }
|
|
||||||
serviceManager.handleTunnelServiceDestroy()
|
serviceManager.handleTunnelServiceDestroy()
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||||
Timber.d("onDestroy")
|
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +283,6 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
tunnelConf.id,
|
tunnelConf.id,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
onGoing = true,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,4 +303,14 @@ class TunnelForegroundService : LifecycleService() {
|
|||||||
title = getString(R.string.tunnel_starting),
|
title = getString(R.string.tunnel_starting),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO add notification handling and optional log reading for restart on handshake failures
|
||||||
|
companion object {
|
||||||
|
const val STATS_DELAY = 1_000L
|
||||||
|
// ipv6 disabled or block on network
|
||||||
|
// Failed to send handshake initiation: write udp [::]"
|
||||||
|
// Failed to send data packets: write udp [::]
|
||||||
|
// Failed to send data packets: write udp 0.0.0.0:51820
|
||||||
|
// Handshake did not complete after 5 seconds, retrying
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+158
-300
@@ -3,39 +3,34 @@ package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import android.os.PowerManager
|
||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
|
||||||
import com.zaneschepke.networkmonitor.ConnectivityState
|
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
|
import com.zaneschepke.networkmonitor.NetworkStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelMonitor
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus.StopReason.Ping
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
import com.zaneschepke.wireguardautotunnel.domain.events.KillSwitchEvent
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.AutoTunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.AutoTunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.NetworkState
|
import com.zaneschepke.wireguardautotunnel.domain.state.NetworkState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.to
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toMillis
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Provider
|
import javax.inject.Provider
|
||||||
import kotlin.math.pow
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.sync.Mutex
|
|
||||||
import kotlinx.coroutines.sync.withLock
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -53,24 +48,20 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
|
|
||||||
@Inject lateinit var tunnelManager: TunnelManager
|
@Inject lateinit var tunnelManager: TunnelManager
|
||||||
|
|
||||||
@Inject lateinit var tunnelMonitor: TunnelMonitor
|
|
||||||
|
|
||||||
private val defaultState = AutoTunnelState()
|
private val defaultState = AutoTunnelState()
|
||||||
|
|
||||||
private val autoTunMutex = Mutex()
|
|
||||||
|
|
||||||
private val autoTunnelStateFlow = MutableStateFlow(defaultState)
|
private val autoTunnelStateFlow = MutableStateFlow(defaultState)
|
||||||
|
|
||||||
private val bounceCounts = MutableStateFlow<Map<Int, Int>>(emptyMap())
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
|
|
||||||
private var eventHandlerJob: Job? = null
|
private var killSwitchJob: Job? = null
|
||||||
|
|
||||||
private val lastBounceTimes = mutableMapOf<Int, Long>()
|
|
||||||
|
|
||||||
class LocalBinder(val service: AutoTunnelService) : Binder()
|
class LocalBinder(val service: AutoTunnelService) : Binder()
|
||||||
|
|
||||||
private val binder = LocalBinder(this)
|
private val binder = LocalBinder(this)
|
||||||
|
|
||||||
|
private var isServiceRunning = false
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
launchWatcherNotification()
|
launchWatcherNotification()
|
||||||
@@ -89,21 +80,46 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
launchWatcherNotification()
|
if (isServiceRunning) return
|
||||||
startAutoTunnelStateJob()
|
isServiceRunning = true
|
||||||
startLocationPermissionsNotificationJob()
|
kotlin
|
||||||
|
.runCatching {
|
||||||
|
launchWatcherNotification()
|
||||||
|
initWakeLock()
|
||||||
|
startAutoTunnelJob()
|
||||||
|
startAutoTunnelStateJob()
|
||||||
|
killSwitchJob = startKillSwitchJob()
|
||||||
|
}
|
||||||
|
.onFailure { Timber.e(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
isServiceRunning = false
|
||||||
|
wakeLock?.let { if (it.isHeld) it.release() }
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
serviceManager.handleAutoTunnelServiceDestroy()
|
serviceManager.handleAutoTunnelServiceDestroy()
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
restoreVpnKillSwitch()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun restoreVpnKillSwitch() {
|
||||||
|
with(autoTunnelStateFlow.value) {
|
||||||
|
if (
|
||||||
|
settings.isVpnKillSwitchEnabled &&
|
||||||
|
tunnelManager.getBackendState() != BackendState.KILL_SWITCH_ACTIVE
|
||||||
|
) {
|
||||||
|
killSwitchJob?.cancel()
|
||||||
|
val allowedIps =
|
||||||
|
if (settings.isLanOnKillSwitchEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS
|
||||||
|
else emptyList()
|
||||||
|
tunnelManager.setBackendState(BackendState.KILL_SWITCH_ACTIVE, allowedIps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun launchWatcherNotification(
|
private fun launchWatcherNotification(
|
||||||
description: String = getString(R.string.monitoring_state_changes)
|
description: String = getString(R.string.monitoring_state_changes)
|
||||||
) {
|
) {
|
||||||
@@ -118,7 +134,6 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
NotificationAction.AUTO_TUNNEL_OFF
|
NotificationAction.AUTO_TUNNEL_OFF
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
onGoing = true,
|
|
||||||
)
|
)
|
||||||
ServiceCompat.startForeground(
|
ServiceCompat.startForeground(
|
||||||
this,
|
this,
|
||||||
@@ -128,141 +143,80 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startAutoTunnelStateJob() =
|
private fun initWakeLock() {
|
||||||
lifecycleScope.launch(ioDispatcher) {
|
wakeLock =
|
||||||
val networkFlow =
|
(getSystemService(POWER_SERVICE) as PowerManager).run {
|
||||||
debouncedConnectivityStateFlow
|
val tag = this.javaClass.name
|
||||||
.flowOn(ioDispatcher)
|
newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "$tag::lock").apply {
|
||||||
.map(NetworkState::from)
|
try {
|
||||||
.map { StateChange.NetworkChange(it) }
|
Timber.i("Initiating wakelock with 10 min timeout")
|
||||||
.distinctUntilChanged()
|
acquire(Constants.BATTERY_SAVER_WATCHER_WAKE_LOCK_TIMEOUT)
|
||||||
|
} finally {
|
||||||
val settingsFlow =
|
release()
|
||||||
combineSettings().map { StateChange.SettingsChange(it.first, it.second) }
|
|
||||||
|
|
||||||
val tunnelsFlow =
|
|
||||||
tunnelManager.activeTunnels.map { StateChange.ActiveTunnelsChange(it) }
|
|
||||||
|
|
||||||
val monitoringFlow =
|
|
||||||
tunnelManager.activeTunnels
|
|
||||||
.map { map -> map.mapValues { (_, state) -> state.pingStates } }
|
|
||||||
.distinctUntilChanged()
|
|
||||||
.map { StateChange.MonitoringChange(it) }
|
|
||||||
|
|
||||||
var reevaluationJob: Job? = null
|
|
||||||
|
|
||||||
// get everything in sync before we use merge
|
|
||||||
combine(networkFlow, settingsFlow, tunnelsFlow, monitoringFlow) {
|
|
||||||
network,
|
|
||||||
settings,
|
|
||||||
tunnels,
|
|
||||||
monitoring ->
|
|
||||||
autoTunnelStateFlow.update {
|
|
||||||
it.copy(
|
|
||||||
activeTunnels = tunnels.activeTunnels,
|
|
||||||
networkState = network.networkState,
|
|
||||||
settings = settings.settings,
|
|
||||||
tunnels = settings.tunnels,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.first()
|
|
||||||
|
|
||||||
// use merge to limit the noise of a combine and also increase the scalability of auto
|
|
||||||
// tunnel handling new states
|
|
||||||
merge(networkFlow, settingsFlow, tunnelsFlow, monitoringFlow).collect { change ->
|
|
||||||
if (change !is StateChange.ActiveTunnelsChange) {
|
|
||||||
Timber.d("New state changed to ${change.javaClass.simpleName}")
|
|
||||||
}
|
|
||||||
|
|
||||||
when (change) {
|
|
||||||
is StateChange.NetworkChange -> {
|
|
||||||
reevaluationJob?.cancel()
|
|
||||||
val previousState = autoTunnelStateFlow.value
|
|
||||||
autoTunnelStateFlow.update { it.copy(networkState = change.networkState) }
|
|
||||||
// Android late mobile data state change, we can ignore handling this
|
|
||||||
if (
|
|
||||||
isAndroidLateCellularActiveChange(
|
|
||||||
previousState.networkState,
|
|
||||||
change.networkState,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Timber.d("Android late cellular active state change")
|
|
||||||
return@collect
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is StateChange.SettingsChange -> {
|
|
||||||
reevaluationJob?.cancel()
|
|
||||||
autoTunnelStateFlow.update {
|
|
||||||
it.copy(settings = change.settings, tunnels = change.tunnels)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is StateChange.ActiveTunnelsChange -> {
|
|
||||||
autoTunnelStateFlow.update { it.copy(activeTunnels = change.activeTunnels) }
|
|
||||||
return@collect
|
|
||||||
}
|
|
||||||
is StateChange.MonitoringChange -> {
|
|
||||||
change.pingStates.forEach { (config, pingState) ->
|
|
||||||
Timber.d("Ping state $pingState")
|
|
||||||
if (pingState?.all { it.value.isReachable } == true) {
|
|
||||||
Timber.d("Clearing bounce count on success")
|
|
||||||
bounceCounts.update { current ->
|
|
||||||
current.toMutableMap().apply { remove(config.id) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return@collect handleAutoTunnelEvent(
|
|
||||||
autoTunnelStateFlow.value.determineAutoTunnelEvent(
|
|
||||||
StateChange.MonitoringChange(change.pingStates)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleAutoTunnelEvent(autoTunnelStateFlow.value.determineAutoTunnelEvent(change))
|
|
||||||
|
|
||||||
reevaluationJob = launch {
|
|
||||||
delay(REEVALUATE_CHECK_DELAY)
|
|
||||||
val currentState = autoTunnelStateFlow.value
|
|
||||||
if (currentState != defaultState) {
|
|
||||||
Timber.d("Re-evaluating auto-tunnel state..")
|
|
||||||
handleAutoTunnelEvent(currentState.determineAutoTunnelEvent(change))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildNetworkState(networkStatus: NetworkStatus): NetworkState {
|
||||||
|
return with(autoTunnelStateFlow.value.networkState) {
|
||||||
|
val wifiName =
|
||||||
|
when (networkStatus) {
|
||||||
|
is NetworkStatus.Connected -> {
|
||||||
|
networkStatus.wifiSsid
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
copy(
|
||||||
|
isWifiConnected = networkStatus.wifiConnected,
|
||||||
|
isMobileDataConnected = networkStatus.cellularConnected,
|
||||||
|
isEthernetConnected = networkStatus.ethernetConnected,
|
||||||
|
wifiName = wifiName,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
|
private fun startAutoTunnelStateJob() =
|
||||||
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
|
combine(
|
||||||
|
combineSettings(),
|
||||||
|
appDataRepository
|
||||||
|
.get()
|
||||||
|
.settings
|
||||||
|
.flow
|
||||||
|
.distinctUntilChanged { old, new ->
|
||||||
|
old.isKernelEnabled == new.isKernelEnabled
|
||||||
|
} // Only emit when isKernelEnabled changes
|
||||||
|
.flatMapLatest {
|
||||||
|
networkMonitor.networkStatusFlow.flowOn(ioDispatcher).map {
|
||||||
|
buildNetworkState(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.distinctUntilChanged(),
|
||||||
|
) { double, networkState ->
|
||||||
|
AutoTunnelState(
|
||||||
|
tunnelManager.activeTunnels.value,
|
||||||
|
networkState,
|
||||||
|
double.first,
|
||||||
|
double.second,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.collect { state ->
|
||||||
|
autoTunnelStateFlow.update {
|
||||||
|
it.copy(
|
||||||
|
activeTunnels = state.activeTunnels,
|
||||||
|
networkState = state.networkState,
|
||||||
|
settings = state.settings,
|
||||||
|
tunnels = state.tunnels,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isAndroidLateCellularActiveChange(
|
private fun combineSettings(): Flow<Pair<AppSettings, Tunnels>> {
|
||||||
previous: NetworkState,
|
|
||||||
new: NetworkState,
|
|
||||||
): Boolean {
|
|
||||||
return (previous.isWifiConnected != new.isWifiConnected &&
|
|
||||||
previous.wifiName == new.wifiName &&
|
|
||||||
previous.isMobileDataConnected != new.isMobileDataConnected)
|
|
||||||
}
|
|
||||||
|
|
||||||
// all relevant settings to auto tunnel
|
|
||||||
private fun areAutoTunnelSettingsTheSame(old: GeneralSettings, new: GeneralSettings): Boolean {
|
|
||||||
return (old.isTunnelOnWifiEnabled == new.isTunnelOnWifiEnabled &&
|
|
||||||
old.isTunnelOnMobileDataEnabled == new.isTunnelOnMobileDataEnabled &&
|
|
||||||
old.isTunnelOnEthernetEnabled == new.isTunnelOnEthernetEnabled &&
|
|
||||||
old.trustedNetworkSSIDs == new.trustedNetworkSSIDs &&
|
|
||||||
old.isPingEnabled == new.isPingEnabled &&
|
|
||||||
old.debounceDelaySeconds == new.debounceDelaySeconds &&
|
|
||||||
old.wifiDetectionMethod == new.wifiDetectionMethod &&
|
|
||||||
old.isVpnKillSwitchEnabled == new.isVpnKillSwitchEnabled &&
|
|
||||||
old.isLanOnKillSwitchEnabled == new.isLanOnKillSwitchEnabled &&
|
|
||||||
old.isDisableKillSwitchOnTrustedEnabled == new.isDisableKillSwitchOnTrustedEnabled &&
|
|
||||||
old.isStopOnNoInternetEnabled == new.isStopOnNoInternetEnabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun combineSettings(): Flow<Pair<GeneralSettings, Tunnels>> {
|
|
||||||
return combine(
|
return combine(
|
||||||
appDataRepository
|
appDataRepository.get().settings.flow,
|
||||||
.get()
|
|
||||||
.settings
|
|
||||||
.flow
|
|
||||||
.distinctUntilChanged(::areAutoTunnelSettingsTheSame),
|
|
||||||
appDataRepository.get().tunnels.flow.map { tunnels ->
|
appDataRepository.get().tunnels.flow.map { tunnels ->
|
||||||
// isActive is ignored for equality checks so user can manually toggle off
|
// isActive is ignored for equality checks so user can manually toggle off
|
||||||
// tunnel with auto-tunnel
|
// tunnel with auto-tunnel
|
||||||
@@ -274,166 +228,70 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun areAutoTunnelPermissionsRequiredTheSame(
|
private fun startKillSwitchJob() =
|
||||||
old: AutoTunnelState,
|
|
||||||
new: AutoTunnelState,
|
|
||||||
): Boolean {
|
|
||||||
return (old.settings.wifiDetectionMethod == new.settings.wifiDetectionMethod &&
|
|
||||||
old.networkState.locationPermissionGranted ==
|
|
||||||
new.networkState.locationPermissionGranted &&
|
|
||||||
old.networkState.locationServicesEnabled == new.networkState.locationServicesEnabled &&
|
|
||||||
old.tunnels == new.tunnels &&
|
|
||||||
old.settings.trustedNetworkSSIDs == new.settings.trustedNetworkSSIDs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// watch for changes to location permission and notify user it will impact auto-tunneling
|
|
||||||
// TODO or a recheck button for location permission so we dont have to poll it
|
|
||||||
private fun startLocationPermissionsNotificationJob(): Job =
|
|
||||||
lifecycleScope.launch(ioDispatcher) {
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
var locationServicesShown = false
|
autoTunnelStateFlow.collect {
|
||||||
var locationPermissionsShown = false
|
if (it == defaultState) return@collect
|
||||||
|
when (val event = it.asKillSwitchEvent()) {
|
||||||
data class NetworkPermissionState(
|
KillSwitchEvent.DoNothing -> Unit
|
||||||
val detectionMethod: AndroidNetworkMonitor.WifiDetectionMethod,
|
is KillSwitchEvent.Start -> {
|
||||||
val locationServicesEnabled: Boolean,
|
Timber.d("Starting kill switch")
|
||||||
val locationPermissionsEnabled: Boolean,
|
tunnelManager.setBackendState(
|
||||||
val ssidReadRequired: Boolean,
|
BackendState.KILL_SWITCH_ACTIVE,
|
||||||
)
|
event.allowedIps,
|
||||||
|
)
|
||||||
autoTunnelStateFlow
|
}
|
||||||
.distinctUntilChanged(::areAutoTunnelPermissionsRequiredTheSame)
|
KillSwitchEvent.Stop -> {
|
||||||
.map {
|
Timber.d("Stopping kill switch")
|
||||||
NetworkPermissionState(
|
tunnelManager.setBackendState(BackendState.SERVICE_ACTIVE, emptySet())
|
||||||
it.settings.wifiDetectionMethod.to(),
|
|
||||||
it.networkState.locationServicesEnabled == true,
|
|
||||||
it.networkState.locationPermissionGranted == true,
|
|
||||||
(it.tunnels.any { tunnel -> tunnel.tunnelNetworks.isNotEmpty() } ||
|
|
||||||
it.settings.trustedNetworkSSIDs.isNotEmpty()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.collect { state ->
|
|
||||||
when (state.detectionMethod) {
|
|
||||||
AndroidNetworkMonitor.WifiDetectionMethod.DEFAULT,
|
|
||||||
AndroidNetworkMonitor.WifiDetectionMethod.LEGACY -> {
|
|
||||||
if (
|
|
||||||
!state.locationPermissionsEnabled &&
|
|
||||||
!locationPermissionsShown &&
|
|
||||||
state.ssidReadRequired
|
|
||||||
) {
|
|
||||||
locationPermissionsShown = true
|
|
||||||
val notification =
|
|
||||||
notificationManager.createNotification(
|
|
||||||
WireGuardNotification.NotificationChannels.AUTO_TUNNEL,
|
|
||||||
title = getString(R.string.warning),
|
|
||||||
description =
|
|
||||||
getString(R.string.location_permissions_missing),
|
|
||||||
)
|
|
||||||
notificationManager.show(
|
|
||||||
NotificationManager.AUTO_TUNNEL_LOCATION_PERMISSION_ID,
|
|
||||||
notification,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
!state.locationServicesEnabled &&
|
|
||||||
!locationServicesShown &&
|
|
||||||
state.ssidReadRequired
|
|
||||||
) {
|
|
||||||
locationServicesShown = true
|
|
||||||
val notification =
|
|
||||||
notificationManager.createNotification(
|
|
||||||
WireGuardNotification.NotificationChannels.AUTO_TUNNEL,
|
|
||||||
title = getString(R.string.warning),
|
|
||||||
description =
|
|
||||||
getString(R.string.location_services_not_detected),
|
|
||||||
)
|
|
||||||
notificationManager.show(
|
|
||||||
NotificationManager.AUTO_TUNNEL_LOCATION_SERVICES_ID,
|
|
||||||
notification,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (state.locationServicesEnabled || !state.ssidReadRequired) {
|
|
||||||
notificationManager.remove(
|
|
||||||
NotificationManager.AUTO_TUNNEL_LOCATION_SERVICES_ID
|
|
||||||
)
|
|
||||||
locationServicesShown = false
|
|
||||||
}
|
|
||||||
if (state.locationPermissionsEnabled || !state.ssidReadRequired) {
|
|
||||||
notificationManager.remove(
|
|
||||||
NotificationManager.AUTO_TUNNEL_LOCATION_PERMISSION_ID
|
|
||||||
)
|
|
||||||
locationPermissionsShown = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> Unit
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun handleAutoTunnelEvent(autoTunnelEvent: AutoTunnelEvent) {
|
|
||||||
autoTunMutex.withLock {
|
|
||||||
when (
|
|
||||||
val event =
|
|
||||||
autoTunnelEvent.also {
|
|
||||||
Timber.i("Auto tunnel event: ${it.javaClass.simpleName}")
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
is AutoTunnelEvent.Start ->
|
|
||||||
(event.tunnelConf ?: appDataRepository.get().getPrimaryOrFirstTunnel())?.let {
|
|
||||||
tunnelManager.startTunnel(it)
|
|
||||||
}
|
|
||||||
is AutoTunnelEvent.Stop -> tunnelManager.stopTunnel()
|
|
||||||
AutoTunnelEvent.DoNothing -> Timber.i("Auto-tunneling: nothing to do")
|
|
||||||
is AutoTunnelEvent.Bounce ->
|
|
||||||
handleBounceWithBackoff(event.configsPeerKeyResolvedMap)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun handleBounceWithBackoff(
|
@OptIn(FlowPreview::class)
|
||||||
configsPeerKeyResolvedMap: List<Pair<TunnelConf, Map<String, String?>>>
|
private fun startAutoTunnelJob() =
|
||||||
) { // Simplified param: no failureCount
|
lifecycleScope.launch(ioDispatcher) {
|
||||||
val settings = appDataRepository.get().settings.get()
|
Timber.i("Starting auto-tunnel network event watcher")
|
||||||
val pingIntervalMillis = settings.tunnelPingIntervalSeconds.toMillis()
|
val settings = appDataRepository.get().settings.get()
|
||||||
configsPeerKeyResolvedMap.forEach { (config, peerMap) ->
|
|
||||||
val bounceCount = bounceCounts.value.getOrDefault(config.id, 0)
|
var reevaluationJob: Job? = null
|
||||||
val exponent = bounceCount.toDouble()
|
|
||||||
val backoffDelay =
|
autoTunnelStateFlow.debounce(settings.debounceDelayMillis()).collect { watcherState ->
|
||||||
(pingIntervalMillis * 2.0.pow(exponent)).toLong().coerceAtMost(MAX_BACKOFF_MS)
|
if (watcherState == defaultState) return@collect
|
||||||
val currentTime = System.currentTimeMillis()
|
reevaluationJob?.cancel()
|
||||||
val lastTime = lastBounceTimes.getOrDefault(config.id, 0L)
|
handleAutoTunnelEvent(watcherState)
|
||||||
if (currentTime - lastTime >= backoffDelay) {
|
|
||||||
Timber.d(
|
// schedule one-time re-evaluation
|
||||||
"Bouncing tunnel ${config.name} after detecting failure, with bounce count $bounceCount and calculated backoff delay $backoffDelay ms"
|
reevaluationJob = launch {
|
||||||
)
|
delay(REEVALUATE_CHECK_DELAY)
|
||||||
tunnelManager.bounceTunnel(config, Ping(peerMap))
|
if (watcherState != defaultState) {
|
||||||
lastBounceTimes[config.id] = currentTime
|
Timber.d("Re-evaluating auto-tunnel state..")
|
||||||
bounceCounts.update { current ->
|
handleAutoTunnelEvent(watcherState)
|
||||||
current.toMutableMap().apply { this[config.id] = (this[config.id] ?: 0) + 1 }
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Timber.d(
|
|
||||||
"Backoff in progress for tunnel ${config.name}, skipping bounce (required delay: $backoffDelay ms)"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
|
private suspend fun handleAutoTunnelEvent(watcherState: AutoTunnelState) {
|
||||||
private val debouncedConnectivityStateFlow: Flow<ConnectivityState> by lazy {
|
Timber.i("Auto-tunnel settings: ${watcherState.settings.toAutoTunnelStateString()}")
|
||||||
appDataRepository
|
Timber.i("Auto-tunnel network state: ${watcherState.networkState}")
|
||||||
.get()
|
when (
|
||||||
.settings
|
val event =
|
||||||
.flow
|
watcherState.asAutoTunnelEvent().also {
|
||||||
.map { it.debounceDelaySeconds.toMillis() }
|
Timber.i("Auto-tunnel event: ${it.javaClass.simpleName}")
|
||||||
.distinctUntilChanged()
|
}
|
||||||
.flatMapLatest { debounceMillis ->
|
) {
|
||||||
networkMonitor.connectivityStateFlow.debounce(debounceMillis)
|
is AutoTunnelEvent.Start ->
|
||||||
}
|
(event.tunnelConf ?: appDataRepository.get().getPrimaryOrFirstTunnel())?.let {
|
||||||
|
tunnelManager.startTunnel(it)
|
||||||
|
}
|
||||||
|
is AutoTunnelEvent.Stop -> tunnelManager.stopTunnel()
|
||||||
|
AutoTunnelEvent.DoNothing -> Timber.i("Auto-tunneling: nothing to do")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// try to keep this window short as it will interrupt manual overrides
|
const val REEVALUATE_CHECK_DELAY = 5_000L
|
||||||
const val REEVALUATE_CHECK_DELAY = 2_000L
|
|
||||||
const val MAX_BACKOFF_MS = 300_000L // 5 minutes
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.NetworkState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
|
||||||
import org.amnezia.awg.crypto.Key
|
|
||||||
|
|
||||||
sealed class StateChange {
|
|
||||||
data class NetworkChange(val networkState: NetworkState) : StateChange()
|
|
||||||
|
|
||||||
data class SettingsChange(val settings: GeneralSettings, val tunnels: Tunnels) : StateChange()
|
|
||||||
|
|
||||||
data class ActiveTunnelsChange(val activeTunnels: Map<TunnelConf, TunnelState>) : StateChange()
|
|
||||||
|
|
||||||
data class MonitoringChange(val pingStates: Map<TunnelConf, Map<Key, PingState>?>) :
|
|
||||||
StateChange()
|
|
||||||
}
|
|
||||||
@@ -2,42 +2,37 @@ package com.zaneschepke.wireguardautotunnel.core.tunnel
|
|||||||
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
||||||
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.BackendMessage
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.ConfigProxy
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asTunnelState
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import kotlin.coroutines.cancellation.CancellationException
|
import kotlin.concurrent.thread
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import org.amnezia.awg.crypto.Key
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
abstract class BaseTunnel(
|
abstract class BaseTunnel(
|
||||||
private val applicationScope: CoroutineScope,
|
@ApplicationScope private val applicationScope: CoroutineScope,
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
) : TunnelProvider {
|
) : TunnelProvider {
|
||||||
|
|
||||||
private val _errorEvents = MutableSharedFlow<Pair<TunnelConf, BackendCoreException>>()
|
private val _errorEvents =
|
||||||
|
MutableSharedFlow<Pair<TunnelConf, BackendError>>(replay = 0, extraBufferCapacity = 1)
|
||||||
override val errorEvents = _errorEvents.asSharedFlow()
|
override val errorEvents = _errorEvents.asSharedFlow()
|
||||||
|
|
||||||
private val _messageEvents = MutableSharedFlow<Pair<TunnelConf, BackendMessage>>()
|
|
||||||
override val messageEvents = _messageEvents.asSharedFlow()
|
|
||||||
|
|
||||||
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
private val activeTuns = MutableStateFlow<Map<TunnelConf, TunnelState>>(emptyMap())
|
||||||
private val tunJobs = ConcurrentHashMap<Int, Job>()
|
private val tunThreads = ConcurrentHashMap<Int, Thread>()
|
||||||
override val activeTunnels = activeTuns.asStateFlow()
|
override val activeTunnels = activeTuns.asStateFlow()
|
||||||
|
|
||||||
private val tunMutex = Mutex()
|
private val tunMutex = Mutex()
|
||||||
@@ -54,43 +49,32 @@ abstract class BaseTunnel(
|
|||||||
return serviceManager.hasVpnPermission()
|
return serviceManager.hasVpnPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateTunnelStatus(
|
protected suspend fun updateTunnelStatus(
|
||||||
tunnelConf: TunnelConf,
|
tunnelConf: TunnelConf,
|
||||||
status: TunnelStatus?,
|
status: TunnelStatus? = null,
|
||||||
stats: TunnelStatistics?,
|
stats: TunnelStatistics? = null,
|
||||||
pingStates: Map<Key, PingState>?,
|
|
||||||
handshakeSuccessLogs: Boolean?,
|
|
||||||
) {
|
) {
|
||||||
tunStatusMutex.withLock {
|
tunStatusMutex.withLock {
|
||||||
activeTuns.update { currentTuns ->
|
activeTuns.update { currentTuns ->
|
||||||
val originalConf = currentTuns.getKeyById(tunnelConf.id) ?: tunnelConf
|
val originalConf = currentTuns.getKeyById(tunnelConf.id) ?: tunnelConf
|
||||||
val existingState = currentTuns.getValueById(tunnelConf.id) ?: TunnelState()
|
val existingState = currentTuns.getValueById(tunnelConf.id) ?: TunnelState()
|
||||||
val newStatus = status ?: existingState.status
|
val newState = status ?: existingState.status
|
||||||
if (newStatus == TunnelStatus.Down) {
|
if (newState == TunnelStatus.Down) {
|
||||||
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
Timber.d("Removing tunnel ${tunnelConf.id} from activeTunnels as state is DOWN")
|
||||||
cleanUpTunJob(tunnelConf)
|
cleanUpTunThread(tunnelConf)
|
||||||
currentTuns - originalConf
|
currentTuns - originalConf
|
||||||
} else if (
|
} else if (existingState.status == newState && stats == null) {
|
||||||
existingState.status == newStatus &&
|
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
||||||
stats == null &&
|
|
||||||
pingStates == null &&
|
|
||||||
handshakeSuccessLogs == null
|
|
||||||
) {
|
|
||||||
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newStatus")
|
|
||||||
currentTuns
|
currentTuns
|
||||||
} else {
|
} else {
|
||||||
val updated =
|
val updated =
|
||||||
existingState.copy(
|
existingState.copy(
|
||||||
status = newStatus,
|
status = newState,
|
||||||
statistics = stats ?: existingState.statistics,
|
statistics = stats ?: existingState.statistics,
|
||||||
pingStates = pingStates ?: existingState.pingStates,
|
|
||||||
handshakeSuccessLogs =
|
|
||||||
handshakeSuccessLogs ?: existingState.handshakeSuccessLogs,
|
|
||||||
)
|
)
|
||||||
currentTuns + (originalConf to updated)
|
currentTuns + (originalConf to updated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleServiceStateOnChange()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,100 +104,44 @@ abstract class BaseTunnel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
||||||
|
val stats = getStatistics(tunnel)
|
||||||
|
updateTunnelStatus(tunnel, null, stats)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun startTunnel(tunnelConf: TunnelConf) {
|
override suspend fun startTunnel(tunnelConf: TunnelConf) {
|
||||||
if (activeTuns.exists(tunnelConf.id) || tunJobs.containsKey(tunnelConf.id))
|
if (activeTuns.exists(tunnelConf.id) || tunThreads.containsKey(tunnelConf.id)) return
|
||||||
return Timber.w("Tunnel is already running ${tunnelConf.name}")
|
|
||||||
// For userspace, we need to make sure all previous tunnels are down
|
|
||||||
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
if (this@BaseTunnel is UserspaceTunnel) stopActiveTunnels()
|
||||||
tunMutex.withLock {
|
tunMutex.withLock {
|
||||||
val job =
|
tunThreads[tunnelConf.id] = thread {
|
||||||
applicationScope.launch {
|
try {
|
||||||
try {
|
runBlocking {
|
||||||
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
Timber.d("Starting tunnel ${tunnelConf.id}...")
|
||||||
startTunnelInner(tunnelConf)
|
startTunnelInner(tunnelConf)
|
||||||
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
Timber.d("Started complete for tunnel ${tunnelConf.name}...")
|
||||||
// catch cancellation that could occur before and during startTunnelInner
|
|
||||||
// and trigger at that suspend point
|
|
||||||
} catch (e: CancellationException) {
|
|
||||||
Timber.w(
|
|
||||||
"Tunnel start has been cancelled as ${tunnelConf.name} failed to start"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
} catch (e: InterruptedException) {
|
||||||
|
Timber.w(
|
||||||
|
"Tunnel start has been interrupted as ${tunnelConf.name} failed to start"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
tunJobs[tunnelConf.id] = job
|
|
||||||
job.invokeOnCompletion {
|
|
||||||
tunJobs.remove(tunnelConf.id)
|
|
||||||
Timber.d("Start job completed for tunnel ${tunnelConf.id}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun startTunnelInner(tunnelConf: TunnelConf) {
|
private suspend fun startTunnelInner(tunnelConf: TunnelConf) {
|
||||||
configureTunnelCallbacks(tunnelConf)
|
configureTunnelCallbacks(tunnelConf)
|
||||||
Timber.d("Starting backend for tunnel ${tunnelConf.id}...")
|
Timber.d("Starting backend for tunnel ${tunnelConf.id}...")
|
||||||
|
try {
|
||||||
var currentConf = tunnelConf
|
startBackend(tunnelConf)
|
||||||
var restoreAttempted = false
|
updateTunnelStatus(tunnelConf, TunnelStatus.Up)
|
||||||
var originalError: BackendCoreException? = null
|
Timber.d("Started for tun ${tunnelConf.id}...")
|
||||||
|
saveTunnelActiveState(tunnelConf, true)
|
||||||
while (true) {
|
serviceManager.startTunnelForegroundService()
|
||||||
try {
|
} catch (e: BackendError) {
|
||||||
startBackend(currentConf)
|
Timber.e(e, "Failed to start backend for ${tunnelConf.name}")
|
||||||
updateTunnelStatus(currentConf, TunnelStatus.Up)
|
_errorEvents.emit(tunnelConf to e)
|
||||||
Timber.d("Started for tun ${currentConf.id}...")
|
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||||
saveTunnelActiveState(currentConf, true)
|
|
||||||
serviceManager.startTunnelForegroundService()
|
|
||||||
if (restoreAttempted)
|
|
||||||
_messageEvents.emit(tunnelConf to BackendMessage.BounceRecovery)
|
|
||||||
if (bouncingTunnelIds[currentConf.id] is TunnelStatus.StopReason.Ping) {
|
|
||||||
_messageEvents.emit(tunnelConf to BackendMessage.BounceSuccess)
|
|
||||||
}
|
|
||||||
return // Success, return
|
|
||||||
} catch (e: BackendCoreException) {
|
|
||||||
originalError = originalError ?: e
|
|
||||||
val bounceReason = bouncingTunnelIds[currentConf.id]
|
|
||||||
if (!restoreAttempted && bounceReason is TunnelStatus.StopReason.Ping) {
|
|
||||||
Timber.i(
|
|
||||||
"Attempting to recover bounce failure with previously resolved endpoints for ${currentConf.name}"
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
val previouslyResolved = bounceReason.previouslyResolvedEndpoints
|
|
||||||
val configProxy = ConfigProxy.from(currentConf.toAmConfig())
|
|
||||||
val updatedConfigProxy =
|
|
||||||
configProxy.copy(
|
|
||||||
peers =
|
|
||||||
configProxy.peers.map {
|
|
||||||
it.copy(
|
|
||||||
endpoint =
|
|
||||||
previouslyResolved[it.publicKey] ?: it.endpoint
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
val (wg, amnezia) = updatedConfigProxy.buildConfigs()
|
|
||||||
currentConf =
|
|
||||||
currentConf.copyWithCallback(
|
|
||||||
amQuick = amnezia.toAwgQuickString(true, false),
|
|
||||||
wgQuick = wg.toWgQuickString(true),
|
|
||||||
)
|
|
||||||
bouncingTunnelIds.remove(currentConf.id)
|
|
||||||
restoreAttempted = true
|
|
||||||
continue // Retry
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(
|
|
||||||
e,
|
|
||||||
"Failed to update config with resolved endpoints for ${currentConf.name}",
|
|
||||||
)
|
|
||||||
// Fall through to failure (will emit BounceFailed since
|
|
||||||
// retryAttempted=true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Timber.e(e, "Failed to start backend for ${currentConf.name}")
|
|
||||||
val emitError =
|
|
||||||
if (restoreAttempted) BackendCoreException.BounceFailed(originalError) else e
|
|
||||||
_errorEvents.emit(currentConf to emitError)
|
|
||||||
updateTunnelStatus(currentConf, TunnelStatus.Down)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +166,7 @@ abstract class BaseTunnel(
|
|||||||
stopBackend(tunnel)
|
stopBackend(tunnel)
|
||||||
saveTunnelActiveState(tunnelConf, false)
|
saveTunnelActiveState(tunnelConf, false)
|
||||||
removeActiveTunnel(tunnel)
|
removeActiveTunnel(tunnel)
|
||||||
} catch (e: BackendCoreException) {
|
} catch (e: BackendError) {
|
||||||
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
||||||
_errorEvents.emit(tunnelConf to e)
|
_errorEvents.emit(tunnelConf to e)
|
||||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||||
@@ -246,23 +174,30 @@ abstract class BaseTunnel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleServiceStateOnChange() {
|
private fun handleServiceStateOnChange() {
|
||||||
if (activeTuns.value.isEmpty()) serviceManager.stopTunnelForegroundService()
|
if (activeTuns.value.isEmpty() && bouncingTunnelIds.isEmpty())
|
||||||
|
serviceManager.stopTunnelForegroundService()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleStuckStartingTunnelShutdown(tunnel: TunnelConf) {
|
private suspend fun handleStuckStartingTunnelShutdown(tunnel: TunnelConf) {
|
||||||
Timber.d("Stuck in starting state so cancelling job for tunnel ${tunnel.name}")
|
Timber.d("Stuck in starting state so shutting down tunnel thread for tunnel ${tunnel.name}")
|
||||||
try {
|
try {
|
||||||
tunJobs[tunnel.id]?.cancel() ?: Timber.d("No job found for ${tunnel.name}")
|
tunThreads[tunnel.id]?.let {
|
||||||
|
if (it.state != Thread.State.TERMINATED) {
|
||||||
|
it.interrupt()
|
||||||
|
} else {
|
||||||
|
Timber.d("Thread already terminated")
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Failed to cancel job for ${tunnel.name}")
|
Timber.e(e, "Failed to stop tunnel thread for ${tunnel.name}")
|
||||||
} finally {
|
} finally {
|
||||||
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
updateTunnelStatus(tunnel, TunnelStatus.Down)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanUpTunJob(tunnel: TunnelConf) {
|
private fun cleanUpTunThread(tunnel: TunnelConf) {
|
||||||
Timber.d("Removing job for ${tunnel.name}")
|
Timber.d("Removing thread for ${tunnel.name}")
|
||||||
tunJobs -= tunnel.id
|
tunThreads -= tunnel.id
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeActiveTunnel(tunnelConf: TunnelConf) {
|
private fun removeActiveTunnel(tunnelConf: TunnelConf) {
|
||||||
@@ -275,10 +210,16 @@ abstract class BaseTunnel(
|
|||||||
"Bounce tunnel ${tunnelConf.name} for reason: $reason, current bouncing: ${bouncingTunnelIds.size}"
|
"Bounce tunnel ${tunnelConf.name} for reason: $reason, current bouncing: ${bouncingTunnelIds.size}"
|
||||||
)
|
)
|
||||||
bouncingTunnelIds[tunnelConf.id] = reason
|
bouncingTunnelIds[tunnelConf.id] = reason
|
||||||
runCatching {
|
try {
|
||||||
stopTunnel(tunnelConf, reason)
|
stopTunnel(tunnelConf, reason)
|
||||||
delay(BOUNCE_DELAY)
|
delay(BOUNCE_DELAY)
|
||||||
startTunnel(tunnelConf)
|
startTunnel(tunnelConf)
|
||||||
|
} finally {
|
||||||
|
bouncingTunnelIds.remove(tunnelConf.id)
|
||||||
|
handleServiceStateOnChange()
|
||||||
|
Timber.d(
|
||||||
|
"Cleared bounce state for ${tunnelConf.name}, remaining: ${bouncingTunnelIds.size}"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,13 @@ import com.wireguard.android.backend.BackendException
|
|||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
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.model.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.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.toBackendCoreException
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@@ -24,7 +22,7 @@ constructor(
|
|||||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
@ApplicationScope private val applicationScope: CoroutineScope,
|
||||||
serviceManager: ServiceManager,
|
serviceManager: ServiceManager,
|
||||||
appDataRepository: AppDataRepository,
|
appDataRepository: AppDataRepository,
|
||||||
@Kernel private val backend: Backend,
|
private val backend: Backend,
|
||||||
) : BaseTunnel(applicationScope, appDataRepository, serviceManager) {
|
) : BaseTunnel(applicationScope, appDataRepository, serviceManager) {
|
||||||
|
|
||||||
override fun getStatistics(tunnelConf: TunnelConf): TunnelStatistics? {
|
override fun getStatistics(tunnelConf: TunnelConf): TunnelStatistics? {
|
||||||
@@ -37,17 +35,11 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun startBackend(tunnel: TunnelConf) {
|
override suspend fun startBackend(tunnel: TunnelConf) {
|
||||||
// name too long for kernel mode
|
|
||||||
if (!tunnel.isNameKernelCompatible) throw BackendCoreException.TunnelNameTooLong
|
|
||||||
try {
|
try {
|
||||||
updateTunnelStatus(tunnel, TunnelStatus.Starting)
|
updateTunnelStatus(tunnel, TunnelStatus.Starting)
|
||||||
backend.setState(tunnel, Tunnel.State.UP, tunnel.toWgConfig())
|
backend.setState(tunnel, Tunnel.State.UP, tunnel.toWgConfig())
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
throw e.toBackendError()
|
||||||
throw e.toBackendCoreException()
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
|
||||||
throw BackendCoreException.Config
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,16 +48,16 @@ constructor(
|
|||||||
try {
|
try {
|
||||||
backend.setState(tunnel, Tunnel.State.DOWN, tunnel.toWgConfig())
|
backend.setState(tunnel, Tunnel.State.DOWN, tunnel.toWgConfig())
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
throw e.toBackendCoreException()
|
throw e.toBackendError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setBackendMode(backendMode: BackendMode) {
|
override fun setBackendState(backendState: BackendState, allowedIps: Collection<String>) {
|
||||||
Timber.w("Not yet implemented for kernel")
|
Timber.w("Not yet implemented for kernel")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBackendMode(): BackendMode {
|
override fun getBackendState(): BackendState {
|
||||||
return BackendMode.Inactive
|
return BackendState.INACTIVE
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> {
|
override suspend fun runningTunnelNames(): Set<String> {
|
||||||
|
|||||||
+57
-130
@@ -1,149 +1,71 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.di.*
|
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
import com.zaneschepke.wireguardautotunnel.di.Userspace
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.concurrent.atomics.AtomicBoolean
|
|
||||||
import kotlin.concurrent.atomics.AtomicReference
|
|
||||||
import kotlin.concurrent.atomics.ExperimentalAtomicApi
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.stateIn
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.plus
|
import kotlinx.coroutines.plus
|
||||||
import org.amnezia.awg.crypto.Key
|
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
|
||||||
class TunnelManager
|
class TunnelManager
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
@Kernel private val kernelTunnel: TunnelProvider,
|
@Kernel private val kernelTunnel: TunnelProvider,
|
||||||
@Userspace private val userspaceTunnel: TunnelProvider,
|
@Userspace private val userspaceTunnel: TunnelProvider,
|
||||||
@ProxyUserspace private val proxyUserspaceTunnel: TunnelProvider,
|
|
||||||
private val serviceManager: ServiceManager,
|
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
@ApplicationScope private val applicationScope: CoroutineScope,
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : TunnelProvider {
|
) : TunnelProvider {
|
||||||
|
|
||||||
@OptIn(ExperimentalAtomicApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
private val tunnelProviderFlow: StateFlow<TunnelProvider> = run {
|
private val tunnelProviderFlow =
|
||||||
val currentBackend = AtomicReference(userspaceTunnel)
|
|
||||||
val currentSettings = AtomicReference(GeneralSettings())
|
|
||||||
val initialEmit = AtomicBoolean(true)
|
|
||||||
|
|
||||||
appDataRepository.settings.flow
|
appDataRepository.settings.flow
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
// ignore default state
|
.flatMapLatest { settings ->
|
||||||
.filterNot { it == GeneralSettings() }
|
MutableStateFlow(if (settings.isKernelEnabled) kernelTunnel else userspaceTunnel)
|
||||||
.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 oldBackend = currentBackend.exchange(newBackend)
|
|
||||||
val oldSettings = currentSettings.exchange(settings)
|
|
||||||
|
|
||||||
if ((oldSettings.appMode != settings.appMode) && !isInitialEmit) {
|
|
||||||
oldBackend.stopTunnel()
|
|
||||||
if (oldSettings.appMode == AppMode.LOCK_DOWN)
|
|
||||||
proxyUserspaceTunnel.setBackendMode(BackendMode.Inactive)
|
|
||||||
}
|
|
||||||
if (settings.appMode == AppMode.LOCK_DOWN) {
|
|
||||||
// kill switch will always catch all ipv6, just add ipv4 networks for allowsIps
|
|
||||||
val allowedIps =
|
|
||||||
if (settings.isLanOnKillSwitchEnabled) TunnelConf.IPV4_PUBLIC_NETWORKS
|
|
||||||
else emptySet()
|
|
||||||
try {
|
|
||||||
// TODO handle situation where they don't have vpn permission, request it
|
|
||||||
if (hasVpnPermission()) {
|
|
||||||
proxyUserspaceTunnel.setBackendMode(BackendMode.KillSwitch(allowedIps))
|
|
||||||
}
|
|
||||||
} catch (e: BackendCoreException) {
|
|
||||||
// TODO expose this error to user
|
|
||||||
Timber.e(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// restore state if configured
|
|
||||||
if (isInitialEmit && settings.isRestoreOnBootEnabled) {
|
|
||||||
Timber.d("Restoring previous state")
|
|
||||||
if (
|
|
||||||
settings.isAutoTunnelEnabled &&
|
|
||||||
serviceManager.autoTunnelService.value == null
|
|
||||||
) {
|
|
||||||
serviceManager.startAutoTunnel()
|
|
||||||
} else {
|
|
||||||
val previouslyActiveTuns = appDataRepository.tunnels.getActive()
|
|
||||||
val tunsToStart =
|
|
||||||
previouslyActiveTuns.filterNot { tun ->
|
|
||||||
activeTunnels.value.any { tun.id == it.key.id }
|
|
||||||
}
|
|
||||||
tunsToStart.forEach { startTunnel(it) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.map { (_, backend) -> backend }
|
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope = applicationScope.plus(ioDispatcher),
|
scope = applicationScope.plus(ioDispatcher),
|
||||||
started = SharingStarted.Eagerly,
|
started = SharingStarted.Eagerly,
|
||||||
initialValue = userspaceTunnel,
|
initialValue = userspaceTunnel,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
override val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>> =
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
tunnelProviderFlow
|
override val activeTunnels =
|
||||||
.flatMapLatest { it.activeTunnels }
|
appDataRepository.settings.flow
|
||||||
|
.filterNotNull()
|
||||||
|
.flatMapLatest { settings ->
|
||||||
|
if (settings.isKernelEnabled) {
|
||||||
|
kernelTunnel.activeTunnels
|
||||||
|
} else {
|
||||||
|
userspaceTunnel.activeTunnels
|
||||||
|
}
|
||||||
|
}
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope = applicationScope.plus(ioDispatcher),
|
scope = applicationScope.plus(ioDispatcher),
|
||||||
started = SharingStarted.Eagerly,
|
started = SharingStarted.Eagerly,
|
||||||
initialValue = emptyMap(),
|
initialValue = emptyMap(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||||
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendCoreException>> =
|
get() = tunnelProviderFlow.value.errorEvents
|
||||||
tunnelProviderFlow
|
|
||||||
.flatMapLatest { it.errorEvents }
|
|
||||||
.shareIn(
|
|
||||||
scope = applicationScope.plus(ioDispatcher),
|
|
||||||
started = SharingStarted.Eagerly,
|
|
||||||
replay = 0,
|
|
||||||
)
|
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
|
||||||
override val messageEvents: SharedFlow<Pair<TunnelConf, BackendMessage>> =
|
|
||||||
tunnelProviderFlow
|
|
||||||
.flatMapLatest { it.messageEvents }
|
|
||||||
.filterNotNull()
|
|
||||||
.shareIn(
|
|
||||||
scope = applicationScope.plus(ioDispatcher),
|
|
||||||
started = SharingStarted.Eagerly,
|
|
||||||
replay = 0,
|
|
||||||
)
|
|
||||||
|
|
||||||
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
override val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason> =
|
||||||
tunnelProviderFlow.value.bouncingTunnelIds
|
tunnelProviderFlow.value.bouncingTunnelIds
|
||||||
@@ -152,8 +74,8 @@ constructor(
|
|||||||
return userspaceTunnel.hasVpnPermission()
|
return userspaceTunnel.hasVpnPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getStatistics(tunnelConf: TunnelConf): TunnelStatistics? {
|
override suspend fun updateTunnelStatistics(tunnel: TunnelConf) {
|
||||||
return tunnelProviderFlow.value.getStatistics(tunnelConf)
|
tunnelProviderFlow.value.updateTunnelStatistics(tunnel)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun startTunnel(tunnelConf: TunnelConf) {
|
override suspend fun startTunnel(tunnelConf: TunnelConf) {
|
||||||
@@ -168,31 +90,36 @@ constructor(
|
|||||||
tunnelProviderFlow.value.bounceTunnel(tunnelConf, reason)
|
tunnelProviderFlow.value.bounceTunnel(tunnelConf, reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setBackendMode(backendMode: BackendMode) {
|
override fun setBackendState(backendState: BackendState, allowedIps: Collection<String>) {
|
||||||
tunnelProviderFlow.value.setBackendMode(backendMode)
|
tunnelProviderFlow.value.setBackendState(backendState, allowedIps)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBackendMode(): BackendMode {
|
override fun getBackendState(): BackendState {
|
||||||
return tunnelProviderFlow.value.getBackendMode()
|
return tunnelProviderFlow.value.getBackendState()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> {
|
override suspend fun runningTunnelNames(): Set<String> {
|
||||||
return tunnelProviderFlow.value.runningTunnelNames()
|
return tunnelProviderFlow.value.runningTunnelNames()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateTunnelStatus(
|
override fun getStatistics(tunnelConf: TunnelConf): TunnelStatistics? {
|
||||||
tunnelConf: TunnelConf,
|
return tunnelProviderFlow.value.getStatistics(tunnelConf)
|
||||||
status: TunnelStatus?,
|
|
||||||
stats: TunnelStatistics?,
|
|
||||||
pingStates: Map<Key, PingState>?,
|
|
||||||
handshakeSuccessLogs: Boolean?,
|
|
||||||
) {
|
|
||||||
tunnelProviderFlow.value.updateTunnelStatus(
|
|
||||||
tunnelConf,
|
|
||||||
status,
|
|
||||||
stats,
|
|
||||||
pingStates,
|
|
||||||
handshakeSuccessLogs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun restorePreviousState() =
|
||||||
|
applicationScope.launch(ioDispatcher) {
|
||||||
|
val settings = appDataRepository.settings.get()
|
||||||
|
if (settings.isRestoreOnBootEnabled) {
|
||||||
|
val previouslyActiveTuns = appDataRepository.tunnels.getActive()
|
||||||
|
val tunsToStart =
|
||||||
|
previouslyActiveTuns.filterNot { tun ->
|
||||||
|
activeTunnels.value.any { tun.id == it.key.id }
|
||||||
|
}
|
||||||
|
if (settings.isKernelEnabled) {
|
||||||
|
return@launch tunsToStart.forEach { startTunnel(it) }
|
||||||
|
} else {
|
||||||
|
tunsToStart.firstOrNull()?.let { startTunnel(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,269 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
|
||||||
|
|
||||||
import com.zaneschepke.logcatter.LogReader
|
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.FailureReason
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toMillis
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
|
||||||
import dagger.hilt.android.scopes.ServiceScoped
|
|
||||||
import io.ktor.util.collections.*
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import kotlinx.coroutines.flow.*
|
|
||||||
import org.amnezia.awg.crypto.Key
|
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
@ServiceScoped
|
|
||||||
class TunnelMonitor
|
|
||||||
@Inject
|
|
||||||
constructor(
|
|
||||||
private val appDataRepository: AppDataRepository,
|
|
||||||
private val tunnelManager: TunnelManager,
|
|
||||||
private val networkMonitor: NetworkMonitor,
|
|
||||||
private val networkUtils: NetworkUtils,
|
|
||||||
private val logReader: LogReader,
|
|
||||||
) {
|
|
||||||
|
|
||||||
@OptIn(FlowPreview::class)
|
|
||||||
suspend fun startMonitoring(tunnelConf: TunnelConf, withLogs: Boolean): Job = coroutineScope {
|
|
||||||
launch {
|
|
||||||
launch { startTunnelConfChangesJob(tunnelConf) }
|
|
||||||
launch { startPingMonitor(tunnelConf) }
|
|
||||||
launch { startWgStatsPoll(tunnelConf) }
|
|
||||||
if (withLogs) launch { startLogsMonitor(tunnelConf) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun startTunnelConfChangesJob(tunnelConf: TunnelConf) {
|
|
||||||
appDataRepository.tunnels.flow
|
|
||||||
.map { storedTunnels -> storedTunnels.firstOrNull { it.id == tunnelConf.id } }
|
|
||||||
.filterNotNull()
|
|
||||||
.distinctUntilChanged { old, new -> old == new }
|
|
||||||
.collect { storedTunnel ->
|
|
||||||
if (tunnelConf != storedTunnel) {
|
|
||||||
Timber.d("Config changed for ${storedTunnel.tunName}, bouncing")
|
|
||||||
withContext(NonCancellable) {
|
|
||||||
tunnelManager.bounceTunnel(
|
|
||||||
storedTunnel,
|
|
||||||
TunnelStatus.StopReason.ConfigChanged,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun startLogsMonitor(tunnelConf: TunnelConf) {
|
|
||||||
logReader.liveLogs.collect { log ->
|
|
||||||
val healthLogs =
|
|
||||||
when {
|
|
||||||
log.message.contains(HANDSHAKE_RESPONSE_TEXT, true) ||
|
|
||||||
log.message.contains(KEEPALIVE_RESPONSE_TEXT, true) -> true
|
|
||||||
log.message.contains(HANDSHAKE_INIT_FAILED_TEXT, true) ||
|
|
||||||
log.message.contains(HANDSHAKE_NOT_COMPLETED_TEXT) ||
|
|
||||||
log.message.contains(DATA_PACKET_FAILED_TEXT) -> false
|
|
||||||
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
healthLogs?.let { healthy ->
|
|
||||||
tunnelManager.updateTunnelStatus(tunnelConf, null, null, null, healthy)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun startPingMonitor(tunnelConf: TunnelConf) = coroutineScope {
|
|
||||||
val pingStatsFlow = MutableStateFlow<Map<Key, PingState>>(emptyMap())
|
|
||||||
|
|
||||||
val tunStateFlow =
|
|
||||||
tunnelManager.activeTunnels.mapNotNull { it.getValueById(tunnelConf.id) }.stateIn(this)
|
|
||||||
|
|
||||||
val connectivityStateFlow = networkMonitor.connectivityStateFlow.stateIn(this)
|
|
||||||
|
|
||||||
val isNetworkConnected = connectivityStateFlow.map { it.hasConnectivity() }.stateIn(this)
|
|
||||||
|
|
||||||
data class NetworkChangeKey(
|
|
||||||
val ethernetConnected: Boolean,
|
|
||||||
val wifiConnected: Boolean,
|
|
||||||
val cellularConnected: Boolean,
|
|
||||||
val wifiSsid: String?,
|
|
||||||
)
|
|
||||||
|
|
||||||
connectivityStateFlow
|
|
||||||
.map {
|
|
||||||
NetworkChangeKey(
|
|
||||||
ethernetConnected = it.ethernetConnected,
|
|
||||||
wifiConnected = it.wifiState.connected,
|
|
||||||
cellularConnected = it.cellularConnected,
|
|
||||||
wifiSsid = if (it.wifiState.connected) it.wifiState.ssid else null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.distinctUntilChanged()
|
|
||||||
.stateIn(this)
|
|
||||||
|
|
||||||
appDataRepository.settings.flow
|
|
||||||
.distinctUntilChanged { old, new ->
|
|
||||||
old.isPingEnabled == new.isPingEnabled &&
|
|
||||||
old.tunnelPingIntervalSeconds == new.tunnelPingIntervalSeconds &&
|
|
||||||
old.tunnelPingAttempts == new.tunnelPingAttempts &&
|
|
||||||
old.tunnelPingTimeoutSeconds == new.tunnelPingTimeoutSeconds
|
|
||||||
}
|
|
||||||
.collectLatest { settings ->
|
|
||||||
if (!settings.isPingEnabled) return@collectLatest
|
|
||||||
|
|
||||||
Timber.d("Starting pinger for ${tunnelConf.tunName} with settings")
|
|
||||||
|
|
||||||
val config = tunnelConf.toAmConfig()
|
|
||||||
|
|
||||||
val pingablePeers = config.peers.filter { it.allowedIps.isNotEmpty() }
|
|
||||||
if (pingablePeers.isEmpty()) return@collectLatest
|
|
||||||
|
|
||||||
suspend fun performPing() {
|
|
||||||
val updates = ConcurrentMap<Key, PingState>()
|
|
||||||
|
|
||||||
pingablePeers.forEach { peer ->
|
|
||||||
val previousState = pingStatsFlow.value[peer.publicKey] ?: PingState()
|
|
||||||
|
|
||||||
val allowedIpStr = peer.allowedIps.firstOrNull()?.toString()
|
|
||||||
if (allowedIpStr == null) {
|
|
||||||
updates[peer.publicKey] =
|
|
||||||
previousState.copy(
|
|
||||||
isReachable = false,
|
|
||||||
failureReason = FailureReason.NoResolvedEndpoint,
|
|
||||||
lastPingAttemptMillis = System.currentTimeMillis(),
|
|
||||||
)
|
|
||||||
return@forEach
|
|
||||||
}
|
|
||||||
|
|
||||||
val host =
|
|
||||||
tunnelConf.pingTarget
|
|
||||||
?: {
|
|
||||||
val parts = allowedIpStr.split("/")
|
|
||||||
val internalIp =
|
|
||||||
if (parts.size == 2) parts[0] else allowedIpStr
|
|
||||||
|
|
||||||
val prefix =
|
|
||||||
if (parts.size == 2) parts[1].toIntOrNull() ?: 32
|
|
||||||
else 32
|
|
||||||
if (prefix <= 1) {
|
|
||||||
CLOUDFLARE_IPV4_IP
|
|
||||||
} else {
|
|
||||||
internalIp.removeSurrounding("[", "]")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.invoke()
|
|
||||||
|
|
||||||
val attemptTime = System.currentTimeMillis()
|
|
||||||
runCatching {
|
|
||||||
val pingStats =
|
|
||||||
settings.tunnelPingTimeoutSeconds?.let {
|
|
||||||
networkUtils.pingWithStats(
|
|
||||||
host,
|
|
||||||
settings.tunnelPingAttempts,
|
|
||||||
it.toMillis(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
?: networkUtils.pingWithStats(
|
|
||||||
host,
|
|
||||||
settings.tunnelPingAttempts,
|
|
||||||
)
|
|
||||||
|
|
||||||
updates[peer.publicKey] =
|
|
||||||
previousState.copy(
|
|
||||||
transmitted = pingStats.transmitted,
|
|
||||||
received = pingStats.received,
|
|
||||||
packetLoss = pingStats.packetLoss,
|
|
||||||
rttMin = pingStats.rttMin,
|
|
||||||
rttMax = pingStats.rttMax,
|
|
||||||
rttAvg = pingStats.rttAvg,
|
|
||||||
rttStddev = pingStats.rttStddev,
|
|
||||||
isReachable = pingStats.isReachable,
|
|
||||||
failureReason =
|
|
||||||
if (pingStats.isReachable) null
|
|
||||||
else FailureReason.PingFailed,
|
|
||||||
lastSuccessfulPingMillis =
|
|
||||||
pingStats.lastSuccessfulPingMillis
|
|
||||||
?: previousState.lastSuccessfulPingMillis,
|
|
||||||
pingTarget = host,
|
|
||||||
lastPingAttemptMillis = attemptTime,
|
|
||||||
)
|
|
||||||
Timber.d(
|
|
||||||
"Ping completed for peer ${peer.publicKey.toBase64().substring(0, 5)}.. to host $host with stats: $pingStats"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.onFailure {
|
|
||||||
Timber.e(
|
|
||||||
it,
|
|
||||||
"Ping failed for peer ${peer.publicKey} in ${tunnelConf.tunName} to host $host",
|
|
||||||
)
|
|
||||||
updates[peer.publicKey] =
|
|
||||||
previousState.copy(
|
|
||||||
isReachable = false,
|
|
||||||
failureReason = FailureReason.PingFailed,
|
|
||||||
pingTarget = host,
|
|
||||||
lastPingAttemptMillis = attemptTime,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updates.isNotEmpty()) {
|
|
||||||
pingStatsFlow.update { updates }
|
|
||||||
tunnelManager.updateTunnelStatus(tunnelConf, null, null, updates)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the tunnel to be fully active
|
|
||||||
tunStateFlow.filter { state -> state.status == TunnelStatus.Up }.first()
|
|
||||||
|
|
||||||
// small delay to make sure tunnel is fully up before we actively monitor
|
|
||||||
delay(3_000L)
|
|
||||||
|
|
||||||
while (isActive) {
|
|
||||||
if (isNetworkConnected.value) {
|
|
||||||
performPing()
|
|
||||||
} else {
|
|
||||||
pingStatsFlow.update { current ->
|
|
||||||
current.mapValues { entry ->
|
|
||||||
entry.value.copy(
|
|
||||||
isReachable = false,
|
|
||||||
failureReason = FailureReason.NoConnectivity,
|
|
||||||
lastPingAttemptMillis = System.currentTimeMillis(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tunnelManager.updateTunnelStatus(
|
|
||||||
tunnelConf,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
pingStatsFlow.value,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
delay(settings.tunnelPingIntervalSeconds.toMillis())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun startWgStatsPoll(tunnelConf: TunnelConf) = coroutineScope {
|
|
||||||
while (isActive) {
|
|
||||||
val stats = tunnelManager.getStatistics(tunnelConf)
|
|
||||||
tunnelManager.updateTunnelStatus(tunnelConf, null, stats, null)
|
|
||||||
delay(STATS_DELAY)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val CLOUDFLARE_IPV6_IP = "2606:4700:4700::1111"
|
|
||||||
const val CLOUDFLARE_IPV4_IP = "1.1.1.1"
|
|
||||||
|
|
||||||
const val STATS_DELAY = 1_000L
|
|
||||||
|
|
||||||
const val KEEPALIVE_RESPONSE_TEXT = "Receiving keepalive packet"
|
|
||||||
const val HANDSHAKE_RESPONSE_TEXT = "Received handshake response"
|
|
||||||
const val HANDSHAKE_INIT_FAILED_TEXT = "Failed to send handshake initiation: write udp"
|
|
||||||
const val DATA_PACKET_FAILED_TEXT = "Failed to send data packets"
|
|
||||||
const val HANDSHAKE_NOT_COMPLETED_TEXT =
|
|
||||||
"Handshake did not complete after 5 seconds, retrying"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+10
-21
@@ -1,17 +1,14 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendError
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import org.amnezia.awg.crypto.Key
|
|
||||||
|
|
||||||
interface TunnelProvider {
|
interface TunnelProvider {
|
||||||
/** Starts the specified tunnel configuration. */
|
/** Starts the specified tunnel configuration. */
|
||||||
@@ -26,24 +23,24 @@ interface TunnelProvider {
|
|||||||
*/
|
*/
|
||||||
suspend fun stopTunnel(
|
suspend fun stopTunnel(
|
||||||
tunnelConf: TunnelConf? = null,
|
tunnelConf: TunnelConf? = null,
|
||||||
reason: TunnelStatus.StopReason = TunnelStatus.StopReason.User,
|
reason: TunnelStatus.StopReason = TunnelStatus.StopReason.USER,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bounces (stops and restarts) the specified tunnel.
|
* Bounces (stops and restarts) the specified tunnel.
|
||||||
*
|
*
|
||||||
* @param tunnelConf The tunnel to bounce.
|
* @param tunnelConf The tunnel to bounce.
|
||||||
* @param reason The reason for bouncing, defaults to User for manual actions. Callers should
|
* @param reason The reason for bouncing, defaults to USER for manual actions. Callers should
|
||||||
* override with specific reasons (e.g., Ping, ConfigChanged) when applicable.
|
* override with specific reasons (e.g., PING, CONFIG_CHANGED) when applicable.
|
||||||
*/
|
*/
|
||||||
suspend fun bounceTunnel(
|
suspend fun bounceTunnel(
|
||||||
tunnelConf: TunnelConf,
|
tunnelConf: TunnelConf,
|
||||||
reason: TunnelStatus.StopReason = TunnelStatus.StopReason.User,
|
reason: TunnelStatus.StopReason = TunnelStatus.StopReason.USER,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun setBackendMode(backendMode: BackendMode)
|
fun setBackendState(backendState: BackendState, allowedIps: Collection<String>)
|
||||||
|
|
||||||
fun getBackendMode(): BackendMode
|
fun getBackendState(): BackendState
|
||||||
|
|
||||||
suspend fun runningTunnelNames(): Set<String>
|
suspend fun runningTunnelNames(): Set<String>
|
||||||
|
|
||||||
@@ -51,19 +48,11 @@ interface TunnelProvider {
|
|||||||
|
|
||||||
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
||||||
|
|
||||||
val errorEvents: SharedFlow<Pair<TunnelConf, BackendCoreException>>
|
val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||||
|
|
||||||
val messageEvents: SharedFlow<Pair<TunnelConf, BackendMessage>>
|
|
||||||
|
|
||||||
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
val bouncingTunnelIds: ConcurrentHashMap<Int, TunnelStatus.StopReason>
|
||||||
|
|
||||||
fun hasVpnPermission(): Boolean
|
fun hasVpnPermission(): Boolean
|
||||||
|
|
||||||
suspend fun updateTunnelStatus(
|
suspend fun updateTunnelStatistics(tunnel: TunnelConf)
|
||||||
tunnelConf: TunnelConf,
|
|
||||||
status: TunnelStatus? = null,
|
|
||||||
stats: TunnelStatistics? = null,
|
|
||||||
pingStates: Map<Key, PingState>? = null,
|
|
||||||
handshakeSuccessLogs: Boolean? = null,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-77
@@ -1,99 +1,45 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppProxySettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.AmneziaStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.AmneziaStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asAmBackendMode
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asAmBackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asBackendMode
|
import com.zaneschepke.wireguardautotunnel.util.extensions.asBackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendCoreException
|
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
||||||
import java.io.IOException
|
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import kotlin.jvm.optionals.getOrNull
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import org.amnezia.awg.backend.Backend
|
import org.amnezia.awg.backend.Backend
|
||||||
import org.amnezia.awg.backend.BackendException
|
import org.amnezia.awg.backend.BackendException
|
||||||
import org.amnezia.awg.backend.ProxyGoBackend
|
|
||||||
import org.amnezia.awg.backend.Tunnel
|
import org.amnezia.awg.backend.Tunnel
|
||||||
import org.amnezia.awg.config.Config
|
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
|
import timber.log.Timber
|
||||||
|
|
||||||
class UserspaceTunnel
|
class UserspaceTunnel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
applicationScope: CoroutineScope,
|
@ApplicationScope private val applicationScope: CoroutineScope,
|
||||||
val serviceManager: ServiceManager,
|
val serviceManager: ServiceManager,
|
||||||
val appDataRepository: AppDataRepository,
|
val appDataRepository: AppDataRepository,
|
||||||
private val backend: Backend,
|
private val backend: Backend,
|
||||||
) : BaseTunnel(applicationScope, appDataRepository, serviceManager) {
|
) : BaseTunnel(applicationScope, appDataRepository, serviceManager) {
|
||||||
|
|
||||||
|
private var previousBackendState: Pair<BackendState, Boolean>? = null
|
||||||
|
|
||||||
override suspend fun startBackend(tunnel: TunnelConf) {
|
override suspend fun startBackend(tunnel: TunnelConf) {
|
||||||
try {
|
try {
|
||||||
updateTunnelStatus(tunnel, TunnelStatus.Starting)
|
updateTunnelStatus(tunnel, TunnelStatus.Starting)
|
||||||
|
val amConfig = tunnel.toAmConfig()
|
||||||
val proxies: List<Proxy> =
|
handleVpnKillSwitchWithDomainEndpoints(amConfig)
|
||||||
when (backend) {
|
backend.setState(tunnel, Tunnel.State.UP, amConfig)
|
||||||
is ProxyGoBackend -> {
|
|
||||||
val proxySettings = appDataRepository.proxySettings.get()
|
|
||||||
Timber.d("Adding proxy configs")
|
|
||||||
buildList {
|
|
||||||
if (proxySettings.socks5ProxyEnabled) {
|
|
||||||
add(
|
|
||||||
Socks5Proxy(
|
|
||||||
proxySettings.socks5ProxyBindAddress
|
|
||||||
?: AppProxySettings.DEFAULT_SOCKS_BIND_ADDRESS,
|
|
||||||
proxySettings.proxyUsername,
|
|
||||||
proxySettings.proxyPassword,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (proxySettings.httpProxyEnabled) {
|
|
||||||
add(
|
|
||||||
HttpProxy(
|
|
||||||
proxySettings.httpProxyBindAddress
|
|
||||||
?: AppProxySettings.DEFAULT_HTTP_BIND_ADDRESS,
|
|
||||||
proxySettings.proxyUsername,
|
|
||||||
proxySettings.proxyPassword,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> emptyList()
|
|
||||||
}
|
|
||||||
val setting = appDataRepository.settings.get()
|
|
||||||
val config = tunnel.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(tunnel, Tunnel.State.UP, updatedConfig)
|
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
||||||
throw e.toBackendCoreException()
|
throw e.toBackendError()
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
|
||||||
throw BackendCoreException.Config
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,24 +49,48 @@ constructor(
|
|||||||
backend.setState(tunnel, Tunnel.State.DOWN, tunnel.toAmConfig())
|
backend.setState(tunnel, Tunnel.State.DOWN, tunnel.toAmConfig())
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
||||||
throw e.toBackendCoreException()
|
throw e.toBackendError()
|
||||||
|
} finally {
|
||||||
|
handlePreviouslyEnabledVpnKillSwitch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setBackendMode(backendMode: BackendMode) {
|
// stop vpn kill switch if we need to resolve DNS for peer endpoints
|
||||||
Timber.d("Setting backend mode: $backendMode")
|
private suspend fun handleVpnKillSwitchWithDomainEndpoints(config: Config) {
|
||||||
|
if (
|
||||||
|
config.peers.any { it.endpoint.getOrNull()?.toString()?.isUrl() == true } &&
|
||||||
|
backend.backendState.asBackendState() == BackendState.KILL_SWITCH_ACTIVE
|
||||||
|
) {
|
||||||
|
val bypassLan = appDataRepository.settings.get().isLanOnKillSwitchEnabled
|
||||||
|
previousBackendState = Pair(BackendState.KILL_SWITCH_ACTIVE, bypassLan)
|
||||||
|
setBackendState(BackendState.SERVICE_ACTIVE, emptyList())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore vpn kill switch if needed
|
||||||
|
private fun handlePreviouslyEnabledVpnKillSwitch() {
|
||||||
|
// let auto tunnel handle this if it is active
|
||||||
|
if (serviceManager.autoTunnelService.value == null) {
|
||||||
|
previousBackendState?.let { (state, lanEnabled) ->
|
||||||
|
Timber.d("Restoring kill switch configuration")
|
||||||
|
val lan = if (lanEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS else emptyList()
|
||||||
|
backend.setBackendState(state.asAmBackendState(), lan)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
previousBackendState = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setBackendState(backendState: BackendState, allowedIps: Collection<String>) {
|
||||||
|
Timber.d("Setting backend state: $backendState with allowedIps: $allowedIps")
|
||||||
try {
|
try {
|
||||||
backend.backendMode = backendMode.asAmBackendMode()
|
backend.setBackendState(backendState.asAmBackendState(), allowedIps)
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
throw e.toBackendCoreException()
|
throw e.toBackendError()
|
||||||
// TODO this should be mapped to BackendException in the lib
|
|
||||||
} catch (e: IOException) {
|
|
||||||
throw BackendCoreException.NotAuthorized
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBackendMode(): BackendMode {
|
override fun getBackendState(): BackendState {
|
||||||
return backend.backendMode.asBackendMode()
|
return backend.backendState.asBackendState()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun runningTunnelNames(): Set<String> {
|
override suspend fun runningTunnelNames(): Set<String> {
|
||||||
|
|||||||
@@ -2,8 +2,13 @@ package com.zaneschepke.wireguardautotunnel.core.worker
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.hilt.work.HiltWorker
|
import androidx.hilt.work.HiltWorker
|
||||||
import androidx.work.*
|
import androidx.work.CoroutineWorker
|
||||||
|
import androidx.work.ExistingPeriodicWorkPolicy
|
||||||
|
import androidx.work.PeriodicWorkRequestBuilder
|
||||||
|
import androidx.work.WorkManager
|
||||||
|
import androidx.work.WorkerParameters
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
@@ -22,6 +27,7 @@ constructor(
|
|||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
|
private val tunnelManager: TunnelManager,
|
||||||
) : CoroutineWorker(context, params) {
|
) : CoroutineWorker(context, params) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -51,11 +57,10 @@ constructor(
|
|||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
Timber.i("Service worker started")
|
Timber.i("Service worker started")
|
||||||
with(appDataRepository.settings.get()) {
|
with(appDataRepository.settings.get()) {
|
||||||
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) {
|
return@with serviceManager.startAutoTunnel()
|
||||||
Timber.i("Service has been killed by system, restoring.")
|
if (tunnelManager.activeTunnels.value.isEmpty())
|
||||||
serviceManager.startAutoTunnel()
|
tunnelManager.restorePreviousState()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Result.success()
|
Result.success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data
|
package com.zaneschepke.wireguardautotunnel.data
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.AutoMigration
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.DeleteColumn
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import androidx.room.TypeConverters
|
||||||
import androidx.room.migration.AutoMigrationSpec
|
import androidx.room.migration.AutoMigrationSpec
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.ProxySettingsDao
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.ProxySettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities = [Settings::class, TunnelConfig::class, ProxySettings::class],
|
entities = [Settings::class, TunnelConfig::class],
|
||||||
version = 22,
|
version = 17,
|
||||||
autoMigrations =
|
autoMigrations =
|
||||||
[
|
[
|
||||||
AutoMigration(from = 1, to = 2),
|
AutoMigration(from = 1, to = 2),
|
||||||
@@ -31,11 +32,6 @@ import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
|||||||
AutoMigration(from = 14, to = 15),
|
AutoMigration(from = 14, to = 15),
|
||||||
AutoMigration(from = 15, to = 16),
|
AutoMigration(from = 15, to = 16),
|
||||||
AutoMigration(from = 16, to = 17, spec = WifiDetectionMigration::class),
|
AutoMigration(from = 16, to = 17, spec = WifiDetectionMigration::class),
|
||||||
AutoMigration(from = 17, to = 18),
|
|
||||||
AutoMigration(from = 18, to = 19, spec = PingMigration::class),
|
|
||||||
AutoMigration(from = 19, to = 20, spec = ProxyMigration::class),
|
|
||||||
AutoMigration(from = 20, to = 21, spec = FixProxySettingsMigration::class),
|
|
||||||
AutoMigration(from = 21, to = 22),
|
|
||||||
],
|
],
|
||||||
exportSchema = true,
|
exportSchema = true,
|
||||||
)
|
)
|
||||||
@@ -44,8 +40,6 @@ abstract class AppDatabase : RoomDatabase() {
|
|||||||
abstract fun settingDao(): SettingsDao
|
abstract fun settingDao(): SettingsDao
|
||||||
|
|
||||||
abstract fun tunnelConfigDoa(): TunnelConfigDao
|
abstract fun tunnelConfigDoa(): TunnelConfigDao
|
||||||
|
|
||||||
abstract fun proxySettingsDoa(): ProxySettingsDao
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteColumn(tableName = "Settings", columnName = "default_tunnel")
|
@DeleteColumn(tableName = "Settings", columnName = "default_tunnel")
|
||||||
@@ -57,46 +51,3 @@ class RemoveTunnelPauseMigration : AutoMigrationSpec
|
|||||||
|
|
||||||
@DeleteColumn(tableName = "Settings", columnName = "is_wifi_by_shell_enabled")
|
@DeleteColumn(tableName = "Settings", columnName = "is_wifi_by_shell_enabled")
|
||||||
class WifiDetectionMigration : AutoMigrationSpec
|
class WifiDetectionMigration : AutoMigrationSpec
|
||||||
|
|
||||||
@DeleteColumn.Entries(
|
|
||||||
DeleteColumn(tableName = "TunnelConfig", columnName = "ping_interval"),
|
|
||||||
DeleteColumn(tableName = "TunnelConfig", columnName = "ping_cooldown"),
|
|
||||||
DeleteColumn(tableName = "Settings", columnName = "split_tunnel_apps"),
|
|
||||||
)
|
|
||||||
@RenameColumn.Entries(
|
|
||||||
RenameColumn(
|
|
||||||
tableName = "TunnelConfig",
|
|
||||||
fromColumnName = "is_ping_enabled",
|
|
||||||
toColumnName = "restart_on_ping_failure",
|
|
||||||
),
|
|
||||||
RenameColumn(
|
|
||||||
tableName = "TunnelConfig",
|
|
||||||
fromColumnName = "ping_ip",
|
|
||||||
toColumnName = "ping_target",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
class PingMigration : AutoMigrationSpec
|
|
||||||
|
|
||||||
@DeleteColumn.Entries(
|
|
||||||
DeleteColumn(tableName = "Settings", columnName = "is_amnezia_enabled"),
|
|
||||||
DeleteColumn(tableName = "Settings", columnName = "is_vpn_kill_switch_enabled"),
|
|
||||||
DeleteColumn(tableName = "Settings", columnName = "is_kernel_kill_switch_enabled"),
|
|
||||||
DeleteColumn(tableName = "Settings", columnName = "is_kernel_enabled"),
|
|
||||||
)
|
|
||||||
class ProxyMigration : AutoMigrationSpec {
|
|
||||||
override fun onPostMigrate(db: SupportSQLiteDatabase) {
|
|
||||||
db.execSQL("INSERT INTO proxy_settings DEFAULT VALUES")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FixProxySettingsMigration : AutoMigrationSpec {
|
|
||||||
override fun onPostMigrate(db: SupportSQLiteDatabase) {
|
|
||||||
val cursor = db.query("SELECT COUNT(*) FROM proxy_settings")
|
|
||||||
val count = if (cursor.moveToFirst()) cursor.getInt(0) else 0
|
|
||||||
cursor.close()
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
db.execSQL("INSERT INTO proxy_settings DEFAULT VALUES")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@@ -30,7 +31,6 @@ class DataStoreManager(
|
|||||||
val theme = stringPreferencesKey("THEME")
|
val theme = stringPreferencesKey("THEME")
|
||||||
val isRemoteControlEnabled = booleanPreferencesKey("IS_REMOTE_CONTROL_ENABLED")
|
val isRemoteControlEnabled = booleanPreferencesKey("IS_REMOTE_CONTROL_ENABLED")
|
||||||
val remoteKey = stringPreferencesKey("REMOTE_KEY")
|
val remoteKey = stringPreferencesKey("REMOTE_KEY")
|
||||||
val showDetailedPingStats = booleanPreferencesKey("SHOW_DETAILED_PING_STATS")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// preferences
|
// preferences
|
||||||
@@ -84,5 +84,9 @@ class DataStoreManager(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> getFromStoreBlocking(key: Preferences.Key<T>) = runBlocking {
|
||||||
|
context.dataStore.data.map { it[key] }.first()
|
||||||
|
}
|
||||||
|
|
||||||
val preferencesFlow: Flow<Preferences?> = context.dataStore.data.flowOn(ioDispatcher)
|
val preferencesFlow: Flow<Preferences?> = context.dataStore.data.flowOn(ioDispatcher)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,20 @@ 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 timber.log.Timber
|
||||||
import javax.inject.Provider
|
|
||||||
|
|
||||||
class DatabaseCallback @Inject constructor(private val databaseProvider: Provider<AppDatabase>) :
|
class DatabaseCallback : RoomDatabase.Callback() {
|
||||||
RoomDatabase.Callback() {
|
override fun onCreate(db: SupportSQLiteDatabase) =
|
||||||
|
db.run {
|
||||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
beginTransaction()
|
||||||
super.onCreate(db)
|
try {
|
||||||
db.execSQL("INSERT INTO proxy_settings DEFAULT VALUES")
|
execSQL(Queries.createDefaultSettings())
|
||||||
db.execSQL("INSERT INTO Settings DEFAULT VALUES")
|
Timber.i("Bootstrapping settings data")
|
||||||
}
|
setTransactionSuccessful()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e)
|
||||||
|
} finally {
|
||||||
|
endTransaction()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,30 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data
|
package com.zaneschepke.wireguardautotunnel.data
|
||||||
|
|
||||||
import androidx.room.TypeConverter
|
import androidx.room.TypeConverter
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.WifiDetectionMethod
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
class DatabaseConverters {
|
class DatabaseConverters {
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun listToString(value: List<String>): String {
|
fun listToString(value: MutableList<String>): String {
|
||||||
return Json.encodeToString(value)
|
return Json.encodeToString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun stringToList(value: String): List<String> {
|
fun stringToList(value: String): MutableList<String> {
|
||||||
if (value.isBlank() || value.isEmpty()) return mutableListOf()
|
if (value.isBlank() || value.isEmpty()) return mutableListOf()
|
||||||
return try {
|
return try {
|
||||||
Json.decodeFromString<List<String>>(value)
|
Json.decodeFromString<MutableList<String>>(value)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
val list = value.split(",").toMutableList()
|
val list = value.split(",").toMutableList()
|
||||||
val json = listToString(list)
|
val json = listToString(list)
|
||||||
Json.decodeFromString<List<String>>(json)
|
Json.decodeFromString<MutableList<String>>(json)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter fun fromStatus(status: Settings.WifiDetectionMethod): Int = status.value
|
||||||
fun setToString(value: Set<String>): String {
|
|
||||||
return listToString(value.toList())
|
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun stringToSet(value: String): Set<String> {
|
fun toStatus(value: Int): Settings.WifiDetectionMethod =
|
||||||
return stringToList(value).toSet()
|
Settings.WifiDetectionMethod.fromValue(value)
|
||||||
}
|
|
||||||
|
|
||||||
@TypeConverter fun fromStatus(status: WifiDetectionMethod): Int = status.value
|
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
fun toStatus(value: Int): WifiDetectionMethod = WifiDetectionMethod.fromValue(value)
|
|
||||||
|
|
||||||
@TypeConverter fun toMode(value: Int): AppMode = AppMode.fromValue(value)
|
|
||||||
|
|
||||||
@TypeConverter fun fromMode(mode: AppMode): Int = mode.value
|
|
||||||
|
|
||||||
@TypeConverter fun toDnsProtocol(value: Int): DnsProtocol = DnsProtocol.fromValue(value)
|
|
||||||
|
|
||||||
@TypeConverter fun fromDnsProtocol(mode: DnsProtocol): Int = mode.value
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.data
|
||||||
|
|
||||||
|
object Queries {
|
||||||
|
fun createDefaultSettings(): String {
|
||||||
|
return """
|
||||||
|
INSERT INTO Settings (is_tunnel_enabled,
|
||||||
|
is_tunnel_on_mobile_data_enabled,
|
||||||
|
trusted_network_ssids,
|
||||||
|
is_always_on_vpn_enabled,
|
||||||
|
is_tunnel_on_ethernet_enabled,
|
||||||
|
is_shortcuts_enabled,
|
||||||
|
is_tunnel_on_wifi_enabled,
|
||||||
|
is_kernel_enabled,
|
||||||
|
is_restore_on_boot_enabled,
|
||||||
|
is_multi_tunnel_enabled)
|
||||||
|
VALUES
|
||||||
|
('false',
|
||||||
|
'false',
|
||||||
|
'',
|
||||||
|
'false',
|
||||||
|
'false',
|
||||||
|
'false',
|
||||||
|
'false',
|
||||||
|
'false',
|
||||||
|
'false',
|
||||||
|
'false')
|
||||||
|
"""
|
||||||
|
.trimIndent()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createTunnelConfig(): String {
|
||||||
|
return """
|
||||||
|
INSERT INTO TunnelConfig (name, wg_quick) VALUES ('test', 'test')
|
||||||
|
"""
|
||||||
|
.trimIndent()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.dao
|
|
||||||
|
|
||||||
import androidx.room.*
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.ProxySettings
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface ProxySettingsDao {
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun save(t: ProxySettings)
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun saveAll(t: List<ProxySettings>)
|
|
||||||
|
|
||||||
@Query("SELECT * FROM proxy_settings WHERE id=:id")
|
|
||||||
suspend fun getById(id: Long): ProxySettings?
|
|
||||||
|
|
||||||
@Query("SELECT * FROM proxy_settings") suspend fun getAll(): List<ProxySettings>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM proxy_settings LIMIT 1") fun getSettingsFlow(): Flow<ProxySettings>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM proxy_settings") fun getAllFlow(): Flow<List<ProxySettings>>
|
|
||||||
|
|
||||||
@Delete suspend fun delete(t: ProxySettings)
|
|
||||||
|
|
||||||
@Query("SELECT COUNT('id') FROM proxy_settings") suspend fun count(): Long
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.dao
|
package com.zaneschepke.wireguardautotunnel.data.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Delete
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@@ -16,7 +20,7 @@ interface SettingsDao {
|
|||||||
|
|
||||||
@Query("SELECT * FROM settings LIMIT 1") fun getSettingsFlow(): Flow<Settings>
|
@Query("SELECT * FROM settings LIMIT 1") fun getSettingsFlow(): Flow<Settings>
|
||||||
|
|
||||||
@Query("SELECT * FROM settings") fun getAllFlow(): Flow<List<Settings>>
|
@Query("SELECT * FROM settings") fun getAllFlow(): Flow<MutableList<Settings>>
|
||||||
|
|
||||||
@Delete suspend fun delete(t: Settings)
|
@Delete suspend fun delete(t: Settings)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.dao
|
package com.zaneschepke.wireguardautotunnel.data.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Delete
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@@ -22,8 +26,6 @@ interface TunnelConfigDao {
|
|||||||
|
|
||||||
@Delete suspend fun delete(t: TunnelConfig)
|
@Delete suspend fun delete(t: TunnelConfig)
|
||||||
|
|
||||||
@Delete suspend fun delete(t: TunnelConfigs)
|
|
||||||
|
|
||||||
@Query("SELECT COUNT('id') FROM TunnelConfig") suspend fun count(): Long
|
@Query("SELECT COUNT('id') FROM TunnelConfig") suspend fun count(): Long
|
||||||
|
|
||||||
@Query("SELECT * FROM TunnelConfig WHERE tunnel_networks LIKE '%' || :name || '%'")
|
@Query("SELECT * FROM TunnelConfig WHERE tunnel_networks LIKE '%' || :name || '%'")
|
||||||
@@ -44,6 +46,5 @@ interface TunnelConfigDao {
|
|||||||
@Query("SELECT * FROM TUNNELCONFIG WHERE is_mobile_data_tunnel=1")
|
@Query("SELECT * FROM TUNNELCONFIG WHERE is_mobile_data_tunnel=1")
|
||||||
suspend fun findByMobileDataTunnel(): TunnelConfigs
|
suspend fun findByMobileDataTunnel(): TunnelConfigs
|
||||||
|
|
||||||
@Query("SELECT * FROM tunnelconfig ORDER BY position")
|
@Query("SELECT * FROM tunnelconfig") fun getAllFlow(): Flow<MutableList<TunnelConfig>>
|
||||||
fun getAllFlow(): Flow<List<TunnelConfig>>
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ data class GeneralState(
|
|||||||
val expandedTunnelIds: List<Int> = emptyList(),
|
val expandedTunnelIds: List<Int> = emptyList(),
|
||||||
val isLocalLogsEnabled: Boolean = IS_LOGS_ENABLED_DEFAULT,
|
val isLocalLogsEnabled: Boolean = IS_LOGS_ENABLED_DEFAULT,
|
||||||
val isRemoteControlEnabled: Boolean = IS_REMOTE_CONTROL_ENABLED,
|
val isRemoteControlEnabled: Boolean = IS_REMOTE_CONTROL_ENABLED,
|
||||||
val showDetailedPingStats: Boolean = SHOW_DETAILED_PING_STATS_DEFAULT,
|
|
||||||
val remoteKey: String? = null,
|
val remoteKey: String? = null,
|
||||||
val locale: String? = null,
|
val locale: String? = null,
|
||||||
val theme: Theme = Theme.AUTOMATIC,
|
val theme: Theme = Theme.AUTOMATIC,
|
||||||
@@ -21,6 +20,5 @@ data class GeneralState(
|
|||||||
const val PIN_LOCK_ENABLED_DEFAULT = false
|
const val PIN_LOCK_ENABLED_DEFAULT = false
|
||||||
const val IS_LOGS_ENABLED_DEFAULT = false
|
const val IS_LOGS_ENABLED_DEFAULT = false
|
||||||
const val IS_REMOTE_CONTROL_ENABLED = false
|
const val IS_REMOTE_CONTROL_ENABLED = false
|
||||||
const val SHOW_DETAILED_PING_STATS_DEFAULT = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.entity
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity(tableName = "proxy_settings")
|
|
||||||
data class ProxySettings(
|
|
||||||
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
|
||||||
@ColumnInfo(name = "socks5_proxy_enabled", defaultValue = "0")
|
|
||||||
val socks5ProxyEnabled: Boolean = false,
|
|
||||||
@ColumnInfo(name = "socks5_proxy_bind_address") val socks5ProxyBindAddress: String? = null,
|
|
||||||
@ColumnInfo(name = "http_proxy_enable", defaultValue = "0")
|
|
||||||
val httpProxyEnabled: Boolean = false,
|
|
||||||
@ColumnInfo(name = "http_proxy_bind_address") val httpProxyBindAddress: String? = null,
|
|
||||||
@ColumnInfo(name = "proxy_username") val proxyUsername: String? = null,
|
|
||||||
@ColumnInfo(name = "proxy_password") val proxyPassword: String? = null,
|
|
||||||
)
|
|
||||||
@@ -3,54 +3,63 @@ package com.zaneschepke.wireguardautotunnel.data.entity
|
|||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.WifiDetectionMethod
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
data class Settings(
|
data class Settings(
|
||||||
@PrimaryKey(autoGenerate = true) val id: Int = 0,
|
@PrimaryKey(autoGenerate = true) val id: Int = 0,
|
||||||
@ColumnInfo(name = "is_tunnel_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_tunnel_enabled") val isAutoTunnelEnabled: Boolean = false,
|
||||||
val isAutoTunnelEnabled: Boolean = false,
|
@ColumnInfo(name = "is_tunnel_on_mobile_data_enabled")
|
||||||
@ColumnInfo(name = "is_tunnel_on_mobile_data_enabled", defaultValue = "0")
|
|
||||||
val isTunnelOnMobileDataEnabled: Boolean = false,
|
val isTunnelOnMobileDataEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "trusted_network_ssids", defaultValue = "")
|
@ColumnInfo(name = "trusted_network_ssids")
|
||||||
val trustedNetworkSSIDs: Set<String> = emptySet(),
|
val trustedNetworkSSIDs: MutableList<String> = mutableListOf(),
|
||||||
@ColumnInfo(name = "is_always_on_vpn_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_always_on_vpn_enabled") val isAlwaysOnVpnEnabled: Boolean = false,
|
||||||
val isAlwaysOnVpnEnabled: Boolean = false,
|
@ColumnInfo(name = "is_tunnel_on_ethernet_enabled")
|
||||||
@ColumnInfo(name = "is_tunnel_on_ethernet_enabled", defaultValue = "0")
|
|
||||||
val isTunnelOnEthernetEnabled: Boolean = false,
|
val isTunnelOnEthernetEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_shortcuts_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_shortcuts_enabled", defaultValue = "false")
|
||||||
val isShortcutsEnabled: Boolean = false,
|
val isShortcutsEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_tunnel_on_wifi_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_tunnel_on_wifi_enabled", defaultValue = "false")
|
||||||
val isTunnelOnWifiEnabled: Boolean = false,
|
val isTunnelOnWifiEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_restore_on_boot_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_kernel_enabled", defaultValue = "false")
|
||||||
|
val isKernelEnabled: Boolean = false,
|
||||||
|
@ColumnInfo(name = "is_restore_on_boot_enabled", defaultValue = "false")
|
||||||
val isRestoreOnBootEnabled: Boolean = false,
|
val isRestoreOnBootEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_multi_tunnel_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_multi_tunnel_enabled", defaultValue = "false")
|
||||||
val isMultiTunnelEnabled: Boolean = false,
|
val isMultiTunnelEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_ping_enabled", defaultValue = "0") val isPingEnabled: Boolean = false,
|
@ColumnInfo(name = "is_ping_enabled", defaultValue = "false")
|
||||||
@ColumnInfo(name = "is_wildcards_enabled", defaultValue = "0")
|
val isPingEnabled: Boolean = false,
|
||||||
|
@ColumnInfo(name = "is_amnezia_enabled", defaultValue = "false")
|
||||||
|
val isAmneziaEnabled: Boolean = false,
|
||||||
|
@ColumnInfo(name = "is_wildcards_enabled", defaultValue = "false")
|
||||||
val isWildcardsEnabled: Boolean = false,
|
val isWildcardsEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_stop_on_no_internet_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_stop_on_no_internet_enabled", defaultValue = "false")
|
||||||
val isStopOnNoInternetEnabled: Boolean = false,
|
val isStopOnNoInternetEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_lan_on_kill_switch_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_vpn_kill_switch_enabled", defaultValue = "false")
|
||||||
|
val isVpnKillSwitchEnabled: Boolean = false,
|
||||||
|
@ColumnInfo(name = "is_kernel_kill_switch_enabled", defaultValue = "false")
|
||||||
|
val isKernelKillSwitchEnabled: Boolean = false,
|
||||||
|
@ColumnInfo(name = "is_lan_on_kill_switch_enabled", defaultValue = "false")
|
||||||
val isLanOnKillSwitchEnabled: Boolean = false,
|
val isLanOnKillSwitchEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "debounce_delay_seconds", defaultValue = "3")
|
@ColumnInfo(name = "debounce_delay_seconds", defaultValue = "3")
|
||||||
val debounceDelaySeconds: Int = 3,
|
val debounceDelaySeconds: Int = 3,
|
||||||
@ColumnInfo(name = "is_disable_kill_switch_on_trusted_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_disable_kill_switch_on_trusted_enabled", defaultValue = "false")
|
||||||
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "is_tunnel_on_unsecure_enabled", defaultValue = "0")
|
@ColumnInfo(name = "is_tunnel_on_unsecure_enabled", defaultValue = "false")
|
||||||
val isTunnelOnUnsecureEnabled: Boolean = false,
|
val isTunnelOnUnsecureEnabled: Boolean = false,
|
||||||
|
@ColumnInfo(name = "split_tunnel_apps", defaultValue = "")
|
||||||
|
val splitTunnelApps: MutableList<String> = mutableListOf(),
|
||||||
@ColumnInfo(name = "wifi_detection_method", defaultValue = "0")
|
@ColumnInfo(name = "wifi_detection_method", defaultValue = "0")
|
||||||
val wifiDetectionMethod: WifiDetectionMethod = WifiDetectionMethod.fromValue(0),
|
val wifiDetectionMethod: WifiDetectionMethod = WifiDetectionMethod.fromValue(0),
|
||||||
@ColumnInfo(name = "is_ping_monitoring_enabled", defaultValue = "1")
|
) {
|
||||||
val isPingMonitoringEnabled: Boolean = true,
|
|
||||||
@ColumnInfo(name = "tunnel_ping_interval_sec", defaultValue = "30")
|
enum class WifiDetectionMethod(val value: Int) {
|
||||||
val tunnelPingIntervalSeconds: Int = 30,
|
DEFAULT(0),
|
||||||
@ColumnInfo(name = "tunnel_ping_attempts", defaultValue = "3") val tunnelPingAttempts: Int = 3,
|
LEGACY(1),
|
||||||
@ColumnInfo(name = "tunnel_ping_timeout_sec") val tunnelPingTimeoutSeconds: Int? = null,
|
ROOT(2),
|
||||||
@ColumnInfo(name = "app_mode", defaultValue = "0") val appMode: AppMode = AppMode.fromValue(0),
|
SHIZUKU(3);
|
||||||
@ColumnInfo(name = "dns_protocol", defaultValue = "0")
|
|
||||||
val dnsProtocol: DnsProtocol = DnsProtocol.fromValue(0),
|
companion object {
|
||||||
@ColumnInfo(name = "dns_endpoint") val dnsEndpoint: String? = null,
|
fun fromValue(value: Int): WifiDetectionMethod =
|
||||||
)
|
entries.find { it.value == value } ?: DEFAULT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,23 +11,22 @@ data class TunnelConfig(
|
|||||||
@ColumnInfo(name = "name") val name: String,
|
@ColumnInfo(name = "name") val name: String,
|
||||||
@ColumnInfo(name = "wg_quick") val wgQuick: String,
|
@ColumnInfo(name = "wg_quick") val wgQuick: String,
|
||||||
@ColumnInfo(name = "tunnel_networks", defaultValue = "")
|
@ColumnInfo(name = "tunnel_networks", defaultValue = "")
|
||||||
val tunnelNetworks: Set<String> = setOf(),
|
val tunnelNetworks: MutableList<String> = mutableListOf(),
|
||||||
@ColumnInfo(name = "is_mobile_data_tunnel", defaultValue = "false")
|
@ColumnInfo(name = "is_mobile_data_tunnel", defaultValue = "false")
|
||||||
val isMobileDataTunnel: Boolean = false,
|
val isMobileDataTunnel: Boolean = false,
|
||||||
@ColumnInfo(name = "is_primary_tunnel", defaultValue = "false")
|
@ColumnInfo(name = "is_primary_tunnel", defaultValue = "false")
|
||||||
val isPrimaryTunnel: Boolean = false,
|
val isPrimaryTunnel: Boolean = false,
|
||||||
@ColumnInfo(name = "am_quick", defaultValue = "") val amQuick: String = AM_QUICK_DEFAULT,
|
@ColumnInfo(name = "am_quick", defaultValue = "") val amQuick: String = AM_QUICK_DEFAULT,
|
||||||
@ColumnInfo(name = "is_Active", defaultValue = "false") val isActive: Boolean = false,
|
@ColumnInfo(name = "is_Active", defaultValue = "false") val isActive: Boolean = false,
|
||||||
@ColumnInfo(name = "restart_on_ping_failure", defaultValue = "false")
|
@ColumnInfo(name = "is_ping_enabled", defaultValue = "false")
|
||||||
val restartOnPingFailure: Boolean = false,
|
val isPingEnabled: Boolean = false,
|
||||||
@ColumnInfo(name = "ping_target", defaultValue = "null") var pingTarget: String? = null,
|
@ColumnInfo(name = "ping_interval", defaultValue = "null") val pingInterval: Long? = null,
|
||||||
|
@ColumnInfo(name = "ping_cooldown", defaultValue = "null") val pingCooldown: Long? = null,
|
||||||
|
@ColumnInfo(name = "ping_ip", defaultValue = "null") var pingIp: String? = null,
|
||||||
@ColumnInfo(name = "is_ethernet_tunnel", defaultValue = "false")
|
@ColumnInfo(name = "is_ethernet_tunnel", defaultValue = "false")
|
||||||
val isEthernetTunnel: Boolean = false,
|
var isEthernetTunnel: Boolean = false,
|
||||||
@ColumnInfo(name = "is_ipv4_preferred", defaultValue = "true")
|
@ColumnInfo(name = "is_ipv4_preferred", defaultValue = "true")
|
||||||
val isIpv4Preferred: Boolean = true,
|
var isIpv4Preferred: Boolean = true,
|
||||||
@ColumnInfo(name = "position", defaultValue = "0") val position: Int = 0,
|
|
||||||
@ColumnInfo(name = "auto_tunnel_apps", defaultValue = "[]")
|
|
||||||
val autoTunnelApps: Set<String> = setOf(),
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
-2
@@ -13,7 +13,6 @@ object GeneralStateMapper {
|
|||||||
expandedTunnelIds,
|
expandedTunnelIds,
|
||||||
isLocalLogsEnabled,
|
isLocalLogsEnabled,
|
||||||
isRemoteControlEnabled,
|
isRemoteControlEnabled,
|
||||||
showDetailedPingStats,
|
|
||||||
remoteKey,
|
remoteKey,
|
||||||
locale,
|
locale,
|
||||||
theme,
|
theme,
|
||||||
@@ -29,7 +28,6 @@ object GeneralStateMapper {
|
|||||||
expandedTunnelIds,
|
expandedTunnelIds,
|
||||||
isLocalLogsEnabled,
|
isLocalLogsEnabled,
|
||||||
isRemoteControlEnabled,
|
isRemoteControlEnabled,
|
||||||
showDetailedPingStats,
|
|
||||||
remoteKey,
|
remoteKey,
|
||||||
locale,
|
locale,
|
||||||
theme,
|
theme,
|
||||||
|
|||||||
+1
@@ -2,6 +2,7 @@ package com.zaneschepke.wireguardautotunnel.data.mapper
|
|||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.GitHubRelease
|
import com.zaneschepke.wireguardautotunnel.data.entity.GitHubRelease
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppUpdate
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppUpdate
|
||||||
|
import kotlin.collections.firstOrNull
|
||||||
|
|
||||||
object GitHubReleaseMapper {
|
object GitHubReleaseMapper {
|
||||||
fun toAppUpdate(gitHubRelease: GitHubRelease, newVersion: String): AppUpdate {
|
fun toAppUpdate(gitHubRelease: GitHubRelease, newVersion: String): AppUpdate {
|
||||||
|
|||||||
-32
@@ -1,32 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.mapper
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.ProxySettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppProxySettings
|
|
||||||
|
|
||||||
object ProxySettingsMapper {
|
|
||||||
fun to(proxySettings: ProxySettings): AppProxySettings =
|
|
||||||
with(proxySettings) {
|
|
||||||
AppProxySettings(
|
|
||||||
id,
|
|
||||||
socks5ProxyEnabled,
|
|
||||||
socks5ProxyBindAddress,
|
|
||||||
httpProxyEnabled,
|
|
||||||
httpProxyBindAddress,
|
|
||||||
proxyUsername,
|
|
||||||
proxyPassword,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun to(proxySettings: AppProxySettings): ProxySettings =
|
|
||||||
with(proxySettings) {
|
|
||||||
ProxySettings(
|
|
||||||
id,
|
|
||||||
socks5ProxyEnabled,
|
|
||||||
socks5ProxyBindAddress,
|
|
||||||
httpProxyEnabled,
|
|
||||||
httpProxyBindAddress,
|
|
||||||
proxyUsername,
|
|
||||||
proxyPassword,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+61
-71
@@ -1,77 +1,67 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.mapper
|
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||||
|
|
||||||
|
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsSettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.WifiDetectionMethod
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
|
||||||
|
|
||||||
fun Settings.toAppSettings(): GeneralSettings {
|
object SettingsMapper {
|
||||||
return GeneralSettings(
|
fun toAppSettings(settings: Settings): AppSettings {
|
||||||
id = id,
|
return AppSettings(
|
||||||
isAutoTunnelEnabled = isAutoTunnelEnabled,
|
id = settings.id,
|
||||||
isTunnelOnMobileDataEnabled = isTunnelOnMobileDataEnabled,
|
isAutoTunnelEnabled = settings.isAutoTunnelEnabled,
|
||||||
trustedNetworkSSIDs = trustedNetworkSSIDs,
|
isTunnelOnMobileDataEnabled = settings.isTunnelOnMobileDataEnabled,
|
||||||
isAlwaysOnVpnEnabled = isAlwaysOnVpnEnabled,
|
trustedNetworkSSIDs = settings.trustedNetworkSSIDs,
|
||||||
isTunnelOnEthernetEnabled = isTunnelOnEthernetEnabled,
|
isAlwaysOnVpnEnabled = settings.isAlwaysOnVpnEnabled,
|
||||||
isShortcutsEnabled = isShortcutsEnabled,
|
isTunnelOnEthernetEnabled = settings.isTunnelOnEthernetEnabled,
|
||||||
isTunnelOnWifiEnabled = isTunnelOnWifiEnabled,
|
isShortcutsEnabled = settings.isShortcutsEnabled,
|
||||||
isRestoreOnBootEnabled = isRestoreOnBootEnabled,
|
isTunnelOnWifiEnabled = settings.isTunnelOnWifiEnabled,
|
||||||
isMultiTunnelEnabled = isMultiTunnelEnabled,
|
isKernelEnabled = settings.isKernelEnabled,
|
||||||
isPingEnabled = isPingEnabled,
|
isRestoreOnBootEnabled = settings.isRestoreOnBootEnabled,
|
||||||
isWildcardsEnabled = isWildcardsEnabled,
|
isMultiTunnelEnabled = settings.isMultiTunnelEnabled,
|
||||||
isStopOnNoInternetEnabled = isStopOnNoInternetEnabled,
|
isPingEnabled = settings.isPingEnabled,
|
||||||
isLanOnKillSwitchEnabled = isLanOnKillSwitchEnabled,
|
isAmneziaEnabled = settings.isAmneziaEnabled,
|
||||||
debounceDelaySeconds = debounceDelaySeconds,
|
isWildcardsEnabled = settings.isWildcardsEnabled,
|
||||||
isDisableKillSwitchOnTrustedEnabled = isDisableKillSwitchOnTrustedEnabled,
|
isStopOnNoInternetEnabled = settings.isStopOnNoInternetEnabled,
|
||||||
isTunnelOnUnsecureEnabled = isTunnelOnUnsecureEnabled,
|
isVpnKillSwitchEnabled = settings.isVpnKillSwitchEnabled,
|
||||||
wifiDetectionMethod = WifiDetectionMethod.fromValue(wifiDetectionMethod.value),
|
isKernelKillSwitchEnabled = settings.isKernelKillSwitchEnabled,
|
||||||
tunnelPingIntervalSeconds = tunnelPingIntervalSeconds,
|
isLanOnKillSwitchEnabled = settings.isLanOnKillSwitchEnabled,
|
||||||
tunnelPingAttempts = tunnelPingAttempts,
|
debounceDelaySeconds = settings.debounceDelaySeconds,
|
||||||
tunnelPingTimeoutSeconds = tunnelPingTimeoutSeconds,
|
isDisableKillSwitchOnTrustedEnabled = settings.isDisableKillSwitchOnTrustedEnabled,
|
||||||
appMode = appMode,
|
isTunnelOnUnsecureEnabled = settings.isTunnelOnUnsecureEnabled,
|
||||||
dnsProtocol = dnsProtocol,
|
splitTunnelApps = settings.splitTunnelApps,
|
||||||
dnsEndpoint = dnsEndpoint,
|
wifiDetectionMethod =
|
||||||
)
|
AndroidNetworkMonitor.WifiDetectionMethod.fromValue(
|
||||||
}
|
settings.wifiDetectionMethod.value
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun GeneralSettings.toSettings(): Settings {
|
fun toSettings(appSettings: AppSettings): Settings {
|
||||||
return Settings(
|
return Settings(
|
||||||
id = id,
|
id = appSettings.id,
|
||||||
isAutoTunnelEnabled = isAutoTunnelEnabled,
|
isAutoTunnelEnabled = appSettings.isAutoTunnelEnabled,
|
||||||
isTunnelOnMobileDataEnabled = isTunnelOnMobileDataEnabled,
|
isTunnelOnMobileDataEnabled = appSettings.isTunnelOnMobileDataEnabled,
|
||||||
trustedNetworkSSIDs = trustedNetworkSSIDs,
|
trustedNetworkSSIDs = appSettings.trustedNetworkSSIDs.toMutableList(),
|
||||||
isAlwaysOnVpnEnabled = isAlwaysOnVpnEnabled,
|
isAlwaysOnVpnEnabled = appSettings.isAlwaysOnVpnEnabled,
|
||||||
isTunnelOnEthernetEnabled = isTunnelOnEthernetEnabled,
|
isTunnelOnEthernetEnabled = appSettings.isTunnelOnEthernetEnabled,
|
||||||
isShortcutsEnabled = isShortcutsEnabled,
|
isShortcutsEnabled = appSettings.isShortcutsEnabled,
|
||||||
isTunnelOnWifiEnabled = isTunnelOnWifiEnabled,
|
isTunnelOnWifiEnabled = appSettings.isTunnelOnWifiEnabled,
|
||||||
isRestoreOnBootEnabled = isRestoreOnBootEnabled,
|
isKernelEnabled = appSettings.isKernelEnabled,
|
||||||
isMultiTunnelEnabled = isMultiTunnelEnabled,
|
isRestoreOnBootEnabled = appSettings.isRestoreOnBootEnabled,
|
||||||
isPingEnabled = isPingEnabled,
|
isMultiTunnelEnabled = appSettings.isMultiTunnelEnabled,
|
||||||
isWildcardsEnabled = isWildcardsEnabled,
|
isPingEnabled = appSettings.isPingEnabled,
|
||||||
isStopOnNoInternetEnabled = isStopOnNoInternetEnabled,
|
isAmneziaEnabled = appSettings.isAmneziaEnabled,
|
||||||
isLanOnKillSwitchEnabled = isLanOnKillSwitchEnabled,
|
isWildcardsEnabled = appSettings.isWildcardsEnabled,
|
||||||
debounceDelaySeconds = debounceDelaySeconds,
|
isStopOnNoInternetEnabled = appSettings.isStopOnNoInternetEnabled,
|
||||||
isDisableKillSwitchOnTrustedEnabled = isDisableKillSwitchOnTrustedEnabled,
|
isVpnKillSwitchEnabled = appSettings.isVpnKillSwitchEnabled,
|
||||||
isTunnelOnUnsecureEnabled = isTunnelOnUnsecureEnabled,
|
isKernelKillSwitchEnabled = appSettings.isKernelKillSwitchEnabled,
|
||||||
wifiDetectionMethod = WifiDetectionMethod.fromValue(wifiDetectionMethod.value),
|
isLanOnKillSwitchEnabled = appSettings.isLanOnKillSwitchEnabled,
|
||||||
tunnelPingIntervalSeconds = tunnelPingIntervalSeconds,
|
debounceDelaySeconds = appSettings.debounceDelaySeconds,
|
||||||
tunnelPingAttempts = tunnelPingAttempts,
|
isDisableKillSwitchOnTrustedEnabled = appSettings.isDisableKillSwitchOnTrustedEnabled,
|
||||||
tunnelPingTimeoutSeconds = tunnelPingTimeoutSeconds,
|
isTunnelOnUnsecureEnabled = appSettings.isTunnelOnUnsecureEnabled,
|
||||||
appMode = appMode,
|
splitTunnelApps = appSettings.splitTunnelApps.toMutableList(),
|
||||||
dnsProtocol = dnsProtocol,
|
wifiDetectionMethod =
|
||||||
dnsEndpoint = dnsEndpoint,
|
Settings.WifiDetectionMethod.fromValue(appSettings.wifiDetectionMethod.value),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun GeneralSettings.toDomain(): DnsSettings {
|
|
||||||
return DnsSettings(
|
|
||||||
protocol =
|
|
||||||
DnsProtocol.entries.toTypedArray().getOrElse(dnsProtocol.value) { DnsProtocol.SYSTEM },
|
|
||||||
endpoint = dnsEndpoint,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun DnsSettings.toAppSettings(existing: GeneralSettings): GeneralSettings {
|
|
||||||
return existing.copy(dnsProtocol = protocol, dnsEndpoint = endpoint)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-7
@@ -15,11 +15,12 @@ object TunnelConfigMapper {
|
|||||||
isPrimaryTunnel,
|
isPrimaryTunnel,
|
||||||
amQuick,
|
amQuick,
|
||||||
isActive,
|
isActive,
|
||||||
pingTarget,
|
isPingEnabled,
|
||||||
restartOnPingFailure,
|
pingInterval,
|
||||||
|
pingCooldown,
|
||||||
|
pingIp,
|
||||||
isEthernetTunnel,
|
isEthernetTunnel,
|
||||||
isIpv4Preferred,
|
isIpv4Preferred,
|
||||||
position,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,16 +31,17 @@ object TunnelConfigMapper {
|
|||||||
id,
|
id,
|
||||||
tunName,
|
tunName,
|
||||||
wgQuick,
|
wgQuick,
|
||||||
tunnelNetworks,
|
tunnelNetworks.toMutableList(),
|
||||||
isMobileDataTunnel,
|
isMobileDataTunnel,
|
||||||
isPrimaryTunnel,
|
isPrimaryTunnel,
|
||||||
amQuick,
|
amQuick,
|
||||||
isActive,
|
isActive,
|
||||||
restartOnPingFailure,
|
isPingEnabled,
|
||||||
pingTarget,
|
pingInterval,
|
||||||
|
pingCooldown,
|
||||||
|
pingIp,
|
||||||
isEthernetTunnel,
|
isEthernetTunnel,
|
||||||
isIpv4Preferred,
|
isIpv4Preferred,
|
||||||
position,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.model
|
|
||||||
|
|
||||||
enum class AppMode(val value: Int) {
|
|
||||||
VPN(0),
|
|
||||||
PROXY(1),
|
|
||||||
LOCK_DOWN(2),
|
|
||||||
KERNEL(3);
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun fromValue(value: Int): AppMode = entries.find { it.value == value } ?: VPN
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.model
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
|
|
||||||
enum class DnsProtocol(val value: Int) {
|
|
||||||
SYSTEM(0),
|
|
||||||
DOH(1);
|
|
||||||
|
|
||||||
fun asString(context: Context): String {
|
|
||||||
return when (this) {
|
|
||||||
SYSTEM -> context.getString(R.string.system)
|
|
||||||
DOH -> context.getString(R.string.doh)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun fromValue(value: Int): DnsProtocol =
|
|
||||||
DnsProtocol.entries.find { it.value == value } ?: SYSTEM
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class DnsSettings(
|
|
||||||
val protocol: DnsProtocol = DnsProtocol.SYSTEM,
|
|
||||||
val endpoint: String? = null,
|
|
||||||
)
|
|
||||||
|
|
||||||
enum class DnsProvider(private val systemAddress: String, private val dohAddress: String) {
|
|
||||||
CLOUDFLARE("1.1.1.1", "https://1.1.1.1/dns-query"),
|
|
||||||
ADGUARD("94.140.14.14", "https://94.140.14.14/dns-query");
|
|
||||||
|
|
||||||
fun asAddress(protocol: DnsProtocol): String {
|
|
||||||
return when (protocol) {
|
|
||||||
DnsProtocol.SYSTEM -> systemAddress
|
|
||||||
DnsProtocol.DOH -> dohAddress
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun fromAddress(address: String): DnsProvider {
|
|
||||||
return entries.find { it.systemAddress == address || it.dohAddress == address }
|
|
||||||
?: CLOUDFLARE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.model
|
|
||||||
|
|
||||||
enum class WifiDetectionMethod(val value: Int) {
|
|
||||||
DEFAULT(0),
|
|
||||||
LEGACY(1),
|
|
||||||
ROOT(2),
|
|
||||||
SHIZUKU(3);
|
|
||||||
|
|
||||||
fun needsLocationPermissions(): Boolean {
|
|
||||||
return this == LEGACY || this == DEFAULT
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun fromValue(value: Int): WifiDetectionMethod =
|
|
||||||
entries.find { it.value == value } ?: DEFAULT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.network
|
package com.zaneschepke.wireguardautotunnel.data.network
|
||||||
|
|
||||||
import io.ktor.client.*
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.engine.okhttp.*
|
import io.ktor.client.engine.okhttp.OkHttp
|
||||||
import io.ktor.client.plugins.*
|
import io.ktor.client.plugins.HttpTimeout
|
||||||
import io.ktor.client.plugins.contentnegotiation.*
|
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||||
import io.ktor.serialization.kotlinx.json.*
|
import io.ktor.serialization.kotlinx.json.json
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
object KtorClient {
|
object KtorClient {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.network
|
package com.zaneschepke.wireguardautotunnel.data.network
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.GitHubRelease
|
import com.zaneschepke.wireguardautotunnel.data.entity.GitHubRelease
|
||||||
import io.ktor.client.*
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.call.*
|
import io.ktor.client.call.body
|
||||||
import io.ktor.client.plugins.*
|
import io.ktor.client.plugins.ClientRequestException
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.get
|
||||||
import io.ktor.http.*
|
import io.ktor.http.HttpStatusCode
|
||||||
|
|
||||||
class KtorGitHubApi(private val client: HttpClient) : GitHubApi {
|
class KtorGitHubApi(private val client: HttpClient) : GitHubApi {
|
||||||
override suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease> {
|
override suspend fun getLatestRelease(owner: String, repo: String): Result<GitHubRelease> {
|
||||||
|
|||||||
+5
-3
@@ -1,16 +1,18 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.*
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class AppDataRoomRepository
|
class AppDataRoomRepository
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
override val settings: GeneralSettingRepository,
|
override val settings: AppSettingRepository,
|
||||||
override val tunnels: TunnelRepository,
|
override val tunnels: TunnelRepository,
|
||||||
override val appState: AppStateRepository,
|
override val appState: AppStateRepository,
|
||||||
override val proxySettings: ProxySettingsRepository,
|
|
||||||
) : AppDataRepository {
|
) : AppDataRepository {
|
||||||
|
|
||||||
override suspend fun getPrimaryOrFirstTunnel(): TunnelConf? {
|
override suspend fun getPrimaryOrFirstTunnel(): TunnelConf? {
|
||||||
|
|||||||
+2
-29
@@ -3,25 +3,15 @@ package com.zaneschepke.wireguardautotunnel.data.repository
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralState
|
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralState
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.GeneralStateMapper
|
import com.zaneschepke.wireguardautotunnel.data.mapper.GeneralStateMapper
|
||||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppState
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.stateIn
|
|
||||||
import kotlinx.coroutines.plus
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class DataStoreAppStateRepository(
|
class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager) :
|
||||||
private val dataStoreManager: DataStoreManager,
|
AppStateRepository {
|
||||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : AppStateRepository {
|
|
||||||
override suspend fun isLocationDisclosureShown(): Boolean {
|
override suspend fun isLocationDisclosureShown(): Boolean {
|
||||||
return dataStoreManager.getFromStore(DataStoreManager.locationDisclosureShown)
|
return dataStoreManager.getFromStore(DataStoreManager.locationDisclosureShown)
|
||||||
?: GeneralState.LOCATION_DISCLOSURE_SHOWN_DEFAULT
|
?: GeneralState.LOCATION_DISCLOSURE_SHOWN_DEFAULT
|
||||||
@@ -129,15 +119,6 @@ class DataStoreAppStateRepository(
|
|||||||
return dataStoreManager.getFromStore(DataStoreManager.remoteKey)
|
return dataStoreManager.getFromStore(DataStoreManager.remoteKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setShowDetailedPingStats(showDetailedPing: Boolean) {
|
|
||||||
dataStoreManager.saveToDataStore(DataStoreManager.showDetailedPingStats, showDetailedPing)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getShowDetailedPing(): Boolean {
|
|
||||||
return dataStoreManager.getFromStore(DataStoreManager.showDetailedPingStats)
|
|
||||||
?: GeneralState.SHOW_DETAILED_PING_STATS_DEFAULT
|
|
||||||
}
|
|
||||||
|
|
||||||
override val flow: Flow<AppState> =
|
override val flow: Flow<AppState> =
|
||||||
dataStoreManager.preferencesFlow
|
dataStoreManager.preferencesFlow
|
||||||
.map { prefs ->
|
.map { prefs ->
|
||||||
@@ -163,9 +144,6 @@ class DataStoreAppStateRepository(
|
|||||||
isRemoteControlEnabled =
|
isRemoteControlEnabled =
|
||||||
pref[DataStoreManager.isRemoteControlEnabled]
|
pref[DataStoreManager.isRemoteControlEnabled]
|
||||||
?: GeneralState.IS_REMOTE_CONTROL_ENABLED,
|
?: GeneralState.IS_REMOTE_CONTROL_ENABLED,
|
||||||
showDetailedPingStats =
|
|
||||||
pref[DataStoreManager.showDetailedPingStats]
|
|
||||||
?: GeneralState.SHOW_DETAILED_PING_STATS_DEFAULT,
|
|
||||||
remoteKey = pref[DataStoreManager.remoteKey],
|
remoteKey = pref[DataStoreManager.remoteKey],
|
||||||
locale = pref[DataStoreManager.locale],
|
locale = pref[DataStoreManager.locale],
|
||||||
theme = getTheme(),
|
theme = getTheme(),
|
||||||
@@ -177,9 +155,4 @@ class DataStoreAppStateRepository(
|
|||||||
} ?: GeneralState()
|
} ?: GeneralState()
|
||||||
}
|
}
|
||||||
.map(GeneralStateMapper::toAppState)
|
.map(GeneralStateMapper::toAppState)
|
||||||
.stateIn(
|
|
||||||
scope = applicationScope + ioDispatcher,
|
|
||||||
started = SharingStarted.Eagerly,
|
|
||||||
initialValue = AppState(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-12
@@ -9,11 +9,13 @@ 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
|
||||||
@@ -38,13 +40,13 @@ 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 apkAsset =
|
||||||
release.assets.find { asset ->
|
release.assets.find { asset ->
|
||||||
asset.name.startsWith("wgtunnel-${Constants.STANDALONE_FLAVOR}-v") &&
|
asset.name.startsWith("wgtunnel-${Constants.STANDALONE_FLAVOR}-v") &&
|
||||||
asset.name.endsWith(".apk")
|
asset.name.endsWith(".apk")
|
||||||
}
|
}
|
||||||
val newVersion =
|
val newVersion =
|
||||||
standaloneApkAsset
|
apkAsset
|
||||||
?.name
|
?.name
|
||||||
?.removePrefix("wgtunnel-${Constants.STANDALONE_FLAVOR}-v")
|
?.removePrefix("wgtunnel-${Constants.STANDALONE_FLAVOR}-v")
|
||||||
?.removeSuffix(".apk") ?: return@map null
|
?.removeSuffix(".apk") ?: return@map null
|
||||||
@@ -53,10 +55,7 @@ class GitHubUpdateRepository(
|
|||||||
if (isNightly && newVersion != currentVersion)
|
if (isNightly && newVersion != currentVersion)
|
||||||
return@map GitHubReleaseMapper.toAppUpdate(release, newVersion)
|
return@map GitHubReleaseMapper.toAppUpdate(release, newVersion)
|
||||||
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
||||||
GitHubReleaseMapper.toAppUpdate(
|
GitHubReleaseMapper.toAppUpdate(release, newVersion)
|
||||||
release.copy(assets = listOf(standaloneApkAsset)),
|
|
||||||
newVersion,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@@ -66,7 +65,7 @@ class GitHubUpdateRepository(
|
|||||||
override suspend fun downloadApk(
|
override suspend fun downloadApk(
|
||||||
apkUrl: String,
|
apkUrl: String,
|
||||||
fileName: String,
|
fileName: String,
|
||||||
onProgress: suspend (Float) -> Unit,
|
onProgress: (Float) -> Unit,
|
||||||
): Result<File> =
|
): Result<File> =
|
||||||
withContext(ioDispatcher) {
|
withContext(ioDispatcher) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
-92
@@ -1,92 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.IntentFilter
|
|
||||||
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.repository.InstalledPackageRepository
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.getAllInternetCapablePackages
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.getFriendlyAppName
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
class InstalledAndroidPackageRepository(
|
|
||||||
private val context: Context,
|
|
||||||
@ApplicationScope val applicationScope: CoroutineScope,
|
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : InstalledPackageRepository {
|
|
||||||
|
|
||||||
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> =
|
|
||||||
withContext(ioDispatcher) {
|
|
||||||
cachedPackages?.let {
|
|
||||||
return@withContext it
|
|
||||||
}
|
|
||||||
refreshInstalledPackages()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun refreshInstalledPackages(): List<InstalledPackage> =
|
|
||||||
withContext(ioDispatcher) {
|
|
||||||
val packages = context.getAllInternetCapablePackages()
|
|
||||||
|
|
||||||
val installedPackages =
|
|
||||||
packages.mapNotNull { packageInfo ->
|
|
||||||
try {
|
|
||||||
val appInfo =
|
|
||||||
context.packageManager.getApplicationInfo(packageInfo.packageName, 0)
|
|
||||||
InstalledPackage(
|
|
||||||
name =
|
|
||||||
context.packageManager.getFriendlyAppName(
|
|
||||||
packageInfo.packageName,
|
|
||||||
appInfo,
|
|
||||||
),
|
|
||||||
packageName = packageInfo.packageName,
|
|
||||||
uId = appInfo.uid,
|
|
||||||
)
|
|
||||||
} catch (e: PackageManager.NameNotFoundException) {
|
|
||||||
Timber.e(e)
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cachedPackages = installedPackages
|
|
||||||
|
|
||||||
installedPackages
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.ProxySettingsDao
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.ProxySettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.ProxySettingsMapper
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppProxySettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.ProxySettingsRepository
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
class RoomProxySettingsRepository(
|
|
||||||
private val proxySettingsDao: ProxySettingsDao,
|
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
|
||||||
) : ProxySettingsRepository {
|
|
||||||
override suspend fun save(proxySettings: AppProxySettings) {
|
|
||||||
withContext(ioDispatcher) { proxySettingsDao.save(ProxySettingsMapper.to(proxySettings)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override val flow =
|
|
||||||
proxySettingsDao.getSettingsFlow().flowOn(ioDispatcher).map(ProxySettingsMapper::to)
|
|
||||||
|
|
||||||
override suspend fun get(): AppProxySettings {
|
|
||||||
return withContext(ioDispatcher) {
|
|
||||||
ProxySettingsMapper.to(proxySettingsDao.getAll().firstOrNull() ?: ProxySettings())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+9
-10
@@ -2,11 +2,10 @@ package com.zaneschepke.wireguardautotunnel.data.repository
|
|||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toAppSettings
|
import com.zaneschepke.wireguardautotunnel.data.mapper.SettingsMapper
|
||||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toSettings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
@@ -15,18 +14,18 @@ import kotlinx.coroutines.withContext
|
|||||||
class RoomSettingsRepository(
|
class RoomSettingsRepository(
|
||||||
private val settingsDoa: SettingsDao,
|
private val settingsDoa: SettingsDao,
|
||||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : GeneralSettingRepository {
|
) : AppSettingRepository {
|
||||||
|
|
||||||
override suspend fun save(generalSettings: GeneralSettings) {
|
override suspend fun save(appSettings: AppSettings) {
|
||||||
withContext(ioDispatcher) { settingsDoa.save(generalSettings.toSettings()) }
|
withContext(ioDispatcher) { settingsDoa.save(SettingsMapper.toSettings(appSettings)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override val flow =
|
override val flow =
|
||||||
settingsDoa.getSettingsFlow().flowOn(ioDispatcher).map { it.toAppSettings() }
|
settingsDoa.getSettingsFlow().flowOn(ioDispatcher).map(SettingsMapper::toAppSettings)
|
||||||
|
|
||||||
override suspend fun get(): GeneralSettings {
|
override suspend fun get(): AppSettings {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
(settingsDoa.getAll().firstOrNull() ?: Settings()).toAppSettings()
|
SettingsMapper.toAppSettings(settingsDoa.getAll().firstOrNull() ?: Settings())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-6
@@ -105,10 +105,4 @@ class RoomTunnelRepository(
|
|||||||
tunnelConfigDao.findByPrimary().map(TunnelConfigMapper::toTunnelConf)
|
tunnelConfigDao.findByPrimary().map(TunnelConfigMapper::toTunnelConf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun delete(tunnels: List<TunnelConf>) {
|
|
||||||
withContext(ioDispatcher) {
|
|
||||||
tunnelConfigDao.delete(tunnels.map { TunnelConfigMapper.toTunnelConfig(it) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,9 @@ import android.content.Context
|
|||||||
import com.zaneschepke.logcatter.LogReader
|
import com.zaneschepke.logcatter.LogReader
|
||||||
import com.zaneschepke.logcatter.LogcatReader
|
import com.zaneschepke.logcatter.LogcatReader
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationMonitor
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
import com.zaneschepke.wireguardautotunnel.core.notification.WireGuardNotification
|
||||||
import com.zaneschepke.wireguardautotunnel.core.shortcut.DynamicShortcutManager
|
import com.zaneschepke.wireguardautotunnel.core.shortcut.DynamicShortcutManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.shortcut.ShortcutManager
|
import com.zaneschepke.wireguardautotunnel.core.shortcut.ShortcutManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
@@ -23,7 +20,6 @@ import kotlinx.coroutines.SupervisorJob
|
|||||||
@Module
|
@Module
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
class AppModule {
|
class AppModule {
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@ApplicationScope
|
@ApplicationScope
|
||||||
@Provides
|
@Provides
|
||||||
@@ -51,19 +47,4 @@ class AppModule {
|
|||||||
): ShortcutManager {
|
): ShortcutManager {
|
||||||
return DynamicShortcutManager(context, ioDispatcher)
|
return DynamicShortcutManager(context, ioDispatcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideNetworkUtils(@IoDispatcher ioDispatcher: CoroutineDispatcher): NetworkUtils {
|
|
||||||
return NetworkUtils(ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideNotificationMonitor(
|
|
||||||
tunnelManager: TunnelManager,
|
|
||||||
notificationManager: NotificationManager,
|
|
||||||
): NotificationMonitor {
|
|
||||||
return NotificationMonitor(tunnelManager, notificationManager)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,3 @@ import javax.inject.Qualifier
|
|||||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class Kernel
|
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class Kernel
|
||||||
|
|
||||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class Userspace
|
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class Userspace
|
||||||
|
|
||||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class ProxyUserspace
|
|
||||||
|
|||||||
@@ -6,57 +6,43 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
||||||
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
||||||
import com.zaneschepke.wireguardautotunnel.data.DatabaseCallback
|
import com.zaneschepke.wireguardautotunnel.data.DatabaseCallback
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.ProxySettingsDao
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||||
import com.zaneschepke.wireguardautotunnel.data.network.KtorClient
|
import com.zaneschepke.wireguardautotunnel.data.network.KtorClient
|
||||||
import com.zaneschepke.wireguardautotunnel.data.network.KtorGitHubApi
|
import com.zaneschepke.wireguardautotunnel.data.network.KtorGitHubApi
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.*
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRoomRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.*
|
import com.zaneschepke.wireguardautotunnel.data.repository.DataStoreAppStateRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.GitHubUpdateRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.RoomSettingsRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.repository.RoomTunnelRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.repository.UpdateRepository
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import io.ktor.client.*
|
import io.ktor.client.HttpClient
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
class RepositoryModule {
|
class RepositoryModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideGlobalEffectRepository(): GlobalEffectRepository {
|
fun provideDatabase(@ApplicationContext context: Context): AppDatabase {
|
||||||
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,
|
|
||||||
): AppDatabase {
|
|
||||||
return Room.databaseBuilder(
|
return Room.databaseBuilder(
|
||||||
context,
|
context,
|
||||||
AppDatabase::class.java,
|
AppDatabase::class.java,
|
||||||
context.getString(R.string.db_name),
|
context.getString(R.string.db_name),
|
||||||
)
|
)
|
||||||
.fallbackToDestructiveMigration(true)
|
.fallbackToDestructiveMigration(true)
|
||||||
.addCallback(callback)
|
.addCallback(DatabaseCallback())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,12 +52,6 @@ class RepositoryModule {
|
|||||||
return appDatabase.settingDao()
|
return appDatabase.settingDao()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideProxyDoa(appDatabase: AppDatabase): ProxySettingsDao {
|
|
||||||
return appDatabase.proxySettingsDoa()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
fun provideTunnelConfigDoa(appDatabase: AppDatabase): TunnelConfigDao {
|
fun provideTunnelConfigDoa(appDatabase: AppDatabase): TunnelConfigDao {
|
||||||
@@ -92,19 +72,10 @@ class RepositoryModule {
|
|||||||
fun provideSettingsRepository(
|
fun provideSettingsRepository(
|
||||||
settingsDao: SettingsDao,
|
settingsDao: SettingsDao,
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||||
): GeneralSettingRepository {
|
): AppSettingRepository {
|
||||||
return RoomSettingsRepository(settingsDao, ioDispatcher)
|
return RoomSettingsRepository(settingsDao, ioDispatcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideProxySettingsRepository(
|
|
||||||
proxySettingsDao: ProxySettingsDao,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): ProxySettingsRepository {
|
|
||||||
return RoomProxySettingsRepository(proxySettingsDao, ioDispatcher)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
fun providePreferencesDataStore(
|
fun providePreferencesDataStore(
|
||||||
@@ -116,28 +87,18 @@ class RepositoryModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideGeneralStateRepository(
|
fun provideGeneralStateRepository(dataStoreManager: DataStoreManager): AppStateRepository {
|
||||||
dataStoreManager: DataStoreManager,
|
return DataStoreAppStateRepository(dataStoreManager)
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
|
||||||
): AppStateRepository {
|
|
||||||
return DataStoreAppStateRepository(dataStoreManager, applicationScope, ioDispatcher)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideAppDataRepository(
|
fun provideAppDataRepository(
|
||||||
settingsRepository: GeneralSettingRepository,
|
settingsRepository: AppSettingRepository,
|
||||||
tunnelRepository: TunnelRepository,
|
tunnelRepository: TunnelRepository,
|
||||||
appStateRepository: AppStateRepository,
|
appStateRepository: AppStateRepository,
|
||||||
proxySettingsRepository: ProxySettingsRepository,
|
|
||||||
): AppDataRepository {
|
): AppDataRepository {
|
||||||
return AppDataRoomRepository(
|
return AppDataRoomRepository(settingsRepository, tunnelRepository, appStateRepository)
|
||||||
settingsRepository,
|
|
||||||
tunnelRepository,
|
|
||||||
appStateRepository,
|
|
||||||
proxySettingsRepository,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import android.content.Context
|
|||||||
import com.wireguard.android.backend.WgQuickBackend
|
import com.wireguard.android.backend.WgQuickBackend
|
||||||
import com.wireguard.android.util.RootShell
|
import com.wireguard.android.util.RootShell
|
||||||
import com.wireguard.android.util.ToolsInstaller
|
import com.wireguard.android.util.ToolsInstaller
|
||||||
import com.zaneschepke.logcatter.LogReader
|
|
||||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.*
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.KernelTunnel
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelProvider
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.UserspaceTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.to
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
@@ -26,7 +26,6 @@ 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.RootTunnelActionHandler
|
import org.amnezia.awg.backend.RootTunnelActionHandler
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@@ -49,21 +48,10 @@ class TunnelModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Userspace
|
|
||||||
fun provideAmneziaBackend(@ApplicationContext context: Context): Backend {
|
fun provideAmneziaBackend(@ApplicationContext context: Context): Backend {
|
||||||
return GoBackend(context, RootTunnelActionHandler(org.amnezia.awg.util.RootShell(context)))
|
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
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideKernelBackend(
|
fun provideKernelBackend(
|
||||||
@@ -98,19 +86,7 @@ class TunnelModule {
|
|||||||
@ApplicationScope applicationScope: CoroutineScope,
|
@ApplicationScope applicationScope: CoroutineScope,
|
||||||
serviceManager: ServiceManager,
|
serviceManager: ServiceManager,
|
||||||
appDataRepository: AppDataRepository,
|
appDataRepository: AppDataRepository,
|
||||||
@Userspace backend: Backend,
|
backend: Backend,
|
||||||
): TunnelProvider {
|
|
||||||
return UserspaceTunnel(applicationScope, serviceManager, appDataRepository, backend)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@ProxyUserspace
|
|
||||||
fun provideProxyUserspaceProvider(
|
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
|
||||||
serviceManager: ServiceManager,
|
|
||||||
appDataRepository: AppDataRepository,
|
|
||||||
@ProxyUserspace backend: Backend,
|
|
||||||
): TunnelProvider {
|
): TunnelProvider {
|
||||||
return UserspaceTunnel(applicationScope, serviceManager, appDataRepository, backend)
|
return UserspaceTunnel(applicationScope, serviceManager, appDataRepository, backend)
|
||||||
}
|
}
|
||||||
@@ -120,8 +96,6 @@ class TunnelModule {
|
|||||||
fun provideTunnelManager(
|
fun provideTunnelManager(
|
||||||
@Kernel kernelTunnel: TunnelProvider,
|
@Kernel kernelTunnel: TunnelProvider,
|
||||||
@Userspace userspaceTunnel: TunnelProvider,
|
@Userspace userspaceTunnel: TunnelProvider,
|
||||||
@ProxyUserspace proxyTunnel: TunnelProvider,
|
|
||||||
serviceManager: ServiceManager,
|
|
||||||
appDataRepository: AppDataRepository,
|
appDataRepository: AppDataRepository,
|
||||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
@ApplicationScope applicationScope: CoroutineScope,
|
||||||
@@ -129,8 +103,6 @@ class TunnelModule {
|
|||||||
return TunnelManager(
|
return TunnelManager(
|
||||||
kernelTunnel,
|
kernelTunnel,
|
||||||
userspaceTunnel,
|
userspaceTunnel,
|
||||||
proxyTunnel,
|
|
||||||
serviceManager,
|
|
||||||
appDataRepository,
|
appDataRepository,
|
||||||
applicationScope,
|
applicationScope,
|
||||||
ioDispatcher,
|
ioDispatcher,
|
||||||
@@ -141,7 +113,7 @@ class TunnelModule {
|
|||||||
@Singleton
|
@Singleton
|
||||||
fun provideNetworkMonitor(
|
fun provideNetworkMonitor(
|
||||||
@ApplicationContext context: Context,
|
@ApplicationContext context: Context,
|
||||||
settingsRepository: GeneralSettingRepository,
|
settingsRepository: AppSettingRepository,
|
||||||
@ApplicationScope applicationScope: CoroutineScope,
|
@ApplicationScope applicationScope: CoroutineScope,
|
||||||
@AppShell appShell: RootShell,
|
@AppShell appShell: RootShell,
|
||||||
): NetworkMonitor {
|
): NetworkMonitor {
|
||||||
@@ -152,7 +124,7 @@ class TunnelModule {
|
|||||||
get() =
|
get() =
|
||||||
settingsRepository.flow
|
settingsRepository.flow
|
||||||
.distinctUntilChangedBy { it.wifiDetectionMethod }
|
.distinctUntilChangedBy { it.wifiDetectionMethod }
|
||||||
.map { it.wifiDetectionMethod.to() }
|
.map { it.wifiDetectionMethod }
|
||||||
|
|
||||||
override val rootShell: RootShell
|
override val rootShell: RootShell
|
||||||
get() = appShell
|
get() = appShell
|
||||||
@@ -178,23 +150,4 @@ class TunnelModule {
|
|||||||
appDataRepository,
|
appDataRepository,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
fun provideTunnelMonitor(
|
|
||||||
@ApplicationContext context: Context,
|
|
||||||
tunnelManager: TunnelManager,
|
|
||||||
networkMonitor: NetworkMonitor,
|
|
||||||
networkUtils: NetworkUtils,
|
|
||||||
logReader: LogReader,
|
|
||||||
appDataRepository: AppDataRepository,
|
|
||||||
): TunnelMonitor {
|
|
||||||
return TunnelMonitor(
|
|
||||||
appDataRepository,
|
|
||||||
tunnelManager,
|
|
||||||
networkMonitor,
|
|
||||||
networkUtils,
|
|
||||||
logReader,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
|
||||||
|
sealed class BackendError : Exception() {
|
||||||
|
data object DNS : BackendError()
|
||||||
|
|
||||||
|
data object Unauthorized : BackendError()
|
||||||
|
|
||||||
|
data object Config : BackendError()
|
||||||
|
|
||||||
|
data object KernelModuleName : BackendError()
|
||||||
|
|
||||||
|
data object InvalidConfig : BackendError()
|
||||||
|
|
||||||
|
data object NotAuthorized : BackendError()
|
||||||
|
|
||||||
|
data object ServiceNotRunning : BackendError()
|
||||||
|
|
||||||
|
data object Unknown : BackendError()
|
||||||
|
|
||||||
|
fun toStringRes() =
|
||||||
|
when (this) {
|
||||||
|
Config -> R.string.config_error
|
||||||
|
DNS -> R.string.dns_resolve_error
|
||||||
|
InvalidConfig -> R.string.invalid_config_error
|
||||||
|
KernelModuleName -> R.string.kernel_name_error
|
||||||
|
NotAuthorized,
|
||||||
|
Unauthorized -> R.string.auth_error
|
||||||
|
ServiceNotRunning -> R.string.service_running_error
|
||||||
|
Unknown -> R.string.unknown_error
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
|
||||||
|
|
||||||
sealed class BackendMode {
|
|
||||||
data object Inactive : BackendMode()
|
|
||||||
|
|
||||||
data class KillSwitch(val allowedIps: Set<String>) : BackendMode()
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||||
|
|
||||||
|
enum class BackendState {
|
||||||
|
KILL_SWITCH_ACTIVE,
|
||||||
|
SERVICE_ACTIVE,
|
||||||
|
INACTIVE,
|
||||||
|
}
|
||||||
@@ -10,12 +10,10 @@ sealed class TunnelStatus {
|
|||||||
|
|
||||||
data object Starting : TunnelStatus()
|
data object Starting : TunnelStatus()
|
||||||
|
|
||||||
sealed class StopReason {
|
enum class StopReason {
|
||||||
data object User : StopReason()
|
USER,
|
||||||
|
PING,
|
||||||
data class Ping(val previouslyResolvedEndpoints: Map<String, String?>) : StopReason()
|
CONFIG_CHANGED,
|
||||||
|
|
||||||
data object ConfigChanged : StopReason()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isDown(): Boolean {
|
fun isDown(): Boolean {
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
|||||||
sealed class AutoTunnelEvent {
|
sealed class AutoTunnelEvent {
|
||||||
data class Start(val tunnelConf: TunnelConf? = null) : AutoTunnelEvent()
|
data class Start(val tunnelConf: TunnelConf? = null) : AutoTunnelEvent()
|
||||||
|
|
||||||
data class Bounce(val configsPeerKeyResolvedMap: List<Pair<TunnelConf, Map<String, String?>>>) :
|
|
||||||
AutoTunnelEvent()
|
|
||||||
|
|
||||||
data object Stop : AutoTunnelEvent()
|
data object Stop : AutoTunnelEvent()
|
||||||
|
|
||||||
data object DoNothing : AutoTunnelEvent()
|
data object DoNothing : AutoTunnelEvent()
|
||||||
|
|||||||
-48
@@ -1,48 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.events
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
|
||||||
|
|
||||||
sealed class BackendCoreException : Exception() {
|
|
||||||
data object DNS : BackendCoreException()
|
|
||||||
|
|
||||||
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 class BounceFailed(val error: BackendCoreException) : 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
|
|
||||||
is BounceFailed -> R.string.bounce_failed_template
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toStringValue(): StringValue {
|
|
||||||
return when (val backendError = this) {
|
|
||||||
is BounceFailed ->
|
|
||||||
StringValue.StringResource(
|
|
||||||
backendError.toStringRes(),
|
|
||||||
backendError.error.toStringRes(),
|
|
||||||
)
|
|
||||||
else -> StringValue.StringResource(backendError.toStringRes())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.events
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
|
||||||
|
|
||||||
sealed class BackendMessage {
|
|
||||||
|
|
||||||
data object BounceSuccess : BackendMessage()
|
|
||||||
|
|
||||||
data object BounceRecovery : BackendMessage()
|
|
||||||
|
|
||||||
fun toStringRes() =
|
|
||||||
when (this) {
|
|
||||||
BounceRecovery -> R.string.pinger_bounce_recovery
|
|
||||||
BounceSuccess -> R.string.pinger_bounce_successful
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toStringValue() = StringValue.StringResource(this.toStringRes())
|
|
||||||
}
|
|
||||||
-16
@@ -1,16 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
|
||||||
|
|
||||||
data class AppProxySettings(
|
|
||||||
val id: Long = 0,
|
|
||||||
val socks5ProxyEnabled: Boolean = false,
|
|
||||||
val socks5ProxyBindAddress: String? = null,
|
|
||||||
val httpProxyEnabled: Boolean = false,
|
|
||||||
val httpProxyBindAddress: String? = null,
|
|
||||||
val proxyUsername: String? = null,
|
|
||||||
val proxyPassword: String? = null,
|
|
||||||
) {
|
|
||||||
companion object {
|
|
||||||
const val DEFAULT_SOCKS_BIND_ADDRESS = "127.0.0.1:25344"
|
|
||||||
const val DEFAULT_HTTP_BIND_ADDRESS = "127.0.0.1:25345"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+12
-17
@@ -1,21 +1,21 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.WifiDetectionMethod
|
|
||||||
|
|
||||||
data class GeneralSettings(
|
data class AppSettings(
|
||||||
val id: Int = 0,
|
val id: Int = 0,
|
||||||
val isAutoTunnelEnabled: Boolean = false,
|
val isAutoTunnelEnabled: Boolean = false,
|
||||||
val isTunnelOnMobileDataEnabled: Boolean = false,
|
val isTunnelOnMobileDataEnabled: Boolean = false,
|
||||||
val trustedNetworkSSIDs: Set<String> = emptySet(),
|
val trustedNetworkSSIDs: List<String> = emptyList(),
|
||||||
val isAlwaysOnVpnEnabled: Boolean = false,
|
val isAlwaysOnVpnEnabled: Boolean = false,
|
||||||
val isTunnelOnEthernetEnabled: Boolean = false,
|
val isTunnelOnEthernetEnabled: Boolean = false,
|
||||||
val isShortcutsEnabled: Boolean = false,
|
val isShortcutsEnabled: Boolean = false,
|
||||||
val isTunnelOnWifiEnabled: Boolean = false,
|
val isTunnelOnWifiEnabled: Boolean = false,
|
||||||
|
val isKernelEnabled: Boolean = false,
|
||||||
val isRestoreOnBootEnabled: Boolean = false,
|
val isRestoreOnBootEnabled: Boolean = false,
|
||||||
val isMultiTunnelEnabled: Boolean = false,
|
val isMultiTunnelEnabled: Boolean = false,
|
||||||
val isPingEnabled: Boolean = false,
|
val isPingEnabled: Boolean = false,
|
||||||
|
val isAmneziaEnabled: Boolean = false,
|
||||||
val isWildcardsEnabled: Boolean = false,
|
val isWildcardsEnabled: Boolean = false,
|
||||||
val isStopOnNoInternetEnabled: Boolean = false,
|
val isStopOnNoInternetEnabled: Boolean = false,
|
||||||
val isVpnKillSwitchEnabled: Boolean = false,
|
val isVpnKillSwitchEnabled: Boolean = false,
|
||||||
@@ -24,14 +24,14 @@ data class GeneralSettings(
|
|||||||
val debounceDelaySeconds: Int = 3,
|
val debounceDelaySeconds: Int = 3,
|
||||||
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
||||||
val isTunnelOnUnsecureEnabled: Boolean = false,
|
val isTunnelOnUnsecureEnabled: Boolean = false,
|
||||||
val wifiDetectionMethod: WifiDetectionMethod = WifiDetectionMethod.DEFAULT,
|
val splitTunnelApps: List<String> = emptyList(),
|
||||||
val tunnelPingIntervalSeconds: Int = PING_INTERVAL_DEFAULT,
|
val wifiDetectionMethod: AndroidNetworkMonitor.WifiDetectionMethod =
|
||||||
val tunnelPingAttempts: Int = PING_ATTEMPTS_DEFAULT,
|
AndroidNetworkMonitor.WifiDetectionMethod.DEFAULT,
|
||||||
val tunnelPingTimeoutSeconds: Int? = null,
|
|
||||||
val appMode: AppMode = AppMode.VPN,
|
|
||||||
val dnsProtocol: DnsProtocol = DnsProtocol.SYSTEM,
|
|
||||||
val dnsEndpoint: String? = null,
|
|
||||||
) {
|
) {
|
||||||
|
fun debounceDelayMillis(): Long {
|
||||||
|
return debounceDelaySeconds * 1000L
|
||||||
|
}
|
||||||
|
|
||||||
fun toAutoTunnelStateString(): String {
|
fun toAutoTunnelStateString(): String {
|
||||||
return """
|
return """
|
||||||
TunnelOnWifi: $isTunnelOnWifiEnabled
|
TunnelOnWifi: $isTunnelOnWifiEnabled
|
||||||
@@ -43,9 +43,4 @@ data class GeneralSettings(
|
|||||||
"""
|
"""
|
||||||
.trimIndent()
|
.trimIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val PING_INTERVAL_DEFAULT = 30
|
|
||||||
const val PING_ATTEMPTS_DEFAULT = 3
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,14 +3,13 @@ package com.zaneschepke.wireguardautotunnel.domain.model
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||||
|
|
||||||
data class AppState(
|
data class AppState(
|
||||||
val isLocationDisclosureShown: Boolean = false,
|
val isLocationDisclosureShown: Boolean,
|
||||||
val isBatteryOptimizationDisableShown: Boolean = false,
|
val isBatteryOptimizationDisableShown: Boolean,
|
||||||
val isPinLockEnabled: Boolean = false,
|
val isPinLockEnabled: Boolean,
|
||||||
val expandedTunnelIds: List<Int> = emptyList(),
|
val expandedTunnelIds: List<Int>,
|
||||||
val isLocalLogsEnabled: Boolean = false,
|
val isLocalLogsEnabled: Boolean,
|
||||||
val isRemoteControlEnabled: Boolean = false,
|
val isRemoteControlEnabled: Boolean,
|
||||||
val showDetailedPingStats: Boolean = false,
|
val remoteKey: String?,
|
||||||
val remoteKey: String? = null,
|
val locale: String?,
|
||||||
val locale: String? = null,
|
val theme: Theme,
|
||||||
val theme: Theme = Theme.AUTOMATIC,
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
|
||||||
|
|
||||||
data class InstalledPackage(val name: String, val packageName: String, val uId: Int)
|
|
||||||
@@ -1,32 +1,33 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.wireguard.config.Config
|
import com.wireguard.config.Config
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
import java.net.InetAddress
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
@Parcelize
|
|
||||||
data class TunnelConf(
|
data class TunnelConf(
|
||||||
val id: Int = 0,
|
val id: Int = 0,
|
||||||
val tunName: String,
|
val tunName: String,
|
||||||
val wgQuick: String,
|
val wgQuick: String,
|
||||||
val tunnelNetworks: Set<String> = emptySet(),
|
val tunnelNetworks: List<String> = emptyList(),
|
||||||
val isMobileDataTunnel: Boolean = false,
|
val isMobileDataTunnel: Boolean = false,
|
||||||
val isPrimaryTunnel: Boolean = false,
|
val isPrimaryTunnel: Boolean = false,
|
||||||
val amQuick: String,
|
val amQuick: String,
|
||||||
val isActive: Boolean = false,
|
val isActive: Boolean = false,
|
||||||
val pingTarget: String? = null,
|
val isPingEnabled: Boolean = false,
|
||||||
val restartOnPingFailure: Boolean = false,
|
val pingInterval: Long? = null,
|
||||||
|
val pingCooldown: Long? = null,
|
||||||
|
val pingIp: String? = null,
|
||||||
val isEthernetTunnel: Boolean = false,
|
val isEthernetTunnel: Boolean = false,
|
||||||
val isIpv4Preferred: Boolean = true,
|
val isIpv4Preferred: Boolean = true,
|
||||||
val position: Int = 0,
|
|
||||||
@Transient private var stateChangeCallback: ((Any) -> Unit)? = null,
|
@Transient private var stateChangeCallback: ((Any) -> Unit)? = null,
|
||||||
) : Tunnel, org.amnezia.awg.backend.Tunnel, Parcelable {
|
) : Tunnel, org.amnezia.awg.backend.Tunnel {
|
||||||
|
|
||||||
val isNameKernelCompatible: Boolean = (name.length <= 15)
|
|
||||||
|
|
||||||
fun setStateChangeCallback(callback: (Any) -> Unit) {
|
fun setStateChangeCallback(callback: (Any) -> Unit) {
|
||||||
stateChangeCallback = callback
|
stateChangeCallback = callback
|
||||||
@@ -42,8 +43,10 @@ data class TunnelConf(
|
|||||||
isPrimaryTunnel == other.isPrimaryTunnel &&
|
isPrimaryTunnel == other.isPrimaryTunnel &&
|
||||||
isMobileDataTunnel == other.isMobileDataTunnel &&
|
isMobileDataTunnel == other.isMobileDataTunnel &&
|
||||||
isEthernetTunnel == other.isEthernetTunnel &&
|
isEthernetTunnel == other.isEthernetTunnel &&
|
||||||
pingTarget == other.pingTarget &&
|
isPingEnabled == other.isPingEnabled &&
|
||||||
restartOnPingFailure == other.restartOnPingFailure &&
|
pingIp == other.pingIp &&
|
||||||
|
pingCooldown == other.pingCooldown &&
|
||||||
|
pingInterval == other.pingInterval &&
|
||||||
tunnelNetworks == other.tunnelNetworks &&
|
tunnelNetworks == other.tunnelNetworks &&
|
||||||
isIpv4Preferred == other.isIpv4Preferred
|
isIpv4Preferred == other.isIpv4Preferred
|
||||||
}
|
}
|
||||||
@@ -64,13 +67,15 @@ data class TunnelConf(
|
|||||||
id: Int = this.id,
|
id: Int = this.id,
|
||||||
tunName: String = this.tunName,
|
tunName: String = this.tunName,
|
||||||
wgQuick: String = this.wgQuick,
|
wgQuick: String = this.wgQuick,
|
||||||
tunnelNetworks: Set<String> = this.tunnelNetworks,
|
tunnelNetworks: List<String> = this.tunnelNetworks,
|
||||||
isMobileDataTunnel: Boolean = this.isMobileDataTunnel,
|
isMobileDataTunnel: Boolean = this.isMobileDataTunnel,
|
||||||
isPrimaryTunnel: Boolean = this.isPrimaryTunnel,
|
isPrimaryTunnel: Boolean = this.isPrimaryTunnel,
|
||||||
amQuick: String = this.amQuick,
|
amQuick: String = this.amQuick,
|
||||||
isActive: Boolean = this.isActive,
|
isActive: Boolean = this.isActive,
|
||||||
restartOnPingFailure: Boolean = this.restartOnPingFailure,
|
isPingEnabled: Boolean = this.isPingEnabled,
|
||||||
pingIp: String? = this.pingTarget,
|
pingInterval: Long? = this.pingInterval,
|
||||||
|
pingCooldown: Long? = this.pingCooldown,
|
||||||
|
pingIp: String? = this.pingIp,
|
||||||
isEthernetTunnel: Boolean = this.isEthernetTunnel,
|
isEthernetTunnel: Boolean = this.isEthernetTunnel,
|
||||||
isIpv4Preferred: Boolean = this.isIpv4Preferred,
|
isIpv4Preferred: Boolean = this.isIpv4Preferred,
|
||||||
): TunnelConf {
|
): TunnelConf {
|
||||||
@@ -83,11 +88,12 @@ data class TunnelConf(
|
|||||||
isPrimaryTunnel,
|
isPrimaryTunnel,
|
||||||
amQuick,
|
amQuick,
|
||||||
isActive,
|
isActive,
|
||||||
|
isPingEnabled,
|
||||||
|
pingInterval,
|
||||||
|
pingCooldown,
|
||||||
pingIp,
|
pingIp,
|
||||||
restartOnPingFailure,
|
|
||||||
isEthernetTunnel,
|
isEthernetTunnel,
|
||||||
isIpv4Preferred,
|
isIpv4Preferred,
|
||||||
position,
|
|
||||||
)
|
)
|
||||||
.apply { stateChangeCallback = this@TunnelConf.stateChangeCallback }
|
.apply { stateChangeCallback = this@TunnelConf.stateChangeCallback }
|
||||||
}
|
}
|
||||||
@@ -102,6 +108,8 @@ data class TunnelConf(
|
|||||||
|
|
||||||
override fun getName(): String = tunName
|
override fun getName(): String = tunName
|
||||||
|
|
||||||
|
override fun isIpv4ResolutionPreferred(): Boolean = isIpv4Preferred
|
||||||
|
|
||||||
override fun onStateChange(newState: org.amnezia.awg.backend.Tunnel.State) {
|
override fun onStateChange(newState: org.amnezia.awg.backend.Tunnel.State) {
|
||||||
stateChangeCallback?.invoke(newState)
|
stateChangeCallback?.invoke(newState)
|
||||||
}
|
}
|
||||||
@@ -110,10 +118,6 @@ data class TunnelConf(
|
|||||||
stateChangeCallback?.invoke(newState)
|
stateChangeCallback?.invoke(newState)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isIpv4ResolutionPreferred(): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun generateUniqueName(tunnelNames: List<String>): String {
|
fun generateUniqueName(tunnelNames: List<String>): String {
|
||||||
var tunnelName = this.tunName
|
var tunnelName = this.tunName
|
||||||
var num = 1
|
var num = 1
|
||||||
@@ -130,6 +134,21 @@ data class TunnelConf(
|
|||||||
return tunnelName
|
return tunnelName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun isTunnelPingable(context: CoroutineContext): Boolean {
|
||||||
|
return withContext(context) {
|
||||||
|
val config = toWgConfig()
|
||||||
|
if (pingIp != null) {
|
||||||
|
return@withContext InetAddress.getByName(pingIp)
|
||||||
|
.isReachable(Constants.PING_TIMEOUT.toInt())
|
||||||
|
.also { Timber.i("Ping reachable $pingIp: $it") }
|
||||||
|
}
|
||||||
|
config.peers
|
||||||
|
.map { peer -> peer.isReachable() }
|
||||||
|
.all { true }
|
||||||
|
.also { Timber.i("Ping of all peers reachable: $it") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun configFromWgQuick(wgQuick: String): Config {
|
fun configFromWgQuick(wgQuick: String): Config {
|
||||||
val inputStream: InputStream = wgQuick.byteInputStream()
|
val inputStream: InputStream = wgQuick.byteInputStream()
|
||||||
@@ -143,21 +162,11 @@ data class TunnelConf(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun tunnelConfFromQuick(amQuick: String, name: String? = null): TunnelConf {
|
fun tunnelConfigFromAmConfig(
|
||||||
val config = configFromAmQuick(amQuick)
|
|
||||||
val wgQuick = config.toWgQuickString()
|
|
||||||
return TunnelConf(
|
|
||||||
tunName = name ?: config.defaultName(),
|
|
||||||
wgQuick = wgQuick,
|
|
||||||
amQuick = amQuick,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun tunnelConfFromAmConfig(
|
|
||||||
config: org.amnezia.awg.config.Config,
|
config: org.amnezia.awg.config.Config,
|
||||||
name: String? = null,
|
name: String? = null,
|
||||||
): TunnelConf {
|
): TunnelConf {
|
||||||
val amQuick = config.toAwgQuickString(true, false)
|
val amQuick = config.toAwgQuickString(true)
|
||||||
val wgQuick = config.toWgQuickString()
|
val wgQuick = config.toWgQuickString()
|
||||||
return TunnelConf(
|
return TunnelConf(
|
||||||
tunName = name ?: config.defaultName(),
|
tunName = name ?: config.defaultName(),
|
||||||
@@ -169,8 +178,8 @@ data class TunnelConf(
|
|||||||
private const val IPV6_ALL_NETWORKS = "::/0"
|
private const val IPV6_ALL_NETWORKS = "::/0"
|
||||||
private const val IPV4_ALL_NETWORKS = "0.0.0.0/0"
|
private const val IPV4_ALL_NETWORKS = "0.0.0.0/0"
|
||||||
val ALL_IPS = listOf(IPV4_ALL_NETWORKS, IPV6_ALL_NETWORKS)
|
val ALL_IPS = listOf(IPV4_ALL_NETWORKS, IPV6_ALL_NETWORKS)
|
||||||
val IPV4_PUBLIC_NETWORKS =
|
private val IPV4_PUBLIC_NETWORKS =
|
||||||
setOf(
|
listOf(
|
||||||
"0.0.0.0/5",
|
"0.0.0.0/5",
|
||||||
"8.0.0.0/7",
|
"8.0.0.0/7",
|
||||||
"11.0.0.0/8",
|
"11.0.0.0/8",
|
||||||
@@ -202,6 +211,6 @@ data class TunnelConf(
|
|||||||
"200.0.0.0/5",
|
"200.0.0.0/5",
|
||||||
"208.0.0.0/4",
|
"208.0.0.0/4",
|
||||||
)
|
)
|
||||||
val LAN_BYPASS_ALLOWED_IPS = setOf(IPV6_ALL_NETWORKS) + IPV4_PUBLIC_NETWORKS
|
val LAN_BYPASS_ALLOWED_IPS = listOf(IPV6_ALL_NETWORKS) + IPV4_PUBLIC_NETWORKS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -7,9 +7,7 @@ interface AppDataRepository {
|
|||||||
|
|
||||||
suspend fun getStartTunnelConfig(): TunnelConf?
|
suspend fun getStartTunnelConfig(): TunnelConf?
|
||||||
|
|
||||||
val settings: GeneralSettingRepository
|
val settings: AppSettingRepository
|
||||||
val tunnels: TunnelRepository
|
val tunnels: TunnelRepository
|
||||||
val appState: AppStateRepository
|
val appState: AppStateRepository
|
||||||
|
|
||||||
val proxySettings: ProxySettingsRepository
|
|
||||||
}
|
}
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface AppSettingRepository {
|
||||||
|
suspend fun save(appSettings: AppSettings)
|
||||||
|
|
||||||
|
val flow: Flow<AppSettings>
|
||||||
|
|
||||||
|
suspend fun get(): AppSettings
|
||||||
|
}
|
||||||
-4
@@ -41,9 +41,5 @@ interface AppStateRepository {
|
|||||||
|
|
||||||
suspend fun getRemoteKey(): String?
|
suspend fun getRemoteKey(): String?
|
||||||
|
|
||||||
suspend fun setShowDetailedPingStats(showDetailedPing: Boolean)
|
|
||||||
|
|
||||||
suspend fun getShowDetailedPing(): Boolean
|
|
||||||
|
|
||||||
val flow: Flow<AppState>
|
val flow: Flow<AppState>
|
||||||
}
|
}
|
||||||
|
|||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.sideeffect.GlobalSideEffect
|
|
||||||
import javax.inject.Singleton
|
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
|
||||||
import kotlinx.coroutines.flow.asSharedFlow
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
class GlobalEffectRepository {
|
|
||||||
|
|
||||||
private val _globalEffectFlow =
|
|
||||||
MutableSharedFlow<GlobalSideEffect>(replay = 0, extraBufferCapacity = 1)
|
|
||||||
val flow = _globalEffectFlow.asSharedFlow()
|
|
||||||
|
|
||||||
suspend fun post(effect: GlobalSideEffect) {
|
|
||||||
_globalEffectFlow.emit(effect)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
interface GeneralSettingRepository {
|
|
||||||
suspend fun save(generalSettings: GeneralSettings)
|
|
||||||
|
|
||||||
val flow: Flow<GeneralSettings>
|
|
||||||
|
|
||||||
suspend fun get(): GeneralSettings
|
|
||||||
}
|
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.InstalledPackage
|
|
||||||
|
|
||||||
interface InstalledPackageRepository {
|
|
||||||
|
|
||||||
// gets packages from cache or queries and updates cache if empty
|
|
||||||
suspend fun getInstalledPackages(): List<InstalledPackage>
|
|
||||||
|
|
||||||
// updates the cache and returns the results
|
|
||||||
suspend fun refreshInstalledPackages(): List<InstalledPackage>
|
|
||||||
}
|
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppProxySettings
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
interface ProxySettingsRepository {
|
|
||||||
suspend fun save(proxySettings: AppProxySettings)
|
|
||||||
|
|
||||||
val flow: Flow<AppProxySettings>
|
|
||||||
|
|
||||||
suspend fun get(): AppProxySettings
|
|
||||||
}
|
|
||||||
-2
@@ -34,6 +34,4 @@ interface TunnelRepository {
|
|||||||
suspend fun findByMobileDataTunnel(): Tunnels
|
suspend fun findByMobileDataTunnel(): Tunnels
|
||||||
|
|
||||||
suspend fun findPrimary(): Tunnels
|
suspend fun findPrimary(): Tunnels
|
||||||
|
|
||||||
suspend fun delete(tunnels: List<TunnelConf>)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -9,6 +9,6 @@ interface UpdateRepository {
|
|||||||
suspend fun downloadApk(
|
suspend fun downloadApk(
|
||||||
apkUrl: String,
|
apkUrl: String,
|
||||||
fileName: String,
|
fileName: String,
|
||||||
onProgress: suspend (Float) -> Unit,
|
onProgress: (Float) -> Unit,
|
||||||
): Result<File>
|
): Result<File>
|
||||||
}
|
}
|
||||||
|
|||||||
-27
@@ -1,27 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.sideeffect
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
sealed class GlobalSideEffect {
|
|
||||||
data object RequestBatteryOptimizationDisabled : GlobalSideEffect()
|
|
||||||
|
|
||||||
data class Snackbar(val message: StringValue) : GlobalSideEffect()
|
|
||||||
|
|
||||||
data class Toast(val message: StringValue) : GlobalSideEffect()
|
|
||||||
|
|
||||||
data object PopBackStack : GlobalSideEffect()
|
|
||||||
|
|
||||||
data class ShareFile(val file: File) : GlobalSideEffect()
|
|
||||||
|
|
||||||
data class LaunchUrl(val url: String) : GlobalSideEffect()
|
|
||||||
|
|
||||||
data object ConfigChanged : GlobalSideEffect()
|
|
||||||
|
|
||||||
data class RequestVpnPermission(val requestingMode: AppMode, val config: TunnelConf?) :
|
|
||||||
GlobalSideEffect()
|
|
||||||
|
|
||||||
data class InstallApk(val apk: File) : GlobalSideEffect()
|
|
||||||
}
|
|
||||||
+122
-76
@@ -1,71 +1,21 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.state
|
package com.zaneschepke.wireguardautotunnel.domain.state
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.StateChange
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.allDown
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.hasActive
|
||||||
|
import com.zaneschepke.wireguardautotunnel.core.tunnel.isUp
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent.*
|
import com.zaneschepke.wireguardautotunnel.domain.events.KillSwitchEvent
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isMatchingToWildcardList
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isMatchingToWildcardList
|
||||||
|
|
||||||
data class AutoTunnelState(
|
data class AutoTunnelState(
|
||||||
val activeTunnels: Map<TunnelConf, TunnelState> = emptyMap(),
|
val activeTunnels: Map<TunnelConf, TunnelState> = emptyMap(),
|
||||||
val networkState: NetworkState = NetworkState(),
|
val networkState: NetworkState = NetworkState(),
|
||||||
val settings: GeneralSettings = GeneralSettings(),
|
val settings: AppSettings = AppSettings(),
|
||||||
val tunnels: List<TunnelConf> = emptyList(),
|
val tunnels: List<TunnelConf> = emptyList(),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun determineAutoTunnelEvent(stateChange: StateChange): AutoTunnelEvent {
|
|
||||||
when (val change = stateChange) {
|
|
||||||
is StateChange.NetworkChange,
|
|
||||||
is StateChange.SettingsChange -> {
|
|
||||||
// Compute desired tunnel based on network conditions
|
|
||||||
var desiredTunnel: TunnelConf? = null
|
|
||||||
if (networkState.isEthernetConnected && settings.isTunnelOnEthernetEnabled) {
|
|
||||||
desiredTunnel = preferredEthernetTunnel()
|
|
||||||
} else if (isMobileDataActive() && settings.isTunnelOnMobileDataEnabled) {
|
|
||||||
desiredTunnel = preferredMobileDataTunnel()
|
|
||||||
} else if (
|
|
||||||
isWifiActive() && settings.isTunnelOnWifiEnabled && !isCurrentSSIDTrusted()
|
|
||||||
) {
|
|
||||||
desiredTunnel = preferredWifiTunnel()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override for no connectivity if enabled
|
|
||||||
if (isNoConnectivity() && settings.isStopOnNoInternetEnabled) {
|
|
||||||
desiredTunnel = null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine current active tunnel (assuming only one can be active)
|
|
||||||
val currentTunnel = activeTunnels.entries.firstOrNull()?.key
|
|
||||||
|
|
||||||
// Handle tunnel start/stop/change
|
|
||||||
if (desiredTunnel != null) {
|
|
||||||
if (currentTunnel != desiredTunnel) {
|
|
||||||
// Start or switch to the desired tunnel (overrides any kill switch)
|
|
||||||
return Start(desiredTunnel)
|
|
||||||
}
|
|
||||||
// If already active and matching, fall through to kill switch check (though
|
|
||||||
// unlikely needed)
|
|
||||||
} else {
|
|
||||||
if (currentTunnel != null) {
|
|
||||||
// Stop the active tunnel (then next emission can handle kill switch if
|
|
||||||
// needed)
|
|
||||||
return AutoTunnelEvent.Stop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is StateChange.MonitoringChange -> {
|
|
||||||
val bounceTunnels = bounceOnPingFailed()
|
|
||||||
if (bounceTunnels.isNotEmpty()) {
|
|
||||||
return Bounce(bounceTunnels)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is StateChange.ActiveTunnelsChange -> Unit
|
|
||||||
}
|
|
||||||
return DoNothing
|
|
||||||
}
|
|
||||||
|
|
||||||
// also need to check for Wi-Fi state as there is some overlap when they are both connected
|
// also need to check for Wi-Fi state as there is some overlap when they are both connected
|
||||||
private fun isMobileDataActive(): Boolean {
|
private fun isMobileDataActive(): Boolean {
|
||||||
return !networkState.isEthernetConnected &&
|
return !networkState.isEthernetConnected &&
|
||||||
@@ -73,22 +23,32 @@ data class AutoTunnelState(
|
|||||||
networkState.isMobileDataConnected
|
networkState.isMobileDataConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isMobileTunnelDataChangeNeeded(): Boolean {
|
||||||
|
val preferredTunnel = preferredMobileDataTunnel()
|
||||||
|
return preferredTunnel != null &&
|
||||||
|
activeTunnels.isNotEmpty() &&
|
||||||
|
!activeTunnels.isUp(preferredTunnel)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isEthernetTunnelChangeNeeded(): Boolean {
|
||||||
|
val preferredTunnel = preferredEthernetTunnel()
|
||||||
|
return preferredTunnel != null &&
|
||||||
|
activeTunnels.isNotEmpty() &&
|
||||||
|
!activeTunnels.isUp(preferredTunnel)
|
||||||
|
}
|
||||||
|
|
||||||
private fun preferredMobileDataTunnel(): TunnelConf? {
|
private fun preferredMobileDataTunnel(): TunnelConf? {
|
||||||
return tunnels.firstOrNull { it.isMobileDataTunnel }
|
return tunnels.firstOrNull { it.isMobileDataTunnel }
|
||||||
?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
||||||
?: tunnels.firstOrNull()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun preferredEthernetTunnel(): TunnelConf? {
|
private fun preferredEthernetTunnel(): TunnelConf? {
|
||||||
return tunnels.firstOrNull { it.isEthernetTunnel }
|
return tunnels.firstOrNull { it.isEthernetTunnel }
|
||||||
?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
||||||
?: tunnels.firstOrNull()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun preferredWifiTunnel(): TunnelConf? {
|
private fun preferredWifiTunnel(): TunnelConf? {
|
||||||
return getTunnelWithMatchingTunnelNetwork()
|
return getTunnelWithMatchingTunnelNetwork() ?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
||||||
?: tunnels.firstOrNull { it.isPrimaryTunnel }
|
|
||||||
?: tunnels.firstOrNull()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore cellular state as there is overlap where it may still be active, but not prioritized
|
// ignore cellular state as there is overlap where it may still be active, but not prioritized
|
||||||
@@ -96,6 +56,19 @@ data class AutoTunnelState(
|
|||||||
return !networkState.isEthernetConnected && networkState.isWifiConnected
|
return !networkState.isEthernetConnected && networkState.isWifiConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun startOnEthernet(): Boolean {
|
||||||
|
return networkState.isEthernetConnected &&
|
||||||
|
settings.isTunnelOnEthernetEnabled &&
|
||||||
|
activeTunnels.allDown()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopOnEthernet(): Boolean {
|
||||||
|
return networkState.isEthernetConnected &&
|
||||||
|
!settings.isTunnelOnEthernetEnabled &&
|
||||||
|
activeTunnels.hasActive()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO test removed kill switch state check
|
||||||
private fun stopKillSwitchOnTrusted(): Boolean {
|
private fun stopKillSwitchOnTrusted(): Boolean {
|
||||||
return networkState.isWifiConnected &&
|
return networkState.isWifiConnected &&
|
||||||
settings.isVpnKillSwitchEnabled &&
|
settings.isVpnKillSwitchEnabled &&
|
||||||
@@ -103,6 +76,7 @@ data class AutoTunnelState(
|
|||||||
isCurrentSSIDTrusted()
|
isCurrentSSIDTrusted()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO test, removed kill switch state check
|
||||||
private fun startKillSwitch(): Boolean {
|
private fun startKillSwitch(): Boolean {
|
||||||
return settings.isVpnKillSwitchEnabled &&
|
return settings.isVpnKillSwitchEnabled &&
|
||||||
(!settings.isDisableKillSwitchOnTrustedEnabled || !isCurrentSSIDTrusted())
|
(!settings.isDisableKillSwitchOnTrustedEnabled || !isCurrentSSIDTrusted())
|
||||||
@@ -114,21 +88,93 @@ data class AutoTunnelState(
|
|||||||
!networkState.isMobileDataConnected
|
!networkState.isMobileDataConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bounceOnPingFailed(): List<Pair<TunnelConf, Map<String, String?>>> {
|
private fun stopOnMobileData(): Boolean {
|
||||||
return activeTunnels.entries
|
return isMobileDataActive() &&
|
||||||
.filter { (tunnel, state) ->
|
!settings.isTunnelOnMobileDataEnabled &&
|
||||||
tunnel.restartOnPingFailure &&
|
activeTunnels.hasActive()
|
||||||
(state.pingStates?.any { (key, pingState) ->
|
}
|
||||||
pingState.failureReason == FailureReason.PingFailed
|
|
||||||
} ?: false)
|
private fun startOnMobileData(): Boolean {
|
||||||
}
|
return isMobileDataActive() &&
|
||||||
.map { (tunnel, state) ->
|
settings.isTunnelOnMobileDataEnabled &&
|
||||||
val peerMap =
|
activeTunnels.allDown()
|
||||||
(state.statistics?.getPeers()?.associate { peerKey ->
|
}
|
||||||
peerKey.toBase64() to state.statistics.peerStats(peerKey)?.resolvedEndpoint
|
|
||||||
} ?: emptyMap())
|
private fun changeOnMobileData(): Boolean {
|
||||||
Pair(tunnel, peerMap)
|
return isMobileDataActive() &&
|
||||||
|
settings.isTunnelOnMobileDataEnabled &&
|
||||||
|
isMobileTunnelDataChangeNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun changeOnEthernet(): Boolean {
|
||||||
|
return networkState.isEthernetConnected &&
|
||||||
|
settings.isTunnelOnEthernetEnabled &&
|
||||||
|
isEthernetTunnelChangeNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopOnWifi(): Boolean {
|
||||||
|
return isWifiActive() && !settings.isTunnelOnWifiEnabled && activeTunnels.hasActive()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopOnTrustedWifi(): Boolean {
|
||||||
|
return isWifiActive() &&
|
||||||
|
settings.isTunnelOnWifiEnabled &&
|
||||||
|
activeTunnels.hasActive() &&
|
||||||
|
isCurrentSSIDTrusted()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startOnUntrustedWifi(): Boolean {
|
||||||
|
return isWifiActive() &&
|
||||||
|
settings.isTunnelOnWifiEnabled &&
|
||||||
|
activeTunnels.allDown() &&
|
||||||
|
!isCurrentSSIDTrusted()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun changeOnUntrustedWifi(): Boolean {
|
||||||
|
return isWifiActive() &&
|
||||||
|
settings.isTunnelOnWifiEnabled &&
|
||||||
|
activeTunnels.hasActive() &&
|
||||||
|
!isCurrentSSIDTrusted() &&
|
||||||
|
!isWifiTunnelPreferred()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isWifiTunnelPreferred(): Boolean {
|
||||||
|
val preferred = preferredWifiTunnel()
|
||||||
|
return preferred?.let { activeTunnels.isUp(it) } ?: true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun asAutoTunnelEvent(): AutoTunnelEvent {
|
||||||
|
return when {
|
||||||
|
// ethernet scenarios
|
||||||
|
stopOnEthernet() -> AutoTunnelEvent.Stop
|
||||||
|
startOnEthernet() || changeOnEthernet() ->
|
||||||
|
AutoTunnelEvent.Start(preferredEthernetTunnel())
|
||||||
|
// mobile data scenarios
|
||||||
|
stopOnMobileData() -> AutoTunnelEvent.Stop
|
||||||
|
startOnMobileData() || changeOnMobileData() ->
|
||||||
|
AutoTunnelEvent.Start(preferredMobileDataTunnel())
|
||||||
|
// wifi scenarios
|
||||||
|
stopOnWifi() -> AutoTunnelEvent.Stop
|
||||||
|
stopOnTrustedWifi() -> AutoTunnelEvent.Stop
|
||||||
|
startOnUntrustedWifi() || changeOnUntrustedWifi() ->
|
||||||
|
AutoTunnelEvent.Start(preferredWifiTunnel())
|
||||||
|
// no connectivity
|
||||||
|
isNoConnectivity() && settings.isStopOnNoInternetEnabled -> AutoTunnelEvent.Stop
|
||||||
|
else -> AutoTunnelEvent.DoNothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun asKillSwitchEvent(): KillSwitchEvent {
|
||||||
|
return when {
|
||||||
|
stopKillSwitchOnTrusted() -> KillSwitchEvent.Stop
|
||||||
|
startKillSwitch() -> {
|
||||||
|
val allowedIps =
|
||||||
|
if (settings.isLanOnKillSwitchEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS
|
||||||
|
else emptyList()
|
||||||
|
KillSwitchEvent.Start(allowedIps)
|
||||||
}
|
}
|
||||||
|
else -> KillSwitchEvent.DoNothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isCurrentSSIDTrusted(): Boolean {
|
private fun isCurrentSSIDTrusted(): Boolean {
|
||||||
@@ -137,7 +183,7 @@ data class AutoTunnelState(
|
|||||||
|
|
||||||
private fun hasTrustedWifiName(
|
private fun hasTrustedWifiName(
|
||||||
wifiName: String,
|
wifiName: String,
|
||||||
wifiNames: Set<String> = settings.trustedNetworkSSIDs,
|
wifiNames: List<String> = settings.trustedNetworkSSIDs,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return if (settings.isWildcardsEnabled) {
|
return if (settings.isWildcardsEnabled) {
|
||||||
wifiNames.isMatchingToWildcardList(wifiName)
|
wifiNames.isMatchingToWildcardList(wifiName)
|
||||||
|
|||||||
@@ -1,38 +1,12 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.state
|
package com.zaneschepke.wireguardautotunnel.domain.state
|
||||||
|
|
||||||
import com.zaneschepke.networkmonitor.ConnectivityState
|
|
||||||
import com.zaneschepke.networkmonitor.util.WifiSecurityType
|
|
||||||
|
|
||||||
data class NetworkState(
|
data class NetworkState(
|
||||||
val isWifiConnected: Boolean = false,
|
val isWifiConnected: Boolean = false,
|
||||||
val isMobileDataConnected: Boolean = false,
|
val isMobileDataConnected: Boolean = false,
|
||||||
val isEthernetConnected: Boolean = false,
|
val isEthernetConnected: Boolean = false,
|
||||||
val wifiName: String? = null,
|
val wifiName: String? = null,
|
||||||
val isWifiSecure: Boolean? = null,
|
|
||||||
val locationServicesEnabled: Boolean? = null,
|
|
||||||
val locationPermissionGranted: Boolean? = null,
|
|
||||||
) {
|
) {
|
||||||
fun hasNoCapabilities(): Boolean {
|
fun hasNoCapabilities(): Boolean {
|
||||||
return !isWifiConnected && !isMobileDataConnected && !isEthernetConnected
|
return !isWifiConnected && !isMobileDataConnected && !isEthernetConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun from(connectivityState: ConnectivityState): NetworkState {
|
|
||||||
return NetworkState(
|
|
||||||
isWifiSecure =
|
|
||||||
when (connectivityState.wifiState.securityType) {
|
|
||||||
WifiSecurityType.OPEN,
|
|
||||||
WifiSecurityType.UNKNOWN -> false
|
|
||||||
null -> null
|
|
||||||
else -> true
|
|
||||||
},
|
|
||||||
isWifiConnected = connectivityState.wifiState.connected,
|
|
||||||
isMobileDataConnected = connectivityState.cellularConnected,
|
|
||||||
isEthernetConnected = connectivityState.ethernetConnected,
|
|
||||||
wifiName = connectivityState.wifiState.ssid,
|
|
||||||
locationPermissionGranted = connectivityState.wifiState.locationPermissionsGranted,
|
|
||||||
locationServicesEnabled = connectivityState.wifiState.locationServicesEnabled,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.state
|
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelMonitor.Companion.CLOUDFLARE_IPV4_IP
|
|
||||||
|
|
||||||
enum class FailureReason {
|
|
||||||
NoConnectivity,
|
|
||||||
PingFailed,
|
|
||||||
NoResolvedEndpoint,
|
|
||||||
Timeout,
|
|
||||||
Unknown,
|
|
||||||
}
|
|
||||||
|
|
||||||
data class PingState(
|
|
||||||
val transmitted: Int = 0,
|
|
||||||
val received: Int = 0,
|
|
||||||
val packetLoss: Double = 0.0,
|
|
||||||
val rttMin: Double = 0.0,
|
|
||||||
val rttMax: Double = 0.0,
|
|
||||||
val rttAvg: Double = 0.0,
|
|
||||||
val rttStddev: Double = 0.0,
|
|
||||||
val isReachable: Boolean = false,
|
|
||||||
val lastSuccessfulPingMillis: Long? = null,
|
|
||||||
val lastPingAttemptMillis: Long? = null,
|
|
||||||
val failureReason: FailureReason? = null,
|
|
||||||
val pingTarget: String = CLOUDFLARE_IPV4_IP,
|
|
||||||
)
|
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.domain.state
|
package com.zaneschepke.wireguardautotunnel.domain.state
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendState
|
||||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||||
import org.amnezia.awg.crypto.Key
|
|
||||||
|
|
||||||
data class TunnelState(
|
data class TunnelState(
|
||||||
val status: TunnelStatus = TunnelStatus.Down,
|
val status: TunnelStatus = TunnelStatus.Down,
|
||||||
val backendState: BackendMode = BackendMode.Inactive,
|
val backendState: BackendState = BackendState.INACTIVE,
|
||||||
val statistics: TunnelStatistics? = null,
|
val statistics: TunnelStatistics? = null,
|
||||||
val pingStates: Map<Key, PingState>? = null,
|
|
||||||
val handshakeSuccessLogs: Boolean? = null,
|
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-14
@@ -3,24 +3,13 @@ package com.zaneschepke.wireguardautotunnel.domain.state
|
|||||||
import org.amnezia.awg.crypto.Key
|
import org.amnezia.awg.crypto.Key
|
||||||
|
|
||||||
abstract class TunnelStatistics {
|
abstract class TunnelStatistics {
|
||||||
open class PeerStats(
|
@JvmRecord
|
||||||
|
data class PeerStats(
|
||||||
val rxBytes: Long,
|
val rxBytes: Long,
|
||||||
val txBytes: Long,
|
val txBytes: Long,
|
||||||
val latestHandshakeEpochMillis: Long,
|
val latestHandshakeEpochMillis: Long,
|
||||||
val resolvedEndpoint: String,
|
val resolvedEndpoint: String,
|
||||||
) {
|
)
|
||||||
// mimic data class copy
|
|
||||||
open fun copy(
|
|
||||||
rxBytes: Long = this.rxBytes,
|
|
||||||
txBytes: Long = this.txBytes,
|
|
||||||
latestHandshakeEpochMillis: Long = this.latestHandshakeEpochMillis,
|
|
||||||
resolvedEndpoint: String = this.resolvedEndpoint,
|
|
||||||
): PeerStats = PeerStats(rxBytes, txBytes, latestHandshakeEpochMillis, resolvedEndpoint)
|
|
||||||
|
|
||||||
// Manual toString: Format like data class
|
|
||||||
override fun toString(): String =
|
|
||||||
"PeerStats(rxBytes=$rxBytes, txBytes=$txBytes, latestHandshakeEpochMillis=$latestHandshakeEpochMillis, resolvedEndpoint=$resolvedEndpoint)"
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract fun peerStats(peer: Key): PeerStats?
|
abstract fun peerStats(peer: Key): PeerStats?
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui
|
|
||||||
|
|
||||||
import androidx.compose.runtime.compositionLocalOf
|
|
||||||
import androidx.compose.runtime.staticCompositionLocalOf
|
|
||||||
import androidx.navigation.NavHostController
|
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.SharedAppViewModel
|
|
||||||
|
|
||||||
val LocalNavController =
|
|
||||||
compositionLocalOf<NavHostController> { error("NavController was not provided") }
|
|
||||||
|
|
||||||
val LocalIsAndroidTV = staticCompositionLocalOf { false }
|
|
||||||
|
|
||||||
val LocalSharedVm = staticCompositionLocalOf<SharedAppViewModel> { error("No SharedVm") }
|
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
sealed class Route {
|
||||||
|
@Serializable data object Support : Route()
|
||||||
|
|
||||||
|
@Serializable data object Settings : Route()
|
||||||
|
|
||||||
|
@Serializable data object SettingsAdvanced : Route()
|
||||||
|
|
||||||
|
@Serializable data object AutoTunnel : Route()
|
||||||
|
|
||||||
|
@Serializable data object AutoTunnelAdvanced : Route()
|
||||||
|
|
||||||
|
@Serializable data object WifiDetectionMethod : Route()
|
||||||
|
|
||||||
|
@Serializable data object LocationDisclosure : Route()
|
||||||
|
|
||||||
|
@Serializable data object Appearance : Route()
|
||||||
|
|
||||||
|
@Serializable data object Display : Route()
|
||||||
|
|
||||||
|
@Serializable data object KillSwitch : Route()
|
||||||
|
|
||||||
|
@Serializable data object Language : Route()
|
||||||
|
|
||||||
|
@Serializable data object Main : Route()
|
||||||
|
|
||||||
|
@Serializable data class TunnelOptions(val id: Int) : Route()
|
||||||
|
|
||||||
|
@Serializable data object Lock : Route()
|
||||||
|
|
||||||
|
@Serializable data object License : Route()
|
||||||
|
|
||||||
|
@Serializable data class Config(val id: Int) : Route()
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class SplitTunnel(val id: Int) : Route() {
|
||||||
|
companion object {
|
||||||
|
const val KEY_ID = "id"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable data class TunnelAutoTunnel(val id: Int) : Route()
|
||||||
|
|
||||||
|
@Serializable data object Logs : Route()
|
||||||
|
}
|
||||||
+14
-14
@@ -1,12 +1,16 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.dropdown
|
package com.zaneschepke.wireguardautotunnel.ui.common
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.heightIn
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@@ -16,28 +20,24 @@ import com.zaneschepke.wireguardautotunnel.R
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun <T> DropdownSelector(
|
fun <T> DropdownSelector(
|
||||||
currentValue: T?,
|
currentValue: T,
|
||||||
options: List<T?>,
|
options: List<T>,
|
||||||
onValueSelected: (T?) -> Unit,
|
onValueSelected: (T) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
label: @Composable (() -> Unit)? = null,
|
label: @Composable (() -> Unit)? = null,
|
||||||
isExpanded: Boolean = false,
|
isExpanded: Boolean = false,
|
||||||
onDismiss: () -> Unit = {},
|
onDismiss: () -> Unit = {},
|
||||||
optionToString: @Composable (T?) -> String = {
|
|
||||||
it?.toString() ?: stringResource(R.string._default)
|
|
||||||
},
|
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.spacedBy(5.dp),
|
horizontalArrangement = Arrangement.spacedBy(5.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
if (label != null) label()
|
if (label != null) label()
|
||||||
Text(text = optionToString(currentValue), style = MaterialTheme.typography.bodyMedium)
|
Text(text = currentValue.toString(), style = MaterialTheme.typography.bodyMedium)
|
||||||
Icon(Icons.Default.ArrowDropDown, contentDescription = stringResource(R.string.dropdown))
|
Icon(Icons.Default.ArrowDropDown, contentDescription = stringResource(R.string.dropdown))
|
||||||
}
|
}
|
||||||
|
|
||||||
DropdownMenu(
|
DropdownMenu(
|
||||||
modifier = modifier.heightIn(max = 250.dp),
|
modifier = modifier.height(250.dp),
|
||||||
scrollState = rememberScrollState(),
|
scrollState = rememberScrollState(),
|
||||||
containerColor = MaterialTheme.colorScheme.surface,
|
containerColor = MaterialTheme.colorScheme.surface,
|
||||||
expanded = isExpanded,
|
expanded = isExpanded,
|
||||||
@@ -45,10 +45,10 @@ fun <T> DropdownSelector(
|
|||||||
) {
|
) {
|
||||||
options.forEach { option ->
|
options.forEach { option ->
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(optionToString(option)) },
|
text = { Text(text = option.toString()) },
|
||||||
onClick = {
|
onClick = {
|
||||||
onValueSelected(option)
|
onValueSelected(option)
|
||||||
onDismiss()
|
onDismiss() // Close dropdown after selection
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
+33
-6
@@ -3,41 +3,68 @@ package com.zaneschepke.wireguardautotunnel.ui.common
|
|||||||
import androidx.compose.animation.animateContentSize
|
import androidx.compose.animation.animateContentSize
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.combinedClickable
|
||||||
|
import androidx.compose.foundation.indication
|
||||||
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.ripple
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ExpandingRowListItem(
|
fun ExpandingRowListItem(
|
||||||
leading: @Composable () -> Unit,
|
leading: @Composable () -> Unit,
|
||||||
text: String,
|
text: String,
|
||||||
|
onHold: () -> Unit,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
onDoubleClick: () -> Unit,
|
||||||
trailing: @Composable () -> Unit,
|
trailing: @Composable () -> Unit,
|
||||||
isSelected: Boolean,
|
isSelected: Boolean,
|
||||||
expanded: (@Composable () -> Unit),
|
expanded: (@Composable () -> Unit)?,
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
) {
|
) {
|
||||||
|
val isTv = LocalIsAndroidTV.current
|
||||||
|
val haptic = LocalHapticFeedback.current
|
||||||
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
modifier
|
Modifier.animateContentSize()
|
||||||
.animateContentSize()
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.clip(RoundedCornerShape(8.dp))
|
||||||
.background(
|
.background(
|
||||||
if (isSelected) MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
|
if (isSelected) MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
|
||||||
else Color.Transparent
|
else Color.Transparent
|
||||||
)
|
)
|
||||||
|
.then(
|
||||||
|
if (!isTv) {
|
||||||
|
Modifier.combinedClickable(
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
indication = ripple(),
|
||||||
|
onClick = onClick,
|
||||||
|
onLongClick = {
|
||||||
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
|
onHold()
|
||||||
|
},
|
||||||
|
onDoubleClick = onDoubleClick,
|
||||||
|
)
|
||||||
|
} else Modifier
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
Column {
|
Column {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp).height(48.dp),
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
) {
|
) {
|
||||||
@@ -57,7 +84,7 @@ fun ExpandingRowListItem(
|
|||||||
}
|
}
|
||||||
trailing()
|
trailing()
|
||||||
}
|
}
|
||||||
expanded()
|
expanded?.invoke()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common
|
|
||||||
|
|
||||||
import android.view.WindowManager
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.DisposableEffect
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import com.zaneschepke.wireguardautotunnel.MainActivity
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SecureScreenFromRecording() {
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
val activity = context as? MainActivity
|
|
||||||
|
|
||||||
// Secure screen due to sensitive information
|
|
||||||
DisposableEffect(Unit) {
|
|
||||||
activity
|
|
||||||
?.window
|
|
||||||
?.setFlags(
|
|
||||||
WindowManager.LayoutParams.FLAG_SECURE,
|
|
||||||
WindowManager.LayoutParams.FLAG_SECURE,
|
|
||||||
)
|
|
||||||
onDispose { activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.common.animation
|
||||||
|
|
||||||
|
import androidx.compose.animation.core.LinearEasing
|
||||||
|
import androidx.compose.animation.core.animateFloat
|
||||||
|
import androidx.compose.animation.core.infiniteRepeatable
|
||||||
|
import androidx.compose.animation.core.rememberInfiniteTransition
|
||||||
|
import androidx.compose.animation.core.tween
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
|
import androidx.compose.ui.graphics.Brush
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ShimmerEffect(modifier: Modifier = Modifier): Brush {
|
||||||
|
val shimmerColors =
|
||||||
|
listOf(
|
||||||
|
Color.LightGray.copy(alpha = 0.9f),
|
||||||
|
Color.LightGray.copy(alpha = 0.3f),
|
||||||
|
Color.LightGray.copy(alpha = 0.9f),
|
||||||
|
)
|
||||||
|
|
||||||
|
val transition = rememberInfiniteTransition()
|
||||||
|
val translateAnim by
|
||||||
|
transition.animateFloat(
|
||||||
|
initialValue = 0f,
|
||||||
|
targetValue = 1000f,
|
||||||
|
animationSpec =
|
||||||
|
infiniteRepeatable(animation = tween(durationMillis = 1200, easing = LinearEasing)),
|
||||||
|
)
|
||||||
|
|
||||||
|
return Brush.linearGradient(
|
||||||
|
colors = shimmerColors,
|
||||||
|
start = Offset(0f, 0f),
|
||||||
|
end = Offset(translateAnim, translateAnim),
|
||||||
|
)
|
||||||
|
}
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.banner
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun AppAlertBanner(
|
|
||||||
message: String,
|
|
||||||
textColor: Color,
|
|
||||||
containerColor: Color,
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(IntrinsicSize.Min)
|
|
||||||
.background(
|
|
||||||
color = containerColor,
|
|
||||||
shape = RoundedCornerShape(bottomStart = 8.dp, bottomEnd = 8.dp),
|
|
||||||
)
|
|
||||||
.clip(RoundedCornerShape(bottomStart = 8.dp, bottomEnd = 8.dp))
|
|
||||||
.statusBarsPadding()
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = message,
|
|
||||||
color = textColor,
|
|
||||||
style = MaterialTheme.typography.labelSmall.copy(fontSize = 8.sp),
|
|
||||||
modifier = Modifier.align(Alignment.Center).padding(bottom = 5.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-74
@@ -1,74 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.banner
|
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
|
||||||
import androidx.compose.animation.expandVertically
|
|
||||||
import androidx.compose.animation.shrinkVertically
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.outlined.Warning
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Surface
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Straw
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun WarningBanner(
|
|
||||||
title: String,
|
|
||||||
visible: Boolean,
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
trailing: (@Composable () -> Unit)? = null,
|
|
||||||
) {
|
|
||||||
AnimatedVisibility(visible = visible, enter = expandVertically(), exit = shrinkVertically()) {
|
|
||||||
Surface(
|
|
||||||
color = MaterialTheme.colorScheme.secondary,
|
|
||||||
modifier = modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)),
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp).padding(start = 2.dp),
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.Start),
|
|
||||||
modifier = Modifier.weight(4f, false).fillMaxWidth(),
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Outlined.Warning,
|
|
||||||
stringResource(R.string.warning),
|
|
||||||
Modifier.size(18.dp),
|
|
||||||
tint = Straw,
|
|
||||||
)
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.Start,
|
|
||||||
verticalArrangement =
|
|
||||||
Arrangement.spacedBy(2.dp, Alignment.CenterVertically),
|
|
||||||
modifier = Modifier.fillMaxWidth().weight(1f).padding(start = 6.dp),
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurface,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trailing?.let {
|
|
||||||
Box(
|
|
||||||
contentAlignment = Alignment.CenterEnd,
|
|
||||||
modifier = Modifier.padding(start = 16.dp),
|
|
||||||
) {
|
|
||||||
it()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-21
@@ -1,21 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common.button
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ActionIconButton(icon: ImageVector, labelRes: Int, onClick: () -> Unit) {
|
|
||||||
IconButton(onClick = onClick) {
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
contentDescription = stringResource(labelRes),
|
|
||||||
modifier = Modifier.size(iconSize),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+5
-1
@@ -3,7 +3,11 @@ package com.zaneschepke.wireguardautotunnel.ui.common.button
|
|||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
|||||||
+25
-8
@@ -2,25 +2,34 @@ package com.zaneschepke.wireguardautotunnel.ui.common.button
|
|||||||
|
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.IntrinsicSize
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItemLabel
|
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionLabelType
|
|
||||||
|
|
||||||
@Composable
|
@androidx.compose.runtime.Composable
|
||||||
fun IconSurfaceButton(
|
fun IconSurfaceButton(
|
||||||
title: String,
|
title: String,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
selected: Boolean,
|
selected: Boolean,
|
||||||
leading: (@Composable () -> Unit)? = null,
|
leadingIcon: ImageVector? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
) {
|
) {
|
||||||
val border: BorderStroke? =
|
val border: BorderStroke? =
|
||||||
@@ -55,9 +64,17 @@ fun IconSurfaceButton(
|
|||||||
modifier =
|
modifier =
|
||||||
Modifier.padding(vertical = if (description == null) 10.dp else 0.dp),
|
Modifier.padding(vertical = if (description == null) 10.dp else 0.dp),
|
||||||
) {
|
) {
|
||||||
leading?.invoke()
|
leadingIcon?.let {
|
||||||
|
Icon(
|
||||||
|
leadingIcon,
|
||||||
|
leadingIcon.name,
|
||||||
|
Modifier.size(iconSize),
|
||||||
|
if (selected) MaterialTheme.colorScheme.primary
|
||||||
|
else MaterialTheme.colorScheme.onSurface,
|
||||||
|
)
|
||||||
|
}
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||||
SelectionItemLabel(title, SelectionLabelType.TITLE)
|
Text(title, style = MaterialTheme.typography.titleMedium)
|
||||||
description?.let {
|
description?.let {
|
||||||
Text(
|
Text(
|
||||||
description,
|
description,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user