blob: 99aa76b71108f4a5cb5dd1ec11376fa6e1e7eb4f [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
Alex Deymofa78f142016-01-26 21:36:16 -080017#ifndef UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
18#define UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
Christopher Wiley9e1eda92015-11-16 15:23:37 -080019
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"
Alex Deymofa78f142016-01-26 21:36:16 -080028#include "update_engine/service_observer_interface.h"
Casey Dahlina93cd532016-01-14 16:55:11 -080029
30#include "android/brillo/BnUpdateEngine.h"
31#include "android/brillo/IUpdateEngineStatusCallback.h"
Christopher Wiley9e1eda92015-11-16 15:23:37 -080032
33namespace chromeos_update_engine {
34
Alex Deymofa78f142016-01-26 21:36:16 -080035class BinderUpdateEngineBrilloService : public android::brillo::BnUpdateEngine,
36 public ServiceObserverInterface {
Christopher Wiley9e1eda92015-11-16 15:23:37 -080037 public:
Alex Deymofa78f142016-01-26 21:36:16 -080038 BinderUpdateEngineBrilloService(SystemState* system_state)
Casey Dahlina93cd532016-01-14 16:55:11 -080039 : common_(new UpdateEngineService(system_state)) {}
Alex Deymofa78f142016-01-26 21:36:16 -080040 virtual ~BinderUpdateEngineBrilloService() = default;
Christopher Wiley9e1eda92015-11-16 15:23:37 -080041
Alex Deymofa78f142016-01-26 21:36:16 -080042 const char* ServiceName() const {
43 return "android.brillo.UpdateEngineService";
44 }
45
46 // ServiceObserverInterface overrides.
47 void SendStatusUpdate(int64_t last_checked_time,
48 double progress,
49 update_engine::UpdateStatus status,
50 const std::string& new_version,
51 int64_t new_size) override;
52 // Channel tracking changes are ignored.
53 void SendChannelChangeUpdate(const std::string& tracking_channel) override {}
Casey Dahlin40892492016-01-25 16:55:28 -080054
Casey Dahlina93cd532016-01-14 16:55:11 -080055 // android::brillo::BnUpdateEngine overrides.
56 android::binder::Status AttemptUpdate(const android::String16& app_version,
57 const android::String16& omaha_url,
58 int flags) override;
59 android::binder::Status AttemptRollback(bool powerwash) override;
60 android::binder::Status CanRollback(bool* out_can_rollback) override;
61 android::binder::Status ResetStatus() override;
62 android::binder::Status GetStatus(
63 android::brillo::ParcelableUpdateEngineStatus* status);
64 android::binder::Status RebootIfNeeded() override;
65 android::binder::Status SetChannel(const android::String16& target_channel,
66 bool powerwash) override;
67 android::binder::Status GetChannel(bool get_current_channel,
68 android::String16* out_channel) override;
69 android::binder::Status SetP2PUpdatePermission(bool enabled) override;
70 android::binder::Status GetP2PUpdatePermission(
71 bool* out_p2p_permission) override;
72 android::binder::Status SetUpdateOverCellularPermission(
73 bool enabled) override;
74 android::binder::Status GetUpdateOverCellularPermission(
75 bool* out_cellular_permission) override;
76 android::binder::Status GetDurationSinceUpdate(
77 int64_t* out_duration) override;
78 android::binder::Status GetPrevVersion(
79 android::String16* out_prev_version) override;
80 android::binder::Status GetRollbackPartition(
81 android::String16* out_rollback_partition) override;
82 android::binder::Status RegisterStatusCallback(
83 const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
84 override;
Tao Baoe78e3fb2016-01-04 17:57:53 -080085
Casey Dahlina93cd532016-01-14 16:55:11 -080086 private:
Casey Dahlin40892492016-01-25 16:55:28 -080087 // Generic function for dispatching to the common service.
Alex Deymofa78f142016-01-26 21:36:16 -080088 template <typename... Parameters, typename... Arguments>
Casey Dahlina93cd532016-01-14 16:55:11 -080089 android::binder::Status CallCommonHandler(
90 bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
91 Arguments... arguments);
Christopher Wiley9e1eda92015-11-16 15:23:37 -080092
Casey Dahlin40892492016-01-25 16:55:28 -080093 // To be used as a death notification handler only.
94 void UnregisterStatusCallback(
95 android::brillo::IUpdateEngineStatusCallback* callback);
96
Casey Dahlina93cd532016-01-14 16:55:11 -080097 std::unique_ptr<UpdateEngineService> common_;
Casey Dahlin40892492016-01-25 16:55:28 -080098
99 std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
100 callbacks_;
Alex Deymofa78f142016-01-26 21:36:16 -0800101};
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800102
103} // namespace chromeos_update_engine
104
Alex Deymofa78f142016-01-26 21:36:16 -0800105#endif // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_