[KV] Refactor sendDataToTransport() and finishTask()
Refactor sendDataToTransport():
* Instead of truncating backup data when reading backup data / writing widget
data, consider the IOException a transport-level failure. Added tests for
this.
* Extracted a few methods: validateBackupData(), updateFiles(),
handleTransportStatus().
* Put the if (size > 0) check outside try-catch block.
* Used try-with-resources.
* Clean files in case of transport error, quota exceeded.
Refactor finishTask():
* Extracted triggerTransportInitializationLocked(), assigned queue lock
to private final var in ctor.
* In triggerTransportInitializationLocked() set the status to T_ERROR if
we failed to query the name of the transport.
* Tests for TRANSPORT_NOT_INITIALIZED.
General:
* Small refactors in KVBT.
* Small refactors in test.
Bug: 110082831
Bug: 113311470
Test: adb shell bmgr backupnow <kv_package>
Test: 1. adb shell bmgr backupnow <kv_package>
2. Transport returns T_NOT_INITIALIZED
3. Make sure PM metadata state file is deleted.
Test: atest KeyValueBackupTaskTest
Change-Id: I8d85c24cba6da4fbaf14234e2ce6d8e0699a3eed
9 files changed