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

Verified Commit 308e1ec3 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

refactor: rename InstallHelper to InstallOrchestrator

parent cb9eb567
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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
@@ -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() {
@@ -134,7 +138,7 @@ class AppLoungeApplication : Application(), Configuration.Provider {
            removeStalledInstallationFromDb()
        }

        installHelper.init()
        installOrchestrator.init()
    }

    private fun isRunningUnderRobolectric(): Boolean = Build.FINGERPRINT == "robolectric"
+1 −1
Original line number Diff line number Diff line
@@ -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")
+1 −1
Original line number Diff line number Diff line
@@ -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,
+22 −22
Original line number Diff line number Diff line
@@ -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
@@ -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()
@@ -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)
@@ -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)
@@ -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())
@@ -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) }
@@ -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()) }
@@ -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))
@@ -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())
@@ -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())
@@ -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) }
@@ -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()