DownloadWorker: Use a generic download notification if required
On old android versions, work manager runs expedited jobs using FGS which seem to require a work notification as soon as the service starts by automatically calling getForegroundInfo method. This causes an exception as we haven't parsed the data yet. Use a generic download notification for such cases. Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -224,7 +224,11 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getForegroundInfo(): ForegroundInfo {
|
override suspend fun getForegroundInfo(): ForegroundInfo {
|
||||||
val notification = NotificationUtil.getDownloadNotification(appContext, download, id)
|
val notification = if (this::download.isInitialized) {
|
||||||
|
NotificationUtil.getDownloadNotification(appContext, download, id)
|
||||||
|
} else {
|
||||||
|
NotificationUtil.getDownloadNotification(appContext)
|
||||||
|
}
|
||||||
return if (isQAndAbove()) {
|
return if (isQAndAbove()) {
|
||||||
ForegroundInfo(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC)
|
ForegroundInfo(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -79,6 +79,16 @@ object NotificationUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDownloadNotification(context: Context): Notification {
|
||||||
|
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_GENERAL)
|
||||||
|
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||||
|
.setColor(ContextCompat.getColor(context, R.color.colorAccent))
|
||||||
|
.setContentTitle(context.getString(R.string.app_updater_service_notif_title))
|
||||||
|
.setContentText(context.getString(R.string.app_updater_service_notif_text))
|
||||||
|
.setOngoing(true)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
fun getDownloadNotification(
|
fun getDownloadNotification(
|
||||||
context: Context,
|
context: Context,
|
||||||
app: App,
|
app: App,
|
||||||
|
|||||||
Reference in New Issue
Block a user