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

Commit 1a36783c authored by Eric Biggers's avatar Eric Biggers
Browse files

PolicyVersionUpgrader: fix ERROR + stacktrace on first boot

On first boot it is expected that the device_policies_version file
doesn't exist yet, so properly handle this case.

Bug: 280155081
Test: Booted Cuttlefish and verified that logcat no longer contains
      "DevicePolicyManager: Error reading version" and the stacktrace,
      but does contain "DevicePolicyManager: Upgrading from version 0"
Change-Id: Ib0322997848fd86734a9e1e660a60274cfc8f15e
Merged-In: Ib0322997848fd86734a9e1e660a60274cfc8f15e
(cherry picked from commit a4e08889)
parent 6c8fb011
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
import java.util.List;

@@ -251,6 +252,8 @@ public class PolicyVersionUpgrader {
            String versionString = Files.readAllLines(
                    file.toPath(), Charset.defaultCharset()).get(0);
            return Integer.parseInt(versionString);
        } catch (NoSuchFileException e) {
            return 0; // expected on first boot
        } catch (IOException | NumberFormatException | IndexOutOfBoundsException e) {
            Slog.e(LOG_TAG, "Error reading version", e);
            return 0;