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