Unverified Commit 936ad1aa authored by 南宫雪珊's avatar 南宫雪珊 Committed by GitHub

Handle download fail

Co-authored-by: 's avatartopjohnwu <topjohnwu@gmail.com>
parent d021bca6
...@@ -29,6 +29,7 @@ import kotlinx.coroutines.Job ...@@ -29,6 +29,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
import java.io.File import java.io.File
import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
...@@ -84,6 +85,7 @@ class DownloadService : NotificationService() { ...@@ -84,6 +85,7 @@ class DownloadService : NotificationService() {
if (isRunningAsStub) { if (isRunningAsStub) {
val apk = subject.file.toFile() val apk = subject.file.toFile()
val id = subject.notifyId val id = subject.notifyId
try {
write(StubApk.update(this).outputStream()) write(StubApk.update(this).outputStream())
if (Info.stub!!.version < subject.stub.versionCode) { if (Info.stub!!.version < subject.stub.versionCode) {
// Also upgrade stub // Also upgrade stub
...@@ -94,7 +96,10 @@ class DownloadService : NotificationService() { ...@@ -94,7 +96,10 @@ class DownloadService : NotificationService() {
} }
service.fetchFile(subject.stub.link).byteStream().writeTo(apk) service.fetchFile(subject.stub.link).byteStream().writeTo(apk)
val patched = File(apk.parent, "patched.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() apk.delete()
patched.renameTo(apk) patched.renameTo(apk)
} else { } else {
...@@ -102,6 +107,9 @@ class DownloadService : NotificationService() { ...@@ -102,6 +107,9 @@ class DownloadService : NotificationService() {
PhoenixActivity.rebirth(this, clz) PhoenixActivity.rebirth(this, clz)
return return
} }
} catch (e: Exception) {
StubApk.update(this).delete()
}
} }
val receiver = APKInstall.register(this, null, null) val receiver = APKInstall.register(this, null, null)
write(APKInstall.openStream(this, false)) write(APKInstall.openStream(this, false))
......
...@@ -125,7 +125,7 @@ public class DynLoad { ...@@ -125,7 +125,7 @@ public class DynLoad {
PackageInfo pkgInfo = pm.getPackageArchiveInfo(apk.getPath(), 0); PackageInfo pkgInfo = pm.getPackageArchiveInfo(apk.getPath(), 0);
try { try {
return newApp(pkgInfo.applicationInfo); return newApp(pkgInfo.applicationInfo);
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException | NullPointerException e) {
Log.e(DynLoad.class.getSimpleName(), "", e); Log.e(DynLoad.class.getSimpleName(), "", e);
apk.delete(); apk.delete();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment