Loading app/src/main/java/foundation/e/apps/manager/download/DownloadManagerUtils.kt +6 −4 Original line number Diff line number Diff line Loading @@ -64,10 +64,12 @@ class DownloadManagerUtils @Inject constructor( ) if (downloaded == fusedDownload.downloadIdMap.size) { fusedManagerRepository.moveOBBFileToOBBDirectory(fusedDownload) fusedManagerRepository.updateDownloadStatus( fusedDownload, Status.INSTALLING ) fusedDownload.status = Status.DOWNLOADED fusedManagerRepository.updateFusedDownload(fusedDownload) // fusedManagerRepository.updateDownloadStatus( // fusedDownload, // Status.INSTALLING // ) } } } Loading app/src/main/java/foundation/e/apps/manager/fused/FusedManagerImpl.kt +1 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,7 @@ class FusedManagerImpl @Inject constructor( Log.d(TAG, "installApp: ENDED ${fusedDownload.name} ${list.size}") } catch (e: Exception) { installationIssue(fusedDownload) throw e } } } Loading app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt +32 −11 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.takeWhile import kotlinx.coroutines.sync.Mutex import java.lang.RuntimeException import java.util.concurrent.atomic.AtomicInteger import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds Loading Loading @@ -59,6 +61,8 @@ class InstallAppWorker @AssistedInject constructor( private val atomicInteger = AtomicInteger(100) } private val mutex = Mutex(true) override suspend fun doWork(): Result { var fusedDownload: FusedDownload? = null try { Loading @@ -75,15 +79,19 @@ class InstallAppWorker @AssistedInject constructor( ) ) startAppInstallationProcess(it) mutex.lock() } Log.d(TAG, "doWork: RESULT SUCCESS: ${fusedDownload?.name}") return Result.success() // Log.d(TAG, "doWork: RESULT SUCCESS: ${fusedDownload?.name}") // return Result.success() } catch (e: Exception) { Log.e(TAG, "doWork: Failed: ${e.stackTraceToString()}") fusedDownload?.let { fusedManagerRepository.installationIssue(it) } return Result.failure() // return Result.failure() } finally { Log.d(TAG, "doWork: RESULT SUCCESS: ${fusedDownload?.name}") return Result.success() } } Loading @@ -94,10 +102,10 @@ class InstallAppWorker @AssistedInject constructor( Log.d(TAG, "===> doWork: Download started ${fusedDownload.name} ${fusedDownload.status}") if (fusedDownload.type == Type.NATIVE) { isDownloading = true tickerFlow(1.seconds) .onEach { checkDownloadProcess(fusedDownload) }.launchIn(CoroutineScope(Dispatchers.IO)) // tickerFlow(1.seconds) // .onEach { // checkDownloadProcess(fusedDownload) // }.launchIn(CoroutineScope(Dispatchers.IO)) observeDownload(fusedDownload) } } Loading Loading @@ -141,20 +149,29 @@ class InstallAppWorker @AssistedInject constructor( .collect { fusedDownload -> if (fusedDownload == null) { isDownloading = false mutex.unlock() return@collect } Log.d( TAG, "doWork: flow collect ===> ${fusedDownload.name} ${fusedDownload.status}" ) try { handleFusedDownloadStatus(fusedDownload) } catch (e: Exception) { Log.e(TAG, "observeDownload: ", e) mutex.unlock() } } } private fun handleFusedDownloadStatus(fusedDownload: FusedDownload) { private suspend fun handleFusedDownloadStatus(fusedDownload: FusedDownload) { when (fusedDownload.status) { Status.AWAITING, Status.DOWNLOADING -> { } Status.DOWNLOADED -> { fusedManagerRepository.updateDownloadStatus(fusedDownload, Status.INSTALLING) } Status.INSTALLING -> { Log.d( TAG, Loading @@ -165,8 +182,12 @@ class InstallAppWorker @AssistedInject constructor( isDownloading = false Log.d( TAG, "===> doWork: Installed/Failed started ${fusedDownload.name} ${fusedDownload.status}" "===> doWork: Installed/Failed: ${fusedDownload.name} ${fusedDownload.status}" ) // if(fusedDownload.status == Status.INSTALLATION_ISSUE) { // throw RuntimeException("Installation error occurred") // } mutex.unlock() } else -> { isDownloading = false Loading app/src/main/java/foundation/e/apps/utils/enums/Status.kt +1 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ enum class Status { UPDATABLE, INSTALLING, DOWNLOADING, DOWNLOADED, UNAVAILABLE, UNINSTALLING, QUEUED, Loading Loading
app/src/main/java/foundation/e/apps/manager/download/DownloadManagerUtils.kt +6 −4 Original line number Diff line number Diff line Loading @@ -64,10 +64,12 @@ class DownloadManagerUtils @Inject constructor( ) if (downloaded == fusedDownload.downloadIdMap.size) { fusedManagerRepository.moveOBBFileToOBBDirectory(fusedDownload) fusedManagerRepository.updateDownloadStatus( fusedDownload, Status.INSTALLING ) fusedDownload.status = Status.DOWNLOADED fusedManagerRepository.updateFusedDownload(fusedDownload) // fusedManagerRepository.updateDownloadStatus( // fusedDownload, // Status.INSTALLING // ) } } } Loading
app/src/main/java/foundation/e/apps/manager/fused/FusedManagerImpl.kt +1 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,7 @@ class FusedManagerImpl @Inject constructor( Log.d(TAG, "installApp: ENDED ${fusedDownload.name} ${list.size}") } catch (e: Exception) { installationIssue(fusedDownload) throw e } } } Loading
app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt +32 −11 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.takeWhile import kotlinx.coroutines.sync.Mutex import java.lang.RuntimeException import java.util.concurrent.atomic.AtomicInteger import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds Loading Loading @@ -59,6 +61,8 @@ class InstallAppWorker @AssistedInject constructor( private val atomicInteger = AtomicInteger(100) } private val mutex = Mutex(true) override suspend fun doWork(): Result { var fusedDownload: FusedDownload? = null try { Loading @@ -75,15 +79,19 @@ class InstallAppWorker @AssistedInject constructor( ) ) startAppInstallationProcess(it) mutex.lock() } Log.d(TAG, "doWork: RESULT SUCCESS: ${fusedDownload?.name}") return Result.success() // Log.d(TAG, "doWork: RESULT SUCCESS: ${fusedDownload?.name}") // return Result.success() } catch (e: Exception) { Log.e(TAG, "doWork: Failed: ${e.stackTraceToString()}") fusedDownload?.let { fusedManagerRepository.installationIssue(it) } return Result.failure() // return Result.failure() } finally { Log.d(TAG, "doWork: RESULT SUCCESS: ${fusedDownload?.name}") return Result.success() } } Loading @@ -94,10 +102,10 @@ class InstallAppWorker @AssistedInject constructor( Log.d(TAG, "===> doWork: Download started ${fusedDownload.name} ${fusedDownload.status}") if (fusedDownload.type == Type.NATIVE) { isDownloading = true tickerFlow(1.seconds) .onEach { checkDownloadProcess(fusedDownload) }.launchIn(CoroutineScope(Dispatchers.IO)) // tickerFlow(1.seconds) // .onEach { // checkDownloadProcess(fusedDownload) // }.launchIn(CoroutineScope(Dispatchers.IO)) observeDownload(fusedDownload) } } Loading Loading @@ -141,20 +149,29 @@ class InstallAppWorker @AssistedInject constructor( .collect { fusedDownload -> if (fusedDownload == null) { isDownloading = false mutex.unlock() return@collect } Log.d( TAG, "doWork: flow collect ===> ${fusedDownload.name} ${fusedDownload.status}" ) try { handleFusedDownloadStatus(fusedDownload) } catch (e: Exception) { Log.e(TAG, "observeDownload: ", e) mutex.unlock() } } } private fun handleFusedDownloadStatus(fusedDownload: FusedDownload) { private suspend fun handleFusedDownloadStatus(fusedDownload: FusedDownload) { when (fusedDownload.status) { Status.AWAITING, Status.DOWNLOADING -> { } Status.DOWNLOADED -> { fusedManagerRepository.updateDownloadStatus(fusedDownload, Status.INSTALLING) } Status.INSTALLING -> { Log.d( TAG, Loading @@ -165,8 +182,12 @@ class InstallAppWorker @AssistedInject constructor( isDownloading = false Log.d( TAG, "===> doWork: Installed/Failed started ${fusedDownload.name} ${fusedDownload.status}" "===> doWork: Installed/Failed: ${fusedDownload.name} ${fusedDownload.status}" ) // if(fusedDownload.status == Status.INSTALLATION_ISSUE) { // throw RuntimeException("Installation error occurred") // } mutex.unlock() } else -> { isDownloading = false Loading
app/src/main/java/foundation/e/apps/utils/enums/Status.kt +1 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ enum class Status { UPDATABLE, INSTALLING, DOWNLOADING, DOWNLOADED, UNAVAILABLE, UNINSTALLING, QUEUED, Loading