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_CLIENT_LIBRARY_CLIENT_BINDER_H_ 18 #define UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_ 19 20 #include <cstdint> 21 #include <memory> 22 #include <string> 23 #include <vector> 24 25 #include <base/macros.h> 26 #include <utils/String16.h> 27 #include <utils/StrongPointer.h> 28 29 #include <brillo/binder_watcher.h> 30 31 #include "android/brillo/BnUpdateEngineStatusCallback.h" 32 #include "android/brillo/IUpdateEngine.h" 33 34 #include "update_engine/client_library/include/update_engine/client.h" 35 36 namespace update_engine { 37 namespace internal { 38 39 class BinderUpdateEngineClient : public UpdateEngineClient { 40 public: 41 BinderUpdateEngineClient() = default; 42 bool Init(); 43 44 virtual ~BinderUpdateEngineClient() = default; 45 46 bool AttemptUpdate(const std::string& app_version, 47 const std::string& omaha_url, 48 bool at_user_request) override; 49 50 bool GetStatus(int64_t* out_last_checked_time, 51 double* out_progress, 52 UpdateStatus* out_update_status, 53 std::string* out_new_version, 54 int64_t* out_new_size) const override; 55 56 bool SetCohortHint(const std::string& in_cohort_hint) override; 57 bool GetCohortHint(std::string* out_cohort_hint) const override; 58 59 bool SetUpdateOverCellularPermission(bool allowed) override; 60 bool GetUpdateOverCellularPermission(bool* allowed) const override; 61 62 bool SetP2PUpdatePermission(bool enabled) override; 63 bool GetP2PUpdatePermission(bool* enabled) const override; 64 65 bool Rollback(bool powerwash) override; 66 67 bool GetRollbackPartition(std::string* rollback_partition) const override; 68 69 void RebootIfNeeded() override; 70 71 bool GetPrevVersion(std::string* prev_version) const override; 72 73 bool ResetStatus() override; 74 75 bool SetTargetChannel(const std::string& target_channel, 76 bool allow_powerwash) override; 77 78 bool GetTargetChannel(std::string* out_channel) const override; 79 80 bool GetChannel(std::string* out_channel) const override; 81 82 bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override; 83 bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override; 84 85 bool GetLastAttemptError(int32_t* last_attempt_error) const override; 86 87 bool GetEolStatus(int32_t* eol_status) const override; 88 89 private: 90 class StatusUpdateCallback : 91 public android::brillo::BnUpdateEngineStatusCallback { 92 public: StatusUpdateCallback(BinderUpdateEngineClient * client)93 explicit StatusUpdateCallback(BinderUpdateEngineClient* client) 94 : client_(client) {} 95 96 android::binder::Status HandleStatusUpdate( 97 int64_t last_checked_time, 98 double progress, 99 const android::String16& current_operation, 100 const android::String16& new_version, 101 int64_t new_size) override; 102 103 private: 104 BinderUpdateEngineClient* client_; 105 }; 106 107 android::sp<android::brillo::IUpdateEngine> service_; 108 android::sp<android::brillo::IUpdateEngineStatusCallback> status_callback_; 109 std::vector<update_engine::StatusUpdateHandler*> handlers_; 110 brillo::BinderWatcher binder_watcher_; 111 112 DISALLOW_COPY_AND_ASSIGN(BinderUpdateEngineClient); 113 }; // class BinderUpdateEngineClient 114 115 } // namespace internal 116 } // namespace update_engine 117 118 #endif // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_ 119