Remove D2D setting, it is now always on

This commit is contained in:
Torsten Grote 2024-09-17 17:24:41 -03:00
parent fe8d458890
commit 9de1d2472b
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
21 changed files with 24 additions and 144 deletions

View file

@ -10,10 +10,8 @@ echo "Installing Seedvault app..."
./gradlew --stacktrace :app:installDebugAndroidTest
sleep 60
D2D_BACKUP_TEST=$1
large_test_exit_code=0
./gradlew --stacktrace -Pinstrumented_test_size=large -Pd2d_backup_test="$D2D_BACKUP_TEST" :app:connectedAndroidTest || large_test_exit_code=$?
./gradlew --stacktrace -Pinstrumented_test_size=large :app:connectedAndroidTest || large_test_exit_code=$?
adb pull /sdcard/seedvault_test_results

View file

@ -20,7 +20,6 @@ jobs:
matrix:
android_target: [ 34 ]
emulator_type: [ aosp_atd ]
d2d_backup_test: [ true, false ]
steps:
- name: Checkout Code
uses: actions/checkout@v3
@ -53,7 +52,7 @@ jobs:
disable-animations: true
script: |
./app/development/scripts/provision_emulator.sh "test" "system-images;android-${{ matrix.android_target }};${{ matrix.emulator_type }};x86_64"
./.github/scripts/run_tests.sh ${{ matrix.d2d_backup_test }}
./.github/scripts/run_tests.sh
- name: Upload test results
if: always()

View file

@ -39,9 +39,6 @@ android {
testInstrumentationRunnerArguments["size"] = testSize
}
val d2dBackupTest = project.findProperty("d2d_backup_test")?.toString() ?: "true"
testInstrumentationRunnerArguments["d2d_backup_test"] = d2dBackupTest
}
signingConfigs {

View file

@ -32,7 +32,7 @@ class KoinInstrumentationTestApp : App() {
val testModule = module {
val context = this@KoinInstrumentationTestApp
single { spyk(PackageService(context, get(), get(), get())) }
single { spyk(PackageService(context, get(), get())) }
single { spyk(SettingsManager(context)) }
single { spyk(BackupNotificationManager(context)) }

View file

@ -74,7 +74,6 @@ internal interface LargeBackupTestBase : LargeTestBase {
full = mutableMapOf(),
kv = mutableMapOf(),
userApps = packageService.userApps,
userNotAllowedApps = packageService.userNotAllowedApps
)
val completed = spyOnBackup(backupResult)

View file

@ -63,7 +63,6 @@ internal interface LargeRestoreTestBase : LargeTestBase {
full = mutableMapOf(),
kv = mutableMapOf(),
userApps = emptyList(), // will update everything below this after restore
userNotAllowedApps = emptyList()
)
spyOnRestoreData(result)
@ -97,7 +96,6 @@ internal interface LargeRestoreTestBase : LargeTestBase {
return result.copy(
userApps = packageService.userApps,
userNotAllowedApps = packageService.userNotAllowedApps
)
}

View file

@ -112,11 +112,9 @@ internal interface LargeTestBase : KoinComponent {
}
fun testResultFilename(testName: String): String {
val arguments = InstrumentationRegistry.getArguments()
val d2d = if (arguments.getString("d2d_backup_test") == "true") "d2d" else ""
val simpleDateFormat = SimpleDateFormat("yyyyMMdd_hhmmss")
val timeStamp = simpleDateFormat.format(Calendar.getInstance().time)
return "${timeStamp}_${d2d}_${testName.replace(" ", "_")}"
return "${timeStamp}_${testName.replace(" ", "_")}"
}
@OptIn(DelicateCoroutinesApi::class)

View file

@ -7,7 +7,6 @@ package com.stevesoltys.seedvault.e2e
import android.content.pm.PackageManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
@ -52,17 +51,6 @@ internal abstract class SeedvaultLargeTest :
startRecordingTest(keepRecordingScreen, name.methodName)
restoreBaselineBackup()
val arguments = InstrumentationRegistry.getArguments()
if (arguments.getString("d2d_backup_test") == "true") {
println("Enabling D2D backups for test")
settingsManager.setD2dBackupsEnabled(true)
} else {
println("Disabling D2D backups for test")
settingsManager.setD2dBackupsEnabled(false)
}
}
@After

View file

@ -24,7 +24,6 @@ internal data class SeedvaultLargeTestResult(
val full: MutableMap<String, String>,
val kv: MutableMap<String, MutableMap<String, String>>,
val userApps: List<PackageInfo>,
val userNotAllowedApps: List<PackageInfo>,
) {
fun allUserApps() = userApps + userNotAllowedApps
fun allUserApps() = userApps
}

View file

@ -131,7 +131,7 @@ internal class SnapshotCreator(
androidId = Settings.Secure.getString(context.contentResolver, ANDROID_ID) ?: ""
sdkInt = Build.VERSION.SDK_INT
androidIncremental = Build.VERSION.INCREMENTAL
d2D = settingsManager.d2dBackupsEnabled()
d2D = true
putAllApps(appBuilderMap.mapValues { it.value.build() })
putAllBlobs(this@SnapshotCreator.blobsMap)
}.build()

View file

@ -62,7 +62,6 @@ internal class AppListRetriever(
val appListSections = linkedMapOf(
AppSectionTitle(R.string.backup_section_system) to getSpecialApps(),
AppSectionTitle(R.string.backup_section_user) to getApps(),
AppSectionTitle(R.string.backup_section_not_allowed) to getNotAllowedApps()
).filter { it.value.isNotEmpty() }
return appListSections.flatMap { (sectionTitle, appList) ->
@ -129,21 +128,6 @@ internal class AppListRetriever(
}).sortedBy { it.name.lowercase(locale) }
}
private fun getNotAllowedApps(): List<AppStatus> {
val locale = Locale.getDefault()
return packageService.userNotAllowedApps.map {
AppStatus(
packageName = it.packageName,
enabled = settingsManager.isBackupEnabled(it.packageName),
icon = getIconFromPackageManager(it.packageName),
name = getAppName(context, it.packageName).toString(),
time = 0,
size = null,
status = FAILED_NOT_ALLOWED,
)
}.sortedBy { it.name.lowercase(locale) }
}
private fun getIconFromPackageManager(packageName: String): Drawable = try {
pm.getApplicationIcon(packageName)
} catch (e: PackageManager.NameNotFoundException) {

View file

@ -46,18 +46,6 @@ class ExpertSettingsFragment : PreferenceFragmentCompat() {
quotaPreference.isChecked = newValue as Boolean
true
}
val d2dPreference = findPreference<SwitchPreferenceCompat>(PREF_KEY_D2D_BACKUPS)
d2dPreference?.setOnPreferenceChangeListener { _, newValue ->
d2dPreference.isChecked = newValue as Boolean
// automatically enable unlimited quota when enabling D2D backups
if (d2dPreference.isChecked) {
quotaPreference?.isChecked = true
}
true
}
}
override fun onStart() {

View file

@ -56,7 +56,6 @@ private const val PREF_KEY_BACKUP_APP_BLACKLIST = "backupAppBlacklist"
private const val PREF_KEY_BACKUP_STORAGE = "backup_storage"
internal const val PREF_KEY_UNLIMITED_QUOTA = "unlimited_quota"
internal const val PREF_KEY_D2D_BACKUPS = "d2d_backups"
internal const val PREF_KEY_LAST_BACKUP = "lastBackup"
class SettingsManager(private val context: Context) {
@ -249,14 +248,6 @@ class SettingsManager(private val context: Context) {
fun isQuotaUnlimited() = prefs.getBoolean(PREF_KEY_UNLIMITED_QUOTA, false)
fun d2dBackupsEnabled() = prefs.getBoolean(PREF_KEY_D2D_BACKUPS, false)
fun setD2dBackupsEnabled(enabled: Boolean) {
prefs.edit()
.putBoolean(PREF_KEY_D2D_BACKUPS, enabled)
.apply()
}
/**
* This assumes that if there's no storage plugin set, it is the first start.
* We enforce a storage plugin and don't allow unsetting one,

View file

@ -62,13 +62,7 @@ class ConfigurableBackupTransport internal constructor(private val context: Cont
* which is accessible to the BackupAgent.
* This allows the agent to decide what to do based on properties of the transport.
*/
override fun getTransportFlags(): Int {
return if (settingsManager.d2dBackupsEnabled()) {
D2D_TRANSPORT_FLAGS
} else {
DEFAULT_TRANSPORT_FLAGS
}
}
override fun getTransportFlags(): Int = D2D_TRANSPORT_FLAGS
/**
* Ask the transport for an [Intent] that can be used to launch

View file

@ -14,7 +14,6 @@ val backupModule = module {
single {
PackageService(
context = androidContext(),
backupManager = get(),
settingsManager = get(),
backendManager = get(),
)

View file

@ -5,12 +5,10 @@
package com.stevesoltys.seedvault.transport.backup
import android.app.backup.IBackupManager
import android.content.Context
import android.content.Intent
import android.content.Intent.ACTION_MAIN
import android.content.Intent.CATEGORY_LAUNCHER
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
@ -22,7 +20,6 @@ import android.content.pm.PackageManager.GET_SIGNING_CERTIFICATES
import android.content.pm.PackageManager.MATCH_SYSTEM_ONLY
import android.content.pm.ResolveInfo
import android.os.RemoteException
import android.os.UserHandle
import android.util.Log
import android.util.Log.INFO
import androidx.annotation.WorkerThread
@ -41,13 +38,11 @@ private const val LOG_MAX_PACKAGES = 100
*/
internal class PackageService(
private val context: Context,
private val backupManager: IBackupManager,
private val settingsManager: SettingsManager,
private val backendManager: BackendManager,
) {
private val packageManager: PackageManager = context.packageManager
private val myUserId = UserHandle.myUserId()
private val backend: Backend get() = backendManager.backend
val eligiblePackages: List<String>
@ -64,14 +59,7 @@ internal class PackageService(
logPackages(packages)
}
val eligibleApps = if (settingsManager.d2dBackupsEnabled()) {
// if D2D is enabled, use the "new method" for filtering packages
packages.filter(::shouldIncludeAppInBackup).toTypedArray()
} else {
// otherwise, use the BackupManager call.
backupManager.filterAppsEligibleForBackupForUser(myUserId, packages.toTypedArray())
}
val eligibleApps = packages.filter(::shouldIncludeAppInBackup).toTypedArray()
// log eligible packages
if (Log.isLoggable(TAG, INFO)) {
Log.i(TAG, "Filtering left ${eligibleApps.size} eligible packages:")
@ -140,17 +128,7 @@ internal class PackageService(
/**
* A list of apps that do not allow backup.
*/
val userNotAllowedApps: List<PackageInfo>
@WorkerThread
get() {
// if D2D backups are enabled, all apps are allowed
if (settingsManager.d2dBackupsEnabled()) return emptyList()
return packageManager.getInstalledPackages(0).filter { packageInfo ->
!packageInfo.allowsBackup() &&
!packageInfo.isSystemApp()
}
}
val userNotAllowedApps: List<PackageInfo> = emptyList()
val launchableSystemApps: List<ResolveInfo>
@WorkerThread
@ -196,10 +174,6 @@ internal class PackageService(
}
private fun PackageInfo.allowsBackup(): Boolean {
val appInfo = applicationInfo
if (packageName == MAGIC_PACKAGE_MANAGER || appInfo == null) return false
return if (settingsManager.d2dBackupsEnabled()) {
/**
* TODO: Consider ways of replicating the system's logic so that the user can have
* advance knowledge of apps that the system will exclude, particularly apps targeting
@ -212,10 +186,8 @@ internal class PackageService(
* See frameworks/base/services/backup/java/com/android/server/backup/utils/
* BackupEligibilityRules.java lines 74-81 and 163-167 (tag: android-13.0.0_r8).
*/
true
} else {
appInfo.flags and FLAG_ALLOW_BACKUP != 0
}
val appInfo = applicationInfo
return !(packageName == MAGIC_PACKAGE_MANAGER || appInfo == null)
}
/**

View file

@ -167,10 +167,6 @@ internal class RestoreCoordinator(
*/
fun beforeStartRestore(restorableBackup: RestorableBackup) {
this.restorableBackup = restorableBackup
if (restorableBackup.d2dBackup) {
settingsManager.setD2dBackupsEnabled(true)
}
}
/**

View file

@ -69,8 +69,6 @@
<string name="settings_expert_title">Expert settings</string>
<string name="settings_expert_quota_title">Unlimited app quota</string>
<string name="settings_expert_quota_summary">Do not impose a limitation on the size of app backups.\n\nWarning: This can fill up your storage location quickly. Not needed for most apps.</string>
<string name="settings_expert_d2d_title">Device-to-device backups</string>
<string name="settings_expert_d2d_summary">This forces backups for most apps, even when they disallow them. This is alpha, use at your own risk.</string>
<string name="settings_expert_logcat_title">Save app log</string>
<string name="settings_expert_logcat_summary">Developers can diagnose bugs with these logs.\n\nWarning: The log file might contain personally identifiable information. Review before and delete after sharing!</string>
<string name="settings_expert_logcat_error">Error: Could not save app log</string>
@ -204,7 +202,6 @@
<string name="backup_app_quota_exceeded">Backup quota exceeded</string>
<string name="restore_app_quota_exceeded">Backup quota was exceeded</string>
<string name="restore_app_not_installed">App not installed</string>
<string name="backup_section_not_allowed">Apps that do not allow data backup</string>
<!-- Restore -->
<string name="restore_title">Restore from backup</string>

View file

@ -9,12 +9,6 @@
android:key="unlimited_quota"
android:summary="@string/settings_expert_quota_summary"
android:title="@string/settings_expert_quota_title" />
<SwitchPreferenceCompat
android:id="@+id/d2d_backup_preference"
android:defaultValue="false"
android:key="d2d_backups"
android:summary="@string/settings_expert_d2d_summary"
android:title="@string/settings_expert_d2d_title" />
<Preference
android:icon="@drawable/ic_bug_report"
android:key="logcat"

View file

@ -30,7 +30,6 @@ import io.mockk.verify
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.koin.core.context.stopKoin
@ -75,11 +74,6 @@ class MetadataManagerTest {
private val cacheInputStream: FileInputStream = mockk()
private val encodedMetadata = getRandomByteArray()
@Before
fun beforeEachTest() {
every { settingsManager.d2dBackupsEnabled() } returns false
}
@After
fun afterEachTest() {
stopKoin()

View file

@ -23,6 +23,7 @@ import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
@ -44,7 +45,6 @@ internal class SnapshotCreatorTest : TransportTest() {
fun `test onApkBackedUp`() {
every { applicationInfo.loadLabel(any()) } returns name
every { clock.time() } returns token
every { settingsManager.d2dBackupsEnabled() } returns Random.nextBoolean()
snapshotCreator.onApkBackedUp(packageInfo, apk, blobMap)
val s = snapshotCreator.finalizeSnapshot()
@ -70,7 +70,6 @@ internal class SnapshotCreatorTest : TransportTest() {
every { appInfo.loadLabel(any()) } returns name
every { metadataManager.onPackageBackedUp(packageInfo, BackupType.FULL, size) } just Runs
every { clock.time() } returns token andThen token + 1
every { settingsManager.d2dBackupsEnabled() } returns Random.nextBoolean()
every { packageService.launchableSystemApps } returns listOf(resolveInfo)
snapshotCreator.onPackageBackedUp(packageInfo, BackupType.FULL, apkBackupData)
@ -92,7 +91,6 @@ internal class SnapshotCreatorTest : TransportTest() {
val size = apkBackupData.size
every { metadataManager.onPackageBackedUp(packageInfo, BackupType.FULL, size) } just Runs
every { clock.time() } returns token andThen token + 1
every { settingsManager.d2dBackupsEnabled() } returns Random.nextBoolean()
every { packageService.launchableSystemApps } returns emptyList()
snapshotCreator.onPackageBackedUp(packageInfo, BackupType.FULL, apkBackupData)
@ -102,7 +100,6 @@ internal class SnapshotCreatorTest : TransportTest() {
@Test
fun `test onIconsBackedUp`() {
every { clock.time() } returns token andThen token + 1
every { settingsManager.d2dBackupsEnabled() } returns Random.nextBoolean()
snapshotCreator.onIconsBackedUp(apkBackupData)
val s = snapshotCreator.finalizeSnapshot()
@ -113,9 +110,7 @@ internal class SnapshotCreatorTest : TransportTest() {
@Test
fun `test finalize`() {
val d2d = Random.nextBoolean()
every { clock.time() } returns token
every { settingsManager.d2dBackupsEnabled() } returns d2d
val s = snapshotCreator.finalizeSnapshot()
@ -126,7 +121,7 @@ internal class SnapshotCreatorTest : TransportTest() {
assertEquals("", s.androidId) // not mocked
assertEquals(34, s.sdkInt) // as per config above, needs bump once possible
assertEquals("unknown", s.androidIncremental)
assertEquals(d2d, s.d2D)
assertTrue(s.d2D)
assertEquals(0, s.appsCount)
assertEquals(0, s.iconChunkIdsCount)
assertEquals(emptyMap<String, Snapshot.Blob>(), s.blobsMap)