diff --git a/core/runtime/api/runtime.api b/core/runtime/api/runtime.api index 0443a3df..2592ef0d 100644 --- a/core/runtime/api/runtime.api +++ b/core/runtime/api/runtime.api @@ -21,7 +21,7 @@ public final class dev/teogor/ceres/core/runtime/AppMetadataManager { public final fun getPackageManager ()Landroid/content/pm/PackageManager; public final fun getPackageName ()Ljava/lang/String; public final fun getSanitizedPackageName ()Ljava/lang/String; - public final fun getVersionCode ()I + public final fun getVersionCode ()J public final fun getVersionName ()Ljava/lang/String; public final fun getZoneOffset ()Ljava/time/ZoneOffset; public final fun isDebuggable ()Z diff --git a/core/runtime/build.gradle.kts b/core/runtime/build.gradle.kts index 8353b1a4..38f6f10c 100644 --- a/core/runtime/build.gradle.kts +++ b/core/runtime/build.gradle.kts @@ -28,6 +28,7 @@ android { dependencies { api(project(":core:startup")) + api(project(":core:foundation")) } ceresLibrary { diff --git a/core/runtime/src/main/kotlin/dev/teogor/ceres/core/runtime/AppMetadataManager.kt b/core/runtime/src/main/kotlin/dev/teogor/ceres/core/runtime/AppMetadataManager.kt index 16f1d255..c2761bf7 100644 --- a/core/runtime/src/main/kotlin/dev/teogor/ceres/core/runtime/AppMetadataManager.kt +++ b/core/runtime/src/main/kotlin/dev/teogor/ceres/core/runtime/AppMetadataManager.kt @@ -18,12 +18,9 @@ package dev.teogor.ceres.core.runtime import android.content.pm.PackageInfo import android.content.pm.PackageManager -import android.os.Build -import android.os.Build.VERSION -import android.os.Build.VERSION_CODES import android.util.Base64 import dev.teogor.ceres.core.android.config.BuildConfig -import dev.teogor.ceres.core.runtime.AppMetadataManager.AppMetadataManagerImpl.getPackageInfoCompat +import dev.teogor.ceres.core.foundation.packageManagerUtils import dev.teogor.ceres.core.startup.ApplicationContextProvider import java.io.File import java.io.FileInputStream @@ -55,21 +52,16 @@ object AppMetadataManager { } val packageManager: PackageManager - get() = ApplicationContextProvider.context.packageManager + get() = ApplicationContextProvider.context.packageManagerUtils().packageManager val packageInfo: PackageInfo - get() = packageManager.getPackageInfoCompat(packageName) + get() = ApplicationContextProvider.context.packageManagerUtils().packageInfo val versionName: String - get() = packageInfo.versionName + get() = ApplicationContextProvider.context.packageManagerUtils().versionName - val versionCode: Int - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - packageInfo.longVersionCode.toInt() - } else { - @Suppress("DEPRECATION") - packageInfo.versionCode - } + val versionCode: Long + get() = ApplicationContextProvider.context.packageManagerUtils().versionCode val zoneOffset = ZoneId.systemDefault().rules.getOffset(LocalDateTime.now()) val buildDateTime = LocalDateTime.ofEpochSecond( @@ -110,16 +102,4 @@ object AppMetadataManager { } return null } - - private object AppMetadataManagerImpl { - fun PackageManager.getPackageInfoCompat( - packageName: String, - flags: Int = 0, - ): PackageInfo = if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) { - getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong())) - } else { - // @Suppress("DEPRECATION") - getPackageInfo(packageName, flags) - } - } } diff --git a/firebase/crashlytics/build.gradle.kts b/firebase/crashlytics/build.gradle.kts index a753c38b..2b315a8c 100644 --- a/firebase/crashlytics/build.gradle.kts +++ b/firebase/crashlytics/build.gradle.kts @@ -28,6 +28,8 @@ android { } dependencies { + implementation(project(":core:foundation")) + implementation(libs.firebase.crashlytics) implementation(platform(libs.firebase.bom)) diff --git a/firebase/crashlytics/src/main/kotlin/dev/teogor/ceres/firebase/crashlytics/CrashlyticsManager.kt b/firebase/crashlytics/src/main/kotlin/dev/teogor/ceres/firebase/crashlytics/CrashlyticsManager.kt index d3c08cd6..50c623f8 100644 --- a/firebase/crashlytics/src/main/kotlin/dev/teogor/ceres/firebase/crashlytics/CrashlyticsManager.kt +++ b/firebase/crashlytics/src/main/kotlin/dev/teogor/ceres/firebase/crashlytics/CrashlyticsManager.kt @@ -30,6 +30,7 @@ import com.google.firebase.crashlytics.CustomKeysAndValues.Builder import com.google.firebase.crashlytics.FirebaseCrashlytics import com.google.firebase.crashlytics.ktx.crashlytics import com.google.firebase.ktx.Firebase +import dev.teogor.ceres.core.foundation.packageManagerUtils import java.util.Locale internal class CrashlyticsManager(context: Context) { @@ -212,14 +213,12 @@ private fun Builder.packageInstaller(context: Context) { } private fun Builder.app(context: Context) { - val packageManager = context.packageManager - val packageName = context.packageName + val packageManagerUtils = context.packageManagerUtils() + val packageManager = packageManagerUtils.packageManager + val packageName = packageManagerUtils.packageName + val packageSignatures = packageManagerUtils.packageSignatures - val packageInfoSignatures = packageManager.getPackageInfo( - packageName, - PackageManager.GET_SIGNATURES, - ) - val signatures = packageInfoSignatures.signatures.joinToString(", ") { signature -> + val signatures = packageSignatures.apkContentsSigners.joinToString(", ") { signature -> signature.toCharsString() } putString("app_signatures", signatures)