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

Commit 39712490 authored by Hasib Prince's avatar Hasib Prince
Browse files

Merge branch '1836-refactoring' into 'main'

style: improved coding styles

See merge request !433
parents 81bed6e3 273554d6
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -123,9 +123,9 @@ class DownloadManagerUtils @Inject constructor(

        val numberOfDownloadedItems =
            fusedDownload.downloadIdMap.values.filter { it }.size

        Timber.d("===> updateDownloadStatus: ${fusedDownload.name}: $downloadId: $numberOfDownloadedItems/${fusedDownload.downloadIdMap.size}")

        // if download status code is unknown (-1), consider installation is failed.
        val areAllFilesDownloaded = areAllFilesDownloaded(
            numberOfDownloadedItems,
            fusedDownload
+18 −16
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import foundation.e.apps.data.DownloadManager
import foundation.e.apps.data.enums.Status
import foundation.e.apps.data.fusedDownload.FusedDownloadRepository
import foundation.e.apps.data.fusedDownload.models.FusedDownload
import foundation.e.apps.install.download.DownloadManagerUtils
import foundation.e.apps.utils.NetworkStatusManager
import foundation.e.apps.utils.StorageComputer
import kotlinx.coroutines.MainScope
@@ -48,6 +47,7 @@ class DumpAppInstallStatusReceiver : BroadcastReceiver() {

    @Inject
    lateinit var downloadManager: DownloadManager

    override fun onReceive(context: Context?, intent: Intent?) {
        if (intent?.action == null) {
            return
@@ -56,38 +56,40 @@ class DumpAppInstallStatusReceiver : BroadcastReceiver() {
        MainScope().launch {
            val gson = Gson()
            val appList = fusedDownloadRepository.getDownloadList()
            Timber.tag(Constants.TAG_APP_INSTALL_STATE)
                .i("App install status: ${gson.toJson(appList)}")
            val appInstallStatusLog = "App install status: ${gson.toJson(appList)}"
            val deviceStatusLog = getDeviceInfo(context)
            val downloadStatusLog = getDownloadStatus(appList)

            logDownloadStatusFromDownloadManager(appList)
            logDeviceStatus(context)
            Timber.tag(Constants.TAG_APP_INSTALL_STATE)
                .e("%s\n\n%s\n\n%s", deviceStatusLog, appInstallStatusLog, downloadStatusLog)
        }
    }

    private fun logDeviceStatus(context: Context?) {
    private fun getDeviceInfo(context: Context?): String? {
        context?.let {
            val bm = context.getSystemService(BATTERY_SERVICE) as BatteryManager
            val batteryLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)

            Timber.tag(Constants.TAG_APP_INSTALL_STATE)
                .i(
                    "Available Space: ${StorageComputer.calculateAvailableDiskSpace()}" +
            return "Available Space: ${StorageComputer.calculateAvailableDiskSpace()}" +
                    "\nInternet: ${
                        NetworkStatusManager.init(context).value
                    }\nBattery level: $batteryLevel"
                )
        }

        return null
    }

    private fun logDownloadStatusFromDownloadManager(appList: List<FusedDownload>) {
    private fun getDownloadStatus(appList: List<FusedDownload>): String {
        var downloadStatusLog = ""
        appList.forEach {
            if (listOf(Status.DOWNLOADING, Status.DOWNLOADED).contains(it.status)) {
                it.downloadIdMap.keys.forEach { downloadId ->
                    val downloadStatus = downloadManager.isDownloadSuccessful(downloadId)
                    Timber.tag(Constants.TAG_APP_INSTALL_STATE)
                        .i("DownloadStatus: ${it.name}: Id: $downloadId: ${downloadStatus.second}")
                    downloadStatusLog += "DownloadStatus: ${it.name}: Id: $downloadId: ${downloadStatus.second}\n"
                }
            }
        }

        return downloadStatusLog
    }
}