commit | 9199d0c1ffed3ff3e10c3e20fd7efad10798dc9a | [log] [tgz] |
---|---|---|
author | Michael Wright <michaelwr@google.com> | Wed May 10 21:35:13 2017 +0100 |
committer | Michael Wright <michaelwr@google.com> | Wed May 10 21:38:59 2017 +0100 |
tree | 100792da7bf5c8eb28651e3b9e0365bd69998b04 | |
parent | 47bf1b334a24f719c8ede8145dda4d866c804dac [diff] |
Avoid NPE when getting last shutdown reason. This can be null if there is a file but it's totally empty, and the switch statement will throw an NPE when switching on a null string (thanks Java!) Bug: 38195795 Test: none Change-Id: I86901e001b088a4a9b14f15c82b763e12d11875f
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index 423bc0c..a8d19e9 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -4607,6 +4607,9 @@ } catch (IOException e) { Slog.e(TAG, "Failed to read last_reboot_reason file", e); } + if (line == null) { + return PowerManager.SHUTDOWN_REASON_UNKNOWN; + } switch (line) { case REASON_SHUTDOWN: return PowerManager.SHUTDOWN_REASON_SHUTDOWN;