xref: /aosp_15_r20/system/update_engine/aosp/binder_service_android.h (revision 5a9231315b4521097b8dc3750bc806fcafe0c72f)
1*5a923131SAndroid Build Coastguard Worker //
2*5a923131SAndroid Build Coastguard Worker // Copyright (C) 2015 The Android Open Source Project
3*5a923131SAndroid Build Coastguard Worker //
4*5a923131SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
5*5a923131SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
6*5a923131SAndroid Build Coastguard Worker // You may obtain a copy of the License at
7*5a923131SAndroid Build Coastguard Worker //
8*5a923131SAndroid Build Coastguard Worker //      http://www.apache.org/licenses/LICENSE-2.0
9*5a923131SAndroid Build Coastguard Worker //
10*5a923131SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
11*5a923131SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
12*5a923131SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*5a923131SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
14*5a923131SAndroid Build Coastguard Worker // limitations under the License.
15*5a923131SAndroid Build Coastguard Worker //
16*5a923131SAndroid Build Coastguard Worker 
17*5a923131SAndroid Build Coastguard Worker #ifndef UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_
18*5a923131SAndroid Build Coastguard Worker #define UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_
19*5a923131SAndroid Build Coastguard Worker 
20*5a923131SAndroid Build Coastguard Worker #include <stdint.h>
21*5a923131SAndroid Build Coastguard Worker 
22*5a923131SAndroid Build Coastguard Worker #include <string>
23*5a923131SAndroid Build Coastguard Worker #include <vector>
24*5a923131SAndroid Build Coastguard Worker 
25*5a923131SAndroid Build Coastguard Worker #include <utils/Errors.h>
26*5a923131SAndroid Build Coastguard Worker #include <utils/String16.h>
27*5a923131SAndroid Build Coastguard Worker #include <utils/StrongPointer.h>
28*5a923131SAndroid Build Coastguard Worker 
29*5a923131SAndroid Build Coastguard Worker #include "android/os/BnUpdateEngine.h"
30*5a923131SAndroid Build Coastguard Worker #include "android/os/IUpdateEngineCallback.h"
31*5a923131SAndroid Build Coastguard Worker #include "update_engine/aosp/service_delegate_android_interface.h"
32*5a923131SAndroid Build Coastguard Worker #include "update_engine/common/service_observer_interface.h"
33*5a923131SAndroid Build Coastguard Worker 
34*5a923131SAndroid Build Coastguard Worker namespace chromeos_update_engine {
35*5a923131SAndroid Build Coastguard Worker 
36*5a923131SAndroid Build Coastguard Worker class BinderUpdateEngineAndroidService final
37*5a923131SAndroid Build Coastguard Worker     : public android::os::BnUpdateEngine,
38*5a923131SAndroid Build Coastguard Worker       public ServiceObserverInterface {
39*5a923131SAndroid Build Coastguard Worker  public:
40*5a923131SAndroid Build Coastguard Worker   explicit BinderUpdateEngineAndroidService(
41*5a923131SAndroid Build Coastguard Worker       ServiceDelegateAndroidInterface* service_delegate);
42*5a923131SAndroid Build Coastguard Worker   ~BinderUpdateEngineAndroidService() override = default;
43*5a923131SAndroid Build Coastguard Worker 
ServiceName()44*5a923131SAndroid Build Coastguard Worker   const char* ServiceName() const { return "android.os.UpdateEngineService"; }
45*5a923131SAndroid Build Coastguard Worker 
46*5a923131SAndroid Build Coastguard Worker   // ServiceObserverInterface overrides.
47*5a923131SAndroid Build Coastguard Worker   void SendStatusUpdate(
48*5a923131SAndroid Build Coastguard Worker       const update_engine::UpdateEngineStatus& update_engine_status) override;
49*5a923131SAndroid Build Coastguard Worker   void SendPayloadApplicationComplete(ErrorCode error_code) override;
50*5a923131SAndroid Build Coastguard Worker 
51*5a923131SAndroid Build Coastguard Worker   // android::os::BnUpdateEngine overrides.
52*5a923131SAndroid Build Coastguard Worker   android::binder::Status applyPayload(
53*5a923131SAndroid Build Coastguard Worker       const android::String16& url,
54*5a923131SAndroid Build Coastguard Worker       int64_t payload_offset,
55*5a923131SAndroid Build Coastguard Worker       int64_t payload_size,
56*5a923131SAndroid Build Coastguard Worker       const std::vector<android::String16>& header_kv_pairs) override;
57*5a923131SAndroid Build Coastguard Worker   android::binder::Status applyPayloadFd(
58*5a923131SAndroid Build Coastguard Worker       const ::android::os::ParcelFileDescriptor& pfd,
59*5a923131SAndroid Build Coastguard Worker       int64_t payload_offset,
60*5a923131SAndroid Build Coastguard Worker       int64_t payload_size,
61*5a923131SAndroid Build Coastguard Worker       const std::vector<android::String16>& header_kv_pairs) override;
62*5a923131SAndroid Build Coastguard Worker   android::binder::Status bind(
63*5a923131SAndroid Build Coastguard Worker       const android::sp<android::os::IUpdateEngineCallback>& callback,
64*5a923131SAndroid Build Coastguard Worker       bool* return_value) override;
65*5a923131SAndroid Build Coastguard Worker   android::binder::Status unbind(
66*5a923131SAndroid Build Coastguard Worker       const android::sp<android::os::IUpdateEngineCallback>& callback,
67*5a923131SAndroid Build Coastguard Worker       bool* return_value) override;
68*5a923131SAndroid Build Coastguard Worker   android::binder::Status suspend() override;
69*5a923131SAndroid Build Coastguard Worker   android::binder::Status resume() override;
70*5a923131SAndroid Build Coastguard Worker   android::binder::Status cancel() override;
71*5a923131SAndroid Build Coastguard Worker   android::binder::Status resetStatus() override;
72*5a923131SAndroid Build Coastguard Worker   android::binder::Status setShouldSwitchSlotOnReboot(
73*5a923131SAndroid Build Coastguard Worker       const android::String16& metadata_filename) override;
74*5a923131SAndroid Build Coastguard Worker   android::binder::Status resetShouldSwitchSlotOnReboot() override;
75*5a923131SAndroid Build Coastguard Worker   android::binder::Status verifyPayloadApplicable(
76*5a923131SAndroid Build Coastguard Worker       const android::String16& metadata_filename, bool* return_value) override;
77*5a923131SAndroid Build Coastguard Worker   android::binder::Status allocateSpaceForPayload(
78*5a923131SAndroid Build Coastguard Worker       const android::String16& metadata_filename,
79*5a923131SAndroid Build Coastguard Worker       const std::vector<android::String16>& header_kv_pairs,
80*5a923131SAndroid Build Coastguard Worker       int64_t* return_value) override;
81*5a923131SAndroid Build Coastguard Worker   android::binder::Status cleanupSuccessfulUpdate(
82*5a923131SAndroid Build Coastguard Worker       const android::sp<android::os::IUpdateEngineCallback>& callback) override;
83*5a923131SAndroid Build Coastguard Worker   ::android::binder::Status triggerPostinstall(
84*5a923131SAndroid Build Coastguard Worker       const ::android::String16& partition) override;
85*5a923131SAndroid Build Coastguard Worker 
86*5a923131SAndroid Build Coastguard Worker  private:
87*5a923131SAndroid Build Coastguard Worker   // Remove the passed |callback| from the list of registered callbacks. Called
88*5a923131SAndroid Build Coastguard Worker   // on unbind() or whenever the callback object is destroyed.
89*5a923131SAndroid Build Coastguard Worker   // Returns true on success.
90*5a923131SAndroid Build Coastguard Worker   bool UnbindCallback(const IBinder* callback);
91*5a923131SAndroid Build Coastguard Worker 
92*5a923131SAndroid Build Coastguard Worker   // List of currently bound callbacks.
93*5a923131SAndroid Build Coastguard Worker   std::vector<android::sp<android::os::IUpdateEngineCallback>> callbacks_;
94*5a923131SAndroid Build Coastguard Worker 
95*5a923131SAndroid Build Coastguard Worker   // Cached copy of the last status update sent. Used to send an initial
96*5a923131SAndroid Build Coastguard Worker   // notification when bind() is called from the client.
97*5a923131SAndroid Build Coastguard Worker   int last_status_{-1};
98*5a923131SAndroid Build Coastguard Worker   double last_progress_{0.0};
99*5a923131SAndroid Build Coastguard Worker 
100*5a923131SAndroid Build Coastguard Worker   ServiceDelegateAndroidInterface* service_delegate_;
101*5a923131SAndroid Build Coastguard Worker };
102*5a923131SAndroid Build Coastguard Worker 
103*5a923131SAndroid Build Coastguard Worker }  // namespace chromeos_update_engine
104*5a923131SAndroid Build Coastguard Worker 
105*5a923131SAndroid Build Coastguard Worker #endif  // UPDATE_ENGINE_AOSP_BINDER_SERVICE_ANDROID_H_
106