Loading app/src/main/java/foundation/e/apps/data/install/core/AppInstallationFacade.kt +5 −4 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ class AppInstallationFacade @Inject constructor( application.status == Status.UPDATABLE || appManager.isAppInstalled(appInstall) return enqueueFusedDownload(appInstall, isUpdate, application.isSystemApp) return enqueueAppForInstallation(appInstall, isUpdate, application.isSystemApp) } /** Loading @@ -79,8 +79,9 @@ class AppInstallationFacade @Inject constructor( * @param appInstall represents the app downloading and installing related info, example- Installing Status, * Url of the APK,OBB files are needed to be downloaded and installed etc. * @param isAnUpdate indicates the app is requested for update or not * @param isSystemApp indicates if the app is a system app or not */ suspend fun enqueueFusedDownload( suspend fun enqueueAppForInstallation( appInstall: AppInstall, isAnUpdate: Boolean = false, isSystemApp: Boolean = false Loading @@ -89,11 +90,11 @@ class AppInstallationFacade @Inject constructor( } suspend fun processInstall( fusedDownloadId: String, downloadId: String, isItUpdateWork: Boolean, runInForeground: (suspend (String) -> Unit) ): Result<ResultStatus> { return installationProcessor.processInstall(fusedDownloadId, isItUpdateWork, runInForeground) return installationProcessor.processInstall(downloadId, isItUpdateWork, runInForeground) .map { installationResult -> when (installationResult) { InstallationResult.OK -> ResultStatus.OK Loading app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt +3 −3 Original line number Diff line number Diff line Loading @@ -304,11 +304,11 @@ class MainActivityViewModel @Inject constructor( } suspend fun updateAwaitingForPurchasedApp(packageName: String): AppInstall? { val fusedDownload = appManager.getFusedDownload(packageName = packageName) val queuedInstallation = appManager.getFusedDownload(packageName = packageName) val authData = sessionManager.awaitAuthData() if (authData?.isAnonymous != true) { appInstallationFacade.enqueueFusedDownload(fusedDownload) return fusedDownload appInstallationFacade.enqueueAppForInstallation(queuedInstallation) return queuedInstallation } return null Loading app/src/test/java/foundation/e/apps/installProcessor/AppInstallationFacadeTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -108,11 +108,11 @@ class AppInstallationFacadeTest { } @Test fun enqueueFusedDownload_delegatesResult() = runTest { fun enqueueAppForInstallation_delegatesResult() = runTest { val appInstall = AppInstall(id = "123", packageName = "com.example.app") coEvery { installationEnqueuer.enqueue(appInstall, true, true) } returns false val result = appInstallationFacade.enqueueFusedDownload(appInstall, true, true) val result = appInstallationFacade.enqueueAppForInstallation(appInstall, true, true) assertEquals(false, result) coVerify { installationEnqueuer.enqueue(appInstall, true, true) } Loading data/src/main/java/foundation/e/apps/data/installation/core/InstallationProcessor.kt +11 −11 Original line number Diff line number Diff line Loading @@ -40,12 +40,12 @@ class InstallationProcessor @Inject constructor( @Suppress("ReturnCount") @OptIn(DelicateCoroutinesApi::class) suspend fun processInstall( fusedDownloadId: String, downloadId: String, isItUpdateWork: Boolean, runInForeground: suspend (String) -> Unit ): Result<InstallationResult> { val appInstall = appInstallRepository.getDownloadById(fusedDownloadId) ?: return Result.failure( appInstallRepository.getDownloadById(downloadId) ?: return Result.failure( IllegalStateException("App can't be null here.") ) Loading Loading @@ -124,34 +124,34 @@ class InstallationProcessor @Inject constructor( emit(it) isInstallRunning(it) } .collect { latestFusedDownload -> handleFusedDownload(latestFusedDownload, appInstall, isUpdateWork) .collect { latestDownload -> handleDownload(latestDownload, appInstall, isUpdateWork) } } private suspend fun handleFusedDownload( latestAppInstall: AppInstall?, private suspend fun handleDownload( latestDownload: AppInstall?, appInstall: AppInstall, isUpdateWork: Boolean ) { if (latestAppInstall == null) { if (latestDownload == null) { Timber.d("===> download null: finish installation") finishInstallation(appInstall, isUpdateWork) return } handleFusedDownloadStatusCheckingException(latestAppInstall, isUpdateWork) handleDownloadStatusCheckingException(latestDownload, isUpdateWork) } private fun isInstallRunning(it: AppInstall?) = it != null && it.status != Status.INSTALLATION_ISSUE private suspend fun handleFusedDownloadStatusCheckingException( private suspend fun handleDownloadStatusCheckingException( download: AppInstall, isUpdateWork: Boolean ) { runCatching { handleFusedDownloadStatus(download, isUpdateWork) handleDownloadStatus(download, isUpdateWork) }.onFailure { throwable -> when (throwable) { is CancellationException -> throw throwable Loading @@ -169,7 +169,7 @@ class InstallationProcessor @Inject constructor( } } private suspend fun handleFusedDownloadStatus(appInstall: AppInstall, isUpdateWork: Boolean) { private suspend fun handleDownloadStatus(appInstall: AppInstall, isUpdateWork: Boolean) { when (appInstall.status) { Status.AWAITING, Status.DOWNLOADING -> Unit Status.DOWNLOADED -> appManager.updateDownloadStatus( Loading Loading
app/src/main/java/foundation/e/apps/data/install/core/AppInstallationFacade.kt +5 −4 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ class AppInstallationFacade @Inject constructor( application.status == Status.UPDATABLE || appManager.isAppInstalled(appInstall) return enqueueFusedDownload(appInstall, isUpdate, application.isSystemApp) return enqueueAppForInstallation(appInstall, isUpdate, application.isSystemApp) } /** Loading @@ -79,8 +79,9 @@ class AppInstallationFacade @Inject constructor( * @param appInstall represents the app downloading and installing related info, example- Installing Status, * Url of the APK,OBB files are needed to be downloaded and installed etc. * @param isAnUpdate indicates the app is requested for update or not * @param isSystemApp indicates if the app is a system app or not */ suspend fun enqueueFusedDownload( suspend fun enqueueAppForInstallation( appInstall: AppInstall, isAnUpdate: Boolean = false, isSystemApp: Boolean = false Loading @@ -89,11 +90,11 @@ class AppInstallationFacade @Inject constructor( } suspend fun processInstall( fusedDownloadId: String, downloadId: String, isItUpdateWork: Boolean, runInForeground: (suspend (String) -> Unit) ): Result<ResultStatus> { return installationProcessor.processInstall(fusedDownloadId, isItUpdateWork, runInForeground) return installationProcessor.processInstall(downloadId, isItUpdateWork, runInForeground) .map { installationResult -> when (installationResult) { InstallationResult.OK -> ResultStatus.OK Loading
app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt +3 −3 Original line number Diff line number Diff line Loading @@ -304,11 +304,11 @@ class MainActivityViewModel @Inject constructor( } suspend fun updateAwaitingForPurchasedApp(packageName: String): AppInstall? { val fusedDownload = appManager.getFusedDownload(packageName = packageName) val queuedInstallation = appManager.getFusedDownload(packageName = packageName) val authData = sessionManager.awaitAuthData() if (authData?.isAnonymous != true) { appInstallationFacade.enqueueFusedDownload(fusedDownload) return fusedDownload appInstallationFacade.enqueueAppForInstallation(queuedInstallation) return queuedInstallation } return null Loading
app/src/test/java/foundation/e/apps/installProcessor/AppInstallationFacadeTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -108,11 +108,11 @@ class AppInstallationFacadeTest { } @Test fun enqueueFusedDownload_delegatesResult() = runTest { fun enqueueAppForInstallation_delegatesResult() = runTest { val appInstall = AppInstall(id = "123", packageName = "com.example.app") coEvery { installationEnqueuer.enqueue(appInstall, true, true) } returns false val result = appInstallationFacade.enqueueFusedDownload(appInstall, true, true) val result = appInstallationFacade.enqueueAppForInstallation(appInstall, true, true) assertEquals(false, result) coVerify { installationEnqueuer.enqueue(appInstall, true, true) } Loading
data/src/main/java/foundation/e/apps/data/installation/core/InstallationProcessor.kt +11 −11 Original line number Diff line number Diff line Loading @@ -40,12 +40,12 @@ class InstallationProcessor @Inject constructor( @Suppress("ReturnCount") @OptIn(DelicateCoroutinesApi::class) suspend fun processInstall( fusedDownloadId: String, downloadId: String, isItUpdateWork: Boolean, runInForeground: suspend (String) -> Unit ): Result<InstallationResult> { val appInstall = appInstallRepository.getDownloadById(fusedDownloadId) ?: return Result.failure( appInstallRepository.getDownloadById(downloadId) ?: return Result.failure( IllegalStateException("App can't be null here.") ) Loading Loading @@ -124,34 +124,34 @@ class InstallationProcessor @Inject constructor( emit(it) isInstallRunning(it) } .collect { latestFusedDownload -> handleFusedDownload(latestFusedDownload, appInstall, isUpdateWork) .collect { latestDownload -> handleDownload(latestDownload, appInstall, isUpdateWork) } } private suspend fun handleFusedDownload( latestAppInstall: AppInstall?, private suspend fun handleDownload( latestDownload: AppInstall?, appInstall: AppInstall, isUpdateWork: Boolean ) { if (latestAppInstall == null) { if (latestDownload == null) { Timber.d("===> download null: finish installation") finishInstallation(appInstall, isUpdateWork) return } handleFusedDownloadStatusCheckingException(latestAppInstall, isUpdateWork) handleDownloadStatusCheckingException(latestDownload, isUpdateWork) } private fun isInstallRunning(it: AppInstall?) = it != null && it.status != Status.INSTALLATION_ISSUE private suspend fun handleFusedDownloadStatusCheckingException( private suspend fun handleDownloadStatusCheckingException( download: AppInstall, isUpdateWork: Boolean ) { runCatching { handleFusedDownloadStatus(download, isUpdateWork) handleDownloadStatus(download, isUpdateWork) }.onFailure { throwable -> when (throwable) { is CancellationException -> throw throwable Loading @@ -169,7 +169,7 @@ class InstallationProcessor @Inject constructor( } } private suspend fun handleFusedDownloadStatus(appInstall: AppInstall, isUpdateWork: Boolean) { private suspend fun handleDownloadStatus(appInstall: AppInstall, isUpdateWork: Boolean) { when (appInstall.status) { Status.AWAITING, Status.DOWNLOADING -> Unit Status.DOWNLOADED -> appManager.updateDownloadStatus( Loading