Merge "Update PerformInitializeTask error message"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c87e4b8ea0
@@ -130,9 +130,13 @@ public class PerformInitializeTask implements Runnable {
|
||||
|
||||
IBackupTransport transport = transportClient.connectOrThrow(callerLogString);
|
||||
int status = transport.initializeDevice();
|
||||
|
||||
if (status == BackupTransport.TRANSPORT_OK) {
|
||||
if (status != BackupTransport.TRANSPORT_OK) {
|
||||
Slog.e(TAG, "Transport error in initializeDevice()");
|
||||
} else {
|
||||
status = transport.finishBackup();
|
||||
if (status != BackupTransport.TRANSPORT_OK) {
|
||||
Slog.e(TAG, "Transport error in finishBackup()");
|
||||
}
|
||||
}
|
||||
|
||||
// Okay, the wipe really happened. Clean up our local bookkeeping.
|
||||
@@ -148,7 +152,6 @@ public class PerformInitializeTask implements Runnable {
|
||||
} else {
|
||||
// If this didn't work, requeue this one and try again
|
||||
// after a suitable interval
|
||||
Slog.e(TAG, "Transport error in initializeDevice()");
|
||||
EventLog.writeEvent(EventLogTags.BACKUP_TRANSPORT_FAILURE, "(initialize)");
|
||||
mBackupManagerService.recordInitPending(true, transportName, transportDirName);
|
||||
notifyResult(transportName, status);
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.server.backup.internal;
|
||||
import static android.app.backup.BackupTransport.TRANSPORT_ERROR;
|
||||
import static android.app.backup.BackupTransport.TRANSPORT_OK;
|
||||
|
||||
import static com.android.server.backup.testing.TestUtils.assertLogcatContains;
|
||||
import static com.android.server.backup.testing.TransportData.backupTransport;
|
||||
import static com.android.server.backup.testing.TransportData.d2dTransport;
|
||||
import static com.android.server.backup.testing.TransportData.localTransport;
|
||||
@@ -40,6 +41,7 @@ import android.app.PendingIntent;
|
||||
import android.app.backup.IBackupObserver;
|
||||
import android.os.DeadObjectException;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.backup.IBackupTransport;
|
||||
import com.android.server.backup.BackupManagerService;
|
||||
@@ -50,6 +52,8 @@ import com.android.server.backup.testing.TransportTestUtils.TransportMock;
|
||||
import com.android.server.backup.transport.TransportClient;
|
||||
import com.android.server.testing.FrameworkRobolectricTestRunner;
|
||||
import com.android.server.testing.SystemLoaderPackages;
|
||||
import com.android.server.testing.shadows.ShadowSlog;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -66,7 +70,7 @@ import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@RunWith(FrameworkRobolectricTestRunner.class)
|
||||
@Config(manifest = Config.NONE, sdk = 26)
|
||||
@Config(manifest = Config.NONE, sdk = 26, shadows = ShadowSlog.class)
|
||||
@SystemLoaderPackages({"com.android.server.backup"})
|
||||
@Presubmit
|
||||
public class PerformInitializeTaskTest {
|
||||
@@ -201,6 +205,32 @@ public class PerformInitializeTaskTest {
|
||||
verify(mListener).onFinished(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRun_whenFinishBackupFails_logs() throws Exception {
|
||||
setUpTransport(mTransport);
|
||||
configureTransport(mTransportBinder, TRANSPORT_OK, TRANSPORT_ERROR);
|
||||
PerformInitializeTask performInitializeTask = createPerformInitializeTask(mTransportName);
|
||||
|
||||
performInitializeTask.run();
|
||||
|
||||
assertLogcatContains(
|
||||
BackupManagerService.TAG,
|
||||
log -> log.msg.contains("finishBackup()") && log.type >= Log.ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRun_whenInitializeDeviceFails_logs() throws Exception {
|
||||
setUpTransport(mTransport);
|
||||
configureTransport(mTransportBinder, TRANSPORT_ERROR, 0);
|
||||
PerformInitializeTask performInitializeTask = createPerformInitializeTask(mTransportName);
|
||||
|
||||
performInitializeTask.run();
|
||||
|
||||
assertLogcatContains(
|
||||
BackupManagerService.TAG,
|
||||
log -> log.msg.contains("initializeDevice()") && log.type >= Log.ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRun_whenFinishBackupFails_schedulesAlarm() throws Exception {
|
||||
setUpTransport(mTransport);
|
||||
|
||||
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import org.robolectric.shadows.ShadowLog;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class TestUtils {
|
||||
/** Reset logcat with {@link ShadowLog#reset()} before the test case */
|
||||
@@ -35,6 +36,10 @@ public class TestUtils {
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
public static void assertLogcatContains(String tag, Predicate<ShadowLog.LogItem> predicate) {
|
||||
assertThat(ShadowLog.getLogsForTag(tag).stream().anyMatch(predicate)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link Runnable#run()} and returns if no exception is thrown. Otherwise, if the
|
||||
* exception is unchecked, rethrow it; if it's checked wrap in a {@link RuntimeException} and
|
||||
|
||||
@@ -25,6 +25,86 @@ import org.robolectric.shadows.ShadowLog;
|
||||
|
||||
@Implements(Slog.class)
|
||||
public class ShadowSlog {
|
||||
@Implementation
|
||||
public static int v(String tag, String msg) {
|
||||
return Log.v(tag, msg);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int v(String tag, String msg, Throwable tr) {
|
||||
return Log.v(tag, msg, tr);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int d(String tag, String msg) {
|
||||
return Log.d(tag, msg);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int d(String tag, String msg, Throwable tr) {
|
||||
return Log.d(tag, msg, tr);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int i(String tag, String msg) {
|
||||
return Log.i(tag, msg);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int i(String tag, String msg, Throwable tr) {
|
||||
return Log.i(tag, msg, tr);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int w(String tag, String msg) {
|
||||
return Log.w(tag, msg);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int w(String tag, String msg, Throwable tr) {
|
||||
return Log.w(tag, msg, tr);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int w(String tag, Throwable tr) {
|
||||
return Log.w(tag, tr);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int e(String tag, String msg) {
|
||||
return Log.e(tag, msg);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int e(String tag, String msg, Throwable tr) {
|
||||
return Log.e(tag, msg, tr);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int wtf(String tag, String msg) {
|
||||
return Log.wtf(tag, msg);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static void wtfQuiet(String tag, String msg) {
|
||||
Log.wtf(tag, msg);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int wtfStack(String tag, String msg) {
|
||||
return Log.wtf(tag, msg);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int wtf(String tag, Throwable tr) {
|
||||
return Log.wtf(tag, tr);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int wtf(String tag, String msg, Throwable tr) {
|
||||
return Log.wtf(tag, msg, tr);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int println(int priority, String tag, String msg) {
|
||||
return Log.println(priority, tag, msg);
|
||||
|
||||
Reference in New Issue
Block a user