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

Commit 7a110152 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Merge branch '2834-main-check_updatable' into 'main'

apps: Add package status check before updating system apps

See merge request !529
parents cc94b8ee 51b62175
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ plugins {
}

def versionMajor = 2
def versionMinor = 11
def versionMinor = 12
def versionPatch = 0

def getGitHash = { ->
+0 −4
Original line number Diff line number Diff line
@@ -111,13 +111,9 @@ class ApplicationDataManager @Inject constructor(
        return if (application.is_pwa) {
            pwaManager.getPwaStatus(application)
        } else {
            val versionName = if (application.isSystemApp) {
                application.latest_version_number
            } else ""
            appLoungePackageManager.getPackageStatus(
                application.package_name,
                application.latest_version_code,
                versionName,
            )
        }
    }
+21 −8
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ 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.enums.Status
import foundation.e.apps.data.gitlab.UpdatableSystemAppsApi.*
import foundation.e.apps.data.gitlab.models.OsReleaseType
import foundation.e.apps.data.gitlab.models.SystemAppInfo
@@ -189,10 +190,17 @@ class SystemAppsUpdatesRepository @Inject constructor(
        return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_DEVICE) ?: ""
    }

    /**
     * Available release types are:
     * - community
     * - official
     * - partner
     * - test
     * - unofficial/UNOFFICIAL
     */
    private fun getSystemReleaseType(): OsReleaseType {
        return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_RELEASE_TYPE).let {
            OsReleaseType.get(it)
        }
        return OsReleaseType.get(SystemInfoProvider.getSystemProperty(
            SystemInfoProvider.KEY_LINEAGE_RELEASE_TYPE) ?: OsReleaseType.TEST.name)
    }

    /**
@@ -235,15 +243,20 @@ class SystemAppsUpdatesRepository @Inject constructor(
                )
            }

            result.data?.run {
            if (!result.isSuccess()) {
                Timber.e("Failed to get system app info for $it - ${result.message}")
                return@forEach
            }

            val app: Application = result.data ?: return@forEach
            val appStatus = appLoungePackageManager.getPackageStatus(it, app.latest_version_code)
            if (appStatus != Status.UPDATABLE) return@forEach

            app.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
+8 −12
Original line number Diff line number Diff line
@@ -41,19 +41,15 @@ data class ReleaseLinks(
)

enum class OsReleaseType {
    TEST,
    COMMUNITY,
    STABLE,
    UNKNOWN,
    ;

    override fun toString(): String {
        return this.name.lowercase()
    }
    COMMUNITY, OFFICIAL, TEST;

    companion object {
        fun get(value: String?): OsReleaseType {
            return OsReleaseType.values().find { it.name == value?.trim()?.uppercase() } ?: UNKNOWN
        fun get(value: String?) = when (value?.trim()?.lowercase()) {
            "dev", "community" -> COMMUNITY
            "official", "stable", "partner" -> OFFICIAL
            else -> TEST
        }
    }

    override fun toString() = name.lowercase()
}
+3 −10
Original line number Diff line number Diff line
@@ -71,16 +71,10 @@ class AppLoungePackageManager @Inject constructor(
        }
    }

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

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

        return isVersionNumberHigher || isVersionNameHigher
        return versionCode.toLong() > installedVersionNumber
    }

    fun getLaunchIntent(packageName: String): Intent? {
@@ -105,10 +99,9 @@ class AppLoungePackageManager @Inject constructor(
    fun getPackageStatus(
        packageName: String,
        versionCode: Int,
        versionName: String = "",
    ): Status {
        return if (isInstalled(packageName)) {
            if (isUpdatable(packageName, versionCode, versionName)) {
            if (isUpdatable(packageName, versionCode)) {
                Status.UPDATABLE
            } else {
                Status.INSTALLED
Loading