| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/update_engine_client.h" | 5 #include "chromeos/dbus/update_engine_client.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 if (str == update_engine::kUpdateStatusVerifying) | 62 if (str == update_engine::kUpdateStatusVerifying) |
| 63 return UpdateEngineClient::UPDATE_STATUS_VERIFYING; | 63 return UpdateEngineClient::UPDATE_STATUS_VERIFYING; |
| 64 if (str == update_engine::kUpdateStatusFinalizing) | 64 if (str == update_engine::kUpdateStatusFinalizing) |
| 65 return UpdateEngineClient::UPDATE_STATUS_FINALIZING; | 65 return UpdateEngineClient::UPDATE_STATUS_FINALIZING; |
| 66 if (str == update_engine::kUpdateStatusUpdatedNeedReboot) | 66 if (str == update_engine::kUpdateStatusUpdatedNeedReboot) |
| 67 return UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; | 67 return UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; |
| 68 if (str == update_engine::kUpdateStatusReportingErrorEvent) | 68 if (str == update_engine::kUpdateStatusReportingErrorEvent) |
| 69 return UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT; | 69 return UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT; |
| 70 if (str == update_engine::kUpdateStatusAttemptingRollback) | 70 if (str == update_engine::kUpdateStatusAttemptingRollback) |
| 71 return UpdateEngineClient::UPDATE_STATUS_ATTEMPTING_ROLLBACK; | 71 return UpdateEngineClient::UPDATE_STATUS_ATTEMPTING_ROLLBACK; |
| 72 if (str == update_engine::kUpdateStatusNeedPermissionToUpdate) |
| 73 return UpdateEngineClient::UPDATE_STATUS_NEED_PERMISSION_TO_UPDATE; |
| 72 return UpdateEngineClient::UPDATE_STATUS_ERROR; | 74 return UpdateEngineClient::UPDATE_STATUS_ERROR; |
| 73 } | 75 } |
| 74 | 76 |
| 75 // Used in UpdateEngineClient::EmptyUpdateCheckCallback(). | 77 // Used in UpdateEngineClient::EmptyUpdateCheckCallback(). |
| 76 void EmptyUpdateCheckCallbackBody( | 78 void EmptyUpdateCheckCallbackBody( |
| 77 UpdateEngineClient::UpdateCheckResult unused_result) { | 79 UpdateEngineClient::UpdateCheckResult unused_result) { |
| 78 } | 80 } |
| 79 | 81 |
| 80 bool IsValidChannel(const std::string& channel) { | 82 bool IsValidChannel(const std::string& channel) { |
| 81 return channel == kReleaseChannelDev || channel == kReleaseChannelBeta || | 83 return channel == kReleaseChannelDev || channel == kReleaseChannelBeta || |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 240 |
| 239 VLOG(1) << "Requesting UpdateEngine to " << (allowed ? "allow" : "prohibit") | 241 VLOG(1) << "Requesting UpdateEngine to " << (allowed ? "allow" : "prohibit") |
| 240 << " updates over cellular."; | 242 << " updates over cellular."; |
| 241 | 243 |
| 242 return update_engine_proxy_->CallMethod( | 244 return update_engine_proxy_->CallMethod( |
| 243 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 245 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 244 base::Bind(&UpdateEngineClientImpl::OnSetUpdateOverCellularPermission, | 246 base::Bind(&UpdateEngineClientImpl::OnSetUpdateOverCellularPermission, |
| 245 weak_ptr_factory_.GetWeakPtr(), callback)); | 247 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 246 } | 248 } |
| 247 | 249 |
| 250 void SetUpdateOverCellularTarget( |
| 251 const std::string& target_version, |
| 252 int64_t target_size, |
| 253 const SetUpdateOverCellularTargetCallback& callback) override { |
| 254 dbus::MethodCall method_call(update_engine::kUpdateEngineInterface, |
| 255 update_engine::kSetUpdateOverCellularTarget); |
| 256 dbus::MessageWriter writer(&method_call); |
| 257 writer.AppendString(target_version); |
| 258 writer.AppendInt64(target_size); |
| 259 |
| 260 VLOG(1) << "Requesting UpdateEngine to allow updates over cellular " |
| 261 << "to target version: \"" << target_version << "\" " |
| 262 << "target_size: " << target_size; |
| 263 |
| 264 return update_engine_proxy_->CallMethod( |
| 265 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 266 base::Bind(&UpdateEngineClientImpl::OnSetUpdateOverCellularTarget, |
| 267 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 268 } |
| 269 |
| 248 protected: | 270 protected: |
| 249 void Init(dbus::Bus* bus) override { | 271 void Init(dbus::Bus* bus) override { |
| 250 update_engine_proxy_ = bus->GetObjectProxy( | 272 update_engine_proxy_ = bus->GetObjectProxy( |
| 251 update_engine::kUpdateEngineServiceName, | 273 update_engine::kUpdateEngineServiceName, |
| 252 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)); | 274 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)); |
| 253 update_engine_proxy_->ConnectToSignal( | 275 update_engine_proxy_->ConnectToSignal( |
| 254 update_engine::kUpdateEngineInterface, | 276 update_engine::kUpdateEngineInterface, |
| 255 update_engine::kStatusUpdate, | 277 update_engine::kStatusUpdate, |
| 256 base::Bind(&UpdateEngineClientImpl::StatusUpdateReceived, | 278 base::Bind(&UpdateEngineClientImpl::StatusUpdateReceived, |
| 257 weak_ptr_factory_.GetWeakPtr()), | 279 weak_ptr_factory_.GetWeakPtr()), |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 return; | 447 return; |
| 426 } | 448 } |
| 427 | 449 |
| 428 VLOG(1) << "Eol status received: " << status; | 450 VLOG(1) << "Eol status received: " << status; |
| 429 callback.Run(static_cast<update_engine::EndOfLifeStatus>(status)); | 451 callback.Run(static_cast<update_engine::EndOfLifeStatus>(status)); |
| 430 } | 452 } |
| 431 | 453 |
| 432 // Called when a response for SetUpdateOverCellularPermission() is received. | 454 // Called when a response for SetUpdateOverCellularPermission() is received. |
| 433 void OnSetUpdateOverCellularPermission(const base::Closure& callback, | 455 void OnSetUpdateOverCellularPermission(const base::Closure& callback, |
| 434 dbus::Response* response) { | 456 dbus::Response* response) { |
| 435 constexpr char kFailureMessage[] = | 457 if (!response) { |
| 436 "Failed to set UpdateEngine to allow updates over cellular: "; | 458 LOG(ERROR) << update_engine::kSetUpdateOverCellularPermission |
| 437 | 459 << " call failed"; |
| 438 if (response) { | |
| 439 switch (response->GetMessageType()) { | |
| 440 case dbus::Message::MESSAGE_ERROR: | |
| 441 LOG(ERROR) << kFailureMessage | |
| 442 << "DBus responded with error: " << response->ToString(); | |
| 443 break; | |
| 444 case dbus::Message::MESSAGE_INVALID: | |
| 445 LOG(ERROR) << kFailureMessage | |
| 446 << "Invalid response from DBus (cannot be parsed)."; | |
| 447 break; | |
| 448 default: | |
| 449 VLOG(1) << "Successfully set UpdateEngine to allow update over cell."; | |
| 450 break; | |
| 451 } | |
| 452 } else { | |
| 453 LOG(ERROR) << kFailureMessage << "No response from DBus."; | |
| 454 } | 460 } |
| 455 | 461 |
| 456 // Callback should run anyway, regardless of whether DBus call to enable | 462 // Callback should run anyway, regardless of whether DBus call to enable |
| 457 // update over cellular succeeded or failed. | 463 // update over cellular succeeded or failed. |
| 458 callback.Run(); | 464 callback.Run(); |
| 459 } | 465 } |
| 460 | 466 |
| 467 // Called when a response for SetUpdateOverCellularPermission() is received. |
| 468 void OnSetUpdateOverCellularTarget( |
| 469 const SetUpdateOverCellularTargetCallback& callback, |
| 470 dbus::Response* response) { |
| 471 if (!response) { |
| 472 LOG(ERROR) << update_engine::kSetUpdateOverCellularTarget |
| 473 << " call failed"; |
| 474 callback.Run(false); |
| 475 return; |
| 476 } |
| 477 callback.Run(true); |
| 478 } |
| 479 |
| 461 // Called when a status update signal is received. | 480 // Called when a status update signal is received. |
| 462 void StatusUpdateReceived(dbus::Signal* signal) { | 481 void StatusUpdateReceived(dbus::Signal* signal) { |
| 463 VLOG(1) << "Status update signal received: " << signal->ToString(); | 482 VLOG(1) << "Status update signal received: " << signal->ToString(); |
| 464 dbus::MessageReader reader(signal); | 483 dbus::MessageReader reader(signal); |
| 465 int64_t last_checked_time = 0; | 484 int64_t last_checked_time = 0; |
| 466 double progress = 0.0; | 485 double progress = 0.0; |
| 467 std::string current_operation; | 486 std::string current_operation; |
| 468 std::string new_version; | 487 std::string new_version; |
| 469 int64_t new_size = 0; | 488 int64_t new_size = 0; |
| 470 if (!(reader.PopInt64(&last_checked_time) && | 489 if (!(reader.PopInt64(&last_checked_time) && |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 | 575 |
| 557 void GetEolStatus(const GetEolStatusCallback& callback) override { | 576 void GetEolStatus(const GetEolStatusCallback& callback) override { |
| 558 callback.Run(update_engine::EndOfLifeStatus::kSupported); | 577 callback.Run(update_engine::EndOfLifeStatus::kSupported); |
| 559 } | 578 } |
| 560 | 579 |
| 561 void SetUpdateOverCellularPermission(bool allowed, | 580 void SetUpdateOverCellularPermission(bool allowed, |
| 562 const base::Closure& callback) override { | 581 const base::Closure& callback) override { |
| 563 callback.Run(); | 582 callback.Run(); |
| 564 } | 583 } |
| 565 | 584 |
| 585 void SetUpdateOverCellularTarget( |
| 586 const std::string& target_version, |
| 587 int64_t target_size, |
| 588 const SetUpdateOverCellularTargetCallback& callback) override {} |
| 589 |
| 566 std::string current_channel_; | 590 std::string current_channel_; |
| 567 std::string target_channel_; | 591 std::string target_channel_; |
| 568 }; | 592 }; |
| 569 | 593 |
| 570 // The UpdateEngineClient implementation used on Linux desktop, which | 594 // The UpdateEngineClient implementation used on Linux desktop, which |
| 571 // tries to emulate real update engine client. | 595 // tries to emulate real update engine client. |
| 572 class UpdateEngineClientFakeImpl : public UpdateEngineClientStubImpl { | 596 class UpdateEngineClientFakeImpl : public UpdateEngineClientStubImpl { |
| 573 public: | 597 public: |
| 574 UpdateEngineClientFakeImpl() : weak_factory_(this) { | 598 UpdateEngineClientFakeImpl() : weak_factory_(this) { |
| 575 } | 599 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 private: | 636 private: |
| 613 void StateTransition() { | 637 void StateTransition() { |
| 614 UpdateStatusOperation next_status = UPDATE_STATUS_ERROR; | 638 UpdateStatusOperation next_status = UPDATE_STATUS_ERROR; |
| 615 int delay_ms = kStateTransitionDefaultDelayMs; | 639 int delay_ms = kStateTransitionDefaultDelayMs; |
| 616 switch (last_status_.status) { | 640 switch (last_status_.status) { |
| 617 case UPDATE_STATUS_ERROR: | 641 case UPDATE_STATUS_ERROR: |
| 618 case UPDATE_STATUS_IDLE: | 642 case UPDATE_STATUS_IDLE: |
| 619 case UPDATE_STATUS_UPDATED_NEED_REBOOT: | 643 case UPDATE_STATUS_UPDATED_NEED_REBOOT: |
| 620 case UPDATE_STATUS_REPORTING_ERROR_EVENT: | 644 case UPDATE_STATUS_REPORTING_ERROR_EVENT: |
| 621 case UPDATE_STATUS_ATTEMPTING_ROLLBACK: | 645 case UPDATE_STATUS_ATTEMPTING_ROLLBACK: |
| 646 case UPDATE_STATUS_NEED_PERMISSION_TO_UPDATE: |
| 622 return; | 647 return; |
| 623 case UPDATE_STATUS_CHECKING_FOR_UPDATE: | 648 case UPDATE_STATUS_CHECKING_FOR_UPDATE: |
| 624 next_status = UPDATE_STATUS_UPDATE_AVAILABLE; | 649 next_status = UPDATE_STATUS_UPDATE_AVAILABLE; |
| 625 break; | 650 break; |
| 626 case UPDATE_STATUS_UPDATE_AVAILABLE: | 651 case UPDATE_STATUS_UPDATE_AVAILABLE: |
| 627 next_status = UPDATE_STATUS_DOWNLOADING; | 652 next_status = UPDATE_STATUS_DOWNLOADING; |
| 628 break; | 653 break; |
| 629 case UPDATE_STATUS_DOWNLOADING: | 654 case UPDATE_STATUS_DOWNLOADING: |
| 630 if (last_status_.download_progress >= 1.0) { | 655 if (last_status_.download_progress >= 1.0) { |
| 631 next_status = UPDATE_STATUS_VERIFYING; | 656 next_status = UPDATE_STATUS_VERIFYING; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 const char** cix = std::find( | 719 const char** cix = std::find( |
| 695 kReleaseChannelsList, | 720 kReleaseChannelsList, |
| 696 kReleaseChannelsList + arraysize(kReleaseChannelsList), current_channel); | 721 kReleaseChannelsList + arraysize(kReleaseChannelsList), current_channel); |
| 697 const char** tix = std::find( | 722 const char** tix = std::find( |
| 698 kReleaseChannelsList, | 723 kReleaseChannelsList, |
| 699 kReleaseChannelsList + arraysize(kReleaseChannelsList), target_channel); | 724 kReleaseChannelsList + arraysize(kReleaseChannelsList), target_channel); |
| 700 return tix > cix; | 725 return tix > cix; |
| 701 } | 726 } |
| 702 | 727 |
| 703 } // namespace chromeos | 728 } // namespace chromeos |
| OLD | NEW |