Skip to content

Commit

Permalink
Merge pull request #178 from touchapp/fix/downloads_android_14
Browse files Browse the repository at this point in the history
fix: Crash on Android 14 when trying to download a content
  • Loading branch information
dixidroid authored Jan 12, 2024
2 parents 42f518a + 7ea1dac commit 5f06478
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<queries>
<intent>
Expand Down Expand Up @@ -57,6 +58,11 @@
<meta-data
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="androidx.media3.cast.DefaultCastOptionsProvider" />

<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />
</application>

</manifest>
13 changes: 9 additions & 4 deletions core/src/main/java/org/openedx/core/module/DownloadWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package org.openedx.core.module
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.pm.ServiceInfo
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.work.CoroutineWorker
import androidx.work.ForegroundInfo
import androidx.work.WorkerParameters
import kotlinx.coroutines.flow.first
import org.koin.java.KoinJavaComponent.inject
import org.openedx.core.R
import org.openedx.core.module.db.DownloadDao
import org.openedx.core.module.db.DownloadModel
import org.openedx.core.module.db.DownloadModelEntity
import org.openedx.core.module.db.DownloadedState
import org.openedx.core.module.download.CurrentProgress
import org.openedx.core.module.download.FileDownloader
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.first
import org.koin.java.KoinJavaComponent.inject
import java.io.File

class DownloadWorker(
Expand Down Expand Up @@ -60,6 +60,10 @@ class DownloadWorker(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createChannel()
}
val serviceType =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC else 0

return ForegroundInfo(
NOTIFICATION_ID,
notificationBuilder
Expand All @@ -68,7 +72,8 @@ class DownloadWorker(
.setPriority(NotificationManager.IMPORTANCE_LOW)
.setContentText(context.getString(R.string.core_downloading_in_progress))
.setContentTitle("")
.build()
.build(),
serviceType
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,14 +689,14 @@ fun CourseSubSectionItem(
Box(contentAlignment = Alignment.Center) {
if (downloadedState == DownloadedState.DOWNLOADING || downloadedState == DownloadedState.WAITING) {
CircularProgressIndicator(
modifier = Modifier.size(34.dp),
modifier = Modifier.size(28.dp),
backgroundColor = Color.LightGray,
strokeWidth = 2.dp,
color = MaterialTheme.appColors.primary
)
}
IconButton(
modifier = iconModifier.padding(top = 2.dp),
modifier = iconModifier.padding(2.dp),
onClick = { onDownloadClick(block) }) {
Icon(
imageVector = Icons.Filled.Close,
Expand Down

0 comments on commit 5f06478

Please sign in to comment.