Fix subtle bugs when installing/loading extensions

This commit is contained in:
inorichi 2018-03-09 18:56:02 +01:00
parent ea32ea11f2
commit af637a82c3
2 changed files with 22 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.ExtensionManager
import eu.kanade.tachiyomi.util.toast
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -21,7 +22,13 @@ class ExtensionInstallActivity : Activity() {
.putExtra(Intent.EXTRA_RETURN_RESULT, true) .putExtra(Intent.EXTRA_RETURN_RESULT, true)
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) .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?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

View File

@ -66,7 +66,12 @@ internal object ExtensionLoader {
* contains the required feature flag before trying to load it. * contains the required feature flag before trying to load it.
*/ */
fun loadExtensionFromPkgName(context: Context, pkgName: String): LoadResult { 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)) { if (!isPackageAnExtension(pkgInfo)) {
return LoadResult.Error("Tried to load a package that wasn't a extension") 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 { private fun loadExtension(context: Context, pkgName: String, pkgInfo: PackageInfo): LoadResult {
val pkgManager = context.packageManager 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 versionName = pkgInfo.versionName
val versionCode = pkgInfo.versionCode val versionCode = pkgInfo.versionCode