From 3ed551f2602676c8d6716af2fc276dddc41bfad5 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 15 Jul 2024 22:03:41 +0530 Subject: [PATCH 1/7] fix downloading apps from gitlab --- .../apps/data/application/downloadInfo/DownloadInfoApiImpl.kt | 2 +- .../e/apps/install/workmanager/AppInstallProcessor.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/application/downloadInfo/DownloadInfoApiImpl.kt b/app/src/main/java/foundation/e/apps/data/application/downloadInfo/DownloadInfoApiImpl.kt index a0e47ae3f..86b911230 100644 --- a/app/src/main/java/foundation/e/apps/data/application/downloadInfo/DownloadInfoApiImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/application/downloadInfo/DownloadInfoApiImpl.kt @@ -70,7 +70,7 @@ class DownloadInfoApiImpl @Inject constructor( } Origin.GITLAB_RELEASES -> { - // TODO + return // nothing to do as downloadURLList is already set } } diff --git a/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt b/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt index 83d9d7e94..505b95852 100644 --- a/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt +++ b/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt @@ -29,6 +29,7 @@ import foundation.e.apps.data.enums.Type import foundation.e.apps.data.application.ApplicationRepository import foundation.e.apps.data.application.UpdatesDao import foundation.e.apps.data.application.data.Application +import foundation.e.apps.data.enums.Origin import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.playstore.utils.GplayHttpRequestException import foundation.e.apps.data.preference.DataStoreManager @@ -97,7 +98,7 @@ class AppInstallProcessor @Inject constructor( it.contentRating = application.contentRating } - if (appInstall.type == Type.PWA) { + if (appInstall.type == Type.PWA || application.origin == Origin.GITLAB_RELEASES) { appInstall.downloadURLList = mutableListOf(application.url) } -- GitLab From 565cfd73d40279ac0e310faa2ffa0faaf860ba77 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 15 Jul 2024 22:07:27 +0530 Subject: [PATCH 2/7] integrate system apps api into updater --- .../java/foundation/e/apps/MainActivity.kt | 1 + .../e/apps/data/updates/UpdatesManagerImpl.kt | 32 +++++++++++++++++-- .../install/updates/UpdatesWorkManager.kt | 7 ++-- .../e/apps/install/updates/UpdatesWorker.kt | 9 ++++++ .../e/apps/ui/MainActivityViewModel.kt | 8 +++++ 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/MainActivity.kt b/app/src/main/java/foundation/e/apps/MainActivity.kt index f4f0988ec..46e48eafb 100644 --- a/app/src/main/java/foundation/e/apps/MainActivity.kt +++ b/app/src/main/java/foundation/e/apps/MainActivity.kt @@ -125,6 +125,7 @@ class MainActivity : AppCompatActivity() { viewModel.updateAppWarningList() viewModel.updateContentRatings() + viewModel.fetchUpdatableSystemAppsList() observeEvents() diff --git a/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt b/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt index 7cc60ac31..3e075ef2d 100644 --- a/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt @@ -34,6 +34,7 @@ import foundation.e.apps.data.playstore.PlayStoreRepositoryImpl 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.gitlab.SystemAppsUpdatesRepository import foundation.e.apps.data.handleNetworkResult import foundation.e.apps.data.preference.AppLoungePreference import foundation.e.apps.install.pkg.AppLoungePackageManager @@ -53,6 +54,7 @@ class UpdatesManagerImpl @Inject constructor( private val appLoungePreference: AppLoungePreference, private val fdroidRepository: FdroidRepository, private val blockedAppRepository: BlockedAppRepository, + private val systemAppsUpdatesRepository: SystemAppsUpdatesRepository, ) { companion object { @@ -123,8 +125,12 @@ class UpdatesManagerImpl @Inject constructor( status = if (status == ResultStatus.OK) status else gplayStatus } + val systemApps = getSystemUpdates() val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList) - return Pair(nonFaultyUpdateList, status) + + arrangeWithSystemApps(updateList, nonFaultyUpdateList, systemApps) + + return Pair(updateList, status) } suspend fun getUpdatesOSS(): Pair, ResultStatus> { @@ -157,8 +163,30 @@ class UpdatesManagerImpl @Inject constructor( }, updateList) } + val systemApps = getSystemUpdates() val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList) - return Pair(nonFaultyUpdateList, status) + + arrangeWithSystemApps(updateList, nonFaultyUpdateList, systemApps) + + return Pair(updateList, status) + } + + private suspend fun getSystemUpdates(): List { + val systemApps = mutableListOf() + getUpdatesFromApi({ + Pair(systemAppsUpdatesRepository.getSystemUpdates(), ResultStatus.OK) + }, systemApps) + return systemApps + } + + private fun arrangeWithSystemApps( + updateList: MutableList, + nonFaultyApps: List, + systemApps: List, + ) { + updateList.clear() + updateList.addAll(nonFaultyApps) + updateList.addAll(systemApps) } /** diff --git a/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorkManager.kt b/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorkManager.kt index fa41365ed..9cac39769 100644 --- a/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorkManager.kt +++ b/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorkManager.kt @@ -47,8 +47,11 @@ object UpdatesWorkManager { return OneTimeWorkRequest.Builder(UpdatesWorker::class.java).apply { setConstraints(buildWorkerConstraints()) addTag(USER_TAG) - }.setInputData(Data.Builder().putBoolean(UpdatesWorker.IS_AUTO_UPDATE, false).build()) - .build() + }.setInputData( + Data.Builder() + .putBoolean(UpdatesWorker.IS_AUTO_UPDATE, false) + .build() + ).build() } private fun buildWorkerConstraints() = Constraints.Builder().apply { diff --git a/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt b/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt index ee181a81a..91357ce96 100644 --- a/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt +++ b/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt @@ -20,6 +20,7 @@ import foundation.e.apps.data.blockedApps.BlockedAppRepository import foundation.e.apps.data.enums.ResultStatus import foundation.e.apps.data.enums.User import foundation.e.apps.data.application.data.Application +import foundation.e.apps.data.gitlab.SystemAppsUpdatesRepository import foundation.e.apps.data.login.AuthenticatorRepository import foundation.e.apps.data.preference.DataStoreManager import foundation.e.apps.data.updates.UpdatesManagerRepository @@ -40,6 +41,7 @@ class UpdatesWorker @AssistedInject constructor( private val authenticatorRepository: AuthenticatorRepository, private val appInstallProcessor: AppInstallProcessor, private val blockedAppRepository: BlockedAppRepository, + private val systemAppsUpdatesRepository: SystemAppsUpdatesRepository, ) : CoroutineWorker(context, params) { companion object { @@ -62,6 +64,7 @@ class UpdatesWorker @AssistedInject constructor( } refreshBlockedAppList() + refreshEligibleSystemApps() checkForUpdates() Result.success() } catch (e: Throwable) { @@ -80,6 +83,12 @@ class UpdatesWorker @AssistedInject constructor( } } + private suspend fun refreshEligibleSystemApps() { + if (systemAppsUpdatesRepository.getEligibleSystemApps().isEmpty()) { + systemAppsUpdatesRepository.fetchEligibleSystemApps() + } + } + private suspend fun checkManualUpdateRunning(): Boolean { val workInfos = withContext(Dispatchers.IO) { diff --git a/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt index 474308fee..cd54ddf68 100644 --- a/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt @@ -39,6 +39,7 @@ import foundation.e.apps.data.ecloud.EcloudRepository import foundation.e.apps.data.enums.User import foundation.e.apps.data.enums.isInitialized import foundation.e.apps.data.enums.isUnFiltered +import foundation.e.apps.data.gitlab.SystemAppsUpdatesRepository import foundation.e.apps.data.install.AppManagerWrapper import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.parentalcontrol.fdroid.FDroidAntiFeatureRepository @@ -64,6 +65,7 @@ class MainActivityViewModel @Inject constructor( private val gPlayContentRatingRepository: GPlayContentRatingRepository, private val fDroidAntiFeatureRepository: FDroidAntiFeatureRepository, private val appInstallProcessor: AppInstallProcessor, + private val systemAppsUpdatesRepository: SystemAppsUpdatesRepository, ) : ViewModel() { val tocStatus: LiveData = appLoungeDataStore.tocStatus.asLiveData() @@ -247,6 +249,12 @@ class MainActivityViewModel @Inject constructor( } } + fun fetchUpdatableSystemAppsList() { + viewModelScope.launch { + systemAppsUpdatesRepository.fetchUpdatableSystemApps() + } + } + fun getAppNameByPackageName(packageName: String): String { return appLoungePackageManager.getAppNameFromPackageName(packageName) } -- GitLab From a119ebf6ee6764f79bcd9bb3603aff25adf17579 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 15 Jul 2024 22:24:07 +0530 Subject: [PATCH 3/7] fix test --- .../e/apps/UpdateManagerImptTest.kt | 76 ++++++++++++++++--- 1 file changed, 66 insertions(+), 10 deletions(-) diff --git a/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt b/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt index 214e3ee21..a0bfe1456 100644 --- a/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt +++ b/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt @@ -30,6 +30,7 @@ import foundation.e.apps.data.fdroid.FdroidRepository import foundation.e.apps.data.application.ApplicationRepository import foundation.e.apps.data.application.search.SearchApi import foundation.e.apps.data.application.data.Application +import foundation.e.apps.data.gitlab.SystemAppsUpdatesRepository import foundation.e.apps.data.updates.UpdatesManagerImpl import foundation.e.apps.util.MainCoroutineRule import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -78,6 +79,9 @@ class UpdateManagerImptTest { @Mock private lateinit var fdroidRepository: FdroidRepository + @Mock + private lateinit var systemAppsUpdatesRepository: SystemAppsUpdatesRepository + val authData = AuthData("e@e.email", "AtadyMsIAtadyM") @Before @@ -93,27 +97,40 @@ class UpdateManagerImptTest { faultyAppRepository, preferenceModule, fdroidRepository, - blockedAppRepository + blockedAppRepository, + systemAppsUpdatesRepository, ) } + private fun getSystemApps(status: Status = Status.UPDATABLE) = mutableListOf( + Application( + status = status, + name = "Demo Four", + package_name = "foundation.e.demofour", + origin = Origin.GITLAB_RELEASES, + filterLevel = FilterLevel.NONE + ) + ) + @Test fun getUpdateWhenUpdateIsAvailable() = runTest { val gplayApps = getGplayApps() val openSourceApps = getOpenSourceApps(Status.UPDATABLE) + val systemAppUpdates = getSystemApps() val openSourceUpdates = Pair(openSourceApps, ResultStatus.OK) val gplayUpdates = Pair(gplayApps, ResultStatus.OK) setupMockingForFetchingUpdates( openSourceUpdates, - gplayUpdates + gplayUpdates, + systemAppUpdates ) val updateResult = updatesManagerImpl.getUpdates(authData) System.out.println("===> updates: ${updateResult.first.map { it.package_name }}") - assertEquals("fetchUpdate", 2, updateResult.first.size) + assertEquals("fetchUpdate", 3, updateResult.first.size) } private fun getGplayApps(status: Status = Status.UPDATABLE) = mutableListOf( @@ -140,6 +157,8 @@ class UpdateManagerImptTest { val authData = AuthData("e@e.email", "AtadyMsIAtadyM") pkgManagerModule.applicationInfo.clear() + setupMockingSystemApps() + val updateResult = updatesManagerImpl.getUpdates(authData) System.out.println("===> updates: ${updateResult.first.map { it.package_name }}") @@ -150,13 +169,15 @@ class UpdateManagerImptTest { fun getUpdateWhenUpdateIsUnavailable() = runTest { val gplayApps = getGplayApps(Status.INSTALLED) val openSourceApps = getOpenSourceApps(Status.INSTALLED) + val systemAppUpdates = getSystemApps(Status.INSTALLED) val openSourceUpdates = Pair(openSourceApps, ResultStatus.OK) val gplayUpdates = Pair(gplayApps, ResultStatus.OK) setupMockingForFetchingUpdates( openSourceUpdates, - gplayUpdates + gplayUpdates, + systemAppUpdates, ) val updateResult = updatesManagerImpl.getUpdates(authData) @@ -169,36 +190,59 @@ class UpdateManagerImptTest { fun getUpdateWhenUpdateHasOnlyForOpenSourceApps() = runTest { val gplayApps = getGplayApps(Status.INSTALLED) val openSourceApps = getOpenSourceApps(Status.UPDATABLE) + val systemAppUpdates = getSystemApps(Status.INSTALLED) val openSourceUpdates = Pair(openSourceApps, ResultStatus.OK) val gplayUpdates = Pair(gplayApps, ResultStatus.OK) setupMockingForFetchingUpdates( openSourceUpdates, - gplayUpdates + gplayUpdates, + systemAppUpdates, ) val updateResult = updatesManagerImpl.getUpdates(authData) System.out.println("===> updates: ${updateResult.first.map { it.package_name }}") - assertFalse("fetchupdate", updateResult.first.any { it.origin == Origin.GPLAY }) + assertFalse("fetchupdate", updateResult.first.any { it.origin != Origin.CLEANAPK }) } @Test fun getUpdateWhenUpdateHasOnlyForGplayApps() = runTest { val gplayApps = getGplayApps(Status.UPDATABLE) val openSourceApps = getOpenSourceApps(Status.INSTALLED) + val systemAppUpdates = getSystemApps(Status.INSTALLED) val openSourceUpdates = Pair(openSourceApps, ResultStatus.OK) val gplayUpdates = Pair(gplayApps, ResultStatus.OK) setupMockingForFetchingUpdates( openSourceUpdates, - gplayUpdates + gplayUpdates, + systemAppUpdates, + ) + + val updateResult = updatesManagerImpl.getUpdates(authData) + assertFalse("fetchupdate", updateResult.first.any { it.origin != Origin.GPLAY }) + } + + @Test + fun getUpdateWhenUpdateHasOnlySystemApps() = runTest { + val gplayApps = getGplayApps(Status.INSTALLED) + val openSourceApps = getOpenSourceApps(Status.INSTALLED) + val systemAppUpdates = getSystemApps(Status.UPDATABLE) + + val openSourceUpdates = Pair(openSourceApps, ResultStatus.OK) + val gplayUpdates = Pair(gplayApps, ResultStatus.OK) + + setupMockingForFetchingUpdates( + openSourceUpdates, + gplayUpdates, + systemAppUpdates, ) val updateResult = updatesManagerImpl.getUpdates(authData) - assertFalse("fetchupdate", updateResult.first.any { it.origin == Origin.CLEANAPK }) + assertFalse("fetchupdate", updateResult.first.any { it.origin != Origin.GITLAB_RELEASES }) } @Test @@ -274,15 +318,17 @@ class UpdateManagerImptTest { fun getUpdatesOSSWhenUpdateIsAvailable() = runTest { val openSourceApps = getOpenSourceApps(Status.UPDATABLE) val gPlayApps = getGplayApps(Status.UPDATABLE) + val systemAppUpdates = getSystemApps() val openSourceUpdates = Pair(openSourceApps, ResultStatus.OK) val gplayUpdates = Pair(gPlayApps, ResultStatus.OK) - setupMockingForFetchingUpdates(openSourceUpdates, gplayUpdates) + setupMockingForFetchingUpdates(openSourceUpdates, gplayUpdates, systemAppUpdates) val updateResult = updatesManagerImpl.getUpdatesOSS() - assertEquals("UpdateOSS", 1, updateResult.first.size) + assertEquals("UpdateOSS", 2, updateResult.first.size) assertEquals("UpdateOSS", Origin.CLEANAPK, updateResult.first[0].origin) + assertEquals("UpdateOSS", Origin.GITLAB_RELEASES, updateResult.first[1].origin) } @Test @@ -317,6 +363,7 @@ class UpdateManagerImptTest { private suspend fun setupMockingForFetchingUpdates( openSourceUpdates: Pair, ResultStatus>, gplayUpdates: Pair, ResultStatus>, + systemAppUpdates: MutableList = mutableListOf(), selectedApplicationSources: List = mutableListOf( SearchApi.APP_TYPE_ANY, SearchApi.APP_TYPE_OPEN, @@ -334,6 +381,8 @@ class UpdateManagerImptTest { Mockito.`when`(applicationRepository.getSelectedAppTypes()) .thenReturn(selectedApplicationSources) + setupMockingSystemApps(systemAppUpdates) + if (gplayUpdates.first.isNotEmpty()) { Mockito.`when`( applicationRepository.getApplicationDetails( @@ -357,4 +406,11 @@ class UpdateManagerImptTest { ).thenReturn(Pair(Application(), ResultStatus.TIMEOUT)) } } + + private suspend fun setupMockingSystemApps( + systemAppUpdates: MutableList = mutableListOf() + ) { + Mockito.`when`(systemAppsUpdatesRepository.getSystemUpdates()) + .thenReturn(systemAppUpdates) + } } -- GitLab From 6e9d935933026be2044a858e69aa004ad50b8975 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Wed, 17 Jul 2024 16:42:46 +0530 Subject: [PATCH 4/7] rename getSystemUpdates() to getSystemAppUpdates() --- .../foundation/e/apps/data/updates/UpdatesManagerImpl.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt b/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt index 3e075ef2d..24c924f25 100644 --- a/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt @@ -125,7 +125,7 @@ class UpdatesManagerImpl @Inject constructor( status = if (status == ResultStatus.OK) status else gplayStatus } - val systemApps = getSystemUpdates() + val systemApps = getSystemAppUpdates() val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList) arrangeWithSystemApps(updateList, nonFaultyUpdateList, systemApps) @@ -163,7 +163,7 @@ class UpdatesManagerImpl @Inject constructor( }, updateList) } - val systemApps = getSystemUpdates() + val systemApps = getSystemAppUpdates() val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList) arrangeWithSystemApps(updateList, nonFaultyUpdateList, systemApps) @@ -171,7 +171,7 @@ class UpdatesManagerImpl @Inject constructor( return Pair(updateList, status) } - private suspend fun getSystemUpdates(): List { + private suspend fun getSystemAppUpdates(): List { val systemApps = mutableListOf() getUpdatesFromApi({ Pair(systemAppsUpdatesRepository.getSystemUpdates(), ResultStatus.OK) -- GitLab From 3413c393bc5595498dfae5f05fe574c6aecff3f1 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Wed, 17 Jul 2024 16:43:39 +0530 Subject: [PATCH 5/7] update system apps first. rename arrangeWithSystemApps() to addSystemAppsAtFirst() --- .../e/apps/data/updates/UpdatesManagerImpl.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt b/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt index 24c924f25..ddaacfbad 100644 --- a/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/updates/UpdatesManagerImpl.kt @@ -128,7 +128,7 @@ class UpdatesManagerImpl @Inject constructor( val systemApps = getSystemAppUpdates() val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList) - arrangeWithSystemApps(updateList, nonFaultyUpdateList, systemApps) + addSystemAppsAtFirst(updateList, nonFaultyUpdateList, systemApps) return Pair(updateList, status) } @@ -166,7 +166,7 @@ class UpdatesManagerImpl @Inject constructor( val systemApps = getSystemAppUpdates() val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList) - arrangeWithSystemApps(updateList, nonFaultyUpdateList, systemApps) + addSystemAppsAtFirst(updateList, nonFaultyUpdateList, systemApps) return Pair(updateList, status) } @@ -179,14 +179,19 @@ class UpdatesManagerImpl @Inject constructor( return systemApps } - private fun arrangeWithSystemApps( + /** + * This method adds the system app updates at the beginning of the update list. + * It will ensure our system apps are updated first, followed by other apps, + * avoiding potential conflicts. + */ + private fun addSystemAppsAtFirst( updateList: MutableList, nonFaultyApps: List, systemApps: List, ) { updateList.clear() - updateList.addAll(nonFaultyApps) updateList.addAll(systemApps) + updateList.addAll(nonFaultyApps) } /** -- GitLab From 4dd3cbc24839d526620b5d357b3a19b12082254e Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Wed, 17 Jul 2024 17:47:32 +0530 Subject: [PATCH 6/7] fix tests --- app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt b/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt index a0bfe1456..d483c05c5 100644 --- a/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt +++ b/app/src/test/java/foundation/e/apps/UpdateManagerImptTest.kt @@ -327,8 +327,8 @@ class UpdateManagerImptTest { val updateResult = updatesManagerImpl.getUpdatesOSS() assertEquals("UpdateOSS", 2, updateResult.first.size) - assertEquals("UpdateOSS", Origin.CLEANAPK, updateResult.first[0].origin) - assertEquals("UpdateOSS", Origin.GITLAB_RELEASES, updateResult.first[1].origin) + assertEquals("UpdateOSS", Origin.CLEANAPK, updateResult.first[1].origin) + assertEquals("UpdateOSS", Origin.GITLAB_RELEASES, updateResult.first[0].origin) } @Test -- GitLab From ee14c4d310bdece5f5aef27dd15597a8e14f1e4e Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Wed, 17 Jul 2024 17:57:49 +0530 Subject: [PATCH 7/7] single method to get eligible system apps with forceRefresh flag --- .../apps/data/gitlab/SystemAppsUpdatesRepository.kt | 13 ++++++++----- .../e/apps/install/updates/UpdatesWorker.kt | 8 +------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt index 04812c24a..25d9487da 100644 --- a/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/gitlab/SystemAppsUpdatesRepository.kt @@ -43,8 +43,15 @@ class SystemAppsUpdatesRepository @Inject constructor( private var systemAppProjectList = mutableListOf() - suspend fun fetchUpdatableSystemApps() { + private fun getUpdatableSystemApps(): List { + return systemAppProjectList.map { it.packageName } + } + + suspend fun fetchUpdatableSystemApps(forceRefresh: Boolean = false) { val result = handleNetworkResult { + if (getUpdatableSystemApps().isNotEmpty() && !forceRefresh) { + return@handleNetworkResult + } val response = updatableSystemAppsApi.getUpdatableSystemApps() if (response.isSuccessful && !response.body().isNullOrEmpty()) { response.body()?.let { systemAppProjectList.addAll(it) } @@ -58,10 +65,6 @@ class SystemAppsUpdatesRepository @Inject constructor( } } - fun getUpdatableSystemApps(): List { - return systemAppProjectList.map { it.packageName } - } - private fun isSystemAppBlocked( systemAppInfo: SystemAppInfo, sdkLevel: Int, diff --git a/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt b/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt index 91357ce96..65f78637e 100644 --- a/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt +++ b/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt @@ -64,7 +64,7 @@ class UpdatesWorker @AssistedInject constructor( } refreshBlockedAppList() - refreshEligibleSystemApps() + systemAppsUpdatesRepository.fetchUpdatableSystemApps(forceRefresh = true) checkForUpdates() Result.success() } catch (e: Throwable) { @@ -83,12 +83,6 @@ class UpdatesWorker @AssistedInject constructor( } } - private suspend fun refreshEligibleSystemApps() { - if (systemAppsUpdatesRepository.getEligibleSystemApps().isEmpty()) { - systemAppsUpdatesRepository.fetchEligibleSystemApps() - } - } - private suspend fun checkManualUpdateRunning(): Boolean { val workInfos = withContext(Dispatchers.IO) { -- GitLab