Skip to content

Commit

Permalink
create FOSS and nonFOSS flavors and corresponding AndroidManifests
Browse files Browse the repository at this point in the history
* Disable AutoUpdates in `FOSS` flavor
* Move permissions to `nonFOSS` manifest
  • Loading branch information
kaajjo committed Feb 22, 2025
1 parent 383d6cc commit e183f48
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 42 deletions.
10 changes: 10 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ android {
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}

flavorDimensions += "version"
productFlavors {
create("foss") {
dimension = "version"
}
create("nonFOSS") {
dimension = "version"
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
6 changes: 6 additions & 0 deletions app/src/foss/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<manifest>

<application>
</application>

</manifest>
5 changes: 0 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

<application
android:name=".LibreSudokuApp"
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.util.Log
import androidx.core.content.FileProvider
import com.kaajjo.libresudoku.BuildConfig
import com.kaajjo.libresudoku.util.FlavorUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
Expand Down Expand Up @@ -64,6 +65,9 @@ object UpdateUtil {
}

fun checkForUpdate(allowBetas: Boolean = true): Release? {
if (FlavorUtil.isFoss()) {
return null
}
val currentVersion = BuildConfig.VERSION_NAME.toVersion()

val latestRelease = getLatestRelease(allowBetas)
Expand Down
59 changes: 31 additions & 28 deletions app/src/main/java/com/kaajjo/libresudoku/ui/more/MoreScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import com.kaajjo.libresudoku.ui.components.AnimatedNavigation
import com.kaajjo.libresudoku.ui.components.PreferenceRow
import com.kaajjo.libresudoku.ui.settings.autoupdate.UpdateChannel
import com.kaajjo.libresudoku.ui.theme.RoundedPolygonShape
import com.kaajjo.libresudoku.util.FlavorUtil
import com.materialkolor.ktx.blend
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
Expand Down Expand Up @@ -142,37 +143,39 @@ fun MoreScreen(
onClick = { navigator.navigate(AboutScreenDestination()) }
)

AnimatedVisibility(autoUpdateChannel != UpdateChannel.Disabled) {
var latestRelease by remember { mutableStateOf<Release?>(null) }
LaunchedEffect(Unit) {
if (latestRelease == null) {
withContext(Dispatchers.IO) {
runCatching {
latestRelease =
UpdateUtil.checkForUpdate(autoUpdateChannel == UpdateChannel.Beta)
if (!FlavorUtil.isFoss()) {
AnimatedVisibility(autoUpdateChannel != UpdateChannel.Disabled) {
var latestRelease by remember { mutableStateOf<Release?>(null) }
LaunchedEffect(Unit) {
if (latestRelease == null) {
withContext(Dispatchers.IO) {
runCatching {
latestRelease =
UpdateUtil.checkForUpdate(autoUpdateChannel == UpdateChannel.Beta)
}
}
}
}
}
latestRelease?.let { release ->
AnimatedVisibility(
visible = release.name.toString() != updateDismissedName,
enter = expandVertically() + fadeIn(),
exit = shrinkVertically() + fadeOut()
) {
UpdateFoundBox(
versionToUpdate = release.name ?: "?",
onClick = {
navigator.navigate(AutoUpdateScreenDestination())
},
onDismissed = {
viewModel.dismissUpdate(release)
},
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
.padding(top = 8.dp)
)
latestRelease?.let { release ->
AnimatedVisibility(
visible = release.name.toString() != updateDismissedName,
enter = expandVertically() + fadeIn(),
exit = shrinkVertically() + fadeOut()
) {
UpdateFoundBox(
versionToUpdate = release.name ?: "?",
onClick = {
navigator.navigate(AutoUpdateScreenDestination())
},
onDismissed = {
viewModel.dismissUpdate(release)
},
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
.padding(top = 8.dp)
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import com.kaajjo.libresudoku.ui.components.collapsing_topappbar.CollapsingTopAp
import com.kaajjo.libresudoku.ui.components.collapsing_topappbar.rememberTopAppBarScrollBehavior
import com.kaajjo.libresudoku.ui.settings.components.AppThemePreviewItem
import com.kaajjo.libresudoku.ui.util.getCurrentLocaleString
import com.kaajjo.libresudoku.util.FlavorUtil
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator

Expand Down Expand Up @@ -124,15 +125,17 @@ fun SettingsCategoriesScreen(
painter = rememberVectorPainter(Icons.Outlined.Language)
)
}
item {
PreferenceRow(
title = stringResource(R.string.auto_update_title),
subtitle = stringResource(R.string.auto_updates_summary),
onClick = {
navigator.navigate(AutoUpdateScreenDestination())
},
painter = rememberVectorPainter(Icons.Rounded.SystemUpdate)
)
if (!FlavorUtil.isFoss()) {
item {
PreferenceRow(
title = stringResource(R.string.auto_update_title),
subtitle = stringResource(R.string.auto_updates_summary),
onClick = {
navigator.navigate(AutoUpdateScreenDestination())
},
painter = rememberVectorPainter(Icons.Rounded.SystemUpdate)
)
}
}
item {
PreferenceRow(
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/kaajjo/libresudoku/util/FlavorUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kaajjo.libresudoku.util

import com.kaajjo.libresudoku.BuildConfig

object FlavorUtil {
fun isFoss(): Boolean = BuildConfig.FLAVOR == "foss"
}
11 changes: 11 additions & 0 deletions app/src/nonFOSS/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

<application>
</application>

</manifest>

0 comments on commit e183f48

Please sign in to comment.