From 05428c893d8237dbc62f4350d44a97bdccf6f815 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 15 Jul 2024 21:39:10 +0530 Subject: [PATCH 01/11] API to get GITLAB releases --- .../apps/data/application/data/Application.kt | 2 + .../apps/data/gitlab/EligibleSystemAppsApi.kt | 34 ++++++++++++ .../data/gitlab/SystemAppDefinitionApi.kt | 38 +++++++++++++ .../apps/data/gitlab/models/SystemAppInfo.kt | 55 +++++++++++++++++++ .../data/gitlab/models/SystemAppProject.kt | 23 ++++++++ 5 files changed, 152 insertions(+) create mode 100644 app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt create mode 100644 app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt create mode 100644 app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt create mode 100644 app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppProject.kt diff --git a/app/src/main/java/foundation/e/apps/data/application/data/Application.kt b/app/src/main/java/foundation/e/apps/data/application/data/Application.kt index 0d8bd5184..4a82b2989 100644 --- a/app/src/main/java/foundation/e/apps/data/application/data/Application.kt +++ b/app/src/main/java/foundation/e/apps/data/application/data/Application.kt @@ -105,6 +105,8 @@ data class Application( var contentRating: ContentRating = ContentRating(), @SerializedName(value = "antifeatures") val antiFeatures: List> = emptyList(), + + var isSystemApp: Boolean = false, ) { fun updateType() { this.type = if (this.is_pwa) PWA else NATIVE diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt b/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt new file mode 100644 index 000000000..86d59ca89 --- /dev/null +++ b/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt @@ -0,0 +1,34 @@ +/* + * 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 . + */ + +package foundation.e.apps.data.gitlab + +import foundation.e.apps.data.gitlab.models.SystemAppProject +import retrofit2.Response +import retrofit2.http.GET + +interface EligibleSystemAppsApi { + + companion object { + const val BASE_URL = + "https://gitlab.e.foundation/e/os/system-apps-update-info/-/raw/main/" + } + + @GET("updatable_system_apps.json?inline=false") + suspend fun getAllEligibleApps(): Response> + +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt new file mode 100644 index 000000000..1cfaa4d0e --- /dev/null +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt @@ -0,0 +1,38 @@ +/* + * 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 . + */ + +package foundation.e.apps.data.gitlab + +import foundation.e.apps.data.gitlab.models.SystemAppInfo +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 + +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt new file mode 100644 index 000000000..b7ba3bce2 --- /dev/null +++ b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt @@ -0,0 +1,55 @@ +/* + * 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 . + */ + +package foundation.e.apps.data.gitlab.models + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.squareup.moshi.Json +import foundation.e.apps.data.application.data.Application +import foundation.e.apps.data.enums.FilterLevel +import foundation.e.apps.data.enums.Origin +import java.util.UUID + +@JsonIgnoreProperties(ignoreUnknown = true) +data class SystemAppInfo( + val name: String, + @Json(name = "package_name") val packageName: String, + @Json(name = "version_code") val versionCode: Int, + @Json(name = "min_sdk") val minSdk: Int, + @Json(name = "version_name") val versionName: String, + @Json(name = "url") val downloadUrl: String, + val priority: Boolean?, + @Json(name = "blacklisted_android") val blacklistedAndroid: List?, + @Json(name = "blacklisted_devices") val blacklistedDevices: List?, +) + +fun SystemAppInfo.toApplication(): Application { + return Application( + _id = UUID.randomUUID().toString(), + author = "Murena SAS", + description = "", + latest_version_code = versionCode, + latest_version_number = versionName, + name = name, + package_name = packageName, + origin = Origin.GITLAB_RELEASES, + originalSize = 1, // so that the app is not filtered out, + url = downloadUrl, + isSystemApp = true, + filterLevel = FilterLevel.NONE, + ) +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppProject.kt b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppProject.kt new file mode 100644 index 000000000..b6c0a723d --- /dev/null +++ b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppProject.kt @@ -0,0 +1,23 @@ +/* + * 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 . + */ + +package foundation.e.apps.data.gitlab.models + +data class SystemAppProject( + val packageName: String, + val projectId: Int, +) -- GitLab From eb26be9fddcb0939fb6e28ba9f1c2156437d335a Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 15 Jul 2024 21:40:09 +0530 Subject: [PATCH 02/11] System apps repository --- .../gitlab/SystemAppsUpdatesRepository.kt | 145 ++++++++++++++++++ .../e/apps/di/network/RetrofitApiModule.kt | 30 ++++ .../e/apps/utils/SystemInfoProvider.kt | 2 + 3 files changed, 177 insertions(+) create mode 100644 app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt new file mode 100644 index 000000000..b4ac63964 --- /dev/null +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt @@ -0,0 +1,145 @@ +/* + * 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 . + */ + +package foundation.e.apps.data.gitlab + +import android.content.Context +import android.os.Build +import dagger.hilt.android.qualifiers.ApplicationContext +import foundation.e.apps.data.application.ApplicationDataManager +import foundation.e.apps.data.application.data.Application +import foundation.e.apps.data.gitlab.models.SystemAppInfo +import foundation.e.apps.data.gitlab.models.SystemAppProject +import foundation.e.apps.data.gitlab.models.toApplication +import foundation.e.apps.data.handleNetworkResult +import foundation.e.apps.install.pkg.AppLoungePackageManager +import foundation.e.apps.utils.SystemInfoProvider +import javax.inject.Inject +import javax.inject.Singleton +import timber.log.Timber + +@Singleton +class SystemAppsUpdatesRepository @Inject constructor( + @ApplicationContext private val context: Context, + private val eligibleSystemAppsApi: EligibleSystemAppsApi, + private val systemAppDefinitionApi: SystemAppDefinitionApi, + private val applicationDataManager: ApplicationDataManager, + private val appLoungePackageManager: AppLoungePackageManager, +) { + + private var systemAppProjectList = mutableListOf() + + suspend fun fetchAllEligibleApps() { + handleNetworkResult { + val response = eligibleSystemAppsApi.getAllEligibleApps() + if (response.isSuccessful && !response.body().isNullOrEmpty()) { + response.body()?.let { systemAppProjectList.addAll(it) } + } + } + } + + fun getAllEligibleApps(): List { + return systemAppProjectList.map { it.packageName } + } + + private fun isSystemAppBlacklisted( + systemAppInfo: SystemAppInfo, + sdkLevel: Int, + device: String, + ): Boolean { + return systemAppInfo.run { + sdkLevel < minSdk || + blacklistedAndroid?.contains(sdkLevel) == true || + blacklistedDevices?.contains(device) == true || + blacklistedDevices?.contains("${device}@${sdkLevel}") == true + } + } + + private suspend fun getSystemAppUpdateInfo( + packageName: String, + releaseType: String, + sdkLevel: Int, + device: String, + ): Application? { + + val projectId = + systemAppProjectList.find { it.packageName == packageName }?.projectId ?: return null + + val systemAppInfo = + systemAppDefinitionApi.getSystemAppUpdateInfo(projectId, releaseType).body() + + return if (systemAppInfo == null) { + Timber.e("Null app info for: $packageName") + null + } else if (isSystemAppBlacklisted(systemAppInfo, sdkLevel, device)) { + Timber.e("Blacklisted system app: $packageName, $systemAppInfo") + null + } else { + systemAppInfo.toApplication() + } + } + + 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) ?: "" + } + + suspend fun getSystemUpdates(): List { + val updateList = mutableListOf() + val releaseType = getSystemReleaseType() + val sdkLevel = getSdkLevel() + val device = getDevice() + + val eligibleApps = getAllEligibleApps() + eligibleApps.forEach { + + if (!appLoungePackageManager.isInstalled(it)) { + // Don't install for system apps which are removed (by root or otherwise) + return@forEach + } + + val result = handleNetworkResult { + getSystemAppUpdateInfo( + it, + releaseType, + sdkLevel, + device, + ) + } + + result.data?.run { + applicationDataManager.updateStatus(this) + updateList.add(this) + updateSource(context) + } + + if (!result.isSuccess()) { + Timber.e("Failed to get system app info for $it - ${result.message}") + } + } + + return updateList + } + +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/apps/di/network/RetrofitApiModule.kt b/app/src/main/java/foundation/e/apps/di/network/RetrofitApiModule.kt index 576302cc9..d0e3ff85c 100644 --- a/app/src/main/java/foundation/e/apps/di/network/RetrofitApiModule.kt +++ b/app/src/main/java/foundation/e/apps/di/network/RetrofitApiModule.kt @@ -29,6 +29,8 @@ import foundation.e.apps.data.cleanapk.CleanApkRetrofit import foundation.e.apps.data.ecloud.EcloudApiInterface import foundation.e.apps.data.exodus.ExodusTrackerApi import foundation.e.apps.data.fdroid.FdroidApiInterface +import foundation.e.apps.data.gitlab.EligibleSystemAppsApi +import foundation.e.apps.data.gitlab.SystemAppDefinitionApi import foundation.e.apps.data.parentalcontrol.fdroid.FDroidMonitorApi import foundation.e.apps.data.parentalcontrol.googleplay.AgeGroupApi import foundation.e.apps.di.network.NetworkModule.getYamlFactory @@ -131,4 +133,32 @@ class RetrofitApiModule { .create(FDroidMonitorApi::class.java) } + @Singleton + @Provides + fun provideEligibleSystemAppsApi( + okHttpClient: OkHttpClient, + moshi: Moshi, + ): EligibleSystemAppsApi { + return Retrofit.Builder() + .baseUrl(EligibleSystemAppsApi.BASE_URL) + .client(okHttpClient) + .addConverterFactory(MoshiConverterFactory.create(moshi)) + .build() + .create(EligibleSystemAppsApi::class.java) + } + + @Singleton + @Provides + fun provideSystemAppDefinitionApi( + okHttpClient: OkHttpClient, + moshi: Moshi, + ): SystemAppDefinitionApi { + return Retrofit.Builder() + .baseUrl(SystemAppDefinitionApi.BASE_URL) + .client(okHttpClient) + .addConverterFactory(MoshiConverterFactory.create(moshi)) + .build() + .create(SystemAppDefinitionApi::class.java) + } + } diff --git a/app/src/main/java/foundation/e/apps/utils/SystemInfoProvider.kt b/app/src/main/java/foundation/e/apps/utils/SystemInfoProvider.kt index 68b72945d..bf9fe2efe 100644 --- a/app/src/main/java/foundation/e/apps/utils/SystemInfoProvider.kt +++ b/app/src/main/java/foundation/e/apps/utils/SystemInfoProvider.kt @@ -25,6 +25,8 @@ import org.json.JSONObject object SystemInfoProvider { const val KEY_LINEAGE_VERSION = "ro.lineage.version" + const val KEY_LINEAGE_RELEASE_TYPE = "ro.lineage.releasetype" + const val KEY_LINEAGE_DEVICE = "ro.lineage.device" @SuppressLint("PrivateApi") fun getSystemProperty(key: String?): String? { -- GitLab From 27f90954c888fb2624172878dc905adea4a70ddd Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 15 Jul 2024 21:53:43 +0530 Subject: [PATCH 03/11] add new lines --- .../java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt | 2 +- .../foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt | 2 +- .../e/apps/data/gitlab/SystemAppsUpdatesRepository.kt | 2 +- .../java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt b/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt index 86d59ca89..02ba88ccf 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt @@ -31,4 +31,4 @@ interface EligibleSystemAppsApi { @GET("updatable_system_apps.json?inline=false") suspend fun getAllEligibleApps(): Response> -} \ No newline at end of file +} diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt index 1cfaa4d0e..5ade66876 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt @@ -35,4 +35,4 @@ interface SystemAppDefinitionApi { @Path("releaseType") releaseType: String, ): Response -} \ No newline at end of file +} diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt index b4ac63964..c7399ab48 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt @@ -142,4 +142,4 @@ class SystemAppsUpdatesRepository @Inject constructor( return updateList } -} \ No newline at end of file +} diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt index b7ba3bce2..3251cb4cd 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt @@ -52,4 +52,4 @@ fun SystemAppInfo.toApplication(): Application { isSystemApp = true, filterLevel = FilterLevel.NONE, ) -} \ No newline at end of file +} -- GitLab From 2455c2ff0a424398cee19188e9ab8e2deead2333 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Tue, 16 Jul 2024 16:17:43 +0530 Subject: [PATCH 04/11] better logging --- .../data/gitlab/SystemAppsUpdatesRepository.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt index c7399ab48..47d039c2d 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt @@ -44,12 +44,18 @@ class SystemAppsUpdatesRepository @Inject constructor( private var systemAppProjectList = mutableListOf() suspend fun fetchAllEligibleApps() { - handleNetworkResult { + val result = handleNetworkResult { val response = eligibleSystemAppsApi.getAllEligibleApps() if (response.isSuccessful && !response.body().isNullOrEmpty()) { response.body()?.let { systemAppProjectList.addAll(it) } + } else { + Timber.e("Failed to fetch eligible apps: ${response.errorBody()?.string()}") } } + + if (!result.isSuccess()) { + Timber.e("Network error when fetching eligible apps - ${result.message}") + } } fun getAllEligibleApps(): List { @@ -79,14 +85,14 @@ class SystemAppsUpdatesRepository @Inject constructor( val projectId = systemAppProjectList.find { it.packageName == packageName }?.projectId ?: return null - val systemAppInfo = - systemAppDefinitionApi.getSystemAppUpdateInfo(projectId, releaseType).body() + val response = systemAppDefinitionApi.getSystemAppUpdateInfo(projectId, releaseType) + val systemAppInfo = response.body() return if (systemAppInfo == null) { - Timber.e("Null app info for: $packageName") + Timber.e("Null app info for: $packageName, response: ${response.errorBody()?.string()}") null } else if (isSystemAppBlacklisted(systemAppInfo, sdkLevel, device)) { - Timber.e("Blacklisted system app: $packageName, $systemAppInfo") + Timber.e("Blacklisted system app: $packageName, details: $systemAppInfo") null } else { systemAppInfo.toApplication() -- GitLab From e27d05d9e19f76ab9184baaab95103d99f810bfb Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Tue, 16 Jul 2024 19:05:57 +0530 Subject: [PATCH 05/11] rename methods --- .../e/apps/data/gitlab/EligibleSystemAppsApi.kt | 2 +- .../e/apps/data/gitlab/SystemAppsUpdatesRepository.kt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt b/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt index 02ba88ccf..ba54dabd5 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt @@ -29,6 +29,6 @@ interface EligibleSystemAppsApi { } @GET("updatable_system_apps.json?inline=false") - suspend fun getAllEligibleApps(): Response> + suspend fun getUpdatableSystemApps(): Response> } diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt index 47d039c2d..64ffb0857 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt @@ -43,9 +43,9 @@ class SystemAppsUpdatesRepository @Inject constructor( private var systemAppProjectList = mutableListOf() - suspend fun fetchAllEligibleApps() { + suspend fun fetchEligibleSystemApps() { val result = handleNetworkResult { - val response = eligibleSystemAppsApi.getAllEligibleApps() + val response = eligibleSystemAppsApi.getUpdatableSystemApps() if (response.isSuccessful && !response.body().isNullOrEmpty()) { response.body()?.let { systemAppProjectList.addAll(it) } } else { @@ -58,7 +58,7 @@ class SystemAppsUpdatesRepository @Inject constructor( } } - fun getAllEligibleApps(): List { + fun getEligibleSystemApps(): List { return systemAppProjectList.map { it.packageName } } @@ -117,7 +117,7 @@ class SystemAppsUpdatesRepository @Inject constructor( val sdkLevel = getSdkLevel() val device = getDevice() - val eligibleApps = getAllEligibleApps() + val eligibleApps = getEligibleSystemApps() eligibleApps.forEach { if (!appLoungePackageManager.isInstalled(it)) { -- GitLab From c3e94c1f90ab79cdfbf9d84bb1bcddf50f5c6cb4 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Wed, 17 Jul 2024 16:12:21 +0530 Subject: [PATCH 06/11] allow setting size from gitlab releases. else set a RANDOM_SIZE = 1L --- .../foundation/e/apps/data/gitlab/models/SystemAppInfo.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt index 3251cb4cd..7564236b3 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt @@ -32,11 +32,14 @@ data class SystemAppInfo( @Json(name = "min_sdk") val minSdk: Int, @Json(name = "version_name") val versionName: String, @Json(name = "url") val downloadUrl: String, + @Json(name = "size") val size: Long?, val priority: Boolean?, @Json(name = "blacklisted_android") val blacklistedAndroid: List?, @Json(name = "blacklisted_devices") val blacklistedDevices: List?, ) +private const val RANDOM_SIZE = 1L + fun SystemAppInfo.toApplication(): Application { return Application( _id = UUID.randomUUID().toString(), @@ -47,7 +50,7 @@ fun SystemAppInfo.toApplication(): Application { name = name, package_name = packageName, origin = Origin.GITLAB_RELEASES, - originalSize = 1, // so that the app is not filtered out, + originalSize = size ?: RANDOM_SIZE, url = downloadUrl, isSystemApp = true, filterLevel = FilterLevel.NONE, -- GitLab From 09298e99c9ef2617ac027aa38f1435e78eade820 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Wed, 17 Jul 2024 16:15:49 +0530 Subject: [PATCH 07/11] allow setting author from gitlab releases. change default author name from "Murena SAS" to "eFoundation" --- .../java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt index 7564236b3..0b3c5264c 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt @@ -33,6 +33,7 @@ data class SystemAppInfo( @Json(name = "version_name") val versionName: String, @Json(name = "url") val downloadUrl: String, @Json(name = "size") val size: Long?, + @Json(name = "author_name") val authorName: String?, val priority: Boolean?, @Json(name = "blacklisted_android") val blacklistedAndroid: List?, @Json(name = "blacklisted_devices") val blacklistedDevices: List?, @@ -43,7 +44,7 @@ private const val RANDOM_SIZE = 1L fun SystemAppInfo.toApplication(): Application { return Application( _id = UUID.randomUUID().toString(), - author = "Murena SAS", + author = authorName ?: "eFoundation", description = "", latest_version_code = versionCode, latest_version_number = versionName, -- GitLab From 0ad922634489bafdd08ddd9c945e284cdb0b4cd6 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 18 Jul 2024 06:40:41 +0530 Subject: [PATCH 08/11] fix all copyright --- .../java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt | 2 +- .../foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt | 2 +- .../e/apps/data/gitlab/SystemAppsUpdatesRepository.kt | 2 +- .../java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt | 2 +- .../foundation/e/apps/data/gitlab/models/SystemAppProject.kt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt b/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt index ba54dabd5..7ebe0e102 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 E FOUNDATION + * Copyright (C) 2021-2024 MURENA SAS * * 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 diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt index 5ade66876..b5f7d48b4 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppDefinitionApi.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 E FOUNDATION + * Copyright (C) 2021-2024 MURENA SAS * * 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 diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt index 64ffb0857..20a38e922 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 E FOUNDATION + * Copyright (C) 2021-2024 MURENA SAS * * 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 diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt index 0b3c5264c..d6ee61eb5 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 E FOUNDATION + * Copyright (C) 2021-2024 MURENA SAS * * 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 diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppProject.kt b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppProject.kt index b6c0a723d..edc7f2bff 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppProject.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppProject.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 E FOUNDATION + * Copyright (C) 2021-2024 MURENA SAS * * 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 -- GitLab From ef50a7adf9c0f05358efc7de0a905b1f6eae172e Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 18 Jul 2024 06:45:41 +0530 Subject: [PATCH 09/11] change "blacklisted" to "blocked" --- .../apps/data/gitlab/SystemAppsUpdatesRepository.kt | 12 ++++++------ .../e/apps/data/gitlab/models/SystemAppInfo.kt | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt index 20a38e922..ae3047dda 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt @@ -62,16 +62,16 @@ class SystemAppsUpdatesRepository @Inject constructor( return systemAppProjectList.map { it.packageName } } - private fun isSystemAppBlacklisted( + private fun isSystemAppBlocked( systemAppInfo: SystemAppInfo, sdkLevel: Int, device: String, ): Boolean { return systemAppInfo.run { sdkLevel < minSdk || - blacklistedAndroid?.contains(sdkLevel) == true || - blacklistedDevices?.contains(device) == true || - blacklistedDevices?.contains("${device}@${sdkLevel}") == true + blockedAndroid?.contains(sdkLevel) == true || + blockedDevices?.contains(device) == true || + blockedDevices?.contains("${device}@${sdkLevel}") == true } } @@ -91,8 +91,8 @@ class SystemAppsUpdatesRepository @Inject constructor( return if (systemAppInfo == null) { Timber.e("Null app info for: $packageName, response: ${response.errorBody()?.string()}") null - } else if (isSystemAppBlacklisted(systemAppInfo, sdkLevel, device)) { - Timber.e("Blacklisted system app: $packageName, details: $systemAppInfo") + } else if (isSystemAppBlocked(systemAppInfo, sdkLevel, device)) { + Timber.e("Blocked system app: $packageName, details: $systemAppInfo") null } else { systemAppInfo.toApplication() diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt index d6ee61eb5..5ccb2239a 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/models/SystemAppInfo.kt @@ -35,8 +35,8 @@ data class SystemAppInfo( @Json(name = "size") val size: Long?, @Json(name = "author_name") val authorName: String?, val priority: Boolean?, - @Json(name = "blacklisted_android") val blacklistedAndroid: List?, - @Json(name = "blacklisted_devices") val blacklistedDevices: List?, + @Json(name = "blocked_android") val blockedAndroid: List?, + @Json(name = "blocked_devices") val blockedDevices: List?, ) private const val RANDOM_SIZE = 1L -- GitLab From 8eb91a1dd746ea5061dfd8f890eed1a2b0d8e0ed Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 18 Jul 2024 06:55:10 +0530 Subject: [PATCH 10/11] remove line --- .../java/foundation/e/apps/data/application/data/Application.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/data/application/data/Application.kt b/app/src/main/java/foundation/e/apps/data/application/data/Application.kt index 4a82b2989..fb4646ebe 100644 --- a/app/src/main/java/foundation/e/apps/data/application/data/Application.kt +++ b/app/src/main/java/foundation/e/apps/data/application/data/Application.kt @@ -105,7 +105,6 @@ data class Application( var contentRating: ContentRating = ContentRating(), @SerializedName(value = "antifeatures") val antiFeatures: List> = emptyList(), - var isSystemApp: Boolean = false, ) { fun updateType() { -- GitLab From 0efaa76f601a6e5dc1d82466f3e40c23e00f7b76 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 18 Jul 2024 16:10:54 +0530 Subject: [PATCH 11/11] change "eligible" to "updatable" --- .../data/gitlab/SystemAppsUpdatesRepository.kt | 16 ++++++++-------- ...ystemAppsApi.kt => UpdatableSystemAppsApi.kt} | 2 +- .../e/apps/di/network/RetrofitApiModule.kt | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) rename app/src/main/java/foundation/e/apps/data/gitlab/{EligibleSystemAppsApi.kt => UpdatableSystemAppsApi.kt} (96%) diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt index ae3047dda..04812c24a 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt @@ -35,7 +35,7 @@ import timber.log.Timber @Singleton class SystemAppsUpdatesRepository @Inject constructor( @ApplicationContext private val context: Context, - private val eligibleSystemAppsApi: EligibleSystemAppsApi, + private val updatableSystemAppsApi: UpdatableSystemAppsApi, private val systemAppDefinitionApi: SystemAppDefinitionApi, private val applicationDataManager: ApplicationDataManager, private val appLoungePackageManager: AppLoungePackageManager, @@ -43,22 +43,22 @@ class SystemAppsUpdatesRepository @Inject constructor( private var systemAppProjectList = mutableListOf() - suspend fun fetchEligibleSystemApps() { + suspend fun fetchUpdatableSystemApps() { val result = handleNetworkResult { - val response = eligibleSystemAppsApi.getUpdatableSystemApps() + val response = updatableSystemAppsApi.getUpdatableSystemApps() if (response.isSuccessful && !response.body().isNullOrEmpty()) { response.body()?.let { systemAppProjectList.addAll(it) } } else { - Timber.e("Failed to fetch eligible apps: ${response.errorBody()?.string()}") + Timber.e("Failed to fetch updatable apps: ${response.errorBody()?.string()}") } } if (!result.isSuccess()) { - Timber.e("Network error when fetching eligible apps - ${result.message}") + Timber.e("Network error when fetching updatable apps - ${result.message}") } } - fun getEligibleSystemApps(): List { + fun getUpdatableSystemApps(): List { return systemAppProjectList.map { it.packageName } } @@ -117,8 +117,8 @@ class SystemAppsUpdatesRepository @Inject constructor( val sdkLevel = getSdkLevel() val device = getDevice() - val eligibleApps = getEligibleSystemApps() - eligibleApps.forEach { + val updatableApps = getUpdatableSystemApps() + updatableApps.forEach { if (!appLoungePackageManager.isInstalled(it)) { // Don't install for system apps which are removed (by root or otherwise) diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt b/app/src/main/java/foundation/e/apps/data/gitlab/UpdatableSystemAppsApi.kt similarity index 96% rename from app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt rename to app/src/main/java/foundation/e/apps/data/gitlab/UpdatableSystemAppsApi.kt index 7ebe0e102..2ea9774fa 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/EligibleSystemAppsApi.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/UpdatableSystemAppsApi.kt @@ -21,7 +21,7 @@ import foundation.e.apps.data.gitlab.models.SystemAppProject import retrofit2.Response import retrofit2.http.GET -interface EligibleSystemAppsApi { +interface UpdatableSystemAppsApi { companion object { const val BASE_URL = diff --git a/app/src/main/java/foundation/e/apps/di/network/RetrofitApiModule.kt b/app/src/main/java/foundation/e/apps/di/network/RetrofitApiModule.kt index d0e3ff85c..56914f616 100644 --- a/app/src/main/java/foundation/e/apps/di/network/RetrofitApiModule.kt +++ b/app/src/main/java/foundation/e/apps/di/network/RetrofitApiModule.kt @@ -29,7 +29,7 @@ import foundation.e.apps.data.cleanapk.CleanApkRetrofit import foundation.e.apps.data.ecloud.EcloudApiInterface import foundation.e.apps.data.exodus.ExodusTrackerApi import foundation.e.apps.data.fdroid.FdroidApiInterface -import foundation.e.apps.data.gitlab.EligibleSystemAppsApi +import foundation.e.apps.data.gitlab.UpdatableSystemAppsApi import foundation.e.apps.data.gitlab.SystemAppDefinitionApi import foundation.e.apps.data.parentalcontrol.fdroid.FDroidMonitorApi import foundation.e.apps.data.parentalcontrol.googleplay.AgeGroupApi @@ -135,16 +135,16 @@ class RetrofitApiModule { @Singleton @Provides - fun provideEligibleSystemAppsApi( + fun provideUpdatableSystemAppsApi( okHttpClient: OkHttpClient, moshi: Moshi, - ): EligibleSystemAppsApi { + ): UpdatableSystemAppsApi { return Retrofit.Builder() - .baseUrl(EligibleSystemAppsApi.BASE_URL) + .baseUrl(UpdatableSystemAppsApi.BASE_URL) .client(okHttpClient) .addConverterFactory(MoshiConverterFactory.create(moshi)) .build() - .create(EligibleSystemAppsApi::class.java) + .create(UpdatableSystemAppsApi::class.java) } @Singleton -- GitLab