Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 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 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_ |
| 18 | #define UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_ |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 19 | |
| 20 | #include <cstdint> |
| 21 | #include <memory> |
| 22 | #include <string> |
Casey Dahlin | a715f7b | 2016-01-29 16:38:51 -0800 | [diff] [blame] | 23 | #include <vector> |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 24 | |
| 25 | #include <base/macros.h> |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 26 | #include <dlcservice/proto_bindings/dlcservice.pb.h> |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 27 | #include <update_engine/proto_bindings/update_engine.pb.h> |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 28 | |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 29 | #include "update_engine/client_library/include/update_engine/client.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 30 | #include "update_engine/dbus-proxies.h" |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 31 | |
| 32 | namespace update_engine { |
| 33 | namespace internal { |
| 34 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 35 | class DBusUpdateEngineClient : public UpdateEngineClient { |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 36 | public: |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 37 | DBusUpdateEngineClient() = default; |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 38 | bool Init(); |
| 39 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 40 | virtual ~DBusUpdateEngineClient() = default; |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 41 | |
| 42 | bool AttemptUpdate(const std::string& app_version, |
| 43 | const std::string& omaha_url, |
| 44 | bool at_user_request) override; |
| 45 | |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 46 | bool AttemptInstall(const std::string& omaha_url, |
Xiaochu Liu | f53a5d3 | 2018-11-26 13:48:59 -0800 | [diff] [blame] | 47 | const std::vector<std::string>& dlc_module_ids) override; |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 48 | |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 49 | bool GetStatus(int64_t* out_last_checked_time, |
| 50 | double* out_progress, |
| 51 | UpdateStatus* out_update_status, |
| 52 | std::string* out_new_version, |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 53 | int64_t* out_new_size) const override; |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 54 | |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 55 | bool GetStatus(UpdateEngineStatus* out_status) const override; |
| 56 | |
Alex Deymo | d63fab3 | 2016-10-06 15:40:49 -0700 | [diff] [blame] | 57 | bool SetCohortHint(const std::string& cohort_hint) override; |
| 58 | bool GetCohortHint(std::string* cohort_hint) const override; |
| 59 | |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 60 | bool SetUpdateOverCellularPermission(bool allowed) override; |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 61 | bool GetUpdateOverCellularPermission(bool* allowed) const override; |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 62 | |
| 63 | bool SetP2PUpdatePermission(bool enabled) override; |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 64 | bool GetP2PUpdatePermission(bool* enabled) const override; |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 65 | |
| 66 | bool Rollback(bool powerwash) override; |
| 67 | |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 68 | bool GetRollbackPartition(std::string* rollback_partition) const override; |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 69 | |
| 70 | void RebootIfNeeded() override; |
| 71 | |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 72 | bool GetPrevVersion(std::string* prev_version) const override; |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 73 | |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 74 | bool ResetStatus() override; |
| 75 | |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 76 | bool SetTargetChannel(const std::string& target_channel, |
| 77 | bool allow_powerwash) override; |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 78 | |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 79 | bool GetTargetChannel(std::string* out_channel) const override; |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 80 | |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 81 | bool GetChannel(std::string* out_channel) const override; |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 82 | |
Casey Dahlin | 4089249 | 2016-01-25 16:55:28 -0800 | [diff] [blame] | 83 | bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override; |
Casey Dahlin | a715f7b | 2016-01-29 16:38:51 -0800 | [diff] [blame] | 84 | bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override; |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 85 | |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 86 | bool GetLastAttemptError(int32_t* last_attempt_error) const override; |
| 87 | |
Jae Hoon Kim | 893cae4 | 2019-08-16 17:13:49 -0700 | [diff] [blame] | 88 | bool GetEolStatus(int32_t* eol_status, |
| 89 | int32_t* milestones_to_eol) const override; |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 90 | |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 91 | private: |
Alex Deymo | 492eaf5 | 2016-02-02 12:05:02 -0800 | [diff] [blame] | 92 | void DBusStatusHandlersRegistered(const std::string& interface, |
Casey Dahlin | a715f7b | 2016-01-29 16:38:51 -0800 | [diff] [blame] | 93 | const std::string& signal_name, |
| 94 | bool success) const; |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 95 | |
Casey Dahlin | a715f7b | 2016-01-29 16:38:51 -0800 | [diff] [blame] | 96 | // Send an initial event to new StatusUpdateHandlers. If the handler argument |
| 97 | // is not nullptr, only that handler receives the event. Otherwise all |
| 98 | // registered handlers receive the event. |
| 99 | void StatusUpdateHandlersRegistered(StatusUpdateHandler* handler) const; |
| 100 | |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 101 | void RunStatusUpdateHandlers(const StatusResult& status); |
Casey Dahlin | a715f7b | 2016-01-29 16:38:51 -0800 | [diff] [blame] | 102 | |
Alex Deymo | 492eaf5 | 2016-02-02 12:05:02 -0800 | [diff] [blame] | 103 | std::unique_ptr<org::chromium::UpdateEngineInterfaceProxy> proxy_; |
Casey Dahlin | a715f7b | 2016-01-29 16:38:51 -0800 | [diff] [blame] | 104 | std::vector<update_engine::StatusUpdateHandler*> handlers_; |
Alex Deymo | 492eaf5 | 2016-02-02 12:05:02 -0800 | [diff] [blame] | 105 | bool dbus_handler_registered_{false}; |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 106 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 107 | DISALLOW_COPY_AND_ASSIGN(DBusUpdateEngineClient); |
| 108 | }; // class DBusUpdateEngineClient |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 109 | |
| 110 | } // namespace internal |
| 111 | } // namespace update_engine |
| 112 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 113 | #endif // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_ |