binder_service_android.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Copyright (C) 2015 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_ANDROID_H_
  17. #define UPDATE_ENGINE_BINDER_SERVICE_ANDROID_H_
  18. #include <stdint.h>
  19. #include <string>
  20. #include <vector>
  21. #include <utils/Errors.h>
  22. #include <utils/String16.h>
  23. #include <utils/StrongPointer.h>
  24. #include "android/os/BnUpdateEngine.h"
  25. #include "android/os/IUpdateEngineCallback.h"
  26. #include "update_engine/service_delegate_android_interface.h"
  27. #include "update_engine/service_observer_interface.h"
  28. namespace chromeos_update_engine {
  29. class BinderUpdateEngineAndroidService : public android::os::BnUpdateEngine,
  30. public ServiceObserverInterface {
  31. public:
  32. explicit BinderUpdateEngineAndroidService(
  33. ServiceDelegateAndroidInterface* service_delegate);
  34. ~BinderUpdateEngineAndroidService() override = default;
  35. const char* ServiceName() const { return "android.os.UpdateEngineService"; }
  36. // ServiceObserverInterface overrides.
  37. void SendStatusUpdate(
  38. const update_engine::UpdateEngineStatus& update_engine_status) override;
  39. void SendPayloadApplicationComplete(ErrorCode error_code) override;
  40. // android::os::BnUpdateEngine overrides.
  41. android::binder::Status applyPayload(
  42. const android::String16& url,
  43. int64_t payload_offset,
  44. int64_t payload_size,
  45. const std::vector<android::String16>& header_kv_pairs) override;
  46. android::binder::Status bind(
  47. const android::sp<android::os::IUpdateEngineCallback>& callback,
  48. bool* return_value) override;
  49. android::binder::Status unbind(
  50. const android::sp<android::os::IUpdateEngineCallback>& callback,
  51. bool* return_value) override;
  52. android::binder::Status suspend() override;
  53. android::binder::Status resume() override;
  54. android::binder::Status cancel() override;
  55. android::binder::Status resetStatus() override;
  56. android::binder::Status verifyPayloadApplicable(
  57. const android::String16& metadata_filename, bool* return_value) override;
  58. private:
  59. // Remove the passed |callback| from the list of registered callbacks. Called
  60. // on unbind() or whenever the callback object is destroyed.
  61. // Returns true on success.
  62. bool UnbindCallback(const IBinder* callback);
  63. // List of currently bound callbacks.
  64. std::vector<android::sp<android::os::IUpdateEngineCallback>> callbacks_;
  65. // Cached copy of the last status update sent. Used to send an initial
  66. // notification when bind() is called from the client.
  67. int last_status_{-1};
  68. double last_progress_{0.0};
  69. ServiceDelegateAndroidInterface* service_delegate_;
  70. };
  71. } // namespace chromeos_update_engine
  72. #endif // UPDATE_ENGINE_BINDER_SERVICE_ANDROID_H_