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