From 2fc70878dbe4744e65662df867545958db189f4e Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Sat, 4 Jun 2022 00:05:56 +0600 Subject: [PATCH 1/5] App Lounge: debug log added for app installation issue --- .../e/apps/manager/fused/FusedManagerImpl.kt | 1 + .../e/apps/manager/pkg/InstallerService.kt | 1 + .../manager/workmanager/InstallAppWorker.kt | 24 ++++++++++++------- .../e/apps/updates/manager/UpdatesWorker.kt | 1 + 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerImpl.kt b/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerImpl.kt index b1a26f2ca..86c0f9978 100644 --- a/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerImpl.kt +++ b/app/src/main/java/foundation/e/apps/manager/fused/FusedManagerImpl.kt @@ -132,6 +132,7 @@ class FusedManagerImpl @Inject constructor( pkgManagerModule.installApplication(list, fusedDownload.packageName) Log.d(TAG, "installApp: ENDED ${fusedDownload.name} ${list.size}") } catch (e: Exception) { + Log.d(TAG, ">>> installApp app failed ") installationIssue(fusedDownload) throw e } diff --git a/app/src/main/java/foundation/e/apps/manager/pkg/InstallerService.kt b/app/src/main/java/foundation/e/apps/manager/pkg/InstallerService.kt index 236dea7d2..80429a509 100644 --- a/app/src/main/java/foundation/e/apps/manager/pkg/InstallerService.kt +++ b/app/src/main/java/foundation/e/apps/manager/pkg/InstallerService.kt @@ -80,6 +80,7 @@ class InstallerService : Service() { GlobalScope.launch { val fusedDownload = fusedManagerRepository.getFusedDownload(packageName = pkgName) fusedManagerRepository.installationIssue(fusedDownload) + Log.d("InstallService", ">>> install failed ") } } } diff --git a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt index 2470d31fe..cec6e9e60 100644 --- a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt +++ b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt @@ -46,6 +46,7 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.takeWhile import kotlinx.coroutines.sync.Mutex +import java.lang.RuntimeException import java.util.concurrent.atomic.AtomicInteger import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds @@ -84,7 +85,7 @@ class InstallAppWorker @AssistedInject constructor( var fusedDownload: FusedDownload? = null try { val fusedDownloadString = params.inputData.getString(INPUT_DATA_FUSED_DOWNLOAD) ?: "" - Log.d(TAG, "Fused download name $fusedDownloadString") + Log.d(TAG, ">>> Fused download name $fusedDownloadString") fusedDownload = databaseRepository.getDownloadById(fusedDownloadString) fusedDownload?.let { if (fusedDownload.status != Status.AWAITING) { @@ -96,15 +97,17 @@ class InstallAppWorker @AssistedInject constructor( ) ) startAppInstallationProcess(it) + Log.d(TAG, ">>> doWork: Locking mutex") mutex.lock() + Log.d(TAG, ">>> doWork: released mutex") } } catch (e: Exception) { - Log.e(TAG, "doWork: Failed: ${e.stackTraceToString()}") + Log.e(TAG, ">>> doWork: Failed: ${e.stackTraceToString()}") fusedDownload?.let { fusedManagerRepository.installationIssue(it) } } finally { - Log.d(TAG, "doWork: RESULT SUCCESS: ${fusedDownload?.name}") + Log.d(TAG, ">>> doWork: RESULT SUCCESS: ${fusedDownload?.name}") return Result.success() } } @@ -113,7 +116,6 @@ class InstallAppWorker @AssistedInject constructor( fusedDownload: FusedDownload ) { fusedManagerRepository.downloadApp(fusedDownload) - Log.d(TAG, "===> doWork: Download started ${fusedDownload.name} ${fusedDownload.status}") if (fusedDownload.type == Type.NATIVE) { isDownloading = true tickerFlow(1.seconds) @@ -122,6 +124,7 @@ class InstallAppWorker @AssistedInject constructor( }.launchIn(CoroutineScope(Dispatchers.IO)) observeDownload(fusedDownload) } + Log.d(TAG, ">>> ===> doWork: Download started ${fusedDownload.name} ${fusedDownload.status}") } private fun tickerFlow(period: Duration, initialDelay: Duration = Duration.ZERO) = flow { @@ -173,7 +176,7 @@ class InstallAppWorker @AssistedInject constructor( try { handleFusedDownloadStatus(fusedDownload) } catch (e: Exception) { - Log.e(TAG, "observeDownload: ", e) + Log.e(TAG, " >>> observeDownload: ", e) isDownloading = false unlockMutex() } @@ -195,18 +198,22 @@ class InstallAppWorker @AssistedInject constructor( } Status.INSTALLED, Status.INSTALLATION_ISSUE -> { isDownloading = false - unlockMutex() Log.d( TAG, - "===> doWork: Installed/Failed: ${fusedDownload.name} ${fusedDownload.status}" + ">>> ===> doWork: Installed/Failed: ${fusedDownload.name} ${fusedDownload.status}" ) + if(fusedDownload.status == Status.INSTALLATION_ISSUE) { + throw RuntimeException("App Installation issue!") + } else { + unlockMutex() + } } else -> { isDownloading = false unlockMutex() Log.wtf( TAG, - "===> ${fusedDownload.name} is in wrong state ${fusedDownload.status}" + ">>> ===> ${fusedDownload.name} is in wrong state ${fusedDownload.status}" ) } } @@ -215,6 +222,7 @@ class InstallAppWorker @AssistedInject constructor( private fun unlockMutex() { if (mutex.isLocked) { mutex.unlock() + Log.d(TAG, ">>> unlockMutex:") } } diff --git a/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt b/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt index bd2dc6fd3..b9f8231cf 100644 --- a/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt +++ b/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt @@ -153,6 +153,7 @@ class UpdatesWorker @AssistedInject constructor( "startUpdateProcess: Enqueued for update: ${fusedDownload.name} ${fusedDownload.id} ${fusedDownload.status}" ) InstallWorkManager.enqueueWork(fusedDownload) + Log.d(TAG, ">>> startUpdateProcess: ${fusedDownload.name}") } } -- GitLab From ab56b07348d8bac77de05b6cbd6860cb5dc8eb7a Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Mon, 6 Jun 2022 08:13:31 +0600 Subject: [PATCH 2/5] App Lounge: App install worker updated --- .../e/apps/MainActivityViewModel.kt | 3 +- .../manager/workmanager/InstallAppWorker.kt | 117 +++++++++--------- .../manager/workmanager/InstallWorkManager.kt | 2 +- .../updates/manager/UpdatesWorkManager.kt | 2 +- 4 files changed, 60 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt index 48ed8ce2f..2d08f99c4 100644 --- a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt @@ -49,7 +49,6 @@ import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.fused.FusedManagerRepository import foundation.e.apps.manager.pkg.PkgManagerModule -import foundation.e.apps.manager.workmanager.InstallWorkManager import foundation.e.apps.settings.SettingsFragment import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status @@ -474,7 +473,7 @@ class MainActivityViewModel @Inject constructor( val fusedDownload = fusedManagerRepository.getFusedDownload(packageName = app.package_name) fusedManagerRepository.cancelDownload(fusedDownload) - InstallWorkManager.cancelWork(app.name) +// InstallWorkManager.cancelWork(app._id) } } diff --git a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt index cec6e9e60..5b1a42f1e 100644 --- a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt +++ b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt @@ -44,9 +44,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.flow.takeWhile import kotlinx.coroutines.sync.Mutex -import java.lang.RuntimeException import java.util.concurrent.atomic.AtomicInteger import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds @@ -85,11 +83,14 @@ class InstallAppWorker @AssistedInject constructor( var fusedDownload: FusedDownload? = null try { val fusedDownloadString = params.inputData.getString(INPUT_DATA_FUSED_DOWNLOAD) ?: "" - Log.d(TAG, ">>> Fused download name $fusedDownloadString") fusedDownload = databaseRepository.getDownloadById(fusedDownloadString) + Log.d( + TAG, + ">>> dowork started for Fused download name ${fusedDownload?.name} $fusedDownloadString" + ) fusedDownload?.let { if (fusedDownload.status != Status.AWAITING) { - return@let + return Result.success() } setForeground( createForegroundInfo( @@ -116,15 +117,36 @@ class InstallAppWorker @AssistedInject constructor( fusedDownload: FusedDownload ) { fusedManagerRepository.downloadApp(fusedDownload) - if (fusedDownload.type == Type.NATIVE) { - isDownloading = true - tickerFlow(1.seconds) - .onEach { - checkDownloadProcess(fusedDownload) - }.launchIn(CoroutineScope(Dispatchers.IO)) - observeDownload(fusedDownload) + isDownloading = true + tickerFlow(3.seconds) + .onEach { + val download = databaseRepository.getDownloadById(fusedDownload.id) + if (download == null) { + isDownloading = false + unlockMutex() + } else { + handleFusedDownloadStatusCheckingException(download) + if (download.type == Type.NATIVE && download.status != Status.INSTALLED && download.status != Status.INSTALLATION_ISSUE) { + checkDownloadProcess(download) + } + } + }.launchIn(CoroutineScope(Dispatchers.IO)) + Log.d( + TAG, + ">>> ===> doWork: Download started ${fusedDownload.name} ${fusedDownload.status}" + ) + } + + private suspend fun handleFusedDownloadStatusCheckingException( + download: FusedDownload + ) { + try { + handleFusedDownloadStatus(download) + } catch (e: Exception) { + Log.e(TAG, " >>> observeDownload: ", e) + isDownloading = false + unlockMutex() } - Log.d(TAG, ">>> ===> doWork: Download started ${fusedDownload.name} ${fusedDownload.status}") } private fun tickerFlow(period: Duration, initialDelay: Duration = Duration.ZERO) = flow { @@ -136,51 +158,30 @@ class InstallAppWorker @AssistedInject constructor( } private suspend fun checkDownloadProcess(fusedDownload: FusedDownload) { - - downloadManager.query(downloadManagerQuery.setFilterById(*fusedDownload.downloadIdMap.keys.toLongArray())) - .use { cursor -> - if (cursor.moveToFirst()) { - val id = - cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID)) - val status = - cursor.getInt(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS)) - val totalSizeBytes = - cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)) - val bytesDownloadedSoFar = - cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) - Log.d( - TAG, - "checkDownloadProcess: ${fusedDownload.name} $bytesDownloadedSoFar/$totalSizeBytes $status" - ) - if (status == DownloadManager.STATUS_FAILED) { - fusedManagerRepository.installationIssue(fusedDownload) + try { + downloadManager.query(downloadManagerQuery.setFilterById(*fusedDownload.downloadIdMap.keys.toLongArray())) + .use { cursor -> + if (cursor.moveToFirst()) { + val id = + cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID)) + val status = + cursor.getInt(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS)) + val totalSizeBytes = + cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)) + val bytesDownloadedSoFar = + cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) + Log.d( + TAG, + "checkDownloadProcess: ${fusedDownload.name} $bytesDownloadedSoFar/$totalSizeBytes $status" + ) + if (status == DownloadManager.STATUS_FAILED) { + fusedManagerRepository.installationIssue(fusedDownload) + } } } - } - } - - private suspend fun observeDownload( - it: FusedDownload, - ) { - databaseRepository.getDownloadFlowById(it.id).takeWhile { isDownloading } - .collect { fusedDownload -> - if (fusedDownload == null) { - isDownloading = false - unlockMutex() - return@collect - } - Log.d( - TAG, - "doWork: flow collect ===> ${fusedDownload.name} ${fusedDownload.status}" - ) - try { - handleFusedDownloadStatus(fusedDownload) - } catch (e: Exception) { - Log.e(TAG, " >>> observeDownload: ", e) - isDownloading = false - unlockMutex() - } - } + } catch (e: Exception) { + e.printStackTrace() + } } private suspend fun handleFusedDownloadStatus(fusedDownload: FusedDownload) { @@ -202,11 +203,7 @@ class InstallAppWorker @AssistedInject constructor( TAG, ">>> ===> doWork: Installed/Failed: ${fusedDownload.name} ${fusedDownload.status}" ) - if(fusedDownload.status == Status.INSTALLATION_ISSUE) { - throw RuntimeException("App Installation issue!") - } else { - unlockMutex() - } + unlockMutex() } else -> { isDownloading = false diff --git a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallWorkManager.kt b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallWorkManager.kt index 809884ed0..08edd715f 100644 --- a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallWorkManager.kt +++ b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallWorkManager.kt @@ -19,7 +19,7 @@ object InstallWorkManager { Data.Builder() .putString(InstallAppWorker.INPUT_DATA_FUSED_DOWNLOAD, fusedDownload.id) .build() - ).addTag(fusedDownload.name) + ).addTag(fusedDownload.id) .build() ) } diff --git a/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorkManager.kt b/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorkManager.kt index 577969c28..c70345a09 100644 --- a/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorkManager.kt +++ b/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorkManager.kt @@ -35,7 +35,7 @@ object UpdatesWorkManager { fun startUpdateAllWork(context: Context) { WorkManager.getInstance(context).enqueueUniqueWork( UPDATES_WORK_NAME, - ExistingWorkPolicy.KEEP, + ExistingWorkPolicy.REPLACE, buildOneTimeWorkRequest() ) } -- GitLab From 454bace86213b9be37d2ece19b9d4047c8d4fcd8 Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Tue, 7 Jun 2022 18:12:05 +0600 Subject: [PATCH 3/5] App Lounge: some code clean up --- .../e/apps/manager/workmanager/InstallAppWorker.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt index 5b1a42f1e..52177ca64 100644 --- a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt +++ b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt @@ -98,9 +98,7 @@ class InstallAppWorker @AssistedInject constructor( ) ) startAppInstallationProcess(it) - Log.d(TAG, ">>> doWork: Locking mutex") mutex.lock() - Log.d(TAG, ">>> doWork: released mutex") } } catch (e: Exception) { Log.e(TAG, ">>> doWork: Failed: ${e.stackTraceToString()}") @@ -126,7 +124,7 @@ class InstallAppWorker @AssistedInject constructor( unlockMutex() } else { handleFusedDownloadStatusCheckingException(download) - if (download.type == Type.NATIVE && download.status != Status.INSTALLED && download.status != Status.INSTALLATION_ISSUE) { + if (isAppDownloading(download)) { checkDownloadProcess(download) } } @@ -137,6 +135,10 @@ class InstallAppWorker @AssistedInject constructor( ) } + private fun isAppDownloading(download: FusedDownload): Boolean { + return download.type == Type.NATIVE && download.status != Status.INSTALLED && download.status != Status.INSTALLATION_ISSUE + } + private suspend fun handleFusedDownloadStatusCheckingException( download: FusedDownload ) { @@ -219,7 +221,6 @@ class InstallAppWorker @AssistedInject constructor( private fun unlockMutex() { if (mutex.isLocked) { mutex.unlock() - Log.d(TAG, ">>> unlockMutex:") } } -- GitLab From fdf465c6288d038bb95a298a52c167f4e1a4490d Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Tue, 7 Jun 2022 22:19:53 +0600 Subject: [PATCH 4/5] App Lounge: disable update all button when update running --- .../e/apps/updates/UpdatesFragment.kt | 14 ++++++++ .../e/apps/updates/UpdatesViewModel.kt | 32 ++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt index eb03b02d9..6aa489a8d 100644 --- a/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/updates/UpdatesFragment.kt @@ -19,6 +19,7 @@ package foundation.e.apps.updates import android.os.Bundle +import android.util.Log import android.view.View import android.widget.ImageView import androidx.fragment.app.Fragment @@ -28,6 +29,7 @@ import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import androidx.work.WorkManager import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.AppInfoFetchViewModel import foundation.e.apps.AppProgressViewModel @@ -41,6 +43,7 @@ import foundation.e.apps.applicationlist.model.ApplicationListRVAdapter import foundation.e.apps.databinding.FragmentUpdatesBinding import foundation.e.apps.manager.download.data.DownloadProgress import foundation.e.apps.manager.pkg.PkgManagerModule +import foundation.e.apps.manager.workmanager.InstallWorkManager.INSTALL_WORK_NAME import foundation.e.apps.updates.manager.UpdatesWorkManager import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.User @@ -80,6 +83,7 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { updatesViewModel.getUpdates(data) binding.button.setOnClickListener { UpdatesWorkManager.startUpdateAllWork(requireContext().applicationContext) + binding.button.isEnabled = false } } } @@ -140,7 +144,17 @@ class UpdatesFragment : Fragment(R.layout.fragment_updates), FusedAPIInterface { binding.noUpdates.visibility = View.VISIBLE binding.button.isEnabled = false } + + WorkManager.getInstance(requireContext()) + .getWorkInfosForUniqueWorkLiveData(INSTALL_WORK_NAME).observe(viewLifecycleOwner) { + lifecycleScope.launchWhenResumed { + binding.button.isEnabled = + !updatesViewModel.checkWorkInfoListHasAnyUpdatableWork(it) + } + } } + + } private fun observeDownloadList() { diff --git a/app/src/main/java/foundation/e/apps/updates/UpdatesViewModel.kt b/app/src/main/java/foundation/e/apps/updates/UpdatesViewModel.kt index a440d34ab..4e69f4d49 100644 --- a/app/src/main/java/foundation/e/apps/updates/UpdatesViewModel.kt +++ b/app/src/main/java/foundation/e/apps/updates/UpdatesViewModel.kt @@ -18,19 +18,24 @@ package foundation.e.apps.updates +import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import androidx.work.WorkInfo import com.aurora.gplayapi.data.models.AuthData import dagger.hilt.android.lifecycle.HiltViewModel +import foundation.e.apps.api.fused.FusedAPIRepository import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.updates.manager.UpdatesManagerRepository +import foundation.e.apps.utils.enums.Status import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class UpdatesViewModel @Inject constructor( - private val updatesManagerRepository: UpdatesManagerRepository + private val updatesManagerRepository: UpdatesManagerRepository, + private val fusedAPIRepository: FusedAPIRepository ) : ViewModel() { val updatesList: MutableLiveData> = MutableLiveData() @@ -43,4 +48,29 @@ class UpdatesViewModel @Inject constructor( ) } } + + suspend fun checkWorkInfoListHasAnyUpdatableWork(workInfoList: List): Boolean { + workInfoList.forEach { workInfo -> + if (listOf( + WorkInfo.State.ENQUEUED, + WorkInfo.State.RUNNING + ).contains(workInfo.state) && checkWorkIsForUpdateByTag(workInfo.tags.toList()) + ) { + return true + } + } + return false + } + + private fun checkWorkIsForUpdateByTag(tags: List): Boolean { + updatesList.value?.let { + it.find { fusedApp -> tags.contains(fusedApp._id) }?.let { foundApp -> + return listOf( + Status.INSTALLED, + Status.UPDATABLE + ).contains(fusedAPIRepository.getFusedAppInstallationStatus(foundApp)) + } + } + return false + } } -- GitLab From 62309d7de5e41d744d162b579b8f337822d1dbbb Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Wed, 8 Jun 2022 12:11:55 +0600 Subject: [PATCH 5/5] App Lounge: some code refactoring cleanup logs, removed unused methods --- .../e/apps/MainActivityViewModel.kt | 1 - .../e/apps/manager/pkg/InstallerService.kt | 20 ++++++------------- .../manager/workmanager/InstallAppWorker.kt | 6 +++--- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt index 16aad942b..eae9516d7 100644 --- a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt @@ -382,7 +382,6 @@ class MainActivityViewModel @Inject constructor( val fusedDownload = fusedManagerRepository.getFusedDownload(packageName = app.package_name) fusedManagerRepository.cancelDownload(fusedDownload) -// InstallWorkManager.cancelWork(app._id) } } diff --git a/app/src/main/java/foundation/e/apps/manager/pkg/InstallerService.kt b/app/src/main/java/foundation/e/apps/manager/pkg/InstallerService.kt index 80429a509..1ec727682 100644 --- a/app/src/main/java/foundation/e/apps/manager/pkg/InstallerService.kt +++ b/app/src/main/java/foundation/e/apps/manager/pkg/InstallerService.kt @@ -41,6 +41,10 @@ class InstallerService : Service() { @Inject lateinit var pkgManagerModule: PkgManagerModule + companion object { + const val TAG = "InstallerService" + } + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -69) @@ -52,7 +56,7 @@ class InstallerService : Service() { } private fun postStatus(status: Int, packageName: String?, extra: String?) { - Log.d("InstallerService", "postStatus: $status $packageName $extra") + Log.d(TAG, "postStatus: $status $packageName $extra") if (status != PackageInstaller.STATUS_SUCCESS) { updateInstallationIssue(packageName ?: "") } @@ -62,25 +66,13 @@ class InstallerService : Service() { return null } - private fun updateDownloadStatus(pkgName: String) { - if (pkgName.isEmpty()) { - Log.d("PkgManagerBR", "updateDownloadStatus: package name should not be empty!") - } - GlobalScope.launch { - val fusedDownload = fusedManagerRepository.getFusedDownload(packageName = pkgName) - pkgManagerModule.setFakeStoreAsInstallerIfNeeded(fusedDownload) - fusedManagerRepository.updateDownloadStatus(fusedDownload, Status.INSTALLED) - } - } - private fun updateInstallationIssue(pkgName: String) { if (pkgName.isEmpty()) { - Log.d("PkgManagerBR", "updateDownloadStatus: package name should not be empty!") + Log.d(TAG, "updateDownloadStatus: package name should not be empty!") } GlobalScope.launch { val fusedDownload = fusedManagerRepository.getFusedDownload(packageName = pkgName) fusedManagerRepository.installationIssue(fusedDownload) - Log.d("InstallService", ">>> install failed ") } } } diff --git a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt index 52177ca64..39ee678c9 100644 --- a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt +++ b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallAppWorker.kt @@ -145,7 +145,7 @@ class InstallAppWorker @AssistedInject constructor( try { handleFusedDownloadStatus(download) } catch (e: Exception) { - Log.e(TAG, " >>> observeDownload: ", e) + Log.e(TAG, "observeDownload: ", e) isDownloading = false unlockMutex() } @@ -203,7 +203,7 @@ class InstallAppWorker @AssistedInject constructor( isDownloading = false Log.d( TAG, - ">>> ===> doWork: Installed/Failed: ${fusedDownload.name} ${fusedDownload.status}" + "===> doWork: Installed/Failed: ${fusedDownload.name} ${fusedDownload.status}" ) unlockMutex() } @@ -212,7 +212,7 @@ class InstallAppWorker @AssistedInject constructor( unlockMutex() Log.wtf( TAG, - ">>> ===> ${fusedDownload.name} is in wrong state ${fusedDownload.status}" + "===> ${fusedDownload.name} is in wrong state ${fusedDownload.status}" ) } } -- GitLab