blob: f3e41026ce0cac7bab88965b5abea8b512446efc [file] [log] [blame]
Christopher Wiley16daa082015-10-01 17:18:40 -07001//
Casey Dahlina93cd532016-01-14 16:55:11 -08002// Copyright (C) 2016 The Android Open Source Project
Christopher Wiley16daa082015-10-01 17:18:40 -07003//
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
Casey Dahlina93cd532016-01-14 16:55:11 -080017#ifndef UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_
18#define UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_
Christopher Wiley16daa082015-10-01 17:18:40 -070019
20#include <cstdint>
21#include <memory>
22#include <string>
Casey Dahlin40892492016-01-25 16:55:28 -080023#include <vector>
Christopher Wiley16daa082015-10-01 17:18:40 -070024
25#include <base/macros.h>
Casey Dahlin40892492016-01-25 16:55:28 -080026#include <utils/String16.h>
Alex Deymob3fa53b2016-04-18 19:57:58 -070027#include <utils/StrongPointer.h>
Casey Dahlin40892492016-01-25 16:55:28 -080028
29#include <brillo/binder_watcher.h>
Casey Dahlina93cd532016-01-14 16:55:11 -080030
Casey Dahlin40892492016-01-25 16:55:28 -080031#include "android/brillo/BnUpdateEngineStatusCallback.h"
Alex Deymob3fa53b2016-04-18 19:57:58 -070032#include "android/brillo/IUpdateEngine.h"
Christopher Wiley16daa082015-10-01 17:18:40 -070033
Christopher Wiley16daa082015-10-01 17:18:40 -070034#include "update_engine/client_library/include/update_engine/client.h"
Christopher Wiley16daa082015-10-01 17:18:40 -070035
36namespace update_engine {
37namespace internal {
38
Casey Dahlina93cd532016-01-14 16:55:11 -080039class BinderUpdateEngineClient : public UpdateEngineClient {
Christopher Wiley16daa082015-10-01 17:18:40 -070040 public:
Casey Dahlina93cd532016-01-14 16:55:11 -080041 BinderUpdateEngineClient() = default;
Casey Dahlin19441412016-01-07 14:56:40 -080042 bool Init();
43
Casey Dahlina93cd532016-01-14 16:55:11 -080044 virtual ~BinderUpdateEngineClient() = default;
Christopher Wiley16daa082015-10-01 17:18:40 -070045
46 bool AttemptUpdate(const std::string& app_version,
47 const std::string& omaha_url,
48 bool at_user_request) override;
49
Sen Jiang3ce4e522019-01-04 15:34:19 -080050 bool AttemptInstall(const std::string& omaha_url,
51 const std::vector<std::string>& dlc_module_ids) override;
52
Christopher Wiley16daa082015-10-01 17:18:40 -070053 bool GetStatus(int64_t* out_last_checked_time,
54 double* out_progress,
55 UpdateStatus* out_update_status,
56 std::string* out_new_version,
Casey Dahlin19441412016-01-07 14:56:40 -080057 int64_t* out_new_size) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070058
Alex Deymo5b5fa8b2016-10-06 15:40:49 -070059 bool SetCohortHint(const std::string& in_cohort_hint) override;
60 bool GetCohortHint(std::string* out_cohort_hint) const override;
61
Casey Dahlinef361132015-12-17 13:02:37 -080062 bool SetUpdateOverCellularPermission(bool allowed) override;
Casey Dahlin19441412016-01-07 14:56:40 -080063 bool GetUpdateOverCellularPermission(bool* allowed) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080064
65 bool SetP2PUpdatePermission(bool enabled) override;
Casey Dahlin19441412016-01-07 14:56:40 -080066 bool GetP2PUpdatePermission(bool* enabled) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080067
68 bool Rollback(bool powerwash) override;
69
Casey Dahlin19441412016-01-07 14:56:40 -080070 bool GetRollbackPartition(std::string* rollback_partition) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080071
72 void RebootIfNeeded() override;
73
Casey Dahlin19441412016-01-07 14:56:40 -080074 bool GetPrevVersion(std::string* prev_version) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080075
Casey Dahline844c1a2015-12-16 14:30:58 -080076 bool ResetStatus() override;
77
Casey Dahlin87ab88e2015-12-16 17:58:05 -080078 bool SetTargetChannel(const std::string& target_channel,
79 bool allow_powerwash) override;
Christopher Wiley16daa082015-10-01 17:18:40 -070080
Casey Dahlin19441412016-01-07 14:56:40 -080081 bool GetTargetChannel(std::string* out_channel) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070082
Casey Dahlin19441412016-01-07 14:56:40 -080083 bool GetChannel(std::string* out_channel) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070084
Casey Dahlin40892492016-01-25 16:55:28 -080085 bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
Casey Dahlina715f7b2016-01-29 16:38:51 -080086 bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
Casey Dahlin97c87052016-01-06 14:33:55 -080087
Shuqian Zhao29971732016-02-05 11:29:32 -080088 bool GetLastAttemptError(int32_t* last_attempt_error) const override;
89
Alex Deymob3fa53b2016-04-18 19:57:58 -070090 bool GetEolStatus(int32_t* eol_status) const override;
91
Christopher Wiley16daa082015-10-01 17:18:40 -070092 private:
Amin Hassaniaefaab22019-01-14 16:20:16 -080093 class StatusUpdateCallback
94 : public android::brillo::BnUpdateEngineStatusCallback {
Casey Dahlin40892492016-01-25 16:55:28 -080095 public:
Alex Deymob3fa53b2016-04-18 19:57:58 -070096 explicit StatusUpdateCallback(BinderUpdateEngineClient* client)
97 : client_(client) {}
Casey Dahlin40892492016-01-25 16:55:28 -080098
99 android::binder::Status HandleStatusUpdate(
Aaron Wood7f92e2b2017-08-28 14:51:21 -0700100 const android::brillo::ParcelableUpdateEngineStatus& status) override;
Casey Dahlin40892492016-01-25 16:55:28 -0800101
102 private:
103 BinderUpdateEngineClient* client_;
104 };
105
Casey Dahlina93cd532016-01-14 16:55:11 -0800106 android::sp<android::brillo::IUpdateEngine> service_;
Casey Dahlin40892492016-01-25 16:55:28 -0800107 android::sp<android::brillo::IUpdateEngineStatusCallback> status_callback_;
108 std::vector<update_engine::StatusUpdateHandler*> handlers_;
109 brillo::BinderWatcher binder_watcher_;
Christopher Wiley16daa082015-10-01 17:18:40 -0700110
Casey Dahlina93cd532016-01-14 16:55:11 -0800111 DISALLOW_COPY_AND_ASSIGN(BinderUpdateEngineClient);
112}; // class BinderUpdateEngineClient
Christopher Wiley16daa082015-10-01 17:18:40 -0700113
114} // namespace internal
115} // namespace update_engine
116
Casey Dahlina93cd532016-01-14 16:55:11 -0800117#endif // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_