Index: unclean_shutdown_collector.cc |
diff --git a/unclean_shutdown_collector.cc b/unclean_shutdown_collector.cc |
index bb2dd7a862ee50597868cf5ecfbf8cab6caa2dbe..1e1c7842a66de998c5f8c6fab50a6dc485b143c2 100644 |
--- a/unclean_shutdown_collector.cc |
+++ b/unclean_shutdown_collector.cc |
@@ -11,8 +11,18 @@ |
static const char kUncleanShutdownFile[] = |
"/var/lib/crash_reporter/pending_clean_shutdown"; |
+// Files created by power manager used for crash reporting. |
+static const char kPowerdTracePath[] = "/var/lib/power_manager"; |
+// Presence of this file indicates that the system was suspended |
+static const char kPowerdSuspended[] = "powerd_suspended"; |
+// Presence of this file indicates that the battery was critically low. |
+static const char kPowerdLowBattery[] = "powerd_low_battery"; |
+ |
UncleanShutdownCollector::UncleanShutdownCollector() |
- : unclean_shutdown_file_(kUncleanShutdownFile) { |
+ : unclean_shutdown_file_(kUncleanShutdownFile), |
+ powerd_trace_path_(kPowerdTracePath), |
+ powerd_suspended_file_(powerd_trace_path_.Append(kPowerdSuspended)), |
+ powerd_low_battery_file_(powerd_trace_path_.Append(kPowerdLowBattery)) { |
} |
UncleanShutdownCollector::~UncleanShutdownCollector() { |
@@ -28,12 +38,15 @@ bool UncleanShutdownCollector::Enable() { |
return true; |
} |
-bool UncleanShutdownCollector::DeleteUncleanShutdownFile() { |
+bool UncleanShutdownCollector::DeleteUncleanShutdownFiles() { |
if (!file_util::Delete(FilePath(unclean_shutdown_file_), false)) { |
logger_->LogError("Failed to delete unclean shutdown file %s", |
unclean_shutdown_file_); |
return false; |
} |
+ // Delete power manager trace files if they exist. |
+ file_util::Delete(powerd_suspended_file_, false); |
+ file_util::Delete(powerd_low_battery_file_, false); |
return true; |
} |
@@ -43,7 +56,11 @@ bool UncleanShutdownCollector::Collect() { |
return false; |
} |
logger_->LogWarning("Last shutdown was not clean"); |
- DeleteUncleanShutdownFile(); |
+ if (DeadBatteryCausedUncleanShutdown()) { |
+ DeleteUncleanShutdownFiles(); |
+ return false; |
+ } |
+ DeleteUncleanShutdownFiles(); |
if (is_feedback_allowed_function_()) { |
count_crash_function_(); |
@@ -53,5 +70,24 @@ bool UncleanShutdownCollector::Collect() { |
bool UncleanShutdownCollector::Disable() { |
logger_->LogInfo("Clean shutdown signalled"); |
- return DeleteUncleanShutdownFile(); |
+ return DeleteUncleanShutdownFiles(); |
+} |
+ |
+bool UncleanShutdownCollector::DeadBatteryCausedUncleanShutdown() |
+{ |
+ // Check for case of battery running out while suspended. |
+ if (file_util::PathExists(powerd_suspended_file_)) { |
+ logger_->LogInfo("Unclean shutdown occurred while suspended. Not counting " |
+ "toward unclean shutdown statistic."); |
+ return true; |
+ } |
+ // Check for case of battery running out after resuming from a low-battery |
+ // suspend. |
+ if (file_util::PathExists(powerd_low_battery_file_)) { |
+ logger_->LogInfo("Unclean shutdown occurred while running with battery " |
+ "critically low. Not counting toward unclean shutdown " |
+ "statistic."); |
+ return true; |
+ } |
+ return false; |
} |