Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5dcd917 authored by Eric Hsu's avatar Eric Hsu Committed by Android (Google) Code Review
Browse files

Merge "Instantly excute next state when the agent provides a prohibited key."

parents 6246b85a e6e63cd6
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -884,7 +884,12 @@ public class PerformBackupTask implements BackupRestoreTask {
                                        .sendBackupOnPackageResult(mObserver, pkgName,
                                                BackupManager.ERROR_AGENT_FAILURE);
                                errorCleanup();
                                // agentErrorCleanup() implicitly executes next state properly
                                if (MORE_DEBUG) {
                                    Slog.i(TAG, "Agent failure for " + pkgName
                                            + " with illegal key: " + key + "; dropped");
                                }
                                executeNextState(mQueue.isEmpty() ? BackupState.FINAL
                                        : BackupState.RUNNING_QUEUE);
                                return;
                            }
                            in.skipEntityData();
+35 −2
Original line number Diff line number Diff line
@@ -361,10 +361,43 @@ public class PerformBackupTaskTest {

        runTask(task);

        // TODO: Should it not call mListener.onFinished()? PerformBackupTask:891 return?
        // verify(mListener).onFinished(any());
        verify(mListener).onFinished(any());
        verify(mObserver).onResult(eq(PACKAGE_1), eq(BackupManager.ERROR_AGENT_FAILURE));
        verify(agentMock.agentBinder).fail(any());
        verify(mObserver).backupFinished(BackupManager.SUCCESS);
    }

    @Test
    public void testRunTask_whenFirstAgentKeyProhibitedButLastPermitted() throws Exception {
        TransportMock transportMock = setUpTransport(mTransport);
        List<AgentMock> agentMocks = setUpAgents(PACKAGE_1, PACKAGE_2);
        AgentMock agentMock1 = agentMocks.get(0);
        AgentMock agentMock2 = agentMocks.get(1);
        agentOnBackupDo(
                agentMock1.agent,
                (oldState, dataOutput, newState) -> {
                    char prohibitedChar = 0xff00;
                    writeData(dataOutput, prohibitedChar + "key", "foo".getBytes());
                });
        agentOnBackupDo(
                agentMock2.agent,
                (oldState, dataOutput, newState) -> {
                    writeData(dataOutput, "key", "bar".getBytes());
                });
        PerformBackupTask task =
                createPerformBackupTask(
                        transportMock.transportClient,
                        mTransport.transportDirName,
                        PACKAGE_1,
                        PACKAGE_2);

        runTask(task);

        verify(mListener).onFinished(any());
        verify(mObserver).onResult(eq(PACKAGE_1), eq(BackupManager.ERROR_AGENT_FAILURE));
        verify(agentMock1.agentBinder).fail(any());
        verify(mObserver).onResult(eq(PACKAGE_2), eq(BackupManager.SUCCESS));
        verify(mObserver).backupFinished(BackupManager.SUCCESS);
    }

    @Test