Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile against Android 15 Preview #1193

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package eu.darken.sdmse.common
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.content.res.TypedArray
import android.util.TypedValue
import androidx.annotation.*
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.PluralsRes
import androidx.core.content.ContextCompat
import eu.darken.sdmse.common.debug.logging.log
import okio.Source
Expand Down Expand Up @@ -77,4 +81,6 @@ fun Context.getSpanCount(widthDp: Int = 390): Int {
return max(count, 1).also {
log { "getSpanCount($screenWidthDp/$widthDp)=$it" }
}
}
}

fun Context.getPackageInfo(): PackageInfo = packageManager.getPackageInfo(packageName, 0)
12 changes: 10 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ apply(plugin = "androidx.navigation.safeargs.kotlin")
val commitHashProvider = providers.of(CommitHashValueSource::class) {}

android {
compileSdk = projectConfig.compileSdk
if (projectConfig.compileSdkPreview != null) {
compileSdkPreview = projectConfig.compileSdkPreview
} else {
compileSdk = projectConfig.compileSdk
}

defaultConfig {
namespace = projectConfig.packageName

minSdk = projectConfig.minSdk
targetSdk = projectConfig.targetSdk
if (projectConfig.targetSdkPreview != null) {
targetSdkPreview = projectConfig.targetSdkPreview
} else {
targetSdk = projectConfig.targetSdk
}

versionCode = projectConfig.version.code.toInt()
versionName = projectConfig.version.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import eu.darken.sdmse.common.debug.logging.Logging.Priority.WARN
import eu.darken.sdmse.common.debug.logging.asLog
import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.debug.logging.logTag
import eu.darken.sdmse.common.getPackageInfo
import eu.darken.sdmse.common.pkgs.features.getInstallerInfo
import java.time.Duration
import java.time.Instant
Expand Down Expand Up @@ -96,8 +97,7 @@ class FossUpdateChecker @Inject constructor(

override fun isEnabledByDefault(): Boolean {
val pm = context.packageManager
val installers: Set<String> = pm
.getPackageInfo(context.packageName, 0)
val installers: Set<String> = context.getPackageInfo()
.getInstallerInfo(pm)
.allInstallers
.map { it.id.name }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.darken.sdmse.common.coil

import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import androidx.core.content.ContextCompat
import coil.ImageLoader
Expand Down Expand Up @@ -69,7 +70,7 @@ class PathPreviewFetcher @Inject constructor(
.takeIf { it.canRead() }
?.let { pacMan.getPackageArchiveInfo(it.path, PackageManager.GET_META_DATA) }
?.let {
it.applicationInfo.apply {
(it.applicationInfo ?: ApplicationInfo()).apply {
sourceDir = file.path
publicSourceDir = file.path
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.debug.logging.logTag
import eu.darken.sdmse.common.debug.recorder.ui.RecorderActivity
import eu.darken.sdmse.common.flow.DynamicStateFlow
import eu.darken.sdmse.common.getPackageInfo
import eu.darken.sdmse.common.startServiceCompat
import eu.darken.sdmse.main.core.CurriculumVitae
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -141,7 +142,7 @@ class RecorderModule @Inject constructor(
}

private suspend fun logInfos() {
val pkgInfo = context.packageManager.getPackageInfo(context.packageName, 0)!!
val pkgInfo = context.getPackageInfo()
log(TAG, INFO) { "APILEVEL: ${BuildWrap.VERSION.SDK_INT}" }
log(TAG, INFO) { "Build.FINGERPRINT: ${BuildWrap.FINGERPRINT}" }
log(TAG, INFO) { "Build.MANUFACTOR: ${Build.MANUFACTURER}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import eu.darken.sdmse.common.debug.logging.Logging.Priority.VERBOSE
import eu.darken.sdmse.common.debug.logging.Logging.Priority.WARN
import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.debug.logging.logTag
import eu.darken.sdmse.common.getPackageInfo
import io.github.z4kn4fein.semver.Version
import io.github.z4kn4fein.semver.VersionFormatException
import kotlinx.coroutines.CoroutineScope
Expand All @@ -36,7 +37,7 @@ class CurriculumVitae @Inject constructor(
private val dataStore: DataStore<Preferences>
get() = context.dataStore

private val usPkgInfo: PackageInfo by lazy { context.packageManager.getPackageInfo(context.packageName, 0) }
private val usPkgInfo: PackageInfo by lazy { context.getPackageInfo() }

private val _updateHistory = dataStore.createValue("stats.update.history", emptyList<String>(), moshi)
private val _installedFirst = dataStore.createValue<Instant?>("stats.install.first", null, moshi)
Expand Down Expand Up @@ -100,7 +101,7 @@ class CurriculumVitae @Inject constructor(
log(TAG) { "Current version history is $history" }

val lastVersion = history.lastOrNull()
val current = usPkgInfo.versionName
val current = usPkgInfo.versionName!!
if (lastVersion != current) {
val versionHistory = history + current
log(TAG) { "Update happened, new version history is $versionHistory" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import eu.darken.sdmse.common.debug.logging.Logging.Priority.ERROR
import eu.darken.sdmse.common.debug.logging.Logging.Priority.INFO
import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.debug.logging.logTag
import eu.darken.sdmse.common.getPackageInfo
import eu.darken.sdmse.main.core.CurriculumVitae
import io.github.z4kn4fein.semver.Version
import io.github.z4kn4fein.semver.VersionFormatException
Expand All @@ -23,7 +24,7 @@ class ReleaseManager @Inject constructor(
) {

private val ourVersion: Version by lazy {
val versionName = context.packageManager.getPackageInfo(context.packageName, 0).versionName
val versionName = context.getPackageInfo().versionName!!
try {
Version.parse(versionName, strict = false).also { log(TAG) { "Current version is $it" } }
} catch (e: VersionFormatException) {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="Theme.Material3.DynamicColors.Dark.NoActionBar" parent="Theme.Material3.DynamicColors.Dark">
<item name="windowActionBar">false</item>
Expand Down Expand Up @@ -44,6 +44,8 @@
<item name="colorPrimaryInverse">@color/md_theme_dark_inversePrimary</item>

<item name="dynamicColorThemeOverlay">@style/Theme.Material3.DynamicColors.Dark.NoActionBar</item>

<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:ignore="NewApi">true</item>
</style>

<style name="AppThemeFloating" parent="BaseAppTheme">
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="Theme.Material3.DynamicColors.Light.NoActionBar" parent="Theme.Material3.DynamicColors.Light">
<item name="windowActionBar">false</item>
Expand Down Expand Up @@ -44,6 +44,8 @@
<item name="colorPrimaryInverse">@color/md_theme_light_inversePrimary</item>

<item name="dynamicColorThemeOverlay">@style/Theme.Material3.DynamicColors.Light.NoActionBar</item>

<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:ignore="NewApi">true</item>
</style>

<style name="AppTheme" parent="BaseAppTheme">
Expand Down
6 changes: 4 additions & 2 deletions buildSrc/src/main/java/ProjectConfigPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ open class ProjectConfig {
val packageName = "eu.darken.sdmse"
val minSdk = 26

val compileSdk = 34
val targetSdk = 34
val compileSdk = 35
val compileSdkPreview: String? = null
val targetSdk = 35
val targetSdkPreview: String? = null

lateinit var version: Version

Expand Down
6 changes: 5 additions & 1 deletion buildSrc/src/main/java/ProjectExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ private fun LibraryExtension.kotlinOptions(configure: Action<KotlinJvmOptions>):
(this as org.gradle.api.plugins.ExtensionAware).extensions.configure("kotlinOptions", configure)

fun LibraryExtension.setupLibraryDefaults(projectConfig: ProjectConfig) {
compileSdk = projectConfig.compileSdk
if (projectConfig.compileSdkPreview != null) {
compileSdkPreview = projectConfig.compileSdkPreview
} else {
compileSdk = projectConfig.compileSdk
}

defaultConfig {
minSdk = projectConfig.minSdk
Expand Down
Loading