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

Commit 1058e7cc authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

feature(SystemAppsUpdatesRepository.kt): finish the implementation & add small...

feature(SystemAppsUpdatesRepository.kt): finish the implementation & add small refactoring to avoid NPE
parent 1af86365
Loading
Loading
Loading
Loading
Loading
+26 −17
Original line number Diff line number Diff line
@@ -109,10 +109,10 @@ class SystemAppsUpdatesRepository @Inject constructor(
    }

    private suspend fun getReleaseDetailsUrl(
        projectId: Int,
        systemAppProject: SystemAppProject,
        releaseType: OsReleaseType,
        isAndroidApiSpecific: Boolean
    ): String? {
        val projectId = systemAppProject.projectId
        val releaseResponse = releaseInfoApi.getReleases(projectId)
        val releases = releaseResponse.body()?.toMutableList()

@@ -121,7 +121,7 @@ class SystemAppsUpdatesRepository @Inject constructor(
            return null
        }

        if (isAndroidApiSpecific) {
        if (systemAppProject.dependsOnAndroidVersion) {
            releases.removeIf { !it.tagName.contains("-api$androidVersionCode-")}
        }

@@ -138,7 +138,7 @@ class SystemAppsUpdatesRepository @Inject constructor(
        return null
    }

    private suspend fun getSystemAppUpdateInfo(
    private suspend fun getApplication(
        packageName: String,
        releaseType: OsReleaseType,
        sdkLevel: Int,
@@ -146,18 +146,11 @@ class SystemAppsUpdatesRepository @Inject constructor(
    ): Application? {

        val systemAppProject = systemAppProjectList.find { it.packageName == packageName } ?: return null
        val projectId = systemAppProject.projectId
        val isAndroidApiSpecific =  systemAppProject.dependsOnAndroidVersion
        val detailsUrl = getReleaseDetailsUrl(systemAppProject, releaseType)

        val detailsUrl = getReleaseDetailsUrl(projectId, releaseType, isAndroidApiSpecific) ?: return null

        val response = systemAppDefinitionApi.getSystemAppUpdateInfo(detailsUrl)
        val systemAppInfo = response.body()
        val systemAppInfo = getSystemAppInfo(packageName, detailsUrl) ?: return null

        return if (systemAppInfo == null) {
            Timber.e("Null app info for: $packageName, response: ${response.errorBody()?.string()}")
            null
        } else if (isSystemAppBlocked(systemAppInfo, sdkLevel, device)) {
        return if (isSystemAppBlocked(systemAppInfo, sdkLevel, device)) {
            Timber.e("Blocked system app: $packageName, details: $systemAppInfo")
            null
        } else {
@@ -165,6 +158,22 @@ class SystemAppsUpdatesRepository @Inject constructor(
        }
    }

    private suspend fun getSystemAppInfo(
        packageName: String,
        detailsUrl: String?
    ): SystemAppInfo? {
        if (detailsUrl.isNullOrEmpty()) return null

        val response = systemAppDefinitionApi.getSystemAppUpdateInfo(detailsUrl)

        return if (response.isSuccessful ) {
            response.body()
        } else {
            Timber.e("Can't get AppInfo for $packageName, response: ${response.errorBody()?.string()}")
            null
        }
    }

    private fun getFullSystemName(): String {
        return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_VERSION) ?: ""
    }
@@ -187,7 +196,7 @@ class SystemAppsUpdatesRepository @Inject constructor(
     * This method must be updated when Murena or /e/ foundation support new Android version
     * or stop to support an old one
     */
    fun getAndroidVersionCodeChar(): String {
    private fun getAndroidVersionCodeChar(): String {
        val baseAPI = Build.VERSION_CODES.BASE
        val lastUnsupportedAPI = Build.VERSION_CODES.R

@@ -214,7 +223,7 @@ class SystemAppsUpdatesRepository @Inject constructor(
            }

            val result = handleNetworkResult {
                getSystemAppUpdateInfo(
                getApplication(
                    it,
                    releaseType,
                    sdkLevel,