Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit 8c1f3e3a authored by Saalim Quadri's avatar Saalim Quadri
Browse files

feat: Respect unmetered connections as we should

parent e25a06f1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.net.Uri
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.OpenForTesting
import foundation.e.apps.R
import foundation.e.apps.data.preference.AppLoungePreference
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
@@ -46,6 +47,7 @@ class DownloadManager @Inject constructor(
    private val downloadManager: DownloadManager,
    @Named("cacheDir") private val cacheDir: String,
    private val downloadManagerQuery: DownloadManager.Query,
    private val appLoungePreference: AppLoungePreference,
) {
    private val downloadsMaps = HashMap<Long, Boolean>()

@@ -79,6 +81,10 @@ class DownloadManager @Inject constructor(
            val request = DownloadManager.Request(Uri.parse(url))
                .setTitle(context.getString(R.string.downloading))
                .setDestinationUri(Uri.fromFile(downloadFile))
            if (appLoungePreference.isOnlyUnmeteredNetworkEnabled()) {
                // Set to true by default for Download requests
                request.setAllowedOverMetered(false)
            }
            downloadId = downloadManager.enqueue(request)
        } catch (e: java.lang.NullPointerException) {
            Timber.e(e, "Url: $url; downloadFilePath: ${downloadFile.absolutePath}")
+4 −0
Original line number Diff line number Diff line
@@ -120,4 +120,8 @@ class AppLoungePreference @Inject constructor(
            putBoolean(context.getString(R.string.anonymous_update_migration_completed), true)
        }
    }

    fun isOnlyUnmeteredNetworkEnabled(): Boolean {
        return preferenceManager.getBoolean(context.getString(R.string.only_unmetered_network), true)
    }
}