blob: fad0f8c0cde6aebb19b98d8e219724d1b87f2f47 [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 {}
Alex Deymofa78f142016-01-26 21:36:16 -080055 // Channel tracking changes are ignored.
56 void SendChannelChangeUpdate(const std::string& tracking_channel) override {}
Casey Dahlin40892492016-01-25 16:55:28 -080057
Casey Dahlina93cd532016-01-14 16:55:11 -080058 // android::brillo::BnUpdateEngine overrides.
59 android::binder::Status AttemptUpdate(const android::String16& app_version,
60 const android::String16& omaha_url,
61 int flags) override;
62 android::binder::Status AttemptRollback(bool powerwash) override;
63 android::binder::Status CanRollback(bool* out_can_rollback) override;
64 android::binder::Status ResetStatus() override;
65 android::binder::Status GetStatus(
66 android::brillo::ParcelableUpdateEngineStatus* status);
67 android::binder::Status RebootIfNeeded() override;
68 android::binder::Status SetChannel(const android::String16& target_channel,
69 bool powerwash) override;
70 android::binder::Status GetChannel(bool get_current_channel,
71 android::String16* out_channel) override;
Alex Deymo5b5fa8b2016-10-06 15:40:49 -070072 android::binder::Status SetCohortHint(
73 const android::String16& cohort_hint) override;
74 android::binder::Status GetCohortHint(
75 android::String16* out_cohort_hint) override;
Casey Dahlina93cd532016-01-14 16:55:11 -080076 android::binder::Status SetP2PUpdatePermission(bool enabled) override;
77 android::binder::Status GetP2PUpdatePermission(
78 bool* out_p2p_permission) override;
79 android::binder::Status SetUpdateOverCellularPermission(
80 bool enabled) override;
81 android::binder::Status GetUpdateOverCellularPermission(
82 bool* out_cellular_permission) override;
83 android::binder::Status GetDurationSinceUpdate(
84 int64_t* out_duration) override;
85 android::binder::Status GetPrevVersion(
86 android::String16* out_prev_version) override;
87 android::binder::Status GetRollbackPartition(
88 android::String16* out_rollback_partition) override;
89 android::binder::Status RegisterStatusCallback(
90 const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
91 override;
Shuqian Zhao29971732016-02-05 11:29:32 -080092 android::binder::Status GetLastAttemptError(
93 int* out_last_attempt_error) override;
Alex Deymob3fa53b2016-04-18 19:57:58 -070094 android::binder::Status GetEolStatus(int* out_eol_status) override;
Tao Baoe78e3fb2016-01-04 17:57:53 -080095
Casey Dahlina93cd532016-01-14 16:55:11 -080096 private:
Casey Dahlin40892492016-01-25 16:55:28 -080097 // Generic function for dispatching to the common service.
Alex Deymofa78f142016-01-26 21:36:16 -080098 template <typename... Parameters, typename... Arguments>
Casey Dahlina93cd532016-01-14 16:55:11 -080099 android::binder::Status CallCommonHandler(
100 bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
101 Arguments... arguments);
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800102
Casey Dahlin40892492016-01-25 16:55:28 -0800103 // To be used as a death notification handler only.
104 void UnregisterStatusCallback(
105 android::brillo::IUpdateEngineStatusCallback* callback);
106
Casey Dahlina93cd532016-01-14 16:55:11 -0800107 std::unique_ptr<UpdateEngineService> common_;
Casey Dahlin40892492016-01-25 16:55:28 -0800108
109 std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
110 callbacks_;
Alex Deymofa78f142016-01-26 21:36:16 -0800111};
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800112
113} // namespace chromeos_update_engine
114
Alex Deymofa78f142016-01-26 21:36:16 -0800115#endif // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_