blob: 54c1928bfb48ffa351182eb2a435d5296776c127 [file] [log] [blame]
Steven Moreland9f8b5c72016-11-29 15:03:38 -08001/*
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'Brien74f82922016-10-10 12:31:37 -070016#define LOG_TAG "android.hardware.boot@1.0-impl"
Yifan Hong65cbd602016-12-01 15:58:37 -080017#include <android/log.h>
Connor O'Brien74f82922016-10-10 12:31:37 -070018
19#include <hardware/hardware.h>
20#include <hardware/boot_control.h>
21#include "BootControl.h"
22
23namespace android {
24namespace hardware {
25namespace boot {
26namespace V1_0 {
27namespace implementation {
28
29BootControl::BootControl(boot_control_module_t *module) : mModule(module){
30}
31
32// Methods from ::android::hardware::boot::V1_0::IBootControl follow.
33Return<uint32_t> BootControl::getNumberSlots() {
34 return mModule->getNumberSlots(mModule);
35}
36
37Return<uint32_t> BootControl::getCurrentSlot() {
38 return mModule->getCurrentSlot(mModule);
39}
40
41Return<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
50Return<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
59Return<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
68Return<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
76Return<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
84Return<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
95IBootControl* 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