common_service.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // Copyright (C) 2016 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. #ifndef UPDATE_ENGINE_COMMON_SERVICE_H_
  17. #define UPDATE_ENGINE_COMMON_SERVICE_H_
  18. #include <inttypes.h>
  19. #include <string>
  20. #include <vector>
  21. #include <base/memory/ref_counted.h>
  22. #include <brillo/errors/error.h>
  23. #include "update_engine/client_library/include/update_engine/update_status.h"
  24. #include "update_engine/system_state.h"
  25. namespace chromeos_update_engine {
  26. class UpdateEngineService {
  27. public:
  28. // Error domain for all the service errors.
  29. static const char* const kErrorDomain;
  30. // Generic service error.
  31. static const char* const kErrorFailed;
  32. explicit UpdateEngineService(SystemState* system_state);
  33. virtual ~UpdateEngineService() = default;
  34. // Set flags that influence how updates and checks are performed. These
  35. // influence all future checks and updates until changed or the device
  36. // reboots. The |in_flags_as_int| values are a union of values from
  37. // |UpdateAttemptFlags|
  38. bool SetUpdateAttemptFlags(brillo::ErrorPtr* error, int32_t in_flags_as_int);
  39. bool AttemptUpdate(brillo::ErrorPtr* error,
  40. const std::string& in_app_version,
  41. const std::string& in_omaha_url,
  42. int32_t in_flags_as_int,
  43. bool* out_result);
  44. // Attempts a DLC module install operation.
  45. // |omaha_url|: the URL to query for update.
  46. // |dlc_module_ids|: a list of DLC module IDs.
  47. bool AttemptInstall(brillo::ErrorPtr* error,
  48. const std::string& omaha_url,
  49. const std::vector<std::string>& dlc_module_ids);
  50. bool AttemptRollback(brillo::ErrorPtr* error, bool in_powerwash);
  51. // Checks if the system rollback is available by verifying if the secondary
  52. // system partition is valid and bootable.
  53. bool CanRollback(brillo::ErrorPtr* error, bool* out_can_rollback);
  54. // Resets the status of the update_engine to idle, ignoring any applied
  55. // update. This is used for development only.
  56. bool ResetStatus(brillo::ErrorPtr* error);
  57. // Returns the current status of the Update Engine. If an update is in
  58. // progress, the number of operations, size to download and overall progress
  59. // is reported.
  60. bool GetStatus(brillo::ErrorPtr* error,
  61. update_engine::UpdateEngineStatus* out_status);
  62. // Reboots the device if an update is applied and a reboot is required.
  63. bool RebootIfNeeded(brillo::ErrorPtr* error);
  64. // Changes the current channel of the device to the target channel. If the
  65. // target channel is a less stable channel than the current channel, then the
  66. // channel change happens immediately (at the next update check). If the
  67. // target channel is a more stable channel, then if is_powerwash_allowed is
  68. // set to true, then also the change happens immediately but with a powerwash
  69. // if required. Otherwise, the change takes effect eventually (when the
  70. // version on the target channel goes above the version number of what the
  71. // device currently has).
  72. bool SetChannel(brillo::ErrorPtr* error,
  73. const std::string& in_target_channel,
  74. bool in_is_powerwash_allowed);
  75. // If get_current_channel is set to true, populates |channel| with the name of
  76. // the channel that the device is currently on. Otherwise, it populates it
  77. // with the name of the channel the device is supposed to be (in case of a
  78. // pending channel change).
  79. bool GetChannel(brillo::ErrorPtr* error,
  80. bool in_get_current_channel,
  81. std::string* out_channel);
  82. // Sets the current "cohort hint" value to |in_cohort_hint|. The cohort hint
  83. // is sent back to Omaha on every request and can be used as a hint of what
  84. // cohort should we be put on.
  85. bool SetCohortHint(brillo::ErrorPtr* error, std::string in_cohort_hint);
  86. // Return the current cohort hint. This value can be set with SetCohortHint()
  87. // and can also be updated from Omaha on every update check request.
  88. bool GetCohortHint(brillo::ErrorPtr* error, std::string* out_cohort_hint);
  89. // Enables or disables the sharing and consuming updates over P2P feature
  90. // according to the |enabled| argument passed.
  91. bool SetP2PUpdatePermission(brillo::ErrorPtr* error, bool in_enabled);
  92. // Returns the current value for the P2P enabled setting. This involves both
  93. // sharing and consuming updates over P2P.
  94. bool GetP2PUpdatePermission(brillo::ErrorPtr* error, bool* out_enabled);
  95. // If there's no device policy installed, sets the update over cellular
  96. // networks permission to the |allowed| value. Otherwise, this method returns
  97. // with an error since this setting is overridden by the applied policy.
  98. bool SetUpdateOverCellularPermission(brillo::ErrorPtr* error,
  99. bool in_allowed);
  100. // If there's no device policy installed, sets the update over cellular
  101. // target. Otherwise, this method returns with an error.
  102. bool SetUpdateOverCellularTarget(brillo::ErrorPtr* error,
  103. const std::string& target_version,
  104. int64_t target_size);
  105. // Returns the current value of the update over cellular network setting,
  106. // either forced by the device policy if the device is enrolled or the current
  107. // user preference otherwise.
  108. bool GetUpdateOverCellularPermission(brillo::ErrorPtr* error,
  109. bool* out_allowed);
  110. // Returns the duration since the last successful update, as the
  111. // duration on the wallclock. Returns an error if the device has not
  112. // updated.
  113. bool GetDurationSinceUpdate(brillo::ErrorPtr* error,
  114. int64_t* out_usec_wallclock);
  115. // Returns the version string of OS that was used before the last reboot
  116. // into an updated version. This is available only when rebooting into an
  117. // update from previous version, otherwise an empty string is returned.
  118. bool GetPrevVersion(brillo::ErrorPtr* error, std::string* out_prev_version);
  119. // Returns the name of kernel partition that can be rolled back into.
  120. bool GetRollbackPartition(brillo::ErrorPtr* error,
  121. std::string* out_rollback_partition_name);
  122. // Returns the last UpdateAttempt error.
  123. bool GetLastAttemptError(brillo::ErrorPtr* error,
  124. int32_t* out_last_attempt_error);
  125. // Returns the current end-of-life status of the device. This value is updated
  126. // on every update check and persisted on disk across reboots.
  127. bool GetEolStatus(brillo::ErrorPtr* error, int32_t* out_eol_status);
  128. private:
  129. SystemState* system_state_;
  130. };
  131. } // namespace chromeos_update_engine
  132. #endif // UPDATE_ENGINE_COMMON_SERVICE_H_