Don't use BuildConfig, because it is only available for gradle builds
and not in AOSP builds which will break
This commit is contained in:
parent
30e70527fb
commit
b12adcd4c0
3 changed files with 10 additions and 10 deletions
|
@ -5,7 +5,7 @@ import org.koin.dsl.module
|
||||||
|
|
||||||
val backupModule = module {
|
val backupModule = module {
|
||||||
single { InputFactory() }
|
single { InputFactory() }
|
||||||
single { PackageService(androidContext().packageManager, get()) }
|
single { PackageService(androidContext(), get()) }
|
||||||
single { ApkBackup(androidContext().packageManager, get(), get()) }
|
single { ApkBackup(androidContext().packageManager, get(), get()) }
|
||||||
single { KVBackup(get<BackupPlugin>().kvBackupPlugin, get(), get(), get(), get()) }
|
single { KVBackup(get<BackupPlugin>().kvBackupPlugin, get(), get(), get(), get()) }
|
||||||
single { FullBackup(get<BackupPlugin>().fullBackupPlugin, get(), get(), get()) }
|
single { FullBackup(get<BackupPlugin>().fullBackupPlugin, get(), get(), get()) }
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
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.Context
|
||||||
import android.content.pm.ApplicationInfo.FLAG_ALLOW_BACKUP
|
import android.content.pm.ApplicationInfo.FLAG_ALLOW_BACKUP
|
||||||
import android.content.pm.ApplicationInfo.FLAG_STOPPED
|
import android.content.pm.ApplicationInfo.FLAG_STOPPED
|
||||||
import android.content.pm.ApplicationInfo.FLAG_SYSTEM
|
import android.content.pm.ApplicationInfo.FLAG_SYSTEM
|
||||||
|
@ -14,7 +15,6 @@ 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.stevesoltys.seedvault.BuildConfig.APPLICATION_ID
|
|
||||||
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
|
||||||
|
@ -26,10 +26,11 @@ private const val LOG_MAX_PACKAGES = 100
|
||||||
* @author Torsten Grote
|
* @author Torsten Grote
|
||||||
*/
|
*/
|
||||||
internal class PackageService(
|
internal class PackageService(
|
||||||
private val packageManager: PackageManager,
|
private val context: Context,
|
||||||
private val backupManager: IBackupManager
|
private val backupManager: IBackupManager
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
private val packageManager: PackageManager = context.packageManager
|
||||||
private val myUserId = UserHandle.myUserId()
|
private val myUserId = UserHandle.myUserId()
|
||||||
|
|
||||||
val eligiblePackages: Array<String>
|
val eligiblePackages: Array<String>
|
||||||
|
@ -73,7 +74,7 @@ internal class PackageService(
|
||||||
.filter { packageInfo ->
|
.filter { packageInfo ->
|
||||||
packageInfo.doesNotGetBackedUp() && // only apps that do not allow backup
|
packageInfo.doesNotGetBackedUp() && // only apps that do not allow backup
|
||||||
!packageInfo.isNotUpdatedSystemApp() && // and are not vanilla system apps
|
!packageInfo.isNotUpdatedSystemApp() && // and are not vanilla system apps
|
||||||
packageInfo.packageName != APPLICATION_ID // not this app
|
packageInfo.packageName != context.packageName // not this app
|
||||||
}.sortedBy { packageInfo ->
|
}.sortedBy { packageInfo ->
|
||||||
packageInfo.packageName
|
packageInfo.packageName
|
||||||
}.also { notAllowed ->
|
}.also { notAllowed ->
|
||||||
|
@ -92,7 +93,7 @@ internal class PackageService(
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
get() {
|
get() {
|
||||||
return packageManager.getInstalledPackages(GET_INSTRUMENTATION)
|
return packageManager.getInstalledPackages(GET_INSTRUMENTATION)
|
||||||
.filter { it.isUserVisible() }
|
.filter { it.isUserVisible(context) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val expectedAppTotals: ExpectedAppTotals
|
val expectedAppTotals: ExpectedAppTotals
|
||||||
|
@ -101,7 +102,7 @@ internal class PackageService(
|
||||||
var appsTotal = 0
|
var appsTotal = 0
|
||||||
var appsOptOut = 0
|
var appsOptOut = 0
|
||||||
packageManager.getInstalledPackages(GET_INSTRUMENTATION).forEach { packageInfo ->
|
packageManager.getInstalledPackages(GET_INSTRUMENTATION).forEach { packageInfo ->
|
||||||
if (packageInfo.isUserVisible()) {
|
if (packageInfo.isUserVisible(context)) {
|
||||||
appsTotal++
|
appsTotal++
|
||||||
if (packageInfo.doesNotGetBackedUp()) {
|
if (packageInfo.doesNotGetBackedUp()) {
|
||||||
appsOptOut++
|
appsOptOut++
|
||||||
|
@ -130,9 +131,9 @@ internal data class ExpectedAppTotals(
|
||||||
val appsOptOut: Int
|
val appsOptOut: Int
|
||||||
)
|
)
|
||||||
|
|
||||||
internal fun PackageInfo.isUserVisible(): Boolean {
|
internal fun PackageInfo.isUserVisible(context: Context): Boolean {
|
||||||
if (packageName == MAGIC_PACKAGE_MANAGER || applicationInfo == null) return false
|
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 {
|
internal fun PackageInfo.isSystemApp(): Boolean {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import androidx.core.app.NotificationCompat.Builder
|
||||||
import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT
|
import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT
|
||||||
import androidx.core.app.NotificationCompat.PRIORITY_HIGH
|
import androidx.core.app.NotificationCompat.PRIORITY_HIGH
|
||||||
import androidx.core.app.NotificationCompat.PRIORITY_LOW
|
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.MAGIC_PACKAGE_MANAGER
|
||||||
import com.stevesoltys.seedvault.R
|
import com.stevesoltys.seedvault.R
|
||||||
import com.stevesoltys.seedvault.restore.ACTION_RESTORE_ERROR_UNINSTALL
|
import com.stevesoltys.seedvault.restore.ACTION_RESTORE_ERROR_UNINSTALL
|
||||||
|
@ -207,7 +206,7 @@ internal class BackupNotificationManager(private val context: Context) {
|
||||||
|
|
||||||
fun hasActiveBackupNotifications(): Boolean {
|
fun hasActiveBackupNotifications(): Boolean {
|
||||||
nm.activeNotifications.forEach {
|
nm.activeNotifications.forEach {
|
||||||
if (it.packageName == APPLICATION_ID &&
|
if (it.packageName == context.packageName &&
|
||||||
(it.id == NOTIFICATION_ID_OBSERVER || it.id == NOTIFICATION_ID_BACKGROUND)
|
(it.id == NOTIFICATION_ID_OBSERVER || it.id == NOTIFICATION_ID_BACKGROUND)
|
||||||
) return true
|
) return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue