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

Commit cad924cf authored by Bernardo Rufino's avatar Bernardo Rufino
Browse files

Set KV MORE_DEBUG to false and add tests

Forgot this one in the CL. Also added tests to catch this in presubmit.

Test: atest FrameworksServicesRoboTests
Test: adb shell bmgr backupnow <kv_package> and verify no MORE_DEBUG
      logs

Change-Id: I14affca28609bcd855e13fdcc160994c71ed9695
parent 81e43032
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ import java.util.List;
public class KeyValueBackupReporter {
    @VisibleForTesting static final String TAG = "KeyValueBackupTask";
    private static final boolean DEBUG = BackupManagerService.DEBUG;
    @VisibleForTesting static final boolean MORE_DEBUG = BackupManagerService.MORE_DEBUG || true;
    @VisibleForTesting static final boolean MORE_DEBUG = BackupManagerService.MORE_DEBUG || false;

    static void onNewThread(String threadName) {
        if (DEBUG) {
+7 −0
Original line number Diff line number Diff line
@@ -122,6 +122,13 @@ public class BackupManagerServiceTest {
        ShadowAppBackupUtils.reset();
    }

    @Test
    public void testMoreDebug_isFalse() throws Exception {
        boolean moreDebug = BackupManagerService.MORE_DEBUG;

        assertThat(moreDebug).isFalse();
    }

    /* Tests for destination string */

    @Test
+7 −35
Original line number Diff line number Diff line
@@ -61,6 +61,13 @@ public class KeyValueBackupReporterTest {
        mReporter = new KeyValueBackupReporter(mBackupManagerService, mObserver, mMonitor);
    }

    @Test
    public void testMoreDebug_isFalse() throws Exception {
        boolean moreDebug = KeyValueBackupReporter.MORE_DEBUG;

        assertThat(moreDebug).isFalse();
    }

    @Test
    public void testOnNewThread_logsCorrectly() throws Exception {
        KeyValueBackupReporter.onNewThread("foo");
@@ -81,39 +88,4 @@ public class KeyValueBackupReporterTest {

        assertThat(observer).isEqualTo(mObserver);
    }

    @Test
    public void testOnRevertTask_logsCorrectly() throws Exception {
        setMoreDebug(true);

        mReporter.onRevertTask();

        assertLogcat(TAG, Log.INFO);
    }

    @Test
    public void testOnRemoteCallReturned_logsCorrectly() throws Exception {
        setMoreDebug(true);

        mReporter.onRemoteCallReturned(RemoteResult.of(3), "onFoo()");

        assertLogcat(TAG, Log.VERBOSE);
        ShadowLog.LogItem log = ShadowLog.getLogsForTag(TAG).get(0);
        assertThat(log.msg).contains("onFoo()");
        assertThat(log.msg).contains("3");
    }

    /**
     * HACK: We actually want {@link KeyValueBackupReporter#MORE_DEBUG} to be a constant to be able
     * to strip those lines at build time. So, we have to do this to test :(
     */
    private static void setMoreDebug(boolean value)
            throws NoSuchFieldException, IllegalAccessException {
        if (KeyValueBackupReporter.MORE_DEBUG == value) {
            return;
        }
        Field moreDebugField = KeyValueBackupReporter.class.getDeclaredField("MORE_DEBUG");
        moreDebugField.setAccessible(true);
        moreDebugField.set(null, value);
    }
}