fix: android tv auto tunnel bug

Also fixed bug that could cause need to click start twice on mobile when starting auto tunneling

Fix nightly cd to bump app versionCode
This commit is contained in:
Zane Schepke 2024-09-16 01:01:13 -04:00
parent 9d42e7299b
commit b99b116fdb
5 changed files with 51 additions and 31 deletions

View File

@ -110,6 +110,21 @@ jobs:
version_code=$(grep "VERSION_CODE" buildSrc/src/main/kotlin/Constants.kt | awk '{print $5}' | tr -d '\n') version_code=$(grep "VERSION_CODE" buildSrc/src/main/kotlin/Constants.kt | awk '{print $5}' | tr -d '\n')
echo "VERSION_CODE=$version_code" >> $GITHUB_ENV echo "VERSION_CODE=$version_code" >> $GITHUB_ENV
- name: Commit and push versionCode changes
if: ${{ contains(env.TAG_NAME, 'nightly') || inputs.release_type == 'prerelease' }}
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email 'actions@github.com'
git add versionCode.txt
git commit -m "Automated build update"
- name: Push changes
if: ${{ contains(env.TAG_NAME, 'nightly') || inputs.release_type == 'prerelease' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
# Save the APK after the Build job is complete to publish it as a Github release in the next job # Save the APK after the Build job is complete to publish it as a Github release in the next job
- name: Upload APK - name: Upload APK
uses: actions/upload-artifact@v4.4.0 uses: actions/upload-artifact@v4.4.0

View File

@ -1,3 +1,5 @@
import com.android.build.gradle.internal.scope.ProjectInfo.Companion.getBaseName
plugins { plugins {
alias(libs.plugins.android.application) alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android) alias(libs.plugins.kotlin.android)
@ -20,7 +22,7 @@ android {
applicationId = Constants.APP_ID applicationId = Constants.APP_ID
minSdk = Constants.MIN_SDK minSdk = Constants.MIN_SDK
targetSdk = Constants.TARGET_SDK targetSdk = Constants.TARGET_SDK
versionCode = determineVersionCode() versionCode = Constants.VERSION_CODE + (versionCode ?: 0)
versionName = determineVersionName() versionName = determineVersionName()
ksp { arg("room.schemaLocation", "$projectDir/schemas") } ksp { arg("room.schemaLocation", "$projectDir/schemas") }
@ -199,16 +201,6 @@ dependencies {
implementation(libs.androidx.core.splashscreen) implementation(libs.androidx.core.splashscreen)
} }
fun determineVersionCode(): Int {
return with(getBuildTaskName().lowercase()) {
when {
contains(Constants.NIGHTLY) -> Constants.VERSION_CODE + Constants.NIGHTLY_CODE
contains(Constants.PRERELEASE) -> Constants.VERSION_CODE + Constants.PRERELEASE_CODE
else -> Constants.VERSION_CODE
}
}
}
fun determineVersionName(): String { fun determineVersionName(): String {
return with(getBuildTaskName().lowercase()) { return with(getBuildTaskName().lowercase()) {
when { when {
@ -219,3 +211,26 @@ fun determineVersionName(): String {
} }
} }
} }
val incrementVersionCode by tasks.registering {
doLast {
val versionCodeFile = file("$rootDir/versionCode.txt")
val currentVersionCode = if (versionCodeFile.exists()) {
versionCodeFile.readText().toInt()
} else {
1
}
val newVersionCode = currentVersionCode + 1
versionCodeFile.writeText(newVersionCode.toString())
println("Incremented versionCode to $newVersionCode")
}
}
tasks.whenTaskAdded {
if (name.startsWith("assemble")) {
dependsOn(incrementVersionCode)
}
}

View File

@ -5,6 +5,7 @@ import android.app.Activity
import android.content.Context.POWER_SERVICE import android.content.Context.POWER_SERVICE
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.net.VpnService
import android.os.Build import android.os.Build
import android.os.PowerManager import android.os.PowerManager
import android.provider.Settings import android.provider.Settings
@ -111,7 +112,7 @@ fun SettingsScreen(
var isBackgroundLocationGranted by remember { mutableStateOf(true) } var isBackgroundLocationGranted by remember { mutableStateOf(true) }
var showVpnPermissionDialog by remember { mutableStateOf(false) } var showVpnPermissionDialog by remember { mutableStateOf(false) }
var showLocationServicesAlertDialog by remember { mutableStateOf(false) } var showLocationServicesAlertDialog by remember { mutableStateOf(false) }
var didExportFiles by remember { mutableStateOf(false) } val didExportFiles by remember { mutableStateOf(false) }
var showAuthPrompt by remember { mutableStateOf(false) } var showAuthPrompt by remember { mutableStateOf(false) }
var showLocationDialog by remember { mutableStateOf(false) } var showLocationDialog by remember { mutableStateOf(false) }
@ -126,13 +127,6 @@ fun SettingsScreen(
currentText = "" currentText = ""
} }
val notificationPermissionState =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
rememberPermissionState(Manifest.permission.POST_NOTIFICATIONS)
} else {
null
}
val startForResult = val startForResult =
rememberLauncherForActivityResult( rememberLauncherForActivityResult(
ActivityResultContracts.StartActivityForResult(), ActivityResultContracts.StartActivityForResult(),
@ -165,22 +159,20 @@ fun SettingsScreen(
fun requestBatteryOptimizationsDisabled() { fun requestBatteryOptimizationsDisabled() {
val intent = val intent =
Intent().apply { Intent().apply {
this.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
data = Uri.fromParts("package", context.packageName, null) data = Uri.parse("package:${context.packageName}")
} }
startForResult.launch(intent) startForResult.launch(intent)
} }
fun handleAutoTunnelToggle() { fun handleAutoTunnelToggle() {
if (!uiState.generalState.isBatteryOptimizationDisableShown || !isBatteryOptimizationsDisabled()) return requestBatteryOptimizationsDisabled() if (!uiState.generalState.isBatteryOptimizationDisableShown &&
if (notificationPermissionState != null && !notificationPermissionState.status.isGranted) { !isBatteryOptimizationsDisabled() && !context.isRunningOnTv()
snackbar.showMessage( ) {
context.getString(R.string.notification_permission_required), return requestBatteryOptimizationsDisabled()
)
return notificationPermissionState.launchPermissionRequest()
} }
val intent = if (!uiState.settings.isKernelEnabled) { val intent = if (!uiState.settings.isKernelEnabled) {
com.wireguard.android.backend.GoBackend.VpnService.prepare(context) VpnService.prepare(context)
} else { } else {
null null
} }

View File

@ -16,7 +16,4 @@ object Constants {
const val NIGHTLY = "nightly" const val NIGHTLY = "nightly"
const val PRERELEASE = "prerelease" const val PRERELEASE = "prerelease"
const val TYPE = "type" const val TYPE = "type"
const val NIGHTLY_CODE = 42
const val PRERELEASE_CODE = 54
} }

1
versionCode.txt Normal file
View File

@ -0,0 +1 @@
2