blob: 562cee417109ecbc3a04b97d5a8da17ef6d826f6 [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 Dahlina93cd532016-01-14 16:55:11 -080026#include <utils/StrongPointer.h>
Casey Dahlin40892492016-01-25 16:55:28 -080027#include <utils/String16.h>
28
29#include <brillo/binder_watcher.h>
Casey Dahlina93cd532016-01-14 16:55:11 -080030
31#include "android/brillo/IUpdateEngine.h"
Casey Dahlin40892492016-01-25 16:55:28 -080032#include "android/brillo/BnUpdateEngineStatusCallback.h"
33
Christopher Wiley16daa082015-10-01 17:18:40 -070034
Christopher Wiley16daa082015-10-01 17:18:40 -070035#include "update_engine/client_library/include/update_engine/client.h"
Christopher Wiley16daa082015-10-01 17:18:40 -070036
37namespace update_engine {
38namespace internal {
39
Casey Dahlina93cd532016-01-14 16:55:11 -080040class BinderUpdateEngineClient : public UpdateEngineClient {
Christopher Wiley16daa082015-10-01 17:18:40 -070041 public:
Casey Dahlina93cd532016-01-14 16:55:11 -080042 BinderUpdateEngineClient() = default;
Casey Dahlin19441412016-01-07 14:56:40 -080043 bool Init();
44
Casey Dahlina93cd532016-01-14 16:55:11 -080045 virtual ~BinderUpdateEngineClient() = default;
Christopher Wiley16daa082015-10-01 17:18:40 -070046
47 bool AttemptUpdate(const std::string& app_version,
48 const std::string& omaha_url,
49 bool at_user_request) override;
50
51 bool GetStatus(int64_t* out_last_checked_time,
52 double* out_progress,
53 UpdateStatus* out_update_status,
54 std::string* out_new_version,
Casey Dahlin19441412016-01-07 14:56:40 -080055 int64_t* out_new_size) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070056
Casey Dahlinef361132015-12-17 13:02:37 -080057 bool SetUpdateOverCellularPermission(bool allowed) override;
Casey Dahlin19441412016-01-07 14:56:40 -080058 bool GetUpdateOverCellularPermission(bool* allowed) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080059
60 bool SetP2PUpdatePermission(bool enabled) override;
Casey Dahlin19441412016-01-07 14:56:40 -080061 bool GetP2PUpdatePermission(bool* enabled) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080062
63 bool Rollback(bool powerwash) override;
64
Casey Dahlin19441412016-01-07 14:56:40 -080065 bool GetRollbackPartition(std::string* rollback_partition) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080066
67 void RebootIfNeeded() override;
68
Casey Dahlin19441412016-01-07 14:56:40 -080069 bool GetPrevVersion(std::string* prev_version) const override;
Casey Dahlinef361132015-12-17 13:02:37 -080070
Casey Dahline844c1a2015-12-16 14:30:58 -080071 bool ResetStatus() override;
72
Casey Dahlin87ab88e2015-12-16 17:58:05 -080073 bool SetTargetChannel(const std::string& target_channel,
74 bool allow_powerwash) override;
Christopher Wiley16daa082015-10-01 17:18:40 -070075
Casey Dahlin19441412016-01-07 14:56:40 -080076 bool GetTargetChannel(std::string* out_channel) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070077
Casey Dahlin19441412016-01-07 14:56:40 -080078 bool GetChannel(std::string* out_channel) const override;
Christopher Wiley16daa082015-10-01 17:18:40 -070079
Casey Dahlin40892492016-01-25 16:55:28 -080080 bool RegisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
Casey Dahlina715f7b2016-01-29 16:38:51 -080081 bool UnregisterStatusUpdateHandler(StatusUpdateHandler* handler) override;
Casey Dahlin97c87052016-01-06 14:33:55 -080082
Christopher Wiley16daa082015-10-01 17:18:40 -070083 private:
Casey Dahlin40892492016-01-25 16:55:28 -080084 class StatusUpdateCallback :
85 public android::brillo::BnUpdateEngineStatusCallback {
86 public:
87 StatusUpdateCallback(BinderUpdateEngineClient* client) : client_(client) {}
88
89 android::binder::Status HandleStatusUpdate(
90 int64_t last_checked_time,
91 double progress,
92 const android::String16& current_operation,
93 const android::String16& new_version,
94 int64_t new_size) override;
95
96 private:
97 BinderUpdateEngineClient* client_;
98 };
99
Casey Dahlina93cd532016-01-14 16:55:11 -0800100 android::sp<android::brillo::IUpdateEngine> service_;
Casey Dahlin40892492016-01-25 16:55:28 -0800101 android::sp<android::brillo::IUpdateEngineStatusCallback> status_callback_;
102 std::vector<update_engine::StatusUpdateHandler*> handlers_;
103 brillo::BinderWatcher binder_watcher_;
Christopher Wiley16daa082015-10-01 17:18:40 -0700104
Casey Dahlina93cd532016-01-14 16:55:11 -0800105 DISALLOW_COPY_AND_ASSIGN(BinderUpdateEngineClient);
106}; // class BinderUpdateEngineClient
Christopher Wiley16daa082015-10-01 17:18:40 -0700107
108} // namespace internal
109} // namespace update_engine
110
Casey Dahlina93cd532016-01-14 16:55:11 -0800111#endif // UPDATE_ENGINE_CLIENT_LIBRARY_CLIENT_BINDER_H_