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_CLIENT_DBUS_H_
18 #define UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_
19 
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include <base/macros.h>
26 #include <update_engine/proto_bindings/update_engine.pb.h>
27 
28 #include "update_engine/client_library/include/update_engine/client.h"
29 #include "update_engine/dbus-proxies.h"
30 
31 namespace update_engine {
32 namespace internal {
33 
34 class DBusUpdateEngineClient : public UpdateEngineClient {
35  public:
36   DBusUpdateEngineClient() = default;
37   bool Init();
38 
39   virtual ~DBusUpdateEngineClient() = default;
40 
41   bool AttemptUpdate(const std::string& app_version,
42                      const std::string& omaha_url,
43                      bool at_user_request) override;
44 
45   bool AttemptInstall(const std::string& omaha_url,
46                       const std::vector<std::string>& dlc_ids) override;
47 
48   bool SetDlcActiveValue(bool is_active, const std::string& dlc_id) override;
49 
50   bool GetStatus(UpdateEngineStatus* out_status) const override;
51 
52   bool SetCohortHint(const std::string& cohort_hint) override;
53   bool GetCohortHint(std::string* cohort_hint) const override;
54 
55   bool SetUpdateOverCellularPermission(bool allowed) override;
56   bool GetUpdateOverCellularPermission(bool* allowed) const override;
57 
58   bool SetP2PUpdatePermission(bool enabled) override;
59   bool GetP2PUpdatePermission(bool* enabled) const override;
60 
61   bool Rollback(bool powerwash) override;
62 
63   bool GetRollbackPartition(std::string* rollback_partition) const override;
64 
65   void RebootIfNeeded() override;
66 
67   bool GetPrevVersion(std::string* prev_version) const override;
68 
69   bool ResetStatus() override;
70 
71   bool SetTargetChannel(const std::string& target_channel,
72                         bool allow_powerwash) override;
73 
74   bool GetTargetChannel(std::string* out_channel) const override;
75 
76   bool GetChannel(std::string* out_channel) const override;
77 
78   bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
79   bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
80 
81   bool GetLastAttemptError(int32_t* last_attempt_error) const override;
82 
83  private:
84   void DBusStatusHandlersRegistered(const std::string& interface,
85                                     const std::string& signal_name,
86                                     bool success) const;
87 
88   // 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 
93   void RunStatusUpdateHandlers(const StatusResult& status);
94 
95   std::unique_ptr<org::chromium::UpdateEngineInterfaceProxy> proxy_;
96   std::vector<update_engine::StatusUpdateHandler*> handlers_;
97   bool dbus_handler_registered_{false};
98 
99   DISALLOW_COPY_AND_ASSIGN(DBusUpdateEngineClient);
100 };  // class DBusUpdateEngineClient
101 
102 }  // namespace internal
103 }  // namespace update_engine
104 
105 #endif  // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_
106