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

Commit 93582321 authored by Hasib Prince's avatar Hasib Prince
Browse files

improved behavior of update process

parent bfc23f54
Loading
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
/*
 *  Copyright (C) 2022  ECORP
 *
 *   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.api.fused

import foundation.e.apps.api.fused.data.FusedApp

object MemoryDao {
     var appsAwaitingForUpdate: List<FusedApp> = listOf()

     fun hasAnyAppsForUpdate() = appsAwaitingForUpdate.isNotEmpty()
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -231,11 +231,13 @@ class PkgManagerModule @Inject constructor(
    }

    fun getAllUserApps(): List<ApplicationInfo> {
        Timber.d("===> getAllUsersapp START ${System.currentTimeMillis()}")
        val userPackages = mutableListOf<ApplicationInfo>()
        val allPackages = packageManager.getInstalledApplications(0)
        allPackages.forEach {
            if (it.flags and ApplicationInfo.FLAG_SYSTEM == 0) userPackages.add(it)
        }
        Timber.d("===> getAllUsersapp END ${System.currentTimeMillis()}")
        return userPackages
    }

+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ class UpdatesNotifier {
        private const val UPDATES_NOTIFICATION_CHANNEL_TITLE = "App updates"
    }

    private fun getNotification(
    fun getNotification(
        context: Context,
        numberOfApps: Int,
        installAutomatically: Boolean,
+2 −0
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@ class UpdatesManagerImpl @Inject constructor(
        return Pair(nonFaultyUpdateList, status)
    }

    fun getNumberOfAppsNeedUpdate() = pkgManagerModule.getAllUserApps().size

    fun getApplicationCategoryPreference(): String {
        return fusedAPIRepository.getApplicationCategoryPreference()
    }
+8 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
package foundation.e.apps.updates.manager

import com.aurora.gplayapi.data.models.AuthData
import foundation.e.apps.api.fused.MemoryDao
import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.utils.enums.ResultStatus
import javax.inject.Inject
@@ -27,13 +28,19 @@ class UpdatesManagerRepository @Inject constructor(
    private val updatesManagerImpl: UpdatesManagerImpl
) {

    suspend fun getUpdates(authData: AuthData): Pair<List<FusedApp>, ResultStatus> {
    suspend fun getUpdates(authData: AuthData, isFromUpdateProcess: Boolean = false): Pair<List<FusedApp>, ResultStatus> {
        if (isFromUpdateProcess && MemoryDao.hasAnyAppsForUpdate()) {
            return Pair(MemoryDao.appsAwaitingForUpdate, ResultStatus.OK)
        }
        return updatesManagerImpl.getUpdates(authData).run {
            val filteredApps = first.filter { !(!it.isFree && authData.isAnonymous) }
            MemoryDao.appsAwaitingForUpdate = filteredApps
            Pair(filteredApps, this.second)
        }
    }

    fun getNumberOfAppsNeedUpdate() = updatesManagerImpl.getNumberOfAppsNeedUpdate()

    fun getApplicationCategoryPreference(): String {
        return updatesManagerImpl.getApplicationCategoryPreference()
    }
Loading