116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// 216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// Copyright (C) 2015 The Android Open Source Project 316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// 416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// Licensed under the Apache License, Version 2.0 (the "License"); 516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// you may not use this file except in compliance with the License. 616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// You may obtain a copy of the License at 716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// 816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// http://www.apache.org/licenses/LICENSE-2.0 916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// 1016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// Unless required by applicable law or agreed to in writing, software 1116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// distributed under the License is distributed on an "AS IS" BASIS, 1216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// See the License for the specific language governing permissions and 1416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// limitations under the License. 1516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley// 1616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 1739910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#ifndef UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_ 1839910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#define UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_ 1916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 2016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley#include <cstdint> 2116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley#include <memory> 2216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley#include <string> 2316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 2497c870518ce1149b32966d98ebfe93f3eb5d1fefCasey Dahlin#include "update_engine/status_update_handler.h" 2516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley#include "update_engine/update_status.h" 2616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 2716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wileynamespace update_engine { 2816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 2916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wileyclass UpdateEngineClient { 3016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley public: 3116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley static std::unique_ptr<UpdateEngineClient> CreateInstance(); 3216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 3316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley virtual ~UpdateEngineClient() = default; 3416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 3516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // Force the update_engine to attempt an update. 3616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // |app_version| 3716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // Attempt to update to this version. An empty string indicates that 3816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // update engine should pick the most recent image on the current channel. 3916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // |omaha_url| 4016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // Force update_engine to look for updates from the given server. Passing 4116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // empty indicates update_engine should get this parameter from its 4216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // config. Note that update_engine will ignore this parameter in 4316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // production mode to avoid pulling untrusted updates. 4416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // |at_user_request| 4516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // This update was directly requested by the user. 4616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley virtual bool AttemptUpdate(const std::string& app_version, 4716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley const std::string& omaha_url, 4816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley bool at_user_request) = 0; 4916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 5016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // Returns the current status of the Update Engine. 5116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // 5216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // |out_last_checked_time| 5316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // the last time the update engine checked for an update in seconds since 5416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // the epoc. 5516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // |out_progress| 5616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // when downloading an update, this is calculated as 5716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // (number of bytes received) / (total bytes). 5816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // |out_update_status| 5916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // See update_status.h. 6016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // |out_new_version| 6116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // string version of the new system image. 6216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // |out_new_size| 6316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // number of bytes in the new system image. 6416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley virtual bool GetStatus(int64_t* out_last_checked_time, 6516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley double* out_progress, 6616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley UpdateStatus* out_update_status, 6716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley std::string* out_new_version, 68194414134a954d921c8063610304c4fd21f19df2Casey Dahlin int64_t* out_new_size) const = 0; 6916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 70ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin // Getter and setter for the updates over cellular connections. 71ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin virtual bool SetUpdateOverCellularPermission(bool allowed) = 0; 72194414134a954d921c8063610304c4fd21f19df2Casey Dahlin virtual bool GetUpdateOverCellularPermission(bool* allowed) const = 0; 73ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin 74ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin // Getter and setter for the updates from P2P permission. 75ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin virtual bool SetP2PUpdatePermission(bool enabled) = 0; 76194414134a954d921c8063610304c4fd21f19df2Casey Dahlin virtual bool GetP2PUpdatePermission(bool* enabled) const = 0; 77ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin 78ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin // Attempt a rollback. Set 'powerwash' to reset the device while rolling 79ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin // back. 80ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin virtual bool Rollback(bool powerwash) = 0; 81ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin 82ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin // Get the rollback partition if available. Gives empty string if not. 83194414134a954d921c8063610304c4fd21f19df2Casey Dahlin virtual bool GetRollbackPartition(std::string* rollback_partition) const = 0; 84ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin 85ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin // Reboot the system if needed. 86ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin virtual void RebootIfNeeded() = 0; 87ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin 88ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin // Get the previous version 89194414134a954d921c8063610304c4fd21f19df2Casey Dahlin virtual bool GetPrevVersion(std::string* prev_version) const = 0; 90ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin 91e844c1a5604765bbddafa7e05f1143a27f136747Casey Dahlin // Resets the status of the Update Engine 92e844c1a5604765bbddafa7e05f1143a27f136747Casey Dahlin virtual bool ResetStatus() = 0; 93e844c1a5604765bbddafa7e05f1143a27f136747Casey Dahlin 9416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // Changes the current channel of the device to the target channel. 9587ab88e35fac5d3ded1c70c8911d307ec47a7db9Casey Dahlin virtual bool SetTargetChannel(const std::string& target_channel, 9687ab88e35fac5d3ded1c70c8911d307ec47a7db9Casey Dahlin bool allow_powerwash) = 0; 9716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 9816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // Get the channel the device will switch to on reboot. 99194414134a954d921c8063610304c4fd21f19df2Casey Dahlin virtual bool GetTargetChannel(std::string* out_channel) const = 0; 10016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 10116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // Get the channel the device is currently on. 102194414134a954d921c8063610304c4fd21f19df2Casey Dahlin virtual bool GetChannel(std::string* out_channel) const = 0; 10316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 10497c870518ce1149b32966d98ebfe93f3eb5d1fefCasey Dahlin // Handle status updates. The handler must exist until the client is 105a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin // destroyed or UnregisterStatusUpdateHandler is called for it. Its IPCError 106a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin // method will be called if the handler could not be registered. Otherwise 107a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin // its HandleStatusUpdate method will be called every time update_engine's 108a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin // status changes. Will always report the status on registration to prevent 109a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin // race conditions. 11040892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin virtual bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) = 0; 11197c870518ce1149b32966d98ebfe93f3eb5d1fefCasey Dahlin 112a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin // Unregister a status update handler 113a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin virtual bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) = 0; 114a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin 1152997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao // Get the last UpdateAttempt error code. 1162997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao virtual bool GetLastAttemptError(int32_t* last_attempt_error) const = 0; 1172997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao 11816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley protected: 11916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley // Use CreateInstance(). 12016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley UpdateEngineClient() = default; 12116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 12216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley private: 12316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley UpdateEngineClient(const UpdateEngineClient&) = delete; 12416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley void operator=(const UpdateEngineClient&) = delete; 12516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley}; // class UpdateEngineClient 12616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 12716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley} // namespace update_engine 12816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley 12939910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#endif // UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_ 130