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