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

Commit 38dd11b1 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

feature(SystemAppsUpdatesRepository.kt): add method to get Android version code's letter

parent 1c3853a9
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import javax.inject.Inject
import javax.inject.Singleton
import timber.log.Timber

private class UnsupportedAndroidApiException(message: String) : RuntimeException(message)

@Singleton
class SystemAppsUpdatesRepository @Inject constructor(
    @ApplicationContext private val context: Context,
@@ -40,9 +42,17 @@ class SystemAppsUpdatesRepository @Inject constructor(
    private val systemAppDefinitionApi: SystemAppDefinitionApi,
    private val applicationDataManager: ApplicationDataManager,
    private val appLoungePackageManager: AppLoungePackageManager,
    private val releaseInfoApi: ReleaseInfoApi,
    private val releaseInfoApi: GitLabReleaseInfoApi,
) {

    private val androidVersionCode by lazy {
        try { getAndroidVersionCodeChar() }
        catch (exception: RuntimeException) {
            Timber.w(exception.message)
            "UnsupportedAndroidAPI"
        }
    }

    private val systemAppProjectList = mutableListOf<SystemAppProject>()

    private fun getUpdatableSystemApps(): List<String> {
@@ -80,7 +90,6 @@ class SystemAppsUpdatesRepository @Inject constructor(
        }
    }


    private fun isEligibleToFetchAppListFromTest(systemName: String) = systemName.isBlank() ||
            systemName.contains("beta") ||
            systemName.contains("rc") ||
@@ -168,6 +177,22 @@ 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 {
        val baseAPI = Build.VERSION_CODES.BASE
        val lastUnsupportedAPI = Build.VERSION_CODES.R

        return when (val currentAPI = Build.VERSION.SDK_INT) {
            in baseAPI.. lastUnsupportedAPI -> throw UnsupportedAndroidApiException("Android $currentAPI is not supported anymore")
            Build.VERSION_CODES.S -> "S"
            Build.VERSION_CODES.TIRAMISU -> "T"
            else -> throw UnsupportedAndroidApiException("Android $currentAPI and above is not yet supported")
        }
    }

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