diff --git a/app/src/main/java/ani/dantotsu/App.kt b/app/src/main/java/ani/dantotsu/App.kt index 158d6f5ff2b..e30179bcf0b 100644 --- a/app/src/main/java/ani/dantotsu/App.kt +++ b/app/src/main/java/ani/dantotsu/App.kt @@ -38,8 +38,8 @@ import logcat.AndroidLogcatLogger import logcat.LogPriority import logcat.LogcatLogger import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.addSingletonFactory import uy.kohesive.injekt.api.get -import java.lang.IllegalStateException @SuppressLint("StaticFieldLeak") @@ -64,13 +64,19 @@ class App : MultiDexApplication() { @OptIn(DelicateCoroutinesApi::class) override fun onCreate() { super.onCreate() - PrefManager.init(this) + + val crashlytics = + ani.dantotsu.connections.crashlytics.CrashlyticsFactory.createCrashlytics() + Injekt.addSingletonFactory { crashlytics } + crashlytics.initialize(this) + Logger.init(this) + Thread.setDefaultUncaughtExceptionHandler(FinalExceptionHandler()) + Logger.log(Log.WARN, "App: Logging started") + Injekt.importModule(AppModule(this)) Injekt.importModule(PreferenceModule(this)) - val crashlytics = Injekt.get() - crashlytics.initialize(this) val useMaterialYou: Boolean = PrefManager.getVal(PrefName.UseMaterialYou) if (useMaterialYou) { @@ -92,10 +98,6 @@ class App : MultiDexApplication() { } crashlytics.setCustomKey("device Info", SettingsActivity.getDeviceInfo()) - Logger.init(this) - Thread.setDefaultUncaughtExceptionHandler(FinalExceptionHandler()) - Logger.log(Log.WARN, "App: Logging started") - initializeNetwork() setupNotificationChannels() @@ -154,6 +156,7 @@ class App : MultiDexApplication() { override fun onActivityCreated(p0: Activity, p1: Bundle?) { lastActivity = p0.javaClass.simpleName } + override fun onActivityStarted(p0: Activity) { currentActivity = p0 } diff --git a/app/src/main/java/ani/dantotsu/aniyomi/anime/custom/InjektModules.kt b/app/src/main/java/ani/dantotsu/aniyomi/anime/custom/InjektModules.kt index 0f92966be3e..8f8c4bdac14 100644 --- a/app/src/main/java/ani/dantotsu/aniyomi/anime/custom/InjektModules.kt +++ b/app/src/main/java/ani/dantotsu/aniyomi/anime/custom/InjektModules.kt @@ -60,10 +60,6 @@ class AppModule(val app: Application) : InjektModule { addSingletonFactory { StandaloneDatabaseProvider(app) } - addSingletonFactory { - ani.dantotsu.connections.crashlytics.CrashlyticsFactory.createCrashlytics() - } - addSingletonFactory { MangaCache() } ContextCompat.getMainExecutor(app).execute { 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 d7b454a18c6..268cfa98033 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 @@ -5,6 +5,7 @@ import android.content.pm.PackageInfo import android.content.pm.PackageManager import android.os.Build import androidx.core.content.pm.PackageInfoCompat +import ani.dantotsu.connections.crashlytics.CrashlyticsInterface import ani.dantotsu.media.MediaType import ani.dantotsu.parsers.NovelInterface import ani.dantotsu.parsers.novel.NovelExtension @@ -26,6 +27,8 @@ import eu.kanade.tachiyomi.util.lang.Hash import eu.kanade.tachiyomi.util.system.getApplicationIcon import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy import java.util.Locale @@ -255,22 +258,6 @@ internal object ExtensionLoader { val signatureHash = getSignatureHash(pkgInfo) - if (signatureHash == null) { - Logger.log("Package $pkgName isn't signed") - return AnimeLoadResult.Error - } else if (signatureHash !in trustedSignaturesAnime) { - val extension = AnimeExtension.Untrusted( - extName, - pkgName, - versionName, - versionCode, - libVersion, - signatureHash - ) - Logger.log("Extension $pkgName isn't trusted") - return AnimeLoadResult.Untrusted(extension) - } - val isNsfw = appInfo.metaData.getInt("$ANIME_PACKAGE$XX_METADATA_NSFW") == 1 if (!loadNsfwSource && isNsfw) { Logger.log("NSFW extension $pkgName not allowed") @@ -281,7 +268,13 @@ internal object ExtensionLoader { val hasChangelog = appInfo.metaData.getInt("$ANIME_PACKAGE$XX_METADATA_HAS_CHANGELOG", 0) == 1 - val classLoader = PathClassLoader(appInfo.sourceDir, null, context.classLoader) + val classLoader = try{ + PathClassLoader(appInfo.sourceDir, null, context.classLoader) + } catch (e: Throwable) { + Logger.log("Extension load error: $extName") + Injekt.get().logException(e) + return AnimeLoadResult.Error + } val sources = appInfo.metaData.getString("$ANIME_PACKAGE$XX_METADATA_SOURCE_CLASS")!! .split(";") @@ -371,17 +364,6 @@ internal object ExtensionLoader { val signatureHash = getSignatureHash(pkgInfo) - /* temporarily disabling signature check TODO: remove? - if (signatureHash == null) { - Logger.log("Package $pkgName isn't signed") - return MangaLoadResult.Error - } else if (signatureHash !in trustedSignatures) { - val extension = MangaExtension.Untrusted(extName, pkgName, versionName, versionCode, libVersion, signatureHash) - Logger.log("Extension $pkgName isn't trusted") - return MangaLoadResult.Untrusted(extension) - } - */ - val isNsfw = appInfo.metaData.getInt("$MANGA_PACKAGE$XX_METADATA_NSFW") == 1 if (!loadNsfwSource && isNsfw) { Logger.log("NSFW extension $pkgName not allowed") @@ -392,7 +374,13 @@ internal object ExtensionLoader { val hasChangelog = appInfo.metaData.getInt("$MANGA_PACKAGE$XX_METADATA_HAS_CHANGELOG", 0) == 1 - val classLoader = PathClassLoader(appInfo.sourceDir, null, context.classLoader) + val classLoader = try{ + PathClassLoader(appInfo.sourceDir, null, context.classLoader) + } catch (e: Throwable) { + Logger.log("Extension load error: $extName") + Injekt.get().logException(e) + return MangaLoadResult.Error + } val sources = appInfo.metaData.getString("$MANGA_PACKAGE$XX_METADATA_SOURCE_CLASS")!! .split(";")