Show other (launchable) system apps in backup status
This commit is contained in:
parent
16813395c7
commit
4803288629
3 changed files with 27 additions and 7 deletions
|
@ -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),
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<AppStatusResult> = mAppStatusList
|
||||
|
|
Loading…
Reference in a new issue