From b99b116fdb429243db44869019ccddd6921d0929 Mon Sep 17 00:00:00 2001 From: Zane Schepke Date: Mon, 16 Sep 2024 01:01:13 -0400 Subject: [PATCH] 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 --- .github/workflows/release.yml | 15 ++++++++ app/build.gradle.kts | 37 +++++++++++++------ .../ui/screens/settings/SettingsScreen.kt | 26 +++++-------- buildSrc/src/main/kotlin/Constants.kt | 3 -- versionCode.txt | 1 + 5 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 versionCode.txt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7df6a4b..0ef31ed 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f19a39f..1f9d969 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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) + } +} + + diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt index f538cb0..c87d62b 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt @@ -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 } diff --git a/buildSrc/src/main/kotlin/Constants.kt b/buildSrc/src/main/kotlin/Constants.kt index 5bedb61..bcc0356 100644 --- a/buildSrc/src/main/kotlin/Constants.kt +++ b/buildSrc/src/main/kotlin/Constants.kt @@ -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 } diff --git a/versionCode.txt b/versionCode.txt new file mode 100644 index 0000000..d8263ee --- /dev/null +++ b/versionCode.txt @@ -0,0 +1 @@ +2 \ No newline at end of file