blob: b9b2ea5be85d48ae1ec8c58693744a6982ff2ee8 [file] [log] [blame]
Christopher Wiley9e1eda92015-11-16 15:23:37 -08001//
Casey Dahlina93cd532016-01-14 16:55:11 -08002// Copyright (C) 2016 The Android Open Source Project
Christopher Wiley9e1eda92015-11-16 15:23:37 -08003//
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_H_
18#define UPDATE_ENGINE_BINDER_SERVICE_H_
19
Christopher Wiley9e1eda92015-11-16 15:23:37 -080020#include <utils/Errors.h>
Christopher Wiley9e1eda92015-11-16 15:23:37 -080021
Casey Dahlin40892492016-01-25 16:55:28 -080022#include <vector>
23
24#include <utils/RefBase.h>
25
Casey Dahlina93cd532016-01-14 16:55:11 -080026#include "update_engine/common_service.h"
27#include "update_engine/parcelable_update_engine_status.h"
28
29#include "android/brillo/BnUpdateEngine.h"
30#include "android/brillo/IUpdateEngineStatusCallback.h"
Christopher Wiley9e1eda92015-11-16 15:23:37 -080031
32namespace chromeos_update_engine {
33
Casey Dahlina93cd532016-01-14 16:55:11 -080034class BinderUpdateEngineService : public android::brillo::BnUpdateEngine {
Christopher Wiley9e1eda92015-11-16 15:23:37 -080035 public:
Casey Dahlina93cd532016-01-14 16:55:11 -080036 BinderUpdateEngineService(SystemState* system_state)
37 : common_(new UpdateEngineService(system_state)) {}
38 virtual ~BinderUpdateEngineService() = default;
Christopher Wiley9e1eda92015-11-16 15:23:37 -080039
Casey Dahlin40892492016-01-25 16:55:28 -080040 void SendStatusUpdate(int64_t in_last_checked_time, double in_progress,
41 const std::string& in_current_operation,
42 const std::string& in_new_version, int64_t in_new_size);
43
Casey Dahlina93cd532016-01-14 16:55:11 -080044 // android::brillo::BnUpdateEngine overrides.
45 android::binder::Status AttemptUpdate(const android::String16& app_version,
46 const android::String16& omaha_url,
47 int flags) override;
48 android::binder::Status AttemptRollback(bool powerwash) override;
49 android::binder::Status CanRollback(bool* out_can_rollback) override;
50 android::binder::Status ResetStatus() override;
51 android::binder::Status GetStatus(
52 android::brillo::ParcelableUpdateEngineStatus* status);
53 android::binder::Status RebootIfNeeded() override;
54 android::binder::Status SetChannel(const android::String16& target_channel,
55 bool powerwash) override;
56 android::binder::Status GetChannel(bool get_current_channel,
57 android::String16* out_channel) override;
58 android::binder::Status SetP2PUpdatePermission(bool enabled) override;
59 android::binder::Status GetP2PUpdatePermission(
60 bool* out_p2p_permission) override;
61 android::binder::Status SetUpdateOverCellularPermission(
62 bool enabled) override;
63 android::binder::Status GetUpdateOverCellularPermission(
64 bool* out_cellular_permission) override;
65 android::binder::Status GetDurationSinceUpdate(
66 int64_t* out_duration) override;
67 android::binder::Status GetPrevVersion(
68 android::String16* out_prev_version) override;
69 android::binder::Status GetRollbackPartition(
70 android::String16* out_rollback_partition) override;
71 android::binder::Status RegisterStatusCallback(
72 const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
73 override;
Tao Baoe78e3fb2016-01-04 17:57:53 -080074
Casey Dahlina93cd532016-01-14 16:55:11 -080075 private:
Casey Dahlin40892492016-01-25 16:55:28 -080076 // Generic function for dispatching to the common service.
Casey Dahlina93cd532016-01-14 16:55:11 -080077 template<typename... Parameters, typename... Arguments>
78 android::binder::Status CallCommonHandler(
79 bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
80 Arguments... arguments);
Christopher Wiley9e1eda92015-11-16 15:23:37 -080081
Casey Dahlin40892492016-01-25 16:55:28 -080082 // To be used as a death notification handler only.
83 void UnregisterStatusCallback(
84 android::brillo::IUpdateEngineStatusCallback* callback);
85
Casey Dahlina93cd532016-01-14 16:55:11 -080086 std::unique_ptr<UpdateEngineService> common_;
Casey Dahlin40892492016-01-25 16:55:28 -080087
88 std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
89 callbacks_;
Christopher Wiley9e1eda92015-11-16 15:23:37 -080090}; // class BinderService
91
92} // namespace chromeos_update_engine
93
94#endif // UPDATE_ENGINE_BINDER_SERVICE_H_