xref: /aosp_15_r20/system/update_engine/aosp/binder_service_android.h (revision 5a9231315b4521097b8dc3750bc806fcafe0c72f)
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 
17 #ifndef UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_
18 #define UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_
19 
20 #include <stdint.h>
21 
22 #include <string>
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"
31 #include "update_engine/aosp/service_delegate_android_interface.h"
32 #include "update_engine/common/service_observer_interface.h"
33 
34 namespace chromeos_update_engine {
35 
36 class BinderUpdateEngineAndroidService final
37     : public android::os::BnUpdateEngine,
38       public ServiceObserverInterface {
39  public:
40   explicit BinderUpdateEngineAndroidService(
41       ServiceDelegateAndroidInterface* service_delegate);
42   ~BinderUpdateEngineAndroidService() override = default;
43 
ServiceName()44   const char* ServiceName() const { return "android.os.UpdateEngineService"; }
45 
46   // ServiceObserverInterface overrides.
47   void SendStatusUpdate(
48       const update_engine::UpdateEngineStatus& update_engine_status) override;
49   void SendPayloadApplicationComplete(ErrorCode error_code) override;
50 
51   // android::os::BnUpdateEngine overrides.
52   android::binder::Status applyPayload(
53       const android::String16& url,
54       int64_t payload_offset,
55       int64_t payload_size,
56       const std::vector<android::String16>& header_kv_pairs) override;
57   android::binder::Status applyPayloadFd(
58       const ::android::os::ParcelFileDescriptor& pfd,
59       int64_t payload_offset,
60       int64_t payload_size,
61       const std::vector<android::String16>& header_kv_pairs) override;
62   android::binder::Status bind(
63       const android::sp<android::os::IUpdateEngineCallback>& callback,
64       bool* return_value) override;
65   android::binder::Status unbind(
66       const android::sp<android::os::IUpdateEngineCallback>& callback,
67       bool* return_value) override;
68   android::binder::Status suspend() override;
69   android::binder::Status resume() override;
70   android::binder::Status cancel() override;
71   android::binder::Status resetStatus() override;
72   android::binder::Status setShouldSwitchSlotOnReboot(
73       const android::String16& metadata_filename) override;
74   android::binder::Status resetShouldSwitchSlotOnReboot() override;
75   android::binder::Status verifyPayloadApplicable(
76       const android::String16& metadata_filename, bool* return_value) override;
77   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;
81   android::binder::Status cleanupSuccessfulUpdate(
82       const android::sp<android::os::IUpdateEngineCallback>& callback) override;
83   ::android::binder::Status triggerPostinstall(
84       const ::android::String16& partition) override;
85 
86  private:
87   // Remove the passed |callback| from the list of registered callbacks. Called
88   // on unbind() or whenever the callback object is destroyed.
89   // Returns true on success.
90   bool UnbindCallback(const IBinder* callback);
91 
92   // List of currently bound callbacks.
93   std::vector<android::sp<android::os::IUpdateEngineCallback>> callbacks_;
94 
95   // 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 
100   ServiceDelegateAndroidInterface* service_delegate_;
101 };
102 
103 }  // namespace chromeos_update_engine
104 
105 #endif  // UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_
106