interactive_update_policy_impl.cc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // Copyright (C) 2017 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. #include "update_engine/update_manager/interactive_update_policy_impl.h"
  17. using chromeos_update_engine::ErrorCode;
  18. using chromeos_update_engine::InstallPlan;
  19. namespace chromeos_update_manager {
  20. // Check to see if an interactive update was requested.
  21. EvalStatus InteractiveUpdatePolicyImpl::UpdateCheckAllowed(
  22. EvaluationContext* ec,
  23. State* state,
  24. std::string* error,
  25. UpdateCheckParams* result) const {
  26. bool interactive;
  27. if (CheckInteractiveUpdateRequested(
  28. ec, state->updater_provider(), &interactive)) {
  29. result->interactive = interactive;
  30. LOG(INFO) << "Forced update signaled ("
  31. << (interactive ? "interactive" : "periodic")
  32. << "), allowing update check.";
  33. return EvalStatus::kSucceeded;
  34. }
  35. return EvalStatus::kContinue;
  36. }
  37. EvalStatus InteractiveUpdatePolicyImpl::UpdateCanBeApplied(
  38. EvaluationContext* ec,
  39. State* state,
  40. std::string* error,
  41. ErrorCode* result,
  42. InstallPlan* install_plan) const {
  43. bool interactive;
  44. if (CheckInteractiveUpdateRequested(
  45. ec, state->updater_provider(), &interactive)) {
  46. LOG(INFO) << "Forced update signaled ("
  47. << (interactive ? "interactive" : "periodic")
  48. << "), allowing update to be applied.";
  49. *result = ErrorCode::kSuccess;
  50. return EvalStatus::kSucceeded;
  51. }
  52. return EvalStatus::kContinue;
  53. }
  54. bool InteractiveUpdatePolicyImpl::CheckInteractiveUpdateRequested(
  55. EvaluationContext* ec,
  56. UpdaterProvider* const updater_provider,
  57. bool* interactive_out) const {
  58. // First, check to see if an interactive update was requested.
  59. const UpdateRequestStatus* forced_update_requested_p =
  60. ec->GetValue(updater_provider->var_forced_update_requested());
  61. if (forced_update_requested_p != nullptr &&
  62. *forced_update_requested_p != UpdateRequestStatus::kNone) {
  63. if (interactive_out)
  64. *interactive_out =
  65. (*forced_update_requested_p == UpdateRequestStatus::kInteractive);
  66. return true;
  67. }
  68. return false;
  69. }
  70. } // namespace chromeos_update_manager