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 17 #ifndef UPDATE_ENGINE_AOSP_BINDER_SERVICE_STABLE_ANDROID_H_ 18 #define UPDATE_ENGINE_AOSP_BINDER_SERVICE_STABLE_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/BnUpdateEngineStable.h" 30 #include "android/os/IUpdateEngineStableCallback.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 BinderUpdateEngineAndroidStableService 37 : public android::os::BnUpdateEngineStable, 38 public ServiceObserverInterface { 39 public: 40 explicit BinderUpdateEngineAndroidStableService( 41 ServiceDelegateAndroidInterface* service_delegate); 42 ~BinderUpdateEngineAndroidStableService() override = default; 43 ServiceName()44 const char* ServiceName() const { 45 return "android.os.UpdateEngineStableService"; 46 } 47 48 // ServiceObserverInterface overrides. 49 void SendStatusUpdate( 50 const update_engine::UpdateEngineStatus& update_engine_status) override; 51 void SendPayloadApplicationComplete(ErrorCode error_code) override; 52 53 // android::os::BnUpdateEngineStable overrides. 54 android::binder::Status applyPayloadFd( 55 const ::android::os::ParcelFileDescriptor& pfd, 56 int64_t payload_offset, 57 int64_t payload_size, 58 const std::vector<android::String16>& header_kv_pairs) override; 59 android::binder::Status bind( 60 const android::sp<android::os::IUpdateEngineStableCallback>& callback, 61 bool* return_value) override; 62 android::binder::Status unbind( 63 const android::sp<android::os::IUpdateEngineStableCallback>& callback, 64 bool* return_value) override; 65 66 private: 67 // Remove the passed |callback| from the list of registered callbacks. Called 68 // on unbind() or whenever the callback object is destroyed. 69 // Returns true on success. 70 bool UnbindCallback(const IBinder* callback); 71 72 // Bound callback. The stable interface only supports one callback at a time. 73 android::sp<android::os::IUpdateEngineStableCallback> callback_; 74 75 // Cached copy of the last status update sent. Used to send an initial 76 // notification when bind() is called from the client. 77 int last_status_{-1}; 78 double last_progress_{0.0}; 79 80 ServiceDelegateAndroidInterface* service_delegate_; 81 }; 82 83 } // namespace chromeos_update_engine 84 85 #endif // UPDATE_ENGINE_AOSP_BINDER_SERVICE_STABLE_ANDROID_H_ 86