Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 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 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_ |
| 18 | #define UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_ |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 19 | |
Alex Deymo | 95b8f24 | 2016-01-28 16:06:57 -0800 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 22 | #include <string> |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 23 | #include <vector> |
| 24 | |
| 25 | #include <utils/Errors.h> |
| 26 | #include <utils/String16.h> |
| 27 | #include <utils/StrongPointer.h> |
| 28 | |
| 29 | #include "android/os/BnUpdateEngine.h" |
| 30 | #include "android/os/IUpdateEngineCallback.h" |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 31 | #include "update_engine/aosp/service_delegate_android_interface.h" |
| 32 | #include "update_engine/common/service_observer_interface.h" |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 33 | |
| 34 | namespace chromeos_update_engine { |
| 35 | |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 36 | class BinderUpdateEngineAndroidService : public android::os::BnUpdateEngine, |
| 37 | public ServiceObserverInterface { |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 38 | public: |
Chih-Hung Hsieh | 4d98626 | 2016-07-12 13:45:12 -0700 | [diff] [blame] | 39 | explicit BinderUpdateEngineAndroidService( |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 40 | ServiceDelegateAndroidInterface* service_delegate); |
Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 41 | ~BinderUpdateEngineAndroidService() override = default; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 42 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 43 | const char* ServiceName() const { return "android.os.UpdateEngineService"; } |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 44 | |
| 45 | // ServiceObserverInterface overrides. |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 46 | void SendStatusUpdate( |
| 47 | const update_engine::UpdateEngineStatus& update_engine_status) override; |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 48 | void SendPayloadApplicationComplete(ErrorCode error_code) override; |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 49 | |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 50 | // android::os::BnUpdateEngine overrides. |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 51 | android::binder::Status applyPayload( |
| 52 | const android::String16& url, |
Alex Deymo | 95b8f24 | 2016-01-28 16:06:57 -0800 | [diff] [blame] | 53 | int64_t payload_offset, |
| 54 | int64_t payload_size, |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 55 | const std::vector<android::String16>& header_kv_pairs) override; |
Kyeongkab.Nam | 500ca13 | 2019-06-26 13:48:07 +0900 | [diff] [blame] | 56 | android::binder::Status applyPayloadFd( |
Kyeongkab.Nam | 4213299 | 2019-10-03 18:04:02 +0900 | [diff] [blame] | 57 | const ::android::os::ParcelFileDescriptor& pfd, |
Kyeongkab.Nam | 500ca13 | 2019-06-26 13:48:07 +0900 | [diff] [blame] | 58 | int64_t payload_offset, |
| 59 | int64_t payload_size, |
| 60 | const std::vector<android::String16>& header_kv_pairs) override; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 61 | android::binder::Status bind( |
| 62 | const android::sp<android::os::IUpdateEngineCallback>& callback, |
| 63 | bool* return_value) override; |
Sen Jiang | 5caab19 | 2017-07-07 17:22:29 -0700 | [diff] [blame] | 64 | android::binder::Status unbind( |
| 65 | const android::sp<android::os::IUpdateEngineCallback>& callback, |
| 66 | bool* return_value) override; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 67 | android::binder::Status suspend() override; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 68 | android::binder::Status resume() override; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 69 | android::binder::Status cancel() override; |
Alex Deymo | 3b678db | 2016-02-09 11:50:06 -0800 | [diff] [blame] | 70 | android::binder::Status resetStatus() override; |
Tianjie | da607a3 | 2021-05-05 17:38:06 -0700 | [diff] [blame] | 71 | android::binder::Status setShouldSwitchSlotOnReboot( |
| 72 | const android::String16& metadata_filename) override; |
| 73 | android::binder::Status resetShouldSwitchSlotOnReboot() override; |
Tao Bao | 20c9672 | 2018-01-09 22:38:57 -0800 | [diff] [blame] | 74 | android::binder::Status verifyPayloadApplicable( |
| 75 | const android::String16& metadata_filename, bool* return_value) override; |
Yifan Hong | 6f7e29f | 2019-12-13 14:41:06 -0800 | [diff] [blame] | 76 | android::binder::Status allocateSpaceForPayload( |
| 77 | const android::String16& metadata_filename, |
| 78 | const std::vector<android::String16>& header_kv_pairs, |
| 79 | int64_t* return_value) override; |
Yifan Hong | 2236ea0 | 2019-12-13 16:11:22 -0800 | [diff] [blame] | 80 | android::binder::Status cleanupSuccessfulUpdate( |
Yifan Hong | 40bb0d0 | 2020-02-24 17:33:14 -0800 | [diff] [blame] | 81 | const android::sp<android::os::IUpdateEngineCallback>& callback) override; |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 82 | |
| 83 | private: |
| 84 | // Remove the passed |callback| from the list of registered callbacks. Called |
Sen Jiang | 5caab19 | 2017-07-07 17:22:29 -0700 | [diff] [blame] | 85 | // on unbind() or whenever the callback object is destroyed. |
| 86 | // Returns true on success. |
Sen Jiang | b7f7380 | 2017-07-18 15:29:26 -0700 | [diff] [blame] | 87 | bool UnbindCallback(const IBinder* callback); |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 88 | |
| 89 | // List of currently bound callbacks. |
| 90 | std::vector<android::sp<android::os::IUpdateEngineCallback>> callbacks_; |
| 91 | |
Alex Deymo | 0e061ae | 2016-02-09 17:49:03 -0800 | [diff] [blame] | 92 | // Cached copy of the last status update sent. Used to send an initial |
| 93 | // notification when bind() is called from the client. |
| 94 | int last_status_{-1}; |
| 95 | double last_progress_{0.0}; |
| 96 | |
Alex Deymo | f8bfcff | 2016-02-02 21:22:11 -0800 | [diff] [blame] | 97 | ServiceDelegateAndroidInterface* service_delegate_; |
Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 98 | }; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 99 | |
| 100 | } // namespace chromeos_update_engine |
| 101 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 102 | #endif // UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_ |