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

Commit baec1d5c authored by Louis Chang's avatar Louis Chang
Browse files

Avoid configuration not updated after reasonable configuration changes

Considering the sequence has wrapped around if the sequence number has
a significant large jump. Obviously the original value (0x10000) is not
big enough nowadays.

Also taking the negative jump into account, where the wrap around may
happen on the `other` configuration.

Bug: 239371596
Test: ConfigurationTest
Change-Id: I8ac5ee8c1589b68e63e8e29f961c7fcba719949e
parent f4c8dd05
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -1974,10 +1974,10 @@ public final class Configuration implements Parcelable, Comparable<Configuration
            return true;
            return true;
        }
        }
        int diff = other.seq - seq;
        int diff = other.seq - seq;
        if (diff > 0x10000) {
        if (Math.abs(diff) > 0x10000000) {
            // If there has been a sufficiently large jump, assume the
            // If there has been a sufficiently large jump, assume the
            // sequence has wrapped around.
            // sequence has wrapped around.
            return false;
            return diff < 0;
        }
        }
        return diff > 0;
        return diff > 0;
    }
    }
+16 −0
Original line number Original line Diff line number Diff line
@@ -157,6 +157,22 @@ public class ConfigurationTest extends TestCase {
        assertFalse(config.isNightModeActive());
        assertFalse(config.isNightModeActive());
    }
    }


    @Test
    public void testSequenceNumberWrapAround() {
        Configuration config = new Configuration();
        Configuration otherConfig = new Configuration();

        // Verify the other configuration is not newer when this sequence number warp around.
        config.seq = 1000;
        otherConfig.seq = Integer.MAX_VALUE - 1000;
        assertFalse(config.isOtherSeqNewer(otherConfig));

        // Verify the other configuration is newer when the other sequence number warp around.
        config.seq = Integer.MAX_VALUE - 1000;
        otherConfig.seq = 1000;
        assertTrue(config.isOtherSeqNewer(otherConfig));
    }

    private void dumpDebug(File f, Configuration config) throws Exception {
    private void dumpDebug(File f, Configuration config) throws Exception {
        final AtomicFile af = new AtomicFile(f);
        final AtomicFile af = new AtomicFile(f);
        FileOutputStream fos = af.startWrite();
        FileOutputStream fos = af.startWrite();