blob: 4cc007ba6b63b73397bf0b4b98b4998f912a5fcf [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
Alex Deymo5b5fa8b2016-10-06 15:40:49 -070022#include <memory>
Alex Deymof8bfcff2016-02-02 21:22:11 -080023#include <string>
Casey Dahlin40892492016-01-25 16:55:28 -080024#include <vector>
25
26#include <utils/RefBase.h>
27
Casey Dahlina93cd532016-01-14 16:55:11 -080028#include "update_engine/common_service.h"
29#include "update_engine/parcelable_update_engine_status.h"
Alex Deymofa78f142016-01-26 21:36:16 -080030#include "update_engine/service_observer_interface.h"
Casey Dahlina93cd532016-01-14 16:55:11 -080031
32#include "android/brillo/BnUpdateEngine.h"
33#include "android/brillo/IUpdateEngineStatusCallback.h"
Christopher Wiley9e1eda92015-11-16 15:23:37 -080034
35namespace chromeos_update_engine {
36
Alex Deymofa78f142016-01-26 21:36:16 -080037class BinderUpdateEngineBrilloService : public android::brillo::BnUpdateEngine,
38 public ServiceObserverInterface {
Christopher Wiley9e1eda92015-11-16 15:23:37 -080039 public:
Alex Deymof8bfcff2016-02-02 21:22:11 -080040 explicit BinderUpdateEngineBrilloService(SystemState* system_state)
Casey Dahlina93cd532016-01-14 16:55:11 -080041 : common_(new UpdateEngineService(system_state)) {}
Alex Deymofa78f142016-01-26 21:36:16 -080042 virtual ~BinderUpdateEngineBrilloService() = default;
Christopher Wiley9e1eda92015-11-16 15:23:37 -080043
Alex Deymofa78f142016-01-26 21:36:16 -080044 const char* ServiceName() const {
45 return "android.brillo.UpdateEngineService";
46 }
47
48 // ServiceObserverInterface overrides.
49 void SendStatusUpdate(int64_t last_checked_time,
50 double progress,
51 update_engine::UpdateStatus status,
52 const std::string& new_version,
53 int64_t new_size) override;
Alex Deymof8bfcff2016-02-02 21:22:11 -080054 void SendPayloadApplicationComplete(ErrorCode error_code) override {}
Casey Dahlin40892492016-01-25 16:55:28 -080055
Casey Dahlina93cd532016-01-14 16:55:11 -080056 // android::brillo::BnUpdateEngine overrides.
57 android::binder::Status AttemptUpdate(const android::String16& app_version,
58 const android::String16& omaha_url,
59 int flags) override;
60 android::binder::Status AttemptRollback(bool powerwash) override;
61 android::binder::Status CanRollback(bool* out_can_rollback) override;
62 android::binder::Status ResetStatus() override;
63 android::binder::Status GetStatus(
64 android::brillo::ParcelableUpdateEngineStatus* status);
65 android::binder::Status RebootIfNeeded() override;
66 android::binder::Status SetChannel(const android::String16& target_channel,
67 bool powerwash) override;
68 android::binder::Status GetChannel(bool get_current_channel,
69 android::String16* out_channel) override;
Alex Deymo5b5fa8b2016-10-06 15:40:49 -070070 android::binder::Status SetCohortHint(
71 const android::String16& cohort_hint) override;
72 android::binder::Status GetCohortHint(
73 android::String16* out_cohort_hint) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080074 android::binder::Status SetP2PUpdatePermission(bool enabled) override;
75 android::binder::Status GetP2PUpdatePermission(
76 bool* out_p2p_permission) override;
77 android::binder::Status SetUpdateOverCellularPermission(
78 bool enabled) override;
Weidong Guo4b0d6032017-04-17 10:08:38 -070079 android::binder::Status SetUpdateOverCellularTarget(
80 const android::String16& target_version,
81 int64_t target_size) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080082 android::binder::Status GetUpdateOverCellularPermission(
83 bool* out_cellular_permission) override;
84 android::binder::Status GetDurationSinceUpdate(
85 int64_t* out_duration) override;
86 android::binder::Status GetPrevVersion(
87 android::String16* out_prev_version) override;
88 android::binder::Status GetRollbackPartition(
89 android::String16* out_rollback_partition) override;
90 android::binder::Status RegisterStatusCallback(
91 const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
92 override;
Shuqian Zhao29971732016-02-05 11:29:32 -080093 android::binder::Status GetLastAttemptError(
94 int* out_last_attempt_error) override;
Alex Deymob3fa53b2016-04-18 19:57:58 -070095 android::binder::Status GetEolStatus(int* out_eol_status) override;
Tao Baoe78e3fb2016-01-04 17:57:53 -080096
Casey Dahlina93cd532016-01-14 16:55:11 -080097 private:
Casey Dahlin40892492016-01-25 16:55:28 -080098 // Generic function for dispatching to the common service.
Alex Deymofa78f142016-01-26 21:36:16 -080099 template <typename... Parameters, typename... Arguments>
Casey Dahlina93cd532016-01-14 16:55:11 -0800100 android::binder::Status CallCommonHandler(
101 bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
102 Arguments... arguments);
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800103
Casey Dahlin40892492016-01-25 16:55:28 -0800104 // To be used as a death notification handler only.
105 void UnregisterStatusCallback(
106 android::brillo::IUpdateEngineStatusCallback* callback);
107
Casey Dahlina93cd532016-01-14 16:55:11 -0800108 std::unique_ptr<UpdateEngineService> common_;
Casey Dahlin40892492016-01-25 16:55:28 -0800109
110 std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
111 callbacks_;
Alex Deymofa78f142016-01-26 21:36:16 -0800112};
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800113
114} // namespace chromeos_update_engine
115
Alex Deymofa78f142016-01-26 21:36:16 -0800116#endif // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_