seedvault-app / seedvault

A backup application for the Android Open Source Project.
1.26k stars 74 forks source link

Port to Android 14 #564

Closed grote closed 11 months ago

grote commented 1 year ago

Related to https://github.com/seedvault-app/seedvault/issues/433

chirayudesai commented 12 months ago
chirayudesai commented 12 months ago

13 SeedVault builds in 14, launches, but crashes on "Backup Now" with

                         E  FATAL EXCEPTION: main
                         E  Process: com.stevesoltys.seedvault, PID: 17278
                         E  java.lang.RuntimeException: Unable to start service com.stevesoltys.seedvault.storage.StorageBackupService@a68e85d with Intent
                            { cmp=com.stevesoltys.seedvault/.storage.StorageBackupService }: java.lang.SecurityException: Starting FGS with type dataSync c
                            allerApp=ProcessRecord{2d21933 17278:com.stevesoltys.seedvault/u0a121} targetSDK=34 requires permissions: all of the permission
                            s allOf=true [android.permission.FOREGROUND_SERVICE_DATA_SYNC]
                         E      at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4839)
                         E      at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
                         E      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289)
                         E      at android.os.Handler.dispatchMessage(Handler.java:106)
                         E      at android.os.Looper.loopOnce(Looper.java:205)
                         E      at android.os.Looper.loop(Looper.java:294)
                         E      at android.app.ActivityThread.main(ActivityThread.java:8177)
                         E      at java.lang.reflect.Method.invoke(Native Method)
                         E      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                         E      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
                         E  Caused by: java.lang.SecurityException: Starting FGS with type dataSync callerApp=ProcessRecord{2d21933 17278:com.stevesoltys.s
                            eedvault/u0a121} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_DA
                            TA_SYNC]
                         E      at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
                         E      at android.os.Parcel.createException(Parcel.java:3041)
                         E      at android.os.Parcel.readException(Parcel.java:3024)
                         E      at android.os.Parcel.readException(Parcel.java:2966)
                         E      at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6761)
                         E      at android.app.Service.startForeground(Service.java:775)
                         E      at org.calyxos.backup.storage.backup.BackupService.onStartCommand(BackupService.kt:31)
                         E      at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4821)
                         E      ... 9 more
                         E  Caused by: android.os.RemoteException: Remote stack trace:
                         E      at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2611)
                         E      at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2322)
                         E      at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1679)
                         E      at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:13265)
                         E      at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3385)
chirayudesai commented 12 months ago

Identify all upgraded libraries and find matching versions for the non-AOSP buildsystem, bumping their versions as needed.

Barely any changes. It'll actually be a good thing, to support Android 13 at the same time. Long term, I'd like to use AOSP libs as little as possible anyways, because going an year without an update is bad.

chirayudesai commented 12 months ago

Doing the port in two steps

  1. Android.bp - it mostly seems to work, may just need minor changes. Easy to do as we work on it. #574
  2. gradle - looks like this will need a bit more work and testing. WiP #576
grote commented 11 months ago

Long term, I'd like to use AOSP libs as little as possible anyways, because going an year without an update is bad.

How would we do this? AFAIK we need to build inside AOSP, right? So bundle all dependencies?

chirayudesai commented 11 months ago

How would we do this? AFAIK we need to build inside AOSP, right? So bundle all dependencies?

Yes. Using https://github.com/lineage-next/gradle-generatebp

We don't have to do them all right now, but we can start with anything that's really old / needs upgrading due to some reason or the other.

grote commented 11 months ago

First findings from going through commit messages:

chirayudesai commented 11 months ago
  • BackupAndRestoreFeatureFlags for setting custom timeouts via server syncs. Maybe they noticed that the 5min sync was sometimes too short? adb shell device_config put backup_and_restore backup_transport_callback_timeout_millis 1

We can control this using https://github.com/CalyxOS/vendor_calyx/blob/android13/overlay/common/packages/apps/SimpleDeviceConfig/res/values/config.xml which uses on

grote commented 11 months ago

More findings from going through commit messages:

tl;dr nothing we need urgently react to before making a 14 release. The only thing we might want to check is the shorter timeouts, i.e. by doing a slow APK backup taking more than 5min.

grote commented 11 months ago

The bad news is that we are affected by the timeouts. Our backup transport service gets destroyed and the backups fails.

Error during PM metadata backup
    com.android.server.backup.keyvalue.TaskException
        at com.android.server.backup.keyvalue.KeyValueBackupTask.handleTransportStatus(KeyValueBackupTask.java:1138)
        at com.android.server.backup.keyvalue.KeyValueBackupTask.sendDataToTransport(KeyValueBackupTask.java:1072)
        at com.android.server.backup.keyvalue.KeyValueBackupTask.sendDataToTransport(KeyValueBackupTask.java:577)
        at com.android.server.backup.keyvalue.KeyValueBackupTask.backupPm(KeyValueBackupTask.java:682)
        at com.android.server.backup.keyvalue.KeyValueBackupTask.run(KeyValueBackupTask.java:368)

However, our APK backup code (which I used for testing) keeps running and updates the notification which is bad.

There's two places we hook in to back up APKs: 1) When finishBackup() gets called for @pm@ backup to back up APKs of apps that don't allow backup 2) When getBackupQuota() gets called for apps that do allow backup

The second one is less likely to run into timeouts, but the first one is uploading potentially many large APKs to a slow network storage which may take longer than the timeout we have. Making a @pm@ backup fail let's the system react harshly usually asking for a full re-init of the backup location. So that's also not good.

As a temporary measure, we could increase both DeviceConfig timeouts on a ROM level to a safer default:

A long-term solution could be to move to our own backup scheduling and do APK backups as part of it, so we don't need to hack into places that are not mean to be hacked into. This would also help with the fact that our hacked in code in finishBackup() survives destruction of the backup transport service.

chirayudesai commented 11 months ago

As a temporary measure, we could increase both DeviceConfig timeouts on a ROM level to a safer default:

https://review.calyxos.org/c/CalyxOS/vendor_calyx/+/22132 overlay: SimpleDeviceConfig: Adjust values for SeedVault Backup usage