• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
27 #include "update_engine/client_library/include/update_engine/client.h"
28 #include "update_engine/dbus-proxies.h"
29 
30 namespace update_engine {
31 namespace internal {
32 
33 class DBusUpdateEngineClient : public UpdateEngineClient {
34  public:
35   DBusUpdateEngineClient() = default;
36   bool Init();
37 
38   virtual ~DBusUpdateEngineClient() = default;
39 
40   bool AttemptUpdate(const std::string& app_version,
41                      const std::string& omaha_url,
42                      bool at_user_request) override;
43 
44   bool AttemptInstall(const std::string& omaha_url,
45                       const std::vector<std::string>& dlc_module_ids) override;
46 
47   bool GetStatus(int64_t* out_last_checked_time,
48                  double* out_progress,
49                  UpdateStatus* out_update_status,
50                  std::string* out_new_version,
51                  int64_t* out_new_size) const override;
52 
53   bool SetCohortHint(const std::string& cohort_hint) override;
54   bool GetCohortHint(std::string* cohort_hint) const override;
55 
56   bool SetUpdateOverCellularPermission(bool allowed) override;
57   bool GetUpdateOverCellularPermission(bool* allowed) const override;
58 
59   bool SetP2PUpdatePermission(bool enabled) override;
60   bool GetP2PUpdatePermission(bool* enabled) const override;
61 
62   bool Rollback(bool powerwash) override;
63 
64   bool GetRollbackPartition(std::string* rollback_partition) const override;
65 
66   void RebootIfNeeded() override;
67 
68   bool GetPrevVersion(std::string* prev_version) const override;
69 
70   bool ResetStatus() override;
71 
72   bool SetTargetChannel(const std::string& target_channel,
73                         bool allow_powerwash) override;
74 
75   bool GetTargetChannel(std::string* out_channel) const override;
76 
77   bool GetChannel(std::string* out_channel) const override;
78 
79   bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
80   bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
81 
82   bool GetLastAttemptError(int32_t* last_attempt_error) const override;
83 
84   bool GetEolStatus(int32_t* eol_status) const override;
85 
86  private:
87   void DBusStatusHandlersRegistered(const std::string& interface,
88                                     const std::string& signal_name,
89                                     bool success) const;
90 
91   // Send an initial event to new StatusUpdateHandlers. If the handler argument
92   // is not nullptr, only that handler receives the event. Otherwise all
93   // registered handlers receive the event.
94   void StatusUpdateHandlersRegistered(StatusUpdateHandler* handler) const;
95 
96   void RunStatusUpdateHandlers(int64_t last_checked_time,
97                                double progress,
98                                const std::string& current_operation,
99                                const std::string& new_version,
100                                int64_t new_size);
101 
102   std::unique_ptr<org::chromium::UpdateEngineInterfaceProxy> proxy_;
103   std::vector<update_engine::StatusUpdateHandler*> handlers_;
104   bool dbus_handler_registered_{false};
105 
106   DISALLOW_COPY_AND_ASSIGN(DBusUpdateEngineClient);
107 };  // class DBusUpdateEngineClient
108 
109 }  // namespace internal
110 }  // namespace update_engine
111 
112 #endif  // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_
113