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

Commit eea4ca82 authored by Hyundo Moon's avatar Hyundo Moon Committed by Gerrit Code Review
Browse files

Merge "Fix failing ContentProfileErrorReportUtilsTest" into main

parents 17dc63b2 2b2d81cf
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -34,9 +34,6 @@ public class ContentProfileErrorReportUtils {
    /* Minimum period between two error reports */
    @VisibleForTesting static final long MIN_PERIOD_BETWEEN_TWO_ERROR_REPORTS_MILLIS = 1_000;

    /* Whether reporting is enabled by flags */
    @VisibleForTesting static boolean sEnabled = Flags.contentProfilesErrorsMetrics();

    @VisibleForTesting static long sLastReportTime = 0;

    /**
@@ -52,10 +49,11 @@ public class ContentProfileErrorReportUtils {
     *     BluetoothStatsLog#BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__LOG_WARN}
     * @param tag A tag which represents the code location of this error. The values are managed per
     *     each java file.
     * @return true if successfully wrote the error, false otherwise
     */
    public static synchronized void report(int profile, int fileNameEnum, int type, int tag) {
        if (!sEnabled) {
            return;
    public static synchronized boolean report(int profile, int fileNameEnum, int type, int tag) {
        if (!Flags.contentProfilesErrorsMetrics()) {
            return false;
        }

        if (isTooFrequentReport()) {
@@ -66,7 +64,7 @@ public class ContentProfileErrorReportUtils {
                            + fileNameEnum
                            + ", tag="
                            + tag);
            return;
            return false;
        }

        BluetoothStatsLog.write(
@@ -76,6 +74,7 @@ public class ContentProfileErrorReportUtils {
                type,
                tag);
        sLastReportTime = SystemClock.uptimeMillis();
        return true;
    }

    private static boolean isTooFrequentReport() {
+3 −6
Original line number Diff line number Diff line
@@ -40,8 +40,7 @@ public class ContentProfileErrorReportUtilsTest {
        mSetFlagsRule.disableFlags(Flags.FLAG_CONTENT_PROFILES_ERRORS_METRICS);
        long previousReportTimeMillis = ContentProfileErrorReportUtils.sLastReportTime;

        ContentProfileErrorReportUtils.report(0, 0, 0, 0);

        assertThat(ContentProfileErrorReportUtils.report(0, 0, 0, 0)).isFalse();
        // The last report time should not be changed.
        assertThat(ContentProfileErrorReportUtils.sLastReportTime)
                .isEqualTo(previousReportTimeMillis);
@@ -54,8 +53,7 @@ public class ContentProfileErrorReportUtilsTest {
        long lastReportTimeMillisToSet = SystemClock.uptimeMillis();
        ContentProfileErrorReportUtils.sLastReportTime = lastReportTimeMillisToSet;

        ContentProfileErrorReportUtils.report(0, 0, 0, 0);

        assertThat(ContentProfileErrorReportUtils.report(0, 0, 0, 0)).isFalse();
        // The last report time should not be changed.
        assertThat(ContentProfileErrorReportUtils.sLastReportTime)
                .isEqualTo(lastReportTimeMillisToSet);
@@ -72,8 +70,7 @@ public class ContentProfileErrorReportUtilsTest {
                                * 2);
        ContentProfileErrorReportUtils.sLastReportTime = lastReportTimeMillisToSet;

        ContentProfileErrorReportUtils.report(0, 0, 0, 0);

        assertThat(ContentProfileErrorReportUtils.report(0, 0, 0, 0)).isTrue();
        // After the successful report, the last report time should be changed.
        assertThat(ContentProfileErrorReportUtils.sLastReportTime)
                .isGreaterThan(lastReportTimeMillisToSet);