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

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

Merge branch '8124-update_system_apps_p3' into '8124-update_system_apps_p2'

feat: (Issue 8124) Integrate system update API to updater

See merge request !477
parents 0efaa76f 9d37f4c6
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ class MainActivity : AppCompatActivity() {

        viewModel.updateAppWarningList()
        viewModel.updateContentRatings()
        viewModel.fetchUpdatableSystemAppsList()

        observeEvents()

+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ class DownloadInfoApiImpl @Inject constructor(
            }

            Origin.GITLAB_RELEASES -> {
                // TODO
                return // nothing to do as downloadURLList is already set
            }
        }

+8 −5
Original line number Diff line number Diff line
@@ -43,8 +43,15 @@ class SystemAppsUpdatesRepository @Inject constructor(

    private var systemAppProjectList = mutableListOf<SystemAppProject>()

    suspend fun fetchUpdatableSystemApps() {
    private fun getUpdatableSystemApps(): List<String> {
        return systemAppProjectList.map { it.packageName }
    }

    suspend fun fetchUpdatableSystemApps(forceRefresh: Boolean = false) {
        val result = handleNetworkResult {
            if (getUpdatableSystemApps().isNotEmpty() && !forceRefresh) {
                return@handleNetworkResult
            }
            val response = updatableSystemAppsApi.getUpdatableSystemApps()
            if (response.isSuccessful && !response.body().isNullOrEmpty()) {
                response.body()?.let { systemAppProjectList.addAll(it) }
@@ -58,10 +65,6 @@ class SystemAppsUpdatesRepository @Inject constructor(
        }
    }

    fun getUpdatableSystemApps(): List<String> {
        return systemAppProjectList.map { it.packageName }
    }

    private fun isSystemAppBlocked(
        systemAppInfo: SystemAppInfo,
        sdkLevel: Int,
+35 −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 = getSystemAppUpdates()
        val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList)
        return Pair(nonFaultyUpdateList, status)

        addSystemAppsAtFirst(updateList, nonFaultyUpdateList, systemApps)

        return Pair(updateList, status)
    }

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

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

        addSystemAppsAtFirst(updateList, nonFaultyUpdateList, systemApps)

        return Pair(updateList, status)
    }

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

    /**
     * This method adds the system app updates at the beginning of the update list.
     * It will ensure our system apps are updated first, followed by other apps,
     * avoiding potential conflicts.
     */
    private fun addSystemAppsAtFirst(
        updateList: MutableList<Application>,
        nonFaultyApps: List<Application>,
        systemApps: List<Application>,
    ) {
        updateList.clear()
        updateList.addAll(systemApps)
        updateList.addAll(nonFaultyApps)
    }

    /**
+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 {
Loading