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

Commit f21de93e authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

fetch system apps updates from UpdatesManagerImpl

parent cb6be449
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import foundation.e.apps.data.playstore.PlayStoreRepositoryImpl
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.application.search.SearchApi.Companion.APP_TYPE_ANY
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.gitlab.SystemAppsUpdatesRepository
import foundation.e.apps.data.handleNetworkResult
import foundation.e.apps.data.preference.AppLoungePreference
import foundation.e.apps.install.pkg.AppLoungePackageManager
@@ -53,6 +54,7 @@ class UpdatesManagerImpl @Inject constructor(
    private val appLoungePreference: AppLoungePreference,
    private val fdroidRepository: FdroidRepository,
    private val blockedAppRepository: BlockedAppRepository,
    private val systemAppsUpdatesRepository: SystemAppsUpdatesRepository,
) {

    companion object {
@@ -123,8 +125,12 @@ class UpdatesManagerImpl @Inject constructor(
            status = if (status == ResultStatus.OK) status else gplayStatus
        }

        val systemApps = getSystemUpdates()
        val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList)
        return Pair(nonFaultyUpdateList, status)

        arrangeWithSystemApps(updateList, nonFaultyUpdateList, systemApps)

        return Pair(updateList, status)
    }

    suspend fun getUpdatesOSS(): Pair<List<Application>, ResultStatus> {
@@ -157,8 +163,30 @@ class UpdatesManagerImpl @Inject constructor(
            }, updateList)
        }

        val systemApps = getSystemUpdates()
        val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList)
        return Pair(nonFaultyUpdateList, status)

        arrangeWithSystemApps(updateList, nonFaultyUpdateList, systemApps)

        return Pair(updateList, status)
    }

    private suspend fun getSystemUpdates(): List<Application> {
        val systemApps = mutableListOf<Application>()
        getUpdatesFromApi({
            Pair(systemAppsUpdatesRepository.getSystemUpdates(), ResultStatus.OK)
        }, systemApps)
        return systemApps
    }

    private fun arrangeWithSystemApps(
        updateList: MutableList<Application>,
        nonFaultyApps: List<Application>,
        systemApps: List<Application>,
    ) {
        updateList.clear()
        updateList.addAll(nonFaultyApps)
        updateList.addAll(systemApps)
    }

    /**
+5 −2
Original line number Diff line number Diff line
@@ -47,8 +47,11 @@ object UpdatesWorkManager {
        return OneTimeWorkRequest.Builder(UpdatesWorker::class.java).apply {
            setConstraints(buildWorkerConstraints())
            addTag(USER_TAG)
        }.setInputData(Data.Builder().putBoolean(UpdatesWorker.IS_AUTO_UPDATE, false).build())
        }.setInputData(
            Data.Builder()
                .putBoolean(UpdatesWorker.IS_AUTO_UPDATE, false)
                .build()
        ).build()
    }

    private fun buildWorkerConstraints() = Constraints.Builder().apply {
+9 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import foundation.e.apps.data.blockedApps.BlockedAppRepository
import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.enums.User
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.gitlab.SystemAppsUpdatesRepository
import foundation.e.apps.data.login.AuthenticatorRepository
import foundation.e.apps.data.preference.DataStoreManager
import foundation.e.apps.data.updates.UpdatesManagerRepository
@@ -40,6 +41,7 @@ class UpdatesWorker @AssistedInject constructor(
    private val authenticatorRepository: AuthenticatorRepository,
    private val appInstallProcessor: AppInstallProcessor,
    private val blockedAppRepository: BlockedAppRepository,
    private val systemAppsUpdatesRepository: SystemAppsUpdatesRepository,
) : CoroutineWorker(context, params) {

    companion object {
@@ -62,6 +64,7 @@ class UpdatesWorker @AssistedInject constructor(
            }

            refreshBlockedAppList()
            refreshEligibleSystemApps()
            checkForUpdates()
            Result.success()
        } catch (e: Throwable) {
@@ -80,6 +83,12 @@ class UpdatesWorker @AssistedInject constructor(
        }
    }

    private suspend fun refreshEligibleSystemApps() {
        if (systemAppsUpdatesRepository.getAllEligibleApps().isEmpty()) {
            systemAppsUpdatesRepository.fetchAllEligibleApps()
        }
    }

    private suspend fun checkManualUpdateRunning(): Boolean {
        val workInfos =
            withContext(Dispatchers.IO) {