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