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 // Error domain for all the service errors. 35a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin static const char* const kErrorDomain; 36a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 37a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Generic service error. 38a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin static const char* const kErrorFailed; 39a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 40a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin explicit UpdateEngineService(SystemState* system_state); 41a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin virtual ~UpdateEngineService() = default; 42a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 43224dfc23caf524ef5e3661010c694781e2d9d819Aaron Wood // Set flags that influence how updates and checks are performed. These 44224dfc23caf524ef5e3661010c694781e2d9d819Aaron Wood // influence all future checks and updates until changed or the device 45224dfc23caf524ef5e3661010c694781e2d9d819Aaron Wood // reboots. The |in_flags_as_int| values are a union of values from 46224dfc23caf524ef5e3661010c694781e2d9d819Aaron Wood // |UpdateAttemptFlags| 47224dfc23caf524ef5e3661010c694781e2d9d819Aaron Wood bool SetUpdateAttemptFlags(brillo::ErrorPtr* error, int32_t in_flags_as_int); 48224dfc23caf524ef5e3661010c694781e2d9d819Aaron Wood 49a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool AttemptUpdate(brillo::ErrorPtr* error, 50a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin const std::string& in_app_version, 51a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin const std::string& in_omaha_url, 523a9c9623f2ffbe256f2d4d8897939f3d48b3cf52Aaron Wood int32_t in_flags_as_int, 533a9c9623f2ffbe256f2d4d8897939f3d48b3cf52Aaron Wood bool* out_result); 54a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 55a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool AttemptRollback(brillo::ErrorPtr* error, bool in_powerwash); 56a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 57a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Checks if the system rollback is available by verifying if the secondary 58a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // system partition is valid and bootable. 59a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool CanRollback(brillo::ErrorPtr* error, bool* out_can_rollback); 60a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 61a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Resets the status of the update_engine to idle, ignoring any applied 62a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // update. This is used for development only. 63a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool ResetStatus(brillo::ErrorPtr* error); 64a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 65a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the current status of the Update Engine. If an update is in 66a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // progress, the number of operations, size to download and overall progress 67a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // is reported. 68a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetStatus(brillo::ErrorPtr* error, 697f92e2b7060cb35719acf96ef96a4e273e165bc5Aaron Wood update_engine::UpdateEngineStatus* out_status); 70a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 71a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Reboots the device if an update is applied and a reboot is required. 72a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool RebootIfNeeded(brillo::ErrorPtr* error); 73a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 74a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Changes the current channel of the device to the target channel. If the 75a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // target channel is a less stable channel than the current channel, then the 76a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // channel change happens immediately (at the next update check). If the 77a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // target channel is a more stable channel, then if is_powerwash_allowed is 78a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // set to true, then also the change happens immediately but with a powerwash 79a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // if required. Otherwise, the change takes effect eventually (when the 80a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // version on the target channel goes above the version number of what the 81a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // device currently has). 82a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool SetChannel(brillo::ErrorPtr* error, 83a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin const std::string& in_target_channel, 84a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool in_is_powerwash_allowed); 85a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 86a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // If get_current_channel is set to true, populates |channel| with the name of 87a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // the channel that the device is currently on. Otherwise, it populates it 88a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // with the name of the channel the device is supposed to be (in case of a 89a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // pending channel change). 90a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetChannel(brillo::ErrorPtr* error, 91a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool in_get_current_channel, 92a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin std::string* out_channel); 93a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 945b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo // Sets the current "cohort hint" value to |in_cohort_hint|. The cohort hint 955b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo // is sent back to Omaha on every request and can be used as a hint of what 965b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo // cohort should we be put on. 975b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo bool SetCohortHint(brillo::ErrorPtr* error, std::string in_cohort_hint); 985b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo 995b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo // Return the current cohort hint. This value can be set with SetCohortHint() 1005b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo // and can also be updated from Omaha on every update check request. 1015b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo bool GetCohortHint(brillo::ErrorPtr* error, std::string* out_cohort_hint); 1025b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo 103a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Enables or disables the sharing and consuming updates over P2P feature 104a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // according to the |enabled| argument passed. 105a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool SetP2PUpdatePermission(brillo::ErrorPtr* error, bool in_enabled); 106a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 107a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the current value for the P2P enabled setting. This involves both 108a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // sharing and consuming updates over P2P. 109a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetP2PUpdatePermission(brillo::ErrorPtr* error, bool* out_enabled); 110a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 111a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // If there's no device policy installed, sets the update over cellular 112a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // networks permission to the |allowed| value. Otherwise, this method returns 113a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // with an error since this setting is overridden by the applied policy. 114a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool SetUpdateOverCellularPermission(brillo::ErrorPtr* error, 115a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool in_allowed); 116a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 117a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the current value of the update over cellular network setting, 118a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // either forced by the device policy if the device is enrolled or the current 119a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // user preference otherwise. 120a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetUpdateOverCellularPermission(brillo::ErrorPtr* error, 121a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool* out_allowed); 122a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 123a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the duration since the last successful update, as the 124a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // duration on the wallclock. Returns an error if the device has not 125a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // updated. 126a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetDurationSinceUpdate(brillo::ErrorPtr* error, 127a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin int64_t* out_usec_wallclock); 128a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 129a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the version string of OS that was used before the last reboot 130a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // into an updated version. This is available only when rebooting into an 131a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // update from previous version, otherwise an empty string is returned. 132a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetPrevVersion(brillo::ErrorPtr* error, std::string* out_prev_version); 133a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 134a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin // Returns the name of kernel partition that can be rolled back into. 135a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin bool GetRollbackPartition(brillo::ErrorPtr* error, 136a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin std::string* out_rollback_partition_name); 137a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 1382997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao // Returns the last UpdateAttempt error. 1392997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao bool GetLastAttemptError(brillo::ErrorPtr* error, 1402997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao int32_t* out_last_attempt_error); 1412997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao 142b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo // Returns the current end-of-life status of the device. This value is updated 143b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo // on every update check and persisted on disk across reboots. 144b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo bool GetEolStatus(brillo::ErrorPtr* error, int32_t* out_eol_status); 145b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo 146a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin private: 147a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin SystemState* system_state_; 148a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin}; 149a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 150a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin} // namespace chromeos_update_engine 151a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin 152a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#endif // UPDATE_ENGINE_COMMON_SERVICE_H_ 153