seedvault icon indicating copy to clipboard operation
seedvault copied to clipboard

Port to Android 13

Open grote opened this issue 2 years ago • 8 comments

Branch: https://github.com/seedvault-app/seedvault/tree/android13

Also check upstream commits for any changes to the backup related code.

grote avatar Aug 19 '22 12:08 grote

Some behavior changes to check:

  • [x] Apps need to ask permission to show notifications - https://developer.android.com/about/versions/13/changes/notification-permission
  • [ ] New rules for intent filters could affect our use of intents to open other apps https://developer.android.com/about/versions/13/behavior-changes-13#security
  • [x] must request more granular media permissions instead of the READ_EXTERNAL_STORAGE https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions

grote avatar Aug 19 '22 17:08 grote

  • There's an EncryptedLocalTransport now. Not sure if functional.
  • But looks like the "Encryption in the Framework project" is dead?
  • timeout in TransportStatusCallback was halfed to 5min which hopefully doesn't cause issues when we do stuff like long-running APK backups during a package backup
  • Allow BackupHelper to be overridden. This will allow vendor versions of System UI to backup their vendor-specific data.

Also lots of internal bug fixes which might solve some issues we've seen.

grote avatar Aug 19 '22 18:08 grote

EncryptedLocalTranspot

The commit adding it has some more info: https://android.googlesource.com/platform/frameworks/base.git/+/004e85f798dc88265edffebeba66da4efaeb2735

CTS tests are public, GTS not.

"Encryption in the Framework"

Linked commit mentions "making the backup transport AIDL async"

Transport timeout

I guess we could always consider optionally bumping it - it'd be a quality of life patch that ROMs could apply if they want

vendor versions of System UI

Google ships SystemUIGoogle on Pixels for example (where a LOT of features are implemented)

chirayudesai avatar Sep 05 '22 14:09 chirayudesai

Did a quick test backup to internal storage, worked at first and then fails with https://zifb.in/raw/Wdox1TrFJs

Need to test more, with more data as well (usually I restore one of my actual backups to have a good set)

chirayudesai avatar Sep 07 '22 14:09 chirayudesai

more verbose log when I reproduced this by backup up and then restoring and then doing another backup:

2022-09-08 16:44:58.517 9670-9696/com.stevesoltys.seedvault I/PackageService: Got 241 packages:
2022-09-08 16:44:58.807 9670-9696/com.stevesoltys.seedvault I/PackageService: [all apps]
2022-09-08 16:44:58.520 9670-9670/com.stevesoltys.seedvault D/ConfigurableBackupTransportService: Service created.
2022-09-08 16:44:58.525 9670-9670/com.stevesoltys.seedvault D/ConfigurableBackupTransportService: Transport bound.
2022-09-08 16:44:58.527 1741-1741/system_process I/TransportConnection: ConfigurableBackupTransportService#161: Notifying [AppBackupUtils.appIsRunningAndEligibleForBackupWithTransport] transport = BackupTransportClient
2022-09-08 16:44:58.802 9670-9696/com.stevesoltys.seedvault I/PackageService: Filtering left 154 eligible packages:
2022-09-08 16:44:58.803 9670-9670/com.stevesoltys.seedvault D/ConfigurableBackupTransportService: Service destroyed.
2022-09-08 16:44:58.807 9670-9696/com.stevesoltys.seedvault I/PackageService: [filtered apps]
2022-09-08 16:44:58.819 9670-9696/com.stevesoltys.seedvault D/ConfigurableBackupTransportService: Backup is enabled, request backup...
2022-09-08 16:44:58.819 9670-9696/com.stevesoltys.seedvault I/BackupNotificationManager: 0/155 - 0% - 
2022-09-08 16:44:58.825 9670-9670/com.stevesoltys.seedvault D/ConfigurableBackupTransportService: Service created.
2022-09-08 16:44:58.828 9670-9670/com.stevesoltys.seedvault D/ConfigurableBackupTransportService: Transport bound.
2022-09-08 16:44:58.829 1741-1741/system_process I/TransportConnection: ConfigurableBackupTransportService#162: Notifying [BMS.getOperationTypeFromTransport] transport = BackupTransportClient
2022-09-08 16:44:58.837 9670-9696/com.stevesoltys.seedvault I/ConfigurableBackupTransportService: Backup succeeded 
2022-09-08 16:44:58.837 1741-4073/system_process V/BackupManagerService: [UserID:0] Acquired wakelock:*backup*-0-4073
2022-09-08 16:44:58.838 1741-4073/system_process D/KeyValueBackupTask: Spinning thread key-value-backup-4
2022-09-08 16:44:58.839 9670-9670/com.stevesoltys.seedvault D/BackupService: onDestroy
2022-09-08 16:44:58.843 1741-23215/system_process D/PFTBT: backupmanager pftbt token=67d43a00
2022-09-08 16:44:58.843 1741-23215/system_process V/KeyValueBackupTask: Beginning backup of 13 targets
2022-09-08 16:44:58.845 1741-23215/system_process I/KeyValueBackupTask: Initializing transport and resetting backup state
2022-09-08 16:44:58.856 1741-23215/system_process V/BackupManagerService: [UserID:0] Ancestral packages:  172
2022-09-08 16:44:58.885 9670-14378/com.stevesoltys.seedvault I/BackupCoordinator: Initialize Device!
2022-09-08 16:44:59.077 9670-14378/com.stevesoltys.seedvault D/BackupCoordinator: Resetting backup metadata for token 1661261856359...
2022-09-08 16:44:59.135 1741-23215/system_process D/KeyValueBackupTask: Starting key-value backup of @pm@
2022-09-08 16:44:59.141 1741-23215/system_process D/KeyValueBackupTask: Invoking agent on @pm@
2022-09-08 16:44:59.149 9670-14378/com.stevesoltys.seedvault I/BackupCoordinator: Get backup quota for @pm@. Is full backup: false.
2022-09-08 16:44:59.149 9670-14378/com.stevesoltys.seedvault I/BackupCoordinator: Reported quota of 10485760 bytes.
2022-09-08 16:44:59.150 1741-23215/system_process I/PMBA: Previous metadata null mismatch vs eng.cdesai.20220908.170828 - rewriting
2022-09-08 16:44:59.166 1741-23215/system_process I/BackupRestoreController: Getting widget state for user: 0
2022-09-08 16:44:59.169 9670-14378/com.stevesoltys.seedvault I/KVBackup: Performing non-incremental K/V backup for @pm@
2022-09-08 16:44:59.170 9670-14378/com.stevesoltys.seedvault W/KVBackup: Requested non-incremental, deleting existing data.
2022-09-08 16:44:59.170 9670-14378/com.stevesoltys.seedvault I/KVBackup: Clearing K/V data of @pm@
2022-09-08 16:44:59.183 9670-14378/com.stevesoltys.seedvault V/KVBackup:   Delta operation key @ancestral_record@   size 4
2022-09-08 16:44:59.232 9670-14378/com.stevesoltys.seedvault V/KVBackup:   Delta operation key @home@   size 125
2022-09-08 16:44:59.233 9670-14378/com.stevesoltys.seedvault V/KVBackup:   Delta operation key @meta@   size 32
2022-09-08 16:44:59.234 9670-14378/com.stevesoltys.seedvault V/KVBackup:   Delta operation key com.android.internal.display.cutout.emulation.noCutout   size 44
2022-09-08 16:44:59.235 9670-14378/com.stevesoltys.seedvault V/KVBackup:   Delta operation key com.nextcloud.client   size 44
2022-09-08 16:44:59.236 9670-14378/com.stevesoltys.seedvault V/KVBackup:   Delta operation key com.android.cts.priv.ctsshim   size 44
...
2022-09-08 16:44:59.423 9670-14378/com.stevesoltys.seedvault I/KVBackup: Finish K/V Backup of @pm@ - needs upload: true
2022-09-08 16:44:59.500 9670-14378/com.stevesoltys.seedvault D/KVBackup: Uploaded db file for @pm@
2022-09-08 16:44:59.526 9670-14378/com.stevesoltys.seedvault D/BackupCoordinator: Checking if APKs of opt-out apps need backup...
2022-09-08 16:44:59.585 9670-14378/com.stevesoltys.seedvault I/PackageService: 20 apps do not allow backup:
2022-09-08 16:44:59.586 9670-14378/com.stevesoltys.seedvault I/PackageService: [apps]
2022-09-08 16:44:59.586 9670-14378/com.stevesoltys.seedvault I/BackupNotificationManager: 1/175 - 1% - Opt-out APK for app.organicmaps
2022-09-08 16:44:59.962 9670-14378/com.stevesoltys.seedvault I/NotificationBackupObserver: Completed. Target: @pm@, status: -1000
2022-09-08 16:44:59.962 9670-14378/com.stevesoltys.seedvault I/NotificationBackupObserver: Showing progress notification for null 0/155
2022-09-08 16:44:59.962 9670-14378/com.stevesoltys.seedvault I/BackupNotificationManager: 21/175 - 12% - System package manager
2022-09-08 16:44:59.962 1741-23215/system_process E/KeyValueBackupTask: Error during PM metadata backup
    com.android.server.backup.keyvalue.TaskException
        at com.android.server.backup.keyvalue.KeyValueBackupTask.handleTransportStatus(KeyValueBackupTask.java:1135)
        at com.android.server.backup.keyvalue.KeyValueBackupTask.sendDataToTransport(KeyValueBackupTask.java:1069)
        at com.android.server.backup.keyvalue.KeyValueBackupTask.sendDataToTransport(KeyValueBackupTask.java:576)
        at com.android.server.backup.keyvalue.KeyValueBackupTask.backupPm(KeyValueBackupTask.java:681)
        at com.android.server.backup.keyvalue.KeyValueBackupTask.run(KeyValueBackupTask.java:367)
        at java.lang.Thread.run(Thread.java:1012)
2022-09-08 16:44:59.963 9670-14378/com.stevesoltys.seedvault I/BackupCoordinator: Request incremental backup time. Returned 0
2022-09-08 16:44:59.964 1741-23215/system_process I/KeyValueBackupTask: K/V backup pass finished
2022-09-08 16:44:59.966 9670-11765/com.stevesoltys.seedvault I/NotificationBackupObserver: Backup finished 1/155. Status: -1000
2022-09-08 16:44:59.966 1741-23215/system_process V/BackupManagerService: [UserID:0] Released wakelock:*backup*-0-4073
2022-09-08 16:44:59.967 9670-9670/com.stevesoltys.seedvault W/BackupNotificationManager: Needed to clean up notification with ID 1
2022-09-08 16:44:59.968 9670-9670/com.stevesoltys.seedvault D/ConfigurableBackupTransportService: Service destroyed.

grote avatar Sep 08 '22 19:09 grote

What I find curious:

I/KeyValueBackupTask: Initializing transport and resetting backup state
I/PMBA: Previous metadata null mismatch vs eng.cdesai.20220908.170828 - rewriting

Now this could be due to restoring mid-flight and then backing that restored system up again? Still, why is it even resetting the backup state? Maybe that's fine, but maybe some internal states get into mismatch due to that.

Then we are doing a non-incremental @pm@ backup which is expected, but we get the exception in the middle of it. Still need to check AOSP source code why this could be.

When @pm@ comes back with status -1000, we probably shouldn't start touching opt-out apps. Also, this should probably not be happening:

I/NotificationBackupObserver: Showing progress notification for null 0/155

grote avatar Sep 08 '22 20:09 grote

So it seems to be actually us returning TRANSPORT_ERROR (aka -1000) to the system, but we fail to log the reason for it.

When @pm@ comes back with status -1000, we probably shouldn't start touching opt-out apps.

We don't do this. Until here, we are TRANSPORT_OK. An exception gets thrown inside backUpApksOfNotBackedUpPackages(), but it doesn't get logged.

grote avatar Sep 08 '22 20:09 grote

We pre-grant the notification permission now and if the user removes it, there's no crash or anything, so I guess nothing else to do about it.

In settings, there's new permission being shown for accessing photos and videos which are not granted, but we have manage storage permission. So I tested that we are still able to backup photos. Photos taken with the cam app restore just fine.

grote avatar Sep 08 '22 20:09 grote

completed.

grote avatar Jan 04 '23 13:01 grote