Loading app/src/main/java/foundation/e/apps/AppLoungeApplication.kt +6 −2 Original line number Diff line number Diff line Loading @@ -35,6 +35,10 @@ import foundation.e.apps.data.install.pkg.AppLoungePackageManager import foundation.e.apps.data.install.pkg.PkgManagerBR import foundation.e.apps.data.install.updates.UpdatesWorkManager import foundation.e.apps.data.install.workmanager.InstallHelper import foundation.e.apps.data.install.workmanager.InstallOrchestrator import foundation.e.apps.data.install.workmanager.InstallWorkManager import foundation.e.apps.data.preference.AppLoungeDataStore import foundation.e.apps.data.preference.AppLoungePreference import foundation.e.apps.data.system.CustomUncaughtExceptionHandler import foundation.e.apps.domain.preferences.SessionRepository import foundation.e.apps.domain.preferences.updateinterval.GetUpdateIntervalUseCase Loading Loading @@ -82,7 +86,7 @@ class AppLoungeApplication : Application(), Configuration.Provider { lateinit var pkgManagerBR: PkgManagerBR @Inject lateinit var installHelper: InstallHelper lateinit var installOrchestrator: InstallOrchestrator @RequiresApi(Build.VERSION_CODES.TIRAMISU) override fun onCreate() { Loading Loading @@ -134,7 +138,7 @@ class AppLoungeApplication : Application(), Configuration.Provider { removeStalledInstallationFromDb() } installHelper.init() installOrchestrator.init() } private fun isRunningUnderRobolectric(): Boolean = Build.FINGERPRINT == "robolectric" Loading app/src/main/java/foundation/e/apps/data/install/workmanager/AppInstallProcessor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -147,7 +147,7 @@ class AppInstallProcessor @Inject constructor( appInstallComponents.appManagerWrapper.updateAwaiting(appInstall) // Use only for update work for now. For installation work, see InstallHelper#observeDownloads() // Use only for update work for now. For installation work, see InstallOrchestrator#observeDownloads() if (isAnUpdate) { InstallWorkManager.enqueueWork(context, appInstall, true) Timber.d("UPDATE: Successfully enqueued unique work: $uniqueWorkName") Loading app/src/main/java/foundation/e/apps/data/install/workmanager/InstallHelper.kt→app/src/main/java/foundation/e/apps/data/install/workmanager/InstallOrchestrator.kt +1 −1 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ import timber.log.Timber import javax.inject.Inject @Suppress("TooGenericExceptionCaught") class InstallHelper @Inject constructor( class InstallOrchestrator @Inject constructor( @param:ApplicationContext val context: Context, @param:IoCoroutineScope private val scope: CoroutineScope, private val appManagerWrapper: AppManagerWrapper, Loading app/src/test/java/foundation/e/apps/install/workmanager/InstallHelperTest.kt→app/src/test/java/foundation/e/apps/install/workmanager/InstallOrchestratorTest.kt +22 −22 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ import foundation.e.apps.data.enums.Status import foundation.e.apps.data.install.AppInstallDAO import foundation.e.apps.data.install.AppManagerWrapper import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.install.workmanager.InstallHelper import foundation.e.apps.data.install.workmanager.InstallOrchestrator import foundation.e.apps.data.install.workmanager.InstallWorkManager import foundation.e.apps.util.MainCoroutineRule import io.mockk.every Loading Loading @@ -67,7 +67,7 @@ import java.util.concurrent.TimeUnit @OptIn(ExperimentalCoroutinesApi::class) @RunWith(RobolectricTestRunner::class) @Config(sdk = [Build.VERSION_CODES.N]) class InstallHelperTest { class InstallOrchestratorTest { @get:Rule val mainCoroutineRule = MainCoroutineRule() Loading Loading @@ -98,9 +98,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(listOf(app)), emptyFlow()) whenever(appManagerWrapper.isFusedDownloadInstalled(app)).thenReturn(false) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper).installationIssue(app) Loading @@ -114,9 +114,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(listOf(app)), emptyFlow()) whenever(appManagerWrapper.isFusedDownloadInstalled(app)).thenReturn(true) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper).updateDownloadStatus(app, Status.INSTALLED) Loading @@ -139,9 +139,9 @@ class InstallHelperTest { whenever(packageInstaller.allSessions).thenReturn(listOf(sessionInfo)) whenever(installDao.getDownloads()).thenReturn(flowOf(listOf(app)), emptyFlow()) val helper = InstallHelper(wrappedContext, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(wrappedContext, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper, never()).installationIssue(any()) Loading @@ -155,9 +155,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(emptyList()), flowOf(listOf(awaiting))) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verify(exactly = 1) { InstallWorkManager.enqueueWork(awaiting, false) } Loading @@ -172,9 +172,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()) .thenReturn(flowOf(emptyList()), flowOf(listOf(active, awaiting))) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verify(exactly = 0) { InstallWorkManager.enqueueWork(any(), any()) } Loading @@ -187,9 +187,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(emptyList()), flowOf(listOf(awaiting))) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper, times(1)).installationIssue(eq(awaiting)) Loading @@ -206,9 +206,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(listOf(app)), emptyFlow()) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper, never()).installationIssue(any()) Loading @@ -223,9 +223,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(emptyList()), flowOf(listOf(awaiting))) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper, never()).installationIssue(any()) Loading @@ -240,9 +240,9 @@ class InstallHelperTest { .thenThrow(RuntimeException("reconcile failed")) .thenReturn(flowOf(listOf(awaiting))) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verify(exactly = 1) { InstallWorkManager.enqueueWork(awaiting, false) } Loading @@ -252,9 +252,9 @@ class InstallHelperTest { fun init_stopsAfterCancellationExceptionDuringReconciliation() = runTest { whenever(installDao.getDownloads()).thenThrow(CancellationException("cancel reconcile")) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(installDao, times(1)).getDownloads() Loading Loading
app/src/main/java/foundation/e/apps/AppLoungeApplication.kt +6 −2 Original line number Diff line number Diff line Loading @@ -35,6 +35,10 @@ import foundation.e.apps.data.install.pkg.AppLoungePackageManager import foundation.e.apps.data.install.pkg.PkgManagerBR import foundation.e.apps.data.install.updates.UpdatesWorkManager import foundation.e.apps.data.install.workmanager.InstallHelper import foundation.e.apps.data.install.workmanager.InstallOrchestrator import foundation.e.apps.data.install.workmanager.InstallWorkManager import foundation.e.apps.data.preference.AppLoungeDataStore import foundation.e.apps.data.preference.AppLoungePreference import foundation.e.apps.data.system.CustomUncaughtExceptionHandler import foundation.e.apps.domain.preferences.SessionRepository import foundation.e.apps.domain.preferences.updateinterval.GetUpdateIntervalUseCase Loading Loading @@ -82,7 +86,7 @@ class AppLoungeApplication : Application(), Configuration.Provider { lateinit var pkgManagerBR: PkgManagerBR @Inject lateinit var installHelper: InstallHelper lateinit var installOrchestrator: InstallOrchestrator @RequiresApi(Build.VERSION_CODES.TIRAMISU) override fun onCreate() { Loading Loading @@ -134,7 +138,7 @@ class AppLoungeApplication : Application(), Configuration.Provider { removeStalledInstallationFromDb() } installHelper.init() installOrchestrator.init() } private fun isRunningUnderRobolectric(): Boolean = Build.FINGERPRINT == "robolectric" Loading
app/src/main/java/foundation/e/apps/data/install/workmanager/AppInstallProcessor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -147,7 +147,7 @@ class AppInstallProcessor @Inject constructor( appInstallComponents.appManagerWrapper.updateAwaiting(appInstall) // Use only for update work for now. For installation work, see InstallHelper#observeDownloads() // Use only for update work for now. For installation work, see InstallOrchestrator#observeDownloads() if (isAnUpdate) { InstallWorkManager.enqueueWork(context, appInstall, true) Timber.d("UPDATE: Successfully enqueued unique work: $uniqueWorkName") Loading
app/src/main/java/foundation/e/apps/data/install/workmanager/InstallHelper.kt→app/src/main/java/foundation/e/apps/data/install/workmanager/InstallOrchestrator.kt +1 −1 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ import timber.log.Timber import javax.inject.Inject @Suppress("TooGenericExceptionCaught") class InstallHelper @Inject constructor( class InstallOrchestrator @Inject constructor( @param:ApplicationContext val context: Context, @param:IoCoroutineScope private val scope: CoroutineScope, private val appManagerWrapper: AppManagerWrapper, Loading
app/src/test/java/foundation/e/apps/install/workmanager/InstallHelperTest.kt→app/src/test/java/foundation/e/apps/install/workmanager/InstallOrchestratorTest.kt +22 −22 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ import foundation.e.apps.data.enums.Status import foundation.e.apps.data.install.AppInstallDAO import foundation.e.apps.data.install.AppManagerWrapper import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.install.workmanager.InstallHelper import foundation.e.apps.data.install.workmanager.InstallOrchestrator import foundation.e.apps.data.install.workmanager.InstallWorkManager import foundation.e.apps.util.MainCoroutineRule import io.mockk.every Loading Loading @@ -67,7 +67,7 @@ import java.util.concurrent.TimeUnit @OptIn(ExperimentalCoroutinesApi::class) @RunWith(RobolectricTestRunner::class) @Config(sdk = [Build.VERSION_CODES.N]) class InstallHelperTest { class InstallOrchestratorTest { @get:Rule val mainCoroutineRule = MainCoroutineRule() Loading Loading @@ -98,9 +98,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(listOf(app)), emptyFlow()) whenever(appManagerWrapper.isFusedDownloadInstalled(app)).thenReturn(false) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper).installationIssue(app) Loading @@ -114,9 +114,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(listOf(app)), emptyFlow()) whenever(appManagerWrapper.isFusedDownloadInstalled(app)).thenReturn(true) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper).updateDownloadStatus(app, Status.INSTALLED) Loading @@ -139,9 +139,9 @@ class InstallHelperTest { whenever(packageInstaller.allSessions).thenReturn(listOf(sessionInfo)) whenever(installDao.getDownloads()).thenReturn(flowOf(listOf(app)), emptyFlow()) val helper = InstallHelper(wrappedContext, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(wrappedContext, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper, never()).installationIssue(any()) Loading @@ -155,9 +155,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(emptyList()), flowOf(listOf(awaiting))) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verify(exactly = 1) { InstallWorkManager.enqueueWork(awaiting, false) } Loading @@ -172,9 +172,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()) .thenReturn(flowOf(emptyList()), flowOf(listOf(active, awaiting))) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verify(exactly = 0) { InstallWorkManager.enqueueWork(any(), any()) } Loading @@ -187,9 +187,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(emptyList()), flowOf(listOf(awaiting))) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper, times(1)).installationIssue(eq(awaiting)) Loading @@ -206,9 +206,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(listOf(app)), emptyFlow()) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper, never()).installationIssue(any()) Loading @@ -223,9 +223,9 @@ class InstallHelperTest { whenever(installDao.getDownloads()).thenReturn(flowOf(emptyList()), flowOf(listOf(awaiting))) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(appManagerWrapper, never()).installationIssue(any()) Loading @@ -240,9 +240,9 @@ class InstallHelperTest { .thenThrow(RuntimeException("reconcile failed")) .thenReturn(flowOf(listOf(awaiting))) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verify(exactly = 1) { InstallWorkManager.enqueueWork(awaiting, false) } Loading @@ -252,9 +252,9 @@ class InstallHelperTest { fun init_stopsAfterCancellationExceptionDuringReconciliation() = runTest { whenever(installDao.getDownloads()).thenThrow(CancellationException("cancel reconcile")) val helper = InstallHelper(context, this, appManagerWrapper, installDao) val installOrchestrator = InstallOrchestrator(context, this, appManagerWrapper, installDao) helper.init() installOrchestrator.init() advanceUntilIdle() verifyMockito(installDao, times(1)).getDownloads() Loading