blob: a2de5948249ddfe87f82b8efef688b04e473c236 [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>
26
Christopher Wiley16daa082015-10-01 17:18:40 -070027#include "update_engine/client_library/include/update_engine/client.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080028#include "update_engine/dbus-proxies.h"
Christopher Wiley16daa082015-10-01 17:18:40 -070029
30namespace update_engine {
31namespace internal {
32
Casey Dahlina93cd532016-01-14 16:55:11 -080033class DBusUpdateEngineClient : public UpdateEngineClient {
Christopher Wiley16daa082015-10-01 17:18:40 -070034 public:
Casey Dahlina93cd532016-01-14 16:55:11 -080035 DBusUpdateEngineClient() = default;
Casey Dahlin19441412016-01-07 14:56:40 -080036 bool Init();
37
Casey Dahlina93cd532016-01-14 16:55:11 -080038 virtual ~DBusUpdateEngineClient() = default;
Christopher Wiley16daa082015-10-01 17:18:40 -070039
40 bool AttemptUpdate(const std::string& app_version,
41 const std::string& omaha_url,
42 bool at_user_request) override;
43
44 bool GetStatus(int64_t* out_last_checked_time,
45 double* out_progress,
46 UpdateStatus* out_update_status,
47 std::string* out_new_version,
Casey Dahlin19441412016-01-07 14:56:40 -080048 int64_t* out_new_size) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070049
Casey Dahlinef361132015-12-17 13:02:37 -080050 bool SetUpdateOverCellularPermission(bool allowed) override;
Casey Dahlin19441412016-01-07 14:56:40 -080051 bool GetUpdateOverCellularPermission(bool* allowed) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080052
53 bool SetP2PUpdatePermission(bool enabled) override;
Casey Dahlin19441412016-01-07 14:56:40 -080054 bool GetP2PUpdatePermission(bool* enabled) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080055
56 bool Rollback(bool powerwash) override;
57
Casey Dahlin19441412016-01-07 14:56:40 -080058 bool GetRollbackPartition(std::string* rollback_partition) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080059
60 void RebootIfNeeded() override;
61
Casey Dahlin19441412016-01-07 14:56:40 -080062 bool GetPrevVersion(std::string* prev_version) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080063
Casey Dahline844c1a2015-12-16 14:30:58 -080064 bool ResetStatus() override;
65
Casey Dahlin87ab88e2015-12-16 17:58:05 -080066 bool SetTargetChannel(const std::string& target_channel,
67 bool allow_powerwash) override;
Christopher Wiley16daa082015-10-01 17:18:40 -070068
Casey Dahlin19441412016-01-07 14:56:40 -080069 bool GetTargetChannel(std::string* out_channel) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070070
Casey Dahlin19441412016-01-07 14:56:40 -080071 bool GetChannel(std::string* out_channel) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070072
Casey Dahlin40892492016-01-25 16:55:28 -080073 bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
Casey Dahlina715f7b2016-01-29 16:38:51 -080074 bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
Casey Dahlin97c87052016-01-06 14:33:55 -080075
Shuqian Zhao29971732016-02-05 11:29:32 -080076 bool GetLastAttemptError(int32_t* last_attempt_error) const override;
77
Alex Deymob3fa53b2016-04-18 19:57:58 -070078 bool GetEolStatus(int32_t* eol_status) const override;
79
Christopher Wiley16daa082015-10-01 17:18:40 -070080 private:
Alex Deymo492eaf52016-02-02 12:05:02 -080081 void DBusStatusHandlersRegistered(const std::string& interface,
Casey Dahlina715f7b2016-01-29 16:38:51 -080082 const std::string& signal_name,
83 bool success) const;
Casey Dahlin97c87052016-01-06 14:33:55 -080084
Casey Dahlina715f7b2016-01-29 16:38:51 -080085 // Send an initial event to new StatusUpdateHandlers. If the handler argument
86 // is not nullptr, only that handler receives the event. Otherwise all
87 // registered handlers receive the event.
88 void StatusUpdateHandlersRegistered(StatusUpdateHandler* handler) const;
89
90 void RunStatusUpdateHandlers(int64_t last_checked_time,
91 double progress,
92 const std::string& current_operation,
93 const std::string& new_version,
94 int64_t new_size);
95
Alex Deymo492eaf52016-02-02 12:05:02 -080096 std::unique_ptr<org::chromium::UpdateEngineInterfaceProxy> proxy_;
Casey Dahlina715f7b2016-01-29 16:38:51 -080097 std::vector<update_engine::StatusUpdateHandler*> handlers_;
Alex Deymo492eaf52016-02-02 12:05:02 -080098 bool dbus_handler_registered_{false};
Casey Dahlin97c87052016-01-06 14:33:55 -080099
Casey Dahlina93cd532016-01-14 16:55:11 -0800100 DISALLOW_COPY_AND_ASSIGN(DBusUpdateEngineClient);
101}; // class DBusUpdateEngineClient
Christopher Wiley16daa082015-10-01 17:18:40 -0700102
103} // namespace internal
104} // namespace update_engine
105
Casey Dahlina93cd532016-01-14 16:55:11 -0800106#endif // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_DBUS_H_