selectBackupTransportAsync should report failure when backup is disabled
Fix: 37304539
Test: runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java
Test: setup device owner, then set up profile.
Ensure tapping Settings->Google->Work->Security -> Verify app
is working
Change-Id: I393308857ea6082dca167e3e417b946615a83c20
diff --git a/services/backup/java/com/android/server/backup/Trampoline.java b/services/backup/java/com/android/server/backup/Trampoline.java
index 0fd0ea5..1e56e95 100644
--- a/services/backup/java/com/android/server/backup/Trampoline.java
+++ b/services/backup/java/com/android/server/backup/Trampoline.java
@@ -356,6 +356,8 @@
BackupManagerServiceInterface svc = mService;
if (svc != null) {
svc.selectBackupTransportAsync(transport, listener);
+ } else {
+ listener.onFailure(BackupManager.ERROR_BACKUP_NOT_ALLOWED);
}
}
diff --git a/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java b/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java
index 1896cda..4c53915 100644
--- a/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java
+++ b/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java
@@ -18,6 +18,7 @@
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
@@ -31,6 +32,7 @@
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IBackupObserver;
import android.app.backup.IFullBackupRestoreObserver;
+import android.app.backup.ISelectBackupTransportCallback;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -54,6 +56,9 @@
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;
@SmallTest
@Presubmit
@@ -568,9 +573,30 @@
}
@Test
- public void selectBackupTransportAsync_calledBeforeInitialize_ignored() throws RemoteException {
- mTrampoline.selectBackupTransportAsync(TRANSPORT_COMPONENT_NAME, null);
+ public void selectBackupTransportAsync_calledBeforeInitialize_ignored() throws Exception {
+ LinkedBlockingQueue<Integer> q = new LinkedBlockingQueue();
+ mTrampoline.selectBackupTransportAsync(
+ TRANSPORT_COMPONENT_NAME,
+ new ISelectBackupTransportCallback() {
+ @Override
+ public void onSuccess(String transportName) throws RemoteException {
+
+ }
+
+ @Override
+ public void onFailure(int reason) throws RemoteException {
+ q.offer(reason);
+ }
+
+ @Override
+ public IBinder asBinder() {
+ return null;
+ }
+ });
verifyNoMoreInteractions(mBackupManagerServiceMock);
+ Integer errorCode = q.poll(5, TimeUnit.SECONDS);
+ assertNotNull(errorCode);
+ assertEquals(BackupManager.ERROR_BACKUP_NOT_ALLOWED, (int) errorCode);
}
@Test