Steven Moreland | 9f8b5c7 | 2016-11-29 15:03:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | */ |
Connor O'Brien | 74f8292 | 2016-10-10 12:31:37 -0700 | [diff] [blame] | 16 | #define LOG_TAG "android.hardware.boot@1.0-impl" |
Yifan Hong | 65cbd60 | 2016-12-01 15:58:37 -0800 | [diff] [blame] | 17 | #include <android/log.h> |
Connor O'Brien | 74f8292 | 2016-10-10 12:31:37 -0700 | [diff] [blame] | 18 | |
| 19 | #include <hardware/hardware.h> |
| 20 | #include <hardware/boot_control.h> |
| 21 | #include "BootControl.h" |
| 22 | |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace boot { |
| 26 | namespace V1_0 { |
| 27 | namespace implementation { |
| 28 | |
| 29 | BootControl::BootControl(boot_control_module_t *module) : mModule(module){ |
| 30 | } |
| 31 | |
| 32 | // Methods from ::android::hardware::boot::V1_0::IBootControl follow. |
| 33 | Return<uint32_t> BootControl::getNumberSlots() { |
| 34 | return mModule->getNumberSlots(mModule); |
| 35 | } |
| 36 | |
| 37 | Return<uint32_t> BootControl::getCurrentSlot() { |
| 38 | return mModule->getCurrentSlot(mModule); |
| 39 | } |
| 40 | |
| 41 | Return<void> BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { |
| 42 | int ret = mModule->markBootSuccessful(mModule); |
| 43 | struct CommandResult cr; |
| 44 | cr.success = (ret == 0); |
| 45 | cr.errMsg = strerror(-ret); |
| 46 | _hidl_cb(cr); |
| 47 | return Void(); |
| 48 | } |
| 49 | |
| 50 | Return<void> BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { |
| 51 | int ret = mModule->setActiveBootSlot(mModule, slot); |
| 52 | struct CommandResult cr; |
| 53 | cr.success = (ret == 0); |
| 54 | cr.errMsg = strerror(-ret); |
| 55 | _hidl_cb(cr); |
| 56 | return Void(); |
| 57 | } |
| 58 | |
| 59 | Return<void> BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { |
| 60 | int ret = mModule->setSlotAsUnbootable(mModule, slot); |
| 61 | struct CommandResult cr; |
| 62 | cr.success = (ret == 0); |
| 63 | cr.errMsg = strerror(-ret); |
| 64 | _hidl_cb(cr); |
| 65 | return Void(); |
| 66 | } |
| 67 | |
| 68 | Return<BoolResult> BootControl::isSlotBootable(uint32_t slot) { |
| 69 | int32_t ret = mModule->isSlotBootable(mModule, slot); |
| 70 | if (ret < 0) { |
| 71 | return BoolResult::INVALID_SLOT; |
| 72 | } |
| 73 | return ret ? BoolResult::TRUE : BoolResult::FALSE; |
| 74 | } |
| 75 | |
| 76 | Return<BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) { |
| 77 | int32_t ret = mModule->isSlotMarkedSuccessful(mModule, slot); |
| 78 | if (ret < 0) { |
| 79 | return BoolResult::INVALID_SLOT; |
| 80 | } |
| 81 | return ret ? BoolResult::TRUE : BoolResult::FALSE; |
| 82 | } |
| 83 | |
| 84 | Return<void> BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { |
| 85 | hidl_string ans; |
| 86 | const char *suffix = mModule->getSuffix(mModule, slot); |
| 87 | if (suffix) { |
| 88 | ans = suffix; |
| 89 | } |
| 90 | _hidl_cb(ans); |
| 91 | return Void(); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | IBootControl* HIDL_FETCH_IBootControl(const char* hal) { |
| 96 | int ret = 0; |
| 97 | boot_control_module_t* module = NULL; |
| 98 | hw_module_t **hwm = reinterpret_cast<hw_module_t**>(&module); |
| 99 | ret = hw_get_module(hal, const_cast<const hw_module_t**>(hwm)); |
| 100 | if (ret) |
| 101 | { |
| 102 | ALOGE("hw_get_module %s failed: %d", hal, ret); |
| 103 | return nullptr; |
| 104 | } |
| 105 | module->init(module); |
| 106 | return new BootControl(module); |
| 107 | } |
| 108 | |
| 109 | } // namespace implementation |
| 110 | } // namespace V1_0 |
| 111 | } // namespace boot |
| 112 | } // namespace hardware |
| 113 | } // namespace android |