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

Commit 6c50d5ae authored by Ethan Lee's avatar Ethan Lee Committed by Brian Egizi
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.

Cherry picked I9d1b97c9ff0791d1ac49d333cd75656432ccabe2 to master due to b/286408867.

Code was merged via `-s ours` and is missing even though the sha exists on the target branch. Cherry pick is required to bring in the code.

Manually remove the "Merged in" directive to allow for downstream propagation.

Test: atest CpuInfoReaderTest
Fixes: 284537086
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:fe20e634351512d9be270830d4fc66345ddfe6b4)
Change-Id: Ifc5f1614fc4c70e3d0e5ee753d9ba1ac2ab48417
parent 23e806a8
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