blob: f19555fccb91fcdfd2464cb70a2c5b754994b149 [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 Hassanieb463ee2019-06-20 19:23:03 -070026#include <update_engine/proto_bindings/update_engine.pb.h>
Christopher Wiley16daa082015-10-01 17:18:40 -070027
Christopher Wiley16daa082015-10-01 17:18:40 -070028#include "update_engine/client_library/include/update_engine/client.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080029#include "update_engine/dbus-proxies.h"
Christopher Wiley16daa082015-10-01 17:18:40 -070030
31namespace update_engine {
32namespace internal {
33
Casey Dahlina93cd532016-01-14 16:55:11 -080034class DBusUpdateEngineClient : public UpdateEngineClient {
Christopher Wiley16daa082015-10-01 17:18:40 -070035 public:
Casey Dahlina93cd532016-01-14 16:55:11 -080036 DBusUpdateEngineClient() = default;
Casey Dahlin19441412016-01-07 14:56:40 -080037 bool Init();
38
Casey Dahlina93cd532016-01-14 16:55:11 -080039 virtual ~DBusUpdateEngineClient() = default;
Christopher Wiley16daa082015-10-01 17:18:40 -070040
41 bool AttemptUpdate(const std::string& app_version,
42 const std::string& omaha_url,
43 bool at_user_request) override;
44
Xiaochu Liu88d90382018-08-29 16:09:11 -070045 bool AttemptInstall(const std::string& omaha_url,
Amin Hassani2b68e6b2020-04-17 10:49:12 -070046 const std::vector<std::string>& dlc_ids) override;
Xiaochu Liu88d90382018-08-29 16:09:11 -070047
Andrewa8d7df32020-03-15 20:10:01 -070048 bool SetDlcActiveValue(bool is_active, const std::string& dlc_id) override;
49
Amin Hassanieb463ee2019-06-20 19:23:03 -070050 bool GetStatus(UpdateEngineStatus* out_status) const override;
51
Alex Deymod63fab32016-10-06 15:40:49 -070052 bool SetCohortHint(const std::string& cohort_hint) override;
53 bool GetCohortHint(std::string* cohort_hint) const override;
54
Casey Dahlinef361132015-12-17 13:02:37 -080055 bool SetUpdateOverCellularPermission(bool allowed) override;
Casey Dahlin19441412016-01-07 14:56:40 -080056 bool GetUpdateOverCellularPermission(bool* allowed) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080057
58 bool SetP2PUpdatePermission(bool enabled) override;
Casey Dahlin19441412016-01-07 14:56:40 -080059 bool GetP2PUpdatePermission(bool* enabled) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080060
61 bool Rollback(bool powerwash) override;
62
Casey Dahlin19441412016-01-07 14:56:40 -080063 bool GetRollbackPartition(std::string* rollback_partition) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080064
65 void RebootIfNeeded() override;
66
Casey Dahlin19441412016-01-07 14:56:40 -080067 bool GetPrevVersion(std::string* prev_version) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080068
Casey Dahline844c1a2015-12-16 14:30:58 -080069 bool ResetStatus() override;
70
Casey Dahlin87ab88e2015-12-16 17:58:05 -080071 bool SetTargetChannel(const std::string& target_channel,
72 bool allow_powerwash) override;
Christopher Wiley16daa082015-10-01 17:18:40 -070073
Casey Dahlin19441412016-01-07 14:56:40 -080074 bool GetTargetChannel(std::string* out_channel) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070075
Casey Dahlin19441412016-01-07 14:56:40 -080076 bool GetChannel(std::string* out_channel) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070077
Casey Dahlin40892492016-01-25 16:55:28 -080078 bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
Casey Dahlina715f7b2016-01-29 16:38:51 -080079 bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
Casey Dahlin97c87052016-01-06 14:33:55 -080080
Shuqian Zhao29971732016-02-05 11:29:32 -080081 bool GetLastAttemptError(int32_t* last_attempt_error) const override;
82
Christopher Wiley16daa082015-10-01 17:18:40 -070083 private:
Alex Deymo492eaf52016-02-02 12:05:02 -080084 void DBusStatusHandlersRegistered(const std::string& interface,
Casey Dahlina715f7b2016-01-29 16:38:51 -080085 const std::string& signal_name,
86 bool success) const;
Casey Dahlin97c87052016-01-06 14:33:55 -080087
Casey Dahlina715f7b2016-01-29 16:38:51 -080088 // Send an initial event to new StatusUpdateHandlers. If the handler argument
89 // is not nullptr, only that handler receives the event. Otherwise all
90 // registered handlers receive the event.
91 void StatusUpdateHandlersRegistered(StatusUpdateHandler* handler) const;
92
Amin Hassanieb463ee2019-06-20 19:23:03 -070093 void RunStatusUpdateHandlers(const StatusResult& status);
Casey Dahlina715f7b2016-01-29 16:38:51 -080094
Alex Deymo492eaf52016-02-02 12:05:02 -080095 std::unique_ptr<org::chromium::UpdateEngineInterfaceProxy> proxy_;
Casey Dahlina715f7b2016-01-29 16:38:51 -080096 std::vector<update_engine::StatusUpdateHandler*> handlers_;
Alex Deymo492eaf52016-02-02 12:05:02 -080097 bool dbus_handler_registered_{false};
Casey Dahlin97c87052016-01-06 14:33:55 -080098
Casey Dahlina93cd532016-01-14 16:55:11 -080099 DISALLOW_COPY_AND_ASSIGN(DBusUpdateEngineClient);
100}; // class DBusUpdateEngineClient
Christopher Wiley16daa082015-10-01 17:18:40 -0700101
102} // namespace internal
103} // namespace update_engine
104
Casey Dahlina93cd532016-01-14 16:55:11 -0800105#endif // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_