Add null checking and exception handling in selectBackupTransportAsync

Bug: 37304539

Test: bit FrameworksServicesTests:com.android.server.backup.TrampolineTest

Change-Id: I01ffa25bfca6ca743220ee7277c2a6473c055bf1
This commit is contained in:
Tony Mak
2017-05-04 11:42:31 +01:00
parent b300217639
commit 2dd109d238
2 changed files with 40 additions and 2 deletions

View File

@@ -357,7 +357,13 @@ public class Trampoline extends IBackupManager.Stub {
if (svc != null) {
svc.selectBackupTransportAsync(transport, listener);
} else {
listener.onFailure(BackupManager.ERROR_BACKUP_NOT_ALLOWED);
if (listener != null) {
try {
listener.onFailure(BackupManager.ERROR_BACKUP_NOT_ALLOWED);
} catch (RemoteException ex) {
// ignore
}
}
}
}

View File

@@ -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);