Ask transport for a monitor during restore

The current API is designed so that the requester of the restore
operation passes in a BackupManagerMonitor. This functionality is
currently unused, so effectively we'll start asking for a monitor every
time.

Note that the requester and transport are not necessarily the same
entity in the current API definition. This means in the future the
requester can start passing in a monitor which would mean we stop asking
the transport for one. This is not ideal so while it's infeasible now,
in the future we can investigate formally coupling the transport and the
requester in the API.

Bug: 254815434, 254641961
Test: This class is not testable without a major refactor.
  atest CtsBackupHostTestCases
  Also manually by ensuring getBackupManagerMonitor() gets called when
  running 'adb shell bmgr restore` for KV and full backup packages.

Change-Id: I8892ed7e3aa04ca771c9628b44751a9fdef4aad2
This commit is contained in:
Sarp Misoglu
2022-11-09 16:04:11 +00:00
parent 104604674f
commit 2801c741d3

View File

@@ -405,6 +405,12 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask {
BackupTransportClient transport =
mTransportConnection.connectOrThrow("PerformUnifiedRestoreTask.startRestore()");
// If the requester of the restore has not passed in a monitor, we ask the transport
// for one.
if (mMonitor == null) {
mMonitor = transport.getBackupManagerMonitor();
}
mStatus = transport.startRestore(mToken, packages);
if (mStatus != BackupTransport.TRANSPORT_OK) {
Slog.e(TAG, "Transport error " + mStatus + "; no restore possible");