From e58945a20934a99dfc5e570314ff66269e091960 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 10 Aug 2022 21:53:47 +0200 Subject: [PATCH] Log extension loading errors directly (#7716) (cherry picked from commit 7892cc1519ef0ecf0dc0b519a0df8806eba05e99) --- .../tachiyomi/extension/model/LoadResult.kt | 4 +--- .../util/ExtensionInstallReceiver.kt | 7 ++++++- .../extension/util/ExtensionLoader.kt | 21 ++++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/model/LoadResult.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/model/LoadResult.kt index 0cf470fe8..f1982b2f2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/model/LoadResult.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/model/LoadResult.kt @@ -4,7 +4,5 @@ sealed class LoadResult { class Success(val extension: Extension.Installed) : LoadResult() class Untrusted(val extension: Extension.Untrusted) : LoadResult() - class Error(val message: String? = null) : LoadResult() { - constructor(exception: Throwable) : this(exception.message) - } + object Error : LoadResult() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt index 943e82845..08bea8ff9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallReceiver.kt @@ -7,10 +7,12 @@ import android.content.IntentFilter import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.LoadResult import eu.kanade.tachiyomi.util.lang.launchNow +import eu.kanade.tachiyomi.util.system.logcat import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.async +import logcat.LogPriority /** * Broadcast receiver that listens for the system's packages installed, updated or removed, and only @@ -94,7 +96,10 @@ internal class ExtensionInstallReceiver(private val listener: Listener) : */ private suspend fun getExtensionFromIntent(context: Context, intent: Intent?): LoadResult { val pkgName = getPackageNameFromIntent(intent) - ?: return LoadResult.Error("Package name not found") + if (pkgName == null) { + logcat(LogPriority.WARN) { "Package name not found" } + return LoadResult.Error + } return GlobalScope.async(Dispatchers.Default, CoroutineStart.DEFAULT) { ExtensionLoader.loadExtensionFromPkgName(context, pkgName) }.await() } 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 240cb1f65..6d5f763bc 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 @@ -80,10 +80,12 @@ internal object ExtensionLoader { context.packageManager.getPackageInfo(pkgName, PACKAGE_FLAGS) } catch (error: PackageManager.NameNotFoundException) { // Unlikely, but the package may have been uninstalled at this point - return LoadResult.Error(error) + logcat(LogPriority.ERROR, error) + return LoadResult.Error } if (!isPackageAnExtension(pkgInfo)) { - return LoadResult.Error("Tried to load a package that wasn't a extension") + logcat(LogPriority.WARN) { "Tried to load a package that wasn't a extension ($pkgName)" } + return LoadResult.Error } return loadExtension(context, pkgName, pkgInfo) } @@ -102,7 +104,8 @@ internal object ExtensionLoader { pkgManager.getApplicationInfo(pkgName, PackageManager.GET_META_DATA) } catch (error: PackageManager.NameNotFoundException) { // Unlikely, but the package may have been uninstalled at this point - return LoadResult.Error(error) + logcat(LogPriority.ERROR, error) + return LoadResult.Error } val extName = pkgManager.getApplicationLabel(appInfo).toString().substringAfter("Tachiyomi: ") @@ -112,7 +115,7 @@ internal object ExtensionLoader { if (versionName.isNullOrEmpty()) { val exception = Exception("Missing versionName for extension $extName") logcat(LogPriority.WARN, exception) - return LoadResult.Error(exception) + return LoadResult.Error } // Validate lib version @@ -123,13 +126,14 @@ internal object ExtensionLoader { "$LIB_VERSION_MIN to $LIB_VERSION_MAX are allowed", ) logcat(LogPriority.WARN, exception) - return LoadResult.Error(exception) + return LoadResult.Error } val signatureHash = getSignatureHash(pkgInfo) if (signatureHash == null) { - return LoadResult.Error("Package $pkgName isn't signed") + logcat(LogPriority.WARN) { "Package $pkgName isn't signed" } + return LoadResult.Error } else if (signatureHash !in trustedSignatures) { val extension = Extension.Untrusted(extName, pkgName, versionName, versionCode, signatureHash) logcat(LogPriority.WARN) { "Extension $pkgName isn't trusted" } @@ -138,7 +142,8 @@ internal object ExtensionLoader { val isNsfw = appInfo.metaData.getInt(METADATA_NSFW) == 1 if (!loadNsfwSource && isNsfw) { - return LoadResult.Error("NSFW extension $pkgName not allowed") + logcat(LogPriority.WARN) { "NSFW extension $pkgName not allowed" } + return LoadResult.Error } val hasReadme = appInfo.metaData.getInt(METADATA_HAS_README, 0) == 1 @@ -165,7 +170,7 @@ internal object ExtensionLoader { } } catch (e: Throwable) { logcat(LogPriority.ERROR, e) { "Extension load error: $extName ($it)" } - return LoadResult.Error(e) + return LoadResult.Error } }