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

Commit badc6f24 authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Disable Flags Logging] Fix CollapsedStatusBarFragmentLogger to log

new+newAfterLocalModification instead of old+new.

The paramaters passed into CollapsedStatusBarFragmentLogger were the
newly received disable flags and the disable flags after they've been
locally modified by CollapsedSBFragment. However, it was being logged as
the previously received flags and then the newly received flags. This CL
fixes that.

Old string: "Old: enaihbcrso.qingr | New: eNaIhbCrsO.qingr (NICO.)"

New string: "New: enaihbcrso.qingr | New after local modification: eNaIhbCrsO.qingr (NICO.)"

Test: dumped buffer and verified output
Test: atest DisableFlagsLoggerTest
Bug: 197851207
Change-Id: Ifc36b1b6b85f5cfc08c2dff5078ed63f73899e9c
parent cec06948
Loading
Loading
Loading
Loading
+13 −7
Original line number Original line Diff line number Diff line
@@ -85,24 +85,30 @@ class DisableFlagsLogger constructor(
     * is no difference. the new-after-modification state also won't be included if there's no
     * is no difference. the new-after-modification state also won't be included if there's no
     * difference from the new state.
     * difference from the new state.
     *
     *
     * @param old the disable state that had been previously sent.
     * @param old the disable state that had been previously sent. Null if we don't need to log the
     *   previously sent state.
     * @param new the new disable state that has just been sent.
     * @param new the new disable state that has just been sent.
     * @param newAfterLocalModification the new disable states after a class has locally modified
     * @param newAfterLocalModification the new disable states after a class has locally modified
     *   them. Null if the class does not locally modify.
     *   them. Null if the class does not locally modify.
     */
     */
    fun getDisableFlagsString(
    fun getDisableFlagsString(
        old: DisableState,
        old: DisableState? = null,
        new: DisableState,
        new: DisableState,
        newAfterLocalModification: DisableState? = null
        newAfterLocalModification: DisableState? = null
    ): String {
    ): String {
        val builder = StringBuilder("Received new disable state. ")
        val builder = StringBuilder("Received new disable state. ")

        old?.let {
            builder.append("Old: ")
            builder.append("Old: ")
            builder.append(getFlagsString(old))
            builder.append(getFlagsString(old))
        builder.append(" | New: ")
            builder.append(" | ")
        if (old != new) {
        }

        builder.append("New: ")
        if (old != null && old != new) {
            builder.append(getFlagsStringWithDiff(old, new))
            builder.append(getFlagsStringWithDiff(old, new))
        } else {
        } else {
            builder.append(getFlagsString(old))
            builder.append(getFlagsString(new))
        }
        }


        if (newAfterLocalModification != null && new != newAfterLocalModification) {
        if (newAfterLocalModification != null && new != newAfterLocalModification) {
+2 −2
Original line number Original line Diff line number Diff line
@@ -253,8 +253,8 @@ public class CollapsedStatusBarFragment extends Fragment implements CommandQueue
        state1 = adjustDisableFlags(state1);
        state1 = adjustDisableFlags(state1);


        mCollapsedStatusBarFragmentLogger.logDisableFlagChange(
        mCollapsedStatusBarFragmentLogger.logDisableFlagChange(
                new DisableState(state1BeforeAdjustment, state2),
                /* new= */ new DisableState(state1BeforeAdjustment, state2),
                new DisableState(state1, state2));
                /* newAfterLocalModification= */ new DisableState(state1, state2));


        final int old1 = mDisabled1;
        final int old1 = mDisabled1;
        final int diff1 = state1 ^ old1;
        final int diff1 = state1 ^ old1;
+17 −8
Original line number Original line Diff line number Diff line
@@ -28,22 +28,31 @@ class CollapsedStatusBarFragmentLogger @Inject constructor(
        private val disableFlagsLogger: DisableFlagsLogger,
        private val disableFlagsLogger: DisableFlagsLogger,
) {
) {


    /** Logs a string representing the old and new disable flag states to [buffer]. */
    /**
     * Logs a string representing the new state received by [CollapsedStatusBarFragment] and any
     * modifications that were made to the flags locally.
     *
     * @param new see [DisableFlagsLogger.getDisableFlagsString]
     * @param newAfterLocalModification see [DisableFlagsLogger.getDisableFlagsString]
     */
    fun logDisableFlagChange(
    fun logDisableFlagChange(
            oldState: DisableFlagsLogger.DisableState,
        new: DisableFlagsLogger.DisableState,
            newState: DisableFlagsLogger.DisableState) {
        newAfterLocalModification: DisableFlagsLogger.DisableState
    ) {
        buffer.log(
        buffer.log(
                TAG,
                TAG,
                LogLevel.INFO,
                LogLevel.INFO,
                {
                {
                    int1 = oldState.disable1
                    int1 = new.disable1
                    int2 = oldState.disable2
                    int2 = new.disable2
                    long1 = newState.disable1.toLong()
                    long1 = newAfterLocalModification.disable1.toLong()
                    long2 = newState.disable2.toLong()
                    long2 = newAfterLocalModification.disable2.toLong()
                },
                },
                {
                {
                    disableFlagsLogger.getDisableFlagsString(
                    disableFlagsLogger.getDisableFlagsString(
                            DisableFlagsLogger.DisableState(int1, int2),
                        old = null,
                        new = DisableFlagsLogger.DisableState(int1, int2),
                        newAfterLocalModification =
                            DisableFlagsLogger.DisableState(long1.toInt(), long2.toInt())
                            DisableFlagsLogger.DisableState(long1.toInt(), long2.toInt())
                    )
                    )
                }
                }
+17 −0
Original line number Original line Diff line number Diff line
@@ -85,6 +85,23 @@ class DisableFlagsLoggerTest : SysuiTestCase() {
        assertThat(result).contains("(.n)")
        assertThat(result).contains("(.n)")
    }
    }


    @Test
    fun getDisableFlagsString_nullOld_onlyNewStateLogged() {
        val result = disableFlagsLogger.getDisableFlagsString(
            old = null,
            new = DisableFlagsLogger.DisableState(
                0b001, // abC
                0b01, // mN
            ),
        )

        assertThat(result).doesNotContain("Old")
        assertThat(result).contains("New: abC.mN")
        // We have no state to diff on, so we shouldn't see any diff in parentheses
        assertThat(result).doesNotContain("(")
        assertThat(result).doesNotContain(")")
    }

    @Test
    @Test
    fun getDisableFlagsString_nullLocalModification_localModNotLogged() {
    fun getDisableFlagsString_nullLocalModification_localModNotLogged() {
        val result = disableFlagsLogger.getDisableFlagsString(
        val result = disableFlagsLogger.getDisableFlagsString(
+4 −2
Original line number Original line Diff line number Diff line
@@ -40,7 +40,7 @@ class CollapsedStatusBarFragmentLoggerTest : SysuiTestCase() {
    private val logger = CollapsedStatusBarFragmentLogger(buffer, disableFlagsLogger)
    private val logger = CollapsedStatusBarFragmentLogger(buffer, disableFlagsLogger)


    @Test
    @Test
    fun logToBuffer_bufferHasStates() {
    fun logDisableFlagChange_bufferHasStates() {
        val state = DisableFlagsLogger.DisableState(0, 1)
        val state = DisableFlagsLogger.DisableState(0, 1)


        logger.logDisableFlagChange(state, state)
        logger.logDisableFlagChange(state, state)
@@ -48,7 +48,9 @@ class CollapsedStatusBarFragmentLoggerTest : SysuiTestCase() {
        val stringWriter = StringWriter()
        val stringWriter = StringWriter()
        buffer.dump(PrintWriter(stringWriter), tailLength = 0)
        buffer.dump(PrintWriter(stringWriter), tailLength = 0)
        val actualString = stringWriter.toString()
        val actualString = stringWriter.toString()
        val expectedLogString = disableFlagsLogger.getDisableFlagsString(state, state)
        val expectedLogString = disableFlagsLogger.getDisableFlagsString(
            old = null, new = state, newAfterLocalModification = state
        )


        assertThat(actualString).contains(expectedLogString)
        assertThat(actualString).contains(expectedLogString)
    }
    }