Skip to content

Commit c97b286

Browse files
committed
WIP: Try to also back up uninstalled apps
e.g. archived or hidden apps
1 parent 824ce97 commit c97b286

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

app/src/main/java/com/stevesoltys/seedvault/transport/backup/PackageService.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import android.content.pm.PackageManager
1818
import android.content.pm.PackageManager.GET_INSTRUMENTATION
1919
import android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES
2020
import android.content.pm.PackageManager.MATCH_SYSTEM_ONLY
21+
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
2122
import android.content.pm.ResolveInfo
2223
import android.os.RemoteException
2324
import android.util.Log
@@ -49,7 +50,7 @@ internal class PackageService(
4950
@WorkerThread
5051
@Throws(RemoteException::class)
5152
get() {
52-
val packages = packageManager.getInstalledPackages(0)
53+
val packages = packageManager.getInstalledPackages(MATCH_UNINSTALLED_PACKAGES)
5354
.map { packageInfo -> packageInfo.packageName }
5455
.sorted()
5556

@@ -81,7 +82,8 @@ internal class PackageService(
8182
get() {
8283
// We need the GET_SIGNING_CERTIFICATES flag here,
8384
// because the package info is used by [ApkBackup] which needs signing info.
84-
return packageManager.getInstalledPackages(GET_SIGNING_CERTIFICATES)
85+
val flags = GET_SIGNING_CERTIFICATES or MATCH_UNINSTALLED_PACKAGES
86+
return packageManager.getInstalledPackages(flags)
8587
.filter { packageInfo -> // only apps that are:
8688
!packageInfo.isNotUpdatedSystemApp() && // not vanilla system apps
8789
packageInfo.packageName != context.packageName // not this app
@@ -97,7 +99,8 @@ internal class PackageService(
9799
get() {
98100
// We need the GET_SIGNING_CERTIFICATES flag here,
99101
// because the package info is used by [ApkBackup] which needs signing info.
100-
return packageManager.getInstalledPackages(GET_SIGNING_CERTIFICATES)
102+
val flags = GET_SIGNING_CERTIFICATES or MATCH_UNINSTALLED_PACKAGES
103+
return packageManager.getInstalledPackages(flags)
101104
.filter { packageInfo ->
102105
packageInfo.doesNotGetBackedUp() && // only apps that do not allow backup
103106
!packageInfo.isNotUpdatedSystemApp() && // and are not vanilla system apps

0 commit comments

Comments
 (0)