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
705b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo  // Getter and setter for the cohort hint.
715b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo  virtual bool SetCohortHint(const std::string& cohort_hint) = 0;
725b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo  virtual bool GetCohortHint(std::string* cohort_hint) const = 0;
735b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo
74ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  // Getter and setter for the updates over cellular connections.
75ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  virtual bool SetUpdateOverCellularPermission(bool allowed) = 0;
76194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  virtual bool GetUpdateOverCellularPermission(bool* allowed) const = 0;
77ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
78ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  // Getter and setter for the updates from P2P permission.
79ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  virtual bool SetP2PUpdatePermission(bool enabled) = 0;
80194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  virtual bool GetP2PUpdatePermission(bool* enabled) const = 0;
81ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
82ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  // Attempt a rollback. Set 'powerwash' to reset the device while rolling
83ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  // back.
84ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  virtual bool Rollback(bool powerwash) = 0;
85ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
86ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  // Get the rollback partition if available. Gives empty string if not.
87194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  virtual bool GetRollbackPartition(std::string* rollback_partition) const = 0;
88ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
89ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  // Reboot the system if needed.
90ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  virtual void RebootIfNeeded() = 0;
91ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
92ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  // Get the previous version
93194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  virtual bool GetPrevVersion(std::string* prev_version) const = 0;
94ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
95e844c1a5604765bbddafa7e05f1143a27f136747Casey Dahlin  // Resets the status of the Update Engine
96e844c1a5604765bbddafa7e05f1143a27f136747Casey Dahlin  virtual bool ResetStatus() = 0;
97e844c1a5604765bbddafa7e05f1143a27f136747Casey Dahlin
9816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // Changes the current channel of the device to the target channel.
9987ab88e35fac5d3ded1c70c8911d307ec47a7db9Casey Dahlin  virtual bool SetTargetChannel(const std::string& target_channel,
10087ab88e35fac5d3ded1c70c8911d307ec47a7db9Casey Dahlin                                bool allow_powerwash) = 0;
10116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
10216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // Get the channel the device will switch to on reboot.
103194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  virtual bool GetTargetChannel(std::string* out_channel) const = 0;
10416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
10516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // Get the channel the device is currently on.
106194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  virtual bool GetChannel(std::string* out_channel) const = 0;
10716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
10897c870518ce1149b32966d98ebfe93f3eb5d1fefCasey Dahlin  // Handle status updates. The handler must exist until the client is
109a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin  // destroyed or UnregisterStatusUpdateHandler is called for it. Its IPCError
110a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin  // method will be called if the handler could not be registered. Otherwise
111a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin  // its HandleStatusUpdate method will be called every time update_engine's
112a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin  // status changes. Will always report the status on registration to prevent
113a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin  // race conditions.
11440892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  virtual bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) = 0;
11597c870518ce1149b32966d98ebfe93f3eb5d1fefCasey Dahlin
116a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin  // Unregister a status update handler
117a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin  virtual bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) = 0;
118a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin
1192997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao  // Get the last UpdateAttempt error code.
1202997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao  virtual bool GetLastAttemptError(int32_t* last_attempt_error) const = 0;
1212997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao
122b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo  // Get the current end-of-life status code. See EolStatus enum for details.
123b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo  virtual bool GetEolStatus(int32_t* eol_status) const = 0;
124b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo
12516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley protected:
12616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  // Use CreateInstance().
12716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  UpdateEngineClient() = default;
12816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
12916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley private:
13016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  UpdateEngineClient(const UpdateEngineClient&) = delete;
13116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  void operator=(const UpdateEngineClient&) = delete;
13216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley};  // class UpdateEngineClient
13316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
13416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley}  // namespace update_engine
13516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
13639910dcd1d68987ccee7c3031dc269233a8490bbAlex Deymo#endif  // UPDATE_ENGINE_CLIENT_LIBRARY_INCLUDE_UPDATE_ENGINE_CLIENT_H_
137