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

Commit 666ff2c3 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

move fetching system apps definition to AppsApiImpl

parent ef4c96f7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -156,4 +156,6 @@ class ApplicationRepository @Inject constructor(
        appsApi.isAnyAppInstallStatusChanged(currentList)

    fun isOpenSourceSelected() = appsApi.isOpenSourceSelected()

    suspend fun getSystemUpdates(): List<Application> = appsApi.getSystemUpdates()
}
+2 −0
Original line number Diff line number Diff line
@@ -66,4 +66,6 @@ interface AppsApi {

    fun isAnyAppInstallStatusChanged(currentList: List<Application>): Boolean
    fun isOpenSourceSelected(): Boolean

    suspend fun getSystemUpdates(): List<Application>
}
+49 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
package foundation.e.apps.data.application.apps

import android.content.Context
import android.os.Build
import com.aurora.gplayapi.data.models.App
import com.aurora.gplayapi.data.models.AuthData
import dagger.hilt.android.qualifiers.ApplicationContext
@@ -32,9 +33,12 @@ import foundation.e.apps.data.enums.Origin
import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.enums.Status
import foundation.e.apps.data.enums.isUnFiltered
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
import foundation.e.apps.ui.applicationlist.ApplicationDiffUtil
import foundation.e.apps.utils.SystemInfoProvider
import retrofit2.Response
import javax.inject.Inject
import foundation.e.apps.data.cleanapk.data.app.Application as CleanApkApplication
@@ -43,7 +47,9 @@ class AppsApiImpl @Inject constructor(
    @ApplicationContext private val context: Context,
    private val appLoungePreference: AppLoungePreference,
    private val appSources: AppSourcesContainer,
    private val applicationDataManager: ApplicationDataManager
    private val applicationDataManager: ApplicationDataManager,
    private val systemAppsUpdatesRepository: SystemAppsUpdatesRepository,
    private val appLoungePackageManager: AppLoungePackageManager,
) : AppsApi {

    companion object {
@@ -212,6 +218,48 @@ class AppsApiImpl @Inject constructor(
        return Pair(result.data ?: Application(), result.getResultStatus())
    }

    override suspend fun getSystemUpdates(): List<Application> {
        val updateList = mutableListOf<Application>()
        val releaseType = getSystemReleaseType()

        val eligibleApps = systemAppsUpdatesRepository.getAllEligibleApps()
        eligibleApps?.forEach {
            val packageName = it.packageName

            if (!appLoungePackageManager.isInstalled(it.packageName)) {
                // Don't install for system apps which are removed (by root or otherwise)
                return@forEach
            }

            val releaseTypes = it.releaseTypes
            if (releaseType in releaseTypes) {
                systemAppsUpdatesRepository.getSystemAppUpdateInfo(
                    packageName,
                    releaseType,
                    getSdkLevel(),
                    getDevice(),
                )?.run {
                    applicationDataManager.updateStatus(this)
                    updateList.add(this)
                }
            }
        }

        return updateList
    }

    private fun getSdkLevel(): Int {
        return Build.VERSION.SDK_INT
    }

    private fun getDevice(): String {
        return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_DEVICE) ?: ""
    }

    private fun getSystemReleaseType(): String {
        return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_RELEASE_TYPE) ?: ""
    }

    override fun getFusedAppInstallationStatus(application: Application): Status {
        return applicationDataManager.getFusedAppInstallationStatus(application)
    }
+0 −3
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@

package foundation.e.apps.data.gitlab

import foundation.e.apps.data.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.gitlab.models.EligibleSystemApps
import foundation.e.apps.data.gitlab.models.toApplication
@@ -28,7 +27,6 @@ import timber.log.Timber
@Singleton
class SystemAppsUpdatesRepository @Inject constructor(
    private val systemAppsUpdatesApi: SystemAppsUpdatesApi,
    private val applicationDataManager: ApplicationDataManager,
) {

    suspend fun getAllEligibleApps(): List<EligibleSystemApps>? {
@@ -72,7 +70,6 @@ class SystemAppsUpdatesRepository @Inject constructor(
            }
            else -> {
                val app = updateDef.toApplication()
                app.status = applicationDataManager.getFusedAppInstallationStatus(app)
                app
            }
        }
+1 −45
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ class UpdatesManagerImpl @Inject constructor(
    private val faultyAppRepository: FaultyAppRepository,
    private val appLoungePreference: AppLoungePreference,
    private val fdroidRepository: FdroidRepository,
    private val systemAppsUpdatesRepository: SystemAppsUpdatesRepository,
    private val blockedAppRepository: BlockedAppRepository,
) {

@@ -173,38 +172,7 @@ class UpdatesManagerImpl @Inject constructor(
        return Pair(nonFaultyUpdateList + systemApps, status)
    }

    suspend fun getSystemUpdates(onlySelf: Boolean = false): List<Application> {
        val updateList = mutableListOf<Application>()
        val releaseType = getSystemReleaseType()

        val eligibleApps = systemAppsUpdatesRepository.getAllEligibleApps()
        eligibleApps?.forEach {
            val packageName = it.packageName

            if (onlySelf && packageName != context.packageName) {
                return@forEach
            }

            if (!appLoungePackageManager.isInstalled(it.packageName)) {
                // Don't install for system apps which are removed (by root or otherwise)
                return@forEach
            }

            val releaseTypes = it.releaseTypes
            if (releaseType in releaseTypes) {
                systemAppsUpdatesRepository.getSystemAppUpdateInfo(
                    packageName,
                    releaseType,
                    getSdkLevel(),
                    getDevice(),
                )?.run {
                    updateList.add(this)
                }
            }
        }

        return updateList
    }
    suspend fun getSystemUpdates(): List<Application> = applicationRepository.getSystemUpdates()

    private fun putAppLoungeAtLast(updateList: MutableList<Application>) {
        val appLoungeItem = updateList.find { it.isSystemApp && it.package_name == context.packageName }
@@ -213,18 +181,6 @@ class UpdatesManagerImpl @Inject constructor(
        updateList.add(appLoungeItem)
    }

    private fun getSdkLevel(): Int {
        return Build.VERSION.SDK_INT
    }

    private fun getDevice(): String {
        return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_DEVICE) ?: ""
    }

    private fun getSystemReleaseType(): String {
        return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_RELEASE_TYPE) ?: ""
    }

    /**
     * Lists apps directly updatable by App Lounge from the Open Source category.
     * (This includes apps installed by F-Droid client app, if used by the user;
Loading