mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-20 00:38:29 +00:00
Fix download notifications
This commit is contained in:
parent
5a88984d34
commit
0726a00e3b
@ -64,7 +64,7 @@ open class App() : Application() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
base.resources.patch()
|
base.resources.patch()
|
||||||
app.registerActivityLifecycleCallbacks(ForegroundTracker)
|
app.registerActivityLifecycleCallbacks(ActivityTracker)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
@ -86,7 +86,7 @@ open class App() : Application() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
object ForegroundTracker : Application.ActivityLifecycleCallbacks {
|
object ActivityTracker : Application.ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
var foreground: Activity? = null
|
var foreground: Activity? = null
|
||||||
|
@ -11,7 +11,7 @@ import android.os.IBinder
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.core.ForegroundTracker
|
import com.topjohnwu.magisk.core.ActivityTracker
|
||||||
import com.topjohnwu.magisk.core.base.BaseService
|
import com.topjohnwu.magisk.core.base.BaseService
|
||||||
import com.topjohnwu.magisk.core.intent
|
import com.topjohnwu.magisk.core.intent
|
||||||
import com.topjohnwu.magisk.core.utils.ProgressInputStream
|
import com.topjohnwu.magisk.core.utils.ProgressInputStream
|
||||||
@ -68,9 +68,10 @@ class DownloadService : BaseService() {
|
|||||||
is Subject.Manager -> handleAPK(subject, stream)
|
is Subject.Manager -> handleAPK(subject, stream)
|
||||||
else -> stream.toModule(subject.file, service.fetchInstaller().byteStream())
|
else -> stream.toModule(subject.file, service.fetchInstaller().byteStream())
|
||||||
}
|
}
|
||||||
if (ForegroundTracker.hasForeground) {
|
val activity = ActivityTracker.foreground
|
||||||
|
if (activity != null && subject.autoStart) {
|
||||||
remove(subject.notifyId)
|
remove(subject.notifyId)
|
||||||
subject.pendingIntent(this@DownloadService)?.send()
|
subject.pendingIntent(activity).send()
|
||||||
} else {
|
} else {
|
||||||
notifyFinish(subject)
|
notifyFinish(subject)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import androidx.core.content.getSystemService
|
|||||||
import androidx.core.net.toFile
|
import androidx.core.net.toFile
|
||||||
import com.topjohnwu.magisk.DynAPK
|
import com.topjohnwu.magisk.DynAPK
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.core.ForegroundTracker
|
import com.topjohnwu.magisk.core.ActivityTracker
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.isRunningAsStub
|
import com.topjohnwu.magisk.core.isRunningAsStub
|
||||||
import com.topjohnwu.magisk.core.tasks.HideAPK
|
import com.topjohnwu.magisk.core.tasks.HideAPK
|
||||||
@ -64,7 +64,7 @@ suspend fun DownloadService.handleAPK(subject: Subject.Manager, stream: InputStr
|
|||||||
//noinspection InlinedApi
|
//noinspection InlinedApi
|
||||||
val flag = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
val flag = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
val pending = PendingIntent.getActivity(this, id, intent, flag)
|
val pending = PendingIntent.getActivity(this, id, intent, flag)
|
||||||
if (ForegroundTracker.hasForeground) {
|
if (ActivityTracker.hasForeground) {
|
||||||
val alarm = getSystemService<AlarmManager>()
|
val alarm = getSystemService<AlarmManager>()
|
||||||
alarm!!.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, pending)
|
alarm!!.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, pending)
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,9 @@ sealed class Subject : Parcelable {
|
|||||||
abstract val file: Uri
|
abstract val file: Uri
|
||||||
abstract val title: String
|
abstract val title: String
|
||||||
abstract val notifyId: Int
|
abstract val notifyId: Int
|
||||||
|
open val autoStart: Boolean get() = true
|
||||||
|
|
||||||
abstract fun pendingIntent(context: Context): PendingIntent?
|
abstract fun pendingIntent(context: Context): PendingIntent
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
class Module(
|
class Module(
|
||||||
@ -45,16 +46,15 @@ sealed class Subject : Parcelable {
|
|||||||
) : Subject() {
|
) : Subject() {
|
||||||
override val url: String get() = module.zipUrl
|
override val url: String get() = module.zipUrl
|
||||||
override val title: String get() = module.downloadFilename
|
override val title: String get() = module.downloadFilename
|
||||||
|
override val autoStart: Boolean get() = action == Action.Flash
|
||||||
|
|
||||||
@IgnoredOnParcel
|
@IgnoredOnParcel
|
||||||
override val file by lazy {
|
override val file by lazy {
|
||||||
MediaStoreUtils.getFile(title).uri
|
MediaStoreUtils.getFile(title).uri
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pendingIntent(context: Context) = when (action) {
|
override fun pendingIntent(context: Context) =
|
||||||
Action.Flash -> FlashFragment.installIntent(context, file)
|
FlashFragment.installIntent(context, file)
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
|
Loading…
x
Reference in New Issue
Block a user