blob: b3bb81f149e1296e4014badf1a62f990e4434966 [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 Deymof8bfcff2016-02-02 21:22:11 -080022#include <string>
Casey Dahlin40892492016-01-25 16:55:28 -080023#include <vector>
24
25#include <utils/RefBase.h>
26
Casey Dahlina93cd532016-01-14 16:55:11 -080027#include "update_engine/common_service.h"
28#include "update_engine/parcelable_update_engine_status.h"
Alex Deymofa78f142016-01-26 21:36:16 -080029#include "update_engine/service_observer_interface.h"
Casey Dahlina93cd532016-01-14 16:55:11 -080030
31#include "android/brillo/BnUpdateEngine.h"
32#include "android/brillo/IUpdateEngineStatusCallback.h"
Christopher Wiley9e1eda92015-11-16 15:23:37 -080033
34namespace chromeos_update_engine {
35
Alex Deymofa78f142016-01-26 21:36:16 -080036class BinderUpdateEngineBrilloService : public android::brillo::BnUpdateEngine,
37 public ServiceObserverInterface {
Christopher Wiley9e1eda92015-11-16 15:23:37 -080038 public:
Alex Deymof8bfcff2016-02-02 21:22:11 -080039 explicit BinderUpdateEngineBrilloService(SystemState* system_state)
Casey Dahlina93cd532016-01-14 16:55:11 -080040 : common_(new UpdateEngineService(system_state)) {}
Alex Deymofa78f142016-01-26 21:36:16 -080041 virtual ~BinderUpdateEngineBrilloService() = default;
Christopher Wiley9e1eda92015-11-16 15:23:37 -080042
Alex Deymofa78f142016-01-26 21:36:16 -080043 const char* ServiceName() const {
44 return "android.brillo.UpdateEngineService";
45 }
46
47 // ServiceObserverInterface overrides.
48 void SendStatusUpdate(int64_t last_checked_time,
49 double progress,
50 update_engine::UpdateStatus status,
51 const std::string& new_version,
52 int64_t new_size) override;
Alex Deymof8bfcff2016-02-02 21:22:11 -080053 void SendPayloadApplicationComplete(ErrorCode error_code) override {}
Alex Deymofa78f142016-01-26 21:36:16 -080054 // Channel tracking changes are ignored.
55 void SendChannelChangeUpdate(const std::string& tracking_channel) override {}
Casey Dahlin40892492016-01-25 16:55:28 -080056
Casey Dahlina93cd532016-01-14 16:55:11 -080057 // android::brillo::BnUpdateEngine overrides.
58 android::binder::Status AttemptUpdate(const android::String16& app_version,
59 const android::String16& omaha_url,
60 int flags) override;
61 android::binder::Status AttemptRollback(bool powerwash) override;
62 android::binder::Status CanRollback(bool* out_can_rollback) override;
63 android::binder::Status ResetStatus() override;
64 android::binder::Status GetStatus(
65 android::brillo::ParcelableUpdateEngineStatus* status);
66 android::binder::Status RebootIfNeeded() override;
67 android::binder::Status SetChannel(const android::String16& target_channel,
68 bool powerwash) override;
69 android::binder::Status GetChannel(bool get_current_channel,
70 android::String16* out_channel) override;
71 android::binder::Status SetP2PUpdatePermission(bool enabled) override;
72 android::binder::Status GetP2PUpdatePermission(
73 bool* out_p2p_permission) override;
74 android::binder::Status SetUpdateOverCellularPermission(
75 bool enabled) override;
76 android::binder::Status GetUpdateOverCellularPermission(
77 bool* out_cellular_permission) override;
78 android::binder::Status GetDurationSinceUpdate(
79 int64_t* out_duration) override;
80 android::binder::Status GetPrevVersion(
81 android::String16* out_prev_version) override;
82 android::binder::Status GetRollbackPartition(
83 android::String16* out_rollback_partition) override;
84 android::binder::Status RegisterStatusCallback(
85 const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
86 override;
Shuqian Zhao29971732016-02-05 11:29:32 -080087 android::binder::Status GetLastAttemptError(
88 int* out_last_attempt_error) override;
Alex Deymob3fa53b2016-04-18 19:57:58 -070089 android::binder::Status GetEolStatus(int* out_eol_status) override;
Tao Baoe78e3fb2016-01-04 17:57:53 -080090
Casey Dahlina93cd532016-01-14 16:55:11 -080091 private:
Casey Dahlin40892492016-01-25 16:55:28 -080092 // Generic function for dispatching to the common service.
Alex Deymofa78f142016-01-26 21:36:16 -080093 template <typename... Parameters, typename... Arguments>
Casey Dahlina93cd532016-01-14 16:55:11 -080094 android::binder::Status CallCommonHandler(
95 bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
96 Arguments... arguments);
Christopher Wiley9e1eda92015-11-16 15:23:37 -080097
Casey Dahlin40892492016-01-25 16:55:28 -080098 // To be used as a death notification handler only.
99 void UnregisterStatusCallback(
100 android::brillo::IUpdateEngineStatusCallback* callback);
101
Casey Dahlina93cd532016-01-14 16:55:11 -0800102 std::unique_ptr<UpdateEngineService> common_;
Casey Dahlin40892492016-01-25 16:55:28 -0800103
104 std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
105 callbacks_;
Alex Deymofa78f142016-01-26 21:36:16 -0800106};
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800107
108} // namespace chromeos_update_engine
109
Alex Deymofa78f142016-01-26 21:36:16 -0800110#endif // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_