Move UpdateStatus and helpers to dedicated files
This allows us to easily share it between the update_engine proper
and a forthcoming client library.
Bug: 24547247
Test: mmm system/update_engine; emerge-panther update_engine
Change-Id: I8c0db7a0f95dd6368bfc886f1b0d1a9d2efb461f
diff --git a/Android.mk b/Android.mk
index abbae26..5962573 100644
--- a/Android.mk
+++ b/Android.mk
@@ -45,6 +45,7 @@
LOCAL_LDFLAGS += \
-Wl,--gc-sections
LOCAL_C_INCLUDES += \
+ $(LOCAL_PATH)/client_library/include \
external/gtest/include \
system
LOCAL_SHARED_LIBRARIES += \
@@ -177,6 +178,7 @@
update_manager/real_updater_provider.cc \
update_manager/state_factory.cc \
update_manager/update_manager.cc \
+ update_status_utils.cc \
utils.cc \
xz_extent_writer.cc
$(eval $(update_engine_common))
diff --git a/client_library/include/update_engine/update_status.h b/client_library/include/update_engine/update_status.h
new file mode 100644
index 0000000..525249c
--- /dev/null
+++ b/client_library/include/update_engine/update_status.h
@@ -0,0 +1,37 @@
+//
+// Copyright (C) 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_UPDATE_STATUS_H_
+#define CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_UPDATE_STATUS_H_
+
+namespace update_engine {
+
+enum class UpdateStatus {
+ IDLE = 0,
+ CHECKING_FOR_UPDATE,
+ UPDATE_AVAILABLE,
+ DOWNLOADING,
+ VERIFYING,
+ FINALIZING,
+ UPDATED_NEED_REBOOT,
+ REPORTING_ERROR_EVENT,
+ ATTEMPTING_ROLLBACK,
+ DISABLED,
+};
+
+} // namespace update_engine
+
+#endif // CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_UPDATE_STATUS_H_
diff --git a/update_attempter.cc b/update_attempter.cc
index d4e1654..433d112 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -64,6 +64,7 @@
#include "update_engine/system_state.h"
#include "update_engine/update_manager/policy.h"
#include "update_engine/update_manager/update_manager.h"
+#include "update_engine/update_status_utils.h"
#include "update_engine/utils.h"
using base::Bind;
@@ -98,33 +99,6 @@
const char kScheduledAUTestURLRequest[] = "autest-scheduled";
} // namespace
-const char* UpdateStatusToString(UpdateStatus status) {
- switch (status) {
- case UPDATE_STATUS_IDLE:
- return update_engine::kUpdateStatusIdle;
- case UPDATE_STATUS_CHECKING_FOR_UPDATE:
- return update_engine::kUpdateStatusCheckingForUpdate;
- case UPDATE_STATUS_UPDATE_AVAILABLE:
- return update_engine::kUpdateStatusUpdateAvailable;
- case UPDATE_STATUS_DOWNLOADING:
- return update_engine::kUpdateStatusDownloading;
- case UPDATE_STATUS_VERIFYING:
- return update_engine::kUpdateStatusVerifying;
- case UPDATE_STATUS_FINALIZING:
- return update_engine::kUpdateStatusFinalizing;
- case UPDATE_STATUS_UPDATED_NEED_REBOOT:
- return update_engine::kUpdateStatusUpdatedNeedReboot;
- case UPDATE_STATUS_REPORTING_ERROR_EVENT:
- return update_engine::kUpdateStatusReportingErrorEvent;
- case UPDATE_STATUS_ATTEMPTING_ROLLBACK:
- return update_engine::kUpdateStatusAttemptingRollback;
- case UPDATE_STATUS_DISABLED:
- return update_engine::kUpdateStatusDisabled;
- default:
- return "unknown status";
- }
-}
-
// Turns a generic ErrorCode::kError to a generic error code specific
// to |action| (e.g., ErrorCode::kFilesystemVerifierError). If |code| is
// not ErrorCode::kError, or the action is not matched, returns |code|
@@ -166,9 +140,9 @@
debugd_proxy_(debugd_proxy) {
if (!update_completed_marker_.empty() &&
utils::FileExists(update_completed_marker_.c_str())) {
- status_ = UPDATE_STATUS_UPDATED_NEED_REBOOT;
+ status_ = UpdateStatus::UPDATED_NEED_REBOOT;
} else {
- status_ = UPDATE_STATUS_IDLE;
+ status_ = UpdateStatus::IDLE;
}
}
@@ -278,7 +252,7 @@
chrome_proxy_resolver_.Init();
fake_update_success_ = false;
- if (status_ == UPDATE_STATUS_UPDATED_NEED_REBOOT) {
+ if (status_ == UpdateStatus::UPDATED_NEED_REBOOT) {
// Although we have applied an update, we still want to ping Omaha
// to ensure the number of active statistics is accurate.
//
@@ -293,7 +267,7 @@
PingOmaha();
return;
}
- if (status_ != UPDATE_STATUS_IDLE) {
+ if (status_ != UpdateStatus::IDLE) {
// Update in progress. Do nothing
return;
}
@@ -309,7 +283,7 @@
BuildUpdateActions(interactive);
- SetStatusAndNotify(UPDATE_STATUS_CHECKING_FOR_UPDATE);
+ SetStatusAndNotify(UpdateStatus::CHECKING_FOR_UPDATE);
// Update the last check time here; it may be re-updated when an Omaha
// response is received, but this will prevent us from repeatedly scheduling
@@ -751,7 +725,7 @@
// Update the payload state for Rollback.
system_state_->payload_state()->Rollback();
- SetStatusAndNotify(UPDATE_STATUS_ATTEMPTING_ROLLBACK);
+ SetStatusAndNotify(UpdateStatus::ATTEMPTING_ROLLBACK);
// Just in case we didn't update boot flags yet, make sure they're updated
// before any update processing starts. This also schedules the start of the
@@ -764,7 +738,7 @@
bool UpdateAttempter::CanRollback() const {
// We can only rollback if the update_engine isn't busy and we have a valid
// rollback partition.
- return (status_ == UPDATE_STATUS_IDLE &&
+ return (status_ == UpdateStatus::IDLE &&
GetRollbackSlot() != BootControlInterface::kInvalidSlot);
}
@@ -829,7 +803,7 @@
}
bool UpdateAttempter::RebootIfNeeded() {
- if (status_ != UPDATE_STATUS_UPDATED_NEED_REBOOT) {
+ if (status_ != UpdateStatus::UPDATED_NEED_REBOOT) {
LOG(INFO) << "Reboot requested, but status is "
<< UpdateStatusToString(status_) << ", so not rebooting.";
return false;
@@ -890,8 +864,8 @@
// actually notice one on subsequent calls. Note that we don't need to
// re-schedule a check in this case as updates are permanently disabled;
// further (forced) checks may still initiate a scheduling call.
- SetStatusAndNotify(UPDATE_STATUS_DISABLED);
- SetStatusAndNotify(UPDATE_STATUS_IDLE);
+ SetStatusAndNotify(UpdateStatus::DISABLED);
+ SetStatusAndNotify(UpdateStatus::IDLE);
return;
}
@@ -937,11 +911,11 @@
// Reset cpu shares back to normal.
CleanupCpuSharesManagement();
- if (status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) {
+ if (status_ == UpdateStatus::REPORTING_ERROR_EVENT) {
LOG(INFO) << "Error event sent.";
// Inform scheduler of new status;
- SetStatusAndNotify(UPDATE_STATUS_IDLE);
+ SetStatusAndNotify(UpdateStatus::IDLE);
ScheduleUpdates();
if (!fake_update_success_) {
@@ -973,7 +947,7 @@
system_state_->payload_state()->SetScatteringWaitPeriod(TimeDelta());
prefs_->Delete(kPrefsUpdateFirstSeenAt);
- SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT);
+ SetStatusAndNotify(UpdateStatus::UPDATED_NEED_REBOOT);
ScheduleUpdates();
LOG(INFO) << "Update successfully applied, waiting to reboot.";
@@ -1006,7 +980,7 @@
return;
}
LOG(INFO) << "No update.";
- SetStatusAndNotify(UPDATE_STATUS_IDLE);
+ SetStatusAndNotify(UpdateStatus::IDLE);
ScheduleUpdates();
}
@@ -1014,7 +988,7 @@
// Reset cpu shares back to normal.
CleanupCpuSharesManagement();
download_progress_ = 0.0;
- SetStatusAndNotify(UPDATE_STATUS_IDLE);
+ SetStatusAndNotify(UpdateStatus::IDLE);
ScheduleUpdates();
actions_.clear();
error_event_.reset(nullptr);
@@ -1058,7 +1032,7 @@
// If the current state is at or past the download phase, count the failure
// in case a switch to full update becomes necessary. Ignore network
// transfer timeouts and failures.
- if (status_ >= UPDATE_STATUS_DOWNLOADING &&
+ if (status_ >= UpdateStatus::DOWNLOADING &&
code != ErrorCode::kDownloadTransferError) {
MarkDeltaUpdateFailure();
}
@@ -1079,9 +1053,9 @@
new_payload_size_ = plan.payload_size;
SetupDownload();
SetupCpuSharesManagement();
- SetStatusAndNotify(UPDATE_STATUS_UPDATE_AVAILABLE);
+ SetStatusAndNotify(UpdateStatus::UPDATE_AVAILABLE);
} else if (type == DownloadAction::StaticType()) {
- SetStatusAndNotify(UPDATE_STATUS_FINALIZING);
+ SetStatusAndNotify(UpdateStatus::FINALIZING);
}
}
@@ -1100,32 +1074,32 @@
// Self throttle based on progress. Also send notifications if
// progress is too slow.
const double kDeltaPercent = 0.01; // 1%
- if (status_ != UPDATE_STATUS_DOWNLOADING ||
+ if (status_ != UpdateStatus::DOWNLOADING ||
bytes_received == total ||
progress - download_progress_ >= kDeltaPercent ||
TimeTicks::Now() - last_notify_time_ >= TimeDelta::FromSeconds(10)) {
download_progress_ = progress;
- SetStatusAndNotify(UPDATE_STATUS_DOWNLOADING);
+ SetStatusAndNotify(UpdateStatus::DOWNLOADING);
}
}
bool UpdateAttempter::ResetStatus() {
LOG(INFO) << "Attempting to reset state from "
- << UpdateStatusToString(status_) << " to UPDATE_STATUS_IDLE";
+ << UpdateStatusToString(status_) << " to UpdateStatus::IDLE";
switch (status_) {
- case UPDATE_STATUS_IDLE:
+ case UpdateStatus::IDLE:
// no-op.
return true;
- case UPDATE_STATUS_UPDATED_NEED_REBOOT: {
+ case UpdateStatus::UPDATED_NEED_REBOOT: {
bool ret_value = true;
- status_ = UPDATE_STATUS_IDLE;
+ status_ = UpdateStatus::IDLE;
LOG(INFO) << "Reset Successful";
// Remove the reboot marker so that if the machine is rebooted
// after resetting to idle state, it doesn't go back to
- // UPDATE_STATUS_UPDATED_NEED_REBOOT state.
+ // UpdateStatus::UPDATED_NEED_REBOOT state.
if (!update_completed_marker_.empty()) {
if (!base::DeleteFile(base::FilePath(update_completed_marker_), false))
ret_value = false;
@@ -1261,7 +1235,7 @@
// don't schedule another. This shouldn't really happen but just in case...
if ((action->Type() == OmahaResponseHandlerAction::StaticType() &&
code == ErrorCode::kError) ||
- status_ == UPDATE_STATUS_REPORTING_ERROR_EVENT) {
+ status_ == UpdateStatus::REPORTING_ERROR_EVENT) {
return;
}
@@ -1310,7 +1284,7 @@
false));
actions_.push_back(shared_ptr<AbstractAction>(error_event_action));
processor_->EnqueueAction(error_event_action.get());
- SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT);
+ SetStatusAndNotify(UpdateStatus::REPORTING_ERROR_EVENT);
processor_->StartProcessing();
return true;
}
@@ -1439,7 +1413,7 @@
UpdateLastCheckedTime();
// Update the status which will schedule the next update check
- SetStatusAndNotify(UPDATE_STATUS_UPDATED_NEED_REBOOT);
+ SetStatusAndNotify(UpdateStatus::UPDATED_NEED_REBOOT);
ScheduleUpdates();
}
@@ -1574,8 +1548,8 @@
}
bool UpdateAttempter::IsUpdateRunningOrScheduled() {
- return ((status_ != UPDATE_STATUS_IDLE &&
- status_ != UPDATE_STATUS_UPDATED_NEED_REBOOT) ||
+ return ((status_ != UpdateStatus::IDLE &&
+ status_ != UpdateStatus::UPDATED_NEED_REBOOT) ||
waiting_for_scheduled_check_);
}
diff --git a/update_attempter.h b/update_attempter.h
index 06a3dac..a106a2e 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -39,6 +39,7 @@
#include "update_engine/system_state.h"
#include "update_engine/update_manager/policy.h"
#include "update_engine/update_manager/update_manager.h"
+#include "update_engine/update_status.h"
class MetricsLibraryInterface;
@@ -50,24 +51,10 @@
class UpdateEngineAdaptor;
-enum UpdateStatus {
- UPDATE_STATUS_IDLE = 0,
- UPDATE_STATUS_CHECKING_FOR_UPDATE,
- UPDATE_STATUS_UPDATE_AVAILABLE,
- UPDATE_STATUS_DOWNLOADING,
- UPDATE_STATUS_VERIFYING,
- UPDATE_STATUS_FINALIZING,
- UPDATE_STATUS_UPDATED_NEED_REBOOT,
- UPDATE_STATUS_REPORTING_ERROR_EVENT,
- UPDATE_STATUS_ATTEMPTING_ROLLBACK,
- UPDATE_STATUS_DISABLED,
-};
-
-const char* UpdateStatusToString(UpdateStatus status);
-
class UpdateAttempter : public ActionProcessorDelegate,
public DownloadActionDelegate {
public:
+ using UpdateStatus = update_engine::UpdateStatus;
static const int kMaxDeltaUpdateFailures;
UpdateAttempter(SystemState* system_state,
diff --git a/update_engine.gyp b/update_engine.gyp
index 2a1768e..ec32550 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -51,6 +51,7 @@
# We need this include dir because we include all the local code as
# "update_engine/...".
'<(platform2_root)/../aosp/system',
+ '<(platform2_root)/../aosp/system/update_engine/client_library/include',
],
},
'targets': [
@@ -213,6 +214,7 @@
'update_manager/real_updater_provider.cc',
'update_manager/state_factory.cc',
'update_manager/update_manager.cc',
+ 'update_status_utils.cc',
'utils.cc',
'xz_extent_writer.cc',
],
diff --git a/update_status_utils.cc b/update_status_utils.cc
new file mode 100644
index 0000000..c1504fd
--- /dev/null
+++ b/update_status_utils.cc
@@ -0,0 +1,53 @@
+//
+// Copyright (C) 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include "update_engine/update_status_utils.h"
+
+#include <base/logging.h>
+#include <update_engine/dbus-constants.h>
+
+using update_engine::UpdateStatus;
+
+namespace chromeos_update_engine {
+
+const char* UpdateStatusToString(const UpdateStatus& status) {
+ switch (status) {
+ case UpdateStatus::IDLE:
+ return update_engine::kUpdateStatusIdle;
+ case UpdateStatus::CHECKING_FOR_UPDATE:
+ return update_engine::kUpdateStatusCheckingForUpdate;
+ case UpdateStatus::UPDATE_AVAILABLE:
+ return update_engine::kUpdateStatusUpdateAvailable;
+ case UpdateStatus::DOWNLOADING:
+ return update_engine::kUpdateStatusDownloading;
+ case UpdateStatus::VERIFYING:
+ return update_engine::kUpdateStatusVerifying;
+ case UpdateStatus::FINALIZING:
+ return update_engine::kUpdateStatusFinalizing;
+ case UpdateStatus::UPDATED_NEED_REBOOT:
+ return update_engine::kUpdateStatusUpdatedNeedReboot;
+ case UpdateStatus::REPORTING_ERROR_EVENT:
+ return update_engine::kUpdateStatusReportingErrorEvent;
+ case UpdateStatus::ATTEMPTING_ROLLBACK:
+ return update_engine::kUpdateStatusAttemptingRollback;
+ case UpdateStatus::DISABLED:
+ return update_engine::kUpdateStatusDisabled;
+ }
+
+ NOTREACHED();
+ return nullptr;
+}
+
+} // namespace chromeos_update_engine
diff --git a/update_status_utils.h b/update_status_utils.h
new file mode 100644
index 0000000..8a07ebe
--- /dev/null
+++ b/update_status_utils.h
@@ -0,0 +1,28 @@
+//
+// Copyright (C) 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef CLIENT_LIBRARY_UPDATE_STATUS_TO_STRING_H_
+#define CLIENT_LIBRARY_UPDATE_STATUS_TO_STRING_H_
+
+#include "update_engine/update_status.h"
+
+namespace chromeos_update_engine {
+
+const char* UpdateStatusToString(const update_engine::UpdateStatus& status);
+
+} // namespace chromeos_update_engine
+
+#endif // CLIENT_LIBRARY_UPDATE_STATUS_TO_STRING_H_