Christopher Wiley | 9e1eda9 | 2015-11-16 15:23:37 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 The Android Open Source Project |
| 3 | // |
| 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 | |
| 17 | #include "update_engine/binder_service.h" |
| 18 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 19 | #include <utils/String16.h> |
| 20 | #include <utils/StrongPointer.h> |
| 21 | |
Christopher Wiley | 9e1eda9 | 2015-11-16 15:23:37 -0800 | [diff] [blame] | 22 | using android::String16; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 23 | using android::String8; |
Christopher Wiley | 09af881 | 2015-11-19 08:12:33 -0800 | [diff] [blame] | 24 | using android::binder::Status; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 25 | using android::brillo::IUpdateEngineStatusCallback; |
| 26 | using android::brillo::ParcelableUpdateEngineStatus; |
| 27 | using android::sp; |
| 28 | using brillo::ErrorPtr; |
| 29 | using std::string; |
Christopher Wiley | 9e1eda9 | 2015-11-16 15:23:37 -0800 | [diff] [blame] | 30 | |
| 31 | namespace chromeos_update_engine { |
| 32 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 33 | namespace { |
| 34 | string NormalString(const String16& in) { |
| 35 | return string{String8{in}.string()}; |
Tao Bao | e78e3fb | 2016-01-04 17:57:53 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 38 | Status ToStatus(ErrorPtr* error) { |
| 39 | return Status::fromServiceSpecificError( |
| 40 | 1, String8{error->get()->GetMessage().c_str()}); |
| 41 | } |
| 42 | } // namespace |
| 43 | |
| 44 | template<typename... Parameters, typename... Arguments> |
| 45 | Status BinderUpdateEngineService::CallCommonHandler( |
| 46 | bool (UpdateEngineService::*Handler)(ErrorPtr*, Parameters...), |
| 47 | Arguments... arguments) { |
| 48 | ErrorPtr error; |
| 49 | if (((common_.get())->*Handler)(&error, arguments...)) return Status::ok(); |
| 50 | return ToStatus(&error); |
Christopher Wiley | 9e1eda9 | 2015-11-16 15:23:37 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 53 | Status BinderUpdateEngineService::AttemptUpdate(const String16& app_version, |
| 54 | const String16& omaha_url, |
| 55 | int flags) { |
| 56 | return CallCommonHandler( |
| 57 | &UpdateEngineService::AttemptUpdate, NormalString(app_version), |
| 58 | NormalString(omaha_url), flags); |
Christopher Wiley | 9e1eda9 | 2015-11-16 15:23:37 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 61 | Status BinderUpdateEngineService::AttemptRollback(bool powerwash) { |
| 62 | return CallCommonHandler(&UpdateEngineService::AttemptRollback, powerwash); |
Christopher Wiley | 9e1eda9 | 2015-11-16 15:23:37 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 65 | Status BinderUpdateEngineService::CanRollback(bool* out_can_rollback) { |
| 66 | return CallCommonHandler(&UpdateEngineService::CanRollback, |
| 67 | out_can_rollback); |
| 68 | } |
| 69 | |
| 70 | Status BinderUpdateEngineService::ResetStatus() { |
| 71 | return CallCommonHandler(&UpdateEngineService::ResetStatus); |
| 72 | } |
| 73 | |
| 74 | Status BinderUpdateEngineService::GetStatus( |
| 75 | ParcelableUpdateEngineStatus* status) { |
| 76 | string current_op; |
| 77 | string new_version; |
| 78 | |
| 79 | auto ret = CallCommonHandler(&UpdateEngineService::GetStatus, |
| 80 | &status->last_checked_time_, |
| 81 | &status->progress_, |
| 82 | ¤t_op, |
| 83 | &new_version, |
| 84 | &status->new_size_); |
| 85 | |
| 86 | if (ret.isOk()) { |
| 87 | status->current_operation_ = String16{current_op.c_str()}; |
| 88 | status->new_version_ = String16{new_version.c_str()}; |
| 89 | } |
| 90 | |
| 91 | return ret; |
| 92 | } |
| 93 | |
| 94 | Status BinderUpdateEngineService::RebootIfNeeded() { |
| 95 | return CallCommonHandler(&UpdateEngineService::RebootIfNeeded); |
| 96 | } |
| 97 | |
| 98 | Status BinderUpdateEngineService::SetChannel(const String16& target_channel, |
| 99 | bool powerwash) { |
| 100 | return CallCommonHandler(&UpdateEngineService::SetChannel, |
| 101 | NormalString(target_channel), powerwash); |
| 102 | } |
| 103 | |
| 104 | Status BinderUpdateEngineService::GetChannel(bool get_current_channel, |
| 105 | String16* out_channel) { |
| 106 | string channel_string; |
| 107 | auto ret = CallCommonHandler(&UpdateEngineService::GetChannel, |
| 108 | get_current_channel, |
| 109 | &channel_string); |
| 110 | |
| 111 | *out_channel = String16(channel_string.c_str()); |
| 112 | return ret; |
| 113 | } |
| 114 | |
| 115 | Status BinderUpdateEngineService::SetP2PUpdatePermission(bool enabled) { |
| 116 | return CallCommonHandler(&UpdateEngineService::SetP2PUpdatePermission, |
| 117 | enabled); |
| 118 | } |
| 119 | |
| 120 | Status BinderUpdateEngineService::GetP2PUpdatePermission( |
| 121 | bool* out_p2p_permission) { |
| 122 | return CallCommonHandler(&UpdateEngineService::GetP2PUpdatePermission, |
| 123 | out_p2p_permission); |
| 124 | } |
| 125 | |
| 126 | Status BinderUpdateEngineService::SetUpdateOverCellularPermission( |
| 127 | bool enabled) { |
| 128 | return CallCommonHandler( |
| 129 | &UpdateEngineService::SetUpdateOverCellularPermission, enabled); |
| 130 | } |
| 131 | |
| 132 | Status BinderUpdateEngineService::GetUpdateOverCellularPermission( |
| 133 | bool* out_cellular_permission) { |
| 134 | return CallCommonHandler( |
| 135 | &UpdateEngineService::GetUpdateOverCellularPermission, |
| 136 | out_cellular_permission); |
| 137 | } |
| 138 | |
| 139 | Status BinderUpdateEngineService::GetDurationSinceUpdate( |
| 140 | int64_t* out_duration) { |
| 141 | return CallCommonHandler(&UpdateEngineService::GetDurationSinceUpdate, |
| 142 | out_duration); |
| 143 | } |
| 144 | |
| 145 | Status BinderUpdateEngineService::GetPrevVersion(String16* out_prev_version) { |
| 146 | string version_string; |
| 147 | auto ret = CallCommonHandler(&UpdateEngineService::GetPrevVersion, |
| 148 | &version_string); |
| 149 | |
| 150 | *out_prev_version = String16(version_string.c_str()); |
| 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | Status BinderUpdateEngineService::GetRollbackPartition( |
| 155 | String16* out_rollback_partition) { |
| 156 | string partition_string; |
| 157 | auto ret = CallCommonHandler(&UpdateEngineService::GetRollbackPartition, |
| 158 | &partition_string); |
| 159 | |
| 160 | if (ret.isOk()) { |
| 161 | *out_rollback_partition = String16(partition_string.c_str()); |
| 162 | } |
| 163 | |
| 164 | return ret; |
| 165 | } |
| 166 | |
| 167 | Status BinderUpdateEngineService::RegisterStatusCallback( |
| 168 | const sp<IUpdateEngineStatusCallback>& callback) { |
Christopher Wiley | 09af881 | 2015-11-19 08:12:33 -0800 | [diff] [blame] | 169 | return Status::ok(); |
Christopher Wiley | 9e1eda9 | 2015-11-16 15:23:37 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | } // namespace chromeos_update_engine |