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

Commit b3f506aa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add null checking and exception handling in selectBackupTransportAsync"

parents 2dcec3ce 2dd109d2
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -357,7 +357,13 @@ public class Trampoline extends IBackupManager.Stub {
        if (svc != null) {
            svc.selectBackupTransportAsync(transport, listener);
        } else {
            if (listener != null) {
                try {
                    listener.onFailure(BackupManager.ERROR_BACKUP_NOT_ALLOWED);
                } catch (RemoteException ex) {
                    // ignore
                }
            }
        }
    }

+33 −1
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

@@ -599,6 +598,39 @@ public class TrampolineTest {
        assertEquals(BackupManager.ERROR_BACKUP_NOT_ALLOWED, (int) errorCode);
    }

    @Test
    public void selectBackupTransportAsync_calledBeforeInitialize_ignored_nullListener()
            throws Exception {
        mTrampoline.selectBackupTransportAsync(TRANSPORT_COMPONENT_NAME, null);
        verifyNoMoreInteractions(mBackupManagerServiceMock);
        // No crash.
    }

    @Test
    public void selectBackupTransportAsync_calledBeforeInitialize_ignored_listenerThrowException()
            throws Exception {
        mTrampoline.selectBackupTransportAsync(
                TRANSPORT_COMPONENT_NAME,
                new ISelectBackupTransportCallback() {
                    @Override
                    public void onSuccess(String transportName) throws RemoteException {

                    }

                    @Override
                    public void onFailure(int reason) throws RemoteException {
                        throw new RemoteException("Crash");
                    }

                    @Override
                    public IBinder asBinder() {
                        return null;
                    }
                });
        verifyNoMoreInteractions(mBackupManagerServiceMock);
        // No crash.
    }

    @Test
    public void selectBackupTransportAsync_forwarded() throws RemoteException {
        mTrampoline.initialize(UserHandle.USER_SYSTEM);