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

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

single method to get eligible system apps with forceRefresh flag

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


    private var systemAppProjectList = mutableListOf<SystemAppProject>()
    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 {
        val result = handleNetworkResult {
            if (getUpdatableSystemApps().isNotEmpty() && !forceRefresh) {
                return@handleNetworkResult
            }
            val response = updatableSystemAppsApi.getUpdatableSystemApps()
            val response = updatableSystemAppsApi.getUpdatableSystemApps()
            if (response.isSuccessful && !response.body().isNullOrEmpty()) {
            if (response.isSuccessful && !response.body().isNullOrEmpty()) {
                response.body()?.let { systemAppProjectList.addAll(it) }
                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(
    private fun isSystemAppBlocked(
        systemAppInfo: SystemAppInfo,
        systemAppInfo: SystemAppInfo,
        sdkLevel: Int,
        sdkLevel: Int,
+1 −7
Original line number Original line Diff line number Diff line
@@ -64,7 +64,7 @@ class UpdatesWorker @AssistedInject constructor(
            }
            }


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


    private suspend fun refreshEligibleSystemApps() {
        if (systemAppsUpdatesRepository.getEligibleSystemApps().isEmpty()) {
            systemAppsUpdatesRepository.fetchEligibleSystemApps()
        }
    }

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