Yifan Hong | 2562cf2 | 2020-07-21 19:28:44 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2020 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 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_AOSP_BINDER_SERVICE_STABLE_ANDROID_H_ |
| 18 | #define UPDATE_ENGINE_AOSP_BINDER_SERVICE_STABLE_ANDROID_H_ |
Yifan Hong | 2562cf2 | 2020-07-21 19:28:44 -0700 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | |
Yifan Hong | 2562cf2 | 2020-07-21 19:28:44 -0700 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
| 24 | #include <utils/Errors.h> |
| 25 | #include <utils/String16.h> |
| 26 | #include <utils/StrongPointer.h> |
| 27 | |
| 28 | #include "android/os/BnUpdateEngineStable.h" |
| 29 | #include "android/os/IUpdateEngineStableCallback.h" |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 30 | #include "update_engine/aosp/service_delegate_android_interface.h" |
| 31 | #include "update_engine/common/service_observer_interface.h" |
Yifan Hong | 2562cf2 | 2020-07-21 19:28:44 -0700 | [diff] [blame] | 32 | |
| 33 | namespace chromeos_update_engine { |
| 34 | |
Kelvin Zhang | 9c5baeb | 2024-11-05 13:42:32 -0800 | [diff] [blame^] | 35 | class BinderUpdateEngineAndroidStableService final |
Yifan Hong | 2562cf2 | 2020-07-21 19:28:44 -0700 | [diff] [blame] | 36 | : public android::os::BnUpdateEngineStable, |
| 37 | public ServiceObserverInterface { |
| 38 | public: |
| 39 | explicit BinderUpdateEngineAndroidStableService( |
| 40 | ServiceDelegateAndroidInterface* service_delegate); |
| 41 | ~BinderUpdateEngineAndroidStableService() override = default; |
| 42 | |
| 43 | const char* ServiceName() const { |
| 44 | return "android.os.UpdateEngineStableService"; |
| 45 | } |
| 46 | |
| 47 | // ServiceObserverInterface overrides. |
| 48 | void SendStatusUpdate( |
| 49 | const update_engine::UpdateEngineStatus& update_engine_status) override; |
| 50 | void SendPayloadApplicationComplete(ErrorCode error_code) override; |
| 51 | |
| 52 | // android::os::BnUpdateEngineStable overrides. |
| 53 | android::binder::Status applyPayloadFd( |
| 54 | const ::android::os::ParcelFileDescriptor& pfd, |
| 55 | int64_t payload_offset, |
| 56 | int64_t payload_size, |
| 57 | const std::vector<android::String16>& header_kv_pairs) override; |
| 58 | android::binder::Status bind( |
| 59 | const android::sp<android::os::IUpdateEngineStableCallback>& callback, |
| 60 | bool* return_value) override; |
| 61 | android::binder::Status unbind( |
| 62 | const android::sp<android::os::IUpdateEngineStableCallback>& callback, |
| 63 | bool* return_value) override; |
Kelvin Zhang | 9c5baeb | 2024-11-05 13:42:32 -0800 | [diff] [blame^] | 64 | android::binder::Status triggerPostinstall( |
| 65 | const ::android::String16& partition) override; |
Yifan Hong | 2562cf2 | 2020-07-21 19:28:44 -0700 | [diff] [blame] | 66 | |
| 67 | private: |
| 68 | // Remove the passed |callback| from the list of registered callbacks. Called |
| 69 | // on unbind() or whenever the callback object is destroyed. |
| 70 | // Returns true on success. |
| 71 | bool UnbindCallback(const IBinder* callback); |
| 72 | |
| 73 | // Bound callback. The stable interface only supports one callback at a time. |
| 74 | android::sp<android::os::IUpdateEngineStableCallback> callback_; |
| 75 | |
| 76 | // Cached copy of the last status update sent. Used to send an initial |
| 77 | // notification when bind() is called from the client. |
| 78 | int last_status_{-1}; |
| 79 | double last_progress_{0.0}; |
| 80 | |
| 81 | ServiceDelegateAndroidInterface* service_delegate_; |
| 82 | }; |
| 83 | |
| 84 | } // namespace chromeos_update_engine |
| 85 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 86 | #endif // UPDATE_ENGINE_AOSP_BINDER_SERVICE_STABLE_ANDROID_H_ |