update_status_utils.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Copyright (C) 2015 The Android Open Source Project
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #include "update_engine/update_status_utils.h"
  17. #include <base/logging.h>
  18. #include <update_engine/dbus-constants.h>
  19. using update_engine::UpdateStatus;
  20. namespace chromeos_update_engine {
  21. const char* UpdateStatusToString(const UpdateStatus& status) {
  22. switch (status) {
  23. case UpdateStatus::IDLE:
  24. return update_engine::kUpdateStatusIdle;
  25. case UpdateStatus::CHECKING_FOR_UPDATE:
  26. return update_engine::kUpdateStatusCheckingForUpdate;
  27. case UpdateStatus::UPDATE_AVAILABLE:
  28. return update_engine::kUpdateStatusUpdateAvailable;
  29. case UpdateStatus::NEED_PERMISSION_TO_UPDATE:
  30. return update_engine::kUpdateStatusNeedPermissionToUpdate;
  31. case UpdateStatus::DOWNLOADING:
  32. return update_engine::kUpdateStatusDownloading;
  33. case UpdateStatus::VERIFYING:
  34. return update_engine::kUpdateStatusVerifying;
  35. case UpdateStatus::FINALIZING:
  36. return update_engine::kUpdateStatusFinalizing;
  37. case UpdateStatus::UPDATED_NEED_REBOOT:
  38. return update_engine::kUpdateStatusUpdatedNeedReboot;
  39. case UpdateStatus::REPORTING_ERROR_EVENT:
  40. return update_engine::kUpdateStatusReportingErrorEvent;
  41. case UpdateStatus::ATTEMPTING_ROLLBACK:
  42. return update_engine::kUpdateStatusAttemptingRollback;
  43. case UpdateStatus::DISABLED:
  44. return update_engine::kUpdateStatusDisabled;
  45. }
  46. NOTREACHED();
  47. return nullptr;
  48. }
  49. bool StringToUpdateStatus(const std::string& s, UpdateStatus* status) {
  50. if (s == update_engine::kUpdateStatusIdle) {
  51. *status = UpdateStatus::IDLE;
  52. return true;
  53. } else if (s == update_engine::kUpdateStatusCheckingForUpdate) {
  54. *status = UpdateStatus::CHECKING_FOR_UPDATE;
  55. return true;
  56. } else if (s == update_engine::kUpdateStatusUpdateAvailable) {
  57. *status = UpdateStatus::UPDATE_AVAILABLE;
  58. return true;
  59. } else if (s == update_engine::kUpdateStatusNeedPermissionToUpdate) {
  60. *status = UpdateStatus::NEED_PERMISSION_TO_UPDATE;
  61. return true;
  62. } else if (s == update_engine::kUpdateStatusDownloading) {
  63. *status = UpdateStatus::DOWNLOADING;
  64. return true;
  65. } else if (s == update_engine::kUpdateStatusVerifying) {
  66. *status = UpdateStatus::VERIFYING;
  67. return true;
  68. } else if (s == update_engine::kUpdateStatusFinalizing) {
  69. *status = UpdateStatus::FINALIZING;
  70. return true;
  71. } else if (s == update_engine::kUpdateStatusUpdatedNeedReboot) {
  72. *status = UpdateStatus::UPDATED_NEED_REBOOT;
  73. return true;
  74. } else if (s == update_engine::kUpdateStatusReportingErrorEvent) {
  75. *status = UpdateStatus::REPORTING_ERROR_EVENT;
  76. return true;
  77. } else if (s == update_engine::kUpdateStatusAttemptingRollback) {
  78. *status = UpdateStatus::ATTEMPTING_ROLLBACK;
  79. return true;
  80. } else if (s == update_engine::kUpdateStatusDisabled) {
  81. *status = UpdateStatus::DISABLED;
  82. return true;
  83. }
  84. return false;
  85. }
  86. } // namespace chromeos_update_engine