Handle download fail

Co-authored-by: topjohnwu <topjohnwu@gmail.com>
This commit is contained in:
南宫雪珊 2022-02-13 18:30:09 +08:00 committed by GitHub
parent d021bca6ef
commit 936ad1aa20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 17 deletions

View File

@ -29,6 +29,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import timber.log.Timber
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.util.zip.ZipEntry
@ -84,6 +85,7 @@ class DownloadService : NotificationService() {
if (isRunningAsStub) {
val apk = subject.file.toFile()
val id = subject.notifyId
try {
write(StubApk.update(this).outputStream())
if (Info.stub!!.version < subject.stub.versionCode) {
// Also upgrade stub
@ -94,7 +96,10 @@ class DownloadService : NotificationService() {
}
service.fetchFile(subject.stub.link).byteStream().writeTo(apk)
val patched = File(apk.parent, "patched.apk")
HideAPK.patch(this, apk, patched, packageName, applicationInfo.nonLocalizedLabel)
val label = applicationInfo.nonLocalizedLabel
if (!HideAPK.patch(this, apk, patched, packageName, label)) {
throw IOException("HideAPK patch error")
}
apk.delete()
patched.renameTo(apk)
} else {
@ -102,6 +107,9 @@ class DownloadService : NotificationService() {
PhoenixActivity.rebirth(this, clz)
return
}
} catch (e: Exception) {
StubApk.update(this).delete()
}
}
val receiver = APKInstall.register(this, null, null)
write(APKInstall.openStream(this, false))

View File

@ -125,7 +125,7 @@ public class DynLoad {
PackageInfo pkgInfo = pm.getPackageArchiveInfo(apk.getPath(), 0);
try {
return newApp(pkgInfo.applicationInfo);
} catch (ReflectiveOperationException e) {
} catch (ReflectiveOperationException | NullPointerException e) {
Log.e(DynLoad.class.getSimpleName(), "", e);
apk.delete();
}