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

Commit 097087fe authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Tweaking the irq pattern regex for wakeup reasons

Fixing to match only at the start of the line, so that invalid reasons
like "adb1 adb2" or negative ids don't get matched.

Also, removing a spurious newline introduced in the previous change.

Test: atest FrameworksServicesTests:CpuWakeupStatsTest

Bug: 195684213
Change-Id: Iab70f1a665a71a846a0bf8c186942f96b7e7ae95
parent 4d4a5ab0
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import java.lang.annotation.RetentionPolicy;
import java.util.Collection;
import java.util.List;


/**
 * Battery stats local system service interface. This is used to pass internal data out of
 * BatteryStatsImpl, as well as make unchecked calls into BatteryStatsImpl.
+2 −2
Original line number Diff line number Diff line
@@ -384,7 +384,7 @@ public class CpuWakeupStats {
    private static final class Wakeup {
        private static final String PARSER_TAG = "CpuWakeupStats.Wakeup";
        private static final String ABORT_REASON_PREFIX = "Abort";
        private static final Pattern sIrqPattern = Pattern.compile("(\\d+)\\s+(\\S+)");
        private static final Pattern sIrqPattern = Pattern.compile("^(\\d+)\\s+(\\S+)");

        String mRawReason;
        long mElapsedMillis;
@@ -409,7 +409,7 @@ public class CpuWakeupStats {
            IrqDevice[] parsedDevices = new IrqDevice[components.length];

            for (String component : components) {
                final Matcher matcher = sIrqPattern.matcher(component);
                final Matcher matcher = sIrqPattern.matcher(component.trim());
                if (matcher.find()) {
                    final int line;
                    final String device;
+30 −2
Original line number Diff line number Diff line
@@ -44,7 +44,9 @@ import java.util.concurrent.ThreadLocalRandom;
public class CpuWakeupStatsTest {
    private static final String KERNEL_REASON_ALARM_IRQ = "120 test.alarm.device";
    private static final String KERNEL_REASON_UNKNOWN_IRQ = "140 test.unknown.device";
    private static final String KERNEL_REASON_UNKNOWN = "unsupported-free-form-reason";
    private static final String KERNEL_REASON_UNKNOWN = "free-form-reason test.alarm.device";
    private static final String KERNEL_REASON_UNSUPPORTED = "-1 test.alarm.device";
    private static final String KERNEL_REASON_ABORT = "Abort: due to test.alarm.device";

    private static final int TEST_UID_1 = 13239823;
    private static final int TEST_UID_2 = 25268423;
@@ -57,6 +59,7 @@ public class CpuWakeupStatsTest {

    @Test
    public void removesOldWakeups() {
        // The xml resource doesn't matter for this test.
        final CpuWakeupStats obj = new CpuWakeupStats(sContext, R.xml.irq_device_map_1);

        final Set<Long> timestamps = new HashSet<>();
@@ -165,11 +168,36 @@ public class CpuWakeupStatsTest {

        obj.noteWakeupTimeAndReason(wakeupTime, 34, KERNEL_REASON_UNKNOWN);

        // Unrelated subsystems, should be ignored.
        // Should be ignored as this type of wakeup is unsupported.
        obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_ALARM, wakeupTime + 5, TEST_UID_3);
        obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_ALARM, wakeupTime - 3, TEST_UID_4);

        // There should be nothing in the attribution map.
        assertThat(obj.mWakeupAttribution.size()).isEqualTo(0);
    }

    @Test
    public void unsupportedAttribution() {
        final CpuWakeupStats obj = new CpuWakeupStats(sContext, R.xml.irq_device_map_3);

        long wakeupTime = 970934;
        obj.noteWakeupTimeAndReason(wakeupTime, 34, KERNEL_REASON_UNSUPPORTED);

        // Should be ignored as this type of wakeup is unsupported.
        obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_ALARM, wakeupTime + 5, TEST_UID_3);
        obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_ALARM, wakeupTime - 3, TEST_UID_4);

        // There should be nothing in the attribution map.
        assertThat(obj.mWakeupAttribution.size()).isEqualTo(0);

        wakeupTime = 883124;
        obj.noteWakeupTimeAndReason(wakeupTime, 3, KERNEL_REASON_ABORT);

        // Should be ignored as this type of wakeup is unsupported.
        obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_ALARM, wakeupTime + 2, TEST_UID_1, TEST_UID_4);
        obj.noteWakingActivity(CPU_WAKEUP_SUBSYSTEM_ALARM, wakeupTime - 5, TEST_UID_3);

        // There should be nothing in the attribution map.
        assertThat(obj.mWakeupAttribution.size()).isEqualTo(0);
    }
}