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')
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
- name: Upload APK
uses: actions/upload-artifact@v4.4.0

View File

@ -1,3 +1,5 @@
import com.android.build.gradle.internal.scope.ProjectInfo.Companion.getBaseName
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
@ -20,7 +22,7 @@ android {
applicationId = Constants.APP_ID
minSdk = Constants.MIN_SDK
targetSdk = Constants.TARGET_SDK
versionCode = determineVersionCode()
versionCode = Constants.VERSION_CODE + (versionCode ?: 0)
versionName = determineVersionName()
ksp { arg("room.schemaLocation", "$projectDir/schemas") }
@ -199,16 +201,6 @@ dependencies {
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 {
return with(getBuildTaskName().lowercase()) {
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.Intent
import android.net.Uri
import android.net.VpnService
import android.os.Build
import android.os.PowerManager
import android.provider.Settings
@ -111,7 +112,7 @@ fun SettingsScreen(
var isBackgroundLocationGranted by remember { mutableStateOf(true) }
var showVpnPermissionDialog 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 showLocationDialog by remember { mutableStateOf(false) }
@ -126,13 +127,6 @@ fun SettingsScreen(
currentText = ""
}
val notificationPermissionState =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
rememberPermissionState(Manifest.permission.POST_NOTIFICATIONS)
} else {
null
}
val startForResult =
rememberLauncherForActivityResult(
ActivityResultContracts.StartActivityForResult(),
@ -165,22 +159,20 @@ fun SettingsScreen(
fun requestBatteryOptimizationsDisabled() {
val intent =
Intent().apply {
this.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
data = Uri.fromParts("package", context.packageName, null)
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
data = Uri.parse("package:${context.packageName}")
}
startForResult.launch(intent)
}
fun handleAutoTunnelToggle() {
if (!uiState.generalState.isBatteryOptimizationDisableShown || !isBatteryOptimizationsDisabled()) return requestBatteryOptimizationsDisabled()
if (notificationPermissionState != null && !notificationPermissionState.status.isGranted) {
snackbar.showMessage(
context.getString(R.string.notification_permission_required),
)
return notificationPermissionState.launchPermissionRequest()
if (!uiState.generalState.isBatteryOptimizationDisableShown &&
!isBatteryOptimizationsDisabled() && !context.isRunningOnTv()
) {
return requestBatteryOptimizationsDisabled()
}
val intent = if (!uiState.settings.isKernelEnabled) {
com.wireguard.android.backend.GoBackend.VpnService.prepare(context)
VpnService.prepare(context)
} else {
null
}

View File

@ -16,7 +16,4 @@ object Constants {
const val NIGHTLY = "nightly"
const val PRERELEASE = "prerelease"
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