blob: 3f782e9102413a15f44b238898637fe8eed5c273 [file] [log] [blame]
Christopher Wiley16daa082015-10-01 17:18:40 -07001//
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 Dahlina93cd532016-01-14 16:55:11 -080017#ifndef UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_
18#define UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_
Christopher Wiley16daa082015-10-01 17:18:40 -070019
20#include <cstdint>
21#include <memory>
22#include <string>
Casey Dahlina715f7b2016-01-29 16:38:51 -080023#include <vector>
Christopher Wiley16daa082015-10-01 17:18:40 -070024
25#include <base/macros.h>
Amin Hassani3bab1772019-06-21 14:58:25 -070026#include <dlcservice/proto_bindings/dlcservice.pb.h>
Amin Hassanieb463ee2019-06-20 19:23:03 -070027#include <update_engine/proto_bindings/update_engine.pb.h>
Christopher Wiley16daa082015-10-01 17:18:40 -070028
Christopher Wiley16daa082015-10-01 17:18:40 -070029#include "update_engine/client_library/include/update_engine/client.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080030#include "update_engine/dbus-proxies.h"
Christopher Wiley16daa082015-10-01 17:18:40 -070031
32namespace update_engine {
33namespace internal {
34
Casey Dahlina93cd532016-01-14 16:55:11 -080035class DBusUpdateEngineClient : public UpdateEngineClient {
Christopher Wiley16daa082015-10-01 17:18:40 -070036 public:
Casey Dahlina93cd532016-01-14 16:55:11 -080037 DBusUpdateEngineClient() = default;
Casey Dahlin19441412016-01-07 14:56:40 -080038 bool Init();
39
Casey Dahlina93cd532016-01-14 16:55:11 -080040 virtual ~DBusUpdateEngineClient() = default;
Christopher Wiley16daa082015-10-01 17:18:40 -070041
42 bool AttemptUpdate(const std::string& app_version,
43 const std::string& omaha_url,
44 bool at_user_request) override;
45
Xiaochu Liu88d90382018-08-29 16:09:11 -070046 bool AttemptInstall(const std::string& omaha_url,
Xiaochu Liuf53a5d32018-11-26 13:48:59 -080047 const std::vector<std::string>& dlc_module_ids) override;
Xiaochu Liu88d90382018-08-29 16:09:11 -070048
Christopher Wiley16daa082015-10-01 17:18:40 -070049 bool GetStatus(int64_t* out_last_checked_time,
50 double* out_progress,
51 UpdateStatus* out_update_status,
52 std::string* out_new_version,
Casey Dahlin19441412016-01-07 14:56:40 -080053 int64_t* out_new_size) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070054
Amin Hassanieb463ee2019-06-20 19:23:03 -070055 bool GetStatus(UpdateEngineStatus* out_status) const override;
56
Alex Deymod63fab32016-10-06 15:40:49 -070057 bool SetCohortHint(const std::string& cohort_hint) override;
58 bool GetCohortHint(std::string* cohort_hint) const override;
59
Casey Dahlinef361132015-12-17 13:02:37 -080060 bool SetUpdateOverCellularPermission(bool allowed) override;
Casey Dahlin19441412016-01-07 14:56:40 -080061 bool GetUpdateOverCellularPermission(bool* allowed) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080062
63 bool SetP2PUpdatePermission(bool enabled) override;
Casey Dahlin19441412016-01-07 14:56:40 -080064 bool GetP2PUpdatePermission(bool* enabled) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080065
66 bool Rollback(bool powerwash) override;
67
Casey Dahlin19441412016-01-07 14:56:40 -080068 bool GetRollbackPartition(std::string* rollback_partition) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080069
70 void RebootIfNeeded() override;
71
Casey Dahlin19441412016-01-07 14:56:40 -080072 bool GetPrevVersion(std::string* prev_version) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080073
Casey Dahline844c1a2015-12-16 14:30:58 -080074 bool ResetStatus() override;
75
Casey Dahlin87ab88e2015-12-16 17:58:05 -080076 bool SetTargetChannel(const std::string& target_channel,
77 bool allow_powerwash) override;
Christopher Wiley16daa082015-10-01 17:18:40 -070078
Casey Dahlin19441412016-01-07 14:56:40 -080079 bool GetTargetChannel(std::string* out_channel) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070080
Casey Dahlin19441412016-01-07 14:56:40 -080081 bool GetChannel(std::string* out_channel) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070082
Casey Dahlin40892492016-01-25 16:55:28 -080083 bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
Casey Dahlina715f7b2016-01-29 16:38:51 -080084 bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
Casey Dahlin97c87052016-01-06 14:33:55 -080085
Shuqian Zhao29971732016-02-05 11:29:32 -080086 bool GetLastAttemptError(int32_t* last_attempt_error) const override;
87
Jae Hoon Kim893cae42019-08-16 17:13:49 -070088 bool GetEolStatus(int32_t* eol_status,
89 int32_t* milestones_to_eol) const override;
Alex Deymob3fa53b2016-04-18 19:57:58 -070090
Christopher Wiley16daa082015-10-01 17:18:40 -070091 private:
Alex Deymo492eaf52016-02-02 12:05:02 -080092 void DBusStatusHandlersRegistered(const std::string& interface,
Casey Dahlina715f7b2016-01-29 16:38:51 -080093 const std::string& signal_name,
94 bool success) const;
Casey Dahlin97c87052016-01-06 14:33:55 -080095
Casey Dahlina715f7b2016-01-29 16:38:51 -080096 // 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 Hassanieb463ee2019-06-20 19:23:03 -0700101 void RunStatusUpdateHandlers(const StatusResult& status);
Casey Dahlina715f7b2016-01-29 16:38:51 -0800102
Alex Deymo492eaf52016-02-02 12:05:02 -0800103 std::unique_ptr<org::chromium::UpdateEngineInterfaceProxy> proxy_;
Casey Dahlina715f7b2016-01-29 16:38:51 -0800104 std::vector<update_engine::StatusUpdateHandler*> handlers_;
Alex Deymo492eaf52016-02-02 12:05:02 -0800105 bool dbus_handler_registered_{false};
Casey Dahlin97c87052016-01-06 14:33:55 -0800106
Casey Dahlina93cd532016-01-14 16:55:11 -0800107 DISALLOW_COPY_AND_ASSIGN(DBusUpdateEngineClient);
108}; // class DBusUpdateEngineClient
Christopher Wiley16daa082015-10-01 17:18:40 -0700109
110} // namespace internal
111} // namespace update_engine
112
Casey Dahlina93cd532016-01-14 16:55:11 -0800113#endif // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_