Address some warnings and deprecations (#18436)

* Address some warnings and deprecations

* Add back `AndroidConfig.targetSdk`
This commit is contained in:
AntsyLich 2023-10-09 03:47:14 +06:00 committed by GitHub
parent 1c8478fcca
commit 7eb7c2567a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 28 additions and 29 deletions

View File

@ -21,5 +21,5 @@ allprojects {
}
tasks.register<Delete>("clean") {
delete(rootProject.buildDir)
delete(rootProject.layout.buildDirectory.asFile.get())
}

View File

@ -1,5 +1,6 @@
object AndroidConfig {
const val compileSdk = 34
const val minSdk = 21
@Suppress("UNUSED")
const val targetSdk = 34
}

View File

@ -11,6 +11,7 @@ android {
namespace = "eu.kanade.tachiyomi.extension"
@Suppress("UnstableApiUsage")
sourceSets {
named("main") {
manifest.srcFile("AndroidManifest.xml")

View File

@ -8,7 +8,6 @@ android {
defaultConfig {
minSdk = AndroidConfig.minSdk
targetSdk = AndroidConfig.targetSdk
}
namespace = "eu.kanade.tachiyomi.lib.cryptoaes"

View File

@ -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<ByteArray?>? {
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

View File

@ -9,8 +9,8 @@ package eu.kanade.tachiyomi.lib.cryptoaes
object Deobfuscator {
fun deobfuscateJsPassword(inputString: String): String {
var idx = 0
val brackets = listOf<Char>('[', '(')
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) {

View File

@ -8,7 +8,6 @@ android {
defaultConfig {
minSdk = AndroidConfig.minSdk
targetSdk = AndroidConfig.targetSdk
}
namespace = "eu.kanade.tachiyomi.lib.dataimage"

View File

@ -8,7 +8,6 @@ android {
defaultConfig {
minSdk = AndroidConfig.minSdk
targetSdk = AndroidConfig.targetSdk
}
namespace = "eu.kanade.tachiyomi.lib.i18n"

View File

@ -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<String>,
private val baseLanguage: String,
private val availableLanguages: Set<String>,
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)

View File

@ -9,7 +9,6 @@ android {
defaultConfig {
minSdk = AndroidConfig.minSdk
targetSdk = AndroidConfig.targetSdk
}
namespace = "eu.kanade.tachiyomi.lib.randomua"

View File

@ -8,7 +8,6 @@ android {
defaultConfig {
minSdk = AndroidConfig.minSdk
targetSdk = AndroidConfig.targetSdk
}
namespace = "eu.kanade.tachiyomi.lib.synchrony"

View File

@ -33,7 +33,6 @@ object Deobfuscator {
}
}
@Suppress("unused")
private interface TestInterface {
fun getValue(): String
}

View File

@ -8,7 +8,6 @@ android {
defaultConfig {
minSdk = AndroidConfig.minSdk
targetSdk = AndroidConfig.targetSdk
}
namespace = "eu.kanade.tachiyomi.lib.textinterceptor"

View File

@ -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)

View File

@ -9,7 +9,6 @@ android {
defaultConfig {
minSdk = 29
targetSdk = AndroidConfig.targetSdk
}
namespace = "eu.kanade.tachiyomi.lib.themesources"
@ -42,6 +41,7 @@ dependencies {
tasks {
register<JavaExec>("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