1 //
2 // Copyright (C) 2012 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 #include "update_engine/dbus_service.h"
18
19 #include "update_engine/dbus-constants.h"
20 #include "update_engine/dbus_connection.h"
21 #include "update_engine/update_status_utils.h"
22
23 namespace chromeos_update_engine {
24
25 using brillo::ErrorPtr;
26 using chromeos_update_engine::UpdateEngineService;
27 using std::string;
28
DBusUpdateEngineService(SystemState * system_state)29 DBusUpdateEngineService::DBusUpdateEngineService(SystemState* system_state)
30 : common_(new UpdateEngineService{system_state}) {
31 }
32
33 // org::chromium::UpdateEngineInterfaceInterface methods implementation.
34
AttemptUpdate(ErrorPtr * error,const string & in_app_version,const string & in_omaha_url)35 bool DBusUpdateEngineService::AttemptUpdate(ErrorPtr* error,
36 const string& in_app_version,
37 const string& in_omaha_url) {
38 return AttemptUpdateWithFlags(
39 error, in_app_version, in_omaha_url, 0 /* no flags */);
40 }
41
AttemptUpdateWithFlags(ErrorPtr * error,const string & in_app_version,const string & in_omaha_url,int32_t in_flags_as_int)42 bool DBusUpdateEngineService::AttemptUpdateWithFlags(
43 ErrorPtr* error,
44 const string& in_app_version,
45 const string& in_omaha_url,
46 int32_t in_flags_as_int) {
47 update_engine::AttemptUpdateFlags flags =
48 static_cast<update_engine::AttemptUpdateFlags>(in_flags_as_int);
49 bool interactive = !(flags &
50 update_engine::kAttemptUpdateFlagNonInteractive);
51
52 return common_->AttemptUpdate(
53 error, in_app_version, in_omaha_url,
54 interactive ? 0 : UpdateEngineService::kAttemptUpdateFlagNonInteractive);
55 }
56
AttemptRollback(ErrorPtr * error,bool in_powerwash)57 bool DBusUpdateEngineService::AttemptRollback(ErrorPtr* error,
58 bool in_powerwash) {
59 return common_->AttemptRollback(error, in_powerwash);
60 }
61
CanRollback(ErrorPtr * error,bool * out_can_rollback)62 bool DBusUpdateEngineService::CanRollback(ErrorPtr* error,
63 bool* out_can_rollback) {
64 return common_->CanRollback(error, out_can_rollback);
65 }
66
ResetStatus(ErrorPtr * error)67 bool DBusUpdateEngineService::ResetStatus(ErrorPtr* error) {
68 return common_->ResetStatus(error);
69 }
70
GetStatus(ErrorPtr * error,int64_t * out_last_checked_time,double * out_progress,string * out_current_operation,string * out_new_version,int64_t * out_new_size)71 bool DBusUpdateEngineService::GetStatus(ErrorPtr* error,
72 int64_t* out_last_checked_time,
73 double* out_progress,
74 string* out_current_operation,
75 string* out_new_version,
76 int64_t* out_new_size) {
77 return common_->GetStatus(error,
78 out_last_checked_time,
79 out_progress,
80 out_current_operation,
81 out_new_version,
82 out_new_size);
83 }
84
RebootIfNeeded(ErrorPtr * error)85 bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) {
86 return common_->RebootIfNeeded(error);
87 }
88
SetChannel(ErrorPtr * error,const string & in_target_channel,bool in_is_powerwash_allowed)89 bool DBusUpdateEngineService::SetChannel(ErrorPtr* error,
90 const string& in_target_channel,
91 bool in_is_powerwash_allowed) {
92 return common_->SetChannel(error, in_target_channel, in_is_powerwash_allowed);
93 }
94
GetChannel(ErrorPtr * error,bool in_get_current_channel,string * out_channel)95 bool DBusUpdateEngineService::GetChannel(ErrorPtr* error,
96 bool in_get_current_channel,
97 string* out_channel) {
98 return common_->GetChannel(error, in_get_current_channel, out_channel);
99 }
100
GetCohortHint(ErrorPtr * error,string * out_cohort_hint)101 bool DBusUpdateEngineService::GetCohortHint(ErrorPtr* error,
102 string* out_cohort_hint) {
103 return common_->GetCohortHint(error, out_cohort_hint);
104 }
105
SetCohortHint(ErrorPtr * error,const string & in_cohort_hint)106 bool DBusUpdateEngineService::SetCohortHint(ErrorPtr* error,
107 const string& in_cohort_hint) {
108 return common_->SetCohortHint(error, in_cohort_hint);
109 }
110
SetP2PUpdatePermission(ErrorPtr * error,bool in_enabled)111 bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
112 bool in_enabled) {
113 return common_->SetP2PUpdatePermission(error, in_enabled);
114 }
115
GetP2PUpdatePermission(ErrorPtr * error,bool * out_enabled)116 bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
117 bool* out_enabled) {
118 return common_->GetP2PUpdatePermission(error, out_enabled);
119 }
120
SetUpdateOverCellularPermission(ErrorPtr * error,bool in_allowed)121 bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error,
122 bool in_allowed) {
123 return common_->SetUpdateOverCellularPermission(error, in_allowed);
124 }
125
GetUpdateOverCellularPermission(ErrorPtr * error,bool * out_allowed)126 bool DBusUpdateEngineService::GetUpdateOverCellularPermission(
127 ErrorPtr* error, bool* out_allowed) {
128 return common_->GetUpdateOverCellularPermission(error, out_allowed);
129 }
130
GetDurationSinceUpdate(ErrorPtr * error,int64_t * out_usec_wallclock)131 bool DBusUpdateEngineService::GetDurationSinceUpdate(
132 ErrorPtr* error, int64_t* out_usec_wallclock) {
133 return common_->GetDurationSinceUpdate(error, out_usec_wallclock);
134 }
135
GetPrevVersion(ErrorPtr * error,string * out_prev_version)136 bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error,
137 string* out_prev_version) {
138 return common_->GetPrevVersion(error, out_prev_version);
139 }
140
GetRollbackPartition(ErrorPtr * error,string * out_rollback_partition_name)141 bool DBusUpdateEngineService::GetRollbackPartition(
142 ErrorPtr* error, string* out_rollback_partition_name) {
143 return common_->GetRollbackPartition(error, out_rollback_partition_name);
144 }
145
GetLastAttemptError(ErrorPtr * error,int32_t * out_last_attempt_error)146 bool DBusUpdateEngineService::GetLastAttemptError(
147 ErrorPtr* error, int32_t* out_last_attempt_error) {
148 return common_->GetLastAttemptError(error, out_last_attempt_error);
149 }
150
GetEolStatus(ErrorPtr * error,int32_t * out_eol_status)151 bool DBusUpdateEngineService::GetEolStatus(ErrorPtr* error,
152 int32_t* out_eol_status) {
153 return common_->GetEolStatus(error, out_eol_status);
154 }
155
UpdateEngineAdaptor(SystemState * system_state)156 UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state)
157 : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_),
158 bus_(DBusConnection::Get()->GetDBus()),
159 dbus_service_(system_state),
160 dbus_object_(nullptr,
161 bus_,
162 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {}
163
RegisterAsync(const base::Callback<void (bool)> & completion_callback)164 void UpdateEngineAdaptor::RegisterAsync(
165 const base::Callback<void(bool)>& completion_callback) {
166 RegisterWithDBusObject(&dbus_object_);
167 dbus_object_.RegisterAsync(completion_callback);
168 }
169
RequestOwnership()170 bool UpdateEngineAdaptor::RequestOwnership() {
171 return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName,
172 dbus::Bus::REQUIRE_PRIMARY);
173 }
174
SendStatusUpdate(int64_t last_checked_time,double progress,update_engine::UpdateStatus status,const string & new_version,int64_t new_size)175 void UpdateEngineAdaptor::SendStatusUpdate(int64_t last_checked_time,
176 double progress,
177 update_engine::UpdateStatus status,
178 const string& new_version,
179 int64_t new_size) {
180 const string str_status = UpdateStatusToString(status);
181 SendStatusUpdateSignal(
182 last_checked_time, progress, str_status, new_version, new_size);
183 }
184
185 } // namespace chromeos_update_engine
186