From 7eb7c2567afb0cb700cb9451876a1f05ab65e7e3 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Mon, 9 Oct 2023 03:47:14 +0600 Subject: [PATCH] Address some warnings and deprecations (#18436) * Address some warnings and deprecations * Add back `AndroidConfig.targetSdk` --- build.gradle.kts | 2 +- buildSrc/src/main/kotlin/AndroidConfig.kt | 1 + core/build.gradle.kts | 1 + lib/cryptoaes/build.gradle.kts | 1 - .../tachiyomi/lib/cryptoaes/CryptoAES.kt | 10 +++++----- .../tachiyomi/lib/cryptoaes/Deobfuscator.kt | 8 ++++---- lib/dataimage/build.gradle.kts | 1 - lib/i18n/build.gradle.kts | 1 - .../java/eu/kanade/tachiyomi/lib/i18n/Intl.kt | 8 ++++---- lib/randomua/build.gradle.kts | 1 - lib/synchrony/build.gradle.kts | 1 - .../tachiyomi/lib/synchrony/Deobfuscator.kt | 1 - lib/textinterceptor/build.gradle.kts | 1 - .../lib/textinterceptor/TextInterceptor.kt | 18 +++++++++++------- multisrc/build.gradle.kts | 2 +- 15 files changed, 28 insertions(+), 29 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b3b8f26ca..b2e8c87e3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,5 +21,5 @@ allprojects { } tasks.register("clean") { - delete(rootProject.buildDir) + delete(rootProject.layout.buildDirectory.asFile.get()) } diff --git a/buildSrc/src/main/kotlin/AndroidConfig.kt b/buildSrc/src/main/kotlin/AndroidConfig.kt index 39f2ab038..ac6d1d01e 100644 --- a/buildSrc/src/main/kotlin/AndroidConfig.kt +++ b/buildSrc/src/main/kotlin/AndroidConfig.kt @@ -1,5 +1,6 @@ object AndroidConfig { const val compileSdk = 34 const val minSdk = 21 + @Suppress("UNUSED") const val targetSdk = 34 } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index d3e951c3e..e3948945d 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -11,6 +11,7 @@ android { namespace = "eu.kanade.tachiyomi.extension" + @Suppress("UnstableApiUsage") sourceSets { named("main") { manifest.srcFile("AndroidManifest.xml") diff --git a/lib/cryptoaes/build.gradle.kts b/lib/cryptoaes/build.gradle.kts index caabcb291..a9c8a57c6 100644 --- a/lib/cryptoaes/build.gradle.kts +++ b/lib/cryptoaes/build.gradle.kts @@ -8,7 +8,6 @@ android { defaultConfig { minSdk = AndroidConfig.minSdk - targetSdk = AndroidConfig.targetSdk } namespace = "eu.kanade.tachiyomi.lib.cryptoaes" diff --git a/lib/cryptoaes/src/main/java/eu/kanade/tachiyomi/lib/cryptoaes/CryptoAES.kt b/lib/cryptoaes/src/main/java/eu/kanade/tachiyomi/lib/cryptoaes/CryptoAES.kt index 808758439..43594c247 100644 --- a/lib/cryptoaes/src/main/java/eu/kanade/tachiyomi/lib/cryptoaes/CryptoAES.kt +++ b/lib/cryptoaes/src/main/java/eu/kanade/tachiyomi/lib/cryptoaes/CryptoAES.kt @@ -11,7 +11,6 @@ import javax.crypto.spec.SecretKeySpec /** * Conforming with CryptoJS AES method */ -@Suppress("unused", "FunctionName") object CryptoAES { private const val KEY_SIZE = 256 @@ -29,17 +28,17 @@ object CryptoAES { * @param password passphrase */ fun decrypt(cipherText: String, password: String): String { - try { + return try { val ctBytes = Base64.decode(cipherText, Base64.DEFAULT) val saltBytes = Arrays.copyOfRange(ctBytes, 8, 16) val cipherTextBytes = Arrays.copyOfRange(ctBytes, 16, ctBytes.size) val md5: MessageDigest = MessageDigest.getInstance("MD5") val keyAndIV = generateKeyAndIV(32, 16, 1, saltBytes, password.toByteArray(Charsets.UTF_8), md5) - return decryptAES(cipherTextBytes, + decryptAES(cipherTextBytes, keyAndIV?.get(0) ?: ByteArray(32), keyAndIV?.get(1) ?: ByteArray(16)) } catch (e: Exception) { - return "" + "" } } @@ -93,6 +92,7 @@ object CryptoAES { * @param md the message digest algorithm to use * @return an two-element array with the generated key and IV */ + @Suppress("SameParameterValue") private fun generateKeyAndIV(keyLength: Int, ivLength: Int, iterations: Int, salt: ByteArray, password: ByteArray, md: MessageDigest): Array? { val digestLength = md.digestLength val requiredLength = (keyLength + ivLength + digestLength - 1) / digestLength * digestLength @@ -107,7 +107,7 @@ object CryptoAES { // Digest data (last digest if available, password data, salt if available) if (generatedLength > 0) md.update(generatedData, generatedLength - digestLength, digestLength) md.update(password) - if (salt != null) md.update(salt, 0, 8) + md.update(salt, 0, 8) md.digest(generatedData, generatedLength, digestLength) // additional rounds diff --git a/lib/cryptoaes/src/main/java/eu/kanade/tachiyomi/lib/cryptoaes/Deobfuscator.kt b/lib/cryptoaes/src/main/java/eu/kanade/tachiyomi/lib/cryptoaes/Deobfuscator.kt index e1edf4843..70f1c4227 100644 --- a/lib/cryptoaes/src/main/java/eu/kanade/tachiyomi/lib/cryptoaes/Deobfuscator.kt +++ b/lib/cryptoaes/src/main/java/eu/kanade/tachiyomi/lib/cryptoaes/Deobfuscator.kt @@ -9,8 +9,8 @@ package eu.kanade.tachiyomi.lib.cryptoaes object Deobfuscator { fun deobfuscateJsPassword(inputString: String): String { var idx = 0 - val brackets = listOf('[', '(') - var evaluatedString = StringBuilder() + val brackets = listOf('[', '(') + val evaluatedString = StringBuilder() while (idx < inputString.length) { val chr = inputString[idx] if (chr !in brackets) { @@ -60,9 +60,9 @@ object Deobfuscator { therefore '!+[]' count equals the digit if count equals 0, check for '+[]' just to be sure */ - val digit = "\\!\\+\\[\\]".toRegex().findAll(inputSubString).count() // matches '!+[]' + val digit = "!\\+\\[]".toRegex().findAll(inputSubString).count() // matches '!+[]' if (digit == 0) { - if ("\\+\\[\\]".toRegex().findAll(inputSubString).count() == 1) { // matches '+[]' + if ("\\+\\[]".toRegex().findAll(inputSubString).count() == 1) { // matches '+[]' return '0' } } else if (digit in 1..9) { diff --git a/lib/dataimage/build.gradle.kts b/lib/dataimage/build.gradle.kts index d5fcea1df..eebbf7808 100644 --- a/lib/dataimage/build.gradle.kts +++ b/lib/dataimage/build.gradle.kts @@ -8,7 +8,6 @@ android { defaultConfig { minSdk = AndroidConfig.minSdk - targetSdk = AndroidConfig.targetSdk } namespace = "eu.kanade.tachiyomi.lib.dataimage" diff --git a/lib/i18n/build.gradle.kts b/lib/i18n/build.gradle.kts index 4a741aa0a..f21bb7314 100644 --- a/lib/i18n/build.gradle.kts +++ b/lib/i18n/build.gradle.kts @@ -8,7 +8,6 @@ android { defaultConfig { minSdk = AndroidConfig.minSdk - targetSdk = AndroidConfig.targetSdk } namespace = "eu.kanade.tachiyomi.lib.i18n" diff --git a/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt b/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt index aa6e9bf12..cdb02f5ff 100644 --- a/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt +++ b/lib/i18n/src/main/java/eu/kanade/tachiyomi/lib/i18n/Intl.kt @@ -1,10 +1,8 @@ package eu.kanade.tachiyomi.lib.i18n -import org.jetbrains.annotations.NonNls import org.jetbrains.annotations.PropertyKey import java.io.InputStreamReader import java.text.Collator -import java.text.MessageFormat import java.util.Locale import java.util.PropertyResourceBundle @@ -23,9 +21,9 @@ import java.util.PropertyResourceBundle * on how to do so. */ class Intl( - private val language: String, + language: String, + availableLanguages: Set, private val baseLanguage: String, - private val availableLanguages: Set, private val classLoader: ClassLoader, private val createMessageFileName: (String) -> String = { createDefaultMessageFileName(it) } ) { @@ -50,6 +48,7 @@ class Intl( * in the current language, the English value will be returned. If the [key] * is also not present in English, the [key] surrounded by brackets will be returned. */ + @Suppress("InvalidBundleOrProperty") operator fun get(@PropertyKey(resourceBundle = "i18n.messages") key: String): String = when { bundle.containsKey(key) -> bundle.getString(key) baseBundle.containsKey(key) -> baseBundle.getString(key) @@ -60,6 +59,7 @@ class Intl( * Uses the string as a format string and returns a string obtained by * substituting the specified arguments, using the instance locale. */ + @Suppress("InvalidBundleOrProperty") fun format(@PropertyKey(resourceBundle = "i18n.messages") key: String, vararg args: Any?) = get(key).format(locale, *args) diff --git a/lib/randomua/build.gradle.kts b/lib/randomua/build.gradle.kts index 39942da28..36ef0d678 100644 --- a/lib/randomua/build.gradle.kts +++ b/lib/randomua/build.gradle.kts @@ -9,7 +9,6 @@ android { defaultConfig { minSdk = AndroidConfig.minSdk - targetSdk = AndroidConfig.targetSdk } namespace = "eu.kanade.tachiyomi.lib.randomua" diff --git a/lib/synchrony/build.gradle.kts b/lib/synchrony/build.gradle.kts index d53ef825e..c178641a2 100644 --- a/lib/synchrony/build.gradle.kts +++ b/lib/synchrony/build.gradle.kts @@ -8,7 +8,6 @@ android { defaultConfig { minSdk = AndroidConfig.minSdk - targetSdk = AndroidConfig.targetSdk } namespace = "eu.kanade.tachiyomi.lib.synchrony" diff --git a/lib/synchrony/src/main/java/eu/kanade/tachiyomi/lib/synchrony/Deobfuscator.kt b/lib/synchrony/src/main/java/eu/kanade/tachiyomi/lib/synchrony/Deobfuscator.kt index a32b6f89d..f85a43cdf 100644 --- a/lib/synchrony/src/main/java/eu/kanade/tachiyomi/lib/synchrony/Deobfuscator.kt +++ b/lib/synchrony/src/main/java/eu/kanade/tachiyomi/lib/synchrony/Deobfuscator.kt @@ -33,7 +33,6 @@ object Deobfuscator { } } - @Suppress("unused") private interface TestInterface { fun getValue(): String } diff --git a/lib/textinterceptor/build.gradle.kts b/lib/textinterceptor/build.gradle.kts index aa5a1762c..f7102a8a4 100644 --- a/lib/textinterceptor/build.gradle.kts +++ b/lib/textinterceptor/build.gradle.kts @@ -8,7 +8,6 @@ android { defaultConfig { minSdk = AndroidConfig.minSdk - targetSdk = AndroidConfig.targetSdk } namespace = "eu.kanade.tachiyomi.lib.textinterceptor" diff --git a/lib/textinterceptor/src/main/java/eu/kanade/tachiyomi/lib/textinterceptor/TextInterceptor.kt b/lib/textinterceptor/src/main/java/eu/kanade/tachiyomi/lib/textinterceptor/TextInterceptor.kt index b614c03b9..d1b6fd98f 100644 --- a/lib/textinterceptor/src/main/java/eu/kanade/tachiyomi/lib/textinterceptor/TextInterceptor.kt +++ b/lib/textinterceptor/src/main/java/eu/kanade/tachiyomi/lib/textinterceptor/TextInterceptor.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.lib.textinterceptor +import android.annotation.SuppressLint import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color @@ -53,7 +54,7 @@ class TextInterceptor : Interceptor { } @Suppress("DEPRECATION") - val heading: StaticLayout = StaticLayout( + val heading = StaticLayout( creator, paintHeading, (WIDTH - 2 * X_PADDING).toInt(), Layout.Alignment.ALIGN_NORMAL, SPACING_MULT, SPACING_ADD, true ) @@ -67,7 +68,7 @@ class TextInterceptor : Interceptor { } @Suppress("DEPRECATION") - val body: StaticLayout = StaticLayout( + val body = StaticLayout( story, paintBody, (WIDTH - 2 * X_PADDING).toInt(), Layout.Alignment.ALIGN_NORMAL, SPACING_MULT, SPACING_ADD, true ) @@ -75,12 +76,12 @@ class TextInterceptor : Interceptor { // Image building val imgHeight: Int = (heading.height + body.height + 2 * Y_PADDING).toInt() val bitmap: Bitmap = Bitmap.createBitmap(WIDTH, imgHeight, Bitmap.Config.ARGB_8888) - val canvas: Canvas = Canvas(bitmap) - // Image drawing - canvas.drawColor(Color.WHITE) - heading.draw(canvas, X_PADDING, Y_PADDING) - body.draw(canvas, X_PADDING, Y_PADDING + heading.height.toFloat()) + Canvas(bitmap).apply { + drawColor(Color.WHITE) + heading.draw(this, X_PADDING, Y_PADDING) + body.draw(this, X_PADDING, Y_PADDING + heading.height.toFloat()) + } // Image converting & returning val stream = ByteArrayOutputStream() @@ -95,14 +96,17 @@ class TextInterceptor : Interceptor { .build() } + @SuppressLint("ObsoleteSdkInt") private fun textFixer(htmlString: String): String { return if (Build.VERSION.SDK_INT >= 24) { Html.fromHtml(htmlString , Html.FROM_HTML_MODE_LEGACY).toString() } else { + @Suppress("DEPRECATION") Html.fromHtml(htmlString).toString() } } + @Suppress("SameParameterValue") private fun StaticLayout.draw(canvas: Canvas, x: Float, y: Float) { canvas.save() canvas.translate(x, y) diff --git a/multisrc/build.gradle.kts b/multisrc/build.gradle.kts index 511012eff..7b2948f27 100644 --- a/multisrc/build.gradle.kts +++ b/multisrc/build.gradle.kts @@ -9,7 +9,6 @@ android { defaultConfig { minSdk = 29 - targetSdk = AndroidConfig.targetSdk } namespace = "eu.kanade.tachiyomi.lib.themesources" @@ -42,6 +41,7 @@ dependencies { tasks { register("generateExtensions") { + val buildDir = layout.buildDirectory.asFile.get() classpath = configurations.compileOnly.get() + configurations.androidApis.get() + // android.jar path files("$buildDir/intermediates/aar_main_jar/debug/classes.jar") // jar made from this module