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