blob: 83ee1d27d1669dd9d1ae745d5c89d88498852599 [file] [log] [blame]
Connor O'Brienfe25fd82016-10-10 12:31:37 -07001#define LOG_TAG "android.hardware.boot@1.0-impl"
Mark Salyzyna4842ac2017-01-10 10:16:48 -08002
3#include <log/log.h>
Connor O'Brienfe25fd82016-10-10 12:31:37 -07004
5#include <hardware/hardware.h>
6#include <hardware/boot_control.h>
7#include "BootControl.h"
8
9namespace android {
10namespace hardware {
11namespace boot {
12namespace V1_0 {
13namespace implementation {
14
15BootControl::BootControl(boot_control_module_t *module) : mModule(module){
16}
17
18// Methods from ::android::hardware::boot::V1_0::IBootControl follow.
19Return<uint32_t> BootControl::getNumberSlots() {
20 return mModule->getNumberSlots(mModule);
21}
22
23Return<uint32_t> BootControl::getCurrentSlot() {
24 return mModule->getCurrentSlot(mModule);
25}
26
27Return<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
36Return<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
45Return<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
54Return<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
62Return<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
70Return<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 Phoenix5f578222017-01-20 13:46:36 -080081IBootControl* HIDL_FETCH_IBootControl(const char* /* hal */) {
Connor O'Brienfe25fd82016-10-10 12:31:37 -070082 int ret = 0;
83 boot_control_module_t* module = NULL;
84 hw_module_t **hwm = reinterpret_cast<hw_module_t**>(&module);
Chris Phoenix5f578222017-01-20 13:46:36 -080085 ret = hw_get_module(BOOT_CONTROL_HARDWARE_MODULE_ID, const_cast<const hw_module_t**>(hwm));
Connor O'Brienfe25fd82016-10-10 12:31:37 -070086 if (ret)
87 {
Chris Phoenix5f578222017-01-20 13:46:36 -080088 ALOGE("hw_get_module %s failed: %d", BOOT_CONTROL_HARDWARE_MODULE_ID, ret);
Connor O'Brienfe25fd82016-10-10 12:31:37 -070089 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