mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 12:05:30 +00:00
Handle download fail
Co-authored-by: topjohnwu <topjohnwu@gmail.com>
This commit is contained in:
parent
d021bca6ef
commit
936ad1aa20
@ -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,23 +85,30 @@ 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
|
||||||
write(StubApk.update(this).outputStream())
|
try {
|
||||||
if (Info.stub!!.version < subject.stub.versionCode) {
|
write(StubApk.update(this).outputStream())
|
||||||
// Also upgrade stub
|
if (Info.stub!!.version < subject.stub.versionCode) {
|
||||||
update(id) {
|
// Also upgrade stub
|
||||||
it.setProgress(0, 0, true)
|
update(id) {
|
||||||
.setContentTitle(getString(R.string.hide_app_title))
|
it.setProgress(0, 0, true)
|
||||||
.setContentText("")
|
.setContentTitle(getString(R.string.hide_app_title))
|
||||||
|
.setContentText("")
|
||||||
|
}
|
||||||
|
service.fetchFile(subject.stub.link).byteStream().writeTo(apk)
|
||||||
|
val patched = File(apk.parent, "patched.apk")
|
||||||
|
val label = applicationInfo.nonLocalizedLabel
|
||||||
|
if (!HideAPK.patch(this, apk, patched, packageName, label)) {
|
||||||
|
throw IOException("HideAPK patch error")
|
||||||
|
}
|
||||||
|
apk.delete()
|
||||||
|
patched.renameTo(apk)
|
||||||
|
} else {
|
||||||
|
val clz = Info.stub!!.classToComponent["PHOENIX"]!!
|
||||||
|
PhoenixActivity.rebirth(this, clz)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
service.fetchFile(subject.stub.link).byteStream().writeTo(apk)
|
} catch (e: Exception) {
|
||||||
val patched = File(apk.parent, "patched.apk")
|
StubApk.update(this).delete()
|
||||||
HideAPK.patch(this, apk, patched, packageName, applicationInfo.nonLocalizedLabel)
|
|
||||||
apk.delete()
|
|
||||||
patched.renameTo(apk)
|
|
||||||
} else {
|
|
||||||
val clz = Info.stub!!.classToComponent["PHOENIX"]!!
|
|
||||||
PhoenixActivity.rebirth(this, clz)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val receiver = APKInstall.register(this, null, null)
|
val receiver = APKInstall.register(this, null, null)
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user