mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-13 18:31:48 +00:00
Directly stream APK into install session
This commit is contained in:
@@ -70,7 +70,7 @@ class DownloadService : BaseService() {
|
||||
val activity = ActivityTracker.foreground
|
||||
if (activity != null && subject.autoStart) {
|
||||
remove(subject.notifyId)
|
||||
subject.pendingIntent(activity).send()
|
||||
subject.pendingIntent(activity)?.send()
|
||||
} else {
|
||||
notifyFinish(subject)
|
||||
}
|
||||
@@ -117,13 +117,13 @@ class DownloadService : BaseService() {
|
||||
|
||||
private fun notifyFinish(subject: Subject) = finalNotify(subject.notifyId) {
|
||||
broadcast(1f, subject)
|
||||
it.setContentIntent(subject.pendingIntent(this))
|
||||
.setContentTitle(subject.title)
|
||||
it.setContentTitle(subject.title)
|
||||
.setContentText(getString(R.string.download_complete))
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||
.setProgress(0, 0, false)
|
||||
.setOngoing(false)
|
||||
.setAutoCancel(true)
|
||||
subject.pendingIntent(this)?.let { intent -> it.setContentIntent(intent) }
|
||||
}
|
||||
|
||||
private fun finalNotify(id: Int, editor: (Notification.Builder) -> Unit): Int {
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.topjohnwu.magisk.core.tasks.HideAPK
|
||||
import com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream
|
||||
import com.topjohnwu.magisk.ktx.copyAndClose
|
||||
import com.topjohnwu.magisk.ktx.writeTo
|
||||
import com.topjohnwu.magisk.utils.APKInstall
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
@@ -57,8 +58,10 @@ suspend fun DownloadService.handleAPK(subject: Subject.Manager, stream: InputStr
|
||||
} else {
|
||||
val clz = Info.stub!!.classToComponent["PHOENIX"]!!
|
||||
PhoenixActivity.rebirth(this, clz)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
write(subject.file.outputStream())
|
||||
}
|
||||
val receiver = APKInstall.register(this, null, null)
|
||||
write(APKInstall.openStream(this, false))
|
||||
subject.intent = receiver.waitIntent()
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Parcelable
|
||||
import androidx.core.net.toFile
|
||||
import androidx.core.net.toUri
|
||||
import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.model.MagiskJson
|
||||
@@ -16,7 +15,6 @@ import com.topjohnwu.magisk.core.utils.MediaStoreUtils
|
||||
import com.topjohnwu.magisk.di.AppContext
|
||||
import com.topjohnwu.magisk.ktx.cachedFile
|
||||
import com.topjohnwu.magisk.ui.flash.FlashFragment
|
||||
import com.topjohnwu.magisk.utils.APKInstall
|
||||
import com.topjohnwu.magisk.view.Notifications
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
@@ -36,7 +34,7 @@ sealed class Subject : Parcelable {
|
||||
abstract val notifyId: Int
|
||||
open val autoStart: Boolean get() = true
|
||||
|
||||
abstract fun pendingIntent(context: Context): PendingIntent
|
||||
abstract fun pendingIntent(context: Context): PendingIntent?
|
||||
|
||||
@Parcelize
|
||||
class Module(
|
||||
@@ -71,14 +69,12 @@ sealed class Subject : Parcelable {
|
||||
cachedFile("manager.apk")
|
||||
}
|
||||
|
||||
@IgnoredOnParcel
|
||||
var intent: Intent? = null
|
||||
|
||||
val externalFile get() = MediaStoreUtils.getFile("$title.apk").uri
|
||||
|
||||
override fun pendingIntent(context: Context): PendingIntent {
|
||||
val receiver = APKInstall.register(context, null, null)
|
||||
APKInstall.installapk(context, file.toFile())
|
||||
val intent = receiver.waitIntent() ?: Intent()
|
||||
return intent.toPending(context)
|
||||
}
|
||||
override fun pendingIntent(context: Context) = intent?.toPending(context)
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
|
||||
@@ -125,7 +125,7 @@ object HideAPK {
|
||||
}
|
||||
val cmd = "adb_pm_install $repack ${activity.applicationInfo.uid}"
|
||||
if (!Shell.su(cmd).exec().isSuccess) {
|
||||
APKInstall.installapk(activity, repack)
|
||||
APKInstall.install(activity, repack)
|
||||
receiver.waitIntent()?.let { activity.startActivity(it) }
|
||||
}
|
||||
return true
|
||||
@@ -164,7 +164,7 @@ object HideAPK {
|
||||
val cmd = "adb_pm_install $apk ${activity.applicationInfo.uid}"
|
||||
Shell.su(cmd).submit(Shell.EXECUTOR) { ret ->
|
||||
if (ret.isSuccess) return@submit
|
||||
APKInstall.installapk(activity, apk)
|
||||
APKInstall.install(activity, apk)
|
||||
receiver.waitIntent()?.let { activity.startActivity(it) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user