binder_service_brillo.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // Copyright (C) 2016 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. #ifndef UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
  17. #define UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
  18. #include <utils/Errors.h>
  19. #include <memory>
  20. #include <string>
  21. #include <vector>
  22. #include <utils/RefBase.h>
  23. #include "update_engine/common_service.h"
  24. #include "update_engine/parcelable_update_engine_status.h"
  25. #include "update_engine/service_observer_interface.h"
  26. #include "android/brillo/BnUpdateEngine.h"
  27. #include "android/brillo/IUpdateEngineStatusCallback.h"
  28. namespace chromeos_update_engine {
  29. class BinderUpdateEngineBrilloService : public android::brillo::BnUpdateEngine,
  30. public ServiceObserverInterface {
  31. public:
  32. explicit BinderUpdateEngineBrilloService(SystemState* system_state)
  33. : common_(new UpdateEngineService(system_state)) {}
  34. virtual ~BinderUpdateEngineBrilloService() = default;
  35. const char* ServiceName() const {
  36. return "android.brillo.UpdateEngineService";
  37. }
  38. // ServiceObserverInterface overrides.
  39. void SendStatusUpdate(
  40. const update_engine::UpdateEngineStatus& update_engine_status) override;
  41. void SendPayloadApplicationComplete(ErrorCode error_code) override {}
  42. // android::brillo::BnUpdateEngine overrides.
  43. android::binder::Status SetUpdateAttemptFlags(int flags) override;
  44. android::binder::Status AttemptUpdate(const android::String16& app_version,
  45. const android::String16& omaha_url,
  46. int flags,
  47. bool* out_result) override;
  48. android::binder::Status AttemptRollback(bool powerwash) override;
  49. android::binder::Status CanRollback(bool* out_can_rollback) override;
  50. android::binder::Status ResetStatus() override;
  51. android::binder::Status GetStatus(
  52. android::brillo::ParcelableUpdateEngineStatus* status);
  53. android::binder::Status RebootIfNeeded() override;
  54. android::binder::Status SetChannel(const android::String16& target_channel,
  55. bool powerwash) override;
  56. android::binder::Status GetChannel(bool get_current_channel,
  57. android::String16* out_channel) override;
  58. android::binder::Status SetCohortHint(
  59. const android::String16& cohort_hint) override;
  60. android::binder::Status GetCohortHint(
  61. android::String16* out_cohort_hint) override;
  62. android::binder::Status SetP2PUpdatePermission(bool enabled) override;
  63. android::binder::Status GetP2PUpdatePermission(
  64. bool* out_p2p_permission) override;
  65. android::binder::Status SetUpdateOverCellularPermission(
  66. bool enabled) override;
  67. android::binder::Status SetUpdateOverCellularTarget(
  68. const android::String16& target_version, int64_t target_size) override;
  69. android::binder::Status GetUpdateOverCellularPermission(
  70. bool* out_cellular_permission) override;
  71. android::binder::Status GetDurationSinceUpdate(
  72. int64_t* out_duration) override;
  73. android::binder::Status GetPrevVersion(
  74. android::String16* out_prev_version) override;
  75. android::binder::Status GetRollbackPartition(
  76. android::String16* out_rollback_partition) override;
  77. android::binder::Status RegisterStatusCallback(
  78. const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
  79. override;
  80. android::binder::Status GetLastAttemptError(
  81. int* out_last_attempt_error) override;
  82. android::binder::Status GetEolStatus(int* out_eol_status) override;
  83. private:
  84. // Generic function for dispatching to the common service.
  85. template <typename... Parameters, typename... Arguments>
  86. android::binder::Status CallCommonHandler(
  87. bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
  88. Arguments... arguments);
  89. // To be used as a death notification handler only.
  90. void UnregisterStatusCallback(
  91. android::brillo::IUpdateEngineStatusCallback* callback);
  92. std::unique_ptr<UpdateEngineService> common_;
  93. std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
  94. callbacks_;
  95. };
  96. } // namespace chromeos_update_engine
  97. #endif // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_