116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley//
2a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin// Copyright (C) 2016 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
17a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#ifndef UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_
18a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#define UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_
1916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
2016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley#include <cstdint>
2116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley#include <memory>
2216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley#include <string>
2340892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin#include <vector>
2416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
2516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley#include <base/macros.h>
2640892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin#include <utils/String16.h>
27b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo#include <utils/StrongPointer.h>
2840892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin
2940892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin#include <brillo/binder_watcher.h>
30a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin
3140892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin#include "android/brillo/BnUpdateEngineStatusCallback.h"
32b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo#include "android/brillo/IUpdateEngine.h"
3316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
3416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley#include "update_engine/client_library/include/update_engine/client.h"
3516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
3616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wileynamespace update_engine {
3716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wileynamespace internal {
3816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
39a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlinclass BinderUpdateEngineClient : public UpdateEngineClient {
4016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley public:
41a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  BinderUpdateEngineClient() = default;
42194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  bool Init();
43194414134a954d921c8063610304c4fd21f19df2Casey Dahlin
44a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  virtual ~BinderUpdateEngineClient() = default;
4516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
4616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  bool AttemptUpdate(const std::string& app_version,
4716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                     const std::string& omaha_url,
4816daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                     bool at_user_request) override;
4916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
5016daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley  bool GetStatus(int64_t* out_last_checked_time,
5116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                 double* out_progress,
5216daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                 UpdateStatus* out_update_status,
5316daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley                 std::string* out_new_version,
54194414134a954d921c8063610304c4fd21f19df2Casey Dahlin                 int64_t* out_new_size) const override;
5516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
565b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo  bool SetCohortHint(const std::string& in_cohort_hint) override;
575b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo  bool GetCohortHint(std::string* out_cohort_hint) const override;
585b5fa8b412312a41cfd4d7ab475b54d4f730ed2aAlex Deymo
59ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  bool SetUpdateOverCellularPermission(bool allowed) override;
60194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  bool GetUpdateOverCellularPermission(bool* allowed) const override;
61ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
62ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  bool SetP2PUpdatePermission(bool enabled) override;
63194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  bool GetP2PUpdatePermission(bool* enabled) const override;
64ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
65ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  bool Rollback(bool powerwash) override;
66ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
67194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  bool GetRollbackPartition(std::string* rollback_partition) const override;
68ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
69ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin  void RebootIfNeeded() override;
70ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
71194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  bool GetPrevVersion(std::string* prev_version) const override;
72ef361136cea1e423dc462d2b347923ae60b2cf08Casey Dahlin
73e844c1a5604765bbddafa7e05f1143a27f136747Casey Dahlin  bool ResetStatus() override;
74e844c1a5604765bbddafa7e05f1143a27f136747Casey Dahlin
7587ab88e35fac5d3ded1c70c8911d307ec47a7db9Casey Dahlin  bool SetTargetChannel(const std::string& target_channel,
7687ab88e35fac5d3ded1c70c8911d307ec47a7db9Casey Dahlin                        bool allow_powerwash) override;
7716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
78194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  bool GetTargetChannel(std::string* out_channel) const override;
7916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
80194414134a954d921c8063610304c4fd21f19df2Casey Dahlin  bool GetChannel(std::string* out_channel) const override;
8116daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
8240892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
83a715f7b8a211b5c4b74206539e9aa7ddacf4b243Casey Dahlin  bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
8497c870518ce1149b32966d98ebfe93f3eb5d1fefCasey Dahlin
852997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao  bool GetLastAttemptError(int32_t* last_attempt_error) const override;
862997173235e88c5e4cb13d2844f74afc7b25d6e2Shuqian Zhao
87b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo  bool GetEolStatus(int32_t* eol_status) const override;
88b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo
8916daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley private:
9040892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  class StatusUpdateCallback :
9140892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin      public android::brillo::BnUpdateEngineStatusCallback {
9240892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin   public:
93b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo    explicit StatusUpdateCallback(BinderUpdateEngineClient* client)
94b3fa53bf760bd0a6fd1ef9df28cb425586d733f6Alex Deymo        : client_(client) {}
9540892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin
9640892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin    android::binder::Status HandleStatusUpdate(
9740892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin        int64_t last_checked_time,
9840892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin        double progress,
9940892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin        const android::String16& current_operation,
10040892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin        const android::String16& new_version,
10140892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin        int64_t new_size) override;
10240892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin
10340892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin   private:
10440892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin    BinderUpdateEngineClient* client_;
10540892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  };
10640892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin
107a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  android::sp<android::brillo::IUpdateEngine> service_;
10840892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  android::sp<android::brillo::IUpdateEngineStatusCallback> status_callback_;
10940892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  std::vector<update_engine::StatusUpdateHandler*> handlers_;
11040892497a9b1ea124058baf09f5f2873a15cb696Casey Dahlin  brillo::BinderWatcher binder_watcher_;
11197c870518ce1149b32966d98ebfe93f3eb5d1fefCasey Dahlin
112a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin  DISALLOW_COPY_AND_ASSIGN(BinderUpdateEngineClient);
113a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin};  // class BinderUpdateEngineClient
11416daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
11516daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley}  // namespace internal
11616daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley}  // namespace update_engine
11716daa08470beb5021b85618f1b3ee214d89e59a1Christopher Wiley
118a93cd53c4f8ab8cb926ed9223373567ebbf45cb6Casey Dahlin#endif  // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_
119