diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/AppListRetriever.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/AppListRetriever.kt index 5da1c7a9..b03a27d0 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/AppListRetriever.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/AppListRetriever.kt @@ -7,7 +7,11 @@ package com.stevesoltys.seedvault.settings import android.annotation.StringRes import android.content.Context +import android.content.Intent +import android.content.Intent.ACTION_MAIN +import android.content.Intent.CATEGORY_LAUNCHER import android.content.pm.PackageManager +import android.content.pm.PackageManager.MATCH_SYSTEM_ONLY import android.graphics.drawable.Drawable import android.util.Log import androidx.annotation.WorkerThread @@ -80,6 +84,10 @@ internal class AppListRetriever( Pair(PACKAGE_NAME_CALL_LOG, R.string.backup_call_log), Pair(PACKAGE_NAME_CONTACTS, R.string.backup_contacts) ) + // filter intent for apps with a launcher activity + val i = Intent(ACTION_MAIN).apply { + addCategory(CATEGORY_LAUNCHER) + } return specialPackages.map { (packageName, stringId) -> val metadata = metadataManager.getPackageMetadata(packageName) val status = if (packageName == PACKAGE_NAME_CONTACTS && metadata?.state == null) { @@ -97,6 +105,18 @@ internal class AppListRetriever( status = status, isSpecial = true ) + } + context.packageManager.queryIntentActivities(i, MATCH_SYSTEM_ONLY).map { + val packageName = it.activityInfo.packageName + val metadata = metadataManager.getPackageMetadata(packageName) + AppStatus( + packageName = packageName, + enabled = settingsManager.isBackupEnabled(packageName), + icon = getIcon(packageName), + name = it.loadLabel(context.packageManager).toString(), + time = metadata?.time ?: 0, + size = metadata?.size, + status = metadata?.state.toAppBackupState(), + ) } } @@ -109,9 +129,6 @@ internal class AppListRetriever( if (status == NOT_YET_BACKED_UP) { Log.w(TAG, "No metadata available for: ${it.packageName}") } - if (metadata?.hasApk() == false) { - Log.w(TAG, "No APK stored for: ${it.packageName}") - } AppStatus( packageName = it.packageName, enabled = settingsManager.isBackupEnabled(it.packageName), diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusFragment.kt index eb4ac7d5..25c5aad1 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusFragment.kt @@ -61,10 +61,10 @@ class AppStatusFragment : Fragment(), AppStatusToggleListener { } progressBar.visibility = VISIBLE - viewModel.appStatusList.observe(viewLifecycleOwner, { result -> + viewModel.appStatusList.observe(viewLifecycleOwner) { result -> adapter.update(result.appStatusList, result.diff) progressBar.visibility = INVISIBLE - }) + } } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { @@ -73,10 +73,10 @@ class AppStatusFragment : Fragment(), AppStatusToggleListener { appEditMenuItem = menu.findItem(R.id.edit_app_blacklist) // observe edit mode changes here where we are sure to have the MenuItem - viewModel.appEditMode.observe(viewLifecycleOwner, { enabled -> + viewModel.appEditMode.observe(viewLifecycleOwner) { enabled -> appEditMenuItem.isChecked = enabled adapter.setEditMode(enabled) - }) + } } override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) { diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsViewModel.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsViewModel.kt index 5be48bfd..a62ff3f4 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsViewModel.kt @@ -97,6 +97,9 @@ internal class SettingsViewModel( private val mAppStatusList = lastBackupTime.switchMap { // updates app list when lastBackupTime changes + // FIXME: Since we are currently updating that time a lot, + // re-fetching everything on each change hammers the system hard + // which can cause android.os.DeadObjectException getAppStatusResult() } internal val appStatusList: LiveData = mAppStatusList