Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b3cb7a7988 | |||
| 6415f49377 | |||
| baed8ff2e7 |
@@ -13,17 +13,9 @@ WG Tunnel
|
|||||||
|
|
||||||
|
|
||||||
[](https://play.google.com/store/apps/details?id=com.zaneschepke.wireguardautotunnel)
|
[](https://play.google.com/store/apps/details?id=com.zaneschepke.wireguardautotunnel)
|
||||||
[](https://www.amazon.com/gp/product/B0CFGGL7WK)
|
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span align="center">
|
|
||||||
|
|
||||||
[](https://ko-fi.com/N4N8NMJN2)
|
|
||||||
|
|
||||||
</span>
|
|
||||||
|
|
||||||
|
|
||||||
<span align="left">
|
<span align="left">
|
||||||
|
|
||||||
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) 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.
|
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) 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.
|
||||||
@@ -51,10 +43,8 @@ The inspiration for this app came from the inconvenience of constantly having to
|
|||||||
|
|
||||||
* Add tunnels via .conf file
|
* Add tunnels via .conf file
|
||||||
* Auto connect to VPN based on Wi-Fi SSID
|
* Auto connect to VPN based on Wi-Fi SSID
|
||||||
* Split tunneling by application with search
|
* Split tunneling by application
|
||||||
* Always-on VPN for Android support
|
* Always-on VPN for Android support
|
||||||
* Quick tile support for vpn toggling
|
|
||||||
* Dynamic shortcuts support for automation integration
|
|
||||||
* Configurable Trusted Network list
|
* Configurable Trusted Network list
|
||||||
* Optional auto connect on mobile data
|
* Optional auto connect on mobile data
|
||||||
* Automatic service restart after reboot
|
* Automatic service restart after reboot
|
||||||
|
|||||||
@@ -1,25 +1,31 @@
|
|||||||
|
val rExtra = rootProject.extra
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application)
|
id("com.android.application")
|
||||||
alias(libs.plugins.kotlin.android)
|
id("org.jetbrains.kotlin.android")
|
||||||
alias(libs.plugins.hilt.android)
|
kotlin("kapt")
|
||||||
|
id("com.google.dagger.hilt.android")
|
||||||
|
id("com.google.gms.google-services")
|
||||||
|
id("com.google.firebase.crashlytics")
|
||||||
id("org.jetbrains.kotlin.plugin.serialization")
|
id("org.jetbrains.kotlin.plugin.serialization")
|
||||||
alias(libs.plugins.ksp)
|
id("io.objectbox")
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.zaneschepke.wireguardautotunnel"
|
namespace = "com.zaneschepke.wireguardautotunnel"
|
||||||
compileSdk = 34
|
compileSdk = 34
|
||||||
|
|
||||||
|
val versionMajor = 2
|
||||||
|
val versionMinor = 2
|
||||||
|
val versionPatch = 0
|
||||||
|
val versionBuild = 0
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.zaneschepke.wireguardautotunnel"
|
applicationId = "com.zaneschepke.wireguardautotunnel"
|
||||||
minSdk = 26
|
minSdk = 29
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 30001
|
versionCode = versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
|
||||||
versionName = "3.0.1"
|
versionName = "${versionMajor}.${versionMinor}.${versionPatch}"
|
||||||
|
|
||||||
multiDexEnabled = true
|
|
||||||
|
|
||||||
resourceConfigurations.addAll(listOf("en"))
|
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables {
|
vectorDrawables {
|
||||||
@@ -30,30 +36,12 @@ android {
|
|||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
isDebuggable = false
|
isDebuggable = false
|
||||||
isMinifyEnabled = true
|
isMinifyEnabled = false
|
||||||
isShrinkResources = true
|
|
||||||
proguardFiles(
|
proguardFiles(
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
"proguard-rules.pro"
|
"proguard-rules.pro"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
debug {
|
|
||||||
isDebuggable = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
flavorDimensions.add("type")
|
|
||||||
productFlavors {
|
|
||||||
create("fdroid") {
|
|
||||||
dimension = "type"
|
|
||||||
}
|
|
||||||
create("general") {
|
|
||||||
dimension = "type"
|
|
||||||
if (BuildHelper.isReleaseBuild(gradle) && BuildHelper.isGeneralFlavor(gradle))
|
|
||||||
{
|
|
||||||
apply(plugin = "com.google.gms.google-services")
|
|
||||||
apply(plugin = "com.google.firebase.crashlytics")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
@@ -64,11 +52,9 @@ android {
|
|||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
compose = true
|
compose = true
|
||||||
buildConfig = true
|
|
||||||
|
|
||||||
}
|
}
|
||||||
composeOptions {
|
composeOptions {
|
||||||
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
|
kotlinCompilerExtensionVersion = "1.4.8"
|
||||||
}
|
}
|
||||||
packaging {
|
packaging {
|
||||||
resources {
|
resources {
|
||||||
@@ -77,67 +63,71 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val generalImplementation by configurations
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation("androidx.core:core-ktx:1.10.1")
|
||||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
|
||||||
implementation(libs.androidx.activity.compose)
|
implementation("androidx.activity:activity-compose:1.7.2")
|
||||||
implementation(platform(libs.androidx.compose.bom))
|
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
|
||||||
implementation(libs.androidx.compose.ui)
|
implementation("androidx.compose.ui:ui")
|
||||||
implementation(libs.androidx.compose.ui.graphics)
|
implementation("androidx.compose.ui:ui-graphics")
|
||||||
implementation(libs.androidx.compose.ui.tooling.preview)
|
implementation("androidx.compose.ui:ui-tooling-preview")
|
||||||
implementation(libs.androidx.material3)
|
implementation("androidx.compose.material3:material3:1.1.1")
|
||||||
implementation(libs.androidx.appcompat)
|
implementation("androidx.appcompat:appcompat:1.6.1")
|
||||||
|
|
||||||
//test
|
testImplementation("junit:junit:4.13.2")
|
||||||
testImplementation(libs.junit)
|
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||||
androidTestImplementation(libs.androidx.espresso.core)
|
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
|
||||||
androidTestImplementation(platform(libs.androidx.compose.bom))
|
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
|
||||||
androidTestImplementation(libs.androidx.compose.ui.test)
|
debugImplementation("androidx.compose.ui:ui-tooling")
|
||||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
debugImplementation("androidx.compose.ui:ui-test-manifest")
|
||||||
debugImplementation(libs.androidx.compose.manifest)
|
|
||||||
|
|
||||||
//wg
|
//wireguard tunnel
|
||||||
implementation(libs.tunnel)
|
implementation("com.wireguard.android:tunnel:1.0.20230427")
|
||||||
|
|
||||||
//logging
|
//logging
|
||||||
implementation(libs.timber)
|
implementation("com.jakewharton.timber:timber:5.0.1")
|
||||||
|
|
||||||
// compose navigation
|
// compose navigation
|
||||||
implementation(libs.androidx.navigation.compose)
|
implementation("androidx.navigation:navigation-compose:2.6.0")
|
||||||
implementation(libs.androidx.hilt.navigation.compose)
|
implementation("androidx.hilt:hilt-navigation-compose:1.0.0")
|
||||||
|
|
||||||
// hilt
|
// hilt
|
||||||
implementation(libs.hilt.android)
|
implementation("com.google.dagger:hilt-android:${rExtra.get("hiltVersion")}")
|
||||||
ksp(libs.hilt.android.compiler)
|
kapt("com.google.dagger:hilt-android-compiler:${rExtra.get("hiltVersion")}")
|
||||||
|
|
||||||
//accompanist
|
//accompanist
|
||||||
implementation(libs.accompanist.systemuicontroller)
|
implementation("com.google.accompanist:accompanist-systemuicontroller:${rExtra.get("accompanistVersion")}")
|
||||||
implementation(libs.accompanist.permissions)
|
implementation("com.google.accompanist:accompanist-permissions:${rExtra.get("accompanistVersion")}")
|
||||||
implementation(libs.accompanist.flowlayout)
|
implementation("com.google.accompanist:accompanist-flowlayout:${rExtra.get("accompanistVersion")}")
|
||||||
implementation(libs.accompanist.navigation.animation)
|
implementation("com.google.accompanist:accompanist-navigation-animation:${rExtra.get("accompanistVersion")}")
|
||||||
implementation(libs.accompanist.drawablepainter)
|
implementation("com.google.accompanist:accompanist-drawablepainter:${rExtra.get("accompanistVersion")}")
|
||||||
|
|
||||||
//room
|
//db
|
||||||
implementation(libs.androidx.room.runtime)
|
implementation("io.objectbox:objectbox-kotlin:${rExtra.get("objectBoxVersion")}")
|
||||||
ksp(libs.androidx.room.compiler)
|
|
||||||
implementation(libs.androidx.room.ktx)
|
|
||||||
|
|
||||||
//lifecycle
|
//lifecycle
|
||||||
implementation(libs.lifecycle.runtime.compose)
|
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.1")
|
||||||
|
|
||||||
//icons
|
//icons
|
||||||
implementation(libs.material.icons.extended)
|
implementation("androidx.compose.material:material-icons-extended:1.4.3")
|
||||||
//serialization
|
|
||||||
implementation(libs.kotlinx.serialization.json)
|
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
|
||||||
|
|
||||||
|
|
||||||
//firebase crashlytics
|
//firebase crashlytics
|
||||||
generalImplementation(platform(libs.firebase.bom))
|
implementation(platform("com.google.firebase:firebase-bom:32.0.0"))
|
||||||
generalImplementation(libs.google.firebase.crashlytics.ktx)
|
implementation("com.google.firebase:firebase-crashlytics-ktx")
|
||||||
generalImplementation(libs.google.firebase.analytics.ktx)
|
implementation("com.google.firebase:firebase-analytics-ktx")
|
||||||
|
|
||||||
//barcode scanning
|
//barcode scanning
|
||||||
implementation(libs.zxing.android.embedded)
|
implementation("com.google.android.gms:play-services-code-scanner:16.0.0")
|
||||||
implementation(libs.zxing.core)
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
kapt {
|
||||||
|
correctErrorTypes = true
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
{
|
||||||
|
"_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.",
|
||||||
|
"_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.",
|
||||||
|
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"id": "1:2692736974585027589",
|
||||||
|
"lastPropertyId": "15:5057486545428188436",
|
||||||
|
"name": "TunnelConfig",
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"id": "1:1985347930017457084",
|
||||||
|
"name": "id",
|
||||||
|
"type": 6,
|
||||||
|
"flags": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "12:2409068226744965585",
|
||||||
|
"name": "name",
|
||||||
|
"indexId": "1:4811206443952699137",
|
||||||
|
"type": 9,
|
||||||
|
"flags": 34848
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "13:8987443291286312275",
|
||||||
|
"name": "wgQuick",
|
||||||
|
"type": 9
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"relations": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2:8887605597748372702",
|
||||||
|
"lastPropertyId": "9:4468844863383145378",
|
||||||
|
"name": "Settings",
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"id": "1:7485739868216068651",
|
||||||
|
"name": "id",
|
||||||
|
"type": 6,
|
||||||
|
"flags": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2:5814013113141456749",
|
||||||
|
"name": "isAutoTunnelEnabled",
|
||||||
|
"type": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4:5645665441196906014",
|
||||||
|
"name": "trustedNetworkSSIDs",
|
||||||
|
"type": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "5:4989886999117763881",
|
||||||
|
"name": "isTunnelOnMobileDataEnabled",
|
||||||
|
"type": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6:3370284381040192129",
|
||||||
|
"name": "defaultTunnel",
|
||||||
|
"type": 9
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "9:4468844863383145378",
|
||||||
|
"name": "isAlwaysOnVpnEnabled",
|
||||||
|
"type": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"relations": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"lastEntityId": "2:8887605597748372702",
|
||||||
|
"lastIndexId": "1:4811206443952699137",
|
||||||
|
"lastRelationId": "0:0",
|
||||||
|
"lastSequenceId": "0:0",
|
||||||
|
"modelVersion": 5,
|
||||||
|
"modelVersionParserMinimum": 5,
|
||||||
|
"retiredEntityUids": [],
|
||||||
|
"retiredIndexUids": [],
|
||||||
|
"retiredPropertyUids": [
|
||||||
|
1763475292291320186,
|
||||||
|
6483820955437198310,
|
||||||
|
8323071516033820771,
|
||||||
|
5904440563612311217,
|
||||||
|
1408037976996390989,
|
||||||
|
7737847485212546994,
|
||||||
|
8215616901775229364,
|
||||||
|
8021610768066328637,
|
||||||
|
6174306582797008721,
|
||||||
|
2175939938544485767,
|
||||||
|
7555225587864607050,
|
||||||
|
969146862000617878,
|
||||||
|
5057486545428188436,
|
||||||
|
2814640993034665120,
|
||||||
|
4981008812459251156
|
||||||
|
],
|
||||||
|
"retiredRelationUids": [],
|
||||||
|
"version": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
{
|
||||||
|
"_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.",
|
||||||
|
"_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.",
|
||||||
|
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"id": "1:2692736974585027589",
|
||||||
|
"lastPropertyId": "15:5057486545428188436",
|
||||||
|
"name": "TunnelConfig",
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"id": "1:1985347930017457084",
|
||||||
|
"name": "id",
|
||||||
|
"type": 6,
|
||||||
|
"flags": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "12:2409068226744965585",
|
||||||
|
"name": "name",
|
||||||
|
"indexId": "1:4811206443952699137",
|
||||||
|
"type": 9,
|
||||||
|
"flags": 34848
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "13:8987443291286312275",
|
||||||
|
"name": "wgQuick",
|
||||||
|
"type": 9
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"relations": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2:8887605597748372702",
|
||||||
|
"lastPropertyId": "8:4981008812459251156",
|
||||||
|
"name": "Settings",
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"id": "1:7485739868216068651",
|
||||||
|
"name": "id",
|
||||||
|
"type": 6,
|
||||||
|
"flags": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2:5814013113141456749",
|
||||||
|
"name": "isAutoTunnelEnabled",
|
||||||
|
"type": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4:5645665441196906014",
|
||||||
|
"name": "trustedNetworkSSIDs",
|
||||||
|
"type": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "5:4989886999117763881",
|
||||||
|
"name": "isTunnelOnMobileDataEnabled",
|
||||||
|
"type": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6:3370284381040192129",
|
||||||
|
"name": "defaultTunnel",
|
||||||
|
"type": 9
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"relations": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"lastEntityId": "2:8887605597748372702",
|
||||||
|
"lastIndexId": "1:4811206443952699137",
|
||||||
|
"lastRelationId": "0:0",
|
||||||
|
"lastSequenceId": "0:0",
|
||||||
|
"modelVersion": 5,
|
||||||
|
"modelVersionParserMinimum": 5,
|
||||||
|
"retiredEntityUids": [],
|
||||||
|
"retiredIndexUids": [],
|
||||||
|
"retiredPropertyUids": [
|
||||||
|
1763475292291320186,
|
||||||
|
6483820955437198310,
|
||||||
|
8323071516033820771,
|
||||||
|
5904440563612311217,
|
||||||
|
1408037976996390989,
|
||||||
|
7737847485212546994,
|
||||||
|
8215616901775229364,
|
||||||
|
8021610768066328637,
|
||||||
|
6174306582797008721,
|
||||||
|
2175939938544485767,
|
||||||
|
7555225587864607050,
|
||||||
|
969146862000617878,
|
||||||
|
5057486545428188436,
|
||||||
|
2814640993034665120,
|
||||||
|
4981008812459251156
|
||||||
|
],
|
||||||
|
"retiredRelationUids": [],
|
||||||
|
"version": 1
|
||||||
|
}
|
||||||
@@ -28,9 +28,6 @@
|
|||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.location.gps"
|
android:name="android.hardware.location.gps"
|
||||||
android:required="false" />
|
android:required="false" />
|
||||||
<uses-feature
|
|
||||||
android:name="android.hardware.screen.portrait"
|
|
||||||
android:required="false" />
|
|
||||||
<queries>
|
<queries>
|
||||||
<intent>
|
<intent>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
@@ -42,7 +39,7 @@
|
|||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
android:fullBackupContent="@xml/backup_rules"
|
android:fullBackupContent="@xml/backup_rules"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:banner="@mipmap/ic_banner"
|
android:banner="@mipmap/ic_launcher_foreground"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
@@ -56,44 +53,18 @@
|
|||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||||
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES"/>
|
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
|
||||||
android:name=".ui.CaptureActivityPortrait"
|
|
||||||
android:screenOrientation="fullSensor"
|
|
||||||
android:stateNotNeeded="true"
|
|
||||||
android:theme="@style/zxing_CaptureTheme"
|
|
||||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
|
||||||
<activity
|
|
||||||
android:finishOnTaskLaunch="true"
|
|
||||||
android:theme="@android:style/Theme.NoDisplay"
|
|
||||||
android:name=".service.shortcut.ShortcutsActivity"/>
|
|
||||||
<service
|
<service
|
||||||
android:name=".service.foreground.ForegroundService"
|
android:name=".service.foreground.ForegroundService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:foregroundServiceType="remoteMessaging"
|
android:foregroundServiceType="remoteMessaging"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
</service>
|
</service>
|
||||||
<service
|
|
||||||
android:exported="true"
|
|
||||||
android:name=".service.tile.TunnelControlTile"
|
|
||||||
android:icon="@drawable/shield"
|
|
||||||
android:label="WG Tunnel"
|
|
||||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
|
||||||
<meta-data android:name="android.service.quicksettings.ACTIVE_TILE"
|
|
||||||
android:value="true" />
|
|
||||||
<meta-data android:name="android.service.quicksettings.TOGGLEABLE_TILE"
|
|
||||||
android:value="true" />
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
|
||||||
</intent-filter>
|
|
||||||
</service>
|
|
||||||
<service
|
<service
|
||||||
android:name=".service.foreground.WireGuardTunnelService"
|
android:name=".service.foreground.WireGuardTunnelService"
|
||||||
android:permission="android.permission.BIND_VPN_SERVICE"
|
android:permission="android.permission.BIND_VPN_SERVICE"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:persistent="true"
|
|
||||||
android:foregroundServiceType="remoteMessaging"
|
android:foregroundServiceType="remoteMessaging"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -106,7 +77,6 @@
|
|||||||
android:name=".service.foreground.WireGuardConnectivityWatcherService"
|
android:name=".service.foreground.WireGuardConnectivityWatcherService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:stopWithTask="false"
|
android:stopWithTask="false"
|
||||||
android:persistent="true"
|
|
||||||
android:foregroundServiceType="location"
|
android:foregroundServiceType="location"
|
||||||
android:permission=""
|
android:permission=""
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
@@ -118,5 +88,11 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<receiver android:exported="false" android:name=".receiver.NotificationActionReceiver"/>
|
<receiver android:exported="false" android:name=".receiver.NotificationActionReceiver"/>
|
||||||
|
<meta-data
|
||||||
|
android:name="com.google.mlkit.vision.DEPENDENCIES"
|
||||||
|
android:value="barcode_ui"/>
|
||||||
|
<meta-data
|
||||||
|
android:name="firebase_crashlytics_collection_enabled"
|
||||||
|
android:value="true" />
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel
|
|
||||||
|
|
||||||
object Constants {
|
|
||||||
const val VPN_CONNECTIVITY_CHECK_INTERVAL = 3000L
|
|
||||||
const val VPN_STATISTIC_CHECK_INTERVAL = 10000L
|
|
||||||
const val SNACKBAR_DELAY = 3000L
|
|
||||||
const val TOGGLE_TUNNEL_DELAY = 500L
|
|
||||||
const val FADE_IN_ANIMATION_DURATION = 1000
|
|
||||||
const val SLIDE_IN_ANIMATION_DURATION = 500
|
|
||||||
const val SLIDE_IN_TRANSITION_OFFSET = 1000
|
|
||||||
const val VALID_FILE_EXTENSION = ".conf"
|
|
||||||
const val URI_CONTENT_SCHEME = "content"
|
|
||||||
const val URI_PACKAGE_SCHEME = "package"
|
|
||||||
const val ALLOWED_FILE_TYPES = "*/*"
|
|
||||||
}
|
|
||||||
@@ -1,24 +1,25 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel
|
package com.zaneschepke.wireguardautotunnel
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||||
import android.content.pm.PackageManager
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltAndroidApp
|
@HiltAndroidApp
|
||||||
class WireGuardAutoTunnel : Application() {
|
class WireGuardAutoTunnel : Application() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var settingsRepo : Repository<Settings>
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
if(BuildConfig.DEBUG) {
|
if(BuildConfig.DEBUG) {
|
||||||
|
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false);
|
||||||
Timber.plant(Timber.DebugTree())
|
Timber.plant(Timber.DebugTree())
|
||||||
}
|
}
|
||||||
}
|
settingsRepo.init()
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun isRunningOnAndroidTv(context : Context) : Boolean {
|
|
||||||
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.module
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.MyObjectBox
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import io.objectbox.Box
|
||||||
|
import io.objectbox.BoxStore
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
class BoxModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideBoxStore(@ApplicationContext context : Context) : BoxStore {
|
||||||
|
return MyObjectBox.builder()
|
||||||
|
.androidContext(context.applicationContext)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideBoxForSettings(store : BoxStore) : Box<Settings> {
|
||||||
|
return store.boxFor(Settings::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideBoxForTunnels(store : BoxStore) : Box<TunnelConfig> {
|
||||||
|
return store.boxFor(TunnelConfig::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.module
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.room.Room
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.AppDatabase
|
|
||||||
import dagger.Module
|
|
||||||
import dagger.Provides
|
|
||||||
import dagger.hilt.InstallIn
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import dagger.hilt.components.SingletonComponent
|
|
||||||
import javax.inject.Singleton
|
|
||||||
|
|
||||||
@Module
|
|
||||||
@InstallIn(SingletonComponent::class)
|
|
||||||
class DatabaseModule {
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideDatabase(@ApplicationContext context : Context) : AppDatabase {
|
|
||||||
return Room.databaseBuilder(
|
|
||||||
context,
|
|
||||||
AppDatabase::class.java, context.getString(R.string.db_name)
|
|
||||||
).build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +1,25 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.module
|
package com.zaneschepke.wireguardautotunnel.module
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.AppDatabase
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.repository.SettingsBox
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.repository.TunnelBox
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
|
import dagger.Binds
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
class RepositoryModule {
|
abstract class RepositoryModule {
|
||||||
|
|
||||||
|
@Binds
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
abstract fun provideSettingsRepository(settingsBox: SettingsBox) : Repository<Settings>
|
||||||
fun provideSettingsRepository(appDatabase: AppDatabase) : SettingsDoa {
|
|
||||||
return appDatabase.settingDao()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Binds
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
abstract fun provideTunnelRepository(tunnelBox: TunnelBox) : Repository<TunnelConfig>
|
||||||
fun provideTunnelConfigRepository(appDatabase: AppDatabase) : TunnelConfigDao {
|
|
||||||
return appDatabase.tunnelConfigDoa()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.module
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import com.google.mlkit.vision.barcode.common.Barcode
|
||||||
|
import com.google.mlkit.vision.codescanner.GmsBarcodeScanner
|
||||||
|
import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions
|
||||||
|
import com.google.mlkit.vision.codescanner.GmsBarcodeScanning
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.barcode.CodeScanner
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.barcode.QRScanner
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.android.components.ViewModelComponent
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import dagger.hilt.android.scopes.ViewModelScoped
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(ViewModelComponent::class)
|
||||||
|
class ScannerModule {
|
||||||
|
|
||||||
|
@ViewModelScoped
|
||||||
|
@Provides
|
||||||
|
fun provideBarCodeOptions() : GmsBarcodeScannerOptions {
|
||||||
|
return GmsBarcodeScannerOptions.Builder()
|
||||||
|
.setBarcodeFormats(Barcode.FORMAT_QR_CODE)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewModelScoped
|
||||||
|
@Provides
|
||||||
|
fun provideBarCodeScanner(@ApplicationContext context: Context, options: GmsBarcodeScannerOptions) : GmsBarcodeScanner {
|
||||||
|
return GmsBarcodeScanning.getClient(context, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewModelScoped
|
||||||
|
@Provides
|
||||||
|
fun provideQRScanner(gmsBarcodeScanner: GmsBarcodeScanner) : CodeScanner {
|
||||||
|
return QRScanner(gmsBarcodeScanner)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.module
|
package com.zaneschepke.wireguardautotunnel.module
|
||||||
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.EthernetService
|
import com.zaneschepke.wireguardautotunnel.service.barcode.CodeScanner
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.barcode.QRScanner
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.MobileDataService
|
import com.zaneschepke.wireguardautotunnel.service.network.MobileDataService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.NetworkService
|
import com.zaneschepke.wireguardautotunnel.service.network.NetworkService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.WifiService
|
import com.zaneschepke.wireguardautotunnel.service.network.WifiService
|
||||||
@@ -11,6 +12,7 @@ import dagger.Module
|
|||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.android.components.ServiceComponent
|
import dagger.hilt.android.components.ServiceComponent
|
||||||
import dagger.hilt.android.scopes.ServiceScoped
|
import dagger.hilt.android.scopes.ServiceScoped
|
||||||
|
import dagger.hilt.android.scopes.ViewModelScoped
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@InstallIn(ServiceComponent::class)
|
@InstallIn(ServiceComponent::class)
|
||||||
@@ -27,8 +29,4 @@ abstract class ServiceModule {
|
|||||||
@Binds
|
@Binds
|
||||||
@ServiceScoped
|
@ServiceScoped
|
||||||
abstract fun provideMobileDataService(mobileDataService : MobileDataService) : NetworkService<MobileDataService>
|
abstract fun provideMobileDataService(mobileDataService : MobileDataService) : NetworkService<MobileDataService>
|
||||||
|
|
||||||
@Binds
|
|
||||||
@ServiceScoped
|
|
||||||
abstract fun provideEthernetService(ethernetService: EthernetService) : NetworkService<EthernetService>
|
|
||||||
}
|
}
|
||||||
@@ -3,11 +3,16 @@ package com.zaneschepke.wireguardautotunnel.receiver
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceTracker
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardConnectivityWatcherService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
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.SupervisorJob
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -16,17 +21,22 @@ import javax.inject.Inject
|
|||||||
class BootReceiver : BroadcastReceiver() {
|
class BootReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var settingsRepo : SettingsDoa
|
lateinit var settingsRepo : Repository<Settings>
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
|
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(SupervisorJob()).launch {
|
||||||
try {
|
try {
|
||||||
val settings = settingsRepo.getAll()
|
val settings = settingsRepo.getAll()
|
||||||
if (settings.isNotEmpty()) {
|
if (!settings.isNullOrEmpty()) {
|
||||||
val setting = settings.first()
|
val setting = settings.first()
|
||||||
if (setting.isAutoTunnelEnabled && setting.defaultTunnel != null) {
|
if (setting.isAutoTunnelEnabled && setting.defaultTunnel != null) {
|
||||||
ServiceManager.startWatcherService(context, setting.defaultTunnel!!)
|
ServiceTracker.actionOnService(
|
||||||
|
Action.START, context,
|
||||||
|
WireGuardConnectivityWatcherService::class.java,
|
||||||
|
mapOf(context.resources.getString(R.string.tunnel_extras_key) to
|
||||||
|
setting.defaultTunnel!!)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -3,12 +3,15 @@ package com.zaneschepke.wireguardautotunnel.receiver
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.zaneschepke.wireguardautotunnel.Constants
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceTracker
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
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.SupervisorJob
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -18,17 +21,31 @@ import javax.inject.Inject
|
|||||||
class NotificationActionReceiver : BroadcastReceiver() {
|
class NotificationActionReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var settingsRepo : SettingsDoa
|
lateinit var settingsRepo : Repository<Settings>
|
||||||
override fun onReceive(context: Context, intent: Intent?) {
|
override fun onReceive(context: Context, intent: Intent?) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(SupervisorJob()).launch {
|
||||||
try {
|
try {
|
||||||
val settings = settingsRepo.getAll()
|
val settings = settingsRepo.getAll()
|
||||||
if (settings.isNotEmpty()) {
|
if (!settings.isNullOrEmpty()) {
|
||||||
val setting = settings.first()
|
val setting = settings.first()
|
||||||
if (setting.defaultTunnel != null) {
|
if (setting.defaultTunnel != null) {
|
||||||
ServiceManager.stopVpnService(context)
|
ServiceTracker.actionOnService(
|
||||||
delay(Constants.TOGGLE_TUNNEL_DELAY)
|
Action.STOP, context,
|
||||||
ServiceManager.startVpnService(context, setting.defaultTunnel.toString())
|
WireGuardTunnelService::class.java,
|
||||||
|
mapOf(
|
||||||
|
context.resources.getString(R.string.tunnel_extras_key) to
|
||||||
|
setting.defaultTunnel!!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
delay(1000)
|
||||||
|
ServiceTracker.actionOnService(
|
||||||
|
Action.START, context,
|
||||||
|
WireGuardTunnelService::class.java,
|
||||||
|
mapOf(
|
||||||
|
context.resources.getString(R.string.tunnel_extras_key) to
|
||||||
|
setting.defaultTunnel!!
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.repository
|
|
||||||
|
|
||||||
import androidx.room.Database
|
|
||||||
import androidx.room.RoomDatabase
|
|
||||||
import androidx.room.TypeConverters
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.Settings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
|
|
||||||
@Database(entities = [Settings::class, TunnelConfig::class], version = 1, exportSchema = false)
|
|
||||||
@TypeConverters(DatabaseListConverters::class)
|
|
||||||
abstract class AppDatabase : RoomDatabase() {
|
|
||||||
abstract fun settingDao(): SettingsDoa
|
|
||||||
abstract fun tunnelConfigDoa() : TunnelConfigDao
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.repository
|
|
||||||
|
|
||||||
import androidx.room.TypeConverter
|
|
||||||
|
|
||||||
class DatabaseListConverters {
|
|
||||||
@TypeConverter
|
|
||||||
fun listToString(value: MutableList<String>): String {
|
|
||||||
return value.joinToString()
|
|
||||||
}
|
|
||||||
@TypeConverter
|
|
||||||
fun <T> stringToList(value: String): MutableList<String> {
|
|
||||||
if(value.isEmpty()) return mutableListOf()
|
|
||||||
return value.split(",").toMutableList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.repository
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface Repository<T> {
|
||||||
|
suspend fun save(t : T)
|
||||||
|
suspend fun saveAll(t : List<T>)
|
||||||
|
suspend fun getById(id : Long) : T?
|
||||||
|
suspend fun getAll() : List<T>?
|
||||||
|
suspend fun delete(t : T) : Boolean?
|
||||||
|
suspend fun count() : Long?
|
||||||
|
|
||||||
|
val itemFlow : Flow<MutableList<T>>
|
||||||
|
|
||||||
|
fun init()
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.repository
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
|
import io.objectbox.Box
|
||||||
|
import io.objectbox.BoxStore
|
||||||
|
import io.objectbox.kotlin.awaitCallInTx
|
||||||
|
import io.objectbox.kotlin.toFlow
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsBox @Inject constructor(private val box : Box<Settings>, private val boxStore : BoxStore) : Repository<Settings> {
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
|
override val itemFlow = box.query().build().subscribe().toFlow()
|
||||||
|
|
||||||
|
override fun init() {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
if(getAll().isNullOrEmpty()) {
|
||||||
|
save(Settings())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun save(t : Settings) {
|
||||||
|
boxStore.awaitCallInTx {
|
||||||
|
box.put(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun saveAll(t : List<Settings>) {
|
||||||
|
boxStore.awaitCallInTx {
|
||||||
|
box.put(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getById(id: Long): Settings? {
|
||||||
|
return boxStore.awaitCallInTx {
|
||||||
|
box[id]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getAll(): List<Settings>? {
|
||||||
|
return boxStore.awaitCallInTx {
|
||||||
|
box.all
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun delete(t : Settings): Boolean? {
|
||||||
|
return boxStore.awaitCallInTx {
|
||||||
|
box.remove(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun count() : Long? {
|
||||||
|
return boxStore.awaitCallInTx {
|
||||||
|
box.count()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.repository
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Delete
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.Settings
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface SettingsDoa {
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun save(t: Settings)
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun saveAll(t: List<Settings>)
|
|
||||||
|
|
||||||
@Query("SELECT * FROM settings WHERE id=:id")
|
|
||||||
suspend fun getById(id: Long): Settings?
|
|
||||||
|
|
||||||
@Query("SELECT * FROM settings")
|
|
||||||
suspend fun getAll(): List<Settings>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM settings")
|
|
||||||
fun getAllFlow(): Flow<MutableList<Settings>>
|
|
||||||
|
|
||||||
@Delete
|
|
||||||
suspend fun delete(t: Settings)
|
|
||||||
|
|
||||||
@Query("SELECT COUNT('id') FROM settings")
|
|
||||||
suspend fun count(): Long
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.repository
|
||||||
|
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
|
import io.objectbox.Box
|
||||||
|
import io.objectbox.BoxStore
|
||||||
|
import io.objectbox.kotlin.awaitCallInTx
|
||||||
|
import io.objectbox.kotlin.toFlow
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class TunnelBox @Inject constructor(private val box : Box<TunnelConfig>,private val boxStore : BoxStore) : Repository<TunnelConfig> {
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
|
override val itemFlow = box.query().build().subscribe().toFlow()
|
||||||
|
override fun init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun save(t : TunnelConfig) {
|
||||||
|
Timber.d("Saving tunnel config")
|
||||||
|
boxStore.awaitCallInTx {
|
||||||
|
box.put(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun saveAll(t : List<TunnelConfig>) {
|
||||||
|
boxStore.awaitCallInTx {
|
||||||
|
box.put(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getById(id: Long): TunnelConfig? {
|
||||||
|
return boxStore.awaitCallInTx {
|
||||||
|
box[id]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getAll(): List<TunnelConfig>? {
|
||||||
|
return boxStore.awaitCallInTx {
|
||||||
|
box.all
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun delete(t : TunnelConfig): Boolean? {
|
||||||
|
return boxStore.awaitCallInTx {
|
||||||
|
box.remove(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun count() : Long? {
|
||||||
|
return boxStore.awaitCallInTx {
|
||||||
|
box.count()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.repository
|
|
||||||
|
|
||||||
import androidx.room.Dao
|
|
||||||
import androidx.room.Delete
|
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
interface TunnelConfigDao{
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun save(t: TunnelConfig)
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
suspend fun saveAll(t: List<TunnelConfig>)
|
|
||||||
|
|
||||||
@Query("SELECT * FROM TunnelConfig WHERE id=:id")
|
|
||||||
suspend fun getById(id: Long): TunnelConfig?
|
|
||||||
|
|
||||||
@Query("SELECT * FROM TunnelConfig")
|
|
||||||
suspend fun getAll(): List<TunnelConfig>
|
|
||||||
|
|
||||||
@Delete
|
|
||||||
suspend fun delete(t: TunnelConfig)
|
|
||||||
|
|
||||||
@Query("SELECT COUNT('id') FROM TunnelConfig")
|
|
||||||
suspend fun count(): Long
|
|
||||||
|
|
||||||
@Query("SELECT * FROM tunnelconfig")
|
|
||||||
fun getAllFlow(): Flow<MutableList<TunnelConfig>>
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.repository.model
|
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
data class Settings(
|
|
||||||
@PrimaryKey(autoGenerate = true) val id : Int = 0,
|
|
||||||
@ColumnInfo(name = "is_tunnel_enabled") var isAutoTunnelEnabled : Boolean = false,
|
|
||||||
@ColumnInfo(name = "is_tunnel_on_mobile_data_enabled") var isTunnelOnMobileDataEnabled : Boolean = false,
|
|
||||||
@ColumnInfo(name = "trusted_network_ssids") var trustedNetworkSSIDs : MutableList<String> = mutableListOf(),
|
|
||||||
@ColumnInfo(name = "default_tunnel") var defaultTunnel : String? = null,
|
|
||||||
@ColumnInfo(name = "is_always_on_vpn_enabled") var isAlwaysOnVpnEnabled : Boolean = false,
|
|
||||||
@ColumnInfo(name = "is_tunnel_on_ethernet_enabled") var isTunnelOnEthernetEnabled : Boolean = false,
|
|
||||||
)
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.service.barcode
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface CodeScanner {
|
||||||
|
fun scan() : Flow<String?>
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.service.barcode
|
||||||
|
|
||||||
|
import com.google.mlkit.vision.codescanner.GmsBarcodeScanner
|
||||||
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.callbackFlow
|
||||||
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class QRScanner @Inject constructor(private val gmsBarcodeScanner: GmsBarcodeScanner) : CodeScanner {
|
||||||
|
override fun scan(): Flow<String?> {
|
||||||
|
return callbackFlow {
|
||||||
|
gmsBarcodeScanner.startScan().addOnSuccessListener {
|
||||||
|
trySend(it.rawValue)
|
||||||
|
}.addOnFailureListener {
|
||||||
|
trySend(it.message)
|
||||||
|
Timber.e(it.message)
|
||||||
|
}
|
||||||
|
awaitClose {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,5 @@ package com.zaneschepke.wireguardautotunnel.service.foreground
|
|||||||
|
|
||||||
enum class Action {
|
enum class Action {
|
||||||
START,
|
START,
|
||||||
START_FOREGROUND,
|
|
||||||
STOP
|
STOP
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,10 @@ import android.app.Service
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
open class ForegroundService : Service() {
|
open class ForegroundService : Service() {
|
||||||
@@ -22,7 +25,7 @@ open class ForegroundService : Service() {
|
|||||||
val action = intent.action
|
val action = intent.action
|
||||||
Timber.d("using an intent with action $action")
|
Timber.d("using an intent with action $action")
|
||||||
when (action) {
|
when (action) {
|
||||||
Action.START.name, Action.START_FOREGROUND.name -> startService(intent.extras)
|
Action.START.name -> startService(intent.extras)
|
||||||
Action.STOP.name -> stopService(intent.extras)
|
Action.STOP.name -> stopService(intent.extras)
|
||||||
"android.net.VpnService" -> {
|
"android.net.VpnService" -> {
|
||||||
Timber.d("Always-on VPN starting service")
|
Timber.d("Always-on VPN starting service")
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.foreground
|
|
||||||
|
|
||||||
import android.app.ActivityManager
|
|
||||||
import android.app.Service
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Context.ACTIVITY_SERVICE
|
|
||||||
import android.content.Intent
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
object ServiceManager {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
private // Deprecated for third party Services.
|
|
||||||
fun <T> Context.isServiceRunning(service: Class<T>) =
|
|
||||||
(getSystemService(ACTIVITY_SERVICE) as ActivityManager)
|
|
||||||
.getRunningServices(Integer.MAX_VALUE)
|
|
||||||
.any { it.service.className == service.name }
|
|
||||||
|
|
||||||
fun <T : Service> getServiceState(context: Context, cls : Class<T>): ServiceState {
|
|
||||||
val isServiceRunning = context.isServiceRunning(cls)
|
|
||||||
return if(isServiceRunning) ServiceState.STARTED else ServiceState.STOPPED
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun <T : Service> actionOnService(action: Action, context: Context, cls : Class<T>, extras : Map<String,String>? = null) {
|
|
||||||
if (getServiceState(context, cls) == ServiceState.STOPPED && action == Action.STOP) return
|
|
||||||
if (getServiceState(context, cls) == ServiceState.STARTED && action == Action.START) return
|
|
||||||
val intent = Intent(context, cls).also {
|
|
||||||
it.action = action.name
|
|
||||||
extras?.forEach {(k, v) ->
|
|
||||||
it.putExtra(k, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
intent.component?.javaClass
|
|
||||||
try {
|
|
||||||
when(action) {
|
|
||||||
Action.START_FOREGROUND -> {
|
|
||||||
context.startForegroundService(intent)
|
|
||||||
}
|
|
||||||
Action.START -> {
|
|
||||||
context.startService(intent)
|
|
||||||
}
|
|
||||||
Action.STOP -> context.startService(intent)
|
|
||||||
}
|
|
||||||
} catch (e : Exception) {
|
|
||||||
Timber.e(e.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun startVpnService(context : Context, tunnelConfig : String) {
|
|
||||||
actionOnService(
|
|
||||||
Action.START,
|
|
||||||
context,
|
|
||||||
WireGuardTunnelService::class.java,
|
|
||||||
mapOf(context.getString(R.string.tunnel_extras_key) to tunnelConfig))
|
|
||||||
}
|
|
||||||
fun stopVpnService(context : Context) {
|
|
||||||
actionOnService(
|
|
||||||
Action.STOP,
|
|
||||||
context,
|
|
||||||
WireGuardTunnelService::class.java
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun startVpnServiceForeground(context : Context, tunnelConfig : String) {
|
|
||||||
actionOnService(
|
|
||||||
Action.START_FOREGROUND,
|
|
||||||
context,
|
|
||||||
WireGuardTunnelService::class.java,
|
|
||||||
mapOf(context.getString(R.string.tunnel_extras_key) to tunnelConfig))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startWatcherServiceForeground(context : Context, tunnelConfig : String) {
|
|
||||||
actionOnService(
|
|
||||||
Action.START, context,
|
|
||||||
WireGuardConnectivityWatcherService::class.java, mapOf(context.
|
|
||||||
getString(R.string.tunnel_extras_key) to
|
|
||||||
tunnelConfig))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun startWatcherService(context : Context, tunnelConfig : String) {
|
|
||||||
actionOnService(
|
|
||||||
Action.START, context,
|
|
||||||
WireGuardConnectivityWatcherService::class.java, mapOf(context.
|
|
||||||
getString(R.string.tunnel_extras_key) to
|
|
||||||
tunnelConfig))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun stopWatcherService(context : Context) {
|
|
||||||
actionOnService(
|
|
||||||
Action.STOP, context,
|
|
||||||
WireGuardConnectivityWatcherService::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toggleWatcherService(context: Context, tunnelConfig : String) {
|
|
||||||
when(getServiceState( context,
|
|
||||||
WireGuardConnectivityWatcherService::class.java,)) {
|
|
||||||
ServiceState.STARTED -> stopWatcherService(context)
|
|
||||||
ServiceState.STOPPED -> startWatcherService(context, tunnelConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toggleWatcherServiceForeground(context: Context, tunnelConfig : String) {
|
|
||||||
when(getServiceState( context,
|
|
||||||
WireGuardConnectivityWatcherService::class.java,)) {
|
|
||||||
ServiceState.STARTED -> stopWatcherService(context)
|
|
||||||
ServiceState.STOPPED -> startWatcherServiceForeground(context, tunnelConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.service.foreground
|
||||||
|
|
||||||
|
import android.app.ActivityManager
|
||||||
|
import android.app.Application
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Context.ACTIVITY_SERVICE
|
||||||
|
import android.content.Intent
|
||||||
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
|
import com.google.firebase.ktx.Firebase
|
||||||
|
|
||||||
|
object ServiceTracker {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
private // Deprecated for third party Services.
|
||||||
|
fun <T> Context.isServiceRunning(service: Class<T>) =
|
||||||
|
(getSystemService(ACTIVITY_SERVICE) as ActivityManager)
|
||||||
|
.getRunningServices(Integer.MAX_VALUE)
|
||||||
|
.any { it.service.className == service.name }
|
||||||
|
|
||||||
|
fun <T : Service> getServiceState(context: Context, cls : Class<T>): ServiceState {
|
||||||
|
val isServiceRunning = context.isServiceRunning(cls)
|
||||||
|
return if(isServiceRunning) ServiceState.STARTED else ServiceState.STOPPED
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : Service> actionOnService(action: Action, application: Application, cls : Class<T>, extras : Map<String,String>? = null) {
|
||||||
|
if (getServiceState(application, cls) == ServiceState.STOPPED && action == Action.STOP) return
|
||||||
|
val intent = Intent(application, cls).also {
|
||||||
|
it.action = action.name
|
||||||
|
extras?.forEach {(k, v) ->
|
||||||
|
it.putExtra(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
intent.component?.javaClass
|
||||||
|
try {
|
||||||
|
application.startService(intent)
|
||||||
|
} catch (e : Exception) {
|
||||||
|
e.message?.let { Firebase.crashlytics.log(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : Service> actionOnService(action: Action, context: Context, cls : Class<T>, extras : Map<String,String>? = null) {
|
||||||
|
if (getServiceState(context, cls) == ServiceState.STOPPED && action == Action.STOP) return
|
||||||
|
val intent = Intent(context, cls).also {
|
||||||
|
it.action = action.name
|
||||||
|
extras?.forEach {(k, v) ->
|
||||||
|
it.putExtra(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
intent.component?.javaClass
|
||||||
|
try {
|
||||||
|
context.startService(intent)
|
||||||
|
} catch (e : Exception) {
|
||||||
|
e.message?.let { Firebase.crashlytics.log(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.foreground
|
package com.zaneschepke.wireguardautotunnel.service.foreground
|
||||||
|
|
||||||
import android.app.AlarmManager
|
import android.app.AlarmManager
|
||||||
|
import android.app.Application
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@@ -8,22 +9,19 @@ import android.os.Bundle
|
|||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.Constants
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.Settings
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.EthernetService
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.MobileDataService
|
import com.zaneschepke.wireguardautotunnel.service.network.MobileDataService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.NetworkService
|
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.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
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.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -40,10 +38,7 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
lateinit var mobileDataService : NetworkService<MobileDataService>
|
lateinit var mobileDataService : NetworkService<MobileDataService>
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var ethernetService: NetworkService<EthernetService>
|
lateinit var settingsRepo: Repository<Settings>
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var settingsRepo: SettingsDoa
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var notificationService : NotificationService
|
lateinit var notificationService : NotificationService
|
||||||
@@ -51,37 +46,30 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var vpnService : VpnService
|
lateinit var vpnService : VpnService
|
||||||
|
|
||||||
private var isWifiConnected = false;
|
|
||||||
private var isEthernetConnected = false;
|
|
||||||
private var isMobileDataConnected = false;
|
|
||||||
private var currentNetworkSSID = "";
|
|
||||||
|
|
||||||
private lateinit var watcherJob : Job;
|
private lateinit var watcherJob : Job;
|
||||||
private lateinit var setting : Settings
|
private lateinit var setting : Settings
|
||||||
private lateinit var tunnelConfig: String
|
private lateinit var tunnelId: String
|
||||||
|
|
||||||
|
private var connecting = false
|
||||||
|
private var disconnecting = false
|
||||||
|
private var isWifiConnected = false
|
||||||
|
private var isMobileDataConnected = false
|
||||||
|
|
||||||
private var wakeLock: PowerManager.WakeLock? = null
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
private val tag = this.javaClass.name;
|
private val tag = this.javaClass.name;
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate() {
|
|
||||||
super.onCreate()
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
|
||||||
launchWatcherNotification()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun startService(extras: Bundle?) {
|
override fun startService(extras: Bundle?) {
|
||||||
super.startService(extras)
|
super.startService(extras)
|
||||||
launchWatcherNotification()
|
|
||||||
val tunnelId = extras?.getString(getString(R.string.tunnel_extras_key))
|
val tunnelId = extras?.getString(getString(R.string.tunnel_extras_key))
|
||||||
if (tunnelId != null) {
|
if (tunnelId != null) {
|
||||||
this.tunnelConfig = tunnelId
|
this.tunnelId = tunnelId
|
||||||
}
|
}
|
||||||
// we need this lock so our service gets not affected by Doze Mode
|
// we need this lock so our service gets not affected by Doze Mode
|
||||||
initWakeLock()
|
initWakeLock()
|
||||||
cancelWatcherJob()
|
cancelWatcherJob()
|
||||||
if(this::tunnelConfig.isInitialized) {
|
launchWatcherNotification()
|
||||||
|
if(this::tunnelId.isInitialized) {
|
||||||
startWatcherJob()
|
startWatcherJob()
|
||||||
} else {
|
} else {
|
||||||
stopService(extras)
|
stopService(extras)
|
||||||
@@ -96,6 +84,7 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cancelWatcherJob()
|
cancelWatcherJob()
|
||||||
|
stopVPN()
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,27 +123,19 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startWatcherJob() {
|
private fun startWatcherJob() {
|
||||||
watcherJob = CoroutineScope(Dispatchers.IO).launch {
|
watcherJob = CoroutineScope(SupervisorJob()).launch {
|
||||||
val settings = settingsRepo.getAll();
|
val settings = settingsRepo.getAll();
|
||||||
if(settings.isNotEmpty()) {
|
if(!settings.isNullOrEmpty()) {
|
||||||
setting = settings[0]
|
setting = settings[0]
|
||||||
}
|
}
|
||||||
launch {
|
CoroutineScope(watcherJob).launch {
|
||||||
watchForWifiConnectivityChanges()
|
watchForWifiConnectivityChanges()
|
||||||
}
|
}
|
||||||
if(setting.isTunnelOnMobileDataEnabled) {
|
if(setting.isTunnelOnMobileDataEnabled) {
|
||||||
launch {
|
CoroutineScope(watcherJob).launch {
|
||||||
watchForMobileDataConnectivityChanges()
|
watchForMobileDataConnectivityChanges()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(setting.isTunnelOnEthernetEnabled) {
|
|
||||||
launch {
|
|
||||||
watchForEthernetConnectivityChanges()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
launch {
|
|
||||||
manageVpn()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,34 +149,23 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
is NetworkStatus.CapabilitiesChanged -> {
|
is NetworkStatus.CapabilitiesChanged -> {
|
||||||
isMobileDataConnected = true
|
isMobileDataConnected = true
|
||||||
Timber.d("Mobile data capabilities changed")
|
Timber.d("Mobile data capabilities changed")
|
||||||
|
if(!disconnecting && !connecting) {
|
||||||
|
if(!isWifiConnected && setting.isTunnelOnMobileDataEnabled
|
||||||
|
&& vpnService.getState() == Tunnel.State.DOWN)
|
||||||
|
startVPN()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
is NetworkStatus.Unavailable -> {
|
is NetworkStatus.Unavailable -> {
|
||||||
isMobileDataConnected = false
|
isMobileDataConnected = false
|
||||||
|
if(!disconnecting && !connecting) {
|
||||||
|
if(!isWifiConnected && vpnService.getState() == Tunnel.State.UP) stopVPN()
|
||||||
|
}
|
||||||
Timber.d("Lost mobile data connection")
|
Timber.d("Lost mobile data connection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun watchForEthernetConnectivityChanges() {
|
|
||||||
ethernetService.networkStatus.collect {
|
|
||||||
when (it) {
|
|
||||||
is NetworkStatus.Available -> {
|
|
||||||
Timber.d("Gained Ethernet connection")
|
|
||||||
isEthernetConnected = true
|
|
||||||
}
|
|
||||||
is NetworkStatus.CapabilitiesChanged -> {
|
|
||||||
Timber.d("Ethernet capabilities changed")
|
|
||||||
isEthernetConnected = true
|
|
||||||
}
|
|
||||||
is NetworkStatus.Unavailable -> {
|
|
||||||
isEthernetConnected = false
|
|
||||||
Timber.d("Lost Ethernet connection")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun watchForWifiConnectivityChanges() {
|
private suspend fun watchForWifiConnectivityChanges() {
|
||||||
wifiService.networkStatus.collect {
|
wifiService.networkStatus.collect {
|
||||||
when (it) {
|
when (it) {
|
||||||
@@ -206,40 +176,61 @@ class WireGuardConnectivityWatcherService : ForegroundService() {
|
|||||||
is NetworkStatus.CapabilitiesChanged -> {
|
is NetworkStatus.CapabilitiesChanged -> {
|
||||||
Timber.d("Wifi capabilities changed")
|
Timber.d("Wifi capabilities changed")
|
||||||
isWifiConnected = true
|
isWifiConnected = true
|
||||||
currentNetworkSSID = wifiService.getNetworkName(it.networkCapabilities) ?: "";
|
if (!connecting && !disconnecting) {
|
||||||
|
Timber.d("Not connect and not disconnecting")
|
||||||
|
val ssid = wifiService.getNetworkName(it.networkCapabilities);
|
||||||
|
Timber.d("SSID: $ssid")
|
||||||
|
if (!setting.trustedNetworkSSIDs.contains(ssid) && vpnService.getState() == Tunnel.State.DOWN) {
|
||||||
|
Timber.d("Starting VPN Tunnel for untrusted network: $ssid")
|
||||||
|
startVPN()
|
||||||
|
} else if (!disconnecting && vpnService.getState() == Tunnel.State.UP && setting.trustedNetworkSSIDs.contains(
|
||||||
|
ssid
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Timber.d("Stopping VPN Tunnel for trusted network with ssid: $ssid")
|
||||||
|
stopVPN()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
is NetworkStatus.Unavailable -> {
|
is NetworkStatus.Unavailable -> {
|
||||||
isWifiConnected = false
|
isWifiConnected = false
|
||||||
Timber.d("Lost Wi-Fi connection")
|
Timber.d("Lost Wi-Fi connection")
|
||||||
|
if(!connecting || !disconnecting) {
|
||||||
|
if(setting.isTunnelOnMobileDataEnabled && vpnService.getState() == Tunnel.State.DOWN
|
||||||
|
&& isMobileDataConnected){
|
||||||
|
Timber.d("Wifi not available so starting vpn for mobile data")
|
||||||
|
startVPN()
|
||||||
|
}
|
||||||
|
if(!setting.isTunnelOnMobileDataEnabled && vpnService.getState() == Tunnel.State.UP) {
|
||||||
|
Timber.d("Lost WiFi connection, disabling vpn")
|
||||||
|
stopVPN()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private fun startVPN() {
|
||||||
private suspend fun manageVpn() {
|
if(!connecting) {
|
||||||
while(true) {
|
connecting = true
|
||||||
if(isEthernetConnected && setting.isTunnelOnEthernetEnabled && vpnService.getState() == Tunnel.State.DOWN) {
|
ServiceTracker.actionOnService(
|
||||||
ServiceManager.startVpnService(this, tunnelConfig)
|
Action.START,
|
||||||
}
|
this.applicationContext as Application,
|
||||||
if(!isEthernetConnected && setting.isTunnelOnMobileDataEnabled &&
|
WireGuardTunnelService::class.java,
|
||||||
!isWifiConnected &&
|
mapOf(getString(R.string.tunnel_extras_key) to tunnelId))
|
||||||
isMobileDataConnected
|
connecting = false
|
||||||
&& vpnService.getState() == Tunnel.State.DOWN) {
|
}
|
||||||
ServiceManager.startVpnService(this, tunnelConfig)
|
}
|
||||||
} else if(!isEthernetConnected && !setting.isTunnelOnMobileDataEnabled &&
|
private fun stopVPN() {
|
||||||
!isWifiConnected &&
|
if(!disconnecting) {
|
||||||
vpnService.getState() == Tunnel.State.UP) {
|
disconnecting = true
|
||||||
ServiceManager.stopVpnService(this)
|
ServiceTracker.actionOnService(
|
||||||
} else if(!isEthernetConnected && isWifiConnected &&
|
Action.STOP,
|
||||||
!setting.trustedNetworkSSIDs.contains(currentNetworkSSID) &&
|
this.applicationContext as Application,
|
||||||
(vpnService.getState() != Tunnel.State.UP)) {
|
WireGuardTunnelService::class.java
|
||||||
ServiceManager.startVpnService(this, tunnelConfig)
|
)
|
||||||
} else if(!isEthernetConnected && (isWifiConnected &&
|
disconnecting = false
|
||||||
setting.trustedNetworkSSIDs.contains(currentNetworkSSID)) &&
|
|
||||||
(vpnService.getState() == Tunnel.State.UP)) {
|
|
||||||
ServiceManager.stopVpnService(this)
|
|
||||||
}
|
|
||||||
delay(Constants.VPN_CONNECTIVITY_CHECK_INTERVAL)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,15 +5,17 @@ import android.content.Intent
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.receiver.NotificationActionReceiver
|
import com.zaneschepke.wireguardautotunnel.receiver.NotificationActionReceiver
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
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.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
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.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -27,7 +29,7 @@ class WireGuardTunnelService : ForegroundService() {
|
|||||||
lateinit var vpnService : VpnService
|
lateinit var vpnService : VpnService
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var settingsRepo: SettingsDoa
|
lateinit var settingsRepo: Repository<Settings>
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var notificationService : NotificationService
|
lateinit var notificationService : NotificationService
|
||||||
@@ -36,19 +38,11 @@ class WireGuardTunnelService : ForegroundService() {
|
|||||||
|
|
||||||
private var tunnelName : String = ""
|
private var tunnelName : String = ""
|
||||||
|
|
||||||
override fun onCreate() {
|
|
||||||
super.onCreate()
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
|
||||||
launchVpnStartingNotification()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun startService(extras : Bundle?) {
|
override fun startService(extras : Bundle?) {
|
||||||
super.startService(extras)
|
super.startService(extras)
|
||||||
launchVpnStartingNotification()
|
|
||||||
val tunnelConfigString = extras?.getString(getString(R.string.tunnel_extras_key))
|
val tunnelConfigString = extras?.getString(getString(R.string.tunnel_extras_key))
|
||||||
cancelJob()
|
cancelJob()
|
||||||
job = CoroutineScope(Dispatchers.IO).launch {
|
job = CoroutineScope(SupervisorJob()).launch {
|
||||||
if(tunnelConfigString != null) {
|
if(tunnelConfigString != null) {
|
||||||
try {
|
try {
|
||||||
val tunnelConfig = TunnelConfig.from(tunnelConfigString)
|
val tunnelConfig = TunnelConfig.from(tunnelConfigString)
|
||||||
@@ -61,7 +55,7 @@ class WireGuardTunnelService : ForegroundService() {
|
|||||||
} else {
|
} else {
|
||||||
Timber.d("Tunnel config null, starting default tunnel")
|
Timber.d("Tunnel config null, starting default tunnel")
|
||||||
val settings = settingsRepo.getAll();
|
val settings = settingsRepo.getAll();
|
||||||
if(settings.isNotEmpty()) {
|
if(!settings.isNullOrEmpty()) {
|
||||||
val setting = settings[0]
|
val setting = settings[0]
|
||||||
if(setting.defaultTunnel != null && setting.isAlwaysOnVpnEnabled) {
|
if(setting.defaultTunnel != null && setting.isAlwaysOnVpnEnabled) {
|
||||||
val tunnelConfig = TunnelConfig.from(setting.defaultTunnel!!)
|
val tunnelConfig = TunnelConfig.from(setting.defaultTunnel!!)
|
||||||
@@ -105,7 +99,7 @@ class WireGuardTunnelService : ForegroundService() {
|
|||||||
|
|
||||||
override fun stopService(extras : Bundle?) {
|
override fun stopService(extras : Bundle?) {
|
||||||
super.stopService(extras)
|
super.stopService(extras)
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch() {
|
||||||
vpnService.stopTunnel()
|
vpnService.stopTunnel()
|
||||||
}
|
}
|
||||||
cancelJob()
|
cancelJob()
|
||||||
@@ -124,18 +118,6 @@ class WireGuardTunnelService : ForegroundService() {
|
|||||||
super.startForeground(foregroundId, notification)
|
super.startForeground(foregroundId, notification)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchVpnStartingNotification() {
|
|
||||||
val notification = notificationService.createNotification(
|
|
||||||
channelId = getString(R.string.vpn_channel_id),
|
|
||||||
channelName = getString(R.string.vpn_channel_name),
|
|
||||||
title = getString(R.string.vpn_starting),
|
|
||||||
onGoing = false,
|
|
||||||
showTimestamp = true,
|
|
||||||
description = getString(R.string.attempt_connection)
|
|
||||||
)
|
|
||||||
super.startForeground(foregroundId, notification)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun launchVpnConnectionFailedNotification(message : String) {
|
private fun launchVpnConnectionFailedNotification(message : String) {
|
||||||
val notification = notificationService.createNotification(
|
val notification = notificationService.createNotification(
|
||||||
channelId = getString(R.string.vpn_channel_id),
|
channelId = getString(R.string.vpn_channel_id),
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ abstract class BaseNetworkService<T : BaseNetworkService<T>>(val context: Contex
|
|||||||
object : ConnectivityManager.NetworkCallback(
|
object : ConnectivityManager.NetworkCallback(
|
||||||
FLAG_INCLUDE_LOCATION_INFO
|
FLAG_INCLUDE_LOCATION_INFO
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun onAvailable(network: Network) {
|
override fun onAvailable(network: Network) {
|
||||||
trySend(NetworkStatus.Available(network))
|
trySend(NetworkStatus.Available(network))
|
||||||
}
|
}
|
||||||
@@ -44,7 +45,6 @@ abstract class BaseNetworkService<T : BaseNetworkService<T>>(val context: Contex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
object : ConnectivityManager.NetworkCallback() {
|
object : ConnectivityManager.NetworkCallback() {
|
||||||
|
|
||||||
@@ -67,8 +67,6 @@ abstract class BaseNetworkService<T : BaseNetworkService<T>>(val context: Contex
|
|||||||
}
|
}
|
||||||
val request = NetworkRequest.Builder()
|
val request = NetworkRequest.Builder()
|
||||||
.addTransportType(networkCapability)
|
.addTransportType(networkCapability)
|
||||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
|
||||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
|
|
||||||
.build()
|
.build()
|
||||||
connectivityManager.registerNetworkCallback(request, networkStatusCallback)
|
connectivityManager.registerNetworkCallback(request, networkStatusCallback)
|
||||||
|
|
||||||
@@ -79,8 +77,8 @@ abstract class BaseNetworkService<T : BaseNetworkService<T>>(val context: Contex
|
|||||||
|
|
||||||
|
|
||||||
override fun getNetworkName(networkCapabilities: NetworkCapabilities): String? {
|
override fun getNetworkName(networkCapabilities: NetworkCapabilities): String? {
|
||||||
var ssid: String? = getWifiNameFromCapabilities(networkCapabilities)
|
var ssid : String? = getWifiNameFromCapabilities(networkCapabilities)
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
|
if((Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) || (Build.VERSION.SDK_INT == Build.VERSION_CODES.R)) {
|
||||||
val info = wifiManager.connectionInfo
|
val info = wifiManager.connectionInfo
|
||||||
if (info.supplicantState === SupplicantState.COMPLETED) {
|
if (info.supplicantState === SupplicantState.COMPLETED) {
|
||||||
ssid = info.ssid
|
ssid = info.ssid
|
||||||
@@ -91,15 +89,14 @@ abstract class BaseNetworkService<T : BaseNetworkService<T>>(val context: Contex
|
|||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun getWifiNameFromCapabilities(networkCapabilities: NetworkCapabilities): String? {
|
private fun getWifiNameFromCapabilities(networkCapabilities: NetworkCapabilities) : String? {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
val info : WifiInfo
|
||||||
val info: WifiInfo
|
if(networkCapabilities.transportInfo is WifiInfo) {
|
||||||
if (networkCapabilities.transportInfo is WifiInfo) {
|
info = networkCapabilities.transportInfo as WifiInfo
|
||||||
info = networkCapabilities.transportInfo as WifiInfo
|
} else {
|
||||||
return info.ssid
|
return null
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null
|
return info.ssid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.network
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.net.NetworkCapabilities
|
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class EthernetService @Inject constructor(@ApplicationContext context: Context) :
|
|
||||||
BaseNetworkService<EthernetService>(context, NetworkCapabilities.TRANSPORT_ETHERNET) {
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.shortcut
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class ShortcutsActivity : AppCompatActivity() {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var settingsRepo : SettingsDoa
|
|
||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.Main);
|
|
||||||
|
|
||||||
private fun attemptWatcherServiceToggle(tunnelConfig : String) {
|
|
||||||
scope.launch {
|
|
||||||
val settings = settingsRepo.getAll()
|
|
||||||
if (settings.isNotEmpty()) {
|
|
||||||
val setting = settings.first()
|
|
||||||
if(setting.isAutoTunnelEnabled) {
|
|
||||||
ServiceManager.toggleWatcherServiceForeground(this@ShortcutsActivity, tunnelConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
if(intent.getStringExtra(ShortcutsManager.CLASS_NAME_EXTRA_KEY)
|
|
||||||
.equals(WireGuardTunnelService::class.java.name)) {
|
|
||||||
|
|
||||||
intent.getStringExtra(getString(R.string.tunnel_extras_key))?.let {
|
|
||||||
attemptWatcherServiceToggle(it)
|
|
||||||
}
|
|
||||||
when(intent.action){
|
|
||||||
Action.STOP.name -> ServiceManager.stopVpnService(this)
|
|
||||||
Action.START.name -> intent.getStringExtra(getString(R.string.tunnel_extras_key))
|
|
||||||
?.let { ServiceManager.startVpnService(this, it) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.shortcut
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import androidx.core.content.pm.ShortcutInfoCompat
|
|
||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
|
||||||
import androidx.core.graphics.drawable.IconCompat
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
|
|
||||||
object ShortcutsManager {
|
|
||||||
|
|
||||||
private const val SHORT_LABEL_MAX_SIZE = 10;
|
|
||||||
private const val LONG_LABEL_MAX_SIZE = 25;
|
|
||||||
private const val APPEND_ON = " On";
|
|
||||||
private const val APPEND_OFF = " Off"
|
|
||||||
const val CLASS_NAME_EXTRA_KEY = "className"
|
|
||||||
|
|
||||||
private fun createAndPushShortcut(context : Context, intent : Intent, id : String, shortLabel : String,
|
|
||||||
longLabel : String, drawable : Int ) {
|
|
||||||
val shortcut = ShortcutInfoCompat.Builder(context, id)
|
|
||||||
.setShortLabel(shortLabel)
|
|
||||||
.setLongLabel(longLabel)
|
|
||||||
.setIcon(IconCompat.createWithResource(context, drawable))
|
|
||||||
.setIntent(intent)
|
|
||||||
.build()
|
|
||||||
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createTunnelShortcuts(context : Context, tunnelConfig : TunnelConfig) {
|
|
||||||
createAndPushShortcut(context,
|
|
||||||
createTunnelOnIntent(context, mapOf(context.getString(R.string.tunnel_extras_key) to tunnelConfig.toString())),
|
|
||||||
tunnelConfig.id.toString() + APPEND_ON,
|
|
||||||
tunnelConfig.name.take((SHORT_LABEL_MAX_SIZE - APPEND_ON.length)) + APPEND_ON,
|
|
||||||
tunnelConfig.name.take((LONG_LABEL_MAX_SIZE - APPEND_ON.length)) + APPEND_ON,
|
|
||||||
R.drawable.vpn_on
|
|
||||||
)
|
|
||||||
createAndPushShortcut(context,
|
|
||||||
createTunnelOffIntent(context, mapOf(context.getString(R.string.tunnel_extras_key) to tunnelConfig.toString())),
|
|
||||||
tunnelConfig.id.toString() + APPEND_OFF,
|
|
||||||
tunnelConfig.name.take((SHORT_LABEL_MAX_SIZE - APPEND_OFF.length)) + APPEND_OFF,
|
|
||||||
tunnelConfig.name.take((LONG_LABEL_MAX_SIZE - APPEND_OFF.length)) + APPEND_OFF,
|
|
||||||
R.drawable.vpn_off
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeTunnelShortcuts(context : Context, tunnelConfig : TunnelConfig?) {
|
|
||||||
if(tunnelConfig != null) {
|
|
||||||
ShortcutManagerCompat.removeDynamicShortcuts(context, listOf(tunnelConfig.id.toString() + APPEND_ON,
|
|
||||||
tunnelConfig.id.toString() + APPEND_OFF ))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createTunnelOnIntent(context: Context, extras : Map<String,String>) : Intent {
|
|
||||||
return Intent(context, ShortcutsActivity::class.java).also {
|
|
||||||
it.action = Action.START.name
|
|
||||||
it.putExtra(CLASS_NAME_EXTRA_KEY, WireGuardTunnelService::class.java.name)
|
|
||||||
extras.forEach {(k, v) ->
|
|
||||||
it.putExtra(k, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createTunnelOffIntent(context : Context, extras : Map<String,String>) : Intent {
|
|
||||||
return Intent(context, ShortcutsActivity::class.java).also {
|
|
||||||
it.action = Action.STOP.name
|
|
||||||
it.putExtra(CLASS_NAME_EXTRA_KEY, WireGuardTunnelService::class.java.name)
|
|
||||||
extras.forEach {(k, v) ->
|
|
||||||
it.putExtra(k, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.service.tile
|
|
||||||
|
|
||||||
import android.os.Build
|
|
||||||
import android.service.quicksettings.Tile
|
|
||||||
import android.service.quicksettings.TileService
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.cancel
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import timber.log.Timber
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class TunnelControlTile : TileService() {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var settingsRepo : SettingsDoa
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var configRepo : TunnelConfigDao
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
lateinit var vpnService : VpnService
|
|
||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.Main);
|
|
||||||
|
|
||||||
private lateinit var job : Job
|
|
||||||
|
|
||||||
override fun onStartListening() {
|
|
||||||
job = scope.launch {
|
|
||||||
updateTileState()
|
|
||||||
}
|
|
||||||
super.onStartListening()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTileAdded() {
|
|
||||||
super.onTileAdded()
|
|
||||||
qsTile.contentDescription = this.resources.getString(R.string.toggle_vpn)
|
|
||||||
scope.launch {
|
|
||||||
updateTileState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTileRemoved() {
|
|
||||||
super.onTileRemoved()
|
|
||||||
cancelJob()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick() {
|
|
||||||
super.onClick()
|
|
||||||
unlockAndRun {
|
|
||||||
scope.launch {
|
|
||||||
try {
|
|
||||||
val tunnel = determineTileTunnel();
|
|
||||||
if(tunnel != null) {
|
|
||||||
attemptWatcherServiceToggle(tunnel.toString())
|
|
||||||
if(vpnService.getState() == Tunnel.State.UP) {
|
|
||||||
ServiceManager.stopVpnService(this@TunnelControlTile)
|
|
||||||
} else {
|
|
||||||
ServiceManager.startVpnServiceForeground(this@TunnelControlTile, tunnel.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e : Exception) {
|
|
||||||
Timber.e(e.message)
|
|
||||||
} finally {
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun determineTileTunnel() : TunnelConfig? {
|
|
||||||
var tunnelConfig : TunnelConfig? = null;
|
|
||||||
val settings = settingsRepo.getAll()
|
|
||||||
if (settings.isNotEmpty()) {
|
|
||||||
val setting = settings.first()
|
|
||||||
tunnelConfig = if (setting.defaultTunnel != null) {
|
|
||||||
TunnelConfig.from(setting.defaultTunnel!!);
|
|
||||||
} else {
|
|
||||||
val configs = configRepo.getAll();
|
|
||||||
val config = if(configs.isNotEmpty()) {
|
|
||||||
configs.first();
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
config
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tunnelConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun attemptWatcherServiceToggle(tunnelConfig : String) {
|
|
||||||
scope.launch {
|
|
||||||
val settings = settingsRepo.getAll()
|
|
||||||
if (settings.isNotEmpty()) {
|
|
||||||
val setting = settings.first()
|
|
||||||
if(setting.isAutoTunnelEnabled) {
|
|
||||||
ServiceManager.toggleWatcherServiceForeground(this@TunnelControlTile, tunnelConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun updateTileState() {
|
|
||||||
vpnService.state.collect {
|
|
||||||
when(it) {
|
|
||||||
Tunnel.State.UP -> {
|
|
||||||
qsTile.state = Tile.STATE_ACTIVE
|
|
||||||
}
|
|
||||||
Tunnel.State.DOWN -> {
|
|
||||||
qsTile.state = Tile.STATE_INACTIVE;
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
qsTile.state = Tile.STATE_UNAVAILABLE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val config = determineTileTunnel();
|
|
||||||
setTileDescription(config?.name ?: this.resources.getString(R.string.no_tunnel_available))
|
|
||||||
qsTile.updateTile()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setTileDescription(description : String) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
qsTile.subtitle = description
|
|
||||||
}
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
||||||
qsTile.stateDescription = description;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun cancelJob() {
|
|
||||||
if(this::job.isInitialized) {
|
|
||||||
job.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ package com.zaneschepke.wireguardautotunnel.service.tunnel
|
|||||||
import com.wireguard.android.backend.Statistics
|
import com.wireguard.android.backend.Statistics
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.wireguard.crypto.Key
|
import com.wireguard.crypto.Key
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
|
||||||
interface VpnService : Tunnel {
|
interface VpnService : Tunnel {
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import com.wireguard.android.backend.BackendException
|
|||||||
import com.wireguard.android.backend.Statistics
|
import com.wireguard.android.backend.Statistics
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.wireguard.crypto.Key
|
import com.wireguard.crypto.Key
|
||||||
import com.zaneschepke.wireguardautotunnel.Constants
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -30,7 +29,6 @@ class WireGuardTunnel @Inject constructor(private val backend : Backend,
|
|||||||
override val tunnelName get() = _tunnelName.asStateFlow()
|
override val tunnelName get() = _tunnelName.asStateFlow()
|
||||||
|
|
||||||
private val _state = MutableSharedFlow<Tunnel.State>(
|
private val _state = MutableSharedFlow<Tunnel.State>(
|
||||||
onBufferOverflow = BufferOverflow.DROP_OLDEST,
|
|
||||||
replay = 1)
|
replay = 1)
|
||||||
|
|
||||||
private val _handshakeStatus = MutableSharedFlow<HandshakeStatus>(replay = 1,
|
private val _handshakeStatus = MutableSharedFlow<HandshakeStatus>(replay = 1,
|
||||||
@@ -105,7 +103,7 @@ class WireGuardTunnel @Inject constructor(private val backend : Backend,
|
|||||||
_handshakeStatus.emit(HandshakeStatus.NOT_STARTED)
|
_handshakeStatus.emit(HandshakeStatus.NOT_STARTED)
|
||||||
}
|
}
|
||||||
if(neverHadHandshakeCounter <= HandshakeStatus.NEVER_CONNECTED_TO_UNHEALTHY_TIME_LIMIT_SEC) {
|
if(neverHadHandshakeCounter <= HandshakeStatus.NEVER_CONNECTED_TO_UNHEALTHY_TIME_LIMIT_SEC) {
|
||||||
neverHadHandshakeCounter += 10
|
neverHadHandshakeCounter++
|
||||||
}
|
}
|
||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
@@ -116,7 +114,7 @@ class WireGuardTunnel @Inject constructor(private val backend : Backend,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_lastHandshake.emit(handshakeMap)
|
_lastHandshake.emit(handshakeMap)
|
||||||
delay(Constants.VPN_STATISTIC_CHECK_INTERVAL)
|
delay(1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.zaneschepke.wireguardautotunnel.service.tunnel.model
|
||||||
|
|
||||||
|
import io.objectbox.annotation.Entity
|
||||||
|
import io.objectbox.annotation.Id
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
data class Settings(
|
||||||
|
@Id
|
||||||
|
var id : Long = 0,
|
||||||
|
var isAutoTunnelEnabled : Boolean = false,
|
||||||
|
var isTunnelOnMobileDataEnabled : Boolean = false,
|
||||||
|
var trustedNetworkSSIDs : MutableList<String> = mutableListOf(),
|
||||||
|
var defaultTunnel : String? = null,
|
||||||
|
var isAlwaysOnVpnEnabled : Boolean = false
|
||||||
|
)
|
||||||
@@ -1,21 +1,25 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.repository.model
|
package com.zaneschepke.wireguardautotunnel.service.tunnel.model
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.Index
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
import com.wireguard.config.Config
|
import com.wireguard.config.Config
|
||||||
|
import io.objectbox.annotation.ConflictStrategy
|
||||||
|
import io.objectbox.annotation.Entity
|
||||||
|
import io.objectbox.annotation.Id
|
||||||
|
import io.objectbox.annotation.Unique
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
@Entity(indices = [Index(value = ["name"], unique = true)])
|
|
||||||
|
@Entity
|
||||||
@Serializable
|
@Serializable
|
||||||
data class TunnelConfig(
|
data class TunnelConfig(
|
||||||
@PrimaryKey(autoGenerate = true) val id : Int = 0,
|
@Id
|
||||||
@ColumnInfo(name = "name") var name : String,
|
var id : Long = 0,
|
||||||
@ColumnInfo(name = "wg_quick") var wgQuick : String,
|
@Unique(onConflict = ConflictStrategy.REPLACE)
|
||||||
){
|
var name : String,
|
||||||
|
var wgQuick : String
|
||||||
|
) {
|
||||||
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return Json.encodeToString(serializer(), this)
|
return Json.encodeToString(serializer(), this)
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui
|
|
||||||
|
|
||||||
import com.journeyapps.barcodescanner.CaptureActivity
|
|
||||||
|
|
||||||
class CaptureActivityPortrait : CaptureActivity()
|
|
||||||
@@ -6,7 +6,6 @@ import android.net.Uri
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.view.KeyEvent
|
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
@@ -23,9 +22,6 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
|
||||||
import androidx.compose.ui.input.key.onKeyEvent
|
|
||||||
import com.google.accompanist.navigation.animation.AnimatedNavHost
|
import com.google.accompanist.navigation.animation.AnimatedNavHost
|
||||||
import com.google.accompanist.navigation.animation.composable
|
import com.google.accompanist.navigation.animation.composable
|
||||||
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
|
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
|
||||||
@@ -33,7 +29,6 @@ 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.GoBackend
|
import com.wireguard.android.backend.GoBackend
|
||||||
import com.zaneschepke.wireguardautotunnel.Constants
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.PermissionRequestFailedScreen
|
import com.zaneschepke.wireguardautotunnel.ui.common.PermissionRequestFailedScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.BottomNavBar
|
||||||
@@ -44,10 +39,7 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.SettingsScreen
|
|||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.TransparentSystemBars
|
import com.zaneschepke.wireguardautotunnel.ui.theme.TransparentSystemBars
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelException
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import timber.log.Timber
|
|
||||||
import java.lang.IllegalStateException
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
@@ -59,8 +51,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContent {
|
setContent {
|
||||||
val navController = rememberAnimatedNavController()
|
val navController = rememberAnimatedNavController()
|
||||||
val focusRequester = remember { FocusRequester() }
|
|
||||||
|
|
||||||
WireguardAutoTunnelTheme {
|
WireguardAutoTunnelTheme {
|
||||||
TransparentSystemBars()
|
TransparentSystemBars()
|
||||||
|
|
||||||
@@ -90,25 +80,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
} else requestNotificationPermission()
|
} else requestNotificationPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(snackbarHost = { SnackbarHost(snackbarHostState)},
|
Scaffold(snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||||
modifier = Modifier.onKeyEvent {
|
|
||||||
if (it.nativeKeyEvent.action == KeyEvent.ACTION_UP) {
|
|
||||||
when (it.nativeKeyEvent.keyCode) {
|
|
||||||
KeyEvent.KEYCODE_DPAD_UP -> {
|
|
||||||
try {
|
|
||||||
focusRequester.requestFocus()
|
|
||||||
} catch(e : IllegalStateException) {
|
|
||||||
Timber.e("No D-Pad focus request modifier added to element on screen")
|
|
||||||
}
|
|
||||||
false
|
|
||||||
} else -> {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
bottomBar = if (vpnIntent == null && notificationPermissionState.status.isGranted) {
|
bottomBar = if (vpnIntent == null && notificationPermissionState.status.isGranted) {
|
||||||
{ BottomNavBar(navController, Routes.navItems) }
|
{ BottomNavBar(navController, Routes.navItems) }
|
||||||
} else {
|
} else {
|
||||||
@@ -132,8 +104,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val intentSettings =
|
val intentSettings =
|
||||||
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||||
intentSettings.data =
|
intentSettings.data =
|
||||||
Uri.fromParts(Constants.URI_PACKAGE_SCHEME, this.packageName, null)
|
Uri.fromParts("package", this.packageName, null)
|
||||||
startActivity(intentSettings)
|
startActivity(intentSettings);
|
||||||
},
|
},
|
||||||
message = getString(R.string.notification_permission_required),
|
message = getString(R.string.notification_permission_required),
|
||||||
getString(R.string.open_settings)
|
getString(R.string.open_settings)
|
||||||
@@ -145,12 +117,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
when (initialState.destination.route) {
|
when (initialState.destination.route) {
|
||||||
Routes.Settings.name, Routes.Support.name ->
|
Routes.Settings.name, Routes.Support.name ->
|
||||||
slideInHorizontally(
|
slideInHorizontally(
|
||||||
initialOffsetX = { -Constants.SLIDE_IN_TRANSITION_OFFSET },
|
initialOffsetX = { -1000 },
|
||||||
animationSpec = tween(Constants.SLIDE_IN_ANIMATION_DURATION)
|
animationSpec = tween(500)
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
fadeIn(animationSpec = tween(1000))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
@@ -160,50 +132,41 @@ class MainActivity : AppCompatActivity() {
|
|||||||
when (initialState.destination.route) {
|
when (initialState.destination.route) {
|
||||||
Routes.Main.name ->
|
Routes.Main.name ->
|
||||||
slideInHorizontally(
|
slideInHorizontally(
|
||||||
initialOffsetX = { Constants.SLIDE_IN_TRANSITION_OFFSET },
|
initialOffsetX = { 1000 },
|
||||||
animationSpec = tween(Constants.SLIDE_IN_ANIMATION_DURATION)
|
animationSpec = tween(500)
|
||||||
)
|
)
|
||||||
|
|
||||||
Routes.Support.name -> {
|
Routes.Support.name -> {
|
||||||
slideInHorizontally(
|
slideInHorizontally(
|
||||||
initialOffsetX = { -Constants.SLIDE_IN_TRANSITION_OFFSET },
|
initialOffsetX = { -1000 },
|
||||||
animationSpec = tween(Constants.SLIDE_IN_ANIMATION_DURATION)
|
animationSpec = tween(500)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
fadeIn(animationSpec = tween(1000))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) { SettingsScreen(padding = padding, snackbarHostState = snackbarHostState, navController = navController, focusRequester = focusRequester) }
|
}) { SettingsScreen(padding = padding, snackbarHostState = snackbarHostState, navController = navController) }
|
||||||
composable(Routes.Support.name, enterTransition = {
|
composable(Routes.Support.name, enterTransition = {
|
||||||
when (initialState.destination.route) {
|
when (initialState.destination.route) {
|
||||||
Routes.Settings.name, Routes.Main.name ->
|
Routes.Settings.name, Routes.Main.name ->
|
||||||
slideInHorizontally(
|
slideInHorizontally(
|
||||||
initialOffsetX = { Constants.SLIDE_IN_ANIMATION_DURATION },
|
initialOffsetX = { 1000 },
|
||||||
animationSpec = tween(Constants.SLIDE_IN_ANIMATION_DURATION)
|
animationSpec = tween(500)
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
fadeIn(animationSpec = tween(1000))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) { SupportScreen(padding = padding, focusRequester) }
|
}) { SupportScreen(padding = padding) }
|
||||||
composable("${Routes.Config.name}/{id}", enterTransition = {
|
composable("${Routes.Config.name}/{id}", enterTransition = {
|
||||||
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
fadeIn(animationSpec = tween(1000))
|
||||||
}) {
|
}) { ConfigScreen(padding = padding, navController = navController, id = it.arguments?.getString("id"))}
|
||||||
val id = it.arguments?.getString("id")
|
|
||||||
if(!id.isNullOrBlank()) {
|
|
||||||
ConfigScreen(padding = padding, navController = navController, id = id, focusRequester = focusRequester)}
|
|
||||||
}
|
|
||||||
composable("${Routes.Detail.name}/{id}", enterTransition = {
|
composable("${Routes.Detail.name}/{id}", enterTransition = {
|
||||||
fadeIn(animationSpec = tween(Constants.FADE_IN_ANIMATION_DURATION))
|
fadeIn(animationSpec = tween(1000))
|
||||||
}) {
|
}) { DetailScreen(padding = padding, id = it.arguments?.getString("id")) }
|
||||||
val id = it.arguments?.getString("id")
|
|
||||||
if(!id.isNullOrBlank()) {
|
|
||||||
DetailScreen(padding = padding, id = id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.common
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.rounded.Clear
|
|
||||||
import androidx.compose.material.icons.rounded.Search
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.TextField
|
|
||||||
import androidx.compose.material3.TextFieldDefaults
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.graphics.RectangleShape
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SearchBar(
|
|
||||||
onQuery : (queryString : String) -> Unit
|
|
||||||
) {
|
|
||||||
// Immediately update and keep track of query from text field changes.
|
|
||||||
var query: String by rememberSaveable { mutableStateOf("") }
|
|
||||||
var showClearIcon by rememberSaveable { mutableStateOf(false) }
|
|
||||||
|
|
||||||
if (query.isEmpty()) {
|
|
||||||
showClearIcon = false
|
|
||||||
} else if (query.isNotEmpty()) {
|
|
||||||
showClearIcon = true
|
|
||||||
}
|
|
||||||
|
|
||||||
TextField(
|
|
||||||
value = query,
|
|
||||||
onValueChange = { onQueryChanged ->
|
|
||||||
// If user makes changes to text, immediately updated it.
|
|
||||||
query = onQueryChanged
|
|
||||||
onQuery(onQueryChanged)
|
|
||||||
},
|
|
||||||
leadingIcon = {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Rounded.Search,
|
|
||||||
tint = MaterialTheme.colorScheme.onBackground,
|
|
||||||
contentDescription = stringResource(id = R.string.search_icon)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
trailingIcon = {
|
|
||||||
if (showClearIcon) {
|
|
||||||
IconButton(onClick = { query = "" }) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Rounded.Clear,
|
|
||||||
tint = MaterialTheme.colorScheme.onBackground,
|
|
||||||
contentDescription = stringResource(id = R.string.clear_icon)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
maxLines = 1,
|
|
||||||
colors = TextFieldDefaults.colors(
|
|
||||||
focusedContainerColor = Color.Transparent,
|
|
||||||
unfocusedContainerColor = Color.Transparent,
|
|
||||||
disabledContainerColor = Color.Transparent,
|
|
||||||
),
|
|
||||||
placeholder = { Text(text = stringResource(R.string.hint_search_packages)) },
|
|
||||||
textStyle = MaterialTheme.typography.bodySmall,
|
|
||||||
singleLine = true,
|
|
||||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(color = MaterialTheme.colorScheme.background, shape = RectangleShape)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -24,13 +24,10 @@ import androidx.compose.material3.Text
|
|||||||
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
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
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.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalFocusManager
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
@@ -44,7 +41,6 @@ import androidx.navigation.NavController
|
|||||||
import com.google.accompanist.drawablepainter.DrawablePainter
|
import com.google.accompanist.drawablepainter.DrawablePainter
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Routes
|
import com.zaneschepke.wireguardautotunnel.ui.Routes
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.SearchBar
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@OptIn(ExperimentalComposeUiApi::class)
|
@OptIn(ExperimentalComposeUiApi::class)
|
||||||
@@ -52,14 +48,12 @@ import kotlinx.coroutines.launch
|
|||||||
fun ConfigScreen(
|
fun ConfigScreen(
|
||||||
viewModel: ConfigViewModel = hiltViewModel(),
|
viewModel: ConfigViewModel = hiltViewModel(),
|
||||||
padding: PaddingValues,
|
padding: PaddingValues,
|
||||||
focusRequester: FocusRequester,
|
|
||||||
navController: NavController,
|
navController: NavController,
|
||||||
id : String
|
id : String?
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
|
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val tunnel by viewModel.tunnel.collectAsStateWithLifecycle(null)
|
val tunnel by viewModel.tunnel.collectAsStateWithLifecycle(null)
|
||||||
@@ -68,12 +62,11 @@ fun ConfigScreen(
|
|||||||
val checkedPackages by viewModel.checkedPackages.collectAsStateWithLifecycle()
|
val checkedPackages by viewModel.checkedPackages.collectAsStateWithLifecycle()
|
||||||
val include by viewModel.include.collectAsStateWithLifecycle()
|
val include by viewModel.include.collectAsStateWithLifecycle()
|
||||||
val allApplications by viewModel.allApplications.collectAsStateWithLifecycle()
|
val allApplications by viewModel.allApplications.collectAsStateWithLifecycle()
|
||||||
val sortedPackages = remember(packages) {
|
|
||||||
packages.sortedBy { viewModel.getPackageLabel(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
viewModel.emitScreenData(id)
|
viewModel.getTunnelById(id)
|
||||||
|
viewModel.emitAllInternetCapablePackages()
|
||||||
|
viewModel.emitCurrentPackageConfigurations(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tunnel != null) {
|
if(tunnel != null) {
|
||||||
@@ -93,7 +86,6 @@ fun ConfigScreen(
|
|||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
modifier = Modifier.focusRequester(focusRequester),
|
|
||||||
value = tunnelName.value,
|
value = tunnelName.value,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
viewModel.onTunnelNameChange(it)
|
viewModel.onTunnelNameChange(it)
|
||||||
@@ -166,17 +158,15 @@ fun ConfigScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item {
|
// LazyColumn(
|
||||||
Row(
|
// modifier = Modifier
|
||||||
modifier = Modifier
|
// .fillMaxWidth()
|
||||||
.fillMaxWidth()
|
// .fillMaxHeight(.75f)
|
||||||
.padding(horizontal = 20.dp, vertical = 7.dp),
|
// .padding(horizontal = 14.dp, vertical = 7.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
// verticalArrangement = Arrangement.Center,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween) {
|
// horizontalAlignment = Alignment.Start
|
||||||
SearchBar(viewModel::emitQueriedPackages);
|
// ) {
|
||||||
}
|
items(packages) { pack ->
|
||||||
}
|
|
||||||
items(sortedPackages, key = { it.packageName }) { pack ->
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
@@ -202,7 +192,8 @@ fun ConfigScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
viewModel.getPackageLabel(pack), modifier = Modifier.padding(5.dp)
|
pack.applicationInfo.loadLabel(context.packageManager)
|
||||||
|
.toString(), modifier = Modifier.padding(5.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Checkbox(
|
Checkbox(
|
||||||
|
|||||||
@@ -8,25 +8,19 @@ import android.os.Build
|
|||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.toMutableStateList
|
import androidx.compose.runtime.toMutableStateList
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
import com.wireguard.config.Config
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.shortcut.ShortcutsManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelException
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
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.launch
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class ConfigViewModel @Inject constructor(private val application : Application,
|
class ConfigViewModel @Inject constructor(private val application : Application,
|
||||||
private val tunnelRepo : TunnelConfigDao,
|
private val tunnelRepo : Repository<TunnelConfig>,
|
||||||
private val settingsRepo : SettingsDoa) : ViewModel() {
|
private val settingsRepo : Repository<Settings>) : ViewModel() {
|
||||||
|
|
||||||
private val _tunnel = MutableStateFlow<TunnelConfig?>(null)
|
private val _tunnel = MutableStateFlow<TunnelConfig?>(null)
|
||||||
private val _tunnelName = MutableStateFlow("")
|
private val _tunnelName = MutableStateFlow("")
|
||||||
@@ -44,37 +38,24 @@ class ConfigViewModel @Inject constructor(private val application : Application,
|
|||||||
private val _allApplications = MutableStateFlow(true)
|
private val _allApplications = MutableStateFlow(true)
|
||||||
val allApplications get() = _allApplications.asStateFlow()
|
val allApplications get() = _allApplications.asStateFlow()
|
||||||
|
|
||||||
fun emitScreenData(id : String) {
|
suspend fun getTunnelById(id : String?) : TunnelConfig? {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
val tunnelConfig = getTunnelConfigById(id);
|
|
||||||
emitTunnelConfig(tunnelConfig);
|
|
||||||
emitTunnelConfigName(tunnelConfig?.name)
|
|
||||||
emitQueriedPackages("")
|
|
||||||
emitCurrentPackageConfigurations(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun getTunnelConfigById(id : String) : TunnelConfig? {
|
|
||||||
return try {
|
return try {
|
||||||
tunnelRepo.getById(id.toLong())
|
if(id != null) {
|
||||||
|
val config = tunnelRepo.getById(id.toLong())
|
||||||
|
if (config != null) {
|
||||||
|
_tunnel.emit(config)
|
||||||
|
_tunnelName.emit(config.name)
|
||||||
|
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
return null
|
||||||
} catch (e : Exception) {
|
} catch (e : Exception) {
|
||||||
Timber.e(e.message)
|
Timber.e(e.message)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun emitTunnelConfig(tunnelConfig: TunnelConfig?) {
|
|
||||||
if(tunnelConfig != null) {
|
|
||||||
_tunnel.emit(tunnelConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun emitTunnelConfigName(name : String?) {
|
|
||||||
if(name != null) {
|
|
||||||
_tunnelName.emit(name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onTunnelNameChange(name : String) {
|
fun onTunnelNameChange(name : String) {
|
||||||
_tunnelName.value = name
|
_tunnelName.value = name
|
||||||
}
|
}
|
||||||
@@ -94,71 +75,31 @@ class ConfigViewModel @Inject constructor(private val application : Application,
|
|||||||
_checkedPackages.value.remove(packageName)
|
_checkedPackages.value.remove(packageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun emitSplitTunnelConfiguration(config : Config) {
|
suspend fun emitCurrentPackageConfigurations(id : String?) {
|
||||||
val excludedApps = config.`interface`.excludedApplications
|
val tunnelConfig = getTunnelById(id)
|
||||||
val includedApps = config.`interface`.includedApplications
|
if(tunnelConfig != null) {
|
||||||
if (excludedApps.isNotEmpty() || includedApps.isNotEmpty()) {
|
val config = TunnelConfig.configFromQuick(tunnelConfig.wgQuick)
|
||||||
emitTunnelAllApplicationsDisabled()
|
val excludedApps = config.`interface`.excludedApplications
|
||||||
determineAppInclusionState(excludedApps, includedApps)
|
val includedApps = config.`interface`.includedApplications
|
||||||
} else {
|
if(excludedApps.isNullOrEmpty() && includedApps.isNullOrEmpty()) {
|
||||||
emitTunnelAllApplicationsEnabled()
|
_allApplications.emit(true)
|
||||||
}
|
return
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun determineAppInclusionState(excludedApps : Set<String>, includedApps : Set<String>) {
|
|
||||||
if (excludedApps.isEmpty()) {
|
|
||||||
emitIncludedAppsExist()
|
|
||||||
emitCheckedApps(includedApps)
|
|
||||||
} else {
|
|
||||||
emitExcludedAppsExist()
|
|
||||||
emitCheckedApps(excludedApps)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun emitIncludedAppsExist() {
|
|
||||||
_include.emit(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun emitExcludedAppsExist() {
|
|
||||||
_include.emit(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun emitCheckedApps(apps : Set<String>) {
|
|
||||||
_checkedPackages.emit(apps.toMutableStateList())
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun emitTunnelAllApplicationsEnabled() {
|
|
||||||
_allApplications.emit(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun emitTunnelAllApplicationsDisabled() {
|
|
||||||
_allApplications.emit(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun emitCurrentPackageConfigurations(id : String) {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
val tunnelConfig = getTunnelConfigById(id)
|
|
||||||
if (tunnelConfig != null) {
|
|
||||||
val config = TunnelConfig.configFromQuick(tunnelConfig.wgQuick)
|
|
||||||
emitSplitTunnelConfiguration(config)
|
|
||||||
}
|
}
|
||||||
}
|
if(excludedApps.isEmpty()) {
|
||||||
}
|
_include.emit(true)
|
||||||
|
_checkedPackages.emit(includedApps.toMutableStateList())
|
||||||
fun emitQueriedPackages(query : String) {
|
} else {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
_include.emit(false)
|
||||||
val packages = getAllInternetCapablePackages().filter {
|
_checkedPackages.emit(excludedApps.toMutableStateList())
|
||||||
getPackageLabel(it).lowercase().contains(query.lowercase())
|
|
||||||
}
|
}
|
||||||
_packages.emit(packages)
|
_allApplications.emit(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPackageLabel(packageInfo : PackageInfo) : String {
|
suspend fun emitAllInternetCapablePackages() {
|
||||||
return packageInfo.applicationInfo.loadLabel(application.packageManager).toString()
|
_packages.emit(getAllInternetCapablePackages())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getAllInternetCapablePackages() : List<PackageInfo> {
|
private fun getAllInternetCapablePackages() : List<PackageInfo> {
|
||||||
return getPackagesHoldingPermissions(arrayOf(Manifest.permission.INTERNET))
|
return getPackagesHoldingPermissions(arrayOf(Manifest.permission.INTERNET))
|
||||||
}
|
}
|
||||||
@@ -167,81 +108,39 @@ class ConfigViewModel @Inject constructor(private val application : Application,
|
|||||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
packageManager.getPackagesHoldingPermissions(permissions, PackageManager.PackageInfoFlags.of(0L))
|
packageManager.getPackagesHoldingPermissions(permissions, PackageManager.PackageInfoFlags.of(0L))
|
||||||
} else {
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
packageManager.getPackagesHoldingPermissions(permissions, 0)
|
packageManager.getPackagesHoldingPermissions(permissions, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeTunnelShortcuts(tunnelConfig: TunnelConfig?) {
|
suspend fun onSaveAllChanges() {
|
||||||
if(tunnelConfig != null) {
|
|
||||||
ShortcutsManager.removeTunnelShortcuts(application, tunnelConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isAllApplicationsEnabled() : Boolean {
|
|
||||||
return _allApplications.value
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isIncludeApplicationsEnabled() : Boolean {
|
|
||||||
return _include.value
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateQuickStringWithSelectedPackages() : String {
|
|
||||||
var wgQuick = _tunnel.value?.wgQuick
|
var wgQuick = _tunnel.value?.wgQuick
|
||||||
if(wgQuick != null) {
|
if(wgQuick != null) {
|
||||||
wgQuick = if(isAllApplicationsEnabled()) {
|
wgQuick = if(_include.value) {
|
||||||
TunnelConfig.clearAllApplicationsFromConfig(wgQuick)
|
|
||||||
} else if(isIncludeApplicationsEnabled()) {
|
|
||||||
TunnelConfig.setIncludedApplicationsOnQuick(_checkedPackages.value, wgQuick)
|
TunnelConfig.setIncludedApplicationsOnQuick(_checkedPackages.value, wgQuick)
|
||||||
} else {
|
} else {
|
||||||
TunnelConfig.setExcludedApplicationsOnQuick(_checkedPackages.value, wgQuick)
|
TunnelConfig.setExcludedApplicationsOnQuick(_checkedPackages.value, wgQuick)
|
||||||
}
|
}
|
||||||
} else {
|
if(_allApplications.value) {
|
||||||
throw WgTunnelException("Wg quick string is null")
|
wgQuick = TunnelConfig.clearAllApplicationsFromConfig(wgQuick)
|
||||||
}
|
}
|
||||||
return wgQuick;
|
_tunnel.value?.copy(
|
||||||
}
|
name = _tunnelName.value,
|
||||||
|
wgQuick = wgQuick
|
||||||
private suspend fun saveConfig(tunnelConfig: TunnelConfig) {
|
)?.let {
|
||||||
tunnelRepo.save(tunnelConfig)
|
tunnelRepo.save(it)
|
||||||
}
|
val settings = settingsRepo.getAll()
|
||||||
private suspend fun updateTunnelConfig(tunnelConfig: TunnelConfig?) {
|
if(settings != null) {
|
||||||
if(tunnelConfig != null) {
|
val setting = settings[0]
|
||||||
saveConfig(tunnelConfig)
|
if(setting.defaultTunnel != null) {
|
||||||
addTunnelShortcuts(tunnelConfig)
|
if(it.id == TunnelConfig.from(setting.defaultTunnel!!).id) {
|
||||||
updateSettingsDefaultTunnel(tunnelConfig)
|
settingsRepo.save(setting.copy(
|
||||||
}
|
defaultTunnel = it.toString()
|
||||||
}
|
))
|
||||||
|
}
|
||||||
private suspend fun updateSettingsDefaultTunnel(tunnelConfig: TunnelConfig) {
|
}
|
||||||
val settings = settingsRepo.getAll()
|
|
||||||
if(settings.isNotEmpty()) {
|
|
||||||
val setting = settings[0]
|
|
||||||
if(setting.defaultTunnel != null) {
|
|
||||||
if(tunnelConfig.id == TunnelConfig.from(setting.defaultTunnel!!).id) {
|
|
||||||
settingsRepo.save(setting.copy(
|
|
||||||
defaultTunnel = tunnelConfig.toString()
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addTunnelShortcuts(tunnelConfig: TunnelConfig) {
|
|
||||||
ShortcutsManager.createTunnelShortcuts(application, tunnelConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun onSaveAllChanges() {
|
|
||||||
try {
|
|
||||||
removeTunnelShortcuts(_tunnel.value)
|
|
||||||
val wgQuick = updateQuickStringWithSelectedPackages()
|
|
||||||
val tunnelConfig = _tunnel.value?.copy(
|
|
||||||
name = _tunnelName.value,
|
|
||||||
wgQuick = wgQuick
|
|
||||||
)
|
|
||||||
updateTunnelConfig(tunnelConfig)
|
|
||||||
} catch (e : Exception) {
|
|
||||||
Timber.e(e.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ import java.time.Instant
|
|||||||
fun DetailScreen(
|
fun DetailScreen(
|
||||||
viewModel: DetailViewModel = hiltViewModel(),
|
viewModel: DetailViewModel = hiltViewModel(),
|
||||||
padding: PaddingValues,
|
padding: PaddingValues,
|
||||||
id : String
|
id : String?
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
||||||
@@ -47,17 +47,15 @@ fun DetailScreen(
|
|||||||
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
viewModel.emitConfig(id)
|
viewModel.getTunnelById(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(null != tunnel) {
|
if(tunnel != null) {
|
||||||
val interfaceKey = tunnel?.`interface`?.keyPair?.publicKey?.toBase64().toString()
|
val interfaceKey = tunnel?.`interface`?.keyPair?.publicKey?.toBase64().toString()
|
||||||
val addresses = tunnel?.`interface`?.addresses!!.joinToString()
|
val addresses = tunnel?.`interface`?.addresses!!.joinToString()
|
||||||
val dnsServers = tunnel?.`interface`?.dnsServers!!.joinToString()
|
val dnsServers = tunnel?.`interface`?.dnsServers!!.joinToString()
|
||||||
val optionalMtu = tunnel?.`interface`?.mtu
|
val optionalMtu = tunnel?.`interface`?.mtu
|
||||||
val mtu = if(optionalMtu?.isPresent == true) optionalMtu.get().toString() else stringResource(
|
val mtu = if(optionalMtu?.isPresent == true) optionalMtu.get().toString() else "None"
|
||||||
id = R.string.none
|
|
||||||
)
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.Start,
|
||||||
verticalArrangement = Arrangement.Top,
|
verticalArrangement = Arrangement.Top,
|
||||||
@@ -99,9 +97,7 @@ fun DetailScreen(
|
|||||||
tunnel?.peers?.forEach{
|
tunnel?.peers?.forEach{
|
||||||
val peerKey = it.publicKey.toBase64().toString()
|
val peerKey = it.publicKey.toBase64().toString()
|
||||||
val allowedIps = it.allowedIps.joinToString()
|
val allowedIps = it.allowedIps.joinToString()
|
||||||
val endpoint = if(it.endpoint.isPresent) it.endpoint.get().toString() else stringResource(
|
val endpoint = if(it.endpoint.isPresent) it.endpoint.get().toString() else "None"
|
||||||
id = R.string.none
|
|
||||||
)
|
|
||||||
Text(stringResource(R.string.peer), fontWeight = FontWeight.Bold, fontSize = 20.sp)
|
Text(stringResource(R.string.peer), fontWeight = FontWeight.Bold, fontSize = 20.sp)
|
||||||
Text(stringResource(R.string.public_key), fontStyle = FontStyle.Italic)
|
Text(stringResource(R.string.public_key), fontStyle = FontStyle.Italic)
|
||||||
Text(text = peerKey, modifier = Modifier.clickable {
|
Text(text = peerKey, modifier = Modifier.clickable {
|
||||||
@@ -127,7 +123,7 @@ fun DetailScreen(
|
|||||||
val handshakeEpoch = lastHandshake[it.publicKey]
|
val handshakeEpoch = lastHandshake[it.publicKey]
|
||||||
if(handshakeEpoch != null) {
|
if(handshakeEpoch != null) {
|
||||||
if(handshakeEpoch == 0L) {
|
if(handshakeEpoch == 0L) {
|
||||||
Text(stringResource(id = R.string.never))
|
Text("Never")
|
||||||
} else {
|
} else {
|
||||||
val time = Instant.ofEpochMilli(handshakeEpoch)
|
val time = Instant.ofEpochMilli(handshakeEpoch)
|
||||||
Text("${Duration.between(time, Instant.now()).seconds} seconds ago")
|
Text("${Duration.between(time, Instant.now()).seconds} seconds ago")
|
||||||
|
|||||||
@@ -1,45 +1,45 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.detail
|
package com.zaneschepke.wireguardautotunnel.ui.screens.detail
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import com.wireguard.config.Config
|
import com.wireguard.config.Config
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
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.launch
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class DetailViewModel @Inject constructor(private val tunnelRepo : TunnelConfigDao, private val vpnService : VpnService
|
class DetailViewModel @Inject constructor(private val tunnelRepo : Repository<TunnelConfig>, private val vpnService : VpnService
|
||||||
|
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _tunnel = MutableStateFlow<Config?>(null)
|
private val _tunnel = MutableStateFlow<Config?>(null)
|
||||||
val tunnel get() = _tunnel.asStateFlow()
|
val tunnel get() = _tunnel.asStateFlow()
|
||||||
|
|
||||||
private val _tunnelName = MutableStateFlow("")
|
private val _tunnelName = MutableStateFlow<String>("")
|
||||||
val tunnelName = _tunnelName.asStateFlow()
|
val tunnelName = _tunnelName.asStateFlow()
|
||||||
val tunnelStats get() = vpnService.statistics
|
val tunnelStats get() = vpnService.statistics
|
||||||
val lastHandshake get() = vpnService.lastHandshake
|
val lastHandshake get() = vpnService.lastHandshake
|
||||||
|
|
||||||
private suspend fun getTunnelConfigById(id: String): TunnelConfig? {
|
private var config : TunnelConfig? = null
|
||||||
|
|
||||||
|
suspend fun getTunnelById(id : String?) : TunnelConfig? {
|
||||||
return try {
|
return try {
|
||||||
tunnelRepo.getById(id.toLong())
|
if(id != null) {
|
||||||
} catch (e: Exception) {
|
config = tunnelRepo.getById(id.toLong())
|
||||||
|
if (config != null) {
|
||||||
|
_tunnel.emit(TunnelConfig.configFromQuick(config!!.wgQuick))
|
||||||
|
_tunnelName.emit(config!!.name)
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
} catch (e : Exception) {
|
||||||
Timber.e(e.message)
|
Timber.e(e.message)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun emitConfig(id: String) {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
val tunnelConfig = getTunnelConfigById(id)
|
|
||||||
if(tunnelConfig != null) {
|
|
||||||
_tunnel.emit(TunnelConfig.configFromQuick(tunnelConfig.wgQuick))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.slideInVertically
|
import androidx.compose.animation.slideInVertically
|
||||||
import androidx.compose.animation.slideOutVertically
|
import androidx.compose.animation.slideOutVertically
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.focusable
|
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -27,7 +25,6 @@ import androidx.compose.material.icons.rounded.Add
|
|||||||
import androidx.compose.material.icons.rounded.Circle
|
import androidx.compose.material.icons.rounded.Circle
|
||||||
import androidx.compose.material.icons.rounded.Delete
|
import androidx.compose.material.icons.rounded.Delete
|
||||||
import androidx.compose.material.icons.rounded.Edit
|
import androidx.compose.material.icons.rounded.Edit
|
||||||
import androidx.compose.material.icons.rounded.Info
|
|
||||||
import androidx.compose.material3.Divider
|
import androidx.compose.material3.Divider
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.FabPosition
|
import androidx.compose.material3.FabPosition
|
||||||
@@ -53,8 +50,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
|
||||||
import androidx.compose.ui.focus.focusRequester
|
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
@@ -70,15 +65,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.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.journeyapps.barcodescanner.ScanContract
|
|
||||||
import com.journeyapps.barcodescanner.ScanOptions
|
|
||||||
import com.wireguard.android.backend.Tunnel
|
import com.wireguard.android.backend.Tunnel
|
||||||
import com.zaneschepke.wireguardautotunnel.Constants
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.HandshakeStatus
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.CaptureActivityPortrait
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Routes
|
import com.zaneschepke.wireguardautotunnel.ui.Routes
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.RowListItem
|
import com.zaneschepke.wireguardautotunnel.ui.common.RowListItem
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.brickRed
|
import com.zaneschepke.wireguardautotunnel.ui.theme.brickRed
|
||||||
@@ -107,7 +97,6 @@ fun MainScreen(
|
|||||||
val state by viewModel.state.collectAsStateWithLifecycle(Tunnel.State.DOWN)
|
val state by viewModel.state.collectAsStateWithLifecycle(Tunnel.State.DOWN)
|
||||||
val tunnelName by viewModel.tunnelName.collectAsStateWithLifecycle("")
|
val tunnelName by viewModel.tunnelName.collectAsStateWithLifecycle("")
|
||||||
|
|
||||||
|
|
||||||
// Nested scroll for control FAB
|
// Nested scroll for control FAB
|
||||||
val nestedScrollConnection = remember {
|
val nestedScrollConnection = remember {
|
||||||
object : NestedScrollConnection {
|
object : NestedScrollConnection {
|
||||||
@@ -140,21 +129,12 @@ fun MainScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val pickFileLauncher = rememberLauncherForActivityResult(
|
val pickFileLauncher = rememberLauncherForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.GetContent()
|
||||||
) { result ->
|
) { file ->
|
||||||
result.data?.data?.let { viewModel.onTunnelFileSelected(it) }
|
if (file != null) {
|
||||||
}
|
viewModel.onTunnelFileSelected(file)
|
||||||
|
|
||||||
val scanLauncher = rememberLauncherForActivityResult(
|
|
||||||
contract = ScanContract(),
|
|
||||||
onResult = {
|
|
||||||
try {
|
|
||||||
viewModel.onTunnelQrResult(it.contents)
|
|
||||||
} catch (e : Exception) {
|
|
||||||
viewModel.showSnackBarMessage(context.getString(R.string.qr_result_failed))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier.pointerInput(Unit) {
|
modifier = Modifier.pointerInput(Unit) {
|
||||||
@@ -163,7 +143,7 @@ fun MainScreen(
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
floatingActionButtonPosition = FabPosition.End,
|
floatingActionButtonPosition = FabPosition.End,
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = isVisible.value,
|
visible = isVisible.value,
|
||||||
enter = slideInVertically(initialOffsetY = { it * 2 }),
|
enter = slideInVertically(initialOffsetY = { it * 2 }),
|
||||||
@@ -210,11 +190,7 @@ fun MainScreen(
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable {
|
.clickable {
|
||||||
showBottomSheet = false
|
showBottomSheet = false
|
||||||
val fileSelectionIntent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
pickFileLauncher.launch("*/*")
|
||||||
addCategory(Intent.CATEGORY_OPENABLE)
|
|
||||||
type = Constants.ALLOWED_FILE_TYPES
|
|
||||||
}
|
|
||||||
pickFileLauncher.launch(fileSelectionIntent)
|
|
||||||
}
|
}
|
||||||
.padding(10.dp)
|
.padding(10.dp)
|
||||||
) {
|
) {
|
||||||
@@ -234,13 +210,7 @@ fun MainScreen(
|
|||||||
.clickable {
|
.clickable {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
showBottomSheet = false
|
showBottomSheet = false
|
||||||
val scanOptions = ScanOptions()
|
viewModel.onTunnelQRSelected()
|
||||||
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)
|
||||||
@@ -265,20 +235,16 @@ fun MainScreen(
|
|||||||
.padding(padding)
|
.padding(padding)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(modifier = Modifier.fillMaxSize()
|
||||||
modifier = Modifier
|
.nestedScroll(nestedScrollConnection),) {
|
||||||
.fillMaxSize()
|
items(tunnels.toList()) { tunnel ->
|
||||||
.nestedScroll(nestedScrollConnection),
|
|
||||||
) {
|
|
||||||
items(tunnels, key = { tunnel -> tunnel.id }) {tunnel ->
|
|
||||||
val focusRequester = FocusRequester()
|
|
||||||
RowListItem(leadingIcon = Icons.Rounded.Circle,
|
RowListItem(leadingIcon = Icons.Rounded.Circle,
|
||||||
leadingIconColor = if (tunnelName == tunnel.name) when (handshakeStatus) {
|
leadingIconColor = when (handshakeStatus) {
|
||||||
HandshakeStatus.HEALTHY -> mint
|
HandshakeStatus.HEALTHY -> mint
|
||||||
HandshakeStatus.UNHEALTHY -> brickRed
|
HandshakeStatus.UNHEALTHY -> brickRed
|
||||||
HandshakeStatus.NOT_STARTED -> Color.Gray
|
HandshakeStatus.NOT_STARTED -> Color.Gray
|
||||||
HandshakeStatus.NEVER_CONNECTED -> brickRed
|
HandshakeStatus.NEVER_CONNECTED -> brickRed
|
||||||
} else Color.Gray,
|
},
|
||||||
text = tunnel.name,
|
text = tunnel.name,
|
||||||
onHold = {
|
onHold = {
|
||||||
if (state == Tunnel.State.UP && tunnel.name == tunnelName) {
|
if (state == Tunnel.State.UP && tunnel.name == tunnelName) {
|
||||||
@@ -288,26 +254,18 @@ fun MainScreen(
|
|||||||
return@RowListItem
|
return@RowListItem
|
||||||
}
|
}
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
selectedTunnel = tunnel
|
selectedTunnel = tunnel;
|
||||||
},
|
|
||||||
onClick = {
|
|
||||||
if (!WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
|
||||||
navController.navigate("${Routes.Detail.name}/${tunnel.id}")
|
|
||||||
} else {
|
|
||||||
focusRequester.requestFocus()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
onClick = { navController.navigate("${Routes.Detail.name}/${tunnel.id}") },
|
||||||
rowButton = {
|
rowButton = {
|
||||||
if (tunnel.id == selectedTunnel?.id) {
|
if (tunnel.id == selectedTunnel?.id) {
|
||||||
Row {
|
Row() {
|
||||||
IconButton(onClick = {
|
IconButton(onClick = {
|
||||||
navController.navigate("${Routes.Config.name}/${selectedTunnel?.id}")
|
navController.navigate("${Routes.Config.name}/${selectedTunnel?.id}")
|
||||||
}) {
|
}) {
|
||||||
Icon(Icons.Rounded.Edit, stringResource(id = R.string.edit))
|
Icon(Icons.Rounded.Edit, stringResource(id = R.string.edit))
|
||||||
}
|
}
|
||||||
IconButton(
|
IconButton(onClick = { viewModel.onDelete(tunnel) }) {
|
||||||
modifier = Modifier.focusable(),
|
|
||||||
onClick = { viewModel.onDelete(tunnel) }) {
|
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Rounded.Delete,
|
Icons.Rounded.Delete,
|
||||||
stringResource(id = R.string.delete)
|
stringResource(id = R.string.delete)
|
||||||
@@ -315,64 +273,12 @@ fun MainScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (WireGuardAutoTunnel.isRunningOnAndroidTv(context)) {
|
Switch(
|
||||||
Row {
|
checked = (state == Tunnel.State.UP && tunnel.name == tunnelName),
|
||||||
IconButton(
|
onCheckedChange = { checked ->
|
||||||
modifier = Modifier.focusRequester(focusRequester),
|
if (checked) viewModel.onTunnelStart(tunnel) else viewModel.onTunnelStop()
|
||||||
onClick = {
|
|
||||||
navController.navigate("${Routes.Detail.name}/${tunnel.id}")
|
|
||||||
}) {
|
|
||||||
Icon(Icons.Rounded.Info, "Info")
|
|
||||||
}
|
|
||||||
IconButton(onClick = {
|
|
||||||
if (state == Tunnel.State.UP && tunnel.name == tunnelName)
|
|
||||||
scope.launch {
|
|
||||||
viewModel.showSnackBarMessage(
|
|
||||||
context.resources.getString(
|
|
||||||
R.string.turn_off_tunnel
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
navController.navigate("${Routes.Config.name}/${tunnel.id}")
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
Icon(
|
|
||||||
Icons.Rounded.Edit,
|
|
||||||
stringResource(id = R.string.edit)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
IconButton(onClick = {
|
|
||||||
if (state == Tunnel.State.UP && tunnel.name == tunnelName)
|
|
||||||
scope.launch {
|
|
||||||
viewModel.showSnackBarMessage(
|
|
||||||
context.resources.getString(
|
|
||||||
R.string.turn_off_tunnel
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
viewModel.onDelete(tunnel)
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
Icon(
|
|
||||||
Icons.Rounded.Delete,
|
|
||||||
stringResource(id = R.string.delete)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Switch(
|
|
||||||
checked = (state == Tunnel.State.UP && tunnel.name == tunnelName),
|
|
||||||
onCheckedChange = { checked ->
|
|
||||||
if (checked) viewModel.onTunnelStart(tunnel) else viewModel.onTunnelStop()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else {
|
)
|
||||||
Switch(
|
|
||||||
checked = (state == Tunnel.State.UP && tunnel.name == tunnelName),
|
|
||||||
onCheckedChange = { checked ->
|
|
||||||
if (checked) viewModel.onTunnelStart(tunnel) else viewModel.onTunnelStop()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,46 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
package com.zaneschepke.wireguardautotunnel.ui.screens.main
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
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.BadConfigException
|
import com.wireguard.config.BadConfigException
|
||||||
import com.wireguard.config.Config
|
import com.wireguard.config.Config
|
||||||
import com.zaneschepke.wireguardautotunnel.Constants
|
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.service.barcode.CodeScanner
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.Settings
|
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceState
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceState
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceTracker
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardConnectivityWatcherService
|
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardConnectivityWatcherService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService
|
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.shortcut.ShortcutsManager
|
|
||||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.VpnService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.ViewState
|
import com.zaneschepke.wireguardautotunnel.ui.ViewState
|
||||||
import com.zaneschepke.wireguardautotunnel.util.NumberUtils
|
|
||||||
import com.zaneschepke.wireguardautotunnel.util.WgTunnelException
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.filter
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.io.InputStream
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class MainViewModel @Inject constructor(private val application : Application,
|
class MainViewModel @Inject constructor(private val application : Application,
|
||||||
private val tunnelRepo : TunnelConfigDao,
|
private val tunnelRepo : Repository<TunnelConfig>,
|
||||||
private val settingsRepo : SettingsDoa,
|
private val settingsRepo : Repository<Settings>,
|
||||||
private val vpnService: VpnService
|
private val vpnService: VpnService,
|
||||||
|
private val codeScanner: CodeScanner
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _viewState = MutableStateFlow(ViewState())
|
private val _viewState = MutableStateFlow(ViewState())
|
||||||
val viewState get() = _viewState.asStateFlow()
|
val viewState get() = _viewState.asStateFlow()
|
||||||
val tunnels get() = tunnelRepo.getAllFlow()
|
val tunnels get() = tunnelRepo.itemFlow
|
||||||
val state get() = vpnService.state
|
val state get() = vpnService.state
|
||||||
|
|
||||||
val handshakeStatus get() = vpnService.handshakeStatus
|
val handshakeStatus get() = vpnService.handshakeStatus
|
||||||
@@ -53,9 +48,14 @@ class MainViewModel @Inject constructor(private val application : Application,
|
|||||||
private val _settings = MutableStateFlow(Settings())
|
private val _settings = MutableStateFlow(Settings())
|
||||||
val settings get() = _settings.asStateFlow()
|
val settings get() = _settings.asStateFlow()
|
||||||
|
|
||||||
|
private val defaultConfigName = {
|
||||||
|
"tunnel${(Math.random() * 100000).toInt()}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch {
|
||||||
settingsRepo.getAllFlow().filter { it.isNotEmpty() }.collect {
|
settingsRepo.itemFlow.collect {
|
||||||
val settings = it.first()
|
val settings = it.first()
|
||||||
validateWatcherServiceState(settings)
|
validateWatcherServiceState(settings)
|
||||||
_settings.emit(settings)
|
_settings.emit(settings)
|
||||||
@@ -64,19 +64,25 @@ class MainViewModel @Inject constructor(private val application : Application,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun validateWatcherServiceState(settings: Settings) {
|
private fun validateWatcherServiceState(settings: Settings) {
|
||||||
val watcherState = ServiceManager.getServiceState(application.applicationContext, WireGuardConnectivityWatcherService::class.java)
|
val watcherState = ServiceTracker.getServiceState(application, WireGuardConnectivityWatcherService::class.java)
|
||||||
if(settings.isAutoTunnelEnabled && watcherState == ServiceState.STOPPED && settings.defaultTunnel != null) {
|
if(settings.isAutoTunnelEnabled && watcherState == ServiceState.STOPPED && settings.defaultTunnel != null) {
|
||||||
ServiceManager.startWatcherService(application.applicationContext, settings.defaultTunnel!!)
|
startWatcherService(settings.defaultTunnel!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun startWatcherService(tunnel : String) {
|
||||||
|
ServiceTracker.actionOnService(
|
||||||
|
Action.START, application,
|
||||||
|
WireGuardConnectivityWatcherService::class.java,
|
||||||
|
mapOf(application.resources.getString(R.string.tunnel_extras_key) to tunnel))
|
||||||
|
}
|
||||||
|
|
||||||
fun onDelete(tunnel : TunnelConfig) {
|
fun onDelete(tunnel : TunnelConfig) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
if(tunnelRepo.count() == 1L) {
|
if(tunnelRepo.count() == 1L) {
|
||||||
ServiceManager.stopWatcherService(application.applicationContext)
|
ServiceTracker.actionOnService( Action.STOP, application, WireGuardConnectivityWatcherService::class.java)
|
||||||
val settings = settingsRepo.getAll()
|
val settings = settingsRepo.getAll()
|
||||||
if(settings.isNotEmpty()) {
|
if(!settings.isNullOrEmpty()) {
|
||||||
val setting = settings[0]
|
val setting = settings[0]
|
||||||
setting.defaultTunnel = null
|
setting.defaultTunnel = null
|
||||||
setting.isAutoTunnelEnabled = false
|
setting.isAutoTunnelEnabled = false
|
||||||
@@ -85,170 +91,85 @@ class MainViewModel @Inject constructor(private val application : Application,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
tunnelRepo.delete(tunnel)
|
tunnelRepo.delete(tunnel)
|
||||||
ShortcutsManager.removeTunnelShortcuts(application.applicationContext, tunnel)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onTunnelStart(tunnelConfig : TunnelConfig) {
|
fun onTunnelStart(tunnelConfig : TunnelConfig) = viewModelScope.launch {
|
||||||
viewModelScope.launch {
|
ServiceTracker.actionOnService( Action.START, application, WireGuardTunnelService::class.java,
|
||||||
stopActiveTunnel()
|
mapOf(application.resources.getString(R.string.tunnel_extras_key) to tunnelConfig.toString()))
|
||||||
startTunnel(tunnelConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startTunnel(tunnelConfig: TunnelConfig) {
|
|
||||||
ServiceManager.startVpnService(application.applicationContext, tunnelConfig.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun stopActiveTunnel() {
|
|
||||||
if(ServiceManager.getServiceState(application.applicationContext,
|
|
||||||
WireGuardTunnelService::class.java, ) == ServiceState.STARTED) {
|
|
||||||
onTunnelStop()
|
|
||||||
delay(Constants.TOGGLE_TUNNEL_DELAY)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onTunnelStop() {
|
fun onTunnelStop() {
|
||||||
ServiceManager.stopVpnService(application.applicationContext)
|
ServiceTracker.actionOnService( Action.STOP, application, WireGuardTunnelService::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateConfigString(config : String) {
|
suspend fun onTunnelQRSelected() {
|
||||||
if(!config.contains(application.getString(R.string.config_validation))) {
|
codeScanner.scan().collect {
|
||||||
throw WgTunnelException(application.getString(R.string.config_validation))
|
if(!it.isNullOrEmpty() && it.contains(application.resources.getString(R.string.config_validation))) {
|
||||||
}
|
tunnelRepo.save(TunnelConfig(name = defaultConfigName(), wgQuick = it))
|
||||||
}
|
} else if(!it.isNullOrEmpty() && it.contains(application.resources.getString(R.string.barcode_downloading))) {
|
||||||
|
showSnackBarMessage(application.resources.getString(R.string.barcode_downloading_message))
|
||||||
fun onTunnelQrResult(result : String) {
|
} else {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
showSnackBarMessage(application.resources.getString(R.string.barcode_error))
|
||||||
try {
|
|
||||||
validateConfigString(result)
|
|
||||||
val tunnelConfig = TunnelConfig(name = NumberUtils.generateRandomTunnelName(), wgQuick = result)
|
|
||||||
addTunnel(tunnelConfig)
|
|
||||||
} catch (e : WgTunnelException) {
|
|
||||||
showSnackBarMessage(e.message ?: application.getString(R.string.unknown_error_message))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateFileExtension(fileName : String) {
|
|
||||||
val extension = getFileExtensionFromFileName(fileName)
|
|
||||||
if(extension != Constants.VALID_FILE_EXTENSION) {
|
|
||||||
throw WgTunnelException(application.getString(R.string.file_extension_message))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun saveTunnelConfigFromStream(stream : InputStream, fileName : String) {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
val bufferReader = stream.bufferedReader(charset = Charsets.UTF_8)
|
|
||||||
val config = Config.parse(bufferReader)
|
|
||||||
val tunnelName = getNameFromFileName(fileName)
|
|
||||||
addTunnel(TunnelConfig(name = tunnelName, wgQuick = config.toWgQuickString()))
|
|
||||||
stream.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getInputStreamFromUri(uri: Uri): InputStream {
|
|
||||||
return application.applicationContext.contentResolver.openInputStream(uri)
|
|
||||||
?: throw WgTunnelException(application.getString(R.string.stream_failed))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onTunnelFileSelected(uri : Uri) {
|
fun onTunnelFileSelected(uri : Uri) {
|
||||||
try {
|
try {
|
||||||
val fileName = getFileName(application.applicationContext, uri)
|
val fileName = getFileName(application.applicationContext, uri)
|
||||||
validateFileExtension(fileName)
|
val extension = getFileExtensionFromFileName(fileName)
|
||||||
val stream = getInputStreamFromUri(uri)
|
if(extension != ".conf") {
|
||||||
saveTunnelConfigFromStream(stream, fileName)
|
viewModelScope.launch {
|
||||||
} catch (e : Exception) {
|
showSnackBarMessage(application.resources.getString(R.string.file_extension_message))
|
||||||
showExceptionMessage(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showExceptionMessage(e : Exception) {
|
|
||||||
when(e) {
|
|
||||||
is BadConfigException -> {
|
|
||||||
showSnackBarMessage(application.getString(R.string.bad_config))
|
|
||||||
}
|
|
||||||
is WgTunnelException -> {
|
|
||||||
showSnackBarMessage(e.message ?: application.getString(R.string.unknown_error_message))
|
|
||||||
}
|
|
||||||
else -> showSnackBarMessage(application.getString(R.string.unknown_error_message))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun addTunnel(tunnelConfig: TunnelConfig) {
|
|
||||||
saveTunnel(tunnelConfig)
|
|
||||||
createTunnelAppShortcuts(tunnelConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun saveTunnel(tunnelConfig : TunnelConfig) {
|
|
||||||
tunnelRepo.save(tunnelConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createTunnelAppShortcuts(tunnelConfig: TunnelConfig) {
|
|
||||||
ShortcutsManager.createTunnelShortcuts(application.applicationContext, tunnelConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getFileNameByCursor(context: Context, uri: Uri) : String {
|
|
||||||
val cursor = context.contentResolver.query(uri, null, null, null, null)
|
|
||||||
if(cursor != null) {
|
|
||||||
cursor.use {
|
|
||||||
return getDisplayNameByCursor(it)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw WgTunnelException("Failed to initialize cursor")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDisplayNameColumnIndex(cursor: Cursor) : Int {
|
|
||||||
val columnIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
|
||||||
if(columnIndex == -1) {
|
|
||||||
throw WgTunnelException("Cursor out of bounds")
|
|
||||||
}
|
|
||||||
return columnIndex
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDisplayNameByCursor(cursor: Cursor) : String {
|
|
||||||
if(cursor.moveToFirst()) {
|
|
||||||
val index = getDisplayNameColumnIndex(cursor)
|
|
||||||
return cursor.getString(index)
|
|
||||||
} else {
|
|
||||||
throw WgTunnelException("Cursor failed to move to first")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun validateUriContentScheme(uri : Uri) {
|
|
||||||
if (uri.scheme != Constants.URI_CONTENT_SCHEME) {
|
|
||||||
throw WgTunnelException(application.getString(R.string.file_extension_message))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun getFileName(context: Context, uri: Uri): String {
|
|
||||||
validateUriContentScheme(uri)
|
|
||||||
return try {
|
|
||||||
getFileNameByCursor(context, uri)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
NumberUtils.generateRandomTunnelName()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun showSnackBarMessage(message : String) {
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
_viewState.emit(_viewState.value.copy(
|
|
||||||
showSnackbarMessage = true,
|
|
||||||
snackbarMessage = message,
|
|
||||||
snackbarActionText = application.getString(R.string.okay),
|
|
||||||
onSnackbarActionClick = {
|
|
||||||
viewModelScope.launch {
|
|
||||||
dismissSnackBar()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
))
|
return
|
||||||
delay(Constants.SNACKBAR_DELAY)
|
}
|
||||||
dismissSnackBar()
|
val stream = application.applicationContext.contentResolver.openInputStream(uri)
|
||||||
|
stream ?: return
|
||||||
|
val bufferReader = stream.bufferedReader(charset = Charsets.UTF_8)
|
||||||
|
val config = Config.parse(bufferReader)
|
||||||
|
val tunnelName = getNameFromFileName(fileName)
|
||||||
|
viewModelScope.launch {
|
||||||
|
tunnelRepo.save(TunnelConfig(name = tunnelName, wgQuick = config.toWgQuickString()))
|
||||||
|
}
|
||||||
|
stream.close()
|
||||||
|
} catch(_: BadConfigException) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
showSnackBarMessage(application.applicationContext.getString(R.string.bad_config))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("Range")
|
||||||
|
private fun getFileName(context: Context, uri: Uri): String {
|
||||||
|
if (uri.scheme == "content") {
|
||||||
|
val cursor = context.contentResolver.query(uri, null, null, null, null)
|
||||||
|
cursor ?: return defaultConfigName()
|
||||||
|
cursor.use {
|
||||||
|
if(cursor.moveToFirst()) {
|
||||||
|
return cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultConfigName()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun showSnackBarMessage(message : String) {
|
||||||
|
_viewState.emit(_viewState.value.copy(
|
||||||
|
showSnackbarMessage = true,
|
||||||
|
snackbarMessage = message,
|
||||||
|
snackbarActionText = "Okay",
|
||||||
|
onSnackbarActionClick = {
|
||||||
|
viewModelScope.launch {
|
||||||
|
dismissSnackBar()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
))
|
||||||
|
delay(3000)
|
||||||
|
dismissSnackBar()
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun dismissSnackBar() {
|
private suspend fun dismissSnackBar() {
|
||||||
_viewState.emit(_viewState.value.copy(
|
_viewState.emit(_viewState.value.copy(
|
||||||
showSnackbarMessage = false
|
showSnackbarMessage = false
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.settings
|
|||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
@@ -13,7 +12,6 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
|||||||
import androidx.compose.foundation.layout.FlowRow
|
import androidx.compose.foundation.layout.FlowRow
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
|
||||||
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.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
@@ -49,8 +47,6 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
|
||||||
import androidx.compose.ui.focus.focusRequester
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalFocusManager
|
import androidx.compose.ui.platform.LocalFocusManager
|
||||||
@@ -68,8 +64,7 @@ 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.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Routes
|
import com.zaneschepke.wireguardautotunnel.ui.Routes
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.ClickableIconButton
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -82,7 +77,6 @@ fun SettingsScreen(
|
|||||||
viewModel: SettingsViewModel = hiltViewModel(),
|
viewModel: SettingsViewModel = hiltViewModel(),
|
||||||
padding: PaddingValues,
|
padding: PaddingValues,
|
||||||
navController: NavController,
|
navController: NavController,
|
||||||
focusRequester: FocusRequester,
|
|
||||||
snackbarHostState: SnackbarHostState = remember { SnackbarHostState() }
|
snackbarHostState: SnackbarHostState = remember { SnackbarHostState() }
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -96,7 +90,8 @@ fun SettingsScreen(
|
|||||||
val settings by viewModel.settings.collectAsStateWithLifecycle()
|
val settings by viewModel.settings.collectAsStateWithLifecycle()
|
||||||
val trustedSSIDs by viewModel.trustedSSIDs.collectAsStateWithLifecycle()
|
val trustedSSIDs by viewModel.trustedSSIDs.collectAsStateWithLifecycle()
|
||||||
val tunnels by viewModel.tunnels.collectAsStateWithLifecycle(mutableListOf())
|
val tunnels by viewModel.tunnels.collectAsStateWithLifecycle(mutableListOf())
|
||||||
val fineLocationState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
|
val backgroundLocationState =
|
||||||
|
rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||||
var currentText by remember { mutableStateOf("") }
|
var currentText by remember { mutableStateOf("") }
|
||||||
val scrollState = rememberScrollState()
|
val scrollState = rememberScrollState()
|
||||||
var isLocationServicesEnabled by remember { mutableStateOf(viewModel.checkLocationServicesEnabled())}
|
var isLocationServicesEnabled by remember { mutableStateOf(viewModel.checkLocationServicesEnabled())}
|
||||||
@@ -124,75 +119,43 @@ fun SettingsScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openSettings() {
|
if(!backgroundLocationState.status.isGranted) {
|
||||||
scope.launch {
|
Column(horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
val intentSettings =
|
verticalArrangement = Arrangement.Top,
|
||||||
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
|
||||||
intentSettings.data =
|
|
||||||
Uri.fromParts("package", context.packageName, null)
|
|
||||||
context.startActivity(intentSettings)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
val backgroundLocationState =
|
|
||||||
rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
|
||||||
if(!backgroundLocationState.status.isGranted) {
|
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Top,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.verticalScroll(scrollState)
|
|
||||||
.padding(padding)) {
|
|
||||||
Icon(Icons.Rounded.LocationOff, contentDescription = stringResource(id = R.string.map), modifier = Modifier
|
|
||||||
.padding(30.dp)
|
|
||||||
.size(128.dp))
|
|
||||||
Text(stringResource(R.string.prominent_background_location_title), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 20.sp)
|
|
||||||
Text(stringResource(R.string.prominent_background_location_message), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 15.sp)
|
|
||||||
Row(
|
|
||||||
modifier = if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(10.dp) else Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(30.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly
|
|
||||||
) {
|
|
||||||
Button(onClick = {
|
|
||||||
navController.navigate(Routes.Main.name)
|
|
||||||
}) {
|
|
||||||
Text(stringResource(id = R.string.no_thanks))
|
|
||||||
}
|
|
||||||
Button(modifier = Modifier.focusRequester(focusRequester), onClick = {
|
|
||||||
openSettings()
|
|
||||||
}) {
|
|
||||||
Text(stringResource(id = R.string.turn_on))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!fineLocationState.status.isGranted) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(padding)
|
.verticalScroll(scrollState)
|
||||||
) {
|
.padding(padding)) {
|
||||||
Text(
|
Icon(Icons.Rounded.LocationOff, contentDescription = stringResource(id = R.string.map), modifier = Modifier
|
||||||
stringResource(id = R.string.precise_location_message),
|
.padding(30.dp)
|
||||||
textAlign = TextAlign.Center,
|
.size(128.dp))
|
||||||
modifier = Modifier.padding(15.dp),
|
Text(stringResource(R.string.prominent_background_location_title), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 20.sp)
|
||||||
fontStyle = FontStyle.Italic
|
Text(stringResource(R.string.prominent_background_location_message), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 15.sp)
|
||||||
)
|
//Spacer(modifier = Modifier.weight(1f))
|
||||||
Button(modifier = Modifier.focusRequester(focusRequester),onClick = {
|
Row(
|
||||||
fineLocationState.launchPermissionRequest()
|
modifier = Modifier
|
||||||
}) {
|
.fillMaxWidth()
|
||||||
Text(stringResource(id = R.string.request))
|
.padding(30.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceEvenly
|
||||||
|
) {
|
||||||
|
Button(onClick = {
|
||||||
|
navController.navigate(Routes.Main.name)
|
||||||
|
}) {
|
||||||
|
Text(stringResource(id = R.string.no_thanks))
|
||||||
|
}
|
||||||
|
Button(onClick = {
|
||||||
|
scope.launch {
|
||||||
|
val intentSettings =
|
||||||
|
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||||
|
intentSettings.data =
|
||||||
|
Uri.fromParts("package", context.packageName, null)
|
||||||
|
context.startActivity(intentSettings)
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
Text(stringResource(id = R.string.turn_on))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -214,7 +177,7 @@ fun SettingsScreen(
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if(!isLocationServicesEnabled && Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
|
if(!isLocationServicesEnabled) {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
@@ -228,7 +191,7 @@ fun SettingsScreen(
|
|||||||
modifier = Modifier.padding(15.dp),
|
modifier = Modifier.padding(15.dp),
|
||||||
fontStyle = FontStyle.Italic
|
fontStyle = FontStyle.Italic
|
||||||
)
|
)
|
||||||
Button(modifier = Modifier.focusRequester(focusRequester), onClick = {
|
Button(onClick = {
|
||||||
val locationServicesEnabled = viewModel.checkLocationServicesEnabled()
|
val locationServicesEnabled = viewModel.checkLocationServicesEnabled()
|
||||||
isLocationServicesEnabled = locationServicesEnabled
|
isLocationServicesEnabled = locationServicesEnabled
|
||||||
if(!locationServicesEnabled) {
|
if(!locationServicesEnabled) {
|
||||||
@@ -242,18 +205,11 @@ fun SettingsScreen(
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val screenPadding = if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) 5.dp else 15.dp
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.Start,
|
||||||
verticalArrangement = Arrangement.Top,
|
verticalArrangement = Arrangement.Top,
|
||||||
modifier = if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) Modifier
|
modifier = Modifier
|
||||||
.fillMaxHeight(.85f)
|
|
||||||
.fillMaxWidth()
|
|
||||||
.verticalScroll(scrollState)
|
|
||||||
.clickable(indication = null, interactionSource = interactionSource) {
|
|
||||||
focusManager.clearFocus()
|
|
||||||
}
|
|
||||||
.padding(padding) else Modifier
|
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.verticalScroll(scrollState)
|
.verticalScroll(scrollState)
|
||||||
.clickable(indication = null, interactionSource = interactionSource) {
|
.clickable(indication = null, interactionSource = interactionSource) {
|
||||||
@@ -264,13 +220,12 @@ fun SettingsScreen(
|
|||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(screenPadding),
|
.padding(14.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
Text(stringResource(R.string.enable_auto_tunnel))
|
Text(stringResource(R.string.enable_auto_tunnel))
|
||||||
Switch(
|
Switch(
|
||||||
modifier = Modifier.focusRequester(focusRequester),
|
|
||||||
enabled = !settings.isAlwaysOnVpnEnabled,
|
enabled = !settings.isAlwaysOnVpnEnabled,
|
||||||
checked = settings.isAutoTunnelEnabled,
|
checked = settings.isAutoTunnelEnabled,
|
||||||
onCheckedChange = {
|
onCheckedChange = {
|
||||||
@@ -283,16 +238,14 @@ fun SettingsScreen(
|
|||||||
Text(
|
Text(
|
||||||
stringResource(id = R.string.select_tunnel),
|
stringResource(id = R.string.select_tunnel),
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
modifier = Modifier.padding(screenPadding, bottom = 5.dp, top = 5.dp)
|
modifier = Modifier.padding(15.dp, bottom = 5.dp, top = 5.dp)
|
||||||
)
|
)
|
||||||
ExposedDropdownMenuBox(
|
ExposedDropdownMenuBox(
|
||||||
expanded = expanded,
|
expanded = expanded,
|
||||||
onExpandedChange = {
|
onExpandedChange = {
|
||||||
if(!(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled)) {
|
if(!(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled)) {
|
||||||
expanded = !expanded }},
|
expanded = !expanded }},
|
||||||
modifier = Modifier.padding(start = 15.dp, top = 5.dp, bottom = 10.dp).clickable {
|
modifier = Modifier.padding(start = 15.dp, top = 5.dp, bottom = 10.dp),
|
||||||
expanded = !expanded
|
|
||||||
},
|
|
||||||
) {
|
) {
|
||||||
TextField(
|
TextField(
|
||||||
enabled = !(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled),
|
enabled = !(settings.isAutoTunnelEnabled || settings.isAlwaysOnVpnEnabled),
|
||||||
@@ -331,12 +284,12 @@ fun SettingsScreen(
|
|||||||
Text(
|
Text(
|
||||||
stringResource(R.string.trusted_ssid),
|
stringResource(R.string.trusted_ssid),
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
modifier = Modifier.padding(screenPadding, bottom = 5.dp, top = 5.dp)
|
modifier = Modifier.padding(15.dp, bottom = 5.dp, top = 5.dp)
|
||||||
)
|
)
|
||||||
FlowRow(
|
FlowRow(
|
||||||
modifier = Modifier.padding(screenPadding),
|
modifier = Modifier.padding(15.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
verticalArrangement = Arrangement.SpaceEvenly
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
trustedSSIDs.forEach { ssid ->
|
trustedSSIDs.forEach { ssid ->
|
||||||
ClickableIconButton(onIconClick = {
|
ClickableIconButton(onIconClick = {
|
||||||
@@ -351,7 +304,7 @@ fun SettingsScreen(
|
|||||||
value = currentText,
|
value = currentText,
|
||||||
onValueChange = { currentText = it },
|
onValueChange = { currentText = it },
|
||||||
label = { Text(stringResource(R.string.add_trusted_ssid)) },
|
label = { Text(stringResource(R.string.add_trusted_ssid)) },
|
||||||
modifier = Modifier.padding(start = screenPadding, top = 5.dp),
|
modifier = Modifier.padding(start = 15.dp, top = 5.dp),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
keyboardOptions = KeyboardOptions(
|
keyboardOptions = KeyboardOptions(
|
||||||
capitalization = KeyboardCapitalization.None,
|
capitalization = KeyboardCapitalization.None,
|
||||||
@@ -377,7 +330,7 @@ fun SettingsScreen(
|
|||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(screenPadding),
|
.padding(14.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
@@ -395,25 +348,7 @@ fun SettingsScreen(
|
|||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(screenPadding),
|
.padding(14.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Text("Tunnel on Ethernet")
|
|
||||||
Switch(
|
|
||||||
enabled = !settings.isAutoTunnelEnabled,
|
|
||||||
checked = settings.isTunnelOnEthernetEnabled,
|
|
||||||
onCheckedChange = {
|
|
||||||
scope.launch {
|
|
||||||
viewModel.onToggleTunnelOnEthernet()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(screenPadding),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -6,41 +6,37 @@ import android.location.LocationManager
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.SettingsDoa
|
import com.zaneschepke.wireguardautotunnel.repository.Repository
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.TunnelConfigDao
|
import com.zaneschepke.wireguardautotunnel.service.foreground.Action
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.Settings
|
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceTracker
|
||||||
import com.zaneschepke.wireguardautotunnel.repository.model.TunnelConfig
|
import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardConnectivityWatcherService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.ViewState
|
import com.zaneschepke.wireguardautotunnel.ui.ViewState
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asSharedFlow
|
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
|
||||||
import kotlinx.coroutines.flow.filter
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class SettingsViewModel @Inject constructor(private val application : Application,
|
class SettingsViewModel @Inject constructor(private val application : Application,
|
||||||
private val tunnelRepo : TunnelConfigDao, private val settingsRepo : SettingsDoa
|
private val tunnelRepo : Repository<TunnelConfig>, private val settingsRepo : Repository<Settings>
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _trustedSSIDs = MutableStateFlow(emptyList<String>())
|
private val _trustedSSIDs = MutableStateFlow(emptyList<String>())
|
||||||
val trustedSSIDs = _trustedSSIDs.asStateFlow()
|
val trustedSSIDs = _trustedSSIDs.asStateFlow()
|
||||||
private val _settings = MutableStateFlow(Settings())
|
private val _settings = MutableStateFlow(Settings())
|
||||||
val settings get() = _settings.asStateFlow()
|
val settings get() = _settings.asStateFlow()
|
||||||
val tunnels get() = tunnelRepo.getAllFlow()
|
val tunnels get() = tunnelRepo.itemFlow
|
||||||
private val _viewState = MutableStateFlow(ViewState())
|
private val _viewState = MutableStateFlow(ViewState())
|
||||||
val viewState get() = _viewState.asStateFlow()
|
val viewState get() = _viewState.asStateFlow()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
checkLocationServicesEnabled()
|
checkLocationServicesEnabled()
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch {
|
||||||
settingsRepo.getAllFlow().filter { it.isNotEmpty() }.collect {
|
settingsRepo.itemFlow.collect {
|
||||||
val settings = it.first()
|
val settings = it.first()
|
||||||
_settings.emit(settings)
|
_settings.emit(settings)
|
||||||
_trustedSSIDs.emit(settings.trustedNetworkSSIDs.toList())
|
_trustedSSIDs.emit(settings.trustedNetworkSSIDs.toList())
|
||||||
@@ -81,18 +77,32 @@ class SettingsViewModel @Inject constructor(private val application : Applicatio
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if(_settings.value.isAutoTunnelEnabled) {
|
if(_settings.value.isAutoTunnelEnabled) {
|
||||||
ServiceManager.stopWatcherService(application)
|
actionOnWatcherService(Action.STOP)
|
||||||
} else {
|
} else {
|
||||||
if(_settings.value.defaultTunnel != null) {
|
actionOnWatcherService(Action.START)
|
||||||
val defaultTunnel = _settings.value.defaultTunnel
|
|
||||||
ServiceManager.startWatcherService(application, defaultTunnel!!)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
settingsRepo.save(_settings.value.copy(
|
settingsRepo.save(_settings.value.copy(
|
||||||
isAutoTunnelEnabled = !_settings.value.isAutoTunnelEnabled
|
isAutoTunnelEnabled = !_settings.value.isAutoTunnelEnabled
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun actionOnWatcherService(action : Action) {
|
||||||
|
when(action) {
|
||||||
|
Action.START -> {
|
||||||
|
if(_settings.value.defaultTunnel != null) {
|
||||||
|
val defaultTunnel = _settings.value.defaultTunnel
|
||||||
|
ServiceTracker.actionOnService(
|
||||||
|
action, application,
|
||||||
|
WireGuardConnectivityWatcherService::class.java,
|
||||||
|
mapOf(application.resources.getString(R.string.tunnel_extras_key) to defaultTunnel.toString()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Action.STOP -> {
|
||||||
|
ServiceTracker.actionOnService( Action.STOP, application,
|
||||||
|
WireGuardConnectivityWatcherService::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
suspend fun showSnackBarMessage(message : String) {
|
suspend fun showSnackBarMessage(message : String) {
|
||||||
_viewState.emit(_viewState.value.copy(
|
_viewState.emit(_viewState.value.copy(
|
||||||
showSnackbarMessage = true,
|
showSnackbarMessage = true,
|
||||||
@@ -122,18 +132,6 @@ class SettingsViewModel @Inject constructor(private val application : Applicatio
|
|||||||
showSnackBarMessage(application.getString(R.string.select_tunnel_message))
|
showSnackBarMessage(application.getString(R.string.select_tunnel_message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun onToggleTunnelOnEthernet() {
|
|
||||||
if(_settings.value.defaultTunnel != null) {
|
|
||||||
_settings.emit(
|
|
||||||
_settings.value.copy(isTunnelOnEthernetEnabled = !_settings.value.isTunnelOnEthernetEnabled)
|
|
||||||
)
|
|
||||||
settingsRepo.save(_settings.value)
|
|
||||||
} else {
|
|
||||||
showSnackBarMessage(application.getString(R.string.select_tunnel_message))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun checkLocationServicesEnabled() : Boolean {
|
fun checkLocationServicesEnabled() : Boolean {
|
||||||
val locationManager =
|
val locationManager =
|
||||||
application.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
application.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.support
|
package com.zaneschepke.wireguardautotunnel.ui.screens.support
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.focusable
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
@@ -19,12 +17,8 @@ import androidx.compose.material3.Icon
|
|||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
|
||||||
import androidx.compose.ui.focus.focusRequester
|
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@@ -37,7 +31,7 @@ import androidx.compose.ui.unit.sp
|
|||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SupportScreen(padding : PaddingValues, focusRequester: FocusRequester) {
|
fun SupportScreen(padding : PaddingValues) {
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
@@ -52,7 +46,6 @@ fun SupportScreen(padding : PaddingValues, focusRequester: FocusRequester) {
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
.focusable()
|
|
||||||
.padding(padding)) {
|
.padding(padding)) {
|
||||||
Text(stringResource(R.string.support_text), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 15.sp)
|
Text(stringResource(R.string.support_text), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 15.sp)
|
||||||
Row(
|
Row(
|
||||||
@@ -67,7 +60,7 @@ fun SupportScreen(padding : PaddingValues, focusRequester: FocusRequester) {
|
|||||||
}) {
|
}) {
|
||||||
Icon(imageVector = ImageVector.vectorResource(R.drawable.discord), "Discord")
|
Icon(imageVector = ImageVector.vectorResource(R.drawable.discord), "Discord")
|
||||||
}
|
}
|
||||||
IconButton(modifier = Modifier.focusRequester(focusRequester),onClick = {
|
IconButton(onClick = {
|
||||||
openWebPage(context.resources.getString(R.string.github_url))
|
openWebPage(context.resources.getString(R.string.github_url))
|
||||||
}) {
|
}) {
|
||||||
Icon(imageVector = ImageVector.vectorResource(R.drawable.github), "Github")
|
Icon(imageVector = ImageVector.vectorResource(R.drawable.github), "Github")
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ object NumberUtils {
|
|||||||
return bytes.toBigDecimal().divide(BYTES_IN_KB.toBigDecimal())
|
return bytes.toBigDecimal().divide(BYTES_IN_KB.toBigDecimal())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateRandomTunnelName() : String {
|
|
||||||
return "tunnel${(Math.random() * 100000).toInt()}"
|
|
||||||
}
|
|
||||||
|
|
||||||
fun formatDecimalTwoPlaces(bigDecimal: BigDecimal) : String {
|
fun formatDecimalTwoPlaces(bigDecimal: BigDecimal) : String {
|
||||||
val df = DecimalFormat("#.##")
|
val df = DecimalFormat("#.##")
|
||||||
return df.format(bigDecimal)
|
return df.format(bigDecimal)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.util
|
|
||||||
|
|
||||||
class WgTunnelException(message: String) : Exception(message)
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<vector android:height="24dp" android:tint="#000000"
|
|
||||||
android:viewportHeight="24" android:viewportWidth="24"
|
|
||||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<path android:fillColor="@android:color/white" android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12V5l-9,-4z"/>
|
|
||||||
</vector>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<vector android:height="24dp" android:tint="#000000"
|
|
||||||
android:viewportHeight="24" android:viewportWidth="24"
|
|
||||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<path android:fillColor="@android:color/white" android:pathData="M20.83,18H21v-4h2v-4H12.83L20.83,18zM19.78,22.61l1.41,-1.41L2.81,2.81L1.39,4.22l2.59,2.59C2.2,7.85 1,9.79 1,12c0,3.31 2.69,6 6,6c2.21,0 4.15,-1.2 5.18,-2.99L19.78,22.61zM8.99,11.82C9,11.88 9,11.94 9,12c0,1.1 -0.9,2 -2,2s-2,-0.9 -2,-2s0.9,-2 2,-2c0.06,0 0.12,0 0.18,0.01L8.99,11.82z"/>
|
|
||||||
</vector>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<vector android:height="24dp" android:tint="#000000"
|
|
||||||
android:viewportHeight="24" android:viewportWidth="24"
|
|
||||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<path android:fillColor="@android:color/white" android:pathData="M12.65,10C11.83,7.67 9.61,6 7,6c-3.31,0 -6,2.69 -6,6s2.69,6 6,6c2.61,0 4.83,-1.67 5.65,-4H17v4h4v-4h2v-4H12.65zM7,14c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z"/>
|
|
||||||
</vector>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@color/ic_banner_background"/>
|
|
||||||
<foreground android:drawable="@mipmap/ic_banner_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<color name="ic_banner_background">#121212</color>
|
|
||||||
</resources>
|
|
||||||
@@ -38,6 +38,7 @@
|
|||||||
<string name="trusted_ssid_empty_description">Enter SSID</string>
|
<string name="trusted_ssid_empty_description">Enter SSID</string>
|
||||||
<string name="trusted_ssid_value_description">Submit SSID</string>
|
<string name="trusted_ssid_value_description">Submit SSID</string>
|
||||||
<string name="config_validation">[Interface]</string>
|
<string name="config_validation">[Interface]</string>
|
||||||
|
<string name="invalid_qr">Invalid QR code.</string>
|
||||||
<string name="add_from_file">Add tunnel from files</string>
|
<string name="add_from_file">Add tunnel from files</string>
|
||||||
<string name="open_file">File Open</string>
|
<string name="open_file">File Open</string>
|
||||||
<string name="add_from_qr">Add tunnel from QR code</string>
|
<string name="add_from_qr">Add tunnel from QR code</string>
|
||||||
@@ -61,6 +62,7 @@
|
|||||||
<string name="public_key">Public key</string>
|
<string name="public_key">Public key</string>
|
||||||
<string name="barcode_downloading">Waiting for the Barcode UI module to be downloaded.</string>
|
<string name="barcode_downloading">Waiting for the Barcode UI module to be downloaded.</string>
|
||||||
<string name="barcode_downloading_message">Barcode module downloading. Try again.</string>
|
<string name="barcode_downloading_message">Barcode module downloading. Try again.</string>
|
||||||
|
<string name="barcode_error">Invalid QR code. Try again.</string>
|
||||||
<string name="addresses">Addresses</string>
|
<string name="addresses">Addresses</string>
|
||||||
<string name="dns_servers">DNS servers</string>
|
<string name="dns_servers">DNS servers</string>
|
||||||
<string name="mtu">MTU</string>
|
<string name="mtu">MTU</string>
|
||||||
@@ -80,20 +82,4 @@
|
|||||||
<string name="location_services_not_detected">Unable to detect Location Services which are required for this feature. Please enable Location Services.</string>
|
<string name="location_services_not_detected">Unable to detect Location Services which are required for this feature. Please enable Location Services.</string>
|
||||||
<string name="check_again">Check again</string>
|
<string name="check_again">Check again</string>
|
||||||
<string name="detecting_location_services_disabled">Detecting Location Services disabled</string>
|
<string name="detecting_location_services_disabled">Detecting Location Services disabled</string>
|
||||||
<string name="precise_location_message">This feature requires precise location to access Wi-Fi SSID name. Please enable precise location here or in the app settings.</string>
|
|
||||||
<string name="request">Request</string>
|
|
||||||
<string name="toggle_vpn">Toggle VPN</string>
|
|
||||||
<string name="no_tunnel_available">No tunnels available</string>
|
|
||||||
<string name="hint_search_packages">Search packages</string>
|
|
||||||
<string name="clear_icon">Clear Icon</string>
|
|
||||||
<string name="search_icon">Search Icon</string>
|
|
||||||
<string name="attempt_connection">Attempting connection..</string>
|
|
||||||
<string name="vpn_starting">VPN Starting</string>
|
|
||||||
<string name="db_name">wg-tunnel-db</string>
|
|
||||||
<string name="scanning_qr">Scanning for QR</string>
|
|
||||||
<string name="qr_result_failed">QR scan failed</string>
|
|
||||||
<string name="none">None</string>
|
|
||||||
<string name="never">Never</string>
|
|
||||||
<string name="stream_failed">Failed to open file stream.</string>
|
|
||||||
<string name="unknown_error_message">An unknown error occurred.</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 238 KiB |
@@ -1,18 +1,20 @@
|
|||||||
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
|
val objectBoxVersion by extra("3.5.1")
|
||||||
|
val hiltVersion by extra("2.47")
|
||||||
|
val accompanistVersion by extra("0.31.2-alpha")
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
if (BuildHelper.isReleaseBuild(gradle) && BuildHelper.isGeneralFlavor(gradle)) {
|
classpath("io.objectbox:objectbox-gradle-plugin:$objectBoxVersion")
|
||||||
classpath(libs.google.services)
|
classpath("com.google.gms:google-services:4.3.15")
|
||||||
classpath(libs.firebase.crashlytics.gradle)
|
classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.7")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application) apply false
|
id("com.android.application") version "8.2.0-alpha08" apply false
|
||||||
alias(libs.plugins.kotlin.android) apply false
|
id("org.jetbrains.kotlin.android") version "1.8.22" apply false
|
||||||
alias(libs.plugins.hilt.android) apply false
|
id("com.google.dagger.hilt.android") version "2.44" apply false
|
||||||
kotlin("plugin.serialization").version(libs.versions.kotlin).apply(false)
|
kotlin("plugin.serialization") version "1.8.22" apply false
|
||||||
alias(libs.plugins.ksp) apply false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
plugins {
|
|
||||||
`kotlin-dsl` // enable the Kotlin-DSL
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
google()
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import org.gradle.api.invocation.Gradle
|
|
||||||
|
|
||||||
object BuildHelper {
|
|
||||||
private fun getCurrentFlavor(gradle : Gradle): String {
|
|
||||||
val taskRequestsStr = gradle.startParameter.taskRequests.toString()
|
|
||||||
val pattern: java.util.regex.Pattern = if (taskRequestsStr.contains("assemble")) {
|
|
||||||
java.util.regex.Pattern.compile("assemble(\\w+)(Release|Debug)")
|
|
||||||
} else {
|
|
||||||
java.util.regex.Pattern.compile("bundle(\\w+)(Release|Debug)")
|
|
||||||
}
|
|
||||||
|
|
||||||
val matcher = pattern.matcher(taskRequestsStr)
|
|
||||||
val flavor = if (matcher.find()) {
|
|
||||||
matcher.group(1).lowercase()
|
|
||||||
} else {
|
|
||||||
print("NO FLAVOR FOUND")
|
|
||||||
""
|
|
||||||
}
|
|
||||||
return flavor
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isGeneralFlavor(gradle : Gradle) : Boolean {
|
|
||||||
return getCurrentFlavor(gradle) == "general"
|
|
||||||
}
|
|
||||||
fun isReleaseBuild(gradle: Gradle) : Boolean {
|
|
||||||
return (gradle.startParameter.taskNames.size > 0 && gradle.startParameter.taskNames[0].contains(
|
|
||||||
"Release"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
Features
|
|
||||||
|
|
||||||
- Add tunnels via .conf file or QR
|
|
||||||
- Auto connect to VPN based on Wi-Fi SSID
|
|
||||||
- Split tunneling by application with search
|
|
||||||
- Always-on VPN support
|
|
||||||
- Configurable Trusted Network list
|
|
||||||
- Quick tile and Shortcuts integration
|
|
||||||
- Optional auto connect on mobile data
|
|
||||||
- Automatic service restart after reboot
|
|
||||||
|
Before Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 37 KiB |
@@ -1 +0,0 @@
|
|||||||
An alternative VPN client app for WireGuard with additional features
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
WG Tunnel
|
|
||||||
|
Before Width: | Height: | Size: 32 KiB |
@@ -21,3 +21,5 @@ kotlin.code.style=official
|
|||||||
# resources declared in the library itself and none from the library's dependencies,
|
# resources declared in the library itself and none from the library's dependencies,
|
||||||
# thereby reducing the size of the R class for that library
|
# thereby reducing the size of the R class for that library
|
||||||
android.nonTransitiveRClass=true
|
android.nonTransitiveRClass=true
|
||||||
|
#enable buildconfig values
|
||||||
|
android.defaults.buildfeatures.buildconfig=true
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
[versions]
|
|
||||||
accompanist = "0.31.2-alpha"
|
|
||||||
activityCompose = "1.7.2"
|
|
||||||
androidx-junit = "1.1.5"
|
|
||||||
appcompat = "1.6.1"
|
|
||||||
coreKtx = "1.12.0"
|
|
||||||
espressoCore = "3.5.1"
|
|
||||||
firebase-crashlytics-gradle = "2.9.9"
|
|
||||||
google-services = "4.3.15"
|
|
||||||
hiltAndroid = "2.48"
|
|
||||||
hiltNavigationCompose = "1.0.0"
|
|
||||||
junit = "4.13.2"
|
|
||||||
kotlinx-serialization-json = "1.5.1"
|
|
||||||
lifecycle-runtime-compose = "2.6.2"
|
|
||||||
material-icons-extended = "1.5.1"
|
|
||||||
material3 = "1.1.1"
|
|
||||||
navigationCompose = "2.7.2"
|
|
||||||
roomVersion = "2.6.0-beta01"
|
|
||||||
timber = "5.0.1"
|
|
||||||
tunnel = "1.0.20230706"
|
|
||||||
androidGradlePlugin = "8.2.0-beta03"
|
|
||||||
kotlin="1.9.10"
|
|
||||||
ksp="1.9.10-1.0.13"
|
|
||||||
composeBom="2023.09.00"
|
|
||||||
firebaseBom="32.2.3"
|
|
||||||
compose="1.5.1"
|
|
||||||
crashlytics="18.4.1"
|
|
||||||
analytics="21.3.0"
|
|
||||||
composeCompiler="1.5.3"
|
|
||||||
zxingAndroidEmbedded = "4.3.0"
|
|
||||||
zxingCore = "3.4.1"
|
|
||||||
|
|
||||||
|
|
||||||
[libraries]
|
|
||||||
# accompanist
|
|
||||||
accompanist-drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "accompanist" }
|
|
||||||
accompanist-flowlayout = { module = "com.google.accompanist:accompanist-flowlayout", version.ref = "accompanist" }
|
|
||||||
accompanist-navigation-animation = { module = "com.google.accompanist:accompanist-navigation-animation", version.ref = "accompanist" }
|
|
||||||
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" }
|
|
||||||
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
|
|
||||||
#room
|
|
||||||
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "roomVersion" }
|
|
||||||
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomVersion" }
|
|
||||||
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "roomVersion" }
|
|
||||||
|
|
||||||
#compose
|
|
||||||
androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref="composeBom" }
|
|
||||||
androidx-compose-ui-test = { module="androidx.compose.ui:ui-test-junit4", version.ref="compose" }
|
|
||||||
androidx-compose-ui-tooling = { module="androidx.compose.ui:ui-tooling", version.ref="compose" }
|
|
||||||
androidx-compose-manifest = { module="androidx.compose.ui:ui-test-manifest", version.ref="compose" }
|
|
||||||
androidx-compose-ui-graphics = { module="androidx.compose.ui:ui-graphics", version.ref="compose" }
|
|
||||||
androidx-compose-ui-tooling-preview = { module="androidx.compose.ui:ui-tooling-preview", version.ref="compose" }
|
|
||||||
androidx-compose-ui = { module="androidx.compose.ui:ui", version.ref="compose" }
|
|
||||||
|
|
||||||
#hilt
|
|
||||||
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hiltAndroid" }
|
|
||||||
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hiltAndroid" }
|
|
||||||
|
|
||||||
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
|
|
||||||
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
|
|
||||||
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }
|
|
||||||
androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espressoCore" }
|
|
||||||
androidx-hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "hiltNavigationCompose" }
|
|
||||||
androidx-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-junit" }
|
|
||||||
androidx-lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle-runtime-compose" }
|
|
||||||
androidx-material3 = { module = "androidx.compose.material3:material3", version.ref = "material3" }
|
|
||||||
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
|
|
||||||
|
|
||||||
junit = { module = "junit:junit", version.ref = "junit" }
|
|
||||||
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }
|
|
||||||
lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle-runtime-compose" }
|
|
||||||
material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "material-icons-extended" }
|
|
||||||
|
|
||||||
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
|
|
||||||
|
|
||||||
tunnel = { module = "com.wireguard.android:tunnel", version.ref = "tunnel" }
|
|
||||||
|
|
||||||
#firebase
|
|
||||||
google-firebase-crashlytics-ktx = { module = "com.google.firebase:firebase-crashlytics-ktx", version.ref = "crashlytics" }
|
|
||||||
google-firebase-analytics-ktx = { module = "com.google.firebase:firebase-analytics-ktx", version.ref = "analytics" }
|
|
||||||
firebase-crashlytics-gradle = { module = "com.google.firebase:firebase-crashlytics-gradle", version.ref = "firebase-crashlytics-gradle" }
|
|
||||||
firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebaseBom"}
|
|
||||||
google-services = { module = "com.google.gms:google-services", version.ref = "google-services" }
|
|
||||||
|
|
||||||
zxing-core = { module = "com.google.zxing:core", version.ref = "zxingCore" }
|
|
||||||
zxing-android-embedded = { module = "com.journeyapps:zxing-android-embedded", version.ref = "zxingAndroidEmbedded" }
|
|
||||||
|
|
||||||
[plugins]
|
|
||||||
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
|
|
||||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
|
||||||
hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hiltAndroid" }
|
|
||||||
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#Mon Apr 24 22:46:45 EDT 2023
|
#Mon Apr 24 22:46:45 EDT 2023
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||