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

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

improved update behavior for all-update click

parent 93582321
Loading
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ class PkgManagerModule @Inject constructor(
    companion object {
        const val ERROR_PACKAGE_INSTALL = "ERROR_PACKAGE_INSTALL"
        const val PACKAGE_NAME = "packageName"
        const val FAKE_STORE_PACKAGE_NAME = "com.android.vending"
        private const val TAG = "PkgManagerModule"
    }
    private val packageManager = context.packageManager
@@ -115,12 +116,11 @@ class PkgManagerModule @Inject constructor(
            return
        }
        if (fusedDownload.origin == Origin.GPLAY) {
            val fakeStorePackageName = "com.android.vending"
            if (fusedDownload.type == Type.NATIVE && isInstalled(fakeStorePackageName)) {
            if (fusedDownload.type == Type.NATIVE && isInstalled(FAKE_STORE_PACKAGE_NAME)) {
                val targetPackage = fusedDownload.packageName
                try {
                    packageManager.setInstallerPackageName(targetPackage, fakeStorePackageName)
                    Timber.d("Changed installer to $fakeStorePackageName for $targetPackage")
                    packageManager.setInstallerPackageName(targetPackage, FAKE_STORE_PACKAGE_NAME)
                    Timber.d("Changed installer to $FAKE_STORE_PACKAGE_NAME for $targetPackage")
                } catch (e: Exception) {
                    e.printStackTrace()
                }
@@ -231,16 +231,20 @@ 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
    }

    fun isGplay(packageName: String): Boolean {
        val installerPackageName = packageManager.getInstallerPackageName(packageName)
        Timber.d("===> installer package name for $packageName : $installerPackageName")
        return installerPackageName?.contains(FAKE_STORE_PACKAGE_NAME) == true
    }

    fun getAllSystemApps(): List<ApplicationInfo> {
        return packageManager.getInstalledApplications(PackageManager.MATCH_SYSTEM_ONLY)
    }
+23 −14
Original line number Diff line number Diff line
@@ -48,7 +48,14 @@ class UpdatesNotifier {
            NotificationCompat.Builder(context, UPDATES_NOTIFICATION_CHANNEL_ID)
        notificationBuilder.setSmallIcon(R.drawable.ic_app_updated_on)
        notificationBuilder.priority = NotificationCompat.PRIORITY_DEFAULT
        if (numberOfApps == 1) {

        when (numberOfApps) {
            0 -> {
                notificationBuilder.setContentTitle(
                    "Checking Updates..."
                )
            }
            1 -> {
                notificationBuilder.setContentTitle(
                    context.resources.getQuantityString(
                        R.plurals.updates_notification_title,
@@ -56,7 +63,8 @@ class UpdatesNotifier {
                        numberOfApps
                    )
                )
        } else {
            }
            else -> {
                notificationBuilder.setContentTitle(
                    context.resources.getQuantityString(
                        R.plurals.updates_notification_title,
@@ -65,6 +73,7 @@ class UpdatesNotifier {
                    )
                )
            }
        }
        if (installAutomatically) {
            notificationBuilder.setContentText(context.getString(R.string.automatically_install_updates_notification_text))
            if (unmeteredNetworkOnly && !isConnectedToUnmeteredNetwork) {
+3 −3
Original line number Diff line number Diff line
@@ -47,8 +47,10 @@ class UpdatesManagerImpl @Inject constructor(

        if (pkgList.isNotEmpty()) {
            // Get updates from CleanAPK
            val openSourcePackages = userApplications.filter { !pkgManagerModule.isGplay(it.packageName) }.map { it.packageName }
            pkgList.removeAll(openSourcePackages)
            val cleanAPKResult = fusedAPIRepository.getApplicationDetails(
                pkgList,
                openSourcePackages,
                authData,
                Origin.CLEANAPK
            )
@@ -81,8 +83,6 @@ class UpdatesManagerImpl @Inject constructor(
        return Pair(nonFaultyUpdateList, status)
    }

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

    fun getApplicationCategoryPreference(): String {
        return fusedAPIRepository.getApplicationCategoryPreference()
    }
+0 −2
Original line number Diff line number Diff line
@@ -39,8 +39,6 @@ class UpdatesManagerRepository @Inject constructor(
        }
    }

    fun getNumberOfAppsNeedUpdate() = updatesManagerImpl.getNumberOfAppsNeedUpdate()

    fun getApplicationCategoryPreference(): String {
        return updatesManagerImpl.getApplicationCategoryPreference()
    }
+9 −2
Original line number Diff line number Diff line
@@ -19,7 +19,14 @@ package foundation.e.apps.updates.manager

import android.content.Context
import android.util.Log
import androidx.work.*
import androidx.work.Constraints
import androidx.work.Data
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.ExistingWorkPolicy
import androidx.work.NetworkType
import androidx.work.OneTimeWorkRequest
import androidx.work.PeriodicWorkRequest
import androidx.work.WorkManager
import java.util.concurrent.TimeUnit

object UpdatesWorkManager {
@@ -43,7 +50,7 @@ object UpdatesWorkManager {
        return PeriodicWorkRequest.Builder(
            UpdatesWorker::class.java,
            interval,
            TimeUnit.HOURS
            TimeUnit.MINUTES
        ).apply {
            setConstraints(buildWorkerConstraints())
        }.build()
Loading