Do not back up APKs of test-only apps, as we can not re-install them anyway
The flag to allow installation gets filtered out after we set it: http://aosp.opersys.com/xref/android-11.0.0_r5/xref/frameworks/base/services/core/java/com/android/server/pm/PackageInstallerService.java#544
This commit is contained in:
parent
0a8a286826
commit
0971c5db19
5 changed files with 25 additions and 8 deletions
|
@ -5,7 +5,6 @@ import android.app.backup.IBackupManager
|
|||
import android.app.backup.IRestoreObserver
|
||||
import android.app.backup.IRestoreSession
|
||||
import android.app.backup.RestoreSet
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.RemoteException
|
||||
import android.os.UserHandle
|
||||
import android.util.Log
|
||||
|
@ -31,6 +30,7 @@ import com.stevesoltys.seedvault.restore.DisplayFragment.RESTORE_BACKUP
|
|||
import com.stevesoltys.seedvault.restore.install.ApkRestore
|
||||
import com.stevesoltys.seedvault.restore.install.InstallIntentCreator
|
||||
import com.stevesoltys.seedvault.restore.install.InstallResult
|
||||
import com.stevesoltys.seedvault.restore.install.isInstalled
|
||||
import com.stevesoltys.seedvault.settings.SettingsManager
|
||||
import com.stevesoltys.seedvault.transport.TRANSPORT_ID
|
||||
import com.stevesoltys.seedvault.transport.restore.RestoreCoordinator
|
||||
|
@ -244,12 +244,7 @@ internal class RestoreViewModel(
|
|||
QUOTA_EXCEEDED -> FAILED_QUOTA_EXCEEDED
|
||||
UNKNOWN_ERROR -> FAILED
|
||||
APK_AND_DATA -> {
|
||||
try {
|
||||
app.packageManager.getPackageInfo(packageName, 0)
|
||||
FAILED
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
FAILED_NOT_INSTALLED
|
||||
}
|
||||
if (app.packageManager.isInstalled(packageName)) FAILED else FAILED_NOT_INSTALLED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,6 @@ internal class ApkInstaller(private val context: Context) {
|
|||
}
|
||||
|
||||
// update status and offer result
|
||||
// TODO maybe don't back up statusMsg=INSTALL_FAILED_TEST_ONLY apps in the first place?
|
||||
val status = if (success) SUCCEEDED else FAILED
|
||||
return installResult.update(packageName) { it.copy(state = status) }
|
||||
}
|
||||
|
|
|
@ -53,6 +53,13 @@ class ApkBackup(
|
|||
// do not back up when setting is not enabled
|
||||
if (!settingsManager.backupApks()) return null
|
||||
|
||||
// do not back up test-only apps as we can't re-install them anyway
|
||||
// see: https://commonsware.com/blog/2017/10/31/android-studio-3p0-flag-test-only.html
|
||||
if (packageInfo.isTestOnly()) {
|
||||
Log.d(TAG, "Package $packageName is test-only app. Not backing it up.")
|
||||
return null
|
||||
}
|
||||
|
||||
// do not back up system apps that haven't been updated
|
||||
if (packageInfo.isNotUpdatedSystemApp()) {
|
||||
Log.d(TAG, "Package $packageName is vanilla system app. Not backing it up.")
|
||||
|
|
|
@ -5,6 +5,7 @@ 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
|
||||
import android.content.pm.ApplicationInfo.FLAG_TEST_ONLY
|
||||
import android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
|
@ -162,3 +163,8 @@ internal fun PackageInfo.isStopped(): Boolean {
|
|||
if (packageName == MAGIC_PACKAGE_MANAGER || applicationInfo == null) return false
|
||||
return applicationInfo.flags and FLAG_STOPPED != 0
|
||||
}
|
||||
|
||||
internal fun PackageInfo.isTestOnly(): Boolean {
|
||||
if (packageName == MAGIC_PACKAGE_MANAGER || applicationInfo == null) return false
|
||||
return applicationInfo.flags and FLAG_TEST_ONLY != 0
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.stevesoltys.seedvault.transport.backup
|
||||
|
||||
import android.content.pm.ApplicationInfo.FLAG_SYSTEM
|
||||
import android.content.pm.ApplicationInfo.FLAG_TEST_ONLY
|
||||
import android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
|
||||
import android.content.pm.InstallSourceInfo
|
||||
import android.content.pm.PackageInfo
|
||||
|
@ -65,6 +66,15 @@ internal class ApkBackupTest : BackupTest() {
|
|||
assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `does not back up test-only apps`() = runBlocking {
|
||||
packageInfo.applicationInfo.flags = FLAG_TEST_ONLY
|
||||
|
||||
every { settingsManager.backupApks() } returns true
|
||||
|
||||
assertNull(apkBackup.backupApkIfNecessary(packageInfo, UNKNOWN_ERROR, streamGetter))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `does not back up system apps`() = runBlocking {
|
||||
packageInfo.applicationInfo.flags = FLAG_SYSTEM
|
||||
|
|
Loading…
Reference in a new issue