Simplify PackageService and use standard PackageManager
@stevesoltys this removes your old way of retreiving installed packages via getInstalledPackages(0, UserHandle.USER_SYSTEM) as I couldn't find a difference to the official way. Also IGNORED_PACKAGES isn't needed anymore since filterAppsEligibleForBackupForUser() already filters those out.
This commit is contained in:
parent
fea53a759f
commit
2a4ff39531
1 changed files with 5 additions and 22 deletions
|
@ -1,31 +1,19 @@
|
||||||
package com.stevesoltys.seedvault.transport.backup
|
package com.stevesoltys.seedvault.transport.backup
|
||||||
|
|
||||||
import android.app.backup.IBackupManager
|
import android.app.backup.IBackupManager
|
||||||
import android.content.pm.IPackageManager
|
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES
|
import android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES
|
||||||
import android.os.RemoteException
|
import android.os.RemoteException
|
||||||
import android.os.ServiceManager.getService
|
|
||||||
import android.os.UserHandle
|
import android.os.UserHandle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.util.Log.INFO
|
import android.util.Log.INFO
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import com.google.android.collect.Sets.newArraySet
|
|
||||||
import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER
|
import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER
|
||||||
|
|
||||||
private val TAG = PackageService::class.java.simpleName
|
private val TAG = PackageService::class.java.simpleName
|
||||||
|
|
||||||
private const val LOG_MAX_PACKAGES = 100
|
private const val LOG_MAX_PACKAGES = 100
|
||||||
private val IGNORED_PACKAGES = newArraySet(
|
|
||||||
"com.android.externalstorage",
|
|
||||||
"com.android.providers.downloads.ui",
|
|
||||||
"com.android.providers.downloads",
|
|
||||||
"com.android.providers.media",
|
|
||||||
"com.android.providers.calendar",
|
|
||||||
"com.android.providers.contacts",
|
|
||||||
"com.stevesoltys.seedvault"
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Soltys
|
* @author Steve Soltys
|
||||||
|
@ -35,30 +23,25 @@ internal class PackageService(
|
||||||
private val packageManager: PackageManager,
|
private val packageManager: PackageManager,
|
||||||
private val backupManager: IBackupManager) {
|
private val backupManager: IBackupManager) {
|
||||||
|
|
||||||
// TODO This can probably be removed and PackageManager#getInstalledPackages() used instead
|
|
||||||
private val packageManagerService: IPackageManager = IPackageManager.Stub.asInterface(getService("package"))
|
|
||||||
private val myUserId = UserHandle.myUserId()
|
private val myUserId = UserHandle.myUserId()
|
||||||
|
|
||||||
val eligiblePackages: Array<String>
|
val eligiblePackages: Array<String>
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
@Throws(RemoteException::class)
|
@Throws(RemoteException::class)
|
||||||
get() {
|
get() {
|
||||||
val packages: List<PackageInfo> = packageManagerService.getInstalledPackages(0, UserHandle.USER_SYSTEM).list as List<PackageInfo>
|
val packages = packageManager.getInstalledPackages(0)
|
||||||
val packageList = packages
|
|
||||||
.map { packageInfo -> packageInfo.packageName }
|
.map { packageInfo -> packageInfo.packageName }
|
||||||
.filter { packageName -> !IGNORED_PACKAGES.contains(packageName) }
|
|
||||||
.sorted()
|
.sorted()
|
||||||
|
|
||||||
// log packages
|
// log packages
|
||||||
if (Log.isLoggable(TAG, INFO)) {
|
if (Log.isLoggable(TAG, INFO)) {
|
||||||
Log.i(TAG, "Got ${packageList.size} packages:")
|
Log.i(TAG, "Got ${packages.size} packages:")
|
||||||
packageList.chunked(LOG_MAX_PACKAGES).forEach {
|
packages.chunked(LOG_MAX_PACKAGES).forEach {
|
||||||
Log.i(TAG, it.toString())
|
Log.i(TAG, it.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO why is this filtering out so much?
|
val eligibleApps = backupManager.filterAppsEligibleForBackupForUser(myUserId, packages.toTypedArray())
|
||||||
val eligibleApps = backupManager.filterAppsEligibleForBackupForUser(myUserId, packageList.toTypedArray())
|
|
||||||
|
|
||||||
// log eligible packages
|
// log eligible packages
|
||||||
if (Log.isLoggable(TAG, INFO)) {
|
if (Log.isLoggable(TAG, INFO)) {
|
||||||
|
@ -87,7 +70,7 @@ internal class PackageService(
|
||||||
|
|
||||||
return installed.filter { packageInfo ->
|
return installed.filter { packageInfo ->
|
||||||
packageInfo.packageName !in eligible
|
packageInfo.packageName !in eligible
|
||||||
}
|
}.sortedBy { it.packageName }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue