From 5afcd0d6e60255435ddfbc492a7db9d305cec480 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 4 Sep 2020 16:39:11 -0300 Subject: [PATCH] Don't use BuildConfig, because it is only available for gradle builds and not in AOSP builds which will break --- .../seedvault/transport/backup/BackupModule.kt | 2 +- .../seedvault/transport/backup/PackageService.kt | 15 ++++++++------- .../ui/notification/BackupNotificationManager.kt | 3 +-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt index ce67405c..700379e9 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupModule.kt @@ -5,7 +5,7 @@ import org.koin.dsl.module val backupModule = module { single { InputFactory() } - single { PackageService(androidContext().packageManager, get()) } + single { PackageService(androidContext(), get()) } single { ApkBackup(androidContext().packageManager, get(), get()) } single { KVBackup(get().kvBackupPlugin, get(), get(), get(), get()) } single { FullBackup(get().fullBackupPlugin, get(), get(), get()) } diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/PackageService.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/PackageService.kt index db5eeac1..4b66ebf0 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/PackageService.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/PackageService.kt @@ -1,6 +1,7 @@ package com.stevesoltys.seedvault.transport.backup import android.app.backup.IBackupManager +import android.content.Context import android.content.pm.ApplicationInfo.FLAG_ALLOW_BACKUP import android.content.pm.ApplicationInfo.FLAG_STOPPED import android.content.pm.ApplicationInfo.FLAG_SYSTEM @@ -14,7 +15,6 @@ import android.os.UserHandle import android.util.Log import android.util.Log.INFO import androidx.annotation.WorkerThread -import com.stevesoltys.seedvault.BuildConfig.APPLICATION_ID import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER private val TAG = PackageService::class.java.simpleName @@ -26,10 +26,11 @@ private const val LOG_MAX_PACKAGES = 100 * @author Torsten Grote */ internal class PackageService( - private val packageManager: PackageManager, + private val context: Context, private val backupManager: IBackupManager ) { + private val packageManager: PackageManager = context.packageManager private val myUserId = UserHandle.myUserId() val eligiblePackages: Array @@ -73,7 +74,7 @@ internal class PackageService( .filter { packageInfo -> packageInfo.doesNotGetBackedUp() && // only apps that do not allow backup !packageInfo.isNotUpdatedSystemApp() && // and are not vanilla system apps - packageInfo.packageName != APPLICATION_ID // not this app + packageInfo.packageName != context.packageName // not this app }.sortedBy { packageInfo -> packageInfo.packageName }.also { notAllowed -> @@ -92,7 +93,7 @@ internal class PackageService( @WorkerThread get() { return packageManager.getInstalledPackages(GET_INSTRUMENTATION) - .filter { it.isUserVisible() } + .filter { it.isUserVisible(context) } } val expectedAppTotals: ExpectedAppTotals @@ -101,7 +102,7 @@ internal class PackageService( var appsTotal = 0 var appsOptOut = 0 packageManager.getInstalledPackages(GET_INSTRUMENTATION).forEach { packageInfo -> - if (packageInfo.isUserVisible()) { + if (packageInfo.isUserVisible(context)) { appsTotal++ if (packageInfo.doesNotGetBackedUp()) { appsOptOut++ @@ -130,9 +131,9 @@ internal data class ExpectedAppTotals( val appsOptOut: Int ) -internal fun PackageInfo.isUserVisible(): Boolean { +internal fun PackageInfo.isUserVisible(context: Context): Boolean { if (packageName == MAGIC_PACKAGE_MANAGER || applicationInfo == null) return false - return !isNotUpdatedSystemApp() && instrumentation == null && packageName != APPLICATION_ID + return !isNotUpdatedSystemApp() && instrumentation == null && packageName != context.packageName } internal fun PackageInfo.isSystemApp(): Boolean { diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt index 98e70619..3ba8d563 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/BackupNotificationManager.kt @@ -16,7 +16,6 @@ import androidx.core.app.NotificationCompat.Builder import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT import androidx.core.app.NotificationCompat.PRIORITY_HIGH import androidx.core.app.NotificationCompat.PRIORITY_LOW -import com.stevesoltys.seedvault.BuildConfig.APPLICATION_ID import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.restore.ACTION_RESTORE_ERROR_UNINSTALL @@ -207,7 +206,7 @@ internal class BackupNotificationManager(private val context: Context) { fun hasActiveBackupNotifications(): Boolean { nm.activeNotifications.forEach { - if (it.packageName == APPLICATION_ID && + if (it.packageName == context.packageName && (it.id == NOTIFICATION_ID_OBSERVER || it.id == NOTIFICATION_ID_BACKGROUND) ) return true }