19e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley//
2a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// Copyright (C) 2016 The Android Open Source Project
39e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley//
49e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley// Licensed under the Apache License, Version 2.0 (the "License");
59e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley// you may not use this file except in compliance with the License.
69e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley// You may obtain a copy of the License at
79e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley//
89e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley//      http://www.apache.org/licenses/LICENSE-2.0
99e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley//
109e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley// Unless required by applicable law or agreed to in writing, software
119e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley// distributed under the License is distributed on an "AS IS" BASIS,
129e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley// See the License for the specific language governing permissions and
149e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley// limitations under the License.
159e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley//
169e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley
17fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo#ifndef UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
18fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo#define UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
199e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley
209e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley#include <utils/Errors.h>
219e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley
225b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo#include <memory>
23f8bfcff8debbcbbb572fdd61e640efe2a3df31dcAlex Deymo#include <string>
2440892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin#include <vector>
2540892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin
2640892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin#include <utils/RefBase.h>
2740892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin
28a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#include "update_engine/common_service.h"
29a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#include "update_engine/parcelable_update_engine_status.h"
30fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo#include "update_engine/service_observer_interface.h"
31a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin
32a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#include "android/brillo/BnUpdateEngine.h"
33a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#include "android/brillo/IUpdateEngineStatusCallback.h"
349e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley
359e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wileynamespace chromeos_update_engine {
369e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley
37fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymoclass BinderUpdateEngineBrilloService : public android::brillo::BnUpdateEngine,
38fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo                                        public ServiceObserverInterface {
399e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley public:
40f8bfcff8debbcbbb572fdd61e640efe2a3df31dcAlex Deymo  explicit BinderUpdateEngineBrilloService(SystemState* system_state)
41a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      : common_(new UpdateEngineService(system_state)) {}
42fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo  virtual ~BinderUpdateEngineBrilloService() = default;
439e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley
44fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo  const char* ServiceName() const {
45fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo    return "android.brillo.UpdateEngineService";
46fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo  }
47fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo
48fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo  // ServiceObserverInterface overrides.
49fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo  void SendStatusUpdate(int64_t last_checked_time,
50fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo                        double progress,
51fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo                        update_engine::UpdateStatus status,
52fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo                        const std::string& new_version,
53fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo                        int64_t new_size) override;
54f8bfcff8debbcbbb572fdd61e640efe2a3df31dcAlex Deymo  void SendPayloadApplicationComplete(ErrorCode error_code) override {}
55fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo  // Channel tracking changes are ignored.
56fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo  void SendChannelChangeUpdate(const std::string& tracking_channel) override {}
5740892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin
58a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  // android::brillo::BnUpdateEngine overrides.
59a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status AttemptUpdate(const android::String16& app_version,
60a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin                                        const android::String16& omaha_url,
61a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin                                        int flags) override;
62a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status AttemptRollback(bool powerwash) override;
63a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status CanRollback(bool* out_can_rollback) override;
64a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status ResetStatus() override;
65a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status GetStatus(
66a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      android::brillo::ParcelableUpdateEngineStatus* status);
67a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status RebootIfNeeded() override;
68a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status SetChannel(const android::String16& target_channel,
69a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin                                     bool powerwash) override;
70a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status GetChannel(bool get_current_channel,
71a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin                                     android::String16* out_channel) override;
725b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo  android::binder::Status SetCohortHint(
735b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo      const android::String16& cohort_hint) override;
745b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo  android::binder::Status GetCohortHint(
755b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo      android::String16* out_cohort_hint) override;
76a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status SetP2PUpdatePermission(bool enabled) override;
77a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status GetP2PUpdatePermission(
78a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      bool* out_p2p_permission) override;
79a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status SetUpdateOverCellularPermission(
80a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      bool enabled) override;
81a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status GetUpdateOverCellularPermission(
82a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      bool* out_cellular_permission) override;
83a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status GetDurationSinceUpdate(
84a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      int64_t* out_duration) override;
85a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status GetPrevVersion(
86a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      android::String16* out_prev_version) override;
87a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status GetRollbackPartition(
88a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      android::String16* out_rollback_partition) override;
89a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status RegisterStatusCallback(
90a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
91a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      override;
922997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao  android::binder::Status GetLastAttemptError(
932997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao      int* out_last_attempt_error) override;
94b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo  android::binder::Status GetEolStatus(int* out_eol_status) override;
959e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley
96a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin private:
9740892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  // Generic function for dispatching to the common service.
98fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo  template <typename... Parameters, typename... Arguments>
99a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::binder::Status CallCommonHandler(
100a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
101a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin      Arguments... arguments);
1029e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley
10340892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  // To be used as a death notification handler only.
10440892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  void UnregisterStatusCallback(
10540892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin      android::brillo::IUpdateEngineStatusCallback* callback);
10640892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin
107a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  std::unique_ptr<UpdateEngineService> common_;
10840892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin
10940892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
11040892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin      callbacks_;
111fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo};
1129e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley
1139e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley}  // namespace chromeos_update_engine
1149e1eda984560c8aadd394f3c7c40d17b4dfe22edChristopher Wiley
115fa78f14d818e8e0b8ed5d05ebc389bf833342e7aAlex Deymo#endif  // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
116