client.h revision 2997173235e88c5e4cb13d2844f74afc7b25d6e2
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 updates over cellular connections.
71  virtual bool SetUpdateOverCellularPermission(bool allowed) = 0;
72  virtual bool GetUpdateOverCellularPermission(bool* allowed) const = 0;
73
74  // Getter and setter for the updates from P2P permission.
75  virtual bool SetP2PUpdatePermission(bool enabled) = 0;
76  virtual bool GetP2PUpdatePermission(bool* enabled) const = 0;
77
78  // Attempt a rollback. Set 'powerwash' to reset the device while rolling
79  // back.
80  virtual bool Rollback(bool powerwash) = 0;
81
82  // Get the rollback partition if available. Gives empty string if not.
83  virtual bool GetRollbackPartition(std::string* rollback_partition) const = 0;
84
85  // Reboot the system if needed.
86  virtual void RebootIfNeeded() = 0;
87
88  // Get the previous version
89  virtual bool GetPrevVersion(std::string* prev_version) const = 0;
90
91  // Resets the status of the Update Engine
92  virtual bool ResetStatus() = 0;
93
94  // Changes the current channel of the device to the target channel.
95  virtual bool SetTargetChannel(const std::string& target_channel,
96                                bool allow_powerwash) = 0;
97
98  // Get the channel the device will switch to on reboot.
99  virtual bool GetTargetChannel(std::string* out_channel) const = 0;
100
101  // Get the channel the device is currently on.
102  virtual bool GetChannel(std::string* out_channel) const = 0;
103
104  // Handle status updates. The handler must exist until the client is
105  // destroyed or UnregisterStatusUpdateHandler is called for it. Its IPCError
106  // method will be called if the handler could not be registered. Otherwise
107  // its HandleStatusUpdate method will be called every time update_engine's
108  // status changes. Will always report the status on registration to prevent
109  // race conditions.
110  virtual bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) = 0;
111
112  // Unregister a status update handler
113  virtual bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) = 0;
114
115  // Get the last UpdateAttempt error code.
116  virtual bool GetLastAttemptError(int32_t* last_attempt_error) const = 0;
117
118 protected:
119  // Use CreateInstance().
120  UpdateEngineClient() = default;
121
122 private:
123  UpdateEngineClient(const UpdateEngineClient&) = delete;
124  void operator=(const UpdateEngineClient&) = delete;
125};  // class UpdateEngineClient
126
127}  // namespace update_engine
128
129#endif  // UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_
130