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

Commit 4309dd3a authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Merge branch '2509-allow_versionName_comparison' into 'main'

feat(updates): add version name comparison for update checks (#2509)

See merge request !480
parents 33f57005 6a789721
Loading
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -114,7 +114,11 @@ class ApplicationDataManager @Inject constructor(
        return if (application.is_pwa) {
            pwaManager.getPwaStatus(application)
        } else {
            appLoungePackageManager.getPackageStatus(application.package_name, application.latest_version_code)
            appLoungePackageManager.getPackageStatus(
                application.package_name,
                application.latest_version_code,
                application.latest_version_number,
            )
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ class SystemAppsUpdatesRepository @Inject constructor(
            Timber.e("Blocked system app: $packageName, details: $systemAppInfo")
            null
        } else {
            systemAppInfo.toApplication()
            systemAppInfo.toApplication(context)
        }
    }

+6 −2
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@

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

import android.content.Context
import android.text.format.Formatter
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.squareup.moshi.Json
import foundation.e.apps.data.application.data.Application
@@ -41,7 +43,8 @@ data class SystemAppInfo(

private const val RANDOM_SIZE = 1L

fun SystemAppInfo.toApplication(): Application {
fun SystemAppInfo.toApplication(context: Context): Application {
    val apkSize = size ?: RANDOM_SIZE
    return Application(
        _id = UUID.randomUUID().toString(),
        author = authorName ?: "eFoundation",
@@ -51,7 +54,8 @@ fun SystemAppInfo.toApplication(): Application {
        name = name,
        package_name = packageName,
        origin = Origin.GITLAB_RELEASES,
        originalSize = size ?: RANDOM_SIZE,
        originalSize = apkSize,
        appSize = Formatter.formatFileSize(context, apkSize),
        url = downloadUrl,
        isSystemApp = true,
        filterLevel = FilterLevel.NONE,
+18 −8
Original line number Diff line number Diff line
@@ -32,17 +32,16 @@ import android.os.Build
import androidx.core.content.pm.PackageInfoCompat
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.OpenForTesting
import foundation.e.apps.data.application.search.SearchApi
import foundation.e.apps.data.enums.Origin
import foundation.e.apps.data.enums.Status
import foundation.e.apps.data.enums.Type
import foundation.e.apps.data.application.search.SearchApi
import foundation.e.apps.data.install.models.AppInstall
import kotlinx.coroutines.DelicateCoroutinesApi
import timber.log.Timber
import java.io.File
import java.lang.IllegalArgumentException
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.DelicateCoroutinesApi
import timber.log.Timber

@Singleton
@OpenForTesting
@@ -72,9 +71,16 @@ class AppLoungePackageManager @Inject constructor(
        }
    }

    private fun isUpdatable(packageName: String, versionCode: Int): Boolean {
    private fun isUpdatable(packageName: String, versionCode: Int, versionName: String): Boolean {
        val packageInfo = getPackageInfo(packageName) ?: return false
        return versionCode.toLong() > PackageInfoCompat.getLongVersionCode(packageInfo)
        val installedVersionNumber = PackageInfoCompat.getLongVersionCode(packageInfo)
        val installedVersionName = packageInfo.versionName

        val isVersionNumberHigher = versionCode.toLong() > installedVersionNumber
        val isVersionNameHigher =
            versionName.isNotBlank() && versionName > installedVersionName

        return isVersionNumberHigher || isVersionNameHigher
    }

    fun getLaunchIntent(packageName: String): Intent? {
@@ -96,9 +102,13 @@ class AppLoungePackageManager @Inject constructor(
     *
     * Recommended to use: [SearchApi.getFusedAppInstallationStatus].
     */
    fun getPackageStatus(packageName: String, versionCode: Int): Status {
    fun getPackageStatus(
        packageName: String,
        versionCode: Int,
        versionName: String = "",
    ): Status {
        return if (isInstalled(packageName)) {
            if (isUpdatable(packageName, versionCode)) {
            if (isUpdatable(packageName, versionCode, versionName)) {
                Status.UPDATABLE
            } else {
                Status.INSTALLED
+18 −9
Original line number Diff line number Diff line
@@ -229,7 +229,8 @@ class AppsApiTest {
        Mockito.`when`(
            appLoungePackageManager.getPackageStatus(
                eq("foundation.e.demoone"),
                eq(123)
                eq(123),
                eq(""),
            )
        )
            .thenReturn(
@@ -238,7 +239,8 @@ class AppsApiTest {
        Mockito.`when`(
            appLoungePackageManager.getPackageStatus(
                eq("foundation.e.demotwo"),
                eq(123)
                eq(123),
                eq(""),
            )
        )
            .thenReturn(
@@ -247,7 +249,8 @@ class AppsApiTest {
        Mockito.`when`(
            appLoungePackageManager.getPackageStatus(
                eq("foundation.e.demothree"),
                eq(123)
                eq(123),
                eq(""),
            )
        )
            .thenReturn(
@@ -287,7 +290,8 @@ class AppsApiTest {
        Mockito.`when`(
            appLoungePackageManager.getPackageStatus(
                eq("foundation.e.demoone"),
                eq(123)
                eq(123),
                eq(""),
            )
        )
            .thenReturn(
@@ -296,7 +300,8 @@ class AppsApiTest {
        Mockito.`when`(
            appLoungePackageManager.getPackageStatus(
                eq("foundation.e.demotwo"),
                eq(123)
                eq(123),
                eq(""),
            )
        )
            .thenReturn(
@@ -305,7 +310,8 @@ class AppsApiTest {
        Mockito.`when`(
            appLoungePackageManager.getPackageStatus(
                eq("foundation.e.demothree"),
                eq(123)
                eq(123),
                eq(""),
            )
        )
            .thenReturn(
@@ -345,7 +351,8 @@ class AppsApiTest {
        Mockito.`when`(
            appLoungePackageManager.getPackageStatus(
                eq("foundation.e.demoone"),
                eq(123)
                eq(123),
                eq(""),
            )
        )
            .thenReturn(
@@ -354,7 +361,8 @@ class AppsApiTest {
        Mockito.`when`(
            appLoungePackageManager.getPackageStatus(
                eq("foundation.e.demotwo"),
                eq(123)
                eq(123),
                eq(""),
            )
        )
            .thenReturn(
@@ -363,7 +371,8 @@ class AppsApiTest {
        Mockito.`when`(
            appLoungePackageManager.getPackageStatus(
                eq("foundation.e.demothree"),
                eq(123)
                eq(123),
                eq(""),
            )
        )
            .thenReturn(
Loading