From a629db2884c19a0910eacfe0bc5bde33e838e15b Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 14 Jul 2023 23:08:45 -0400 Subject: [PATCH] Address some build warnings --- .../extension/util/ExtensionLoader.kt | 22 +++++++++---------- .../util/system/ContextExtensions.kt | 1 - .../util/system/DisplayExtensions.kt | 11 ---------- .../tachiyomi/network/JavaScriptEngine.kt | 2 +- .../core/components/material/Tabs.kt | 6 ++--- 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt index 02246a30d2..e8dbe23ec6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt @@ -41,7 +41,12 @@ internal object ExtensionLoader { const val LIB_VERSION_MIN = 1.3 const val LIB_VERSION_MAX = 1.5 - private const val PACKAGE_FLAGS = PackageManager.GET_CONFIGURATIONS or PackageManager.GET_SIGNATURES + private val PACKAGE_FLAGS = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + PackageManager.GET_CONFIGURATIONS or PackageManager.GET_SIGNING_CERTIFICATES + } else { + @Suppress("DEPRECATION") + PackageManager.GET_CONFIGURATIONS or PackageManager.GET_SIGNATURES + } // inorichi's key private const val officialSignature = "7ce04da7773d41b489f4693a366c36bcd0a11fc39b547168553c285bd7348e23" @@ -49,7 +54,7 @@ internal object ExtensionLoader { /** * List of the trusted signatures. */ - var trustedSignatures = mutableSetOf() + preferences.trustedSignatures().get() + officialSignature + var trustedSignatures = mutableSetOf(officialSignature) + preferences.trustedSignatures().get() /** * Return a list of all the installed extensions initialized concurrently. @@ -59,7 +64,6 @@ internal object ExtensionLoader { fun loadExtensions(context: Context): List { val pkgManager = context.packageManager - @Suppress("DEPRECATION") val installedPkgs = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { pkgManager.getInstalledPackages(PackageManager.PackageInfoFlags.of(PACKAGE_FLAGS.toLong())) } else { @@ -135,7 +139,7 @@ internal object ExtensionLoader { return LoadResult.Error } - val signatureHash = getSignatureHash(pkgInfo) + val signatureHash = getSignatureHash(context, pkgInfo) if (signatureHash == null) { logcat(LogPriority.WARN) { "Package $pkgName isn't signed" } return LoadResult.Error @@ -220,12 +224,8 @@ internal object ExtensionLoader { * * @param pkgInfo The package info of the application. */ - private fun getSignatureHash(pkgInfo: PackageInfo): String? { - val signatures = pkgInfo.signatures - return if (signatures != null && signatures.isNotEmpty()) { - Hash.sha256(signatures.first().toByteArray()) - } else { - null - } + private fun getSignatureHash(context: Context, pkgInfo: PackageInfo): String? { + val signatures = PackageInfoCompat.getSignatures(context.packageManager, pkgInfo.packageName) + return signatures.firstOrNull()?.let { Hash.sha256(it.toByteArray()) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 9124619f8c..8cc74445b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -134,7 +134,6 @@ private fun Context.defaultBrowserPackageName(): String? { val resolveInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { packageManager.resolveActivity(browserIntent, PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong())) } else { - @Suppress("DEPRECATION") packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY) } return resolveInfo diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/DisplayExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/DisplayExtensions.kt index e93905c749..50f45ae85b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/DisplayExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/DisplayExtensions.kt @@ -5,10 +5,7 @@ import android.content.Context import android.content.res.Configuration import android.content.res.Resources import android.os.Build -import android.view.Display import android.view.View -import android.view.WindowManager -import androidx.core.content.getSystemService import eu.kanade.domain.ui.UiPreferences import eu.kanade.domain.ui.model.TabletUiMode import uy.kohesive.injekt.Injekt @@ -67,14 +64,6 @@ fun Context.isNightMode(): Boolean { return resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES } -val Context.displayCompat: Display? - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - display - } else { - @Suppress("DEPRECATION") - getSystemService()?.defaultDisplay - } - val Resources.isLTR get() = configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/JavaScriptEngine.kt b/core/src/main/java/eu/kanade/tachiyomi/network/JavaScriptEngine.kt index 3517d1dc9c..4ecf3e09da 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/JavaScriptEngine.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/JavaScriptEngine.kt @@ -7,6 +7,7 @@ import tachiyomi.core.util.lang.withIOContext /** * Util for evaluating JavaScript in sources. */ +@Suppress("UNUSED", "UNCHECKED_CAST") class JavaScriptEngine(context: Context) { /** @@ -17,7 +18,6 @@ class JavaScriptEngine(context: Context) { * @param script JavaScript to execute. * @return Result of JavaScript code as a primitive type. */ - @Suppress("UNUSED", "UNCHECKED_CAST") suspend fun evaluate(script: String): T = withIOContext { QuickJs.create().use { it.evaluate(script) as T diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt index b76407e601..d547ad8d02 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt @@ -13,7 +13,7 @@ import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.TabPosition -import androidx.compose.material3.TabRowDefaults +import androidx.compose.material3.TabRowDefaults.SecondaryIndicator import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -50,8 +50,8 @@ fun TabIndicator( currentTabPosition: TabPosition, currentPageOffsetFraction: Float, ) { - TabRowDefaults.Indicator( - Modifier + SecondaryIndicator( + modifier = Modifier .tabIndicatorOffset(currentTabPosition, currentPageOffsetFraction) .padding(horizontal = 8.dp) .clip(RoundedCornerShape(topStart = 3.dp, topEnd = 3.dp)),