blob: 7e7fea88d2d2a189590bb6e247344c0b46c26421 [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
17#ifndef UPDATE_ENGINE_COMMON_SERVICE_H_
18#define UPDATE_ENGINE_COMMON_SERVICE_H_
19
20#include <inttypes.h>
21
22#include <string>
23
24#include <base/memory/ref_counted.h>
25#include <brillo/errors/error.h>
26
Aaron Wood7f92e2b2017-08-28 14:51:21 -070027#include "update_engine/client_library/include/update_engine/update_status.h"
Casey Dahlina93cd532016-01-14 16:55:11 -080028#include "update_engine/system_state.h"
29
30namespace chromeos_update_engine {
31
32class UpdateEngineService {
33 public:
34 // Flags used in the AttemptUpdateWithFlags() D-Bus method.
35 typedef enum {
36 kAttemptUpdateFlagNonInteractive = (1<<0)
37 } AttemptUpdateFlags;
38
39 // Error domain for all the service errors.
40 static const char* const kErrorDomain;
41
42 // Generic service error.
43 static const char* const kErrorFailed;
44
45 explicit UpdateEngineService(SystemState* system_state);
46 virtual ~UpdateEngineService() = default;
47
48 bool AttemptUpdate(brillo::ErrorPtr* error,
49 const std::string& in_app_version,
50 const std::string& in_omaha_url,
51 int32_t in_flags_as_int);
52
53 bool AttemptRollback(brillo::ErrorPtr* error, bool in_powerwash);
54
55 // Checks if the system rollback is available by verifying if the secondary
56 // system partition is valid and bootable.
57 bool CanRollback(brillo::ErrorPtr* error, bool* out_can_rollback);
58
59 // Resets the status of the update_engine to idle, ignoring any applied
60 // update. This is used for development only.
61 bool ResetStatus(brillo::ErrorPtr* error);
62
63 // Returns the current status of the Update Engine. If an update is in
64 // progress, the number of operations, size to download and overall progress
65 // is reported.
66 bool GetStatus(brillo::ErrorPtr* error,
Aaron Wood7f92e2b2017-08-28 14:51:21 -070067 update_engine::UpdateEngineStatus* out_status);
Casey Dahlina93cd532016-01-14 16:55:11 -080068
69 // Reboots the device if an update is applied and a reboot is required.
70 bool RebootIfNeeded(brillo::ErrorPtr* error);
71
72 // Changes the current channel of the device to the target channel. If the
73 // target channel is a less stable channel than the current channel, then the
74 // channel change happens immediately (at the next update check). If the
75 // target channel is a more stable channel, then if is_powerwash_allowed is
76 // set to true, then also the change happens immediately but with a powerwash
77 // if required. Otherwise, the change takes effect eventually (when the
78 // version on the target channel goes above the version number of what the
79 // device currently has).
80 bool SetChannel(brillo::ErrorPtr* error,
81 const std::string& in_target_channel,
82 bool in_is_powerwash_allowed);
83
84 // If get_current_channel is set to true, populates |channel| with the name of
85 // the channel that the device is currently on. Otherwise, it populates it
86 // with the name of the channel the device is supposed to be (in case of a
87 // pending channel change).
88 bool GetChannel(brillo::ErrorPtr* error,
89 bool in_get_current_channel,
90 std::string* out_channel);
91
Alex Deymo5b5fa8b2016-10-06 15:40:49 -070092 // Sets the current "cohort hint" value to |in_cohort_hint|. The cohort hint
93 // is sent back to Omaha on every request and can be used as a hint of what
94 // cohort should we be put on.
95 bool SetCohortHint(brillo::ErrorPtr* error, std::string in_cohort_hint);
96
97 // Return the current cohort hint. This value can be set with SetCohortHint()
98 // and can also be updated from Omaha on every update check request.
99 bool GetCohortHint(brillo::ErrorPtr* error, std::string* out_cohort_hint);
100
Casey Dahlina93cd532016-01-14 16:55:11 -0800101 // Enables or disables the sharing and consuming updates over P2P feature
102 // according to the |enabled| argument passed.
103 bool SetP2PUpdatePermission(brillo::ErrorPtr* error, bool in_enabled);
104
105 // Returns the current value for the P2P enabled setting. This involves both
106 // sharing and consuming updates over P2P.
107 bool GetP2PUpdatePermission(brillo::ErrorPtr* error, bool* out_enabled);
108
109 // If there's no device policy installed, sets the update over cellular
110 // networks permission to the |allowed| value. Otherwise, this method returns
111 // with an error since this setting is overridden by the applied policy.
112 bool SetUpdateOverCellularPermission(brillo::ErrorPtr* error,
113 bool in_allowed);
114
115 // Returns the current value of the update over cellular network setting,
116 // either forced by the device policy if the device is enrolled or the current
117 // user preference otherwise.
118 bool GetUpdateOverCellularPermission(brillo::ErrorPtr* error,
119 bool* out_allowed);
120
121 // Returns the duration since the last successful update, as the
122 // duration on the wallclock. Returns an error if the device has not
123 // updated.
124 bool GetDurationSinceUpdate(brillo::ErrorPtr* error,
125 int64_t* out_usec_wallclock);
126
127 // Returns the version string of OS that was used before the last reboot
128 // into an updated version. This is available only when rebooting into an
129 // update from previous version, otherwise an empty string is returned.
130 bool GetPrevVersion(brillo::ErrorPtr* error, std::string* out_prev_version);
131
132 // Returns the name of kernel partition that can be rolled back into.
133 bool GetRollbackPartition(brillo::ErrorPtr* error,
134 std::string* out_rollback_partition_name);
135
Shuqian Zhao29971732016-02-05 11:29:32 -0800136 // Returns the last UpdateAttempt error.
137 bool GetLastAttemptError(brillo::ErrorPtr* error,
138 int32_t* out_last_attempt_error);
139
Alex Deymob3fa53b2016-04-18 19:57:58 -0700140 // Returns the current end-of-life status of the device. This value is updated
141 // on every update check and persisted on disk across reboots.
142 bool GetEolStatus(brillo::ErrorPtr* error, int32_t* out_eol_status);
143
Casey Dahlina93cd532016-01-14 16:55:11 -0800144 private:
145 SystemState* system_state_;
146};
147
148} // namespace chromeos_update_engine
149
150#endif // UPDATE_ENGINE_COMMON_SERVICE_H_