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