common_service.h revision 7f92e2b7060cb35719acf96ef96a4e273e165bc5
1a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// 2a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// Copyright (C) 2016 The Android Open Source Project 3a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// 4a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// Licensed under the Apache License, Version 2.0 (the "License"); 5a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// you may not use this file except in compliance with the License. 6a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// You may obtain a copy of the License at 7a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// 8a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// http://www.apache.org/licenses/LICENSE-2.0 9a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// 10a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// Unless required by applicable law or agreed to in writing, software 11a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// distributed under the License is distributed on an "AS IS" BASIS, 12a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// See the License for the specific language governing permissions and 14a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// limitations under the License. 15a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// 16a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 17a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#ifndef UPDATE_ENGINE_COMMON_SERVICE_H_ 18a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#define UPDATE_ENGINE_COMMON_SERVICE_H_ 19a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 20a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#include <inttypes.h> 21a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 22a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#include <string> 23a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 24a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#include <base/memory/ref_counted.h> 25a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#include <brillo/errors/error.h> 26a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 277f92e2b7060cb35719acf96ef96a4e273e165bc5Aaron Wood#include "update_engine/client_library/include/update_engine/update_status.h" 28a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#include "update_engine/system_state.h" 29a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 30a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlinnamespace chromeos_update_engine { 31a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 32a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlinclass UpdateEngineService { 33a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin public: 34a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Flags used in the AttemptUpdateWithFlags() D-Bus method. 35a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin typedef enum { 36a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin kAttemptUpdateFlagNonInteractive = (1<<0) 37a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin } AttemptUpdateFlags; 38a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 39a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Error domain for all the service errors. 40a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin static const char* const kErrorDomain; 41a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 42a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Generic service error. 43a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin static const char* const kErrorFailed; 44a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 45a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin explicit UpdateEngineService(SystemState* system_state); 46a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin virtual ~UpdateEngineService() = default; 47a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 48a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool AttemptUpdate(brillo::ErrorPtr* error, 49a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin const std::string& in_app_version, 50a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin const std::string& in_omaha_url, 51a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin int32_t in_flags_as_int); 52a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 53a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool AttemptRollback(brillo::ErrorPtr* error, bool in_powerwash); 54a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 55a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Checks if the system rollback is available by verifying if the secondary 56a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // system partition is valid and bootable. 57a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool CanRollback(brillo::ErrorPtr* error, bool* out_can_rollback); 58a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 59a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Resets the status of the update_engine to idle, ignoring any applied 60a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // update. This is used for development only. 61a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool ResetStatus(brillo::ErrorPtr* error); 62a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 63a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the current status of the Update Engine. If an update is in 64a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // progress, the number of operations, size to download and overall progress 65a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // is reported. 66a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetStatus(brillo::ErrorPtr* error, 677f92e2b7060cb35719acf96ef96a4e273e165bc5Aaron Wood update_engine::UpdateEngineStatus* out_status); 68a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 69a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Reboots the device if an update is applied and a reboot is required. 70a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool RebootIfNeeded(brillo::ErrorPtr* error); 71a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 72a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Changes the current channel of the device to the target channel. If the 73a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // target channel is a less stable channel than the current channel, then the 74a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // channel change happens immediately (at the next update check). If the 75a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // target channel is a more stable channel, then if is_powerwash_allowed is 76a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // set to true, then also the change happens immediately but with a powerwash 77a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // if required. Otherwise, the change takes effect eventually (when the 78a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // version on the target channel goes above the version number of what the 79a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // device currently has). 80a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool SetChannel(brillo::ErrorPtr* error, 81a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin const std::string& in_target_channel, 82a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool in_is_powerwash_allowed); 83a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 84a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // If get_current_channel is set to true, populates |channel| with the name of 85a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // the channel that the device is currently on. Otherwise, it populates it 86a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // with the name of the channel the device is supposed to be (in case of a 87a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // pending channel change). 88a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetChannel(brillo::ErrorPtr* error, 89a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool in_get_current_channel, 90a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin std::string* out_channel); 91a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 925b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo // Sets the current "cohort hint" value to |in_cohort_hint|. The cohort hint 935b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo // is sent back to Omaha on every request and can be used as a hint of what 945b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo // cohort should we be put on. 955b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo bool SetCohortHint(brillo::ErrorPtr* error, std::string in_cohort_hint); 965b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo 975b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo // Return the current cohort hint. This value can be set with SetCohortHint() 985b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo // and can also be updated from Omaha on every update check request. 995b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo bool GetCohortHint(brillo::ErrorPtr* error, std::string* out_cohort_hint); 1005b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo 101a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Enables or disables the sharing and consuming updates over P2P feature 102a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // according to the |enabled| argument passed. 103a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool SetP2PUpdatePermission(brillo::ErrorPtr* error, bool in_enabled); 104a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 105a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the current value for the P2P enabled setting. This involves both 106a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // sharing and consuming updates over P2P. 107a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetP2PUpdatePermission(brillo::ErrorPtr* error, bool* out_enabled); 108a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 109a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // If there's no device policy installed, sets the update over cellular 110a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // networks permission to the |allowed| value. Otherwise, this method returns 111a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // with an error since this setting is overridden by the applied policy. 112a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool SetUpdateOverCellularPermission(brillo::ErrorPtr* error, 113a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool in_allowed); 114a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 115a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the current value of the update over cellular network setting, 116a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // either forced by the device policy if the device is enrolled or the current 117a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // user preference otherwise. 118a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetUpdateOverCellularPermission(brillo::ErrorPtr* error, 119a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool* out_allowed); 120a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 121a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the duration since the last successful update, as the 122a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // duration on the wallclock. Returns an error if the device has not 123a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // updated. 124a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetDurationSinceUpdate(brillo::ErrorPtr* error, 125a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin int64_t* out_usec_wallclock); 126a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 127a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the version string of OS that was used before the last reboot 128a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // into an updated version. This is available only when rebooting into an 129a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // update from previous version, otherwise an empty string is returned. 130a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetPrevVersion(brillo::ErrorPtr* error, std::string* out_prev_version); 131a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 132a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the name of kernel partition that can be rolled back into. 133a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetRollbackPartition(brillo::ErrorPtr* error, 134a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin std::string* out_rollback_partition_name); 135a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 1362997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao // Returns the last UpdateAttempt error. 1372997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao bool GetLastAttemptError(brillo::ErrorPtr* error, 1382997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao int32_t* out_last_attempt_error); 1392997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao 140b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo // Returns the current end-of-life status of the device. This value is updated 141b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo // on every update check and persisted on disk across reboots. 142b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo bool GetEolStatus(brillo::ErrorPtr* error, int32_t* out_eol_status); 143b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo 144a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin private: 145a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin SystemState* system_state_; 146a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin}; 147a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 148a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin} // namespace chromeos_update_engine 149a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 150a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#endif // UPDATE_ENGINE_COMMON_SERVICE_H_ 151