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 <string> 23 #include <vector> 24 25 #include <utils/RefBase.h> 26 27 #include "update_engine/common_service.h" 28 #include "update_engine/parcelable_update_engine_status.h" 29 #include "update_engine/service_observer_interface.h" 30 31 #include "android/brillo/BnUpdateEngine.h" 32 #include "android/brillo/IUpdateEngineStatusCallback.h" 33 34 namespace chromeos_update_engine { 35 36 class BinderUpdateEngineBrilloService : public android::brillo::BnUpdateEngine, 37 public ServiceObserverInterface { 38 public: BinderUpdateEngineBrilloService(SystemState * system_state)39 explicit BinderUpdateEngineBrilloService(SystemState* system_state) 40 : common_(new UpdateEngineService(system_state)) {} 41 virtual ~BinderUpdateEngineBrilloService() = default; 42 ServiceName()43 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; SendPayloadApplicationComplete(ErrorCode error_code)53 void SendPayloadApplicationComplete(ErrorCode error_code) override {} 54 // Channel tracking changes are ignored. SendChannelChangeUpdate(const std::string & tracking_channel)55 void SendChannelChangeUpdate(const std::string& tracking_channel) override {} 56 57 // 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; 87 android::binder::Status GetLastAttemptError( 88 int* out_last_attempt_error) override; 89 90 private: 91 // Generic function for dispatching to the common service. 92 template <typename... Parameters, typename... Arguments> 93 android::binder::Status CallCommonHandler( 94 bool (UpdateEngineService::*Handler)(brillo::ErrorPtr*, Parameters...), 95 Arguments... arguments); 96 97 // To be used as a death notification handler only. 98 void UnregisterStatusCallback( 99 android::brillo::IUpdateEngineStatusCallback* callback); 100 101 std::unique_ptr<UpdateEngineService> common_; 102 103 std::vector<android::sp<android::brillo::IUpdateEngineStatusCallback>> 104 callbacks_; 105 }; 106 107 } // namespace chromeos_update_engine 108 109 #endif // UPDATE_ENGINE_BINDER_SERVICE_BRILLO_H_ 110