mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f48147b3e |
@@ -1,20 +0,0 @@
|
|||||||
name: Issue Updates Workflow
|
|
||||||
|
|
||||||
on:
|
|
||||||
issues:
|
|
||||||
types: [opened, closed, reopened]
|
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
build:
|
|
||||||
name: Build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Send Telegram Message
|
|
||||||
run: |
|
|
||||||
msg_text='${{ github.actor }} updated an issue:
|
|
||||||
status: ${{ github.event.issue.state }} - #${{ github.event.issue.number }} ${{ github.event.issue.title }}
|
|
||||||
https://github.com/zaneschepke/wgtunnel/issues/${{ github.event.issue.number }}'
|
|
||||||
curl -s -X POST 'https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage' \
|
|
||||||
-d "chat_id=${{ secrets.TELEGRAM_TO }}&text=${msg_text}&message_thread_id=${{ secrets.TELEGRAM_TOPIC }}"
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# name of the workflow
|
||||||
name: Android CI Tag Deployment (Pre-release)
|
name: Android CI Tag Deployment (Pre-release)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@@ -67,7 +68,7 @@ jobs:
|
|||||||
echo "VERSION_CODE=$version_code" >> $GITHUB_ENV
|
echo "VERSION_CODE=$version_code" >> $GITHUB_ENV
|
||||||
# Save the APK after the Build job is complete to publish it as a Github release in the next job
|
# Save the APK after the Build job is complete to publish it as a Github release in the next job
|
||||||
- name: Upload APK
|
- name: Upload APK
|
||||||
uses: actions/upload-artifact@v4.3.3
|
uses: actions/upload-artifact@v4.3.1
|
||||||
with:
|
with:
|
||||||
name: wgtunnel
|
name: wgtunnel
|
||||||
path: ${{ steps.apk-path.outputs.path }}
|
path: ${{ steps.apk-path.outputs.path }}
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
name: Release Updates Workflow
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
build:
|
|
||||||
name: Build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Send Telegram Message
|
|
||||||
run: |
|
|
||||||
msg_text='${{ github.actor }} published a new release:
|
|
||||||
Release: ${{ github.event.release.tag_name }}
|
|
||||||
${{ github.event.release.body }}
|
|
||||||
https://github.com/zaneschepke/wgtunnel/releases/tag/${{ github.event.release.tag_name }}'
|
|
||||||
curl -s -X POST 'https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage' \
|
|
||||||
-d "chat_id=${{ secrets.TELEGRAM_TO }}&text=${msg_text}&message_thread_id=${{ secrets.TELEGRAM_TOPIC }}"
|
|
||||||
@@ -69,7 +69,7 @@ jobs:
|
|||||||
echo "VERSION_CODE=$version_code" >> $GITHUB_ENV
|
echo "VERSION_CODE=$version_code" >> $GITHUB_ENV
|
||||||
# Save the APK after the Build job is complete to publish it as a Github release in the next job
|
# Save the APK after the Build job is complete to publish it as a Github release in the next job
|
||||||
- name: Upload APK
|
- name: Upload APK
|
||||||
uses: actions/upload-artifact@v4.3.3
|
uses: actions/upload-artifact@v4.3.1
|
||||||
with:
|
with:
|
||||||
name: wgtunnel
|
name: wgtunnel
|
||||||
path: ${{ steps.apk-path.outputs.path }}
|
path: ${{ steps.apk-path.outputs.path }}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ WG Tunnel
|
|||||||
|
|
||||||
<div align="left">
|
<div align="left">
|
||||||
|
|
||||||
This is an alternative Android Application for [WireGuard](https://www.wireguard.com/) and [AmneziaWG](https://docs.amnezia.org/documentation/amnezia-wg/) with added
|
This is an alternative Android Application for [WireGuard](https://www.wireguard.com/) with added
|
||||||
features. Built using the [wireguard-android](https://github.com/WireGuard/wireguard-android)
|
features. Built using the [wireguard-android](https://github.com/WireGuard/wireguard-android)
|
||||||
library and [Jetpack Compose](https://developer.android.com/jetpack/compose), this application was
|
library and [Jetpack Compose](https://developer.android.com/jetpack/compose), this application was
|
||||||
inspired by the official [WireGuard Android](https://github.com/WireGuard/wireguard-android) app.
|
inspired by the official [WireGuard Android](https://github.com/WireGuard/wireguard-android) app.
|
||||||
@@ -53,9 +53,8 @@ and on while on different networks. This app was created to offer a free solutio
|
|||||||
* Auto connect to tunnels based on Wi-Fi SSID, ethernet, or mobile data
|
* Auto connect to tunnels based on Wi-Fi SSID, ethernet, or mobile data
|
||||||
* Split tunneling by application with search
|
* Split tunneling by application with search
|
||||||
* WireGuard support for kernel and userspace modes
|
* WireGuard support for kernel and userspace modes
|
||||||
* Amnezia support for userspace mode for DPI/censorship protection
|
|
||||||
* Always-On VPN support
|
* Always-On VPN support
|
||||||
* Export Amnezia and WireGuard tunnels to zip
|
* Export tunnels to zip
|
||||||
* Quick tile support for tunnel toggling, auto-tunneling
|
* Quick tile support for tunnel toggling, auto-tunneling
|
||||||
* Static shortcuts support for tunnel toggling, auto-tunneling
|
* Static shortcuts support for tunnel toggling, auto-tunneling
|
||||||
* Intent automation support for all tunnels
|
* Intent automation support for all tunnels
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ dependencies {
|
|||||||
|
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation(libs.androidx.core.ktx)
|
||||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||||
|
|
||||||
// helpers for implementing LifecycleOwner in a Service
|
// helpers for implementing LifecycleOwner in a Service
|
||||||
implementation(libs.androidx.lifecycle.service)
|
implementation(libs.androidx.lifecycle.service)
|
||||||
implementation(libs.androidx.activity.compose)
|
implementation(libs.androidx.activity.compose)
|
||||||
@@ -161,8 +160,7 @@ dependencies {
|
|||||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||||
debugImplementation(libs.androidx.compose.manifest)
|
debugImplementation(libs.androidx.compose.manifest)
|
||||||
|
|
||||||
// get tunnel lib from github packages or mavenLocal
|
// tunnel
|
||||||
implementation(libs.tunnel)
|
|
||||||
implementation(libs.amneziawg.android)
|
implementation(libs.amneziawg.android)
|
||||||
coreLibraryDesugaring(libs.desugar.jdk.libs)
|
coreLibraryDesugaring(libs.desugar.jdk.libs)
|
||||||
|
|
||||||
@@ -174,8 +172,6 @@ dependencies {
|
|||||||
implementation(libs.androidx.navigation.compose)
|
implementation(libs.androidx.navigation.compose)
|
||||||
implementation(libs.androidx.hilt.navigation.compose)
|
implementation(libs.androidx.hilt.navigation.compose)
|
||||||
|
|
||||||
implementation(libs.zaneschepke.multifab)
|
|
||||||
|
|
||||||
// hilt
|
// hilt
|
||||||
implementation(libs.hilt.android)
|
implementation(libs.hilt.android)
|
||||||
ksp(libs.hilt.android.compiler)
|
ksp(libs.hilt.android.compiler)
|
||||||
|
|||||||
@@ -1,190 +0,0 @@
|
|||||||
{
|
|
||||||
"formatVersion": 1,
|
|
||||||
"database": {
|
|
||||||
"version": 8,
|
|
||||||
"identityHash": "b4d4a7c489f6b2f0d3aa4fa6f37b4935",
|
|
||||||
"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_auto_tunnel_paused` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_amnezia_enabled` INTEGER NOT NULL DEFAULT false)",
|
|
||||||
"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": "isAutoTunnelPaused",
|
|
||||||
"columnName": "is_auto_tunnel_paused",
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": true,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [],
|
|
||||||
"foreignKeys": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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 '')",
|
|
||||||
"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": "''"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"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`)"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"foreignKeys": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"views": [],
|
|
||||||
"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, 'b4d4a7c489f6b2f0d3aa4fa6f37b4935')"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,14 +2,13 @@ package com.zaneschepke.wireguardautotunnel
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.service.quicksettings.TileService
|
import android.service.quicksettings.TileService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tile.AutoTunnelControlTile
|
import com.zaneschepke.wireguardautotunnel.service.tile.AutoTunnelControlTile
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tile.TunnelControlTile
|
import com.zaneschepke.wireguardautotunnel.service.tile.TunnelControlTile
|
||||||
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
import kotlinx.coroutines.MainScope
|
|
||||||
import kotlinx.coroutines.cancel
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import xyz.teamgravity.pin_lock_compose.PinManager
|
import xyz.teamgravity.pin_lock_compose.PinManager
|
||||||
|
|
||||||
@@ -22,16 +21,7 @@ class WireGuardAutoTunnel : Application() {
|
|||||||
PinManager.initialize(this)
|
PinManager.initialize(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLowMemory() {
|
|
||||||
super.onLowMemory()
|
|
||||||
applicationScope.cancel("onLowMemory() called by system")
|
|
||||||
applicationScope = MainScope()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
var applicationScope = MainScope()
|
|
||||||
|
|
||||||
lateinit var instance: WireGuardAutoTunnel
|
lateinit var instance: WireGuardAutoTunnel
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@@ -39,16 +29,16 @@ class WireGuardAutoTunnel : Application() {
|
|||||||
return instance.packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
|
return instance.packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requestTunnelTileServiceStateUpdate() {
|
fun requestTunnelTileServiceStateUpdate(context: Context) {
|
||||||
TileService.requestListeningState(
|
TileService.requestListeningState(
|
||||||
instance,
|
context,
|
||||||
ComponentName(instance, TunnelControlTile::class.java),
|
ComponentName(instance, TunnelControlTile::class.java),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requestAutoTunnelTileServiceUpdate() {
|
fun requestAutoTunnelTileServiceUpdate(context: Context) {
|
||||||
TileService.requestListeningState(
|
TileService.requestListeningState(
|
||||||
instance,
|
context,
|
||||||
ComponentName(instance, AutoTunnelControlTile::class.java),
|
ComponentName(instance, AutoTunnelControlTile::class.java),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import androidx.room.DeleteColumn
|
|||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.TypeConverters
|
import androidx.room.TypeConverters
|
||||||
import androidx.room.migration.AutoMigrationSpec
|
import androidx.room.migration.AutoMigrationSpec
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities = [Settings::class, TunnelConfig::class],
|
entities = [Settings::class, TunnelConfig::class],
|
||||||
version = 8,
|
version = 7,
|
||||||
autoMigrations =
|
autoMigrations =
|
||||||
[
|
[
|
||||||
AutoMigration(from = 1, to = 2),
|
AutoMigration(from = 1, to = 2),
|
||||||
@@ -33,7 +33,6 @@ import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
|||||||
to = 7,
|
to = 7,
|
||||||
spec = RemoveLegacySettingColumnsMigration::class,
|
spec = RemoveLegacySettingColumnsMigration::class,
|
||||||
),
|
),
|
||||||
AutoMigration(7, 8)
|
|
||||||
],
|
],
|
||||||
exportSchema = true,
|
exportSchema = true,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.room.Delete
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.room.Delete
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.util.TunnelConfigs
|
import com.zaneschepke.wireguardautotunnel.util.TunnelConfigs
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@@ -20,9 +20,6 @@ interface TunnelConfigDao {
|
|||||||
@Query("SELECT * FROM TunnelConfig WHERE id=:id")
|
@Query("SELECT * FROM TunnelConfig WHERE id=:id")
|
||||||
suspend fun getById(id: Long): TunnelConfig?
|
suspend fun getById(id: Long): TunnelConfig?
|
||||||
|
|
||||||
@Query("SELECT * FROM TunnelConfig WHERE name=:name")
|
|
||||||
suspend fun getByName(name: String) : TunnelConfig?
|
|
||||||
|
|
||||||
@Query("SELECT * FROM TunnelConfig")
|
@Query("SELECT * FROM TunnelConfig")
|
||||||
suspend fun getAll(): TunnelConfigs
|
suspend fun getAll(): TunnelConfigs
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.domain
|
package com.zaneschepke.wireguardautotunnel.data.model
|
||||||
|
|
||||||
data class GeneralState(
|
data class GeneralState(
|
||||||
val locationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
val locationDisclosureShown: Boolean = LOCATION_DISCLOSURE_SHOWN_DEFAULT,
|
||||||
+1
-6
@@ -1,4 +1,4 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.domain
|
package com.zaneschepke.wireguardautotunnel.data.model
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
@@ -50,9 +50,4 @@ data class Settings(
|
|||||||
defaultValue = "false",
|
defaultValue = "false",
|
||||||
)
|
)
|
||||||
val isPingEnabled: Boolean = false,
|
val isPingEnabled: Boolean = false,
|
||||||
@ColumnInfo(
|
|
||||||
name = "is_amnezia_enabled",
|
|
||||||
defaultValue = "false",
|
|
||||||
)
|
|
||||||
val isAmneziaEnabled: Boolean = false,
|
|
||||||
)
|
)
|
||||||
+5
-18
@@ -1,10 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.domain
|
package com.zaneschepke.wireguardautotunnel.data.model
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.wireguard.config.Config
|
import org.amnezia.awg.config.Config
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
@Entity(indices = [Index(value = ["name"], unique = true)])
|
@Entity(indices = [Index(value = ["name"], unique = true)])
|
||||||
@@ -27,25 +27,12 @@ data class TunnelConfig(
|
|||||||
defaultValue = "false",
|
defaultValue = "false",
|
||||||
)
|
)
|
||||||
val isPrimaryTunnel: Boolean = false,
|
val isPrimaryTunnel: Boolean = false,
|
||||||
@ColumnInfo(
|
|
||||||
name = "am_quick",
|
|
||||||
defaultValue = "",
|
|
||||||
)
|
|
||||||
val amQuick: String = AM_QUICK_DEFAULT,
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun configFromWgQuick(wgQuick: String): Config {
|
fun configFromQuick(wgQuick: String): Config {
|
||||||
val inputStream: InputStream = wgQuick.byteInputStream()
|
val inputStream: InputStream = wgQuick.byteInputStream()
|
||||||
return inputStream.bufferedReader(Charsets.UTF_8).use {
|
val reader = inputStream.bufferedReader(Charsets.UTF_8)
|
||||||
Config.parse(it)
|
return Config.parse(reader)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fun configFromAmQuick(amQuick: String) : org.amnezia.awg.config.Config {
|
|
||||||
val inputStream: InputStream = amQuick.byteInputStream()
|
|
||||||
return inputStream.bufferedReader(Charsets.UTF_8).use {
|
|
||||||
org.amnezia.awg.config.Config.parse(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const val AM_QUICK_DEFAULT = ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
|
|
||||||
interface AppDataRepository {
|
interface AppDataRepository {
|
||||||
suspend fun getPrimaryOrFirstTunnel(): TunnelConfig?
|
suspend fun getPrimaryOrFirstTunnel(): TunnelConfig?
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class AppDataRoomRepository @Inject constructor(
|
class AppDataRoomRepository @Inject constructor(
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.GeneralState
|
import com.zaneschepke.wireguardautotunnel.data.model.GeneralState
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface AppStateRepository {
|
interface AppStateRepository {
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.datastore.DataStoreManager
|
import com.zaneschepke.wireguardautotunnel.data.datastore.DataStoreManager
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.GeneralState
|
import com.zaneschepke.wireguardautotunnel.data.model.GeneralState
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.SettingsDao
|
import com.zaneschepke.wireguardautotunnel.data.SettingsDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
class RoomSettingsRepository(private val settingsDoa: SettingsDao) : SettingsRepository {
|
class RoomSettingsRepository(private val settingsDoa: SettingsDao) : SettingsRepository {
|
||||||
|
|||||||
+1
-5
@@ -1,7 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.data.TunnelConfigDao
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.util.TunnelConfigs
|
import com.zaneschepke.wireguardautotunnel.util.TunnelConfigs
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@@ -54,10 +54,6 @@ class RoomTunnelConfigRepository(private val tunnelConfigDao: TunnelConfigDao) :
|
|||||||
return tunnelConfigDao.count().toInt()
|
return tunnelConfigDao.count().toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByTunnelName(name: String): TunnelConfig? {
|
|
||||||
return tunnelConfigDao.getByName(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun findByTunnelNetworksName(name: String): TunnelConfigs {
|
override suspend fun findByTunnelNetworksName(name: String): TunnelConfigs {
|
||||||
return tunnelConfigDao.findByTunnelNetworkName(name)
|
return tunnelConfigDao.findByTunnelNetworkName(name)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface SettingsRepository {
|
interface SettingsRepository {
|
||||||
|
|||||||
+1
-3
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.util.TunnelConfigs
|
import com.zaneschepke.wireguardautotunnel.util.TunnelConfigs
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@@ -22,8 +22,6 @@ interface TunnelConfigRepository {
|
|||||||
|
|
||||||
suspend fun count(): Int
|
suspend fun count(): Int
|
||||||
|
|
||||||
suspend fun findByTunnelName(name : String) : TunnelConfig?
|
|
||||||
|
|
||||||
suspend fun findByTunnelNetworksName(name: String): TunnelConfigs
|
suspend fun findByTunnelNetworksName(name: String): TunnelConfigs
|
||||||
|
|
||||||
suspend fun findByMobileDataTunnel(): TunnelConfigs
|
suspend fun findByMobileDataTunnel(): TunnelConfigs
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.module
|
package com.zaneschepke.wireguardautotunnel.module
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.wireguard.android.backend.Backend
|
|
||||||
import com.wireguard.android.backend.GoBackend
|
|
||||||
import com.wireguard.android.backend.WgQuickBackend
|
|
||||||
import com.wireguard.android.util.RootShell
|
|
||||||
import com.wireguard.android.util.ToolsInstaller
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
@@ -15,6 +10,11 @@ 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 org.amnezia.awg.backend.AwgQuickBackend
|
||||||
|
import org.amnezia.awg.backend.Backend
|
||||||
|
import org.amnezia.awg.backend.GoBackend
|
||||||
|
import org.amnezia.awg.util.RootShell
|
||||||
|
import org.amnezia.awg.util.ToolsInstaller
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@@ -37,24 +37,17 @@ class TunnelModule {
|
|||||||
@Singleton
|
@Singleton
|
||||||
@Kernel
|
@Kernel
|
||||||
fun provideKernelBackend(@ApplicationContext context: Context, rootShell: RootShell): Backend {
|
fun provideKernelBackend(@ApplicationContext context: Context, rootShell: RootShell): Backend {
|
||||||
return WgQuickBackend(context, rootShell, ToolsInstaller(context, rootShell))
|
return AwgQuickBackend(context, rootShell, ToolsInstaller(context, rootShell))
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideAmneziaBackend(@ApplicationContext context: Context) : org.amnezia.awg.backend.Backend {
|
|
||||||
return org.amnezia.awg.backend.GoBackend(context)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideVpnService(
|
fun provideVpnService(
|
||||||
amneziaBackend: org.amnezia.awg.backend.Backend,
|
|
||||||
@Userspace userspaceBackend: Backend,
|
@Userspace userspaceBackend: Backend,
|
||||||
@Kernel kernelBackend: Backend,
|
@Kernel kernelBackend: Backend,
|
||||||
appDataRepository: AppDataRepository
|
appDataRepository: AppDataRepository
|
||||||
): VpnService {
|
): VpnService {
|
||||||
return WireGuardTunnel(amneziaBackend,userspaceBackend, kernelBackend, appDataRepository)
|
return WireGuardTunnel(userspaceBackend, kernelBackend, appDataRepository)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
+31
-10
@@ -1,63 +1,84 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.foreground
|
package com.zaneschepke.wireguardautotunnel.service.foreground
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
|
import org.amnezia.awg.backend.Tunnel
|
||||||
|
|
||||||
data class WatcherState(
|
data class WatcherState(
|
||||||
val isWifiConnected: Boolean = false,
|
val isWifiConnected: Boolean = false,
|
||||||
|
val config: TunnelConfig? = null,
|
||||||
|
val vpnStatus: Tunnel.State = Tunnel.State.DOWN,
|
||||||
val isEthernetConnected: Boolean = false,
|
val isEthernetConnected: Boolean = false,
|
||||||
val isMobileDataConnected: Boolean = false,
|
val isMobileDataConnected: Boolean = false,
|
||||||
val currentNetworkSSID: String = "",
|
val currentNetworkSSID: String = "",
|
||||||
val settings: Settings = Settings()
|
val settings: Settings = Settings()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
private fun isVpnConnected() = vpnStatus == Tunnel.State.UP
|
||||||
fun isEthernetConditionMet(): Boolean {
|
fun isEthernetConditionMet(): Boolean {
|
||||||
return (isEthernetConnected &&
|
return (isEthernetConnected &&
|
||||||
settings.isTunnelOnEthernetEnabled)
|
settings.isTunnelOnEthernetEnabled &&
|
||||||
|
!isVpnConnected())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isMobileDataConditionMet(): Boolean {
|
fun isMobileDataConditionMet(): Boolean {
|
||||||
return (!isEthernetConnected &&
|
return (!isEthernetConnected &&
|
||||||
settings.isTunnelOnMobileDataEnabled &&
|
settings.isTunnelOnMobileDataEnabled &&
|
||||||
!isWifiConnected &&
|
!isWifiConnected &&
|
||||||
isMobileDataConnected)
|
isMobileDataConnected &&
|
||||||
|
!isVpnConnected())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isTunnelOnMobileDataPreferredConditionMet(): Boolean {
|
fun isTunnelNotMobileDataPreferredConditionMet(): Boolean {
|
||||||
return (!isEthernetConnected &&
|
return (!isEthernetConnected &&
|
||||||
settings.isTunnelOnMobileDataEnabled &&
|
settings.isTunnelOnMobileDataEnabled &&
|
||||||
!isWifiConnected &&
|
!isWifiConnected &&
|
||||||
isMobileDataConnected)
|
isMobileDataConnected &&
|
||||||
|
config?.isMobileDataTunnel == false && isVpnConnected())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isTunnelOffOnMobileDataConditionMet(): Boolean {
|
fun isTunnelOffOnMobileDataConditionMet(): Boolean {
|
||||||
return (!isEthernetConnected &&
|
return (!isEthernetConnected &&
|
||||||
!settings.isTunnelOnMobileDataEnabled &&
|
!settings.isTunnelOnMobileDataEnabled &&
|
||||||
isMobileDataConnected &&
|
isMobileDataConnected &&
|
||||||
!isWifiConnected)
|
!isWifiConnected &&
|
||||||
|
isVpnConnected())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isUntrustedWifiConditionMet(): Boolean {
|
fun isUntrustedWifiConditionMet(): Boolean {
|
||||||
return (!isEthernetConnected &&
|
return (!isEthernetConnected &&
|
||||||
isWifiConnected &&
|
isWifiConnected &&
|
||||||
!settings.trustedNetworkSSIDs.contains(currentNetworkSSID) &&
|
!settings.trustedNetworkSSIDs.contains(currentNetworkSSID) &&
|
||||||
settings.isTunnelOnWifiEnabled)
|
settings.isTunnelOnWifiEnabled
|
||||||
|
&& !isVpnConnected())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isTunnelNotWifiNamePreferredMet(ssid: String): Boolean {
|
||||||
|
return (!isEthernetConnected &&
|
||||||
|
isWifiConnected &&
|
||||||
|
!settings.trustedNetworkSSIDs.contains(currentNetworkSSID) &&
|
||||||
|
settings.isTunnelOnWifiEnabled && config?.tunnelNetworks?.contains(ssid) == false && isVpnConnected())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isTrustedWifiConditionMet(): Boolean {
|
fun isTrustedWifiConditionMet(): Boolean {
|
||||||
return (!isEthernetConnected &&
|
return (!isEthernetConnected &&
|
||||||
(isWifiConnected &&
|
(isWifiConnected &&
|
||||||
settings.trustedNetworkSSIDs.contains(currentNetworkSSID)))
|
settings.trustedNetworkSSIDs.contains(currentNetworkSSID)) &&
|
||||||
|
(isVpnConnected()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isTunnelOffOnWifiConditionMet(): Boolean {
|
fun isTunnelOffOnWifiConditionMet(): Boolean {
|
||||||
return (!isEthernetConnected &&
|
return (!isEthernetConnected &&
|
||||||
(isWifiConnected &&
|
(isWifiConnected &&
|
||||||
!settings.isTunnelOnWifiEnabled))
|
!settings.isTunnelOnWifiEnabled &&
|
||||||
|
(isVpnConnected())))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isTunnelOffOnNoConnectivityMet(): Boolean {
|
fun isTunnelOffOnNoConnectivityMet(): Boolean {
|
||||||
return (!isEthernetConnected &&
|
return (!isEthernetConnected &&
|
||||||
!isWifiConnected &&
|
!isWifiConnected &&
|
||||||
!isMobileDataConnected)
|
!isMobileDataConnected &&
|
||||||
|
(isVpnConnected()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+89
-88
@@ -6,7 +6,7 @@ import android.os.PowerManager
|
|||||||
import androidx.core.app.ServiceCompat
|
import androidx.core.app.ServiceCompat
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.EthernetService
|
import com.zaneschepke.wireguardautotunnel.service.network.EthernetService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.MobileDataService
|
import com.zaneschepke.wireguardautotunnel.service.network.MobileDataService
|
||||||
@@ -14,7 +14,6 @@ import com.zaneschepke.wireguardautotunnel.service.network.NetworkService
|
|||||||
import com.zaneschepke.wireguardautotunnel.service.network.NetworkStatus
|
import com.zaneschepke.wireguardautotunnel.service.network.NetworkStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.WifiService
|
import com.zaneschepke.wireguardautotunnel.service.network.WifiService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.notification.NotificationService
|
import com.zaneschepke.wireguardautotunnel.service.notification.NotificationService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
@@ -24,8 +23,8 @@ import kotlinx.coroutines.Job
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.amnezia.awg.backend.Tunnel
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -163,6 +162,10 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
watchForEthernetConnectivityChanges()
|
watchForEthernetConnectivityChanges()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
launch {
|
||||||
|
Timber.i("Starting vpn state watcher")
|
||||||
|
watchForVpnConnectivityChanges()
|
||||||
|
}
|
||||||
launch {
|
launch {
|
||||||
Timber.i("Starting settings watcher")
|
Timber.i("Starting settings watcher")
|
||||||
watchForSettingsChanges()
|
watchForSettingsChanges()
|
||||||
@@ -182,32 +185,29 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun watchForMobileDataConnectivityChanges() {
|
private suspend fun watchForMobileDataConnectivityChanges() {
|
||||||
mobileDataService.networkStatus.collect { status ->
|
mobileDataService.networkStatus.collect {
|
||||||
when (status) {
|
when (it) {
|
||||||
is NetworkStatus.Available -> {
|
is NetworkStatus.Available -> {
|
||||||
Timber.i("Gained Mobile data connection")
|
Timber.i("Gained Mobile data connection")
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
isMobileDataConnected = true,
|
isMobileDataConnected = true,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.CapabilitiesChanged -> {
|
is NetworkStatus.CapabilitiesChanged -> {
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
isMobileDataConnected = true,
|
isMobileDataConnected = true,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
Timber.i("Mobile data capabilities changed")
|
Timber.i("Mobile data capabilities changed")
|
||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.Unavailable -> {
|
is NetworkStatus.Unavailable -> {
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
isMobileDataConnected = false,
|
isMobileDataConnected = false,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
Timber.i("Lost mobile data connection")
|
Timber.i("Lost mobile data connection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,15 +217,15 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
private suspend fun watchForPingFailure() {
|
private suspend fun watchForPingFailure() {
|
||||||
try {
|
try {
|
||||||
do {
|
do {
|
||||||
if (vpnService.vpnState.value.status == TunnelState.UP) {
|
if (vpnService.vpnState.value.status == Tunnel.State.UP) {
|
||||||
val tunnelConfig = vpnService.vpnState.value.tunnelConfig
|
val tunnelConfig = vpnService.vpnState.value.tunnelConfig
|
||||||
tunnelConfig?.let {
|
tunnelConfig?.let {
|
||||||
val config = TunnelConfig.configFromWgQuick(it.wgQuick)
|
val config = TunnelConfig.configFromQuick(it.wgQuick)
|
||||||
val results = config.peers.map { peer ->
|
val results = config.peers.map { peer ->
|
||||||
val host = if (peer.endpoint.isPresent &&
|
val host = if (peer.endpoint.isPresent &&
|
||||||
peer.endpoint.get().resolved.isPresent)
|
peer.endpoint.get().resolved.isPresent)
|
||||||
peer.endpoint.get().resolved.get().host
|
peer.endpoint.get().resolved.get().host
|
||||||
else Constants.DEFAULT_PING_IP
|
else Constants.BACKUP_PING_HOST
|
||||||
Timber.i("Checking reachability of: $host")
|
Timber.i("Checking reachability of: $host")
|
||||||
val reachable = InetAddress.getByName(host)
|
val reachable = InetAddress.getByName(host)
|
||||||
.isReachable(Constants.PING_TIMEOUT.toInt())
|
.isReachable(Constants.PING_TIMEOUT.toInt())
|
||||||
@@ -236,7 +236,7 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
Timber.i("Restarting VPN for ping failure")
|
Timber.i("Restarting VPN for ping failure")
|
||||||
serviceManager.stopVpnServiceForeground(this)
|
serviceManager.stopVpnServiceForeground(this)
|
||||||
delay(Constants.VPN_RESTART_DELAY)
|
delay(Constants.VPN_RESTART_DELAY)
|
||||||
serviceManager.startVpnServiceForeground(this, it.id)
|
serviceManager.startVpnServiceForeground(this)
|
||||||
delay(Constants.PING_COOLDOWN)
|
delay(Constants.PING_COOLDOWN)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,48 +249,54 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun watchForSettingsChanges() {
|
private suspend fun watchForSettingsChanges() {
|
||||||
appDataRepository.settings.getSettingsFlow().collect { settings ->
|
appDataRepository.settings.getSettingsFlow().collect {
|
||||||
if (networkEventsFlow.value.settings.isAutoTunnelPaused != settings.isAutoTunnelPaused) {
|
if (networkEventsFlow.value.settings.isAutoTunnelPaused != it.isAutoTunnelPaused) {
|
||||||
when (settings.isAutoTunnelPaused) {
|
when (it.isAutoTunnelPaused) {
|
||||||
true -> launchWatcherPausedNotification()
|
true -> launchWatcherPausedNotification()
|
||||||
false -> launchWatcherNotification()
|
false -> launchWatcherNotification()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
settings = settings,
|
settings = it,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun watchForVpnConnectivityChanges() {
|
||||||
|
vpnService.vpnState.collect {
|
||||||
|
networkEventsFlow.value =
|
||||||
|
networkEventsFlow.value.copy(
|
||||||
|
vpnStatus = it.status,
|
||||||
|
config = it.tunnelConfig,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun watchForEthernetConnectivityChanges() {
|
private suspend fun watchForEthernetConnectivityChanges() {
|
||||||
ethernetService.networkStatus.collect { status ->
|
ethernetService.networkStatus.collect {
|
||||||
when (status) {
|
when (it) {
|
||||||
is NetworkStatus.Available -> {
|
is NetworkStatus.Available -> {
|
||||||
Timber.i("Gained Ethernet connection")
|
Timber.i("Gained Ethernet connection")
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
isEthernetConnected = true,
|
isEthernetConnected = true,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.CapabilitiesChanged -> {
|
is NetworkStatus.CapabilitiesChanged -> {
|
||||||
Timber.i("Ethernet capabilities changed")
|
Timber.i("Ethernet capabilities changed")
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
isEthernetConnected = true,
|
isEthernetConnected = true,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.Unavailable -> {
|
is NetworkStatus.Unavailable -> {
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
isEthernetConnected = false,
|
isEthernetConnected = false,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
Timber.i("Lost Ethernet connection")
|
Timber.i("Lost Ethernet connection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,43 +304,40 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun watchForWifiConnectivityChanges() {
|
private suspend fun watchForWifiConnectivityChanges() {
|
||||||
wifiService.networkStatus.collect { status ->
|
wifiService.networkStatus.collect {
|
||||||
when (status) {
|
when (it) {
|
||||||
is NetworkStatus.Available -> {
|
is NetworkStatus.Available -> {
|
||||||
Timber.i("Gained Wi-Fi connection")
|
Timber.i("Gained Wi-Fi connection")
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
isWifiConnected = true,
|
isWifiConnected = true,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.CapabilitiesChanged -> {
|
is NetworkStatus.CapabilitiesChanged -> {
|
||||||
Timber.i("Wifi capabilities changed")
|
Timber.i("Wifi capabilities changed")
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
isWifiConnected = true,
|
isWifiConnected = true,
|
||||||
)
|
)
|
||||||
}
|
val ssid = wifiService.getNetworkName(it.networkCapabilities)
|
||||||
val ssid = wifiService.getNetworkName(status.networkCapabilities)
|
ssid?.let {
|
||||||
ssid?.let { name ->
|
if(it.contains(Constants.UNREADABLE_SSID)) {
|
||||||
if(name.contains(Constants.UNREADABLE_SSID)) {
|
|
||||||
Timber.w("SSID unreadable: missing permissions")
|
Timber.w("SSID unreadable: missing permissions")
|
||||||
} else Timber.i("Detected valid SSID")
|
} else Timber.i("Detected valid SSID")
|
||||||
appDataRepository.appState.setCurrentSsid(name)
|
appDataRepository.appState.setCurrentSsid(ssid)
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
currentNetworkSSID = name,
|
currentNetworkSSID = ssid,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
} ?: Timber.w("Failed to read ssid")
|
} ?: Timber.w("Failed to read ssid")
|
||||||
}
|
}
|
||||||
|
|
||||||
is NetworkStatus.Unavailable -> {
|
is NetworkStatus.Unavailable -> {
|
||||||
networkEventsFlow.update {
|
networkEventsFlow.value =
|
||||||
it.copy(
|
networkEventsFlow.value.copy(
|
||||||
isWifiConnected = false,
|
isWifiConnected = false,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
Timber.i("Lost Wi-Fi connection")
|
Timber.i("Lost Wi-Fi connection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -349,74 +352,72 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
return appDataRepository.tunnels.findByTunnelNetworksName(ssid).firstOrNull()
|
return appDataRepository.tunnels.findByTunnelNetworksName(ssid).firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isTunnelDown() : Boolean {
|
|
||||||
return vpnService.vpnState.value.status == TunnelState.DOWN
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun manageVpn() {
|
private suspend fun manageVpn() {
|
||||||
networkEventsFlow.collectLatest { watcherState ->
|
networkEventsFlow.collectLatest { watcherState ->
|
||||||
val autoTunnel = "Auto-tunnel watcher"
|
val autoTunnel = "Auto-tunnel watcher"
|
||||||
if (!watcherState.settings.isAutoTunnelPaused) {
|
if (!watcherState.settings.isAutoTunnelPaused) {
|
||||||
//delay for rapid network state changes and then collect latest
|
//delay for rapid network state changes and then collect latest
|
||||||
delay(Constants.WATCHER_COLLECTION_DELAY)
|
delay(Constants.WATCHER_COLLECTION_DELAY)
|
||||||
val tunnelConfig = vpnService.vpnState.value.tunnelConfig
|
|
||||||
when {
|
when {
|
||||||
watcherState.isEthernetConditionMet() -> {
|
watcherState.isEthernetConditionMet() -> {
|
||||||
Timber.i("$autoTunnel - tunnel on on ethernet condition met")
|
Timber.i("$autoTunnel - tunnel on on ethernet condition met")
|
||||||
if(isTunnelDown()) serviceManager.startVpnServiceForeground(this)
|
serviceManager.startVpnServiceForeground(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
watcherState.isMobileDataConditionMet() -> {
|
watcherState.isMobileDataConditionMet() -> {
|
||||||
Timber.i("$autoTunnel - tunnel on on mobile data condition met")
|
Timber.i("$autoTunnel - tunnel on on mobile data condition met")
|
||||||
if(isTunnelDown()) serviceManager.startVpnServiceForeground(this, getMobileDataTunnel()?.id)
|
serviceManager.startVpnServiceForeground(this, getMobileDataTunnel()?.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
watcherState.isTunnelOnMobileDataPreferredConditionMet() -> {
|
watcherState.isTunnelNotMobileDataPreferredConditionMet() -> {
|
||||||
if(tunnelConfig?.isMobileDataTunnel == false) {
|
getMobileDataTunnel()?.let {
|
||||||
getMobileDataTunnel()?.let {
|
Timber.i("$autoTunnel - tunnel connected on mobile data is not preferred condition met, switching to preferred")
|
||||||
Timber.i("$autoTunnel - tunnel connected on mobile data is not preferred condition met, switching to preferred")
|
serviceManager.startVpnServiceForeground(
|
||||||
if(isTunnelDown()) serviceManager.startVpnServiceForeground(
|
this,
|
||||||
this,
|
getMobileDataTunnel()?.id,
|
||||||
getMobileDataTunnel()?.id,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watcherState.isTunnelOffOnMobileDataConditionMet() -> {
|
watcherState.isTunnelOffOnMobileDataConditionMet() -> {
|
||||||
Timber.i("$autoTunnel - tunnel off on mobile data met, turning vpn off")
|
Timber.i("$autoTunnel - tunnel off on mobile data met, turning vpn off")
|
||||||
if(!isTunnelDown()) serviceManager.stopVpnServiceForeground(this)
|
serviceManager.stopVpnServiceForeground(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
watcherState.isTunnelNotWifiNamePreferredMet(watcherState.currentNetworkSSID) -> {
|
||||||
|
Timber.i("$autoTunnel - tunnel on ssid not associated with current tunnel condition met")
|
||||||
|
getSsidTunnel(watcherState.currentNetworkSSID)?.let {
|
||||||
|
Timber.i("Found tunnel associated with this SSID, bringing tunnel up")
|
||||||
|
serviceManager.startVpnServiceForeground(this, it.id)
|
||||||
|
} ?: suspend {
|
||||||
|
Timber.i("No tunnel associated with this SSID, using defaults")
|
||||||
|
if (appDataRepository.getPrimaryOrFirstTunnel()?.name != vpnService.name) {
|
||||||
|
serviceManager.startVpnServiceForeground(this)
|
||||||
|
}
|
||||||
|
}.invoke()
|
||||||
}
|
}
|
||||||
|
|
||||||
watcherState.isUntrustedWifiConditionMet() -> {
|
watcherState.isUntrustedWifiConditionMet() -> {
|
||||||
if(tunnelConfig?.tunnelNetworks?.contains(watcherState.currentNetworkSSID) == false ||
|
Timber.i("$autoTunnel - tunnel on untrusted wifi condition met")
|
||||||
tunnelConfig == null) {
|
serviceManager.startVpnServiceForeground(
|
||||||
Timber.i("$autoTunnel - tunnel on ssid not associated with current tunnel condition met")
|
this,
|
||||||
getSsidTunnel(watcherState.currentNetworkSSID)?.let {
|
getSsidTunnel(watcherState.currentNetworkSSID)?.id,
|
||||||
Timber.i("Found tunnel associated with this SSID, bringing tunnel up")
|
)
|
||||||
if(isTunnelDown()) serviceManager.startVpnServiceForeground(this, it.id)
|
|
||||||
} ?: suspend {
|
|
||||||
Timber.i("No tunnel associated with this SSID, using defaults")
|
|
||||||
if (appDataRepository.getPrimaryOrFirstTunnel()?.name != vpnService.name) {
|
|
||||||
if(isTunnelDown()) serviceManager.startVpnServiceForeground(this)
|
|
||||||
}
|
|
||||||
}.invoke()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watcherState.isTrustedWifiConditionMet() -> {
|
watcherState.isTrustedWifiConditionMet() -> {
|
||||||
Timber.i("$autoTunnel - tunnel off on trusted wifi condition met, turning vpn off")
|
Timber.i("$autoTunnel - tunnel off on trusted wifi condition met, turning vpn off")
|
||||||
if(!isTunnelDown()) serviceManager.stopVpnServiceForeground(this)
|
serviceManager.stopVpnServiceForeground(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
watcherState.isTunnelOffOnWifiConditionMet() -> {
|
watcherState.isTunnelOffOnWifiConditionMet() -> {
|
||||||
Timber.i("$autoTunnel - tunnel off on wifi condition met, turning vpn off")
|
Timber.i("$autoTunnel - tunnel off on wifi condition met, turning vpn off")
|
||||||
if(!isTunnelDown()) serviceManager.stopVpnServiceForeground(this)
|
serviceManager.stopVpnServiceForeground(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
watcherState.isTunnelOffOnNoConnectivityMet() -> {
|
watcherState.isTunnelOffOnNoConnectivityMet() -> {
|
||||||
Timber.i("$autoTunnel - tunnel off on no connectivity met, turning vpn off")
|
Timber.i("$autoTunnel - tunnel off on no connectivity met, turning vpn off")
|
||||||
if(!isTunnelDown()) serviceManager.stopVpnServiceForeground(this)
|
serviceManager.stopVpnServiceForeground(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
|
|||||||
+4
-4
@@ -10,7 +10,6 @@ import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
|||||||
import com.zaneschepke.wireguardautotunnel.receiver.NotificationActionReceiver
|
import com.zaneschepke.wireguardautotunnel.receiver.NotificationActionReceiver
|
||||||
import com.zaneschepke.wireguardautotunnel.service.notification.NotificationService
|
import com.zaneschepke.wireguardautotunnel.service.notification.NotificationService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.handshakeStatus
|
import com.zaneschepke.wireguardautotunnel.util.handshakeStatus
|
||||||
@@ -21,6 +20,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.amnezia.awg.backend.Tunnel
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ class WireGuardTunnelService : ForegroundService() {
|
|||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
launch {
|
launch {
|
||||||
val tunnelId = extras?.getInt(Constants.TUNNEL_EXTRA_KEY)
|
val tunnelId = extras?.getInt(Constants.TUNNEL_EXTRA_KEY)
|
||||||
if (vpnService.getState() == TunnelState.UP) {
|
if (vpnService.getState() == Tunnel.State.UP) {
|
||||||
vpnService.stopTunnel()
|
vpnService.stopTunnel()
|
||||||
}
|
}
|
||||||
vpnService.startTunnel(
|
vpnService.startTunnel(
|
||||||
@@ -77,7 +77,7 @@ class WireGuardTunnelService : ForegroundService() {
|
|||||||
private suspend fun handshakeNotifications() {
|
private suspend fun handshakeNotifications() {
|
||||||
var tunnelName: String? = null
|
var tunnelName: String? = null
|
||||||
vpnService.vpnState.collect { state ->
|
vpnService.vpnState.collect { state ->
|
||||||
state.statistics
|
state.statistics
|
||||||
?.mapPeerStats()
|
?.mapPeerStats()
|
||||||
?.map { it.value?.handshakeStatus() }
|
?.map { it.value?.handshakeStatus() }
|
||||||
.let { statuses ->
|
.let { statuses ->
|
||||||
@@ -102,7 +102,7 @@ class WireGuardTunnelService : ForegroundService() {
|
|||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (state.status == TunnelState.UP && state.tunnelConfig?.name != tunnelName) {
|
if (state.status == Tunnel.State.UP && state.tunnelConfig?.name != tunnelName) {
|
||||||
tunnelName = state.tunnelConfig?.name
|
tunnelName = state.tunnelConfig?.name
|
||||||
launchVpnNotification(
|
launchVpnNotification(
|
||||||
getString(R.string.tunnel_start_title),
|
getString(R.string.tunnel_start_title),
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@ package com.zaneschepke.wireguardautotunnel.service.shortcut
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
@@ -24,7 +24,7 @@ class ShortcutsActivity : ComponentActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
WireGuardAutoTunnel.applicationScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.Main) {
|
||||||
val settings = appDataRepository.settings.getSettings()
|
val settings = appDataRepository.settings.getSettings()
|
||||||
if (settings.isShortcutsEnabled) {
|
if (settings.isShortcutsEnabled) {
|
||||||
when (intent.getStringExtra(CLASS_NAME_EXTRA_KEY)) {
|
when (intent.getStringExtra(CLASS_NAME_EXTRA_KEY)) {
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ import android.os.Build
|
|||||||
import android.service.quicksettings.Tile
|
import android.service.quicksettings.Tile
|
||||||
import android.service.quicksettings.TileService
|
import android.service.quicksettings.TileService
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|||||||
+6
-5
@@ -3,16 +3,16 @@ package com.zaneschepke.wireguardautotunnel.service.tile
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.service.quicksettings.Tile
|
import android.service.quicksettings.Tile
|
||||||
import android.service.quicksettings.TileService
|
import android.service.quicksettings.TileService
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.amnezia.awg.backend.Tunnel
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -38,12 +38,12 @@ class TunnelControlTile : TileService() {
|
|||||||
scope.launch {
|
scope.launch {
|
||||||
vpnService.vpnState.collect { it ->
|
vpnService.vpnState.collect { it ->
|
||||||
when (it.status) {
|
when (it.status) {
|
||||||
TunnelState.UP -> {
|
Tunnel.State.UP -> {
|
||||||
setActive()
|
setActive()
|
||||||
it.tunnelConfig?.name?.let { name -> setTileDescription(name) }
|
it.tunnelConfig?.name?.let { name -> setTileDescription(name) }
|
||||||
}
|
}
|
||||||
|
|
||||||
TunnelState.DOWN -> {
|
Tunnel.State.DOWN -> {
|
||||||
setInactive()
|
setInactive()
|
||||||
val config = appDataRepository.getStartTunnelConfig()?.also { config ->
|
val config = appDataRepository.getStartTunnelConfig()?.also { config ->
|
||||||
manualStartConfig = config
|
manualStartConfig = config
|
||||||
@@ -52,6 +52,7 @@ class TunnelControlTile : TileService() {
|
|||||||
setTileDescription(it.name)
|
setTileDescription(it.name)
|
||||||
} ?: setUnavailable()
|
} ?: setUnavailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> setInactive()
|
else -> setInactive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +79,7 @@ class TunnelControlTile : TileService() {
|
|||||||
unlockAndRun {
|
unlockAndRun {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
try {
|
try {
|
||||||
if (vpnService.getState() == TunnelState.UP) {
|
if (vpnService.getState() == Tunnel.State.UP) {
|
||||||
serviceManager.stopVpnServiceForeground(
|
serviceManager.stopVpnServiceForeground(
|
||||||
this@TunnelControlTile,
|
this@TunnelControlTile,
|
||||||
isManualStop = true,
|
isManualStop = true,
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.tunnel
|
|
||||||
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
|
||||||
|
|
||||||
enum class TunnelState {
|
|
||||||
UP,
|
|
||||||
DOWN,
|
|
||||||
TOGGLE;
|
|
||||||
|
|
||||||
fun toWgState() : Tunnel.State {
|
|
||||||
return when(this) {
|
|
||||||
UP -> Tunnel.State.UP
|
|
||||||
DOWN -> Tunnel.State.DOWN
|
|
||||||
TOGGLE -> Tunnel.State.TOGGLE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toAmState() : org.amnezia.awg.backend.Tunnel.State {
|
|
||||||
return when(this) {
|
|
||||||
UP -> org.amnezia.awg.backend.Tunnel.State.UP
|
|
||||||
DOWN -> org.amnezia.awg.backend.Tunnel.State.DOWN
|
|
||||||
TOGGLE -> org.amnezia.awg.backend.Tunnel.State.TOGGLE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun from(state: Tunnel.State) : TunnelState {
|
|
||||||
return when(state) {
|
|
||||||
Tunnel.State.DOWN -> DOWN
|
|
||||||
Tunnel.State.TOGGLE -> TOGGLE
|
|
||||||
Tunnel.State.UP -> UP
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fun from(state: org.amnezia.awg.backend.Tunnel.State) : TunnelState {
|
|
||||||
return when(state) {
|
|
||||||
org.amnezia.awg.backend.Tunnel.State.DOWN -> DOWN
|
|
||||||
org.amnezia.awg.backend.Tunnel.State.TOGGLE -> TOGGLE
|
|
||||||
org.amnezia.awg.backend.Tunnel.State.UP -> UP
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.tunnel
|
package com.zaneschepke.wireguardautotunnel.service.tunnel
|
||||||
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import org.amnezia.awg.backend.Tunnel
|
||||||
|
|
||||||
interface VpnService : Tunnel, org.amnezia.awg.backend.Tunnel {
|
interface VpnService : Tunnel {
|
||||||
suspend fun startTunnel(tunnelConfig: TunnelConfig? = null): TunnelState
|
suspend fun startTunnel(tunnelConfig: TunnelConfig? = null): Tunnel.State
|
||||||
|
|
||||||
suspend fun stopTunnel()
|
suspend fun stopTunnel()
|
||||||
|
|
||||||
val vpnState: StateFlow<VpnState>
|
val vpnState: StateFlow<VpnState>
|
||||||
|
|
||||||
fun getState(): TunnelState
|
fun getState(): Tunnel.State
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.tunnel
|
package com.zaneschepke.wireguardautotunnel.service.tunnel
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.TunnelStatistics
|
import org.amnezia.awg.backend.Statistics
|
||||||
|
import org.amnezia.awg.backend.Tunnel
|
||||||
|
|
||||||
data class VpnState(
|
data class VpnState(
|
||||||
val status: TunnelState = TunnelState.DOWN,
|
val status: Tunnel.State = Tunnel.State.DOWN,
|
||||||
val tunnelConfig: TunnelConfig? = null,
|
val tunnelConfig: TunnelConfig? = null,
|
||||||
val statistics: TunnelStatistics? = null
|
val statistics: Statistics? = null
|
||||||
)
|
)
|
||||||
|
|||||||
+33
-81
@@ -1,16 +1,10 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.tunnel
|
package com.zaneschepke.wireguardautotunnel.service.tunnel
|
||||||
|
|
||||||
import com.wireguard.android.backend.Backend
|
|
||||||
import com.wireguard.android.backend.BackendException
|
|
||||||
import com.wireguard.android.backend.Tunnel.State
|
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.module.Kernel
|
import com.zaneschepke.wireguardautotunnel.module.Kernel
|
||||||
import com.zaneschepke.wireguardautotunnel.module.Userspace
|
import com.zaneschepke.wireguardautotunnel.module.Userspace
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.AmneziaStatistics
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.TunnelStatistics
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.WireGuardStatistics
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@@ -21,6 +15,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.amnezia.awg.backend.Backend
|
||||||
|
import org.amnezia.awg.backend.BackendException
|
||||||
|
import org.amnezia.awg.backend.Statistics
|
||||||
import org.amnezia.awg.backend.Tunnel
|
import org.amnezia.awg.backend.Tunnel
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -28,7 +25,6 @@ import javax.inject.Inject
|
|||||||
class WireGuardTunnel
|
class WireGuardTunnel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val userspaceAmneziaBackend : org.amnezia.awg.backend.Backend,
|
|
||||||
@Userspace private val userspaceBackend: Backend,
|
@Userspace private val userspaceBackend: Backend,
|
||||||
@Kernel private val kernelBackend: Backend,
|
@Kernel private val kernelBackend: Backend,
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
@@ -42,70 +38,46 @@ constructor(
|
|||||||
|
|
||||||
private var backend: Backend = userspaceBackend
|
private var backend: Backend = userspaceBackend
|
||||||
|
|
||||||
private var backendIsWgUserspace = true
|
private var backendIsUserspace = true
|
||||||
|
|
||||||
private var backendIsAmneziaUserspace = false
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
appDataRepository.settings.getSettingsFlow().collect {
|
appDataRepository.settings.getSettingsFlow().collect {
|
||||||
if (it.isKernelEnabled && (backendIsWgUserspace || backendIsAmneziaUserspace)) {
|
if (it.isKernelEnabled && backendIsUserspace) {
|
||||||
Timber.d("Setting kernel backend")
|
Timber.d("Setting kernel backend")
|
||||||
backend = kernelBackend
|
backend = kernelBackend
|
||||||
backendIsWgUserspace = false
|
backendIsUserspace = false
|
||||||
backendIsAmneziaUserspace = false
|
} else if (!it.isKernelEnabled && !backendIsUserspace) {
|
||||||
} else if (!it.isKernelEnabled && !it.isAmneziaEnabled && !backendIsWgUserspace) {
|
Timber.d("Setting userspace backend")
|
||||||
Timber.d("Setting WireGuard userspace backend")
|
|
||||||
backend = userspaceBackend
|
backend = userspaceBackend
|
||||||
backendIsWgUserspace = true
|
backendIsUserspace = true
|
||||||
backendIsAmneziaUserspace = false
|
|
||||||
} else if (it.isAmneziaEnabled && !backendIsAmneziaUserspace) {
|
|
||||||
Timber.d("Setting Amnezia userspace backend")
|
|
||||||
backendIsAmneziaUserspace = true
|
|
||||||
backendIsWgUserspace = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setState(tunnelConfig: TunnelConfig?, tunnelState: TunnelState) : TunnelState {
|
override suspend fun startTunnel(tunnelConfig: TunnelConfig?): Tunnel.State {
|
||||||
return if(backendIsAmneziaUserspace) {
|
|
||||||
Timber.i("Using Amnezia backend")
|
|
||||||
val config = tunnelConfig?.let {
|
|
||||||
if(it.amQuick != "") TunnelConfig.configFromAmQuick(it.amQuick) else {
|
|
||||||
Timber.w("Using backwards compatible wg config, amnezia specific config not found.")
|
|
||||||
TunnelConfig.configFromAmQuick(it.wgQuick)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val state = userspaceAmneziaBackend.setState(this, tunnelState.toAmState(), config)
|
|
||||||
TunnelState.from(state)
|
|
||||||
} else {
|
|
||||||
Timber.i("Using Wg backend")
|
|
||||||
val wgConfig = tunnelConfig?.let { TunnelConfig.configFromWgQuick(it.wgQuick) }
|
|
||||||
val state = backend.setState(
|
|
||||||
this,
|
|
||||||
tunnelState.toWgState(),
|
|
||||||
wgConfig,
|
|
||||||
)
|
|
||||||
TunnelState.from(state)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun startTunnel(tunnelConfig: TunnelConfig?): TunnelState {
|
|
||||||
return try {
|
return try {
|
||||||
//TODO we need better error handling here
|
//TODO we need better error handling here
|
||||||
val config = tunnelConfig ?: appDataRepository.getPrimaryOrFirstTunnel()
|
val config = tunnelConfig ?: appDataRepository.getPrimaryOrFirstTunnel()
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
emitTunnelConfig(config)
|
emitTunnelConfig(config)
|
||||||
setState(config, TunnelState.UP)
|
val wgConfig = TunnelConfig.configFromQuick(config.wgQuick)
|
||||||
|
val state =
|
||||||
|
backend.setState(
|
||||||
|
this,
|
||||||
|
Tunnel.State.UP,
|
||||||
|
wgConfig,
|
||||||
|
)
|
||||||
|
state
|
||||||
} else throw Exception("No tunnels")
|
} else throw Exception("No tunnels")
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e("Failed to start tunnel with error: ${e.message}")
|
Timber.e("Failed to start tunnel with error: ${e.message}")
|
||||||
TunnelState.from(State.DOWN)
|
Tunnel.State.DOWN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun emitTunnelState(state : TunnelState) {
|
private fun emitTunnelState(state: Tunnel.State) {
|
||||||
_vpnState.tryEmit(
|
_vpnState.tryEmit(
|
||||||
_vpnState.value.copy(
|
_vpnState.value.copy(
|
||||||
status = state,
|
status = state,
|
||||||
@@ -113,7 +85,7 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun emitBackendStatistics(statistics: TunnelStatistics) {
|
private fun emitBackendStatistics(statistics: Statistics) {
|
||||||
_vpnState.tryEmit(
|
_vpnState.tryEmit(
|
||||||
_vpnState.value.copy(
|
_vpnState.value.copy(
|
||||||
statistics = statistics,
|
statistics = statistics,
|
||||||
@@ -129,56 +101,40 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resetVpnState() {
|
|
||||||
_vpnState.tryEmit(VpnState())
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun stopTunnel() {
|
override suspend fun stopTunnel() {
|
||||||
try {
|
try {
|
||||||
if (getState() == TunnelState.UP) {
|
if (getState() == Tunnel.State.UP) {
|
||||||
val state = setState(null, TunnelState.DOWN)
|
val state = backend.setState(this, Tunnel.State.DOWN, null)
|
||||||
resetVpnState()
|
|
||||||
emitTunnelState(state)
|
emitTunnelState(state)
|
||||||
}
|
}
|
||||||
} catch (e: BackendException) {
|
} catch (e: BackendException) {
|
||||||
Timber.e("Failed to stop wireguard tunnel with error: ${e.message}")
|
Timber.e("Failed to stop tunnel with error: ${e.message}")
|
||||||
} catch (e: org.amnezia.awg.backend.BackendException) {
|
|
||||||
Timber.e("Failed to stop amnezia tunnel with error: ${e.message}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getState(): TunnelState {
|
override fun getState(): Tunnel.State {
|
||||||
return if(backendIsAmneziaUserspace) TunnelState.from(userspaceAmneziaBackend.getState(this))
|
return backend.getState(this)
|
||||||
else TunnelState.from(backend.getState(this))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(): String {
|
override fun getName(): String {
|
||||||
return _vpnState.value.tunnelConfig?.name ?: ""
|
return _vpnState.value.tunnelConfig?.name ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStateChange(state: Tunnel.State) {
|
||||||
override fun onStateChange(newState: Tunnel.State) {
|
|
||||||
handleStateChange(TunnelState.from(newState))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleStateChange(state: TunnelState) {
|
|
||||||
val tunnel = this
|
val tunnel = this
|
||||||
emitTunnelState(state)
|
emitTunnelState(state)
|
||||||
WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate()
|
WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate(WireGuardAutoTunnel.instance)
|
||||||
if (state == TunnelState.UP) {
|
if (state == Tunnel.State.UP) {
|
||||||
statsJob =
|
statsJob =
|
||||||
scope.launch {
|
scope.launch {
|
||||||
while (true) {
|
while (true) {
|
||||||
if(backendIsAmneziaUserspace) {
|
val statistics = backend.getStatistics(tunnel)
|
||||||
emitBackendStatistics(AmneziaStatistics(userspaceAmneziaBackend.getStatistics(tunnel)))
|
emitBackendStatistics(statistics)
|
||||||
} else {
|
|
||||||
emitBackendStatistics(WireGuardStatistics(backend.getStatistics(tunnel)))
|
|
||||||
}
|
|
||||||
delay(Constants.VPN_STATISTIC_CHECK_INTERVAL)
|
delay(Constants.VPN_STATISTIC_CHECK_INTERVAL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (state == TunnelState.DOWN) {
|
if (state == Tunnel.State.DOWN) {
|
||||||
try {
|
try {
|
||||||
statsJob?.cancel()
|
statsJob?.cancel()
|
||||||
} catch (e : CancellationException) {
|
} catch (e : CancellationException) {
|
||||||
@@ -186,8 +142,4 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStateChange(state: State) {
|
|
||||||
handleStateChange(TunnelState.from(state))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.tunnel.statistics
|
|
||||||
|
|
||||||
import org.amnezia.awg.backend.Statistics
|
|
||||||
import org.amnezia.awg.crypto.Key
|
|
||||||
|
|
||||||
class AmneziaStatistics(private val statistics: Statistics) : TunnelStatistics() {
|
|
||||||
override fun peerStats(peer: Key): PeerStats? {
|
|
||||||
val key = Key.fromBase64(peer.toBase64())
|
|
||||||
val stats = statistics.peer(key)
|
|
||||||
return stats?.let {
|
|
||||||
PeerStats(
|
|
||||||
rxBytes = stats.rxBytes,
|
|
||||||
txBytes = stats.txBytes,
|
|
||||||
latestHandshakeEpochMillis = stats.latestHandshakeEpochMillis
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isTunnelStale(): Boolean {
|
|
||||||
return statistics.isStale
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getPeers(): Array<Key> {
|
|
||||||
return statistics.peers()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun rx(): Long {
|
|
||||||
return statistics.totalRx()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun tx(): Long {
|
|
||||||
return statistics.totalTx()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.tunnel.statistics
|
|
||||||
|
|
||||||
import org.amnezia.awg.crypto.Key
|
|
||||||
|
|
||||||
abstract class TunnelStatistics {
|
|
||||||
@JvmRecord
|
|
||||||
data class PeerStats(val rxBytes: Long, val txBytes: Long, val latestHandshakeEpochMillis: Long)
|
|
||||||
|
|
||||||
abstract fun peerStats(peer: Key): PeerStats?
|
|
||||||
|
|
||||||
abstract fun isTunnelStale() : Boolean
|
|
||||||
|
|
||||||
abstract fun getPeers(): Array<Key>
|
|
||||||
|
|
||||||
abstract fun rx() : Long
|
|
||||||
|
|
||||||
abstract fun tx() : Long
|
|
||||||
}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.tunnel.statistics
|
|
||||||
|
|
||||||
import com.wireguard.android.backend.Statistics
|
|
||||||
import org.amnezia.awg.crypto.Key
|
|
||||||
|
|
||||||
class WireGuardStatistics(private val statistics: Statistics) : TunnelStatistics() {
|
|
||||||
override fun peerStats(peer: Key): PeerStats? {
|
|
||||||
val key = com.wireguard.crypto.Key.fromBase64(peer.toBase64())
|
|
||||||
val peerStats = statistics.peer(key)
|
|
||||||
return peerStats?.let {
|
|
||||||
PeerStats(
|
|
||||||
txBytes = peerStats.txBytes,
|
|
||||||
rxBytes = peerStats.rxBytes,
|
|
||||||
latestHandshakeEpochMillis = peerStats.latestHandshakeEpochMillis
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isTunnelStale(): Boolean {
|
|
||||||
return statistics.isStale
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getPeers(): Array<Key> {
|
|
||||||
return statistics.peers().map {
|
|
||||||
Key.fromBase64(it.toBase64())
|
|
||||||
}.toTypedArray()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun rx(): Long {
|
|
||||||
return statistics.totalRx()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun tx(): Long {
|
|
||||||
return statistics.totalTx()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui
|
package com.zaneschepke.wireguardautotunnel.ui
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
import android.content.ActivityNotFoundException
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.wireguard.android.backend.GoBackend
|
|
||||||
import com.zaneschepke.logcatter.Logcatter
|
import com.zaneschepke.logcatter.Logcatter
|
||||||
import com.zaneschepke.logcatter.model.LogMessage
|
import com.zaneschepke.logcatter.model.LogMessage
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
@@ -19,8 +18,8 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.amnezia.awg.backend.GoBackend
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -28,7 +27,9 @@ import javax.inject.Inject
|
|||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class AppViewModel
|
class AppViewModel
|
||||||
@Inject
|
@Inject
|
||||||
constructor() : ViewModel() {
|
constructor(
|
||||||
|
private val application: Application,
|
||||||
|
) : ViewModel() {
|
||||||
|
|
||||||
val vpnIntent: Intent? = GoBackend.VpnService.prepare(WireGuardAutoTunnel.instance)
|
val vpnIntent: Intent? = GoBackend.VpnService.prepare(WireGuardAutoTunnel.instance)
|
||||||
|
|
||||||
@@ -48,78 +49,68 @@ constructor() : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun requestPermissions() {
|
private fun requestPermissions() {
|
||||||
_appUiState.update {
|
_appUiState.value = _appUiState.value.copy(
|
||||||
it.copy(
|
requestPermissions = true,
|
||||||
requestPermissions = true
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun permissionsRequested() {
|
fun permissionsRequested() {
|
||||||
_appUiState.update {
|
_appUiState.value = _appUiState.value.copy(
|
||||||
it.copy(
|
requestPermissions = false,
|
||||||
requestPermissions = false
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openWebPage(url: String, context : Context) {
|
fun openWebPage(url: String) {
|
||||||
try {
|
try {
|
||||||
val webpage: Uri = Uri.parse(url)
|
val webpage: Uri = Uri.parse(url)
|
||||||
val intent = Intent(Intent.ACTION_VIEW, webpage).apply {
|
val intent = Intent(Intent.ACTION_VIEW, webpage).apply {
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
}
|
}
|
||||||
context.startActivity(intent)
|
application.startActivity(intent)
|
||||||
} catch (e: ActivityNotFoundException) {
|
} catch (e: ActivityNotFoundException) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
showSnackbarMessage(context.getString(R.string.no_browser_detected))
|
showSnackbarMessage(application.getString(R.string.no_browser_detected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onVpnPermissionAccepted() {
|
fun onVpnPermissionAccepted() {
|
||||||
_appUiState.update {
|
_appUiState.value = _appUiState.value.copy(
|
||||||
it.copy(
|
vpnPermissionAccepted = true,
|
||||||
vpnPermissionAccepted = true
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun launchEmail(context: Context) {
|
fun launchEmail() {
|
||||||
try {
|
try {
|
||||||
val intent =
|
val intent =
|
||||||
Intent(Intent.ACTION_SENDTO).apply {
|
Intent(Intent.ACTION_SENDTO).apply {
|
||||||
type = Constants.EMAIL_MIME_TYPE
|
type = Constants.EMAIL_MIME_TYPE
|
||||||
putExtra(Intent.EXTRA_EMAIL, arrayOf(context.getString(R.string.my_email)))
|
putExtra(Intent.EXTRA_EMAIL, arrayOf(application.getString(R.string.my_email)))
|
||||||
putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.email_subject))
|
putExtra(Intent.EXTRA_SUBJECT, application.getString(R.string.email_subject))
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
}
|
}
|
||||||
context.startActivity(
|
application.startActivity(
|
||||||
Intent.createChooser(intent, context.getString(R.string.email_chooser)).apply {
|
Intent.createChooser(intent, application.getString(R.string.email_chooser)).apply {
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} catch (e: ActivityNotFoundException) {
|
} catch (e: ActivityNotFoundException) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
showSnackbarMessage(context.getString(R.string.no_email_detected))
|
showSnackbarMessage(application.getString(R.string.no_email_detected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showSnackbarMessage(message: String) {
|
fun showSnackbarMessage(message: String) {
|
||||||
_appUiState.update {
|
_appUiState.value = _appUiState.value.copy(
|
||||||
it.copy(
|
snackbarMessage = message,
|
||||||
snackbarMessage = message,
|
snackbarMessageConsumed = false,
|
||||||
snackbarMessageConsumed = false,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun snackbarMessageConsumed() {
|
fun snackbarMessageConsumed() {
|
||||||
_appUiState.update {
|
_appUiState.value = _appUiState.value.copy(
|
||||||
it.copy(
|
snackbarMessage = "",
|
||||||
snackbarMessage = "",
|
snackbarMessageConsumed = true,
|
||||||
snackbarMessageConsumed = true,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val logs = mutableStateListOf<LogMessage>()
|
val logs = mutableStateListOf<LogMessage>()
|
||||||
@@ -141,19 +132,17 @@ constructor() : ViewModel() {
|
|||||||
Logcatter.clear()
|
Logcatter.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveLogsToFile(context: Context) {
|
fun saveLogsToFile() {
|
||||||
val fileName = "${Constants.BASE_LOG_FILE_NAME}-${Instant.now().epochSecond}.txt"
|
val fileName = "${Constants.BASE_LOG_FILE_NAME}-${Instant.now().epochSecond}.txt"
|
||||||
val content = logs.joinToString(separator = "\n")
|
val content = logs.joinToString(separator = "\n")
|
||||||
FileUtils.saveFileToDownloads(context.applicationContext, content, fileName)
|
FileUtils.saveFileToDownloads(application.applicationContext, content, fileName)
|
||||||
Toast.makeText(context, context.getString(R.string.logs_saved), Toast.LENGTH_SHORT)
|
Toast.makeText(application, application.getString(R.string.logs_saved), Toast.LENGTH_SHORT)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setNotificationPermissionAccepted(accepted: Boolean) {
|
fun setNotificationPermissionAccepted(accepted: Boolean) {
|
||||||
_appUiState.update {
|
_appUiState.value = _appUiState.value.copy(
|
||||||
it.copy(
|
notificationPermissionAccepted = accepted,
|
||||||
notificationPermissionAccepted = accepted,
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,12 +32,10 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.navigation.NavType
|
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import androidx.navigation.navArgument
|
|
||||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||||
import com.google.accompanist.permissions.isGranted
|
import com.google.accompanist.permissions.isGranted
|
||||||
import com.google.accompanist.permissions.rememberPermissionState
|
import com.google.accompanist.permissions.rememberPermissionState
|
||||||
@@ -49,7 +47,6 @@ import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavBar
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.CustomSnackBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.CustomSnackBar
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.config.ConfigScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.config.ConfigScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.ConfigType
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.options.OptionsScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.options.OptionsScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.pinlock.PinLockScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.pinlock.PinLockScreen
|
||||||
@@ -87,7 +84,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// load preferences into memory and init data
|
// load preferences into memory and init data
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
dataStoreManager.init()
|
dataStoreManager.init()
|
||||||
WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate()
|
WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate(this@MainActivity)
|
||||||
val settings = settingsRepository.getSettings()
|
val settings = settingsRepository.getSettings()
|
||||||
if (settings.isAutoTunnelEnabled) {
|
if (settings.isAutoTunnelEnabled) {
|
||||||
serviceManager.startWatcherService(application.applicationContext)
|
serviceManager.startWatcherService(application.applicationContext)
|
||||||
@@ -141,11 +138,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return@LaunchedEffect notificationPermissionState.launchPermissionRequest()
|
return@LaunchedEffect notificationPermissionState.launchPermissionRequest()
|
||||||
}
|
}
|
||||||
if (!appUiState.vpnPermissionAccepted) {
|
if (!appUiState.vpnPermissionAccepted) {
|
||||||
return@LaunchedEffect appViewModel.vpnIntent?.let {
|
return@LaunchedEffect vpnActivityResultState.launch(appViewModel.vpnIntent)
|
||||||
vpnActivityResultState.launch(
|
|
||||||
it
|
|
||||||
)
|
|
||||||
}!!
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,28 +232,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
composable(Screen.Support.Logs.route) {
|
composable(Screen.Support.Logs.route) {
|
||||||
LogsScreen(appViewModel)
|
LogsScreen(appViewModel)
|
||||||
}
|
}
|
||||||
//TODO fix navigation for amnezia
|
composable("${Screen.Config.route}/{id}") {
|
||||||
composable("${Screen.Config.route}/{id}?configType={configType}", arguments =
|
|
||||||
listOf(
|
|
||||||
navArgument("id") {
|
|
||||||
type = NavType.StringType
|
|
||||||
defaultValue = "0"
|
|
||||||
},
|
|
||||||
navArgument("configType") {
|
|
||||||
type = NavType.StringType
|
|
||||||
defaultValue = ConfigType.WIREGUARD.name
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
val id = it.arguments?.getString("id")
|
val id = it.arguments?.getString("id")
|
||||||
val configType = ConfigType.valueOf( it.arguments?.getString("configType") ?: ConfigType.WIREGUARD.name)
|
|
||||||
if (!id.isNullOrBlank()) {
|
if (!id.isNullOrBlank()) {
|
||||||
ConfigScreen(
|
ConfigScreen(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
tunnelId = id,
|
tunnelId = id,
|
||||||
appViewModel = appViewModel,
|
appViewModel = appViewModel,
|
||||||
focusRequester = focusRequester,
|
focusRequester = focusRequester,
|
||||||
configType = configType
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import androidx.compose.material.icons.Icons
|
|||||||
import androidx.compose.material.icons.rounded.Home
|
import androidx.compose.material.icons.rounded.Home
|
||||||
import androidx.compose.material.icons.rounded.QuestionMark
|
import androidx.compose.material.icons.rounded.QuestionMark
|
||||||
import androidx.compose.material.icons.rounded.Settings
|
import androidx.compose.material.icons.rounded.Settings
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavItem
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
|
|
||||||
sealed class Screen(val route: String) {
|
sealed class Screen(val route: String) {
|
||||||
data object Main : Screen("main") {
|
data object Main : Screen("main") {
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.TunnelStatistics
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.toThreeDecimalPlaceString
|
import com.zaneschepke.wireguardautotunnel.util.toThreeDecimalPlaceString
|
||||||
|
import org.amnezia.awg.backend.Statistics
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -30,7 +30,7 @@ fun RowListItem(
|
|||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
rowButton: @Composable () -> Unit,
|
rowButton: @Composable () -> Unit,
|
||||||
expanded: Boolean,
|
expanded: Boolean,
|
||||||
statistics: TunnelStatistics?
|
statistics: Statistics?
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
@@ -59,7 +59,7 @@ fun RowListItem(
|
|||||||
rowButton()
|
rowButton()
|
||||||
}
|
}
|
||||||
if (expanded) {
|
if (expanded) {
|
||||||
statistics?.getPeers()?.forEach {
|
statistics?.peers()?.forEach {
|
||||||
Row(
|
Row(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
Modifier
|
||||||
@@ -69,9 +69,9 @@ fun RowListItem(
|
|||||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||||
) {
|
) {
|
||||||
//TODO change these to string resources
|
//TODO change these to string resources
|
||||||
val handshakeEpoch = statistics.peerStats(it)!!.latestHandshakeEpochMillis
|
val handshakeEpoch = statistics.peer(it)!!.latestHandshakeEpochMillis
|
||||||
val peerTx = statistics.peerStats(it)!!.txBytes
|
val peerTx = statistics.peer(it)!!.txBytes
|
||||||
val peerRx = statistics.peerStats(it)!!.rxBytes
|
val peerRx = statistics.peer(it)!!.rxBytes
|
||||||
val peerId = it.toBase64().subSequence(0, 3).toString() + "***"
|
val peerId = it.toBase64().subSequence(0, 3).toString() + "***"
|
||||||
val handshakeSec =
|
val handshakeSec =
|
||||||
NumberUtils.getSecondsBetweenTimestampAndNow(handshakeEpoch)
|
NumberUtils.getSecondsBetweenTimestampAndNow(handshakeEpoch)
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.ui.models
|
||||||
|
|
||||||
|
import org.amnezia.awg.config.Interface
|
||||||
|
|
||||||
|
data class InterfaceProxy(
|
||||||
|
var privateKey: String = "",
|
||||||
|
var publicKey: String = "",
|
||||||
|
var addresses: String = "",
|
||||||
|
var dnsServers: String = "",
|
||||||
|
var listenPort: String = "",
|
||||||
|
var mtu: String = ""
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
fun from(i: Interface): InterfaceProxy {
|
||||||
|
return InterfaceProxy(
|
||||||
|
publicKey = i.keyPair.publicKey.toBase64().trim(),
|
||||||
|
privateKey = i.keyPair.privateKey.toBase64().trim(),
|
||||||
|
addresses = i.addresses.joinToString(", ").trim(),
|
||||||
|
dnsServers = i.dnsServers.joinToString(", ").replace("/", "").trim(),
|
||||||
|
listenPort =
|
||||||
|
if (i.listenPort.isPresent) {
|
||||||
|
i.listenPort.get().toString().trim()
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
|
mtu = if (i.mtu.isPresent) i.mtu.get().toString().trim() else "",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-32
@@ -1,13 +1,13 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.config.model
|
package com.zaneschepke.wireguardautotunnel.ui.models
|
||||||
|
|
||||||
import com.wireguard.config.Peer
|
import org.amnezia.awg.config.Peer
|
||||||
|
|
||||||
data class PeerProxy(
|
data class PeerProxy(
|
||||||
val publicKey: String = "",
|
var publicKey: String = "",
|
||||||
val preSharedKey: String = "",
|
var preSharedKey: String = "",
|
||||||
val persistentKeepalive: String = "",
|
var persistentKeepalive: String = "",
|
||||||
val endpoint: String = "",
|
var endpoint: String = "",
|
||||||
val allowedIps: String = IPV4_WILDCARD.joinToString(", ").trim()
|
var allowedIps: String = IPV4_WILDCARD.joinToString(", ").trim()
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun from(peer: Peer): PeerProxy {
|
fun from(peer: Peer): PeerProxy {
|
||||||
@@ -35,31 +35,6 @@ data class PeerProxy(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun from(peer: org.amnezia.awg.config.Peer) : PeerProxy {
|
|
||||||
return PeerProxy(
|
|
||||||
publicKey = peer.publicKey.toBase64(),
|
|
||||||
preSharedKey =
|
|
||||||
if (peer.preSharedKey.isPresent) {
|
|
||||||
peer.preSharedKey.get().toBase64().trim()
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
persistentKeepalive =
|
|
||||||
if (peer.persistentKeepalive.isPresent) {
|
|
||||||
peer.persistentKeepalive.get().toString().trim()
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
endpoint =
|
|
||||||
if (peer.endpoint.isPresent) {
|
|
||||||
peer.endpoint.get().toString().trim()
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
allowedIps = peer.allowedIps.joinToString(", ").trim(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val IPV4_PUBLIC_NETWORKS =
|
val IPV4_PUBLIC_NETWORKS =
|
||||||
setOf(
|
setOf(
|
||||||
"0.0.0.0/5",
|
"0.0.0.0/5",
|
||||||
+14
-103
@@ -79,9 +79,9 @@ import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.screen.LoadingScreen
|
import com.zaneschepke.wireguardautotunnel.ui.common.screen.LoadingScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.ConfigType
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.getMessage
|
import com.zaneschepke.wireguardautotunnel.util.Event
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Result
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
@@ -94,8 +94,7 @@ fun ConfigScreen(
|
|||||||
focusRequester: FocusRequester,
|
focusRequester: FocusRequester,
|
||||||
navController: NavController,
|
navController: NavController,
|
||||||
appViewModel: AppViewModel,
|
appViewModel: AppViewModel,
|
||||||
tunnelId: String,
|
tunnelId: String
|
||||||
configType: ConfigType
|
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
||||||
@@ -149,11 +148,11 @@ fun ConfigScreen(
|
|||||||
},
|
},
|
||||||
onError = {
|
onError = {
|
||||||
showAuthPrompt = false
|
showAuthPrompt = false
|
||||||
appViewModel.showSnackbarMessage(context.getString(R.string.error_authentication_failed))
|
appViewModel.showSnackbarMessage(Event.Error.AuthenticationFailed.message)
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
showAuthPrompt = false
|
showAuthPrompt = false
|
||||||
appViewModel.showSnackbarMessage(context.getString(R.string.error_authorization_failed))
|
appViewModel.showSnackbarMessage(Event.Error.AuthorizationFailed.message)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -320,11 +319,15 @@ fun ConfigScreen(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onClick = {
|
onClick = {
|
||||||
viewModel.onSaveAllChanges(configType).onSuccess {
|
viewModel.onSaveAllChanges().let {
|
||||||
appViewModel.showSnackbarMessage(context.getString(R.string.config_changes_saved))
|
when (it) {
|
||||||
navController.navigate(Screen.Main.route)
|
is Result.Success -> {
|
||||||
}.onFailure {
|
appViewModel.showSnackbarMessage(it.data.message)
|
||||||
appViewModel.showSnackbarMessage(it.getMessage(context))
|
navController.navigate(Screen.Main.route)
|
||||||
|
}
|
||||||
|
|
||||||
|
is Result.Error -> appViewModel.showSnackbarMessage(it.error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
containerColor = fobColor,
|
containerColor = fobColor,
|
||||||
@@ -483,98 +486,6 @@ fun ConfigScreen(
|
|||||||
modifier = Modifier.width(IntrinsicSize.Min),
|
modifier = Modifier.width(IntrinsicSize.Min),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if(configType == ConfigType.AMNEZIA) {
|
|
||||||
ConfigurationTextBox(
|
|
||||||
value = uiState.interfaceProxy.junkPacketCount,
|
|
||||||
onValueChange = { value -> viewModel.onJunkPacketCountChanged(value) },
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
label = stringResource(R.string.junk_packet_count),
|
|
||||||
hint = stringResource(R.string.junk_packet_count).lowercase(),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
)
|
|
||||||
ConfigurationTextBox(
|
|
||||||
value = uiState.interfaceProxy.junkPacketMinSize,
|
|
||||||
onValueChange = { value -> viewModel.onJunkPacketMinSizeChanged(value) },
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
label = stringResource(R.string.junk_packet_minimum_size),
|
|
||||||
hint = stringResource(R.string.junk_packet_minimum_size).lowercase(),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
)
|
|
||||||
ConfigurationTextBox(
|
|
||||||
value = uiState.interfaceProxy.junkPacketMaxSize,
|
|
||||||
onValueChange = { value -> viewModel.onJunkPacketMaxSizeChanged(value) },
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
label = stringResource(R.string.junk_packet_maximum_size),
|
|
||||||
hint = stringResource(R.string.junk_packet_maximum_size).lowercase(),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
)
|
|
||||||
ConfigurationTextBox(
|
|
||||||
value = uiState.interfaceProxy.initPacketJunkSize,
|
|
||||||
onValueChange = { value -> viewModel.onInitPacketJunkSizeChanged(value) },
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
label = stringResource(R.string.init_packet_junk_size),
|
|
||||||
hint = stringResource(R.string.init_packet_junk_size).lowercase(),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
)
|
|
||||||
ConfigurationTextBox(
|
|
||||||
value = uiState.interfaceProxy.responsePacketJunkSize,
|
|
||||||
onValueChange = { value -> viewModel.onResponsePacketJunkSize(value) },
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
label = stringResource(R.string.response_packet_junk_size),
|
|
||||||
hint = stringResource(R.string.response_packet_junk_size).lowercase(),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
)
|
|
||||||
ConfigurationTextBox(
|
|
||||||
value = uiState.interfaceProxy.initPacketMagicHeader,
|
|
||||||
onValueChange = { value -> viewModel.onInitPacketMagicHeader(value) },
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
label = stringResource(R.string.init_packet_magic_header),
|
|
||||||
hint = stringResource(R.string.init_packet_magic_header).lowercase(),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
)
|
|
||||||
ConfigurationTextBox(
|
|
||||||
value = uiState.interfaceProxy.responsePacketMagicHeader,
|
|
||||||
onValueChange = { value -> viewModel.onResponsePacketMagicHeader(value) },
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
label = stringResource(R.string.response_packet_magic_header),
|
|
||||||
hint = stringResource(R.string.response_packet_magic_header).lowercase(),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
)
|
|
||||||
ConfigurationTextBox(
|
|
||||||
value = uiState.interfaceProxy.underloadPacketMagicHeader,
|
|
||||||
onValueChange = { value -> viewModel.onUnderloadPacketMagicHeader(value) },
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
label = stringResource(R.string.underload_packet_magic_header),
|
|
||||||
hint = stringResource(R.string.underload_packet_magic_header).lowercase(),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
)
|
|
||||||
ConfigurationTextBox(
|
|
||||||
value = uiState.interfaceProxy.transportPacketMagicHeader,
|
|
||||||
onValueChange = { value -> viewModel.onTransportPacketMagicHeader(value) },
|
|
||||||
keyboardActions = keyboardActions,
|
|
||||||
label = stringResource(R.string.transport_packet_magic_header),
|
|
||||||
hint = stringResource(R.string.transport_packet_magic_header).lowercase(),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|||||||
+5
-59
@@ -1,9 +1,8 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.config
|
package com.zaneschepke.wireguardautotunnel.ui.screens.config
|
||||||
|
|
||||||
import com.wireguard.config.Config
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.ui.models.InterfaceProxy
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.config.model.InterfaceProxy
|
import com.zaneschepke.wireguardautotunnel.ui.models.PeerProxy
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.config.model.PeerProxy
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Packages
|
import com.zaneschepke.wireguardautotunnel.util.Packages
|
||||||
|
|
||||||
data class ConfigUiState(
|
data class ConfigUiState(
|
||||||
@@ -15,58 +14,5 @@ data class ConfigUiState(
|
|||||||
val isAllApplicationsEnabled: Boolean = false,
|
val isAllApplicationsEnabled: Boolean = false,
|
||||||
val loading: Boolean = true,
|
val loading: Boolean = true,
|
||||||
val tunnel: TunnelConfig? = null,
|
val tunnel: TunnelConfig? = null,
|
||||||
val tunnelName: String = "",
|
val tunnelName: String = ""
|
||||||
val isAmneziaEnabled: Boolean = false
|
)
|
||||||
) {
|
|
||||||
companion object {
|
|
||||||
fun from(config : Config) : ConfigUiState {
|
|
||||||
val proxyPeers = config.peers.map { PeerProxy.from(it) }
|
|
||||||
val proxyInterface = InterfaceProxy.from(config.`interface`)
|
|
||||||
var include = true
|
|
||||||
var isAllApplicationsEnabled = false
|
|
||||||
val checkedPackages =
|
|
||||||
if (config.`interface`.includedApplications.isNotEmpty()) {
|
|
||||||
config.`interface`.includedApplications
|
|
||||||
} else if (config.`interface`.excludedApplications.isNotEmpty()) {
|
|
||||||
include = false
|
|
||||||
config.`interface`.excludedApplications
|
|
||||||
} else {
|
|
||||||
isAllApplicationsEnabled = true
|
|
||||||
emptySet()
|
|
||||||
}
|
|
||||||
return ConfigUiState(
|
|
||||||
proxyPeers,
|
|
||||||
proxyInterface,
|
|
||||||
emptyList(),
|
|
||||||
checkedPackages.toList(),
|
|
||||||
include,
|
|
||||||
isAllApplicationsEnabled,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
fun from(config: org.amnezia.awg.config.Config) : ConfigUiState {
|
|
||||||
//TODO update with new values
|
|
||||||
val proxyPeers = config.peers.map { PeerProxy.from(it) }
|
|
||||||
val proxyInterface = InterfaceProxy.from(config.`interface`)
|
|
||||||
var include = true
|
|
||||||
var isAllApplicationsEnabled = false
|
|
||||||
val checkedPackages =
|
|
||||||
if (config.`interface`.includedApplications.isNotEmpty()) {
|
|
||||||
config.`interface`.includedApplications
|
|
||||||
} else if (config.`interface`.excludedApplications.isNotEmpty()) {
|
|
||||||
include = false
|
|
||||||
config.`interface`.excludedApplications
|
|
||||||
} else {
|
|
||||||
isAllApplicationsEnabled = true
|
|
||||||
emptySet()
|
|
||||||
}
|
|
||||||
return ConfigUiState(
|
|
||||||
proxyPeers,
|
|
||||||
proxyInterface,
|
|
||||||
emptyList(),
|
|
||||||
checkedPackages.toList(),
|
|
||||||
include,
|
|
||||||
isAllApplicationsEnabled,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+77
-228
@@ -1,35 +1,33 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.config
|
package com.zaneschepke.wireguardautotunnel.ui.screens.config
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.app.Application
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.wireguard.config.Config
|
|
||||||
import com.wireguard.config.Interface
|
|
||||||
import com.wireguard.config.Peer
|
|
||||||
import com.wireguard.crypto.Key
|
|
||||||
import com.wireguard.crypto.KeyPair
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.SettingsRepository
|
import com.zaneschepke.wireguardautotunnel.ui.models.InterfaceProxy
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.config.model.PeerProxy
|
import com.zaneschepke.wireguardautotunnel.ui.models.PeerProxy
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.ConfigType
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Event
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.Result
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelExceptions
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.removeAt
|
import com.zaneschepke.wireguardautotunnel.util.removeAt
|
||||||
import com.zaneschepke.wireguardautotunnel.util.update
|
import com.zaneschepke.wireguardautotunnel.util.update
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.amnezia.awg.config.Config
|
||||||
|
import org.amnezia.awg.config.Interface
|
||||||
|
import org.amnezia.awg.config.Peer
|
||||||
|
import org.amnezia.awg.crypto.Key
|
||||||
|
import org.amnezia.awg.crypto.KeyPair
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -37,11 +35,11 @@ import javax.inject.Inject
|
|||||||
class ConfigViewModel
|
class ConfigViewModel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val settingsRepository: SettingsRepository,
|
private val application: Application,
|
||||||
private val appDataRepository: AppDataRepository
|
private val appDataRepository: AppDataRepository
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val packageManager = WireGuardAutoTunnel.instance.packageManager
|
private val packageManager = application.packageManager
|
||||||
|
|
||||||
private val _uiState = MutableStateFlow(ConfigUiState())
|
private val _uiState = MutableStateFlow(ConfigUiState())
|
||||||
val uiState = _uiState.asStateFlow()
|
val uiState = _uiState.asStateFlow()
|
||||||
@@ -54,17 +52,32 @@ constructor(
|
|||||||
val tunnelConfig =
|
val tunnelConfig =
|
||||||
appDataRepository.tunnels.getAll()
|
appDataRepository.tunnels.getAll()
|
||||||
.firstOrNull { it.id.toString() == tunnelId }
|
.firstOrNull { it.id.toString() == tunnelId }
|
||||||
val isAmneziaEnabled = settingsRepository.getSettings().isAmneziaEnabled
|
|
||||||
if (tunnelConfig != null) {
|
if (tunnelConfig != null) {
|
||||||
(if(isAmneziaEnabled) {
|
val config = TunnelConfig.configFromQuick(tunnelConfig.wgQuick)
|
||||||
val amConfig = if(tunnelConfig.amQuick == "") tunnelConfig.wgQuick else tunnelConfig.amQuick
|
val proxyPeers = config.peers.map { PeerProxy.from(it) }
|
||||||
ConfigUiState.from(TunnelConfig.configFromAmQuick(amConfig))
|
val proxyInterface = InterfaceProxy.from(config.`interface`)
|
||||||
} else ConfigUiState.from(TunnelConfig.configFromWgQuick(tunnelConfig.wgQuick))).copy(
|
var include = true
|
||||||
packages = packages,
|
var isAllApplicationsEnabled = false
|
||||||
loading = false,
|
val checkedPackages =
|
||||||
tunnel = tunnelConfig,
|
if (config.`interface`.includedApplications.isNotEmpty()) {
|
||||||
tunnelName = tunnelConfig.name,
|
config.`interface`.includedApplications
|
||||||
isAmneziaEnabled = isAmneziaEnabled
|
} else if (config.`interface`.excludedApplications.isNotEmpty()) {
|
||||||
|
include = false
|
||||||
|
config.`interface`.excludedApplications
|
||||||
|
} else {
|
||||||
|
isAllApplicationsEnabled = true
|
||||||
|
emptySet()
|
||||||
|
}
|
||||||
|
ConfigUiState(
|
||||||
|
proxyPeers,
|
||||||
|
proxyInterface,
|
||||||
|
packages,
|
||||||
|
checkedPackages.toList(),
|
||||||
|
include,
|
||||||
|
isAllApplicationsEnabled,
|
||||||
|
false,
|
||||||
|
tunnelConfig,
|
||||||
|
tunnelConfig.name,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
ConfigUiState(loading = false, packages = packages)
|
ConfigUiState(loading = false, packages = packages)
|
||||||
@@ -108,7 +121,7 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getPackageLabel(packageInfo: PackageInfo): String {
|
fun getPackageLabel(packageInfo: PackageInfo): String {
|
||||||
return packageInfo.applicationInfo.loadLabel(packageManager).toString()
|
return packageInfo.applicationInfo.loadLabel(application.packageManager).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAllInternetCapablePackages(): List<PackageInfo> {
|
private fun getAllInternetCapablePackages(): List<PackageInfo> {
|
||||||
@@ -137,7 +150,7 @@ constructor(
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
if (tunnelConfig != null) {
|
if (tunnelConfig != null) {
|
||||||
saveConfig(tunnelConfig).join()
|
saveConfig(tunnelConfig).join()
|
||||||
WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate()
|
WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate(application)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,20 +168,6 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildAmPeerListFromProxyPeers(): List<org.amnezia.awg.config.Peer> {
|
|
||||||
return _uiState.value.proxyPeers.map {
|
|
||||||
val builder = org.amnezia.awg.config.Peer.Builder()
|
|
||||||
if (it.allowedIps.isNotEmpty()) builder.parseAllowedIPs(it.allowedIps.trim())
|
|
||||||
if (it.publicKey.isNotEmpty()) builder.parsePublicKey(it.publicKey.trim())
|
|
||||||
if (it.preSharedKey.isNotEmpty()) builder.parsePreSharedKey(it.preSharedKey.trim())
|
|
||||||
if (it.endpoint.isNotEmpty()) builder.parseEndpoint(it.endpoint.trim())
|
|
||||||
if (it.persistentKeepalive.isNotEmpty()) {
|
|
||||||
builder.parsePersistentKeepalive(it.persistentKeepalive.trim())
|
|
||||||
}
|
|
||||||
builder.build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun emptyCheckedPackagesList() {
|
private fun emptyCheckedPackagesList() {
|
||||||
_uiState.value = _uiState.value.copy(checkedPackageNames = emptyList())
|
_uiState.value = _uiState.value.copy(checkedPackageNames = emptyList())
|
||||||
}
|
}
|
||||||
@@ -191,226 +190,147 @@ constructor(
|
|||||||
return builder.build()
|
return builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildAmInterfaceListFromProxyInterface(): org.amnezia.awg.config.Interface {
|
fun onSaveAllChanges(): Result<Event> {
|
||||||
val builder = org.amnezia.awg.config.Interface.Builder()
|
|
||||||
builder.parsePrivateKey(_uiState.value.interfaceProxy.privateKey.trim())
|
|
||||||
builder.parseAddresses(_uiState.value.interfaceProxy.addresses.trim())
|
|
||||||
if (_uiState.value.interfaceProxy.dnsServers.isNotEmpty()) {
|
|
||||||
builder.parseDnsServers(_uiState.value.interfaceProxy.dnsServers.trim())
|
|
||||||
}
|
|
||||||
if (_uiState.value.interfaceProxy.mtu.isNotEmpty())
|
|
||||||
builder.parseMtu(_uiState.value.interfaceProxy.mtu.trim())
|
|
||||||
if (_uiState.value.interfaceProxy.listenPort.isNotEmpty()) {
|
|
||||||
builder.parseListenPort(_uiState.value.interfaceProxy.listenPort.trim())
|
|
||||||
}
|
|
||||||
if (isAllApplicationsEnabled()) emptyCheckedPackagesList()
|
|
||||||
if (_uiState.value.include) builder.includeApplications(_uiState.value.checkedPackageNames)
|
|
||||||
if (!_uiState.value.include) builder.excludeApplications(_uiState.value.checkedPackageNames)
|
|
||||||
if(_uiState.value.interfaceProxy.junkPacketCount.isNotEmpty()) {
|
|
||||||
builder.setJunkPacketCount(_uiState.value.interfaceProxy.junkPacketCount.trim().toInt())
|
|
||||||
}
|
|
||||||
if(_uiState.value.interfaceProxy.junkPacketMinSize.isNotEmpty()) {
|
|
||||||
builder.setJunkPacketMinSize(_uiState.value.interfaceProxy.junkPacketMinSize.trim().toInt())
|
|
||||||
}
|
|
||||||
if(_uiState.value.interfaceProxy.junkPacketMaxSize.isNotEmpty()) {
|
|
||||||
builder.setJunkPacketMaxSize(_uiState.value.interfaceProxy.junkPacketMaxSize.trim().toInt())
|
|
||||||
}
|
|
||||||
if(_uiState.value.interfaceProxy.initPacketJunkSize.isNotEmpty()) {
|
|
||||||
builder.setInitPacketJunkSize(_uiState.value.interfaceProxy.initPacketJunkSize.trim().toInt())
|
|
||||||
}
|
|
||||||
if(_uiState.value.interfaceProxy.responsePacketJunkSize.isNotEmpty()) {
|
|
||||||
builder.setResponsePacketJunkSize(_uiState.value.interfaceProxy.responsePacketJunkSize.trim().toInt())
|
|
||||||
}
|
|
||||||
if(_uiState.value.interfaceProxy.initPacketMagicHeader.isNotEmpty()) {
|
|
||||||
builder.setInitPacketMagicHeader(_uiState.value.interfaceProxy.initPacketMagicHeader.trim().toLong())
|
|
||||||
}
|
|
||||||
if(_uiState.value.interfaceProxy.responsePacketMagicHeader.isNotEmpty()) {
|
|
||||||
builder.setResponsePacketMagicHeader(_uiState.value.interfaceProxy.responsePacketMagicHeader.trim().toLong())
|
|
||||||
}
|
|
||||||
if(_uiState.value.interfaceProxy.transportPacketMagicHeader.isNotEmpty()) {
|
|
||||||
builder.setTransportPacketMagicHeader(_uiState.value.interfaceProxy.transportPacketMagicHeader.trim().toLong())
|
|
||||||
}
|
|
||||||
if(_uiState.value.interfaceProxy.underloadPacketMagicHeader.isNotEmpty()) {
|
|
||||||
builder.setUnderloadPacketMagicHeader(_uiState.value.interfaceProxy.underloadPacketMagicHeader.trim().toLong())
|
|
||||||
}
|
|
||||||
return builder.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildConfig() : Config {
|
|
||||||
val peerList = buildPeerListFromProxyPeers()
|
|
||||||
val wgInterface = buildInterfaceListFromProxyInterface()
|
|
||||||
return Config.Builder().addPeers(peerList).setInterface(wgInterface).build()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildAmConfig() : org.amnezia.awg.config.Config {
|
|
||||||
val peerList = buildAmPeerListFromProxyPeers()
|
|
||||||
val amInterface = buildAmInterfaceListFromProxyInterface()
|
|
||||||
return org.amnezia.awg.config.Config.Builder().addPeers(peerList).setInterface(amInterface).build()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onSaveAllChanges(configType: ConfigType): Result<Unit> {
|
|
||||||
return try {
|
return try {
|
||||||
val wgQuick = buildConfig().toWgQuickString()
|
val peerList = buildPeerListFromProxyPeers()
|
||||||
val amQuick = if(configType == ConfigType.AMNEZIA) {
|
val wgInterface = buildInterfaceListFromProxyInterface()
|
||||||
buildAmConfig().toAwgQuickString()
|
val config = Config.Builder().addPeers(peerList).setInterface(wgInterface).build()
|
||||||
} else TunnelConfig.AM_QUICK_DEFAULT
|
|
||||||
val tunnelConfig = when (uiState.value.tunnel) {
|
val tunnelConfig = when (uiState.value.tunnel) {
|
||||||
null -> TunnelConfig(
|
null -> TunnelConfig(
|
||||||
name = _uiState.value.tunnelName,
|
name = _uiState.value.tunnelName,
|
||||||
wgQuick = wgQuick,
|
wgQuick = config.toAwgQuickString(),
|
||||||
amQuick = amQuick
|
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> uiState.value.tunnel!!.copy(
|
else -> uiState.value.tunnel!!.copy(
|
||||||
name = _uiState.value.tunnelName,
|
name = _uiState.value.tunnelName,
|
||||||
wgQuick = wgQuick,
|
wgQuick = config.toAwgQuickString(),
|
||||||
amQuick = amQuick
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
updateTunnelConfig(tunnelConfig)
|
updateTunnelConfig(tunnelConfig)
|
||||||
Result.success(Unit)
|
Result.Success(Event.Message.ConfigSaved)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
val message = e.message?.substringAfter(":", missingDelimiterValue = "")
|
val message = e.message?.substringAfter(":", missingDelimiterValue = "")
|
||||||
val stringValue = message?.let {
|
Result.Error(Event.Error.ConfigParseError(message ?: ""))
|
||||||
StringValue.DynamicString(message)
|
|
||||||
} ?: StringValue.StringResource(R.string.unknown_error)
|
|
||||||
Result.failure(WgTunnelExceptions.ConfigParseError(stringValue))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onPeerPublicKeyChange(index: Int, value: String) {
|
fun onPeerPublicKeyChange(index: Int, value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
proxyPeers =
|
proxyPeers =
|
||||||
_uiState.value.proxyPeers.update(
|
_uiState.value.proxyPeers.update(
|
||||||
index,
|
index,
|
||||||
_uiState.value.proxyPeers[index].copy(publicKey = value),
|
_uiState.value.proxyPeers[index].copy(publicKey = value),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onPreSharedKeyChange(index: Int, value: String) {
|
fun onPreSharedKeyChange(index: Int, value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
proxyPeers =
|
proxyPeers =
|
||||||
_uiState.value.proxyPeers.update(
|
_uiState.value.proxyPeers.update(
|
||||||
index,
|
index,
|
||||||
_uiState.value.proxyPeers[index].copy(preSharedKey = value),
|
_uiState.value.proxyPeers[index].copy(preSharedKey = value),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onEndpointChange(index: Int, value: String) {
|
fun onEndpointChange(index: Int, value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
proxyPeers =
|
proxyPeers =
|
||||||
_uiState.value.proxyPeers.update(
|
_uiState.value.proxyPeers.update(
|
||||||
index,
|
index,
|
||||||
_uiState.value.proxyPeers[index].copy(endpoint = value),
|
_uiState.value.proxyPeers[index].copy(endpoint = value),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onAllowedIpsChange(index: Int, value: String) {
|
fun onAllowedIpsChange(index: Int, value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
proxyPeers =
|
proxyPeers =
|
||||||
_uiState.value.proxyPeers.update(
|
_uiState.value.proxyPeers.update(
|
||||||
index,
|
index,
|
||||||
_uiState.value.proxyPeers[index].copy(allowedIps = value),
|
_uiState.value.proxyPeers[index].copy(allowedIps = value),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onPersistentKeepaliveChanged(index: Int, value: String) {
|
fun onPersistentKeepaliveChanged(index: Int, value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
proxyPeers =
|
proxyPeers =
|
||||||
_uiState.value.proxyPeers.update(
|
_uiState.value.proxyPeers.update(
|
||||||
index,
|
index,
|
||||||
_uiState.value.proxyPeers[index].copy(persistentKeepalive = value),
|
_uiState.value.proxyPeers[index].copy(persistentKeepalive = value),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDeletePeer(index: Int) {
|
fun onDeletePeer(index: Int) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
proxyPeers = _uiState.value.proxyPeers.removeAt(index),
|
proxyPeers = _uiState.value.proxyPeers.removeAt(index),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addEmptyPeer() {
|
fun addEmptyPeer() {
|
||||||
_uiState.update {
|
_uiState.value = _uiState.value.copy(proxyPeers = _uiState.value.proxyPeers + PeerProxy())
|
||||||
it.copy(proxyPeers = _uiState.value.proxyPeers + PeerProxy())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateKeyPair() {
|
fun generateKeyPair() {
|
||||||
val keyPair = KeyPair()
|
val keyPair = KeyPair()
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
interfaceProxy =
|
interfaceProxy =
|
||||||
_uiState.value.interfaceProxy.copy(
|
_uiState.value.interfaceProxy.copy(
|
||||||
privateKey = keyPair.privateKey.toBase64(),
|
privateKey = keyPair.privateKey.toBase64(),
|
||||||
publicKey = keyPair.publicKey.toBase64(),
|
publicKey = keyPair.publicKey.toBase64(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onAddressesChanged(value: String) {
|
fun onAddressesChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(addresses = value),
|
interfaceProxy = _uiState.value.interfaceProxy.copy(addresses = value),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onListenPortChanged(value: String) {
|
fun onListenPortChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(listenPort = value),
|
interfaceProxy = _uiState.value.interfaceProxy.copy(listenPort = value),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDnsServersChanged(value: String) {
|
fun onDnsServersChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(dnsServers = value),
|
interfaceProxy = _uiState.value.interfaceProxy.copy(dnsServers = value),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMtuChanged(value: String) {
|
fun onMtuChanged(value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(interfaceProxy = _uiState.value.interfaceProxy.copy(mtu = value))
|
_uiState.value.copy(interfaceProxy = _uiState.value.interfaceProxy.copy(mtu = value))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onInterfacePublicKeyChange(value: String) {
|
private fun onInterfacePublicKeyChange(value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(publicKey = value),
|
interfaceProxy = _uiState.value.interfaceProxy.copy(publicKey = value),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onPrivateKeyChange(value: String) {
|
fun onPrivateKeyChange(value: String) {
|
||||||
_uiState.update {
|
_uiState.value =
|
||||||
it.copy(
|
_uiState.value.copy(
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(privateKey = value),
|
interfaceProxy = _uiState.value.interfaceProxy.copy(privateKey = value),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
if (NumberUtils.isValidKey(value)) {
|
if (NumberUtils.isValidKey(value)) {
|
||||||
val pair = KeyPair(Key.fromBase64(value))
|
val pair = KeyPair(Key.fromBase64(value))
|
||||||
onInterfacePublicKeyChange(pair.publicKey.toBase64())
|
onInterfacePublicKeyChange(pair.publicKey.toBase64())
|
||||||
@@ -424,77 +344,6 @@ constructor(
|
|||||||
getAllInternetCapablePackages().filter {
|
getAllInternetCapablePackages().filter {
|
||||||
getPackageLabel(it).lowercase().contains(query.lowercase())
|
getPackageLabel(it).lowercase().contains(query.lowercase())
|
||||||
}
|
}
|
||||||
_uiState.update { it.copy(packages = packages) }
|
_uiState.value = _uiState.value.copy(packages = packages)
|
||||||
}
|
|
||||||
|
|
||||||
fun onJunkPacketCountChanged(value: String) {
|
|
||||||
_uiState.update {
|
|
||||||
it.copy(
|
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(junkPacketCount = value)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fun onJunkPacketMinSizeChanged(value: String) {
|
|
||||||
_uiState.update {
|
|
||||||
it.copy(
|
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(junkPacketMinSize = value)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onJunkPacketMaxSizeChanged(value: String) {
|
|
||||||
_uiState.update {
|
|
||||||
it.copy(
|
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(junkPacketMaxSize = value)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onInitPacketJunkSizeChanged(value: String) {
|
|
||||||
_uiState.update {
|
|
||||||
it.copy(
|
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(initPacketJunkSize = value)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onResponsePacketJunkSize(value: String) {
|
|
||||||
_uiState.update {
|
|
||||||
it.copy(
|
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(responsePacketJunkSize = value)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onInitPacketMagicHeader(value: String) {
|
|
||||||
_uiState.update {
|
|
||||||
it.copy(
|
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(initPacketMagicHeader = value)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onResponsePacketMagicHeader(value: String) {
|
|
||||||
_uiState.update {
|
|
||||||
it.copy(
|
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(responsePacketMagicHeader = value)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onTransportPacketMagicHeader(value: String) {
|
|
||||||
_uiState.update {
|
|
||||||
it.copy(
|
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(transportPacketMagicHeader = value)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onUnderloadPacketMagicHeader(value: String) {
|
|
||||||
_uiState.update {
|
|
||||||
it.copy(
|
|
||||||
interfaceProxy = _uiState.value.interfaceProxy.copy(underloadPacketMagicHeader = value)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-63
@@ -1,63 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.config.model
|
|
||||||
|
|
||||||
import com.wireguard.config.Interface
|
|
||||||
|
|
||||||
data class InterfaceProxy(
|
|
||||||
val privateKey: String = "",
|
|
||||||
val publicKey: String = "",
|
|
||||||
val addresses: String = "",
|
|
||||||
val dnsServers: String = "",
|
|
||||||
val listenPort: String = "",
|
|
||||||
val mtu: String = "",
|
|
||||||
val junkPacketCount: String = "",
|
|
||||||
val junkPacketMinSize: String = "",
|
|
||||||
val junkPacketMaxSize: String = "",
|
|
||||||
val initPacketJunkSize: String = "",
|
|
||||||
val responsePacketJunkSize: String = "",
|
|
||||||
val initPacketMagicHeader: String = "",
|
|
||||||
val responsePacketMagicHeader: String = "",
|
|
||||||
val underloadPacketMagicHeader: String = "",
|
|
||||||
val transportPacketMagicHeader: String = "",
|
|
||||||
) {
|
|
||||||
companion object {
|
|
||||||
fun from(i: Interface): InterfaceProxy {
|
|
||||||
return InterfaceProxy(
|
|
||||||
publicKey = i.keyPair.publicKey.toBase64().trim(),
|
|
||||||
privateKey = i.keyPair.privateKey.toBase64().trim(),
|
|
||||||
addresses = i.addresses.joinToString(", ").trim(),
|
|
||||||
dnsServers = i.dnsServers.joinToString(", ").replace("/", "").trim(),
|
|
||||||
listenPort =
|
|
||||||
if (i.listenPort.isPresent) {
|
|
||||||
i.listenPort.get().toString().trim()
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
mtu = if (i.mtu.isPresent) i.mtu.get().toString().trim() else "",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
fun from(i: org.amnezia.awg.config.Interface) : InterfaceProxy {
|
|
||||||
return InterfaceProxy(
|
|
||||||
publicKey = i.keyPair.publicKey.toBase64().trim(),
|
|
||||||
privateKey = i.keyPair.privateKey.toBase64().trim(),
|
|
||||||
addresses = i.addresses.joinToString(", ").trim(),
|
|
||||||
dnsServers = i.dnsServers.joinToString(", ").replace("/", "").trim(),
|
|
||||||
listenPort =
|
|
||||||
if (i.listenPort.isPresent) {
|
|
||||||
i.listenPort.get().toString().trim()
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
mtu = if (i.mtu.isPresent) i.mtu.get().toString().trim() else "",
|
|
||||||
junkPacketCount = if(i.junkPacketCount.isPresent) i.junkPacketCount.get().toString() else "",
|
|
||||||
junkPacketMinSize = if(i.junkPacketMinSize.isPresent) i.junkPacketMinSize.get().toString() else "",
|
|
||||||
junkPacketMaxSize = if(i.junkPacketMaxSize.isPresent) i.junkPacketMaxSize.get().toString() else "",
|
|
||||||
initPacketJunkSize = if(i.initPacketJunkSize.isPresent) i.initPacketJunkSize.get().toString() else "",
|
|
||||||
responsePacketJunkSize = if(i.responsePacketJunkSize.isPresent) i.responsePacketJunkSize.get().toString() else "",
|
|
||||||
initPacketMagicHeader = if(i.initPacketMagicHeader.isPresent) i.initPacketMagicHeader.get().toString() else "",
|
|
||||||
responsePacketMagicHeader = if(i.responsePacketMagicHeader.isPresent) i.responsePacketMagicHeader.get().toString() else "",
|
|
||||||
transportPacketMagicHeader = if(i.transportPacketMagicHeader.isPresent) i.transportPacketMagicHeader.get().toString() else "",
|
|
||||||
underloadPacketMagicHeader = if(i.underloadPacketMagicHeader.isPresent) i.underloadPacketMagicHeader.get().toString() else "",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
|
||||||
|
|
||||||
enum class ConfigType {
|
|
||||||
AMNEZIA,
|
|
||||||
WIREGUARD
|
|
||||||
}
|
|
||||||
+67
-124
@@ -29,11 +29,11 @@ import androidx.compose.foundation.lazy.items
|
|||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.overscroll
|
import androidx.compose.foundation.overscroll
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.text.ClickableText
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Create
|
import androidx.compose.material.icons.filled.Create
|
||||||
import androidx.compose.material.icons.filled.FileOpen
|
import androidx.compose.material.icons.filled.FileOpen
|
||||||
import androidx.compose.material.icons.filled.QrCode
|
import androidx.compose.material.icons.filled.QrCode
|
||||||
|
import androidx.compose.material.icons.rounded.Add
|
||||||
import androidx.compose.material.icons.rounded.Bolt
|
import androidx.compose.material.icons.rounded.Bolt
|
||||||
import androidx.compose.material.icons.rounded.Circle
|
import androidx.compose.material.icons.rounded.Circle
|
||||||
import androidx.compose.material.icons.rounded.CopyAll
|
import androidx.compose.material.icons.rounded.CopyAll
|
||||||
@@ -45,6 +45,7 @@ import androidx.compose.material.icons.rounded.Star
|
|||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.FabPosition
|
import androidx.compose.material3.FabPosition
|
||||||
|
import androidx.compose.material3.FloatingActionButton
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
@@ -80,26 +81,18 @@ import androidx.compose.ui.input.pointer.pointerInput
|
|||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.SpanStyle
|
|
||||||
import androidx.compose.ui.text.buildAnnotatedString
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
import androidx.compose.ui.text.font.FontStyle
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.withStyle
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.iamageo.multifablibrary.FabIcon
|
|
||||||
import com.iamageo.multifablibrary.FabOption
|
|
||||||
import com.iamageo.multifablibrary.MultiFabItem
|
|
||||||
import com.iamageo.multifablibrary.MultiFloatingActionButton
|
|
||||||
import com.journeyapps.barcodescanner.ScanContract
|
import com.journeyapps.barcodescanner.ScanContract
|
||||||
import com.journeyapps.barcodescanner.ScanOptions
|
import com.journeyapps.barcodescanner.ScanOptions
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.CaptureActivityPortrait
|
import com.zaneschepke.wireguardautotunnel.ui.CaptureActivityPortrait
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Screen
|
import com.zaneschepke.wireguardautotunnel.ui.Screen
|
||||||
@@ -108,13 +101,15 @@ import com.zaneschepke.wireguardautotunnel.ui.common.screen.LoadingScreen
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.corn
|
import com.zaneschepke.wireguardautotunnel.ui.theme.corn
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.mint
|
import com.zaneschepke.wireguardautotunnel.ui.theme.mint
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.getMessage
|
import com.zaneschepke.wireguardautotunnel.util.Event
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Result
|
||||||
import com.zaneschepke.wireguardautotunnel.util.handshakeStatus
|
import com.zaneschepke.wireguardautotunnel.util.handshakeStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.util.mapPeerStats
|
import com.zaneschepke.wireguardautotunnel.util.mapPeerStats
|
||||||
import com.zaneschepke.wireguardautotunnel.util.truncateWithEllipsis
|
import com.zaneschepke.wireguardautotunnel.util.truncateWithEllipsis
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.amnezia.awg.backend.Tunnel
|
||||||
|
|
||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
|
||||||
@@ -132,7 +127,6 @@ fun MainScreen(
|
|||||||
|
|
||||||
val sheetState = rememberModalBottomSheetState()
|
val sheetState = rememberModalBottomSheetState()
|
||||||
var showBottomSheet by remember { mutableStateOf(false) }
|
var showBottomSheet by remember { mutableStateOf(false) }
|
||||||
var configType by remember { mutableStateOf(ConfigType.WIREGUARD) }
|
|
||||||
|
|
||||||
// Nested scroll for control FAB
|
// Nested scroll for control FAB
|
||||||
val nestedScrollConnection = remember {
|
val nestedScrollConnection = remember {
|
||||||
@@ -193,7 +187,7 @@ fun MainScreen(
|
|||||||
name.startsWith(Constants.ANDROID_TV_EXPLORER_STUB)
|
name.startsWith(Constants.ANDROID_TV_EXPLORER_STUB)
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
appViewModel.showSnackbarMessage(context.getString(R.string.error_no_file_explorer))
|
appViewModel.showSnackbarMessage(Event.Error.FileExplorerRequired.message)
|
||||||
}
|
}
|
||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
@@ -201,8 +195,11 @@ fun MainScreen(
|
|||||||
) { data ->
|
) { data ->
|
||||||
if (data == null) return@rememberLauncherForActivityResult
|
if (data == null) return@rememberLauncherForActivityResult
|
||||||
scope.launch {
|
scope.launch {
|
||||||
viewModel.onTunnelFileSelected(data, configType, context).onFailure {
|
viewModel.onTunnelFileSelected(data).let {
|
||||||
appViewModel.showSnackbarMessage(it.getMessage(context))
|
when (it) {
|
||||||
|
is Result.Error -> appViewModel.showSnackbarMessage(it.error.message)
|
||||||
|
is Result.Success -> {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,8 +209,11 @@ fun MainScreen(
|
|||||||
onResult = {
|
onResult = {
|
||||||
if (it.contents != null) {
|
if (it.contents != null) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
viewModel.onTunnelQrResult(it.contents, configType).onFailure {
|
viewModel.onTunnelQrResult(it.contents).let { result ->
|
||||||
appViewModel.showSnackbarMessage(it.getMessage(context))
|
when (result) {
|
||||||
|
is Result.Success -> {}
|
||||||
|
is Result.Error -> appViewModel.showSnackbarMessage(result.error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,7 +226,7 @@ fun MainScreen(
|
|||||||
confirmButton = {
|
confirmButton = {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
selectedTunnel?.let { viewModel.onDelete(it, context) }
|
selectedTunnel?.let { viewModel.onDelete(it) }
|
||||||
showDeleteTunnelAlertDialog = false
|
showDeleteTunnelAlertDialog = false
|
||||||
selectedTunnel = null
|
selectedTunnel = null
|
||||||
},
|
},
|
||||||
@@ -246,7 +246,7 @@ fun MainScreen(
|
|||||||
|
|
||||||
fun onTunnelToggle(checked: Boolean, tunnel: TunnelConfig) {
|
fun onTunnelToggle(checked: Boolean, tunnel: TunnelConfig) {
|
||||||
if (appViewModel.isRequiredPermissionGranted()) {
|
if (appViewModel.isRequiredPermissionGranted()) {
|
||||||
if (checked) viewModel.onTunnelStart(tunnel, context) else viewModel.onTunnelStop(context)
|
if (checked) viewModel.onTunnelStart(tunnel) else viewModel.onTunnelStop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,30 +254,14 @@ fun MainScreen(
|
|||||||
return LoadingScreen()
|
return LoadingScreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun launchQrScanner() {
|
|
||||||
val scanOptions = ScanOptions()
|
|
||||||
scanOptions.setDesiredBarcodeFormats(ScanOptions.QR_CODE)
|
|
||||||
scanOptions.setOrientationLocked(true)
|
|
||||||
scanOptions.setPrompt(
|
|
||||||
context.getString(R.string.scanning_qr),
|
|
||||||
)
|
|
||||||
scanOptions.setBeepEnabled(false)
|
|
||||||
scanOptions.captureActivity =
|
|
||||||
CaptureActivityPortrait::class.java
|
|
||||||
scanLauncher.launch(scanOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.pointerInput(Unit) {
|
Modifier.pointerInput(Unit) {
|
||||||
if(uiState.tunnels.isNotEmpty()) {
|
detectTapGestures(
|
||||||
detectTapGestures(
|
onTap = {
|
||||||
onTap = {
|
selectedTunnel = null
|
||||||
selectedTunnel = null
|
},
|
||||||
},
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
floatingActionButtonPosition = FabPosition.End,
|
floatingActionButtonPosition = FabPosition.End,
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
@@ -289,7 +273,7 @@ fun MainScreen(
|
|||||||
val secondaryColor = MaterialTheme.colorScheme.secondary
|
val secondaryColor = MaterialTheme.colorScheme.secondary
|
||||||
val hoverColor = MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp)
|
val hoverColor = MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp)
|
||||||
var fobColor by remember { mutableStateOf(secondaryColor) }
|
var fobColor by remember { mutableStateOf(secondaryColor) }
|
||||||
MultiFloatingActionButton(
|
FloatingActionButton(
|
||||||
modifier =
|
modifier =
|
||||||
(if (
|
(if (
|
||||||
WireGuardAutoTunnel.isRunningOnAndroidTv() &&
|
WireGuardAutoTunnel.isRunningOnAndroidTv() &&
|
||||||
@@ -302,45 +286,29 @@ fun MainScreen(
|
|||||||
fobColor = if (it.isFocused) hoverColor else secondaryColor
|
fobColor = if (it.isFocused) hoverColor else secondaryColor
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fabIcon = FabIcon(
|
onClick = { showBottomSheet = true },
|
||||||
iconRes = R.drawable.add,
|
containerColor = fobColor,
|
||||||
iconResAfterRotate = R.drawable.close,
|
|
||||||
iconRotate = 180f
|
|
||||||
),
|
|
||||||
fabOption = FabOption(
|
|
||||||
iconTint = MaterialTheme.colorScheme.background,
|
|
||||||
backgroundTint = MaterialTheme.colorScheme.primary,
|
|
||||||
),
|
|
||||||
itemsMultiFab = listOf(
|
|
||||||
MultiFabItem(
|
|
||||||
label = {
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.amnezia),
|
|
||||||
color = Color.White,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(end = 10.dp)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
icon = R.drawable.add,
|
|
||||||
value = ConfigType.AMNEZIA.name,
|
|
||||||
),
|
|
||||||
MultiFabItem(
|
|
||||||
label = {
|
|
||||||
Text(stringResource(id = R.string.wireguard), color = Color.White, textAlign = TextAlign.Center, modifier = Modifier.padding(end = 10.dp))
|
|
||||||
},
|
|
||||||
icon = R.drawable.add,
|
|
||||||
value = ConfigType.WIREGUARD.name
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onFabItemClicked = {
|
|
||||||
showBottomSheet = true
|
|
||||||
configType = ConfigType.valueOf(it.value)
|
|
||||||
},
|
|
||||||
shape = RoundedCornerShape(16.dp),
|
shape = RoundedCornerShape(16.dp),
|
||||||
)
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Rounded.Add,
|
||||||
|
contentDescription = stringResource(id = R.string.add_tunnel),
|
||||||
|
tint = Color.DarkGray,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
AnimatedVisibility(uiState.tunnels.isEmpty(), exit = fadeOut(), enter = fadeIn()) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize(),
|
||||||
|
) {
|
||||||
|
Text(text = stringResource(R.string.no_tunnels), fontStyle = FontStyle.Italic)
|
||||||
|
}
|
||||||
|
}
|
||||||
if (showBottomSheet) {
|
if (showBottomSheet) {
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
onDismissRequest = { showBottomSheet = false },
|
onDismissRequest = { showBottomSheet = false },
|
||||||
@@ -376,7 +344,16 @@ fun MainScreen(
|
|||||||
.clickable {
|
.clickable {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
showBottomSheet = false
|
showBottomSheet = false
|
||||||
launchQrScanner()
|
val scanOptions = ScanOptions()
|
||||||
|
scanOptions.setDesiredBarcodeFormats(ScanOptions.QR_CODE)
|
||||||
|
scanOptions.setOrientationLocked(true)
|
||||||
|
scanOptions.setPrompt(
|
||||||
|
context.getString(R.string.scanning_qr),
|
||||||
|
)
|
||||||
|
scanOptions.setBeepEnabled(false)
|
||||||
|
scanOptions.captureActivity =
|
||||||
|
CaptureActivityPortrait::class.java
|
||||||
|
scanLauncher.launch(scanOptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(10.dp),
|
.padding(10.dp),
|
||||||
@@ -400,7 +377,7 @@ fun MainScreen(
|
|||||||
.clickable {
|
.clickable {
|
||||||
showBottomSheet = false
|
showBottomSheet = false
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
"${Screen.Config.route}/${Constants.MANUAL_TUNNEL_CONFIG_ID}?configType=${configType}",
|
"${Screen.Config.route}/${Constants.MANUAL_TUNNEL_CONFIG_ID}",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.padding(10.dp),
|
.padding(10.dp),
|
||||||
@@ -424,46 +401,12 @@ fun MainScreen(
|
|||||||
modifier =
|
modifier =
|
||||||
Modifier
|
Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.overscroll(ScrollableDefaults.overscrollEffect())
|
.overscroll(ScrollableDefaults.overscrollEffect()).nestedScroll(nestedScrollConnection),
|
||||||
.nestedScroll(nestedScrollConnection),
|
|
||||||
state = rememberLazyListState(0, uiState.tunnels.count()),
|
state = rememberLazyListState(0, uiState.tunnels.count()),
|
||||||
userScrollEnabled = true,
|
userScrollEnabled = true,
|
||||||
reverseLayout = false,
|
reverseLayout = false,
|
||||||
flingBehavior = ScrollableDefaults.flingBehavior(),
|
flingBehavior = ScrollableDefaults.flingBehavior(),
|
||||||
) {
|
) {
|
||||||
item {
|
|
||||||
val gettingStarted = buildAnnotatedString {
|
|
||||||
append(stringResource(id = R.string.see_the))
|
|
||||||
append(" ")
|
|
||||||
pushStringAnnotation(tag = "gettingStarted", annotation = stringResource(id = R.string.getting_started_url))
|
|
||||||
withStyle(style = SpanStyle(color = MaterialTheme.colorScheme.primary)) {
|
|
||||||
append(stringResource(id = R.string.getting_started_guide))
|
|
||||||
}
|
|
||||||
pop()
|
|
||||||
append(" ")
|
|
||||||
append(stringResource(R.string.unsure_how))
|
|
||||||
append(".")
|
|
||||||
}
|
|
||||||
AnimatedVisibility(
|
|
||||||
uiState.tunnels.isEmpty(), exit = fadeOut(), enter = fadeIn()) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
modifier = Modifier.padding(top = 100.dp)
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(R.string.no_tunnels), fontStyle = FontStyle.Italic)
|
|
||||||
ClickableText(
|
|
||||||
modifier = Modifier.padding(vertical = 10.dp, horizontal = 24.dp),
|
|
||||||
text = gettingStarted,
|
|
||||||
style = MaterialTheme.typography.bodyMedium.copy(color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.Center),
|
|
||||||
) {
|
|
||||||
gettingStarted.getStringAnnotations(tag = "gettingStarted", it, it).firstOrNull()?.let { annotation ->
|
|
||||||
appViewModel.openWebPage(annotation.item, context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
item {
|
item {
|
||||||
if (uiState.settings.isAutoTunnelEnabled) {
|
if (uiState.settings.isAutoTunnelEnabled) {
|
||||||
val autoTunnelingLabel = buildAnnotatedString {
|
val autoTunnelingLabel = buildAnnotatedString {
|
||||||
@@ -519,7 +462,7 @@ fun MainScreen(
|
|||||||
val leadingIconColor =
|
val leadingIconColor =
|
||||||
(if (
|
(if (
|
||||||
uiState.vpnState.tunnelConfig?.name == tunnel.name &&
|
uiState.vpnState.tunnelConfig?.name == tunnel.name &&
|
||||||
uiState.vpnState.status == TunnelState.UP
|
uiState.vpnState.status == Tunnel.State.UP
|
||||||
) {
|
) {
|
||||||
uiState.vpnState.statistics
|
uiState.vpnState.statistics
|
||||||
?.mapPeerStats()
|
?.mapPeerStats()
|
||||||
@@ -565,10 +508,10 @@ fun MainScreen(
|
|||||||
text = tunnel.name.truncateWithEllipsis(Constants.ALLOWED_DISPLAY_NAME_LENGTH),
|
text = tunnel.name.truncateWithEllipsis(Constants.ALLOWED_DISPLAY_NAME_LENGTH),
|
||||||
onHold = {
|
onHold = {
|
||||||
if (
|
if (
|
||||||
(uiState.vpnState.status == TunnelState.UP) &&
|
(uiState.vpnState.status == Tunnel.State.UP) &&
|
||||||
(tunnel.name == uiState.vpnState.tunnelConfig?.name)
|
(tunnel.name == uiState.vpnState.tunnelConfig?.name)
|
||||||
) {
|
) {
|
||||||
appViewModel.showSnackbarMessage(context.getString(R.string.turn_off_tunnel))
|
appViewModel.showSnackbarMessage(Event.Message.TunnelOffAction.message)
|
||||||
return@RowListItem
|
return@RowListItem
|
||||||
}
|
}
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
@@ -577,7 +520,7 @@ fun MainScreen(
|
|||||||
onClick = {
|
onClick = {
|
||||||
if (!WireGuardAutoTunnel.isRunningOnAndroidTv()) {
|
if (!WireGuardAutoTunnel.isRunningOnAndroidTv()) {
|
||||||
if (
|
if (
|
||||||
uiState.vpnState.status == TunnelState.UP &&
|
uiState.vpnState.status == Tunnel.State.UP &&
|
||||||
(uiState.vpnState.tunnelConfig?.name == tunnel.name)
|
(uiState.vpnState.tunnelConfig?.name == tunnel.name)
|
||||||
) {
|
) {
|
||||||
expanded.value = !expanded.value
|
expanded.value = !expanded.value
|
||||||
@@ -602,7 +545,7 @@ fun MainScreen(
|
|||||||
!uiState.settings.isAutoTunnelPaused
|
!uiState.settings.isAutoTunnelPaused
|
||||||
) {
|
) {
|
||||||
appViewModel.showSnackbarMessage(
|
appViewModel.showSnackbarMessage(
|
||||||
context.getString(R.string.turn_off_tunnel),
|
Event.Message.AutoTunnelOffAction.message,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
@@ -635,7 +578,7 @@ fun MainScreen(
|
|||||||
} else {
|
} else {
|
||||||
val checked by remember {
|
val checked by remember {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
(uiState.vpnState.status == TunnelState.UP &&
|
(uiState.vpnState.status == Tunnel.State.UP &&
|
||||||
tunnel.name == uiState.vpnState.tunnelConfig?.name)
|
tunnel.name == uiState.vpnState.tunnelConfig?.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -657,7 +600,7 @@ fun MainScreen(
|
|||||||
onClick = {
|
onClick = {
|
||||||
if (uiState.settings.isAutoTunnelEnabled) {
|
if (uiState.settings.isAutoTunnelEnabled) {
|
||||||
appViewModel.showSnackbarMessage(
|
appViewModel.showSnackbarMessage(
|
||||||
context.getString(R.string.turn_off_auto),
|
Event.Message.AutoTunnelOffAction.message,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
selectedTunnel = tunnel
|
selectedTunnel = tunnel
|
||||||
@@ -677,13 +620,13 @@ fun MainScreen(
|
|||||||
modifier = Modifier.focusRequester(focusRequester),
|
modifier = Modifier.focusRequester(focusRequester),
|
||||||
onClick = {
|
onClick = {
|
||||||
if (
|
if (
|
||||||
uiState.vpnState.status == TunnelState.UP &&
|
uiState.vpnState.status == Tunnel.State.UP &&
|
||||||
(uiState.vpnState.tunnelConfig?.name == tunnel.name)
|
(uiState.vpnState.tunnelConfig?.name == tunnel.name)
|
||||||
) {
|
) {
|
||||||
expanded.value = !expanded.value
|
expanded.value = !expanded.value
|
||||||
} else {
|
} else {
|
||||||
appViewModel.showSnackbarMessage(
|
appViewModel.showSnackbarMessage(
|
||||||
context.getString(R.string.turn_on_tunnel),
|
Event.Message.TunnelOnAction.message,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -700,11 +643,11 @@ fun MainScreen(
|
|||||||
IconButton(
|
IconButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
if (
|
if (
|
||||||
uiState.vpnState.status == TunnelState.UP &&
|
uiState.vpnState.status == Tunnel.State.UP &&
|
||||||
tunnel.name == uiState.vpnState.tunnelConfig?.name
|
tunnel.name == uiState.vpnState.tunnelConfig?.name
|
||||||
) {
|
) {
|
||||||
appViewModel.showSnackbarMessage(
|
appViewModel.showSnackbarMessage(
|
||||||
context.getString(R.string.turn_off_tunnel),
|
Event.Message.TunnelOffAction.message,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
selectedTunnel = tunnel
|
selectedTunnel = tunnel
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnState
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.TunnelConfigs
|
import com.zaneschepke.wireguardautotunnel.util.TunnelConfigs
|
||||||
|
|
||||||
|
|||||||
+63
-131
@@ -1,22 +1,22 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.OpenableColumns
|
import android.provider.OpenableColumns
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.wireguard.config.Config
|
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Event
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelExceptions
|
import com.zaneschepke.wireguardautotunnel.util.Result
|
||||||
import com.zaneschepke.wireguardautotunnel.util.toWgQuickString
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
@@ -24,6 +24,7 @@ import kotlinx.coroutines.flow.combine
|
|||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.amnezia.awg.config.Config
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
@@ -33,6 +34,7 @@ import javax.inject.Inject
|
|||||||
class MainViewModel
|
class MainViewModel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
|
private val application: Application,
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
val vpnService: VpnService
|
val vpnService: VpnService
|
||||||
@@ -52,21 +54,21 @@ constructor(
|
|||||||
MainUiState(),
|
MainUiState(),
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun stopWatcherService(context: Context) =
|
private fun stopWatcherService() =
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
serviceManager.stopWatcherService(context)
|
serviceManager.stopWatcherService(application.applicationContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDelete(tunnel: TunnelConfig, context: Context) {
|
fun onDelete(tunnel: TunnelConfig) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val settings = appDataRepository.settings.getSettings()
|
val settings = appDataRepository.settings.getSettings()
|
||||||
val isPrimary = tunnel.isPrimaryTunnel
|
val isPrimary = tunnel.isPrimaryTunnel
|
||||||
if (appDataRepository.tunnels.count() == 1 || isPrimary) {
|
if (appDataRepository.tunnels.count() == 1 || isPrimary) {
|
||||||
stopWatcherService(context)
|
stopWatcherService()
|
||||||
resetTunnelSetting(settings)
|
resetTunnelSetting(settings)
|
||||||
}
|
}
|
||||||
appDataRepository.tunnels.delete(tunnel)
|
appDataRepository.tunnels.delete(tunnel)
|
||||||
WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate()
|
WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate(application)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,133 +81,80 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onTunnelStart(tunnelConfig: TunnelConfig, context: Context) =
|
fun onTunnelStart(tunnelConfig: TunnelConfig) =
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
Timber.d("On start called!")
|
Timber.d("On start called!")
|
||||||
serviceManager.startVpnService(
|
serviceManager.startVpnService(
|
||||||
context,
|
application.applicationContext,
|
||||||
tunnelConfig.id,
|
tunnelConfig.id,
|
||||||
isManualStart = true,
|
isManualStart = true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun onTunnelStop(context: Context) =
|
fun onTunnelStop() =
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
Timber.i("Stopping active tunnel")
|
Timber.i("Stopping active tunnel")
|
||||||
serviceManager.stopVpnService(context, isManualStop = true)
|
serviceManager.stopVpnService(application.applicationContext, isManualStop = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateConfigString(config: String, configType: ConfigType) {
|
private fun validateConfigString(config: String) {
|
||||||
when(configType) {
|
TunnelConfig.configFromQuick(config)
|
||||||
ConfigType.AMNEZIA -> TunnelConfig.configFromAmQuick(config)
|
|
||||||
ConfigType.WIREGUARD -> TunnelConfig.configFromWgQuick(config)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateQrCodeDefaultName(config : String, configType: ConfigType) : String {
|
suspend fun onTunnelQrResult(result: String): Result<Unit> {
|
||||||
return try {
|
return try {
|
||||||
when(configType) {
|
validateConfigString(result)
|
||||||
ConfigType.AMNEZIA -> {
|
val tunnelConfig =
|
||||||
TunnelConfig.configFromAmQuick(config).peers[0].endpoint.get().host
|
TunnelConfig(name = NumberUtils.generateRandomTunnelName(), wgQuick = result)
|
||||||
}
|
|
||||||
ConfigType.WIREGUARD -> {
|
|
||||||
TunnelConfig.configFromWgQuick(config).peers[0].endpoint.get().host
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e : Exception) {
|
|
||||||
Timber.e(e)
|
|
||||||
NumberUtils.generateRandomTunnelName()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun generateQrCodeTunnelName(config : String, configType: ConfigType) : String {
|
|
||||||
var defaultName = generateQrCodeDefaultName(config, configType)
|
|
||||||
val lines = config.lines().toMutableList()
|
|
||||||
val linesIterator = lines.iterator()
|
|
||||||
while(linesIterator.hasNext()) {
|
|
||||||
val next = linesIterator.next()
|
|
||||||
if(next.contains(Constants.QR_CODE_NAME_PROPERTY)) {
|
|
||||||
defaultName = next.substringAfter(Constants.QR_CODE_NAME_PROPERTY).trim()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return defaultName
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun onTunnelQrResult(result: String, configType: ConfigType): Result<Unit> {
|
|
||||||
return try {
|
|
||||||
validateConfigString(result, configType)
|
|
||||||
val tunnelName = makeTunnelNameUnique(generateQrCodeTunnelName(result, configType))
|
|
||||||
val tunnelConfig = when(configType) {
|
|
||||||
ConfigType.AMNEZIA ->{
|
|
||||||
TunnelConfig(name = tunnelName, amQuick = result,
|
|
||||||
wgQuick = TunnelConfig.configFromAmQuick(result).toWgQuickString())
|
|
||||||
}
|
|
||||||
ConfigType.WIREGUARD -> TunnelConfig(name = tunnelName, wgQuick = result)
|
|
||||||
}
|
|
||||||
addTunnel(tunnelConfig)
|
addTunnel(tunnelConfig)
|
||||||
Result.success(Unit)
|
Result.Success(Unit)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
Result.failure(WgTunnelExceptions.InvalidQrCode())
|
Result.Error(Event.Error.InvalidQrCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun makeTunnelNameUnique(name : String) : String {
|
private suspend fun saveTunnelConfigFromStream(stream: InputStream, fileName: String) {
|
||||||
val tunnels = appDataRepository.tunnels.getAll()
|
val bufferReader = stream.bufferedReader(charset = Charsets.UTF_8)
|
||||||
var tunnelName = name
|
val config = Config.parse(bufferReader)
|
||||||
var num = 1
|
val tunnelName = getNameFromFileName(fileName)
|
||||||
while (tunnels.any { it.name == tunnelName }) {
|
addTunnel(TunnelConfig(name = tunnelName, wgQuick = config.toAwgQuickString()))
|
||||||
tunnelName = name + "(${num})"
|
withContext(Dispatchers.IO) { stream.close() }
|
||||||
num++
|
|
||||||
}
|
|
||||||
return tunnelName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun saveTunnelConfigFromStream(stream: InputStream, fileName: String, type: ConfigType) {
|
private fun getInputStreamFromUri(uri: Uri): InputStream? {
|
||||||
var amQuick : String? = null
|
return application.applicationContext.contentResolver.openInputStream(uri)
|
||||||
val wgQuick = stream.use {
|
|
||||||
when(type) {
|
|
||||||
ConfigType.AMNEZIA -> {
|
|
||||||
val config = org.amnezia.awg.config.Config.parse(it)
|
|
||||||
amQuick = config.toAwgQuickString()
|
|
||||||
config.toWgQuickString()
|
|
||||||
}
|
|
||||||
ConfigType.WIREGUARD -> {
|
|
||||||
Config.parse(it).toWgQuickString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val tunnelName = makeTunnelNameUnique(getNameFromFileName(fileName))
|
|
||||||
addTunnel(TunnelConfig(name = tunnelName, wgQuick = wgQuick, amQuick = amQuick ?: TunnelConfig.AM_QUICK_DEFAULT))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getInputStreamFromUri(uri: Uri, context: Context): InputStream? {
|
suspend fun onTunnelFileSelected(uri: Uri): Result<Unit> {
|
||||||
return context.applicationContext.contentResolver.openInputStream(uri)
|
try {
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun onTunnelFileSelected(uri: Uri, configType: ConfigType, context: Context): Result<Unit> {
|
|
||||||
return try {
|
|
||||||
if (isValidUriContentScheme(uri)) {
|
if (isValidUriContentScheme(uri)) {
|
||||||
val fileName = getFileName(context, uri)
|
val fileName = getFileName(application.applicationContext, uri)
|
||||||
return when (getFileExtensionFromFileName(fileName)) {
|
when (getFileExtensionFromFileName(fileName)) {
|
||||||
Constants.CONF_FILE_EXTENSION ->
|
Constants.CONF_FILE_EXTENSION ->
|
||||||
saveTunnelFromConfUri(fileName, uri, configType, context)
|
saveTunnelFromConfUri(fileName, uri).let {
|
||||||
Constants.ZIP_FILE_EXTENSION -> saveTunnelsFromZipUri(uri, configType, context)
|
when (it) {
|
||||||
else -> Result.failure(WgTunnelExceptions.InvalidFileExtension())
|
is Result.Error -> return Result.Error(Event.Error.FileReadFailed)
|
||||||
|
is Result.Success -> return it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Constants.ZIP_FILE_EXTENSION -> saveTunnelsFromZipUri(uri)
|
||||||
|
else -> return Result.Error(Event.Error.InvalidFileExtension)
|
||||||
}
|
}
|
||||||
|
return Result.Success(Unit)
|
||||||
} else {
|
} else {
|
||||||
Result.failure(WgTunnelExceptions.InvalidFileExtension())
|
return Result.Error(Event.Error.InvalidFileExtension)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
Result.failure(WgTunnelExceptions.FileReadFailed())
|
return Result.Error(Event.Error.FileReadFailed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun saveTunnelsFromZipUri(uri: Uri, configType: ConfigType, context: Context) : Result<Unit> {
|
private suspend fun saveTunnelsFromZipUri(uri: Uri) {
|
||||||
return ZipInputStream(getInputStreamFromUri(uri, context)).use { zip ->
|
ZipInputStream(getInputStreamFromUri(uri)).use { zip ->
|
||||||
generateSequence { zip.nextEntry }
|
generateSequence { zip.nextEntry }
|
||||||
.filterNot {
|
.filterNot {
|
||||||
it.isDirectory ||
|
it.isDirectory ||
|
||||||
@@ -213,57 +162,40 @@ constructor(
|
|||||||
}
|
}
|
||||||
.forEach {
|
.forEach {
|
||||||
val name = getNameFromFileName(it.name)
|
val name = getNameFromFileName(it.name)
|
||||||
withContext(viewModelScope.coroutineContext + Dispatchers.IO) {
|
val config = Config.parse(zip)
|
||||||
try {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
var amQuick : String? = null
|
addTunnel(TunnelConfig(name = name, wgQuick = config.toAwgQuickString()))
|
||||||
val wgQuick =
|
|
||||||
when(configType) {
|
|
||||||
ConfigType.AMNEZIA -> {
|
|
||||||
val config = org.amnezia.awg.config.Config.parse(zip)
|
|
||||||
amQuick = config.toAwgQuickString()
|
|
||||||
config.toWgQuickString()
|
|
||||||
}
|
|
||||||
ConfigType.WIREGUARD -> {
|
|
||||||
Config.parse(zip).toWgQuickString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addTunnel(TunnelConfig(name = makeTunnelNameUnique(name), wgQuick = wgQuick, amQuick = amQuick ?: TunnelConfig.AM_QUICK_DEFAULT))
|
|
||||||
Result.success(Unit)
|
|
||||||
} catch (e : Exception) {
|
|
||||||
Result.failure(WgTunnelExceptions.FileReadFailed())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Result.success(Unit)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun saveTunnelFromConfUri(name: String, uri: Uri, configType: ConfigType, context: Context): Result<Unit> {
|
private suspend fun saveTunnelFromConfUri(name: String, uri: Uri): Result<Unit> {
|
||||||
val stream = getInputStreamFromUri(uri, context)
|
val stream = getInputStreamFromUri(uri)
|
||||||
return if (stream != null) {
|
return if (stream != null) {
|
||||||
saveTunnelConfigFromStream(stream, name, configType)
|
saveTunnelConfigFromStream(stream, name)
|
||||||
Result.success(Unit)
|
Result.Success(Unit)
|
||||||
} else {
|
} else {
|
||||||
Result.failure(WgTunnelExceptions.FileReadFailed())
|
Result.Error(Event.Error.FileReadFailed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun addTunnel(tunnelConfig: TunnelConfig) {
|
private suspend fun addTunnel(tunnelConfig: TunnelConfig) {
|
||||||
val firstTunnel = appDataRepository.tunnels.count() == 0
|
val firstTunnel = appDataRepository.tunnels.count() == 0
|
||||||
saveTunnel(tunnelConfig)
|
saveTunnel(tunnelConfig)
|
||||||
if (firstTunnel) WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate()
|
if (firstTunnel) WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate(application)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pauseAutoTunneling() =
|
fun pauseAutoTunneling() =
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
appDataRepository.settings.save(uiState.value.settings.copy(isAutoTunnelPaused = true))
|
appDataRepository.settings.save(uiState.value.settings.copy(isAutoTunnelPaused = true))
|
||||||
WireGuardAutoTunnel.requestAutoTunnelTileServiceUpdate()
|
WireGuardAutoTunnel.requestAutoTunnelTileServiceUpdate(application)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resumeAutoTunneling() =
|
fun resumeAutoTunneling() =
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
appDataRepository.settings.save(uiState.value.settings.copy(isAutoTunnelPaused = false))
|
appDataRepository.settings.save(uiState.value.settings.copy(isAutoTunnelPaused = false))
|
||||||
WireGuardAutoTunnel.requestAutoTunnelTileServiceUpdate()
|
WireGuardAutoTunnel.requestAutoTunnelTileServiceUpdate(application)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun saveTunnel(tunnelConfig: TunnelConfig) {
|
private suspend fun saveTunnel(tunnelConfig: TunnelConfig) {
|
||||||
@@ -307,12 +239,12 @@ constructor(
|
|||||||
return fileName.substring(0, fileName.lastIndexOf('.'))
|
return fileName.substring(0, fileName.lastIndexOf('.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFileExtensionFromFileName(fileName: String): String? {
|
private fun getFileExtensionFromFileName(fileName: String): String {
|
||||||
return try {
|
return try {
|
||||||
fileName.substring(fileName.lastIndexOf('.'))
|
fileName.substring(fileName.lastIndexOf('.'))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
null
|
""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+192
-244
@@ -1,6 +1,5 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.options
|
package com.zaneschepke.wireguardautotunnel.ui.screens.options
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
@@ -8,6 +7,7 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||||
import androidx.compose.foundation.layout.FlowRow
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
import androidx.compose.foundation.layout.IntrinsicSize
|
import androidx.compose.foundation.layout.IntrinsicSize
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
@@ -24,10 +24,9 @@ import androidx.compose.material3.Icon
|
|||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Scaffold
|
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.surfaceColorAtElevation
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@@ -39,23 +38,16 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.focus.onFocusChanged
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.platform.LocalFocusManager
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontStyle
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.iamageo.multifablibrary.FabIcon
|
|
||||||
import com.iamageo.multifablibrary.FabOption
|
|
||||||
import com.iamageo.multifablibrary.MultiFabItem
|
|
||||||
import com.iamageo.multifablibrary.MultiFloatingActionButton
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
||||||
@@ -63,13 +55,11 @@ import com.zaneschepke.wireguardautotunnel.ui.Screen
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.ConfigType
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.getMessage
|
import com.zaneschepke.wireguardautotunnel.util.Result
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun OptionsScreen(
|
fun OptionsScreen(
|
||||||
@@ -81,8 +71,6 @@ fun OptionsScreen(
|
|||||||
) {
|
) {
|
||||||
val scrollState = rememberScrollState()
|
val scrollState = rememberScrollState()
|
||||||
val uiState by optionsViewModel.uiState.collectAsStateWithLifecycle()
|
val uiState by optionsViewModel.uiState.collectAsStateWithLifecycle()
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
@@ -102,238 +90,198 @@ fun OptionsScreen(
|
|||||||
fun saveTrustedSSID() {
|
fun saveTrustedSSID() {
|
||||||
if (currentText.isNotEmpty()) {
|
if (currentText.isNotEmpty()) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
optionsViewModel.onSaveRunSSID(currentText).onSuccess {
|
optionsViewModel.onSaveRunSSID(currentText).let {
|
||||||
currentText = ""
|
when (it) {
|
||||||
}.onFailure {
|
is Result.Success -> currentText = ""
|
||||||
appViewModel.showSnackbarMessage(it.getMessage(context))
|
is Result.Error -> appViewModel.showSnackbarMessage(it.error.message)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
|
||||||
floatingActionButton = {
|
|
||||||
val secondaryColor = MaterialTheme.colorScheme.secondary
|
|
||||||
val hoverColor = MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp)
|
|
||||||
var fobColor by remember { mutableStateOf(secondaryColor) }
|
|
||||||
MultiFloatingActionButton(
|
|
||||||
modifier =
|
|
||||||
(if (
|
|
||||||
WireGuardAutoTunnel.isRunningOnAndroidTv()
|
|
||||||
)
|
|
||||||
Modifier.focusRequester(focusRequester)
|
|
||||||
else Modifier)
|
|
||||||
.onFocusChanged {
|
|
||||||
if (WireGuardAutoTunnel.isRunningOnAndroidTv()) {
|
|
||||||
fobColor = if (it.isFocused) hoverColor else secondaryColor
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fabIcon = FabIcon(
|
|
||||||
iconRes = R.drawable.edit,
|
|
||||||
iconResAfterRotate = R.drawable.close,
|
|
||||||
iconRotate = 180f
|
|
||||||
),
|
|
||||||
fabOption = FabOption(
|
|
||||||
iconTint = MaterialTheme.colorScheme.background,
|
|
||||||
backgroundTint = MaterialTheme.colorScheme.primary,
|
|
||||||
),
|
|
||||||
itemsMultiFab = listOf(
|
|
||||||
MultiFabItem(
|
|
||||||
label = {
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.amnezia),
|
|
||||||
color = Color.White,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(end = 10.dp)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
icon = R.drawable.edit,
|
|
||||||
value = ConfigType.AMNEZIA.name,
|
|
||||||
),
|
|
||||||
MultiFabItem(
|
|
||||||
label = {
|
|
||||||
Text(stringResource(id = R.string.wireguard), color = Color.White, textAlign = TextAlign.Center, modifier = Modifier.padding(end = 10.dp))
|
|
||||||
},
|
|
||||||
icon = R.drawable.edit,
|
|
||||||
value = ConfigType.WIREGUARD.name
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onFabItemClicked = {
|
|
||||||
val configType = ConfigType.valueOf(it.value)
|
|
||||||
navController.navigate(
|
|
||||||
"${Screen.Config.route}/${tunnelId}?configType=${configType.name}",
|
|
||||||
)
|
|
||||||
},
|
|
||||||
shape = RoundedCornerShape(16.dp),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Top,
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.verticalScroll(scrollState)
|
|
||||||
.clickable(
|
|
||||||
indication = null,
|
|
||||||
interactionSource = interactionSource,
|
|
||||||
) {
|
|
||||||
focusManager.clearFocus()
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
Surface(
|
|
||||||
tonalElevation = 2.dp,
|
|
||||||
shadowElevation = 2.dp,
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
color = MaterialTheme.colorScheme.surface,
|
|
||||||
modifier =
|
|
||||||
(if (WireGuardAutoTunnel.isRunningOnAndroidTv()) {
|
|
||||||
Modifier
|
|
||||||
.height(IntrinsicSize.Min)
|
|
||||||
.fillMaxWidth(fillMaxWidth)
|
|
||||||
.padding(top = 10.dp)
|
|
||||||
} else {
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth(fillMaxWidth)
|
|
||||||
.padding(top = 20.dp)
|
|
||||||
})
|
|
||||||
.padding(bottom = 10.dp),
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.Start,
|
|
||||||
verticalArrangement = Arrangement.Top,
|
|
||||||
modifier = Modifier.padding(15.dp),
|
|
||||||
) {
|
|
||||||
SectionTitle(
|
|
||||||
title = stringResource(id = R.string.general),
|
|
||||||
padding = screenPadding,
|
|
||||||
)
|
|
||||||
ConfigurationToggle(
|
|
||||||
stringResource(R.string.set_primary_tunnel),
|
|
||||||
enabled = true,
|
|
||||||
checked = uiState.isDefaultTunnel,
|
|
||||||
modifier = Modifier
|
|
||||||
.focusRequester(focusRequester),
|
|
||||||
padding = screenPadding,
|
|
||||||
onCheckChanged = { optionsViewModel.onTogglePrimaryTunnel() },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Surface(
|
|
||||||
tonalElevation = 2.dp,
|
|
||||||
shadowElevation = 2.dp,
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
color = MaterialTheme.colorScheme.surface,
|
|
||||||
modifier =
|
|
||||||
(if (WireGuardAutoTunnel.isRunningOnAndroidTv()) {
|
|
||||||
Modifier
|
|
||||||
.height(IntrinsicSize.Min)
|
|
||||||
.fillMaxWidth(fillMaxWidth)
|
|
||||||
.padding(top = 10.dp)
|
|
||||||
} else {
|
|
||||||
Modifier
|
|
||||||
.fillMaxWidth(fillMaxWidth)
|
|
||||||
.padding(top = 20.dp)
|
|
||||||
})
|
|
||||||
.padding(bottom = 10.dp),
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.Start,
|
|
||||||
verticalArrangement = Arrangement.Top,
|
|
||||||
modifier = Modifier.padding(15.dp),
|
|
||||||
) {
|
|
||||||
SectionTitle(
|
|
||||||
title = stringResource(id = R.string.auto_tunneling),
|
|
||||||
padding = screenPadding,
|
|
||||||
)
|
|
||||||
ConfigurationToggle(
|
|
||||||
stringResource(R.string.mobile_data_tunnel),
|
|
||||||
enabled = true,
|
|
||||||
checked = uiState.tunnel?.isMobileDataTunnel == true,
|
|
||||||
padding = screenPadding,
|
|
||||||
onCheckChanged = { optionsViewModel.onToggleIsMobileDataTunnel() },
|
|
||||||
)
|
|
||||||
Column {
|
|
||||||
FlowRow(
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(screenPadding)
|
|
||||||
.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(5.dp),
|
|
||||||
) {
|
|
||||||
uiState.tunnel?.tunnelNetworks?.forEach { ssid ->
|
|
||||||
ClickableIconButton(
|
|
||||||
onClick = {
|
|
||||||
if (WireGuardAutoTunnel.isRunningOnAndroidTv()) {
|
|
||||||
focusRequester.requestFocus()
|
|
||||||
optionsViewModel.onDeleteRunSSID(ssid)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onIconClick = {
|
|
||||||
if (WireGuardAutoTunnel.isRunningOnAndroidTv()) focusRequester.requestFocus()
|
|
||||||
optionsViewModel.onDeleteRunSSID(ssid)
|
|
||||||
|
|
||||||
},
|
|
||||||
text = ssid,
|
|
||||||
icon = Icons.Filled.Close,
|
|
||||||
enabled = true,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (uiState.tunnel == null || uiState.tunnel?.tunnelNetworks?.isEmpty() == true) {
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.no_wifi_names_configured),
|
|
||||||
fontStyle = FontStyle.Italic,
|
|
||||||
color = Color.Gray,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OutlinedTextField(
|
|
||||||
enabled = true,
|
|
||||||
value = currentText,
|
|
||||||
onValueChange = { currentText = it },
|
|
||||||
label = { Text(stringResource(id = R.string.use_tunnel_on_wifi_name)) },
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.padding(
|
|
||||||
start = screenPadding,
|
|
||||||
top = 5.dp,
|
|
||||||
bottom = 10.dp,
|
|
||||||
),
|
|
||||||
maxLines = 1,
|
|
||||||
keyboardOptions =
|
|
||||||
KeyboardOptions(
|
|
||||||
capitalization = KeyboardCapitalization.None,
|
|
||||||
imeAction = ImeAction.Done,
|
|
||||||
),
|
|
||||||
keyboardActions = KeyboardActions(onDone = { saveTrustedSSID() }),
|
|
||||||
trailingIcon = {
|
|
||||||
if (currentText != "") {
|
|
||||||
IconButton(onClick = { saveTrustedSSID() }) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Outlined.Add,
|
|
||||||
contentDescription =
|
|
||||||
if (currentText == "") {
|
|
||||||
stringResource(
|
|
||||||
id =
|
|
||||||
R.string
|
|
||||||
.trusted_ssid_empty_description,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
stringResource(
|
|
||||||
id =
|
|
||||||
R.string
|
|
||||||
.trusted_ssid_value_description,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
tint = MaterialTheme.colorScheme.primary,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Top,
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.verticalScroll(scrollState)
|
||||||
|
.clickable(
|
||||||
|
indication = null,
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
) {
|
||||||
|
focusManager.clearFocus()
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Surface(
|
||||||
|
tonalElevation = 2.dp,
|
||||||
|
shadowElevation = 2.dp,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = MaterialTheme.colorScheme.surface,
|
||||||
|
modifier =
|
||||||
|
(if (WireGuardAutoTunnel.isRunningOnAndroidTv()) {
|
||||||
|
Modifier
|
||||||
|
.height(IntrinsicSize.Min)
|
||||||
|
.fillMaxWidth(fillMaxWidth)
|
||||||
|
.padding(top = 10.dp)
|
||||||
|
} else {
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth(fillMaxWidth)
|
||||||
|
.padding(top = 20.dp)
|
||||||
|
})
|
||||||
|
.padding(bottom = 10.dp),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.Start,
|
||||||
|
verticalArrangement = Arrangement.Top,
|
||||||
|
modifier = Modifier.padding(15.dp),
|
||||||
|
) {
|
||||||
|
SectionTitle(
|
||||||
|
title = stringResource(id = R.string.general),
|
||||||
|
padding = screenPadding,
|
||||||
|
)
|
||||||
|
ConfigurationToggle(
|
||||||
|
stringResource(R.string.set_primary_tunnel),
|
||||||
|
enabled = true,
|
||||||
|
checked = uiState.isDefaultTunnel,
|
||||||
|
modifier = Modifier
|
||||||
|
.focusRequester(focusRequester),
|
||||||
|
padding = screenPadding,
|
||||||
|
onCheckChanged = { optionsViewModel.onTogglePrimaryTunnel() },
|
||||||
|
)
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(top = 5.dp),
|
||||||
|
horizontalArrangement = Arrangement.Center,
|
||||||
|
) {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
"${Screen.Config.route}/${tunnelId}",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.edit_tunnel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Surface(
|
||||||
|
tonalElevation = 2.dp,
|
||||||
|
shadowElevation = 2.dp,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = MaterialTheme.colorScheme.surface,
|
||||||
|
modifier =
|
||||||
|
(if (WireGuardAutoTunnel.isRunningOnAndroidTv()) {
|
||||||
|
Modifier
|
||||||
|
.height(IntrinsicSize.Min)
|
||||||
|
.fillMaxWidth(fillMaxWidth)
|
||||||
|
.padding(top = 10.dp)
|
||||||
|
} else {
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth(fillMaxWidth)
|
||||||
|
.padding(top = 20.dp)
|
||||||
|
})
|
||||||
|
.padding(bottom = 10.dp),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.Start,
|
||||||
|
verticalArrangement = Arrangement.Top,
|
||||||
|
modifier = Modifier.padding(15.dp),
|
||||||
|
) {
|
||||||
|
SectionTitle(
|
||||||
|
title = stringResource(id = R.string.auto_tunneling),
|
||||||
|
padding = screenPadding,
|
||||||
|
)
|
||||||
|
ConfigurationToggle(
|
||||||
|
stringResource(R.string.mobile_data_tunnel),
|
||||||
|
enabled = true,
|
||||||
|
checked = uiState.tunnel?.isMobileDataTunnel == true,
|
||||||
|
padding = screenPadding,
|
||||||
|
onCheckChanged = { optionsViewModel.onToggleIsMobileDataTunnel() },
|
||||||
|
)
|
||||||
|
Column {
|
||||||
|
FlowRow(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(screenPadding)
|
||||||
|
.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(5.dp),
|
||||||
|
) {
|
||||||
|
uiState.tunnel?.tunnelNetworks?.forEach { ssid ->
|
||||||
|
ClickableIconButton(
|
||||||
|
onClick = {
|
||||||
|
if (WireGuardAutoTunnel.isRunningOnAndroidTv()) {
|
||||||
|
focusRequester.requestFocus()
|
||||||
|
optionsViewModel.onDeleteRunSSID(ssid)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onIconClick = {
|
||||||
|
if (WireGuardAutoTunnel.isRunningOnAndroidTv()) focusRequester.requestFocus()
|
||||||
|
optionsViewModel.onDeleteRunSSID(ssid)
|
||||||
|
|
||||||
|
},
|
||||||
|
text = ssid,
|
||||||
|
icon = Icons.Filled.Close,
|
||||||
|
enabled = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (uiState.tunnel == null || uiState.tunnel?.tunnelNetworks?.isEmpty() == true) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.no_wifi_names_configured),
|
||||||
|
fontStyle = FontStyle.Italic,
|
||||||
|
color = Color.Gray,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OutlinedTextField(
|
||||||
|
enabled = true,
|
||||||
|
value = currentText,
|
||||||
|
onValueChange = { currentText = it },
|
||||||
|
label = { Text(stringResource(id = R.string.use_tunnel_on_wifi_name)) },
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.padding(
|
||||||
|
start = screenPadding,
|
||||||
|
top = 5.dp,
|
||||||
|
bottom = 10.dp,
|
||||||
|
),
|
||||||
|
maxLines = 1,
|
||||||
|
keyboardOptions =
|
||||||
|
KeyboardOptions(
|
||||||
|
capitalization = KeyboardCapitalization.None,
|
||||||
|
imeAction = ImeAction.Done,
|
||||||
|
),
|
||||||
|
keyboardActions = KeyboardActions(onDone = { saveTrustedSSID() }),
|
||||||
|
trailingIcon = {
|
||||||
|
if (currentText != "") {
|
||||||
|
IconButton(onClick = { saveTrustedSSID() }) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.Add,
|
||||||
|
contentDescription =
|
||||||
|
if (currentText == "") {
|
||||||
|
stringResource(
|
||||||
|
id =
|
||||||
|
R.string
|
||||||
|
.trusted_ssid_empty_description,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
stringResource(
|
||||||
|
id =
|
||||||
|
R.string
|
||||||
|
.trusted_ssid_value_description,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.options
|
package com.zaneschepke.wireguardautotunnel.ui.screens.options
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
|
|
||||||
data class OptionsUiState(
|
data class OptionsUiState(
|
||||||
val id: String? = null,
|
val id: String? = null,
|
||||||
|
|||||||
+9
-11
@@ -4,17 +4,17 @@ import androidx.compose.ui.util.fastFirstOrNull
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelExceptions
|
import com.zaneschepke.wireguardautotunnel.util.Event
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Result
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -43,11 +43,9 @@ constructor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun init(tunnelId: String) {
|
fun init(tunnelId: String) {
|
||||||
_optionState.update {
|
_optionState.value = _optionState.value.copy(
|
||||||
it.copy(
|
id = tunnelId,
|
||||||
id = tunnelId
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDeleteRunSSID(ssid: String) = viewModelScope.launch(Dispatchers.IO) {
|
fun onDeleteRunSSID(ssid: String) = viewModelScope.launch(Dispatchers.IO) {
|
||||||
@@ -75,9 +73,9 @@ constructor(
|
|||||||
tunnelsWithName.isEmpty()) {
|
tunnelsWithName.isEmpty()) {
|
||||||
uiState.value.tunnel?.tunnelNetworks?.add(trimmed)
|
uiState.value.tunnel?.tunnelNetworks?.add(trimmed)
|
||||||
saveTunnel(uiState.value.tunnel)
|
saveTunnel(uiState.value.tunnel)
|
||||||
Result.success(Unit)
|
Result.Success(Unit)
|
||||||
} else {
|
} else {
|
||||||
Result.failure(WgTunnelExceptions.SsidConflict())
|
Result.Error(Event.Error.SsidConflict)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +95,7 @@ constructor(
|
|||||||
false -> uiState.value.tunnel
|
false -> uiState.value.tunnel
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate()
|
WireGuardAutoTunnel.requestTunnelTileServiceStateUpdate(WireGuardAutoTunnel.instance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-65
@@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
@@ -70,21 +71,21 @@ import androidx.navigation.NavController
|
|||||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||||
import com.google.accompanist.permissions.isGranted
|
import com.google.accompanist.permissions.isGranted
|
||||||
import com.google.accompanist.permissions.rememberPermissionState
|
import com.google.accompanist.permissions.rememberPermissionState
|
||||||
import com.wireguard.android.backend.WgQuickBackend
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Screen
|
import com.zaneschepke.wireguardautotunnel.ui.Screen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationToggle
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
import com.zaneschepke.wireguardautotunnel.ui.common.text.SectionTitle
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Event
|
||||||
import com.zaneschepke.wireguardautotunnel.util.FileUtils
|
import com.zaneschepke.wireguardautotunnel.util.FileUtils
|
||||||
import com.zaneschepke.wireguardautotunnel.util.getMessage
|
import com.zaneschepke.wireguardautotunnel.util.Result
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.amnezia.awg.backend.AwgQuickBackend
|
||||||
|
import org.amnezia.awg.backend.Tunnel
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import xyz.teamgravity.pin_lock_compose.PinManager
|
import xyz.teamgravity.pin_lock_compose.PinManager
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -130,28 +131,16 @@ fun SettingsScreen(
|
|||||||
|
|
||||||
fun exportAllConfigs() {
|
fun exportAllConfigs() {
|
||||||
try {
|
try {
|
||||||
val wgFiles = uiState.tunnels.map { config ->
|
val files = uiState.tunnels.map { File(context.cacheDir, "${it.name}.conf") }
|
||||||
val file = File(context.cacheDir, "${config.name}-wg.conf")
|
files.forEachIndexed { index, file ->
|
||||||
file.outputStream().use {
|
file.outputStream().use { it.write(uiState.tunnels[index].wgQuick.toByteArray()) }
|
||||||
it.write(config.wgQuick.toByteArray())
|
|
||||||
}
|
|
||||||
file
|
|
||||||
}
|
|
||||||
val amFiles = uiState.tunnels.mapNotNull { config -> if(config.amQuick != TunnelConfig.AM_QUICK_DEFAULT) {
|
|
||||||
val file = File(context.cacheDir, "${config.name}-am.conf")
|
|
||||||
file.outputStream().use {
|
|
||||||
it.write(config.amQuick.toByteArray())
|
|
||||||
}
|
|
||||||
file
|
|
||||||
} else null }
|
|
||||||
FileUtils.saveFilesToZip(context, wgFiles + amFiles).onFailure {
|
|
||||||
appViewModel.showSnackbarMessage(it.getMessage(context))
|
|
||||||
}.onSuccess {
|
|
||||||
didExportFiles = true
|
|
||||||
appViewModel.showSnackbarMessage(context.getString(R.string.exported_configs_message))
|
|
||||||
}
|
}
|
||||||
|
FileUtils.saveFilesToZip(context, files)
|
||||||
|
didExportFiles = true
|
||||||
|
appViewModel.showSnackbarMessage(Event.Message.ConfigsExported.message)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
|
appViewModel.showSnackbarMessage(Event.Error.Exception(e).message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +161,7 @@ fun SettingsScreen(
|
|||||||
fun handleAutoTunnelToggle() {
|
fun handleAutoTunnelToggle() {
|
||||||
if (uiState.isBatteryOptimizeDisableShown || isBatteryOptimizationsDisabled()) {
|
if (uiState.isBatteryOptimizeDisableShown || isBatteryOptimizationsDisabled()) {
|
||||||
if (appViewModel.isRequiredPermissionGranted()) {
|
if (appViewModel.isRequiredPermissionGranted()) {
|
||||||
viewModel.onToggleAutoTunnel(context)
|
viewModel.onToggleAutoTunnel()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
requestBatteryOptimizationsDisabled()
|
requestBatteryOptimizationsDisabled()
|
||||||
@@ -181,10 +170,11 @@ fun SettingsScreen(
|
|||||||
|
|
||||||
fun saveTrustedSSID() {
|
fun saveTrustedSSID() {
|
||||||
if (currentText.isNotEmpty()) {
|
if (currentText.isNotEmpty()) {
|
||||||
viewModel.onSaveTrustedSSID(currentText).onSuccess {
|
viewModel.onSaveTrustedSSID(currentText).let {
|
||||||
currentText = ""
|
when (it) {
|
||||||
}.onFailure {
|
is Result.Success -> currentText = ""
|
||||||
appViewModel.showSnackbarMessage(it.getMessage(context))
|
is Result.Error -> appViewModel.showSnackbarMessage(it.error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,11 +308,11 @@ fun SettingsScreen(
|
|||||||
},
|
},
|
||||||
onError = { _ ->
|
onError = { _ ->
|
||||||
showAuthPrompt = false
|
showAuthPrompt = false
|
||||||
appViewModel.showSnackbarMessage(context.getString(R.string.error_authentication_failed))
|
appViewModel.showSnackbarMessage(Event.Error.AuthenticationFailed.message)
|
||||||
},
|
},
|
||||||
onFailure = {
|
onFailure = {
|
||||||
showAuthPrompt = false
|
showAuthPrompt = false
|
||||||
appViewModel.showSnackbarMessage(context.getString(R.string.error_authorization_failed))
|
appViewModel.showSnackbarMessage(Event.Error.AuthorizationFailed.message)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -530,12 +520,12 @@ fun SettingsScreen(
|
|||||||
when (false) {
|
when (false) {
|
||||||
isBackgroundLocationGranted ->
|
isBackgroundLocationGranted ->
|
||||||
appViewModel.showSnackbarMessage(
|
appViewModel.showSnackbarMessage(
|
||||||
context.getString(R.string.background_location_required),
|
Event.Error.BackgroundLocationRequired.message,
|
||||||
)
|
)
|
||||||
|
|
||||||
fineLocationState.status.isGranted ->
|
fineLocationState.status.isGranted ->
|
||||||
appViewModel.showSnackbarMessage(
|
appViewModel.showSnackbarMessage(
|
||||||
context.getString(R.string.precise_location_required),
|
Event.Error.PreciseLocationRequired.message,
|
||||||
)
|
)
|
||||||
|
|
||||||
viewModel.isLocationEnabled(context) ->
|
viewModel.isLocationEnabled(context) ->
|
||||||
@@ -561,48 +551,39 @@ fun SettingsScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Surface(
|
if (AwgQuickBackend.hasKernelSupport()) {
|
||||||
tonalElevation = 2.dp,
|
Surface(
|
||||||
shadowElevation = 2.dp,
|
tonalElevation = 2.dp,
|
||||||
shape = RoundedCornerShape(12.dp),
|
shadowElevation = 2.dp,
|
||||||
color = MaterialTheme.colorScheme.surface,
|
shape = RoundedCornerShape(12.dp),
|
||||||
modifier = Modifier
|
color = MaterialTheme.colorScheme.surface,
|
||||||
.fillMaxWidth(fillMaxWidth)
|
modifier = Modifier
|
||||||
.padding(vertical = 10.dp),
|
.fillMaxWidth(fillMaxWidth)
|
||||||
) {
|
.padding(vertical = 10.dp),
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.Start,
|
|
||||||
verticalArrangement = Arrangement.Top,
|
|
||||||
modifier = Modifier.padding(15.dp),
|
|
||||||
) {
|
) {
|
||||||
SectionTitle(
|
Column(
|
||||||
title = stringResource(id = R.string.backend),
|
horizontalAlignment = Alignment.Start,
|
||||||
padding = screenPadding,
|
verticalArrangement = Arrangement.Top,
|
||||||
)
|
modifier = Modifier.padding(15.dp),
|
||||||
ConfigurationToggle(
|
) {
|
||||||
stringResource(R.string.use_amnezia),
|
SectionTitle(
|
||||||
enabled =
|
title = stringResource(id = R.string.kernel),
|
||||||
!(uiState.settings.isAutoTunnelEnabled ||
|
padding = screenPadding,
|
||||||
uiState.settings.isAlwaysOnVpnEnabled ||
|
)
|
||||||
(uiState.vpnState.status == TunnelState.UP) || uiState.settings.isKernelEnabled),
|
|
||||||
checked = uiState.settings.isAmneziaEnabled,
|
|
||||||
padding = screenPadding,
|
|
||||||
onCheckChanged = {
|
|
||||||
viewModel.onToggleAmnezia()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if (WgQuickBackend.hasKernelSupport()) {
|
|
||||||
ConfigurationToggle(
|
ConfigurationToggle(
|
||||||
stringResource(R.string.use_kernel),
|
stringResource(R.string.use_kernel),
|
||||||
enabled =
|
enabled =
|
||||||
!(uiState.settings.isAutoTunnelEnabled ||
|
!(uiState.settings.isAutoTunnelEnabled ||
|
||||||
uiState.settings.isAlwaysOnVpnEnabled ||
|
uiState.settings.isAlwaysOnVpnEnabled ||
|
||||||
(uiState.vpnState.status == TunnelState.UP)),
|
(uiState.vpnState.status == Tunnel.State.UP)),
|
||||||
checked = uiState.settings.isKernelEnabled,
|
checked = uiState.settings.isKernelEnabled,
|
||||||
padding = screenPadding,
|
padding = screenPadding,
|
||||||
onCheckChanged = {
|
onCheckChanged = {
|
||||||
viewModel.onToggleKernelMode().onFailure {
|
viewModel.onToggleKernelMode().let {
|
||||||
appViewModel.showSnackbarMessage(it.getMessage(context))
|
when (it) {
|
||||||
|
is Result.Error -> appViewModel.showSnackbarMessage(it.error.message)
|
||||||
|
is Result.Success -> {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings
|
package com.zaneschepke.wireguardautotunnel.ui.screens.settings
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnState
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnState
|
||||||
|
|
||||||
data class SettingsUiState(
|
data class SettingsUiState(
|
||||||
|
|||||||
+15
-33
@@ -1,23 +1,25 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings
|
package com.zaneschepke.wireguardautotunnel.ui.screens.settings
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.location.LocationManager
|
import android.location.LocationManager
|
||||||
import androidx.core.location.LocationManagerCompat
|
import androidx.core.location.LocationManagerCompat
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.wireguard.android.util.RootShell
|
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelExceptions
|
import com.zaneschepke.wireguardautotunnel.util.Event
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.Result
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.amnezia.awg.util.RootShell
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -25,6 +27,7 @@ import javax.inject.Inject
|
|||||||
class SettingsViewModel
|
class SettingsViewModel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
|
private val application: Application,
|
||||||
private val appDataRepository: AppDataRepository,
|
private val appDataRepository: AppDataRepository,
|
||||||
private val serviceManager: ServiceManager,
|
private val serviceManager: ServiceManager,
|
||||||
private val rootShell: RootShell,
|
private val rootShell: RootShell,
|
||||||
@@ -57,9 +60,9 @@ constructor(
|
|||||||
return if (!uiState.value.settings.trustedNetworkSSIDs.contains(trimmed)) {
|
return if (!uiState.value.settings.trustedNetworkSSIDs.contains(trimmed)) {
|
||||||
uiState.value.settings.trustedNetworkSSIDs.add(trimmed)
|
uiState.value.settings.trustedNetworkSSIDs.add(trimmed)
|
||||||
saveSettings(uiState.value.settings)
|
saveSettings(uiState.value.settings)
|
||||||
Result.success(Unit)
|
Result.Success(Unit)
|
||||||
} else {
|
} else {
|
||||||
Result.failure(WgTunnelExceptions.SsidConflict())
|
Result.Error(Event.Error.SsidConflict)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,15 +93,15 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onToggleAutoTunnel(context: Context) =
|
fun onToggleAutoTunnel() =
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val isAutoTunnelEnabled = uiState.value.settings.isAutoTunnelEnabled
|
val isAutoTunnelEnabled = uiState.value.settings.isAutoTunnelEnabled
|
||||||
var isAutoTunnelPaused = uiState.value.settings.isAutoTunnelPaused
|
var isAutoTunnelPaused = uiState.value.settings.isAutoTunnelPaused
|
||||||
|
|
||||||
if (isAutoTunnelEnabled) {
|
if (isAutoTunnelEnabled) {
|
||||||
serviceManager.stopWatcherService(context)
|
serviceManager.stopWatcherService(application)
|
||||||
} else {
|
} else {
|
||||||
serviceManager.startWatcherService(context)
|
serviceManager.startWatcherService(application)
|
||||||
isAutoTunnelPaused = false
|
isAutoTunnelPaused = false
|
||||||
}
|
}
|
||||||
saveSettings(
|
saveSettings(
|
||||||
@@ -107,7 +110,7 @@ constructor(
|
|||||||
isAutoTunnelPaused = isAutoTunnelPaused,
|
isAutoTunnelPaused = isAutoTunnelPaused,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
WireGuardAutoTunnel.requestAutoTunnelTileServiceUpdate()
|
WireGuardAutoTunnel.requestAutoTunnelTileServiceUpdate(application)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onToggleAlwaysOnVPN() =
|
fun onToggleAlwaysOnVPN() =
|
||||||
@@ -159,42 +162,21 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onToggleAmnezia() = viewModelScope.launch {
|
|
||||||
if(uiState.value.settings.isKernelEnabled) {
|
|
||||||
saveKernelMode(false)
|
|
||||||
}
|
|
||||||
saveAmneziaMode(!uiState.value.settings.isAmneziaEnabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun saveAmneziaMode(on: Boolean) {
|
|
||||||
saveSettings(
|
|
||||||
uiState.value.settings.copy(
|
|
||||||
isAmneziaEnabled = on
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onToggleKernelMode(): Result<Unit> {
|
fun onToggleKernelMode(): Result<Unit> {
|
||||||
if (!uiState.value.settings.isKernelEnabled) {
|
if (!uiState.value.settings.isKernelEnabled) {
|
||||||
try {
|
try {
|
||||||
rootShell.start()
|
rootShell.start()
|
||||||
Timber.i("Root shell accepted!")
|
Timber.i("Root shell accepted!")
|
||||||
saveSettings(
|
saveKernelMode(on = true)
|
||||||
uiState.value.settings.copy(
|
|
||||||
isKernelEnabled = true,
|
|
||||||
isAmneziaEnabled = false,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
} catch (e: RootShell.RootShellException) {
|
} catch (e: RootShell.RootShellException) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
saveKernelMode(on = false)
|
saveKernelMode(on = false)
|
||||||
return Result.failure(WgTunnelExceptions.RootDenied())
|
return Result.Error(Event.Error.RootDenied)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
saveKernelMode(on = false)
|
saveKernelMode(on = false)
|
||||||
}
|
}
|
||||||
return Result.success(Unit)
|
return Result.Success(Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onToggleRestartOnPing() = viewModelScope.launch {
|
fun onToggleRestartOnPing() = viewModelScope.launch {
|
||||||
|
|||||||
+6
-6
@@ -107,7 +107,7 @@ fun SupportScreen(
|
|||||||
modifier = Modifier.padding(bottom = 20.dp),
|
modifier = Modifier.padding(bottom = 20.dp),
|
||||||
)
|
)
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = { appViewModel.openWebPage(context.resources.getString(R.string.docs_url), context) },
|
onClick = { appViewModel.openWebPage(context.resources.getString(R.string.docs_url)) },
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(vertical = 5.dp)
|
.padding(vertical = 5.dp)
|
||||||
.focusRequester(focusRequester),
|
.focusRequester(focusRequester),
|
||||||
@@ -143,7 +143,7 @@ fun SupportScreen(
|
|||||||
color = MaterialTheme.colorScheme.onBackground,
|
color = MaterialTheme.colorScheme.onBackground,
|
||||||
)
|
)
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = { appViewModel.openWebPage(context.resources.getString(R.string.telegram_url), context) },
|
onClick = { appViewModel.openWebPage(context.resources.getString(R.string.discord_url)) },
|
||||||
modifier = Modifier.padding(vertical = 5.dp),
|
modifier = Modifier.padding(vertical = 5.dp),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
@@ -152,7 +152,7 @@ fun SupportScreen(
|
|||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) {
|
) {
|
||||||
Row {
|
Row {
|
||||||
val icon = ImageVector.vectorResource(R.drawable.telegram)
|
val icon = ImageVector.vectorResource(R.drawable.discord)
|
||||||
Icon(
|
Icon(
|
||||||
icon,
|
icon,
|
||||||
icon.name,
|
icon.name,
|
||||||
@@ -175,7 +175,7 @@ fun SupportScreen(
|
|||||||
color = MaterialTheme.colorScheme.onBackground,
|
color = MaterialTheme.colorScheme.onBackground,
|
||||||
)
|
)
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = { appViewModel.openWebPage(context.resources.getString(R.string.github_url), context) },
|
onClick = { appViewModel.openWebPage(context.resources.getString(R.string.github_url)) },
|
||||||
modifier = Modifier.padding(vertical = 5.dp),
|
modifier = Modifier.padding(vertical = 5.dp),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
@@ -207,7 +207,7 @@ fun SupportScreen(
|
|||||||
color = MaterialTheme.colorScheme.onBackground,
|
color = MaterialTheme.colorScheme.onBackground,
|
||||||
)
|
)
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = { appViewModel.launchEmail(context) },
|
onClick = { appViewModel.launchEmail() },
|
||||||
modifier = Modifier.padding(vertical = 5.dp),
|
modifier = Modifier.padding(vertical = 5.dp),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
@@ -269,7 +269,7 @@ fun SupportScreen(
|
|||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.clickable {
|
Modifier.clickable {
|
||||||
appViewModel.openWebPage(context.resources.getString(R.string.privacy_policy_url), context)
|
appViewModel.openWebPage(context.resources.getString(R.string.privacy_policy_url))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support
|
package com.zaneschepke.wireguardautotunnel.ui.screens.support
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.Settings
|
import com.zaneschepke.wireguardautotunnel.data.model.Settings
|
||||||
|
|
||||||
data class SupportUiState(val settings: Settings = Settings())
|
data class SupportUiState(val settings: Settings = Settings())
|
||||||
|
|||||||
+1
-4
@@ -27,7 +27,6 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.ClipboardManager
|
import androidx.compose.ui.platform.ClipboardManager
|
||||||
import androidx.compose.ui.platform.LocalClipboardManager
|
import androidx.compose.ui.platform.LocalClipboardManager
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -44,8 +43,6 @@ fun LogsScreen(appViewModel: AppViewModel) {
|
|||||||
appViewModel.logs
|
appViewModel.logs
|
||||||
}
|
}
|
||||||
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
val lazyColumnListState = rememberLazyListState()
|
val lazyColumnListState = rememberLazyListState()
|
||||||
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
@@ -60,7 +57,7 @@ fun LogsScreen(appViewModel: AppViewModel) {
|
|||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
appViewModel.saveLogsToFile(context)
|
appViewModel.saveLogsToFile()
|
||||||
},
|
},
|
||||||
shape = RoundedCornerShape(16.dp),
|
shape = RoundedCornerShape(16.dp),
|
||||||
containerColor = MaterialTheme.colorScheme.primary,
|
containerColor = MaterialTheme.colorScheme.primary,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.zaneschepke.wireguardautotunnel.util
|
|||||||
|
|
||||||
object Constants {
|
object Constants {
|
||||||
|
|
||||||
const val BASE_LOG_FILE_NAME = "wg_tunnel_logs"
|
const val BASE_LOG_FILE_NAME = "wgtunnel-logs"
|
||||||
const val LOG_BUFFER_SIZE = 3_000L
|
const val LOG_BUFFER_SIZE = 3_000L
|
||||||
|
|
||||||
const val MANUAL_TUNNEL_CONFIG_ID = "0"
|
const val MANUAL_TUNNEL_CONFIG_ID = "0"
|
||||||
@@ -25,7 +25,7 @@ object Constants {
|
|||||||
const val SUBSCRIPTION_TIMEOUT = 5_000L
|
const val SUBSCRIPTION_TIMEOUT = 5_000L
|
||||||
const val FOCUS_REQUEST_DELAY = 500L
|
const val FOCUS_REQUEST_DELAY = 500L
|
||||||
|
|
||||||
const val DEFAULT_PING_IP = "1.1.1.1"
|
const val BACKUP_PING_HOST = "1.1.1.1"
|
||||||
const val PING_TIMEOUT = 5_000L
|
const val PING_TIMEOUT = 5_000L
|
||||||
const val VPN_RESTART_DELAY = 1_000L
|
const val VPN_RESTART_DELAY = 1_000L
|
||||||
const val PING_INTERVAL = 60_000L
|
const val PING_INTERVAL = 60_000L
|
||||||
@@ -37,7 +37,4 @@ object Constants {
|
|||||||
|
|
||||||
const val UNREADABLE_SSID = "<unknown ssid>"
|
const val UNREADABLE_SSID = "<unknown ssid>"
|
||||||
|
|
||||||
val amneziaProperties = listOf("Jc", "Jmin", "Jmax", "S1", "S2", "H1", "H2", "H3", "H4")
|
|
||||||
const val QR_CODE_NAME_PROPERTY = "# Name ="
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.util
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||||
|
|
||||||
|
sealed class Event {
|
||||||
|
|
||||||
|
abstract val message: String
|
||||||
|
|
||||||
|
sealed class Error : Event() {
|
||||||
|
data object None : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.error_none)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object SsidConflict : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.error_ssid_exists)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ConfigParseError(val appendedMessage: String) : Error() {
|
||||||
|
override val message: String =
|
||||||
|
WireGuardAutoTunnel.instance.getString(R.string.config_parse_error) + (
|
||||||
|
if (appendedMessage != "") ": ${appendedMessage.trim()}" else "")
|
||||||
|
}
|
||||||
|
|
||||||
|
data object RootDenied : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.error_root_denied)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class General(val customMessage: String) : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = customMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Exception(val exception: kotlin.Exception) : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() =
|
||||||
|
exception.message
|
||||||
|
?: WireGuardAutoTunnel.instance.getString(R.string.unknown_error)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object InvalidQrCode : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.error_invalid_code)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object InvalidFileExtension : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.error_file_extension)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object FileReadFailed : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.error_file_extension)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object AuthenticationFailed : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.error_authentication_failed)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object AuthorizationFailed : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.error_authorization_failed)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object BackgroundLocationRequired : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() =
|
||||||
|
WireGuardAutoTunnel.instance.getString(R.string.background_location_required)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object LocationServicesRequired : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.location_services_required)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object PreciseLocationRequired : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.precise_location_required)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object FileExplorerRequired : Error() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.error_no_file_explorer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class Message : Event() {
|
||||||
|
data object ConfigSaved : Message() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.config_changes_saved)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object ConfigsExported : Message() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.exported_configs_message)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object TunnelOffAction : Message() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.turn_off_tunnel)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object TunnelOnAction : Message() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.turn_on_tunnel)
|
||||||
|
}
|
||||||
|
|
||||||
|
data object AutoTunnelOffAction : Message() {
|
||||||
|
override val message: String
|
||||||
|
get() = WireGuardAutoTunnel.instance.getString(R.string.turn_off_auto)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,15 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.util
|
package com.zaneschepke.wireguardautotunnel.util
|
||||||
|
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.data.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.statistics.TunnelStatistics
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.amnezia.awg.config.Config
|
import org.amnezia.awg.backend.Statistics
|
||||||
|
import org.amnezia.awg.crypto.Key
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
@@ -51,15 +49,15 @@ typealias TunnelConfigs = List<TunnelConfig>
|
|||||||
|
|
||||||
typealias Packages = List<PackageInfo>
|
typealias Packages = List<PackageInfo>
|
||||||
|
|
||||||
fun TunnelStatistics.mapPeerStats(): Map<org.amnezia.awg.crypto.Key, TunnelStatistics.PeerStats?> {
|
fun Statistics.mapPeerStats(): Map<Key, Statistics.PeerStats?> {
|
||||||
return this.getPeers().associateWith { key -> (this.peerStats(key)) }
|
return this.peers().associateWith { key -> (this.peer(key)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TunnelStatistics.PeerStats.latestHandshakeSeconds(): Long? {
|
fun Statistics.PeerStats.latestHandshakeSeconds(): Long? {
|
||||||
return NumberUtils.getSecondsBetweenTimestampAndNow(this.latestHandshakeEpochMillis)
|
return NumberUtils.getSecondsBetweenTimestampAndNow(this.latestHandshakeEpochMillis)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TunnelStatistics.PeerStats.handshakeStatus(): HandshakeStatus {
|
fun Statistics.PeerStats.handshakeStatus(): HandshakeStatus {
|
||||||
// TODO add never connected status after duration
|
// TODO add never connected status after duration
|
||||||
return this.latestHandshakeSeconds().let {
|
return this.latestHandshakeSeconds().let {
|
||||||
when {
|
when {
|
||||||
@@ -72,25 +70,3 @@ fun TunnelStatistics.PeerStats.handshakeStatus(): HandshakeStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Config.toWgQuickString() : String {
|
|
||||||
val amQuick = toAwgQuickString()
|
|
||||||
val lines = amQuick.lines().toMutableList()
|
|
||||||
val linesIterator = lines.iterator()
|
|
||||||
while(linesIterator.hasNext()) {
|
|
||||||
val next = linesIterator.next()
|
|
||||||
Constants.amneziaProperties.forEach {
|
|
||||||
if(next.startsWith(it, ignoreCase = true)) {
|
|
||||||
linesIterator.remove()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lines.joinToString(System.lineSeparator())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Throwable.getMessage(context: Context) : String {
|
|
||||||
return when(this) {
|
|
||||||
is WgTunnelExceptions -> this.getMessage(context)
|
|
||||||
else -> this.message ?: StringValue.StringResource(R.string.unknown_error).asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import android.os.Build
|
|||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.provider.MediaStore.MediaColumns
|
import android.provider.MediaStore.MediaColumns
|
||||||
import timber.log.Timber
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
@@ -71,27 +70,21 @@ object FileUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveFilesToZip(context: Context, files: List<File>) : Result<Unit> {
|
fun saveFilesToZip(context: Context, files: List<File>) {
|
||||||
return try {
|
val zipOutputStream =
|
||||||
val zipOutputStream =
|
createDownloadsFileOutputStream(
|
||||||
createDownloadsFileOutputStream(
|
context,
|
||||||
context,
|
"wg-export_${Instant.now().epochSecond}.zip",
|
||||||
"wg-export_${Instant.now().epochSecond}.zip",
|
ZIP_FILE_MIME_TYPE,
|
||||||
ZIP_FILE_MIME_TYPE,
|
)
|
||||||
)
|
ZipOutputStream(zipOutputStream).use { zos ->
|
||||||
ZipOutputStream(zipOutputStream).use { zos ->
|
files.forEach { file ->
|
||||||
files.forEach { file ->
|
val entry = ZipEntry(file.name)
|
||||||
val entry = ZipEntry(file.name)
|
zos.putNextEntry(entry)
|
||||||
zos.putNextEntry(entry)
|
if (file.isFile) {
|
||||||
if (file.isFile) {
|
file.inputStream().use { fis -> fis.copyTo(zos) }
|
||||||
file.inputStream().use { fis -> fis.copyTo(zos) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Result.success(Unit)
|
|
||||||
}
|
}
|
||||||
} catch (e : Exception) {
|
|
||||||
Timber.e(e)
|
|
||||||
Result.failure(WgTunnelExceptions.ConfigExportFailed())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.util
|
||||||
|
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
sealed class Result<T> {
|
||||||
|
class Success<T>(val data: T) : Result<T>()
|
||||||
|
|
||||||
|
class Error<T>(val error: Event.Error) : Result<T>() {
|
||||||
|
init {
|
||||||
|
when (this.error) {
|
||||||
|
is Event.Error.Exception -> Timber.e(this.error.exception)
|
||||||
|
else -> Timber.e(this.error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.util
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
|
|
||||||
sealed class WgTunnelExceptions : Exception() {
|
|
||||||
abstract fun getMessage(context: Context) : String
|
|
||||||
data class General(private val userMessage : StringValue) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class SsidConflict(private val userMessage : StringValue = StringValue.StringResource(R.string.error_ssid_exists)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class ConfigExportFailed(private val userMessage : StringValue = StringValue.StringResource(R.string.export_configs_failed)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class ConfigParseError(private val appendMessage : StringValue = StringValue.Empty) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return StringValue.StringResource(R.string.config_parse_error).asString(context) + (
|
|
||||||
if (appendMessage != StringValue.Empty) ": ${appendMessage.asString(context)}" else "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class RootDenied(private val userMessage : StringValue = StringValue.StringResource(R.string.error_root_denied)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class InvalidQrCode(private val userMessage : StringValue = StringValue.StringResource(R.string.error_invalid_code)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class InvalidFileExtension(private val userMessage : StringValue = StringValue.StringResource(R.string.error_file_extension)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class FileReadFailed(private val userMessage : StringValue = StringValue.StringResource(R.string.error_file_format)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class AuthenticationFailed(private val userMessage : StringValue = StringValue.StringResource(R.string.error_authentication_failed)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class AuthorizationFailed(private val userMessage : StringValue = StringValue.StringResource(R.string.error_authorization_failed)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class BackgroundLocationRequired(private val userMessage : StringValue = StringValue.StringResource(R.string.background_location_required)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class LocationServicesRequired(private val userMessage : StringValue = StringValue.StringResource(R.string.location_services_required)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class PreciseLocationRequired(private val userMessage : StringValue = StringValue.StringResource(R.string.precise_location_required)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class FileExplorerRequired (private val userMessage : StringValue = StringValue.StringResource(R.string.error_no_file_explorer)) : WgTunnelExceptions() {
|
|
||||||
override fun getMessage(context: Context) : String {
|
|
||||||
return userMessage.asString(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// sealed class Message : Event() {
|
|
||||||
// data object ConfigSaved : Message() {
|
|
||||||
// override val message: String
|
|
||||||
// get() = WireGuardAutoTunnel.instance.getString(R.string.config_changes_saved)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// data object ConfigsExported : Message() {
|
|
||||||
// override val message: String
|
|
||||||
// get() = WireGuardAutoTunnel.instance.getString(R.string.exported_configs_message)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// data object TunnelOffAction : Message() {
|
|
||||||
// override val message: String
|
|
||||||
// get() = WireGuardAutoTunnel.instance.getString(R.string.turn_off_tunnel)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// data object TunnelOnAction : Message() {
|
|
||||||
// override val message: String
|
|
||||||
// get() = WireGuardAutoTunnel.instance.getString(R.string.turn_on_tunnel)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// data object AutoTunnelOffAction : Message() {
|
|
||||||
// override val message: String
|
|
||||||
// get() = WireGuardAutoTunnel.instance.getString(R.string.turn_off_auto)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="960"
|
|
||||||
android:viewportHeight="960">
|
|
||||||
<path
|
|
||||||
android:pathData="M440,520L200,520v-80h240v-240h80v240h240v80L520,520v240h-80v-240Z"
|
|
||||||
android:fillColor="#e8eaed"/>
|
|
||||||
</vector>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="960"
|
|
||||||
android:viewportHeight="960">
|
|
||||||
<path
|
|
||||||
android:pathData="m256,760 l-56,-56 224,-224 -224,-224 56,-56 224,224 224,-224 56,56 -224,224 224,224 -56,56 -224,-224 -224,224Z"
|
|
||||||
android:fillColor="#e8eaed"/>
|
|
||||||
</vector>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="960"
|
|
||||||
android:viewportHeight="960">
|
|
||||||
<path
|
|
||||||
android:pathData="M200,760h57l391,-391 -57,-57 -391,391v57ZM120,840v-170l528,-527q12,-11 26.5,-17t30.5,-6q16,0 31,6t26,18l55,56q12,11 17.5,26t5.5,30q0,16 -5.5,30.5T817,313L290,840L120,840ZM760,256 L704,200 760,256ZM619,341 L591,312 648,369 619,341Z"
|
|
||||||
android:fillColor="#e8eaed"/>
|
|
||||||
</vector>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="50dp"
|
|
||||||
android:height="50dp"
|
|
||||||
android:viewportWidth="50"
|
|
||||||
android:viewportHeight="50">
|
|
||||||
<path
|
|
||||||
android:fillColor="#FF000000"
|
|
||||||
android:pathData="M25,2c12.703,0 23,10.297 23,23S37.703,48 25,48S2,37.703 2,25S12.297,2 25,2zM32.934,34.375c0.423,-1.298 2.405,-14.234 2.65,-16.783c0.074,-0.772 -0.17,-1.285 -0.648,-1.514c-0.578,-0.278 -1.434,-0.139 -2.427,0.219c-1.362,0.491 -18.774,7.884 -19.78,8.312c-0.954,0.405 -1.856,0.847 -1.856,1.487c0,0.45 0.267,0.703 1.003,0.966c0.766,0.273 2.695,0.858 3.834,1.172c1.097,0.303 2.346,0.04 3.046,-0.395c0.742,-0.461 9.305,-6.191 9.92,-6.693c0.614,-0.502 1.104,0.141 0.602,0.644c-0.502,0.502 -6.38,6.207 -7.155,6.997c-0.941,0.959 -0.273,1.953 0.358,2.351c0.721,0.454 5.906,3.932 6.687,4.49c0.781,0.558 1.573,0.811 2.298,0.811C32.191,36.439 32.573,35.484 32.934,34.375z"/>
|
|
||||||
</vector>
|
|
||||||
@@ -73,92 +73,4 @@
|
|||||||
<string name="copy_public_key">Öffentlicher Schlüssel kopieren</string>
|
<string name="copy_public_key">Öffentlicher Schlüssel kopieren</string>
|
||||||
<string name="base64_key">base64-Schlüssel</string>
|
<string name="base64_key">base64-Schlüssel</string>
|
||||||
<string name="comma_separated_list">Kommaseparierte Liste</string>
|
<string name="comma_separated_list">Kommaseparierte Liste</string>
|
||||||
<string name="delete_tunnel">Tunnel löschen</string>
|
|
||||||
<string name="persistent_keepalive">Dauerhaftes Keepalive</string>
|
|
||||||
<string name="background_location_required">Hintergrund Standortdienste erforderlich</string>
|
|
||||||
<string name="enable_app_lock">App Sperre aktiviert</string>
|
|
||||||
<string name="discord_description">Tritt der Community bei</string>
|
|
||||||
<string name="interface_">Schnittstelle</string>
|
|
||||||
<string name="listen_port">Eingehender Port</string>
|
|
||||||
<string name="random">(zufällig)</string>
|
|
||||||
<string name="optional">(nicht erforderlich)</string>
|
|
||||||
<string name="optional_no_recommend">(nicht erforderlich, aber empfohlen)</string>
|
|
||||||
<string name="seconds">Sekunden</string>
|
|
||||||
<string name="cancel">Abbrechen</string>
|
|
||||||
<string name="preshared_key">Geteilter Schlüssel</string>
|
|
||||||
<string name="enabled_app_shortcuts">Aktiviere App Verknüpfungen</string>
|
|
||||||
<string name="exported_configs_message">Konfigurationen in den Download Ordner exportiert</string>
|
|
||||||
<string name="tunnel_on_wifi">Tunnel bei nicht vertrauenswürdigem Wifi</string>
|
|
||||||
<string name="email_subject">WG Tunnel Unterstützung</string>
|
|
||||||
<string name="docs_description">Lese die Dokumentation</string>
|
|
||||||
<string name="email_description">Sende mir eine E-Mail</string>
|
|
||||||
<string name="support_help_text">Bei Fehlern oder Verbesserungsvorschlägen stehen folgende Ressourcen zur Verfügung:</string>
|
|
||||||
<string name="error_root_denied">Root Shell verboten</string>
|
|
||||||
<string name="error_no_file_explorer">Kein Datei-Explorer installiert</string>
|
|
||||||
<string name="location_services_missing_message">Die App konnte keine aktivierten Standortdienste auf deinem Gerät erkennen. Dies kann auf manchen Geräten ein Auslesen des aktuellen WIFI-Names für die \"Nicht vertrauenswürdiges WIFI\" Funktion verhindern. Möchtest du trotzdem fortfahren ?</string>
|
|
||||||
<string name="auto_tunnel_title">Auto-Tunnel Service</string>
|
|
||||||
<string name="delete_tunnel_message">Bist du sicher, dass du den Tunnel löschen möchtest?</string>
|
|
||||||
<string name="yes">Ja</string>
|
|
||||||
<string name="resume">Fortsetzen</string>
|
|
||||||
<string name="pause">Pausieren</string>
|
|
||||||
<string name="paused">Pausiert</string>
|
|
||||||
<string name="active">Aktiv</string>
|
|
||||||
<string name="go">Gehe</string>
|
|
||||||
<string name="excluded">Ausgeschlossen</string>
|
|
||||||
<string name="all">Alle</string>
|
|
||||||
<string name="always_on_disabled">Always-on VPN wollte eine Tunnel starten, aber dieses Feature ist in den Einstellungen deaktiviert.</string>
|
|
||||||
<string name="no_browser_detected">Kein Browser erkannt</string>
|
|
||||||
<string name="open_issue">Öffne ein Issue</string>
|
|
||||||
<string name="read_logs">Lese die Logs</string>
|
|
||||||
<string name="auto">(automatisch)</string>
|
|
||||||
<string name="config_parse_error">Fehler beim lesen der Konfiguration</string>
|
|
||||||
<string name="incorrect_pin">PIN is nicht korrekt</string>
|
|
||||||
<string name="pin_created">PIN erfolgreich angelegt</string>
|
|
||||||
<string name="enter_pin">Gib deine PIN ein</string>
|
|
||||||
<string name="auto_off">Auto-Tunnel pausieren</string>
|
|
||||||
<string name="auto_tun_on">Auto-Tunnel fortsetzen</string>
|
|
||||||
<string name="auto_tun_off">Auto-Tunnel pausieren</string>
|
|
||||||
<string name="version">Version</string>
|
|
||||||
<string name="mode">Modus</string>
|
|
||||||
<string name="userspace">Userspace</string>
|
|
||||||
<string name="settings">Einstellungen</string>
|
|
||||||
<string name="support">Unterstützung</string>
|
|
||||||
<string name="watcher_channel_id">Beobachter Kanal</string>
|
|
||||||
<string name="error_authentication_failed">Anmeldung fehlgeschlagen</string>
|
|
||||||
<string name="export_configs">Exportiere Konfigurationen</string>
|
|
||||||
<string name="unknown_error">Ein unbekannter Fehler ist aufgetreten</string>
|
|
||||||
<string name="email_chooser">Sende eine E-Mail…</string>
|
|
||||||
<string name="error_authorization_failed">Fehler bei der Authorisierung</string>
|
|
||||||
<string name="location_services_required">Standortdienste erforderlich</string>
|
|
||||||
<string name="precise_location_required">Genauer Standort erforderlich</string>
|
|
||||||
<string name="error_invalid_code">Fehlerhafter QR code</string>
|
|
||||||
<string name="error_none">Kein Fehler</string>
|
|
||||||
<string name="tunneling_apps">Tunnel Anwendungen</string>
|
|
||||||
<string name="included">Hinzugefügt</string>
|
|
||||||
<string name="no_email_detected">Keine E-Mail Anwendung erkannt</string>
|
|
||||||
<string name="logs_saved">Logs im Download Ordner gespeichert</string>
|
|
||||||
<string name="create_pin">Erstelle eine PIN</string>
|
|
||||||
<string name="use_tunnel_on_wifi_name">Tunnel in Wifi-Namen verwenden</string>
|
|
||||||
<string name="no_wifi_names_configured">Keine Wifi-Namen für diesen Tunnel konfiguriert</string>
|
|
||||||
<string name="disabled">Deaktiviert</string>
|
|
||||||
<string name="mobile_data_tunnel">Als Tunnel für Mobile Daten setzen</string>
|
|
||||||
<string name="general">Allgemein</string>
|
|
||||||
<string name="restart_on_ping">Neustart bei PING Fehler (Beta)</string>
|
|
||||||
<string name="edit_tunnel">Tunnel bearbeiten</string>
|
|
||||||
<string name="set_primary_tunnel">Als Primären Tunnel setzen</string>
|
|
||||||
<string name="auto_on">Auto-Tunnel fortsetzen</string>
|
|
||||||
<string name="vpn_channel_id">VPN Kanal</string>
|
|
||||||
<string name="vpn_channel_name">VPN Benachrichtigungskanal</string>
|
|
||||||
<string name="watcher_channel_name">Beobachter Benachrichtigungskanal</string>
|
|
||||||
<string name="turn_off_tunnel">Aktion erfordert deaktivierten Tunnel</string>
|
|
||||||
<string name="kernel">Kernel</string>
|
|
||||||
<string name="use_kernel">Verwende das Kernel Modul</string>
|
|
||||||
<string name="error_ssid_exists">SSID existiert bereits</string>
|
|
||||||
<string name="use_amnezia">"Benutze Amnezia Benuzterumgebung "</string>
|
|
||||||
<string name="junk_packet_count">Müll Packet Anzahk</string>
|
|
||||||
<string name="junk_packet_maximum_size">Müll Packet maximale Grösse</string>
|
|
||||||
<string name="init_packet_junk_size">Erstes Packet Müllgrösse</string>
|
|
||||||
<string name="backend">Backend</string>
|
|
||||||
<string name="junk_packet_minimum_size">Müll Packet minimale Grösse</string>
|
|
||||||
<string name="response_packet_junk_size">Antwortpaket Müllgrösse</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -154,4 +154,9 @@
|
|||||||
<string name="watcher_channel_id">Canal del obvervador</string>
|
<string name="watcher_channel_id">Canal del obvervador</string>
|
||||||
<string name="watcher_channel_name">Canal de notificación del obvervador</string>
|
<string name="watcher_channel_name">Canal de notificación del obvervador</string>
|
||||||
<string name="prominent_background_location_message">La monitorización SSID Wi-Fi necesita de permiso de ubicación en segundo plano incluso si la app está cerrada. Mira el enlace a la Política de Privacidad en la pantalla de ayuda para más detalles.</string>
|
<string name="prominent_background_location_message">La monitorización SSID Wi-Fi necesita de permiso de ubicación en segundo plano incluso si la app está cerrada. Mira el enlace a la Política de Privacidad en la pantalla de ayuda para más detalles.</string>
|
||||||
|
<string name="privacy_policy_url" translatable="false"></string>
|
||||||
|
<string name="docs_url" translatable="false"></string>
|
||||||
|
<string name="github_url" translatable="false"></string>
|
||||||
|
<string name="discord_url" translatable="false"></string>
|
||||||
|
<string name="my_email" translatable="false"></string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,39 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="turn_off_tunnel">Действие требует отключения туннеля</string>
|
</resources>
|
||||||
<string name="add_tunnel">Добавить туннель</string>
|
|
||||||
<string name="mtu">MTU</string>
|
|
||||||
<string name="tunnel_name">Имя туннеля</string>
|
|
||||||
<string name="public_key">Публичный ключ</string>
|
|
||||||
<string name="name">Имя</string>
|
|
||||||
<string name="peer">Пир</string>
|
|
||||||
<string name="privacy_policy">Посмотреть политику конфиденциальности</string>
|
|
||||||
<string name="icon">Иконка</string>
|
|
||||||
<string name="turn_on">Включить</string>
|
|
||||||
<string name="add_from_qr">Добавить из QR</string>
|
|
||||||
<string name="qr_scan">Сканер QR</string>
|
|
||||||
<string name="auto_tunneling">Авто-туннелирование</string>
|
|
||||||
<string name="no_tunnels">Туннели еще не добавлены!</string>
|
|
||||||
<string name="open_file">Открыть файл</string>
|
|
||||||
<string name="exclude">Исключить</string>
|
|
||||||
<string name="include">Включить</string>
|
|
||||||
<string name="tunnel_all">Туннель для всех приложений</string>
|
|
||||||
<string name="config_changes_saved">Изменения конфигурации сохранены.</string>
|
|
||||||
<string name="save_changes">Сохранить</string>
|
|
||||||
<string name="no_thanks">Нет, спасибо</string>
|
|
||||||
<string name="map">Карта</string>
|
|
||||||
<string name="addresses">Адреса</string>
|
|
||||||
<string name="dns_servers">DNS сервера</string>
|
|
||||||
<string name="allowed_ips">Разрешенные IP</string>
|
|
||||||
<string name="endpoint">Конечная точка</string>
|
|
||||||
<string name="restart">Перезагрузить туннель</string>
|
|
||||||
<string name="vpn_connection_failed">Ошибка соединения</string>
|
|
||||||
<string name="always_on_vpn_support">Разрешить постоянный VPN</string>
|
|
||||||
<string name="hint_search_packages">Поиск приложений</string>
|
|
||||||
<string name="other">Другое</string>
|
|
||||||
<string name="vpn_on">VPN вкл.</string>
|
|
||||||
<string name="vpn_off">VPN откл.</string>
|
|
||||||
<string name="interface_">Интерфейс</string>
|
|
||||||
<string name="optional">(необязательно)</string>
|
|
||||||
<string name="optional_no_recommend">(необязательно, не рекомендуется)</string>
|
|
||||||
</resources>
|
|
||||||
@@ -94,7 +94,6 @@
|
|||||||
<string name="error_authorization_failed">Failed to authorize</string>
|
<string name="error_authorization_failed">Failed to authorize</string>
|
||||||
<string name="enabled_app_shortcuts">Enable app shortcuts</string>
|
<string name="enabled_app_shortcuts">Enable app shortcuts</string>
|
||||||
<string name="export_configs">Export configs</string>
|
<string name="export_configs">Export configs</string>
|
||||||
<string name="export_configs_failed">Failed to export configs</string>
|
|
||||||
<string name="location_services_required">Location services required</string>
|
<string name="location_services_required">Location services required</string>
|
||||||
<string name="background_location_required">Background location required</string>
|
<string name="background_location_required">Background location required</string>
|
||||||
<string name="precise_location_required">Precise location required</string>
|
<string name="precise_location_required">Precise location required</string>
|
||||||
@@ -109,6 +108,7 @@
|
|||||||
<string name="discord_description">Join the community</string>
|
<string name="discord_description">Join the community</string>
|
||||||
<string name="email_description">Send me an email</string>
|
<string name="email_description">Send me an email</string>
|
||||||
<string name="support_help_text">If you are experiencing issues, have improvement ideas, or just want to engage, the following resources are available:</string>
|
<string name="support_help_text">If you are experiencing issues, have improvement ideas, or just want to engage, the following resources are available:</string>
|
||||||
|
<string name="kernel">Kernel</string>
|
||||||
<string name="use_kernel">Use kernel module</string>
|
<string name="use_kernel">Use kernel module</string>
|
||||||
<string name="error_ssid_exists">SSID already exists</string>
|
<string name="error_ssid_exists">SSID already exists</string>
|
||||||
<string name="error_root_denied">Root shell denied</string>
|
<string name="error_root_denied">Root shell denied</string>
|
||||||
@@ -140,7 +140,7 @@
|
|||||||
<string name="pin_created">Pin successfully created</string>
|
<string name="pin_created">Pin successfully created</string>
|
||||||
<string name="enter_pin">Enter your pin</string>
|
<string name="enter_pin">Enter your pin</string>
|
||||||
<string name="create_pin">Create pin</string>
|
<string name="create_pin">Create pin</string>
|
||||||
<string name="enable_app_lock">Enable app lock</string>
|
<string name="enable_app_lock">Enabled app lock</string>
|
||||||
<string name="restart_on_ping">Restart on ping fail (beta)</string>
|
<string name="restart_on_ping">Restart on ping fail (beta)</string>
|
||||||
<string name="mobile_data_tunnel">Set as mobile data tunnel</string>
|
<string name="mobile_data_tunnel">Set as mobile data tunnel</string>
|
||||||
<string name="set_primary_tunnel">Set as primary tunnel</string>
|
<string name="set_primary_tunnel">Set as primary tunnel</string>
|
||||||
@@ -158,24 +158,4 @@
|
|||||||
<string name="userspace">Userspace</string>
|
<string name="userspace">Userspace</string>
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
<string name="support">Support</string>
|
<string name="support">Support</string>
|
||||||
<string name="backend">Backend</string>
|
|
||||||
<string name="kernel">Kernel</string>
|
|
||||||
<string name="use_amnezia">"Use Amnezia userspace "</string>
|
|
||||||
<string name="junk_packet_count">Junk packet count</string>
|
|
||||||
<string name="junk_packet_minimum_size">Junk packet minimum size</string>
|
|
||||||
<string name="junk_packet_maximum_size">Junk packet maximum size</string>
|
|
||||||
<string name="init_packet_junk_size">Init packet junk size</string>
|
|
||||||
<string name="response_packet_junk_size">Response packet junk size</string>
|
|
||||||
<string name="init_packet_magic_header">Init packet magic header</string>
|
|
||||||
<string name="response_packet_magic_header">Response packet magic header</string>
|
|
||||||
<string name="transport_packet_magic_header">Transport packet magic header</string>
|
|
||||||
<string name="underload_packet_magic_header">Underload packet magic header</string>
|
|
||||||
<string name="telegram_url" translatable="false">https://t.me/wgtunnel</string>
|
|
||||||
<string name="unsure_how">if you are unsure how to proceed</string>
|
|
||||||
<string name="see_the">See the</string>
|
|
||||||
<string name="getting_started_url" translatable="false">https://zaneschepke.com/wgtunnel-docs/getting-started.html</string>
|
|
||||||
<string name="getting_started_guide">getting started guide</string>
|
|
||||||
<string name="amnezia" translatable="false">Amnezia</string>
|
|
||||||
<string name="wireguard" translatable="false">WireGuard</string>
|
|
||||||
<string name="error_file_format">Invalid tunnel config format</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
object Constants {
|
object Constants {
|
||||||
const val VERSION_NAME = "3.4.4"
|
const val VERSION_NAME = "3.4.3-alpha"
|
||||||
const val JVM_TARGET = "17"
|
const val JVM_TARGET = "17"
|
||||||
const val VERSION_CODE = 34400
|
const val VERSION_CODE = 34201
|
||||||
const val TARGET_SDK = 34
|
const val TARGET_SDK = 34
|
||||||
const val MIN_SDK = 26
|
const val MIN_SDK = 26
|
||||||
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
const val APP_ID = "com.zaneschepke.wireguardautotunnel"
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
Verbesserungen:
|
|
||||||
- Refaktorisierung des Zustandsmanagements
|
|
||||||
- Verbesserung der AndroidTV Navigation
|
|
||||||
- Verbesserung der Auto-Tunnel Effizienz
|
|
||||||
- Verbesserung der Navigation
|
|
||||||
- Auto-Tunnel Pause Funktion
|
|
||||||
- Viele Fehlerbehebungen
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
Verbesserungen:
|
|
||||||
- Refaktorisierung des Zustandsmanagements
|
|
||||||
- Verbesserung der AndroidTV Navigation
|
|
||||||
- Verbesserung der Auto-Tunnel Effizienz
|
|
||||||
- Verbesserung der Navigation
|
|
||||||
- Auto-Tunnel Pause Funktion
|
|
||||||
- Reparatur des Auto-Tunnel starts im Vordergrund
|
|
||||||
- Viele Fehlerbehebungen
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
Verbesserungen:
|
|
||||||
- Bestätigung beim Tunnel löschen hinzugefügt
|
|
||||||
- Hintergrundberechtigung für Energiesparmodus hinzugefügt
|
|
||||||
Fehlerbehebungen:
|
|
||||||
- Einfrieren der App bei Tunnel deaktivierung
|
|
||||||
- Fehler im E-Mail Empfängerfeld
|
|
||||||
- Konfigurationsbearbeitung mit leerem DNS Feld
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Verbesserungen:
|
|
||||||
- Erstellte Konfiguration wurde nicht gespeichert
|
|
||||||
- Version angehoben
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Was ist neu:
|
|
||||||
- Dies ist eine CI Test version
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
Was ist neu:
|
|
||||||
- Automatischer Start des Always-On VPN im Kernelmodus nach einem Systemneustart
|
|
||||||
- Unterstützung für adaptive Designicons
|
|
||||||
- Benachrichtigungs- und Kachelicons korrigiert
|
|
||||||
- AndroidTV icons korrigiert
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
Was ist neu:
|
|
||||||
- Verbesserung des ersten Starts
|
|
||||||
- Wechsel zu Wireguard Bibliotheks Fork
|
|
||||||
- Abfrage der VPN Berechtigung beim ersten VPN Start
|
|
||||||
- Version angehoben
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Was ist neu:
|
|
||||||
- GUI Fix for Tunnel Anzeige
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
Was ist neu:
|
|
||||||
- GUI Fix für Konfigurationseditor
|
|
||||||
- AOVPN Benachrichtung für ersten Start auf GrapheneOS hinzugefügt
|
|
||||||
- Version angehoben
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
Was ist neu:
|
|
||||||
- Log anzeige hinzugefügt
|
|
||||||
- Lokale App Sperre hinzugefügt
|
|
||||||
- Funktion für Neustart des Tunnels nach Fehlerhaftem Ping
|
|
||||||
- Verschiedene Fehlerbehebungen
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
Was ist neu:
|
|
||||||
- Auto-Tunnel Auswahl nach WLAN-Name
|
|
||||||
- Auto-Tunnel Kontrolle durch Kacheln und Verknüpfungen
|
|
||||||
- Automatischer Neustart des Manuellen Tunnels nach einem Systemneustart
|
|
||||||
- Verschiedene Fehlerbehebungen und Performanceverbesserungen
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
Was ist neu:
|
|
||||||
- Verbesserung der Auto-Tunnel Zuverlässigkeit
|
|
||||||
- Verbesserung der Kachelsynchronisierung
|
|
||||||
- AndroidTV Asset hinzugefügt
|
|
||||||
- APK Fingerabdruck hinzugefügt
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
Was ist neu:
|
|
||||||
- Behebung einer Regression beim Tunnel Stop
|
|
||||||
- Log Verschleierung hinzugefügt
|
|
||||||
- Ausblenden des Icons beim Scrollen
|
|
||||||
- Türkische Übersetzung hinzugefügt
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Was ist neu:
|
|
||||||
- Amnezia seite-zu-seite mit WireGuard hinzugefügt
|
|
||||||
- App Shortcut Bug behoben
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
What's new:
|
||||||
|
- AmneziaWG support
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
What's new:
|
|
||||||
- Add Amnezia side-by-side with WireGuard
|
|
||||||
- Fix app shortcuts bug
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
What's new:
|
|
||||||
- Official support for AmneziaWG
|
|
||||||
- Import/export for Amnezia configs
|
|
||||||
- Auto-tunnel to only toggle once per network change
|
|
||||||
- Additional languages support
|
|
||||||
- Other bug fixes and improvements
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
What's new:
|
|
||||||
- Improve tunnel import naming
|
|
||||||
- Fix auto tunneling init state bug
|
|
||||||
- Improved error handling
|
|
||||||
- Fix Amnezia zip import bug
|
|
||||||
@@ -4,9 +4,8 @@ Features
|
|||||||
- Auto connect to VPN based on Wi-Fi SSID, ethernet, or mobile data
|
- Auto connect to VPN based on Wi-Fi SSID, ethernet, or mobile data
|
||||||
- Split tunneling by application with search
|
- Split tunneling by application with search
|
||||||
- WireGuard support for kernel and userspace modes
|
- WireGuard support for kernel and userspace modes
|
||||||
- Amnezia support for userspace mode for DPI/censorship protection
|
|
||||||
- Always-On VPN support
|
- Always-On VPN support
|
||||||
- Export Amnezia and WireGuard tunnels to zip
|
- Export tunnels to zip
|
||||||
- Quick tile support for VPN toggling
|
- Quick tile support for VPN toggling
|
||||||
- Static shortcuts support for primary tunnel for automation integration
|
- Static shortcuts support for primary tunnel for automation integration
|
||||||
- Intent automation support for all tunnels
|
- Intent automation support for all tunnels
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
Mejoras:
|
|
||||||
- Gestión del estado de refactorización.
|
|
||||||
- Mejorar la navegación de AndroidTV
|
|
||||||
- Mejorar la eficiencia del túnel automático
|
|
||||||
- Mejorar la navegación
|
|
||||||
- Función de pausa de túnel automático
|
|
||||||
- Muchas correcciones de errores
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
Mejoras:
|
|
||||||
- Gestión del estado de refactorización.
|
|
||||||
- Mejorar la navegación de AndroidTV
|
|
||||||
- Mejorar la eficiencia del túnel automático
|
|
||||||
- Mejorar la navegación
|
|
||||||
- Función de pausa de túnel automático
|
|
||||||
- Muchas correcciones de errores
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
Mejoras:
|
|
||||||
- Gestión del estado de refactorización.
|
|
||||||
- Mejorar la navegación de AndroidTV
|
|
||||||
- Mejorar la eficiencia del túnel automático
|
|
||||||
- Mejorar la navegación
|
|
||||||
- Función de pausa de túnel automático
|
|
||||||
- Se corrigió el inicio del túnel automático en primer plano.
|
|
||||||
- Muchas correcciones de errores
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
Mejoras:
|
|
||||||
- Se agregó confirmación al eliminar el túnel.
|
|
||||||
- Se agregó permiso en segundo plano para el modo de ahorro de energía.
|
|
||||||
Corrección de errores:
|
|
||||||
- La aplicación se congela cuando el túnel está desactivado.
|
|
||||||
- Error en el campo del destinatario del correo electrónico
|
|
||||||
- Edición de configuración con campo DNS vacío
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Mejoras:
|
|
||||||
- La configuración creada no se guardó.
|
|
||||||
- Versión elevada
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Qué hay de nuevo:
|
|
||||||
- Esta es una versión de prueba de CI
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
Qué hay de nuevo:
|
|
||||||
- Inicio automático al reiniciar para el modo kernel de VPN siempre activo
|
|
||||||
- Soporte para íconos de temas adaptables
|
|
||||||
- Arreglar íconos de notificación, ícono de mosaico
|
|
||||||
- Reparar iconos de AndroidTV
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user