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

Commit 05d5d5c2 authored by beatricemarch's avatar beatricemarch Committed by Beatrice Marchegiani
Browse files

Overload putMonitoringExtra so that it can take an int as a parameter.

This will allow to correcly store EXTRA_LOG_OPERATION_TYPE

Test: atest BackupManagerMonitorEventSender,
atest CtsBackupHostTestCases, GtsBackupHostTestCases
manual testing (restore to a phone and check that the backup dumpsys contain non-agent events)
Bug: 297163190

Change-Id: I6bea76f31dba66c3ad958212d77be7e00902bb2b
parent 5918648b
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -222,4 +222,21 @@ public class BackupManagerMonitorEventSender {
        extras.putBoolean(key, value);
        return extras;
    }

    /**
     * Adds given key-value pair in the bundle and returns the bundle. If bundle was null it will
     * be created.
     *
     * @param extras - bundle where to add key-value to, if null a new bundle will be created.
     * @param key - key.
     * @param value - value.
     * @return extras if it was not null and new bundle otherwise.
     */
    public static Bundle putMonitoringExtra(Bundle extras, String key, int value) {
        if (extras == null) {
            extras = new Bundle();
        }
        extras.putInt(key, value);
        return extras;
    }
}
+25 −2
Original line number Diff line number Diff line
@@ -340,8 +340,9 @@ public class BackupManagerMonitorEventSenderTest {
    @Test
    public void putMonitoringExtraLong_bundleExists_fillsBundleCorrectly() throws Exception {
        Bundle bundle = new Bundle();
        long value = 123;

        Bundle result = mBackupManagerMonitorEventSender.putMonitoringExtra(bundle, "key", 123);
        Bundle result = mBackupManagerMonitorEventSender.putMonitoringExtra(bundle, "key", value);

        assertThat(result).isEqualTo(bundle);
        assertThat(result.size()).isEqualTo(1);
@@ -350,7 +351,8 @@ public class BackupManagerMonitorEventSenderTest {

    @Test
    public void putMonitoringExtraLong_bundleDoesNotExist_fillsBundleCorrectly() throws Exception {
        Bundle result = mBackupManagerMonitorEventSender.putMonitoringExtra(null, "key", 123);
        long value = 123;
        Bundle result = mBackupManagerMonitorEventSender.putMonitoringExtra(null, "key", value);

        assertThat(result).isNotNull();
        assertThat(result.size()).isEqualTo(1);
@@ -377,4 +379,25 @@ public class BackupManagerMonitorEventSenderTest {
        assertThat(result.size()).isEqualTo(1);
        assertThat(result.getBoolean("key")).isTrue();
    }

    @Test
    public void putMonitoringExtraInt_bundleExists_fillsBundleCorrectly() throws Exception {
        Bundle bundle = new Bundle();

        Bundle result = mBackupManagerMonitorEventSender.putMonitoringExtra(bundle, "key", 1);

        assertThat(result).isEqualTo(bundle);
        assertThat(result.size()).isEqualTo(1);
        assertThat(result.getInt("key")).isEqualTo(1);
    }

    @Test
    public void putMonitoringExtraInt_bundleDoesNotExist_fillsBundleCorrectly()
            throws Exception {
        Bundle result = mBackupManagerMonitorEventSender.putMonitoringExtra(null, "key", 1);

        assertThat(result).isNotNull();
        assertThat(result.size()).isEqualTo(1);
        assertThat(result.getInt("key")).isEqualTo(1);
    }
}