diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt index b469db7b5b..421cfb191d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.Intent import android.os.Bundle import eu.kanade.tachiyomi.extension.ExtensionManager +import eu.kanade.tachiyomi.util.toast import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -21,7 +22,13 @@ class ExtensionInstallActivity : Activity() { .putExtra(Intent.EXTRA_RETURN_RESULT, true) .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(installIntent, INSTALL_REQUEST_CODE) + try { + startActivityForResult(installIntent, INSTALL_REQUEST_CODE) + } catch (error: Exception) { + // Either install package can't be found (probably bots) or there's a security exception + // with the download manager. Nothing we can workaround. + toast(error.message) + } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 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 06cfa58c57..805effe064 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 @@ -66,7 +66,12 @@ internal object ExtensionLoader { * contains the required feature flag before trying to load it. */ fun loadExtensionFromPkgName(context: Context, pkgName: String): LoadResult { - val pkgInfo = context.packageManager.getPackageInfo(pkgName, PACKAGE_FLAGS) + val pkgInfo = try { + 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) + } if (!isPackageAnExtension(pkgInfo)) { return LoadResult.Error("Tried to load a package that wasn't a extension") } @@ -83,9 +88,15 @@ internal object ExtensionLoader { private fun loadExtension(context: Context, pkgName: String, pkgInfo: PackageInfo): LoadResult { val pkgManager = context.packageManager - val appInfo = pkgManager.getApplicationInfo(pkgName, PackageManager.GET_META_DATA) + val appInfo = try { + 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) + } - val extName = pkgManager.getApplicationLabel(appInfo).toString().substringAfter("Tachiyomi: ") + val extName = pkgManager.getApplicationLabel(appInfo)?.toString() + .orEmpty().substringAfter("Tachiyomi: ") val versionName = pkgInfo.versionName val versionCode = pkgInfo.versionCode