client.h revision 39910dcd1d68987ccee7c3031dc269233a8490bb
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 24#include "update_engine/update_status.h" 25 26namespace update_engine { 27 28class UpdateEngineClient { 29 public: 30 static std::unique_ptr<UpdateEngineClient> CreateInstance(); 31 32 virtual ~UpdateEngineClient() = default; 33 34 // Force the update_engine to attempt an update. 35 // |app_version| 36 // Attempt to update to this version. An empty string indicates that 37 // update engine should pick the most recent image on the current channel. 38 // |omaha_url| 39 // Force update_engine to look for updates from the given server. Passing 40 // empty indicates update_engine should get this parameter from its 41 // config. Note that update_engine will ignore this parameter in 42 // production mode to avoid pulling untrusted updates. 43 // |at_user_request| 44 // This update was directly requested by the user. 45 virtual bool AttemptUpdate(const std::string& app_version, 46 const std::string& omaha_url, 47 bool at_user_request) = 0; 48 49 // Returns the current status of the Update Engine. 50 // 51 // |out_last_checked_time| 52 // the last time the update engine checked for an update in seconds since 53 // the epoc. 54 // |out_progress| 55 // when downloading an update, this is calculated as 56 // (number of bytes received) / (total bytes). 57 // |out_update_status| 58 // See update_status.h. 59 // |out_new_version| 60 // string version of the new system image. 61 // |out_new_size| 62 // number of bytes in the new system image. 63 virtual bool GetStatus(int64_t* out_last_checked_time, 64 double* out_progress, 65 UpdateStatus* out_update_status, 66 std::string* out_new_version, 67 int64_t* out_new_size) = 0; 68 69 // Changes the current channel of the device to the target channel. 70 virtual bool SetTargetChannel(const std::string& target_channel) = 0; 71 72 // Get the channel the device will switch to on reboot. 73 virtual bool GetTargetChannel(std::string* out_channel) = 0; 74 75 // Get the channel the device is currently on. 76 virtual bool GetChannel(std::string* out_channel) = 0; 77 78 protected: 79 // Use CreateInstance(). 80 UpdateEngineClient() = default; 81 82 private: 83 UpdateEngineClient(const UpdateEngineClient&) = delete; 84 void operator=(const UpdateEngineClient&) = delete; 85}; // class UpdateEngineClient 86 87} // namespace update_engine 88 89#endif // UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_ 90