blob: 47e76a7651c50b7362045011ce09e94eb31450ec [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
17#ifndef UPDATE_ENGINE_BINDER_SERVICE_ANDROID_H_
18#define UPDATE_ENGINE_BINDER_SERVICE_ANDROID_H_
19
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"
Alex Deymof8bfcff2016-02-02 21:22:11 -080031#include "update_engine/service_delegate_android_interface.h"
Alex Deymofa78f142016-01-26 21:36:16 -080032#include "update_engine/service_observer_interface.h"
Casey Dahlina93cd532016-01-14 16:55:11 -080033
34namespace chromeos_update_engine {
35
Alex Deymofa78f142016-01-26 21:36:16 -080036class BinderUpdateEngineAndroidService : public android::os::BnUpdateEngine,
37 public ServiceObserverInterface {
Casey Dahlina93cd532016-01-14 16:55:11 -080038 public:
Alex Deymof8bfcff2016-02-02 21:22:11 -080039 BinderUpdateEngineAndroidService(
40 ServiceDelegateAndroidInterface* service_delegate);
Alex Deymoe97b39c2016-01-20 13:22:17 -080041 ~BinderUpdateEngineAndroidService() override = default;
Casey Dahlina93cd532016-01-14 16:55:11 -080042
Alex Deymofa78f142016-01-26 21:36:16 -080043 const char* ServiceName() const {
44 return "android.os.UpdateEngineService";
45 }
46
47 // ServiceObserverInterface overrides.
48 void SendStatusUpdate(int64_t last_checked_time,
49 double progress,
50 update_engine::UpdateStatus status,
51 const std::string& new_version,
52 int64_t new_size) override;
Alex Deymof8bfcff2016-02-02 21:22:11 -080053 void SendPayloadApplicationComplete(ErrorCode error_code) override;
Alex Deymofa78f142016-01-26 21:36:16 -080054
55 // Channel tracking changes are ignored.
56 void SendChannelChangeUpdate(const std::string& tracking_channel) override {}
57
58 // android::os::BnUpdateEngine overrides.
Casey Dahlina93cd532016-01-14 16:55:11 -080059 android::binder::Status applyPayload(
60 const android::String16& url,
Alex Deymo95b8f242016-01-28 16:06:57 -080061 int64_t payload_offset,
62 int64_t payload_size,
Casey Dahlina93cd532016-01-14 16:55:11 -080063 const std::vector<android::String16>& header_kv_pairs) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080064 android::binder::Status bind(
65 const android::sp<android::os::IUpdateEngineCallback>& callback,
66 bool* return_value) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080067 android::binder::Status suspend() override;
Casey Dahlina93cd532016-01-14 16:55:11 -080068 android::binder::Status resume() override;
Casey Dahlina93cd532016-01-14 16:55:11 -080069 android::binder::Status cancel() override;
Alex Deymo3b678db2016-02-09 11:50:06 -080070 android::binder::Status resetStatus() override;
Alex Deymof8bfcff2016-02-02 21:22:11 -080071
72 private:
73 // Remove the passed |callback| from the list of registered callbacks. Called
74 // whenever the callback object is destroyed.
75 void UnbindCallback(android::os::IUpdateEngineCallback* callback);
76
77 // List of currently bound callbacks.
78 std::vector<android::sp<android::os::IUpdateEngineCallback>> callbacks_;
79
Alex Deymo0e061ae2016-02-09 17:49:03 -080080 // Cached copy of the last status update sent. Used to send an initial
81 // notification when bind() is called from the client.
82 int last_status_{-1};
83 double last_progress_{0.0};
84
Alex Deymof8bfcff2016-02-02 21:22:11 -080085 ServiceDelegateAndroidInterface* service_delegate_;
Alex Deymoe97b39c2016-01-20 13:22:17 -080086};
Casey Dahlina93cd532016-01-14 16:55:11 -080087
88} // namespace chromeos_update_engine
89
90#endif // UPDATE_ENGINE_BINDER_SERVICE_ANDROID_H_