client.h revision 39910dcd1d68987ccee7c3031dc269233a8490bb
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
2416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley#include "update_engine/update_status.h"
2516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
2616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wileynamespace update_engine {
2716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
2816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wileyclass UpdateEngineClient {
2916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley public:
3016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  static std::unique_ptr<UpdateEngineClient> CreateInstance();
3116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
3216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  virtual ~UpdateEngineClient() = default;
3316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
3416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // Force the update_engine to attempt an update.
3516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // |app_version|
3616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     Attempt to update to this version.  An empty string indicates that
3716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     update engine should pick the most recent image on the current channel.
3816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // |omaha_url|
3916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     Force update_engine to look for updates from the given server.  Passing
4016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     empty indicates update_engine should get this parameter from its
4116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     config.  Note that update_engine will ignore this parameter in
4216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     production mode to avoid pulling untrusted updates.
4316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // |at_user_request|
4416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     This update was directly requested by the user.
4516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  virtual bool AttemptUpdate(const std::string& app_version,
4616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                             const std::string& omaha_url,
4716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                             bool at_user_request) = 0;
4816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
4916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // Returns the current status of the Update Engine.
5016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //
5116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // |out_last_checked_time|
5216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     the last time the update engine checked for an update in seconds since
5316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     the epoc.
5416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // |out_progress|
5516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     when downloading an update, this is calculated as
5616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     (number of bytes received) / (total bytes).
5716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // |out_update_status|
5816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     See update_status.h.
5916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // |out_new_version|
6016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     string version of the new system image.
6116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // |out_new_size|
6216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  //     number of bytes in the new system image.
6316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  virtual bool GetStatus(int64_t* out_last_checked_time,
6416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                         double* out_progress,
6516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                         UpdateStatus* out_update_status,
6616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                         std::string* out_new_version,
6716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                         int64_t* out_new_size) = 0;
6816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
6916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // Changes the current channel of the device to the target channel.
7016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  virtual bool SetTargetChannel(const std::string& target_channel) = 0;
7116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
7216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // Get the channel the device will switch to on reboot.
7316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  virtual bool GetTargetChannel(std::string* out_channel) = 0;
7416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
7516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // Get the channel the device is currently on.
7616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  virtual bool GetChannel(std::string* out_channel) = 0;
7716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
7816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley protected:
7916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // Use CreateInstance().
8016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  UpdateEngineClient() = default;
8116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
8216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley private:
8316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  UpdateEngineClient(const UpdateEngineClient&) = delete;
8416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  void operator=(const UpdateEngineClient&) = delete;
8516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley};  // class UpdateEngineClient
8616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
8716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley}  // namespace update_engine
8816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
8939910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#endif  // UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_
90