1cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley//
2cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley// Copyright (C) 2015 The Android Open Source Project
3cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley//
4cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley// Licensed under the Apache License, Version 2.0 (the "License");
5cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley// you may not use this file except in compliance with the License.
6cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley// You may obtain a copy of the License at
7cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley//
8cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley//      http://www.apache.org/licenses/LICENSE-2.0
9cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley//
10cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley// Unless required by applicable law or agreed to in writing, software
11cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley// distributed under the License is distributed on an "AS IS" BASIS,
12cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley// See the License for the specific language governing permissions and
14cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley// limitations under the License.
15cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley//
16cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley#include "update_engine/update_status_utils.h"
17cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley
18cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley#include <base/logging.h>
19cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley#include <update_engine/dbus-constants.h>
20cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley
21cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wileyusing update_engine::UpdateStatus;
22cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley
23cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wileynamespace chromeos_update_engine {
24cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley
25cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wileyconst char* UpdateStatusToString(const UpdateStatus& status) {
26cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley  switch (status) {
27cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley    case UpdateStatus::IDLE:
28cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley      return update_engine::kUpdateStatusIdle;
29cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley    case UpdateStatus::CHECKING_FOR_UPDATE:
30cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley      return update_engine::kUpdateStatusCheckingForUpdate;
31cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley    case UpdateStatus::UPDATE_AVAILABLE:
32cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley      return update_engine::kUpdateStatusUpdateAvailable;
33cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley    case UpdateStatus::DOWNLOADING:
34cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley      return update_engine::kUpdateStatusDownloading;
35cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley    case UpdateStatus::VERIFYING:
36cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley      return update_engine::kUpdateStatusVerifying;
37cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley    case UpdateStatus::FINALIZING:
38cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley      return update_engine::kUpdateStatusFinalizing;
39cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley    case UpdateStatus::UPDATED_NEED_REBOOT:
40cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley      return update_engine::kUpdateStatusUpdatedNeedReboot;
41cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley    case UpdateStatus::REPORTING_ERROR_EVENT:
42cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley      return update_engine::kUpdateStatusReportingErrorEvent;
43cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley    case UpdateStatus::ATTEMPTING_ROLLBACK:
44cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley      return update_engine::kUpdateStatusAttemptingRollback;
45cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley    case UpdateStatus::DISABLED:
46cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley      return update_engine::kUpdateStatusDisabled;
47cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley  }
48cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley
49cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley  NOTREACHED();
50cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley  return nullptr;
51cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley}
52cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley
533f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wileybool StringToUpdateStatus(const std::string& s,
543f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley                          UpdateStatus* status) {
553f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  if (s == update_engine::kUpdateStatusIdle) {
563f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    *status = UpdateStatus::IDLE;
573f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    return true;
583f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  } else if (s == update_engine::kUpdateStatusCheckingForUpdate) {
593f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    *status = UpdateStatus::CHECKING_FOR_UPDATE;
603f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    return true;
613f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  } else if (s == update_engine::kUpdateStatusUpdateAvailable) {
623f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    *status = UpdateStatus::UPDATE_AVAILABLE;
633f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    return true;
643f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  } else if (s == update_engine::kUpdateStatusDownloading) {
653f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    *status = UpdateStatus::DOWNLOADING;
663f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    return true;
673f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  } else if (s == update_engine::kUpdateStatusVerifying) {
683f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    *status = UpdateStatus::VERIFYING;
693f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    return true;
703f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  } else if (s == update_engine::kUpdateStatusFinalizing) {
713f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    *status = UpdateStatus::FINALIZING;
723f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    return true;
733f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  } else if (s == update_engine::kUpdateStatusUpdatedNeedReboot) {
743f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    *status = UpdateStatus::UPDATED_NEED_REBOOT;
753f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    return true;
763f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  } else if (s == update_engine::kUpdateStatusReportingErrorEvent) {
773f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    *status = UpdateStatus::REPORTING_ERROR_EVENT;
783f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    return true;
793f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  } else if (s == update_engine::kUpdateStatusAttemptingRollback) {
803f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    *status = UpdateStatus::ATTEMPTING_ROLLBACK;
813f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    return true;
823f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  } else if (s == update_engine::kUpdateStatusDisabled) {
833f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    *status = UpdateStatus::DISABLED;
843f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley    return true;
853f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  }
863f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley  return false;
873f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley}
883f97b5d26350ae4e3029c148189e88b15805bf25Christopher Wiley
89cc8ce0e3b11ac76412c26c687d11140cbe18ad91Christopher Wiley}  // namespace chromeos_update_engine
90