1 // 2 // Copyright (C) 2015 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_INCLUDE_UPDATE_ENGINE_CLIENT_H_ 18 #define UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_ 19 20 #include <cstdint> 21 #include <memory> 22 #include <string> 23 #include <vector> 24 25 #include "update_engine/status_update_handler.h" 26 #include "update_engine/update_status.h" 27 28 namespace update_engine { 29 30 class UpdateEngineClient { 31 public: 32 static std::unique_ptr<UpdateEngineClient> CreateInstance(); 33 34 virtual ~UpdateEngineClient() = default; 35 36 // Force the update_engine to attempt an update. 37 // |app_version| 38 // Attempt to update to this version. An empty string indicates that 39 // update engine should pick the most recent image on the current channel. 40 // |omaha_url| 41 // Force update_engine to look for updates from the given server. Passing 42 // empty indicates update_engine should get this parameter from its 43 // config. Note that update_engine will ignore this parameter in 44 // production mode to avoid pulling untrusted updates. 45 // |at_user_request| 46 // This update was directly requested by the user. 47 virtual bool AttemptUpdate(const std::string& app_version, 48 const std::string& omaha_url, 49 bool at_user_request) = 0; 50 51 // Request the update_engine to install a list of DLC modules. 52 // |omaha_url| 53 // Force update_engine to look for updates from the given server. Passing 54 // empty indicates update_engine should use its default value. Note that 55 // update_engine will ignore this parameter in production mode to avoid 56 // pulling untrusted updates. 57 // |dlc_ids| 58 // A list of DLC module IDs. 59 virtual bool AttemptInstall(const std::string& omaha_url, 60 const std::vector<std::string>& dlc_ids) = 0; 61 62 // Same as above but return the entire struct instead. 63 virtual bool GetStatus(UpdateEngineStatus* out_status) const = 0; 64 65 // Sets the DLC as active or inactive. When set to active, the ping metadata 66 // for the DLC is updated accordingly. When set to inactive, the metadata 67 // for the DLC is deleted. 68 virtual bool SetDlcActiveValue(bool is_active, const std::string& dlc_id) = 0; 69 70 // Getter and setter for the cohort hint. 71 virtual bool SetCohortHint(const std::string& cohort_hint) = 0; 72 virtual bool GetCohortHint(std::string* cohort_hint) const = 0; 73 74 // Getter and setter for the updates over cellular connections. 75 virtual bool SetUpdateOverCellularPermission(bool allowed) = 0; 76 virtual bool GetUpdateOverCellularPermission(bool* allowed) const = 0; 77 78 // Getter and setter for the updates from P2P permission. 79 virtual bool SetP2PUpdatePermission(bool enabled) = 0; 80 virtual bool GetP2PUpdatePermission(bool* enabled) const = 0; 81 82 // Attempt a rollback. Set 'powerwash' to reset the device while rolling 83 // back. 84 virtual bool Rollback(bool powerwash) = 0; 85 86 // Get the rollback partition if available. Gives empty string if not. 87 virtual bool GetRollbackPartition(std::string* rollback_partition) const = 0; 88 89 // Reboot the system if needed. 90 virtual void RebootIfNeeded() = 0; 91 92 // Get the previous version 93 virtual bool GetPrevVersion(std::string* prev_version) const = 0; 94 95 // Resets the status of the Update Engine 96 virtual bool ResetStatus() = 0; 97 98 // Changes the current channel of the device to the target channel. 99 virtual bool SetTargetChannel(const std::string& target_channel, 100 bool allow_powerwash) = 0; 101 102 // Get the channel the device will switch to on reboot. 103 virtual bool GetTargetChannel(std::string* out_channel) const = 0; 104 105 // Get the channel the device is currently on. 106 virtual bool GetChannel(std::string* out_channel) const = 0; 107 108 // Handle status updates. The handler must exist until the client is 109 // destroyed or UnregisterStatusUpdateHandler is called for it. Its IPCError 110 // method will be called if the handler could not be registered. Otherwise 111 // its HandleStatusUpdate method will be called every time update_engine's 112 // status changes. Will always report the status on registration to prevent 113 // race conditions. 114 virtual bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) = 0; 115 116 // Unregister a status update handler 117 virtual bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) = 0; 118 119 // Get the last UpdateAttempt error code. 120 virtual bool GetLastAttemptError(int32_t* last_attempt_error) const = 0; 121 122 protected: 123 // Use CreateInstance(). 124 UpdateEngineClient() = default; 125 126 private: 127 UpdateEngineClient(const UpdateEngineClient&) = delete; 128 void operator=(const UpdateEngineClient&) = delete; 129 }; // class UpdateEngineClient 130 131 } // namespace update_engine 132 133 #endif // UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_ 134