Loading app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt +44 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ package foundation.e.apps.data.updates import android.content.Context import android.content.pm.ApplicationInfo import android.os.Build import com.aurora.gplayapi.data.models.AuthData import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.data.blockedApps.BlockedAppRepository Loading @@ -35,8 +36,10 @@ import foundation.e.apps.data.application.ApplicationRepository import foundation.e.apps.data.application.search.SearchApi.Companion.APP_TYPE_ANY import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.handleNetworkResult import foundation.e.apps.data.gitlab.SystemAppsUpdatesRepository import foundation.e.apps.data.preference.AppLoungePreference import foundation.e.apps.install.pkg.AppLoungePackageManager import foundation.e.apps.utils.SystemInfoProvider import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll Loading @@ -52,6 +55,7 @@ class UpdatesManagerImpl @Inject constructor( private val faultyAppRepository: FaultyAppRepository, private val appLoungePreference: AppLoungePreference, private val fdroidRepository: FdroidRepository, private val systemAppsUpdatesRepository: SystemAppsUpdatesRepository, private val blockedAppRepository: BlockedAppRepository, ) { Loading Loading @@ -161,6 +165,46 @@ class UpdatesManagerImpl @Inject constructor( return Pair(nonFaultyUpdateList, status) } suspend fun getSystemUpdates(onlySelf: Boolean = false): List<Application> { val updateList = mutableListOf<Application>() val releaseType = getSystemReleaseType() val eligibleApps = systemAppsUpdatesRepository.getAllEligibleApps() eligibleApps?.forEach { val packageName = it.packageName if (onlySelf && packageName != context.packageName) { return@forEach } val releaseTypes = it.releaseTypes if (releaseType in releaseTypes) { systemAppsUpdatesRepository.getSystemAppUpdateInfo( packageName, releaseType, getSdkLevel(), getDevice(), )?.run { updateList.add(this) } } } return updateList } private fun getSdkLevel(): Int { return Build.VERSION.SDK_INT } private fun getDevice(): String { return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_DEVICE) ?: "" } private fun getSystemReleaseType(): String { return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_RELEASE_TYPE) ?: "" } /** * Lists apps directly updatable by App Lounge from the Open Source category. * (This includes apps installed by F-Droid client app, if used by the user; Loading app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerRepository.kt +4 −0 Original line number Diff line number Diff line Loading @@ -46,4 +46,8 @@ class UpdatesManagerRepository @Inject constructor( fun getApplicationCategoryPreference(): List<String> { return updatesManagerImpl.getApplicationCategoryPreference() } suspend fun getSystemUpdates(onlySelf: Boolean = false): List<Application> { return updatesManagerImpl.getSystemUpdates(onlySelf) } } app/src/main/java/foundation/e/apps/install/updates/UpdatesWorkManager.kt +15 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,14 @@ object UpdatesWorkManager { const val TAG = "UpdatesWorkTag" const val USER_TAG = "UpdatesWorkUserTag" fun startAppLoungeUpdateWork(context: Context) { WorkManager.getInstance(context).enqueueUniqueWork( UPDATES_WORK_USER_NAME, ExistingWorkPolicy.APPEND_OR_REPLACE, buildOneTimeWorkRequest(selfUpdate = true) ) } fun startUpdateAllWork(context: Context) { WorkManager.getInstance(context).enqueueUniqueWork( UPDATES_WORK_USER_NAME, Loading @@ -43,12 +51,16 @@ object UpdatesWorkManager { ) } private fun buildOneTimeWorkRequest(): OneTimeWorkRequest { private fun buildOneTimeWorkRequest(selfUpdate: Boolean = false): OneTimeWorkRequest { return OneTimeWorkRequest.Builder(UpdatesWorker::class.java).apply { setConstraints(buildWorkerConstraints()) addTag(USER_TAG) }.setInputData(Data.Builder().putBoolean(UpdatesWorker.IS_AUTO_UPDATE, false).build()) }.setInputData( Data.Builder() .putBoolean(UpdatesWorker.IS_AUTO_UPDATE, false) .putBoolean(UpdatesWorker.IS_SELF_UPDATE, selfUpdate) .build() ).build() } private fun buildWorkerConstraints() = Constraints.Builder().apply { Loading app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt +11 −3 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ class UpdatesWorker @AssistedInject constructor( companion object { const val IS_AUTO_UPDATE = "IS_AUTO_UPDATE" const val IS_SELF_UPDATE = "IS_SELF_UPDATE" private const val MAX_RETRY_COUNT = 10 private const val DELAY_FOR_RETRY = 3000L } Loading @@ -52,11 +53,13 @@ class UpdatesWorker @AssistedInject constructor( private var automaticInstallEnabled = true private var onlyOnUnmeteredNetwork = false private var isAutoUpdate = true // indicates it is auto update or user initiated update private var isSelfUpdate = false private var retryCount = 0 override suspend fun doWork(): Result { return try { isAutoUpdate = params.inputData.getBoolean(IS_AUTO_UPDATE, true) isSelfUpdate = params.inputData.getBoolean(IS_SELF_UPDATE, false) if (isAutoUpdate && checkManualUpdateRunning()) { return Result.success() } Loading Loading @@ -109,7 +112,12 @@ class UpdatesWorker @AssistedInject constructor( val authData = authenticatorRepository.getValidatedAuthData().data val resultStatus: ResultStatus if (user in listOf(User.ANONYMOUS, User.GOOGLE) && authData != null) { if (isSelfUpdate) { val list = updatesManagerRepository.getSystemUpdates(onlySelf = true) appsNeededToUpdate.addAll(list) resultStatus = ResultStatus.OK } else if (user in listOf(User.ANONYMOUS, User.GOOGLE) && authData != null) { /* * Signifies valid Google user and valid auth data to update * apps from Google Play store. Loading @@ -133,7 +141,7 @@ class UpdatesWorker @AssistedInject constructor( return } Timber.i("Updates found: ${appsNeededToUpdate.size}; $resultStatus") if (isAutoUpdate && shouldShowNotification) { if (isSelfUpdate || (isAutoUpdate && shouldShowNotification)) { handleNotification(appsNeededToUpdate.size, isConnectedToUnMeteredNetwork) } Loading @@ -145,7 +153,7 @@ class UpdatesWorker @AssistedInject constructor( * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5376 */ retryCount = 0 if (isAutoUpdate && shouldShowNotification) { if (isSelfUpdate || (isAutoUpdate && shouldShowNotification)) { handleNotification(appsNeededToUpdate.size, isConnectedToUnMeteredNetwork) } Loading Loading
app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt +44 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ package foundation.e.apps.data.updates import android.content.Context import android.content.pm.ApplicationInfo import android.os.Build import com.aurora.gplayapi.data.models.AuthData import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.data.blockedApps.BlockedAppRepository Loading @@ -35,8 +36,10 @@ import foundation.e.apps.data.application.ApplicationRepository import foundation.e.apps.data.application.search.SearchApi.Companion.APP_TYPE_ANY import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.handleNetworkResult import foundation.e.apps.data.gitlab.SystemAppsUpdatesRepository import foundation.e.apps.data.preference.AppLoungePreference import foundation.e.apps.install.pkg.AppLoungePackageManager import foundation.e.apps.utils.SystemInfoProvider import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll Loading @@ -52,6 +55,7 @@ class UpdatesManagerImpl @Inject constructor( private val faultyAppRepository: FaultyAppRepository, private val appLoungePreference: AppLoungePreference, private val fdroidRepository: FdroidRepository, private val systemAppsUpdatesRepository: SystemAppsUpdatesRepository, private val blockedAppRepository: BlockedAppRepository, ) { Loading Loading @@ -161,6 +165,46 @@ class UpdatesManagerImpl @Inject constructor( return Pair(nonFaultyUpdateList, status) } suspend fun getSystemUpdates(onlySelf: Boolean = false): List<Application> { val updateList = mutableListOf<Application>() val releaseType = getSystemReleaseType() val eligibleApps = systemAppsUpdatesRepository.getAllEligibleApps() eligibleApps?.forEach { val packageName = it.packageName if (onlySelf && packageName != context.packageName) { return@forEach } val releaseTypes = it.releaseTypes if (releaseType in releaseTypes) { systemAppsUpdatesRepository.getSystemAppUpdateInfo( packageName, releaseType, getSdkLevel(), getDevice(), )?.run { updateList.add(this) } } } return updateList } private fun getSdkLevel(): Int { return Build.VERSION.SDK_INT } private fun getDevice(): String { return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_DEVICE) ?: "" } private fun getSystemReleaseType(): String { return SystemInfoProvider.getSystemProperty(SystemInfoProvider.KEY_LINEAGE_RELEASE_TYPE) ?: "" } /** * Lists apps directly updatable by App Lounge from the Open Source category. * (This includes apps installed by F-Droid client app, if used by the user; Loading
app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerRepository.kt +4 −0 Original line number Diff line number Diff line Loading @@ -46,4 +46,8 @@ class UpdatesManagerRepository @Inject constructor( fun getApplicationCategoryPreference(): List<String> { return updatesManagerImpl.getApplicationCategoryPreference() } suspend fun getSystemUpdates(onlySelf: Boolean = false): List<Application> { return updatesManagerImpl.getSystemUpdates(onlySelf) } }
app/src/main/java/foundation/e/apps/install/updates/UpdatesWorkManager.kt +15 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,14 @@ object UpdatesWorkManager { const val TAG = "UpdatesWorkTag" const val USER_TAG = "UpdatesWorkUserTag" fun startAppLoungeUpdateWork(context: Context) { WorkManager.getInstance(context).enqueueUniqueWork( UPDATES_WORK_USER_NAME, ExistingWorkPolicy.APPEND_OR_REPLACE, buildOneTimeWorkRequest(selfUpdate = true) ) } fun startUpdateAllWork(context: Context) { WorkManager.getInstance(context).enqueueUniqueWork( UPDATES_WORK_USER_NAME, Loading @@ -43,12 +51,16 @@ object UpdatesWorkManager { ) } private fun buildOneTimeWorkRequest(): OneTimeWorkRequest { private fun buildOneTimeWorkRequest(selfUpdate: Boolean = false): OneTimeWorkRequest { return OneTimeWorkRequest.Builder(UpdatesWorker::class.java).apply { setConstraints(buildWorkerConstraints()) addTag(USER_TAG) }.setInputData(Data.Builder().putBoolean(UpdatesWorker.IS_AUTO_UPDATE, false).build()) }.setInputData( Data.Builder() .putBoolean(UpdatesWorker.IS_AUTO_UPDATE, false) .putBoolean(UpdatesWorker.IS_SELF_UPDATE, selfUpdate) .build() ).build() } private fun buildWorkerConstraints() = Constraints.Builder().apply { Loading
app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt +11 −3 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ class UpdatesWorker @AssistedInject constructor( companion object { const val IS_AUTO_UPDATE = "IS_AUTO_UPDATE" const val IS_SELF_UPDATE = "IS_SELF_UPDATE" private const val MAX_RETRY_COUNT = 10 private const val DELAY_FOR_RETRY = 3000L } Loading @@ -52,11 +53,13 @@ class UpdatesWorker @AssistedInject constructor( private var automaticInstallEnabled = true private var onlyOnUnmeteredNetwork = false private var isAutoUpdate = true // indicates it is auto update or user initiated update private var isSelfUpdate = false private var retryCount = 0 override suspend fun doWork(): Result { return try { isAutoUpdate = params.inputData.getBoolean(IS_AUTO_UPDATE, true) isSelfUpdate = params.inputData.getBoolean(IS_SELF_UPDATE, false) if (isAutoUpdate && checkManualUpdateRunning()) { return Result.success() } Loading Loading @@ -109,7 +112,12 @@ class UpdatesWorker @AssistedInject constructor( val authData = authenticatorRepository.getValidatedAuthData().data val resultStatus: ResultStatus if (user in listOf(User.ANONYMOUS, User.GOOGLE) && authData != null) { if (isSelfUpdate) { val list = updatesManagerRepository.getSystemUpdates(onlySelf = true) appsNeededToUpdate.addAll(list) resultStatus = ResultStatus.OK } else if (user in listOf(User.ANONYMOUS, User.GOOGLE) && authData != null) { /* * Signifies valid Google user and valid auth data to update * apps from Google Play store. Loading @@ -133,7 +141,7 @@ class UpdatesWorker @AssistedInject constructor( return } Timber.i("Updates found: ${appsNeededToUpdate.size}; $resultStatus") if (isAutoUpdate && shouldShowNotification) { if (isSelfUpdate || (isAutoUpdate && shouldShowNotification)) { handleNotification(appsNeededToUpdate.size, isConnectedToUnMeteredNetwork) } Loading @@ -145,7 +153,7 @@ class UpdatesWorker @AssistedInject constructor( * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5376 */ retryCount = 0 if (isAutoUpdate && shouldShowNotification) { if (isSelfUpdate || (isAutoUpdate && shouldShowNotification)) { handleNotification(appsNeededToUpdate.size, isConnectedToUnMeteredNetwork) } Loading