| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 1 | // | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 2 | // Copyright (C) 2016 The Android Open Source Project | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 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 |  | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_ | 
 | 18 | #define UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_ | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 19 |  | 
 | 20 | #include <cstdint> | 
 | 21 | #include <memory> | 
 | 22 | #include <string> | 
| Casey Dahlin | 4089249 | 2016-01-25 16:55:28 -0800 | [diff] [blame] | 23 | #include <vector> | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 24 |  | 
 | 25 | #include <base/macros.h> | 
| Casey Dahlin | 4089249 | 2016-01-25 16:55:28 -0800 | [diff] [blame] | 26 | #include <utils/String16.h> | 
| Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 27 | #include <utils/StrongPointer.h> | 
| Casey Dahlin | 4089249 | 2016-01-25 16:55:28 -0800 | [diff] [blame] | 28 |  | 
 | 29 | #include <brillo/binder_watcher.h> | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 30 |  | 
| Casey Dahlin | 4089249 | 2016-01-25 16:55:28 -0800 | [diff] [blame] | 31 | #include "android/brillo/BnUpdateEngineStatusCallback.h" | 
| Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 32 | #include "android/brillo/IUpdateEngine.h" | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 33 |  | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 34 | #include "update_engine/client_library/include/update_engine/client.h" | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 35 |  | 
 | 36 | namespace update_engine { | 
 | 37 | namespace internal { | 
 | 38 |  | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 39 | class BinderUpdateEngineClient : public UpdateEngineClient { | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 40 |  public: | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 41 |   BinderUpdateEngineClient() = default; | 
| Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 42 |   bool Init(); | 
 | 43 |  | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 44 |   virtual ~BinderUpdateEngineClient() = default; | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 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, | 
| Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 54 |                  int64_t* out_new_size) const override; | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 55 |  | 
| Alex Deymo | 5b5fa8b | 2016-10-06 15:40:49 -0700 | [diff] [blame] | 56 |   bool SetCohortHint(const std::string& in_cohort_hint) override; | 
 | 57 |   bool GetCohortHint(std::string* out_cohort_hint) const override; | 
 | 58 |  | 
| Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 59 |   bool SetUpdateOverCellularPermission(bool allowed) override; | 
| Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 60 |   bool GetUpdateOverCellularPermission(bool* allowed) const override; | 
| Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 61 |  | 
 | 62 |   bool SetP2PUpdatePermission(bool enabled) override; | 
| Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 63 |   bool GetP2PUpdatePermission(bool* enabled) const override; | 
| Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 64 |  | 
 | 65 |   bool Rollback(bool powerwash) override; | 
 | 66 |  | 
| Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 67 |   bool GetRollbackPartition(std::string* rollback_partition) const override; | 
| Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 68 |  | 
 | 69 |   void RebootIfNeeded() override; | 
 | 70 |  | 
| Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 71 |   bool GetPrevVersion(std::string* prev_version) const override; | 
| Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 72 |  | 
| Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 73 |   bool ResetStatus() override; | 
 | 74 |  | 
| Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 75 |   bool SetTargetChannel(const std::string& target_channel, | 
 | 76 |                         bool allow_powerwash) override; | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 77 |  | 
| Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 78 |   bool GetTargetChannel(std::string* out_channel) const override; | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 79 |  | 
| Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 80 |   bool GetChannel(std::string* out_channel) const override; | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 81 |  | 
| Casey Dahlin | 4089249 | 2016-01-25 16:55:28 -0800 | [diff] [blame] | 82 |   bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override; | 
| Casey Dahlin | a715f7b | 2016-01-29 16:38:51 -0800 | [diff] [blame] | 83 |   bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override; | 
| Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 84 |  | 
| Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 85 |   bool GetLastAttemptError(int32_t* last_attempt_error) const override; | 
 | 86 |  | 
| Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 87 |   bool GetEolStatus(int32_t* eol_status) const override; | 
 | 88 |  | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 89 |  private: | 
| Casey Dahlin | 4089249 | 2016-01-25 16:55:28 -0800 | [diff] [blame] | 90 |   class StatusUpdateCallback : | 
 | 91 |       public android::brillo::BnUpdateEngineStatusCallback { | 
 | 92 |    public: | 
| Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 93 |     explicit StatusUpdateCallback(BinderUpdateEngineClient* client) | 
 | 94 |         : client_(client) {} | 
| Casey Dahlin | 4089249 | 2016-01-25 16:55:28 -0800 | [diff] [blame] | 95 |  | 
 | 96 |     android::binder::Status HandleStatusUpdate( | 
| Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 97 |         const android::brillo::ParcelableUpdateEngineStatus& status) override; | 
| Casey Dahlin | 4089249 | 2016-01-25 16:55:28 -0800 | [diff] [blame] | 98 |  | 
 | 99 |    private: | 
 | 100 |     BinderUpdateEngineClient* client_; | 
 | 101 |   }; | 
 | 102 |  | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 103 |   android::sp<android::brillo::IUpdateEngine> service_; | 
| Casey Dahlin | 4089249 | 2016-01-25 16:55:28 -0800 | [diff] [blame] | 104 |   android::sp<android::brillo::IUpdateEngineStatusCallback> status_callback_; | 
 | 105 |   std::vector<update_engine::StatusUpdateHandler*> handlers_; | 
 | 106 |   brillo::BinderWatcher binder_watcher_; | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 107 |  | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 108 |   DISALLOW_COPY_AND_ASSIGN(BinderUpdateEngineClient); | 
 | 109 | };  // class BinderUpdateEngineClient | 
| Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 110 |  | 
 | 111 | }  // namespace internal | 
 | 112 | }  // namespace update_engine | 
 | 113 |  | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 114 | #endif  // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_ |