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

Commit 6309561c authored by Abhishek Aggarwal's avatar Abhishek Aggarwal Committed by Abhishek Aggarwal
Browse files

Apps: Add support for shared library

parent c46e32ef
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.enums.Type
import foundation.e.apps.data.enums.Type.NATIVE
import foundation.e.apps.data.enums.Type.PWA
import foundation.e.apps.data.install.models.SharedLib
import foundation.e.apps.domain.model.install.Status

data class Application(
@@ -101,6 +102,7 @@ data class Application(
    @SerializedName(value = "antifeatures")
    val antiFeatures: List<Map<String, String>> = emptyList(),
    var isSystemApp: Boolean = false,
    val dependentLibraries: List<SharedLib> = emptyList(),
) {
    val iconUrl: String?
        get() {
+21 −0
Original line number Diff line number Diff line
@@ -93,6 +93,27 @@ class DownloadInfoApiImpl @Inject constructor(
            )
        appInstall.files = downloadList
        list.addAll(downloadList.map { it.url })

        appInstall.sharedLibs.forEach { lib ->
            if (lib.downloadUrls.isEmpty()) {
                val libFiles = runCatching {
                    appSources.gplayRepo.getDownloadInfo(lib.packageName, lib.versionCode, lib.offerType)
                }.getOrElse { e ->
                    throw IllegalStateException(
                        "Cannot install ${appInstall.packageName}: " +
                            "failed to fetch download info for required library ${lib.packageName}",
                        e
                    )
                }
                if (libFiles.isEmpty()) {
                    error(
                        "Cannot install ${appInstall.packageName}: " +
                            "no download URLs returned for required library ${lib.packageName}"
                    )
                }
                lib.downloadUrls = libFiles.map { it.url }
            }
        }
    }

    private suspend fun updateDownloadInfoFromCleanApk(
+5 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.aurora.gplayapi.data.models.Artwork
import com.aurora.gplayapi.data.models.Category
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.application.data.Ratings
import foundation.e.apps.data.install.models.SharedLib
import foundation.e.apps.data.application.data.Category as AppLoungeCategory

fun App.toApplication(context: Context): Application {
@@ -56,7 +57,10 @@ fun App.toApplication(context: Context): Application {
        isFree = this.isFree,
        price = this.price,
        restriction = this.restriction,
        contentRating = this.contentRating
        contentRating = this.contentRating,
        dependentLibraries = this.dependencies.dependentLibraries.map {
            SharedLib(packageName = it.packageName, versionCode = it.versionCode, offerType = it.offerType)
        }
    )
    return app
}
+8 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import com.aurora.gplayapi.data.models.ContentRating
import com.aurora.gplayapi.data.models.PlayFile
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import foundation.e.apps.data.install.models.SharedLib

class AppInstallConverter {

@@ -40,4 +41,11 @@ class AppInstallConverter {
    fun toContentRating(name: String): ContentRating {
        return gson.fromJson(name, ContentRating::class.java)
    }

    @TypeConverter
    fun sharedLibsToJson(value: List<SharedLib>): String = gson.toJson(value)

    @TypeConverter
    fun jsonToSharedLibs(value: String): List<SharedLib> =
        gson.fromJson(value, object : TypeToken<List<SharedLib>>() {}.type) ?: emptyList()
}
+12 −1
Original line number Diff line number Diff line
@@ -5,11 +5,13 @@ import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import foundation.e.apps.data.database.AppDatabase
import foundation.e.apps.data.install.AppInstallDAO
import foundation.e.apps.data.install.models.AppInstall

@Database(entities = [AppInstall::class], version = 6, exportSchema = false)
@Database(entities = [AppInstall::class], version = 7, exportSchema = false)
@TypeConverters(AppInstallConverter::class)
abstract class AppInstallDatabase : RoomDatabase() {
    abstract fun fusedDownloadDao(): AppInstallDAO
@@ -18,11 +20,20 @@ abstract class AppInstallDatabase : RoomDatabase() {
        private lateinit var INSTANCE: AppInstallDatabase
        private const val DATABASE_NAME = "fused_database"

        val migration6To7 = object : Migration(6, 7) {
            override fun migrate(db: SupportSQLiteDatabase) {
                db.execSQL(
                    "ALTER TABLE FusedDownload ADD COLUMN sharedLibs TEXT NOT NULL DEFAULT '[]'"
                )
            }
        }

        fun getInstance(context: Context): AppInstallDatabase {
            if (!Companion::INSTANCE.isInitialized) {
                synchronized(AppDatabase::class) {
                    INSTANCE =
                        Room.databaseBuilder(context, AppInstallDatabase::class.java, DATABASE_NAME)
                            .addMigrations(migration6To7)
                            .fallbackToDestructiveMigration()
                            .build()
                }
Loading