[KV] State machine to linear task w/ RemoteCall
This is the first CL of key-value backup refactor. * Method execute() that executed the state machine states is now empty and run() is created with the initial version of the linear task. It's basically composed of begin + loop + end. Although it still has the notion of state, it's more restricted than before (with private methods returning the next state). This is intentional to avoid making this CL too heavy to review and to avoid too much behavioral changes here. In the next CLs I intend to remove BackupState. * Introduction of RemoteCall, which encapsulates an outbound call that leaves the system_server, with time-out and cancellation built-in. Agent calls are now triggered using this. As a result there is no more operationComplete() method either. * Cancellation now is cleaner. We don't need a step lock anymore, only a (volatile) boolean that is checked in every queue iteration. If asked to cancel during an ongoing agent call we rely on RemoteCall.cancel() to return control of the task thread to us. We wait for the cancel acknowledgement to preserve the contract of no more transport calls. * PFTBT instantiation moved from the constructor to the run() method, which makes more sense. * No need for mFinished, mBackupData == null bookkeeping since time-outs, cancellation and legitimate agent responses won't step into one another anymore. * Ternary (mQueue.isEmpty) ? BackupState.FINAL : BackupState.RUNNING_QUEUE gone because we check this in the beginning of invokeNextAgent() and now we don't pay the state-machine tick price associated with the handler. * PerformBackupTask call sites now call static method start(), that spins up a new dedicated thread for the task. This new thread is assigned the same (process) priority as the backup thread (THREAD_PRIORITY_BACKGROUND). Work left for future CLs: * RemoteCall spins up a new thread for kicking off the call, this is for system agents that are executed inline. Old PBT also executed in the same thread (backup handler thread), so maintaining this to keep this CL at a reasonable size. Test: atest PerformBackupTaskTest Test: atest RunFrameworksServicesRoboTests Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/backup Test: atest CtsBackupTestCases Test: atest CtsBackupHostTestCases Test: atest GtsBackupTestCases Test: atest GtsBackupHostTestCases Test: adb shell bmgr backupnow <kv_packages> Test: 1. adb shell bmgr backup <p1> <p2> 2. adb shell bmgr run A) 3. Cancel while sending <p1> data to transport 4. Verify <p1> is backed-up and not pending Verify <p2> is not backed-up and is pending B) 3. Cancel while waiting for <p1> agent 4. Verify <p1> is not backed-up and is pending Verify <p2> is not backed-up and is pending Change-Id: Ia456c4e807de95d662c9e923245be07e8996f58a
Loading
Please register or sign in to comment