• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2016 The Android Open Source Project
3 //
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 
17 #ifndef UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
18 #define UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
19 
20 #include <utils/Errors.h>
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include <utils/RefBase.h>
27 
28 #include "update_engine/common_service.h"
29 #include "update_engine/parcelable_update_engine_status.h"
30 #include "update_engine/service_observer_interface.h"
31 
32 #include "android/brillo/BnUpdateEngine.h"
33 #include "android/brillo/IUpdateEngineStatusCallback.h"
34 
35 namespace chromeos_update_engine {
36 
37 class BinderUpdateEngineBrilloService : public android::brillo::BnUpdateEngine,
38                                         public ServiceObserverInterface {
39  public:
BinderUpdateEngineBrilloService(SystemState * system_state)40   explicit BinderUpdateEngineBrilloService(SystemState* system_state)
41       : common_(new UpdateEngineService(system_state)) {}
42   virtual ~BinderUpdateEngineBrilloService() = default;
43 
ServiceName()44   const char* ServiceName() const {
45     return "android.brillo.UpdateEngineService";
46   }
47 
48   // ServiceObserverInterface overrides.
49   void SendStatusUpdate(
50       const update_engine::UpdateEngineStatus& update_engine_status) override;
SendPayloadApplicationComplete(ErrorCode error_code)51   void SendPayloadApplicationComplete(ErrorCode error_code) override {}
52 
53   // android::brillo::BnUpdateEngine overrides.
54   android::binder::Status SetUpdateAttemptFlags(int flags) override;
55   android::binder::Status AttemptUpdate(const android::String16& app_version,
56                                         const android::String16& omaha_url,
57                                         int flags,
58                                         bool* out_result) override;
59   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;
69   android::binder::Status SetCohortHint(
70       const android::String16& cohort_hint) override;
71   android::binder::Status GetCohortHint(
72       android::String16* out_cohort_hint) override;
73   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;
78   android::binder::Status GetUpdateOverCellularPermission(
79       bool* out_cellular_permission) override;
80   android::binder::Status GetDurationSinceUpdate(
81       int64_t* out_duration) override;
82   android::binder::Status GetPrevVersion(
83       android::String16* out_prev_version) override;
84   android::binder::Status GetRollbackPartition(
85       android::String16* out_rollback_partition) override;
86   android::binder::Status RegisterStatusCallback(
87       const android::sp<android::brillo::IUpdateEngineStatusCallback>& callback)
88       override;
89   android::binder::Status GetLastAttemptError(
90       int* out_last_attempt_error) override;
91   android::binder::Status GetEolStatus(int* out_eol_status) override;
92 
93  private:
94   // Generic function for dispatching to the common service.
95   template <typename... Parameters, typename... Arguments>
96   android::binder::Status CallCommonHandler(
97       bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...),
98       Arguments... arguments);
99 
100   // To be used as a death notification handler only.
101   void UnregisterStatusCallback(
102       android::brillo::IUpdateEngineStatusCallback* callback);
103 
104   std::unique_ptr<UpdateEngineService> common_;
105 
106   std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>>
107       callbacks_;
108 };
109 
110 }  // namespace chromeos_update_engine
111 
112 #endif  // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_
113