• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2015 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_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_
18 #define UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_
19 
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "update_engine/status_update_handler.h"
26 #include "update_engine/update_status.h"
27 
28 namespace update_engine {
29 
30 class UpdateEngineClient {
31  public:
32   static std::unique_ptr<UpdateEngineClient> CreateInstance();
33 
34   virtual ~UpdateEngineClient() = default;
35 
36   // Force the update_engine to attempt an update.
37   // |app_version|
38   //     Attempt to update to this version.  An empty string indicates that
39   //     update engine should pick the most recent image on the current channel.
40   // |omaha_url|
41   //     Force update_engine to look for updates from the given server.  Passing
42   //     empty indicates update_engine should get this parameter from its
43   //     config.  Note that update_engine will ignore this parameter in
44   //     production mode to avoid pulling untrusted updates.
45   // |at_user_request|
46   //     This update was directly requested by the user.
47   virtual bool AttemptUpdate(const std::string& app_version,
48                              const std::string& omaha_url,
49                              bool at_user_request) = 0;
50 
51   // Request the update_engine to install a list of DLC modules.
52   // |omaha_url|
53   //     Force update_engine to look for updates from the given server. Passing
54   //     empty indicates update_engine should use its default value. Note that
55   //     update_engine will ignore this parameter in production mode to avoid
56   //     pulling untrusted updates.
57   // |dlc_module_ids|
58   //     A list of DLC module IDs.
59   virtual bool AttemptInstall(
60       const std::string& omaha_url,
61       const std::vector<std::string>& dlc_module_ids) = 0;
62 
63   // Returns the current status of the Update Engine.
64   //
65   // |out_last_checked_time|
66   //     the last time the update engine checked for an update in seconds since
67   //     the epoc.
68   // |out_progress|
69   //     when downloading an update, this is calculated as
70   //     (number of bytes received) / (total bytes).
71   // |out_update_status|
72   //     See update_status.h.
73   // |out_new_version|
74   //     string version of the new system image.
75   // |out_new_size|
76   //     number of bytes in the new system image.
77   virtual bool GetStatus(int64_t* out_last_checked_time,
78                          double* out_progress,
79                          UpdateStatus* out_update_status,
80                          std::string* out_new_version,
81                          int64_t* out_new_size) const = 0;
82 
83   // Getter and setter for the cohort hint.
84   virtual bool SetCohortHint(const std::string& cohort_hint) = 0;
85   virtual bool GetCohortHint(std::string* cohort_hint) const = 0;
86 
87   // Getter and setter for the updates over cellular connections.
88   virtual bool SetUpdateOverCellularPermission(bool allowed) = 0;
89   virtual bool GetUpdateOverCellularPermission(bool* allowed) const = 0;
90 
91   // Getter and setter for the updates from P2P permission.
92   virtual bool SetP2PUpdatePermission(bool enabled) = 0;
93   virtual bool GetP2PUpdatePermission(bool* enabled) const = 0;
94 
95   // Attempt a rollback. Set 'powerwash' to reset the device while rolling
96   // back.
97   virtual bool Rollback(bool powerwash) = 0;
98 
99   // Get the rollback partition if available. Gives empty string if not.
100   virtual bool GetRollbackPartition(std::string* rollback_partition) const = 0;
101 
102   // Reboot the system if needed.
103   virtual void RebootIfNeeded() = 0;
104 
105   // Get the previous version
106   virtual bool GetPrevVersion(std::string* prev_version) const = 0;
107 
108   // Resets the status of the Update Engine
109   virtual bool ResetStatus() = 0;
110 
111   // Changes the current channel of the device to the target channel.
112   virtual bool SetTargetChannel(const std::string& target_channel,
113                                 bool allow_powerwash) = 0;
114 
115   // Get the channel the device will switch to on reboot.
116   virtual bool GetTargetChannel(std::string* out_channel) const = 0;
117 
118   // Get the channel the device is currently on.
119   virtual bool GetChannel(std::string* out_channel) const = 0;
120 
121   // Handle status updates. The handler must exist until the client is
122   // destroyed or UnregisterStatusUpdateHandler is called for it. Its IPCError
123   // method will be called if the handler could not be registered. Otherwise
124   // its HandleStatusUpdate method will be called every time update_engine's
125   // status changes. Will always report the status on registration to prevent
126   // race conditions.
127   virtual bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) = 0;
128 
129   // Unregister a status update handler
130   virtual bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) = 0;
131 
132   // Get the last UpdateAttempt error code.
133   virtual bool GetLastAttemptError(int32_t* last_attempt_error) const = 0;
134 
135   // Get the current end-of-life status code. See EolStatus enum for details.
136   virtual bool GetEolStatus(int32_t* eol_status) const = 0;
137 
138  protected:
139   // Use CreateInstance().
140   UpdateEngineClient() = default;
141 
142  private:
143   UpdateEngineClient(const UpdateEngineClient&) = delete;
144   void operator=(const UpdateEngineClient&) = delete;
145 };  // class UpdateEngineClient
146 
147 }  // namespace update_engine
148 
149 #endif  // UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_
150