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

Commit fe20e634 authored by Ethan Lee's avatar Ethan Lee
Browse files

Don't throw exception on empty line in CPUs file.

Empty line in CPUs file is a valid use case and the CpuInfoReader must
not throw exception. It should gracefully handle this case.

Test: atest CpuInfoReaderTest
Fixes: 284537086
Change-Id: I9d1b97c9ff0791d1ac49d333cd75656432ccabe2
parent 1731def5
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -593,9 +593,12 @@ public final class CpuInfoReader {
            List<String> lines = Files.readAllLines(file.toPath());
            IntArray cpuCores = new IntArray(0);
            for (int i = 0; i < lines.size(); i++) {
                String line = lines.get(i);
                String[] pairs = line.contains(",") ? line.trim().split(",")
                        : line.trim().split(" ");
                String line = lines.get(i).trim();
                if (line.isEmpty()) {
                    continue;
                }
                String[] pairs = line.contains(",") ? line.split(",")
                        : line.split(" ");
                for (int j = 0; j < pairs.length; j++) {
                    String[] minMaxPairs = pairs[j].split("-");
                    if (minMaxPairs.length >= 2) {
@@ -615,6 +618,9 @@ public final class CpuInfoReader {
                }
            }
            return cpuCores;
        } catch (NumberFormatException e) {
            Slogf.e(TAG, e, "Failed to read CPU cores from %s due to incorrect file format",
                    file.getAbsolutePath());
        } catch (Exception e) {
            Slogf.e(TAG, e, "Failed to read CPU cores from %s", file.getAbsolutePath());
        }
+1 −0
Original line number Diff line number Diff line
+1 −0
Original line number Diff line number Diff line
0
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
1230000
+1 −0
Original line number Diff line number Diff line
2500000
Loading