Commit 0726a00e authored by topjohnwu's avatar topjohnwu

Fix download notifications

parent 5a88984d
......@@ -64,7 +64,7 @@ open class App() : Application() {
}
base.resources.patch()
app.registerActivityLifecycleCallbacks(ForegroundTracker)
app.registerActivityLifecycleCallbacks(ActivityTracker)
}
override fun onCreate() {
......@@ -86,7 +86,7 @@ open class App() : Application() {
}
@SuppressLint("StaticFieldLeak")
object ForegroundTracker : Application.ActivityLifecycleCallbacks {
object ActivityTracker : Application.ActivityLifecycleCallbacks {
@Volatile
var foreground: Activity? = null
......
......@@ -11,7 +11,7 @@ import android.os.IBinder
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
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.intent
import com.topjohnwu.magisk.core.utils.ProgressInputStream
......@@ -68,9 +68,10 @@ class DownloadService : BaseService() {
is Subject.Manager -> handleAPK(subject, stream)
else -> stream.toModule(subject.file, service.fetchInstaller().byteStream())
}
if (ForegroundTracker.hasForeground) {
val activity = ActivityTracker.foreground
if (activity != null && subject.autoStart) {
remove(subject.notifyId)
subject.pendingIntent(this@DownloadService)?.send()
subject.pendingIntent(activity).send()
} else {
notifyFinish(subject)
}
......
......@@ -7,7 +7,7 @@ import androidx.core.content.getSystemService
import androidx.core.net.toFile
import com.topjohnwu.magisk.DynAPK
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.isRunningAsStub
import com.topjohnwu.magisk.core.tasks.HideAPK
......@@ -64,7 +64,7 @@ suspend fun DownloadService.handleAPK(subject: Subject.Manager, stream: InputStr
//noinspection InlinedApi
val flag = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
val pending = PendingIntent.getActivity(this, id, intent, flag)
if (ForegroundTracker.hasForeground) {
if (ActivityTracker.hasForeground) {
val alarm = getSystemService<AlarmManager>()
alarm!!.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, pending)
}
......
......@@ -34,8 +34,9 @@ sealed class Subject : Parcelable {
abstract val file: Uri
abstract val title: String
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(
......@@ -45,16 +46,15 @@ sealed class Subject : Parcelable {
) : Subject() {
override val url: String get() = module.zipUrl
override val title: String get() = module.downloadFilename
override val autoStart: Boolean get() = action == Action.Flash
@IgnoredOnParcel
override val file by lazy {
MediaStoreUtils.getFile(title).uri
}
override fun pendingIntent(context: Context) = when (action) {
Action.Flash -> FlashFragment.installIntent(context, file)
else -> null
}
override fun pendingIntent(context: Context) =
FlashFragment.installIntent(context, file)
}
@Parcelize
......
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