blob: 25d3c4bb4e9840dc0fd52ff4bc540229a7ce9583 [file] [log] [blame]
Casey Dahlina93cd532016-01-14 16:55:11 -08001//
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 Hassaniec7bc112020-10-29 16:47:58 -070017#ifndef UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_
18#define UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_
Casey Dahlina93cd532016-01-14 16:55:11 -080019
Alex Deymo95b8f242016-01-28 16:06:57 -080020#include <stdint.h>
21
Alex Deymof8bfcff2016-02-02 21:22:11 -080022#include <string>
Casey Dahlina93cd532016-01-14 16:55:11 -080023#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 Hassaniec7bc112020-10-29 16:47:58 -070031#include "update_engine/aosp/service_delegate_android_interface.h"
32#include "update_engine/common/service_observer_interface.h"
Casey Dahlina93cd532016-01-14 16:55:11 -080033
34namespace chromeos_update_engine {
35
Kelvin Zhang0aaa7362024-11-15 16:09:22 -080036class BinderUpdateEngineAndroidService final
37 : public android::os::BnUpdateEngine,
38 public ServiceObserverInterface {
Casey Dahlina93cd532016-01-14 16:55:11 -080039 public:
Chih-Hung Hsieh4d986262016-07-12 13:45:12 -070040 explicit BinderUpdateEngineAndroidService(
Alex Deymof8bfcff2016-02-02 21:22:11 -080041 ServiceDelegateAndroidInterface* service_delegate);
Alex Deymoe97b39c2016-01-20 13:22:17 -080042 ~BinderUpdateEngineAndroidService() override = default;
Casey Dahlina93cd532016-01-14 16:55:11 -080043
Amin Hassani7cc8bb02019-01-14 16:29:47 -080044 const char* ServiceName() const { return "android.os.UpdateEngineService"; }
Alex Deymofa78f142016-01-26 21:36:16 -080045
46 // ServiceObserverInterface overrides.
Aaron Wood7f92e2b2017-08-28 14:51:21 -070047 void SendStatusUpdate(
48 const update_engine::UpdateEngineStatus& update_engine_status) override;
Alex Deymof8bfcff2016-02-02 21:22:11 -080049 void SendPayloadApplicationComplete(ErrorCode error_code) override;
Alex Deymofa78f142016-01-26 21:36:16 -080050
Alex Deymofa78f142016-01-26 21:36:16 -080051 // android::os::BnUpdateEngine overrides.
Casey Dahlina93cd532016-01-14 16:55:11 -080052 android::binder::Status applyPayload(
53 const android::String16& url,
Alex Deymo95b8f242016-01-28 16:06:57 -080054 int64_t payload_offset,
55 int64_t payload_size,
Casey Dahlina93cd532016-01-14 16:55:11 -080056 const std::vector<android::String16>& header_kv_pairs) override;
Kyeongkab.Nam500ca132019-06-26 13:48:07 +090057 android::binder::Status applyPayloadFd(
Kyeongkab.Nam42132992019-10-03 18:04:02 +090058 const ::android::os::ParcelFileDescriptor& pfd,
Kyeongkab.Nam500ca132019-06-26 13:48:07 +090059 int64_t payload_offset,
60 int64_t payload_size,
61 const std::vector<android::String16>& header_kv_pairs) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080062 android::binder::Status bind(
63 const android::sp<android::os::IUpdateEngineCallback>& callback,
64 bool* return_value) override;
Sen Jiang5caab192017-07-07 17:22:29 -070065 android::binder::Status unbind(
66 const android::sp<android::os::IUpdateEngineCallback>& callback,
67 bool* return_value) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080068 android::binder::Status suspend() override;
Casey Dahlina93cd532016-01-14 16:55:11 -080069 android::binder::Status resume() override;
Casey Dahlina93cd532016-01-14 16:55:11 -080070 android::binder::Status cancel() override;
Alex Deymo3b678db2016-02-09 11:50:06 -080071 android::binder::Status resetStatus() override;
Tianjieda607a32021-05-05 17:38:06 -070072 android::binder::Status setShouldSwitchSlotOnReboot(
73 const android::String16& metadata_filename) override;
74 android::binder::Status resetShouldSwitchSlotOnReboot() override;
Tao Bao20c96722018-01-09 22:38:57 -080075 android::binder::Status verifyPayloadApplicable(
76 const android::String16& metadata_filename, bool* return_value) override;
Yifan Hong6f7e29f2019-12-13 14:41:06 -080077 android::binder::Status allocateSpaceForPayload(
78 const android::String16& metadata_filename,
79 const std::vector<android::String16>& header_kv_pairs,
80 int64_t* return_value) override;
Yifan Hong2236ea02019-12-13 16:11:22 -080081 android::binder::Status cleanupSuccessfulUpdate(
Yifan Hong40bb0d02020-02-24 17:33:14 -080082 const android::sp<android::os::IUpdateEngineCallback>& callback) override;
Kelvin Zhang0aaa7362024-11-15 16:09:22 -080083 ::android::binder::Status triggerPostinstall(
84 const ::android::String16& partition) override;
Alex Deymof8bfcff2016-02-02 21:22:11 -080085
86 private:
87 // Remove the passed |callback| from the list of registered callbacks. Called
Sen Jiang5caab192017-07-07 17:22:29 -070088 // on unbind() or whenever the callback object is destroyed.
89 // Returns true on success.
Sen Jiangb7f73802017-07-18 15:29:26 -070090 bool UnbindCallback(const IBinder* callback);
Alex Deymof8bfcff2016-02-02 21:22:11 -080091
92 // List of currently bound callbacks.
93 std::vector<android::sp<android::os::IUpdateEngineCallback>> callbacks_;
94
Alex Deymo0e061ae2016-02-09 17:49:03 -080095 // Cached copy of the last status update sent. Used to send an initial
96 // notification when bind() is called from the client.
97 int last_status_{-1};
98 double last_progress_{0.0};
99
Alex Deymof8bfcff2016-02-02 21:22:11 -0800100 ServiceDelegateAndroidInterface* service_delegate_;
Alex Deymoe97b39c2016-01-20 13:22:17 -0800101};
Casey Dahlina93cd532016-01-14 16:55:11 -0800102
103} // namespace chromeos_update_engine
104
Amin Hassaniec7bc112020-10-29 16:47:58 -0700105#endif // UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_