blob: 982c7b18188c182b35d527f5cade64bcc21cd833 [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;
79 android::binder::Status GetUpdateOverCellularPermission(
80 bool* out_cellular_permission) override;
81 android::binder::Status GetDurationSinceUpdate(
82 int64_t* out_duration) override;
83 android::binder::Status GetPrevVersion(
84 android::String16* out_prev_version) override;
85 android::binder::Status GetRollbackPartition(
86 android::String16* out_rollback_partition) override;
87 android::binder::Status RegisterStatusCallback(
88 const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
89 override;
Shuqian Zhao29971732016-02-05 11:29:32 -080090 android::binder::Status GetLastAttemptError(
91 int* out_last_attempt_error) override;
Alex Deymob3fa53b2016-04-18 19:57:58 -070092 android::binder::Status GetEolStatus(int* out_eol_status) override;
Tao Baoe78e3fb2016-01-04 17:57:53 -080093
Casey Dahlina93cd532016-01-14 16:55:11 -080094 private:
Casey Dahlin40892492016-01-25 16:55:28 -080095 // Generic function for dispatching to the common service.
Alex Deymofa78f142016-01-26 21:36:16 -080096 template <typename... Parameters, typename... Arguments>
Casey Dahlina93cd532016-01-14 16:55:11 -080097 android::binder::Status CallCommonHandler(
98 bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
99 Arguments... arguments);
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800100
Casey Dahlin40892492016-01-25 16:55:28 -0800101 // To be used as a death notification handler only.
102 void UnregisterStatusCallback(
103 android::brillo::IUpdateEngineStatusCallback* callback);
104
Casey Dahlina93cd532016-01-14 16:55:11 -0800105 std::unique_ptr<UpdateEngineService> common_;
Casey Dahlin40892492016-01-25 16:55:28 -0800106
107 std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
108 callbacks_;
Alex Deymofa78f142016-01-26 21:36:16 -0800109};
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800110
111} // namespace chromeos_update_engine
112
Alex Deymofa78f142016-01-26 21:36:16 -0800113#endif // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_