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

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

update gitlab API and system apps update repository

parent b48ba618
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -15,13 +15,20 @@
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.data.gitlab.models
package foundation.e.apps.data.gitlab

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.squareup.moshi.Json
import foundation.e.apps.data.gitlab.models.ProjectIdMapItem
import retrofit2.Response
import retrofit2.http.GET

@JsonIgnoreProperties(ignoreUnknown = true)
data class EligibleSystemApps(
    @Json(name = "package_name") val packageName: String,
    @Json(name = "release_types") val releaseTypes: List<String>,
)
interface EligibleSystemAppsApi {

    companion object {
        const val BASE_URL =
            "https://gitlab.e.foundation/e/os/blocklist-app-lounge/-/raw/7846-apk_publish_poc/"
    }

    @GET("updatable_system_apps.json")
    suspend fun getAllEligibleApps(): Response<List<ProjectIdMapItem>>

}
 No newline at end of file
+21 −0
Original line number Diff line number Diff line
package foundation.e.apps.data.gitlab

import foundation.e.apps.data.gitlab.models.UpdateDefinition
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Path

interface SystemAppDefinitionApi {

    companion object {
        const val BASE_URL =
            "https://gitlab.e.foundation/api/v4/projects/"
    }

    @GET("{projectId}/releases/permalink/latest/downloads/json/{releaseType}.json")
    suspend fun getSystemAppUpdateInfo(
        @Path("projectId") projectId: Int,
        @Path("releaseType") releaseType: String,
    ): Response<UpdateDefinition>

}
 No newline at end of file
+0 −42
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019-2023  E FOUNDATION
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.data.gitlab

import foundation.e.apps.data.gitlab.models.EligibleSystemApps
import foundation.e.apps.data.gitlab.models.UpdateDefinition
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Path

interface SystemAppsUpdatesApi {

    companion object {
        const val BASE_URL =
            "https://gitlab.e.foundation/e/os/update-assets/-/raw/main/"
    }

    @GET("eligible_apps.json")
    suspend fun getAllEligibleApps(): Response<List<EligibleSystemApps>>

    @GET("{packageName}/{releaseType}.json")
    suspend fun getSystemAppUpdateInfo(
        @Path("packageName") packageName: String,
        @Path("releaseType") releaseType: String,
    ): Response<UpdateDefinition>

}
 No newline at end of file
+22 −10
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
package foundation.e.apps.data.gitlab

import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.gitlab.models.EligibleSystemApps
import foundation.e.apps.data.gitlab.models.ProjectIdMapItem
import foundation.e.apps.data.gitlab.models.toApplication
import javax.inject.Inject
import javax.inject.Singleton
@@ -26,13 +26,21 @@ import timber.log.Timber

@Singleton
class SystemAppsUpdatesRepository @Inject constructor(
    private val systemAppsUpdatesApi: SystemAppsUpdatesApi,
    private val eligibleSystemAppsApi: EligibleSystemAppsApi,
    private val systemAppDefinitionApi: SystemAppDefinitionApi,
) {

    suspend fun getAllEligibleApps(): List<EligibleSystemApps>? {
        val response = systemAppsUpdatesApi.getAllEligibleApps()
        if (!response.isSuccessful) return emptyList()
        return response.body()
    private var projectIdMap = mutableListOf<ProjectIdMapItem>()

    suspend fun fetchAllEligibleApps() {
        val response = eligibleSystemAppsApi.getAllEligibleApps()
        if (response.isSuccessful && !response.body().isNullOrEmpty()) {
            response.body()?.let { projectIdMap.addAll(it) }
        }
    }

    fun getAllEligibleApps(): List<String> {
        return projectIdMap.map { it.packageName }
    }

    suspend fun getSystemAppUpdateInfo(
@@ -41,7 +49,11 @@ class SystemAppsUpdatesRepository @Inject constructor(
        sdkLevel: Int,
        device: String,
    ): Application? {
        val response = systemAppsUpdatesApi.getSystemAppUpdateInfo(packageName, releaseType)

        val projectId =
            projectIdMap.find { it.packageName == packageName }?.projectId ?: return null

        val response = systemAppDefinitionApi.getSystemAppUpdateInfo(projectId, releaseType)
        if (!response.isSuccessful) {
            Timber.e("Failed to fetch system app update definition for: $packageName, $releaseType")
            return null
@@ -54,15 +66,15 @@ class SystemAppsUpdatesRepository @Inject constructor(
                Timber.e("Null update definition: $packageName, $releaseType")
                null
            }
            !updateDef.eligibleAndroidPlatforms.contains(sdkLevel) -> {
            updateDef.blacklistedAndroid?.contains(sdkLevel) == true -> {
                Timber.e("Ineligible sdk level: $packageName, $sdkLevel")
                null
            }
            updateDef.blacklistedDevices.contains(device) -> {
            updateDef.blacklistedDevices?.contains(device) == true -> {
                Timber.e("blacklisted device: $packageName, $device")
                null
            }
            updateDef.blacklistedDevices.contains("${device}@${sdkLevel}") -> {
            updateDef.blacklistedDevices?.contains("${device}@${sdkLevel}") == true -> {
                // In case a device on a specific android version is blacklisted.
                // Eg: "redfin@31" would mean Pixel 5 on Android 12 cannot receive this update.
                Timber.e("blacklisted device: $packageName, ${device}@${sdkLevel}")
+6 −0
Original line number Diff line number Diff line
package foundation.e.apps.data.gitlab.models

data class ProjectIdMapItem(
    val packageName: String,
    val projectId: Int,
)
Loading