diff --git a/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt b/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt index abf5e81c9..2ebb2eb38 100644 --- a/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt +++ b/app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt @@ -119,3 +119,5 @@ fun ApplicationInfo.getLabel(pm: PackageManager): String { return loadLabel(pm).toString() } + +fun Intent.exists(packageManager: PackageManager) = resolveActivity(packageManager) != null \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt b/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt index 4e2c2792e..4fbf8c456 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt @@ -10,6 +10,7 @@ import androidx.core.app.NotificationCompat import com.topjohnwu.magisk.ClassMap import com.topjohnwu.magisk.R import com.topjohnwu.magisk.extensions.chooser +import com.topjohnwu.magisk.extensions.exists import com.topjohnwu.magisk.extensions.provide import com.topjohnwu.magisk.model.entity.internal.Configuration.* import com.topjohnwu.magisk.model.entity.internal.Configuration.Flash.Secondary @@ -17,6 +18,7 @@ import com.topjohnwu.magisk.model.entity.internal.DownloadSubject import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.* import com.topjohnwu.magisk.ui.flash.FlashActivity import com.topjohnwu.magisk.utils.APKInstall +import org.koin.core.get import java.io.File import kotlin.random.Random.Default.nextInt @@ -76,8 +78,14 @@ open class DownloadService : RemoteFileService() { private fun NotificationCompat.Builder.addActionsInternal(subject: Magisk) = when (val conf = subject.configuration) { - Download -> addAction(0, R.string.download_open_parent, fileIntent(subject.file.parentFile!!)) - .addAction(0, R.string.download_open_self, fileIntent(subject.file)) + Download -> this.apply { + fileIntent(subject.file.parentFile!!) + .takeIf { it.exists(get()) } + ?.let { addAction(0, R.string.download_open_parent, it.chooser()) } + fileIntent(subject.file) + .takeIf { it.exists(get()) } + ?.let { addAction(0, R.string.download_open_self, it.chooser()) } + } Uninstall -> setContentIntent(FlashActivity.uninstallIntent(context, subject.file)) is Flash -> setContentIntent(FlashActivity.flashIntent(context, subject.file, conf is Secondary)) is Patch -> setContentIntent(FlashActivity.patchIntent(context, subject.file, conf.fileUri)) @@ -86,8 +94,14 @@ open class DownloadService : RemoteFileService() { private fun NotificationCompat.Builder.addActionsInternal(subject: Module) = when (subject.configuration) { - Download -> addAction(0, R.string.download_open_parent, fileIntent(subject.file.parentFile!!)) - .addAction(0, R.string.download_open_self, fileIntent(subject.file)) + Download -> this.apply { + fileIntent(subject.file.parentFile!!) + .takeIf { it.exists(get()) } + ?.let { addAction(0, R.string.download_open_parent, it.chooser()) } + fileIntent(subject.file) + .takeIf { it.exists(get()) } + ?.let { addAction(0, R.string.download_open_self, it.chooser()) } + } is Flash -> setContentIntent(FlashActivity.installIntent(context, subject.file)) else -> this } @@ -115,7 +129,6 @@ open class DownloadService : RemoteFileService() { .setDataAndType(file.provide(this), file.type) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - .chooser() } class Builder { diff --git a/app/src/main/java/com/topjohnwu/magisk/model/download/NotificationService.kt b/app/src/main/java/com/topjohnwu/magisk/model/download/NotificationService.kt index 41d8eede0..716869fc3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/download/NotificationService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/download/NotificationService.kt @@ -6,10 +6,11 @@ import android.content.Intent import android.os.IBinder import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import org.koin.core.KoinComponent import java.util.* import kotlin.random.Random.Default.nextInt -abstract class NotificationService : Service() { +abstract class NotificationService : Service(), KoinComponent { abstract val defaultNotification: NotificationCompat.Builder