blob: d0d0dc92d9f48c81bd45b644c3ae3be532eed1fc [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.
Aaron Wood7f92e2b2017-08-28 14:51:21 -070049 void SendStatusUpdate(
50 const update_engine::UpdateEngineStatus& update_engine_status) override;
Alex Deymof8bfcff2016-02-02 21:22:11 -080051 void SendPayloadApplicationComplete(ErrorCode error_code) override {}
Casey Dahlin40892492016-01-25 16:55:28 -080052
Casey Dahlina93cd532016-01-14 16:55:11 -080053 // android::brillo::BnUpdateEngine overrides.
Aaron Woodbf5a2522017-10-04 10:58:36 -070054 android::binder::Status SetUpdateAttemptFlags(int flags) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080055 android::binder::Status AttemptUpdate(const android::String16& app_version,
56 const android::String16& omaha_url,
Aaron Wood081c0232017-10-19 17:14:58 -070057 int flags,
58 bool* out_result) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080059 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;
Alex Deymo5b5fa8b2016-10-06 15:40:49 -070069 android::binder::Status SetCohortHint(
70 const android::String16& cohort_hint) override;
71 android::binder::Status GetCohortHint(
72 android::String16* out_cohort_hint) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080073 android::binder::Status SetP2PUpdatePermission(bool enabled) override;
74 android::binder::Status GetP2PUpdatePermission(
75 bool* out_p2p_permission) override;
76 android::binder::Status SetUpdateOverCellularPermission(
77 bool enabled) override;
Weidong Guo421ff332017-04-17 10:08:38 -070078 android::binder::Status SetUpdateOverCellularTarget(
79 const android::String16& target_version, int64_t target_size) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080080 android::binder::Status GetUpdateOverCellularPermission(
81 bool* out_cellular_permission) override;
82 android::binder::Status GetDurationSinceUpdate(
83 int64_t* out_duration) override;
84 android::binder::Status GetPrevVersion(
85 android::String16* out_prev_version) override;
86 android::binder::Status GetRollbackPartition(
87 android::String16* out_rollback_partition) override;
88 android::binder::Status RegisterStatusCallback(
89 const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
90 override;
Shuqian Zhao29971732016-02-05 11:29:32 -080091 android::binder::Status GetLastAttemptError(
92 int* out_last_attempt_error) override;
Alex Deymob3fa53b2016-04-18 19:57:58 -070093 android::binder::Status GetEolStatus(int* out_eol_status) override;
Tao Baoe78e3fb2016-01-04 17:57:53 -080094
Casey Dahlina93cd532016-01-14 16:55:11 -080095 private:
Casey Dahlin40892492016-01-25 16:55:28 -080096 // Generic function for dispatching to the common service.
Alex Deymofa78f142016-01-26 21:36:16 -080097 template <typename... Parameters, typename... Arguments>
Casey Dahlina93cd532016-01-14 16:55:11 -080098 android::binder::Status CallCommonHandler(
99 bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
100 Arguments... arguments);
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800101
Casey Dahlin40892492016-01-25 16:55:28 -0800102 // To be used as a death notification handler only.
103 void UnregisterStatusCallback(
104 android::brillo::IUpdateEngineStatusCallback* callback);
105
Casey Dahlina93cd532016-01-14 16:55:11 -0800106 std::unique_ptr<UpdateEngineService> common_;
Casey Dahlin40892492016-01-25 16:55:28 -0800107
108 std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
109 callbacks_;
Alex Deymofa78f142016-01-26 21:36:16 -0800110};
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800111
112} // namespace chromeos_update_engine
113
Alex Deymofa78f142016-01-26 21:36:16 -0800114#endif // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_