diff --git a/app/src/main/java/foundation/e/apps/install/download/DownloadManagerUtils.kt b/app/src/main/java/foundation/e/apps/install/download/DownloadManagerUtils.kt index c95380f9786dc73821d17686b9afeb0705a1627c..94e10df97ea8ab0fd4e1910a44e36eaf8f8a506d 100644 --- a/app/src/main/java/foundation/e/apps/install/download/DownloadManagerUtils.kt +++ b/app/src/main/java/foundation/e/apps/install/download/DownloadManagerUtils.kt @@ -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 diff --git a/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt b/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt index e21cd022b739691ba86fe68f892f7c8eb6aa659c..f28ada6a4e24b6758f5be3a548dba0e555a01490 100644 --- a/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt +++ b/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt @@ -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()}" + - "\nInternet: ${ - NetworkStatusManager.init(context).value - }\nBattery level: $batteryLevel" - ) + return "Available Space: ${StorageComputer.calculateAvailableDiskSpace()}" + + "\nInternet: ${ + NetworkStatusManager.init(context).value + }\nBattery level: $batteryLevel" } + + return null } - private fun logDownloadStatusFromDownloadManager(appList: List) { + private fun getDownloadStatus(appList: List): 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 } }