blob: 2c176c557ad955603623d133dcaef98f1a6b92c9 [file] [log] [blame]
Casey Dahlina93cd532016-01-14 16:55:11 -08001//
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
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#ifndef UPDATE_ENGINE_CROS_SERVICE_H_
18#define UPDATE_ENGINE_CROS_SERVICE_H_
Casey Dahlina93cd532016-01-14 16:55:11 -080019
20#include <inttypes.h>
21
22#include <string>
Xiaochu Liu88d90382018-08-29 16:09:11 -070023#include <vector>
Casey Dahlina93cd532016-01-14 16:55:11 -080024
25#include <base/memory/ref_counted.h>
26#include <brillo/errors/error.h>
27
Aaron Wood7f92e2b2017-08-28 14:51:21 -070028#include "update_engine/client_library/include/update_engine/update_status.h"
Casey Dahlina93cd532016-01-14 16:55:11 -080029
30namespace chromeos_update_engine {
31
32class UpdateEngineService {
33 public:
Casey Dahlina93cd532016-01-14 16:55:11 -080034 // Error domain for all the service errors.
35 static const char* const kErrorDomain;
36
37 // Generic service error.
38 static const char* const kErrorFailed;
39
Amin Hassani538bd592020-11-04 20:46:08 -080040 UpdateEngineService();
Casey Dahlina93cd532016-01-14 16:55:11 -080041 virtual ~UpdateEngineService() = default;
42
Aaron Woodbf5a2522017-10-04 10:58:36 -070043 // Set flags that influence how updates and checks are performed. These
44 // influence all future checks and updates until changed or the device
45 // reboots. The |in_flags_as_int| values are a union of values from
46 // |UpdateAttemptFlags|
47 bool SetUpdateAttemptFlags(brillo::ErrorPtr* error, int32_t in_flags_as_int);
48
Casey Dahlina93cd532016-01-14 16:55:11 -080049 bool AttemptUpdate(brillo::ErrorPtr* error,
50 const std::string& in_app_version,
51 const std::string& in_omaha_url,
Aaron Wood081c0232017-10-19 17:14:58 -070052 int32_t in_flags_as_int,
53 bool* out_result);
Casey Dahlina93cd532016-01-14 16:55:11 -080054
Xiaochu Liuf53a5d32018-11-26 13:48:59 -080055 // Attempts a DLC module install operation.
Xiaochu Liu88d90382018-08-29 16:09:11 -070056 // |omaha_url|: the URL to query for update.
Amin Hassani2b68e6b2020-04-17 10:49:12 -070057 // |dlc_ids|: a list of DLC module IDs.
Xiaochu Liu88d90382018-08-29 16:09:11 -070058 bool AttemptInstall(brillo::ErrorPtr* error,
59 const std::string& omaha_url,
Amin Hassani2b68e6b2020-04-17 10:49:12 -070060 const std::vector<std::string>& dlc_ids);
Xiaochu Liu88d90382018-08-29 16:09:11 -070061
Casey Dahlina93cd532016-01-14 16:55:11 -080062 bool AttemptRollback(brillo::ErrorPtr* error, bool in_powerwash);
63
64 // Checks if the system rollback is available by verifying if the secondary
65 // system partition is valid and bootable.
66 bool CanRollback(brillo::ErrorPtr* error, bool* out_can_rollback);
67
68 // Resets the status of the update_engine to idle, ignoring any applied
69 // update. This is used for development only.
70 bool ResetStatus(brillo::ErrorPtr* error);
71
Andrewa8d7df32020-03-15 20:10:01 -070072 // Sets the DLC as active or inactive. When set to active, the ping metadata
73 // for the DLC is updated accordingly. When set to inactive, the metadata
74 // for the DLC is deleted.
75 bool SetDlcActiveValue(brillo::ErrorPtr* error,
76 bool is_active,
77 const std::string& dlc_id);
78
Casey Dahlina93cd532016-01-14 16:55:11 -080079 // Returns the current status of the Update Engine. If an update is in
80 // progress, the number of operations, size to download and overall progress
81 // is reported.
82 bool GetStatus(brillo::ErrorPtr* error,
Aaron Wood7f92e2b2017-08-28 14:51:21 -070083 update_engine::UpdateEngineStatus* out_status);
Casey Dahlina93cd532016-01-14 16:55:11 -080084
85 // Reboots the device if an update is applied and a reboot is required.
86 bool RebootIfNeeded(brillo::ErrorPtr* error);
87
88 // Changes the current channel of the device to the target channel. If the
89 // target channel is a less stable channel than the current channel, then the
90 // channel change happens immediately (at the next update check). If the
91 // target channel is a more stable channel, then if is_powerwash_allowed is
92 // set to true, then also the change happens immediately but with a powerwash
93 // if required. Otherwise, the change takes effect eventually (when the
94 // version on the target channel goes above the version number of what the
95 // device currently has).
96 bool SetChannel(brillo::ErrorPtr* error,
97 const std::string& in_target_channel,
98 bool in_is_powerwash_allowed);
99
100 // If get_current_channel is set to true, populates |channel| with the name of
101 // the channel that the device is currently on. Otherwise, it populates it
102 // with the name of the channel the device is supposed to be (in case of a
103 // pending channel change).
104 bool GetChannel(brillo::ErrorPtr* error,
105 bool in_get_current_channel,
106 std::string* out_channel);
107
Alex Deymo5b5fa8b2016-10-06 15:40:49 -0700108 // Sets the current "cohort hint" value to |in_cohort_hint|. The cohort hint
109 // is sent back to Omaha on every request and can be used as a hint of what
110 // cohort should we be put on.
Andrew9d5a61d2020-03-26 13:40:37 -0700111 bool SetCohortHint(brillo::ErrorPtr* error,
112 const std::string& in_cohort_hint);
Alex Deymo5b5fa8b2016-10-06 15:40:49 -0700113
114 // Return the current cohort hint. This value can be set with SetCohortHint()
115 // and can also be updated from Omaha on every update check request.
116 bool GetCohortHint(brillo::ErrorPtr* error, std::string* out_cohort_hint);
117
Casey Dahlina93cd532016-01-14 16:55:11 -0800118 // Enables or disables the sharing and consuming updates over P2P feature
119 // according to the |enabled| argument passed.
120 bool SetP2PUpdatePermission(brillo::ErrorPtr* error, bool in_enabled);
121
122 // Returns the current value for the P2P enabled setting. This involves both
123 // sharing and consuming updates over P2P.
124 bool GetP2PUpdatePermission(brillo::ErrorPtr* error, bool* out_enabled);
125
126 // If there's no device policy installed, sets the update over cellular
127 // networks permission to the |allowed| value. Otherwise, this method returns
128 // with an error since this setting is overridden by the applied policy.
129 bool SetUpdateOverCellularPermission(brillo::ErrorPtr* error,
130 bool in_allowed);
131
Weidong Guo421ff332017-04-17 10:08:38 -0700132 // If there's no device policy installed, sets the update over cellular
133 // target. Otherwise, this method returns with an error.
134 bool SetUpdateOverCellularTarget(brillo::ErrorPtr* error,
135 const std::string& target_version,
136 int64_t target_size);
137
Casey Dahlina93cd532016-01-14 16:55:11 -0800138 // Returns the current value of the update over cellular network setting,
139 // either forced by the device policy if the device is enrolled or the current
140 // user preference otherwise.
141 bool GetUpdateOverCellularPermission(brillo::ErrorPtr* error,
142 bool* out_allowed);
143
144 // Returns the duration since the last successful update, as the
145 // duration on the wallclock. Returns an error if the device has not
146 // updated.
147 bool GetDurationSinceUpdate(brillo::ErrorPtr* error,
148 int64_t* out_usec_wallclock);
149
150 // Returns the version string of OS that was used before the last reboot
151 // into an updated version. This is available only when rebooting into an
152 // update from previous version, otherwise an empty string is returned.
153 bool GetPrevVersion(brillo::ErrorPtr* error, std::string* out_prev_version);
154
155 // Returns the name of kernel partition that can be rolled back into.
156 bool GetRollbackPartition(brillo::ErrorPtr* error,
157 std::string* out_rollback_partition_name);
158
Shuqian Zhao29971732016-02-05 11:29:32 -0800159 // Returns the last UpdateAttempt error.
160 bool GetLastAttemptError(brillo::ErrorPtr* error,
161 int32_t* out_last_attempt_error);
Casey Dahlina93cd532016-01-14 16:55:11 -0800162};
163
164} // namespace chromeos_update_engine
165
Amin Hassaniec7bc112020-10-29 16:47:58 -0700166#endif // UPDATE_ENGINE_CROS_SERVICE_H_