mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Fastboot AIDL additional changes
* Fastbootshim library which wraps HIDL implementation as AIDL * Change default implementation from library to binary Bug: 205760652 Test: Build Change-Id: If92d28d68f1d454b1a65f85e731a78a49b108635 Signed-off-by: Sandeep Dhavale <dhavale@google.com>
This commit is contained in:
@@ -22,16 +22,20 @@ package {
|
||||
default_applicable_licenses: ["hardware_interfaces_license"],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "android.hardware.fastboot-impl-mock",
|
||||
recovery: true,
|
||||
cc_binary {
|
||||
name: "android.hardware.fastboot-service.example_recovery",
|
||||
init_rc: ["android.hardware.fastboot-service.example_recovery.rc"],
|
||||
vintf_fragments: ["android.hardware.fastboot-service.example.xml"],
|
||||
recovery_available: true,
|
||||
srcs: [
|
||||
"Fastboot.cpp",
|
||||
"main.cpp",
|
||||
],
|
||||
relative_install_path: "hw",
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"libcutils",
|
||||
"android.hardware.fastboot-V1-ndk",
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.fastboot</name>
|
||||
<version>1</version>
|
||||
<fqname>IFastboot/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
service vendor.fastboot-default /system/bin/hw/android.hardware.fastboot-service.example_recovery
|
||||
class hal
|
||||
seclabel u:r:hal_fastboot_default:s0
|
||||
user system
|
||||
group system
|
||||
interface aidl android.hardware.fastboot.IFastboot/default
|
||||
38
fastboot/aidl/default/main.cpp
Normal file
38
fastboot/aidl/default/main.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
#include "Fastboot.h"
|
||||
|
||||
using aidl::android::hardware::fastboot::Fastboot;
|
||||
using aidl::android::hardware::fastboot::IFastboot;
|
||||
|
||||
int main(int, char* argv[]) {
|
||||
android::base::InitLogging(argv, android::base::KernelLogger);
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<IFastboot> service = ndk::SharedRefBase::make<Fastboot>();
|
||||
|
||||
const std::string instance = std::string(IFastboot::descriptor) + "/default";
|
||||
auto status = AServiceManager_addService(service->asBinder().get(), instance.c_str());
|
||||
CHECK_EQ(status, STATUS_OK) << "Failed to add service " << instance << " " << status;
|
||||
LOG(INFO) << "IFastboot AIDL service running...";
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
}
|
||||
61
fastboot/aidl/fastbootshim/Android.bp
Normal file
61
fastboot/aidl/fastbootshim/Android.bp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2022 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package {
|
||||
// See: http://go/android-license-faq
|
||||
// A large-scale-change added 'default_applicable_licenses' to import
|
||||
// all of the 'license_kinds' from "hardware_interfaces_license"
|
||||
// to get the below license kinds:
|
||||
// SPDX-license-identifier-Apache-2.0
|
||||
default_applicable_licenses: ["hardware_interfaces_license"],
|
||||
}
|
||||
|
||||
cc_defaults {
|
||||
name: "libfastbootshim_defaults",
|
||||
target: {
|
||||
darwin: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.fastboot-V1-ndk",
|
||||
"android.hardware.fastboot@1.0",
|
||||
"android.hardware.fastboot@1.1",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"libcutils",
|
||||
"libhidlbase",
|
||||
"liblog",
|
||||
"libutils",
|
||||
],
|
||||
}
|
||||
|
||||
// Shim library that wraps a HIDL Fastboot object into an AIDL Fastboot object.
|
||||
cc_library_static {
|
||||
name: "libfastbootshim",
|
||||
defaults: ["libfastbootshim_defaults"],
|
||||
recovery_available: true,
|
||||
srcs: [
|
||||
"fastbootshim.cpp",
|
||||
],
|
||||
export_include_dirs: [
|
||||
"include",
|
||||
],
|
||||
}
|
||||
123
fastboot/aidl/fastbootshim/fastbootshim.cpp
Normal file
123
fastboot/aidl/fastbootshim/fastbootshim.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <fastbootshim.h>
|
||||
|
||||
using ::android::sp;
|
||||
using ::android::hardware::hidl_string;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::hardware::fastboot::V1_0::FileSystemType;
|
||||
using ::android::hardware::fastboot::V1_0::Result;
|
||||
using ::android::hardware::fastboot::V1_0::Status;
|
||||
|
||||
using ndk::ScopedAStatus;
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace fastboot {
|
||||
ScopedAStatus ResultToAStatus(Result result) {
|
||||
switch (result.status) {
|
||||
case Status::SUCCESS:
|
||||
return ScopedAStatus::ok();
|
||||
case Status::NOT_SUPPORTED:
|
||||
return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
case Status::INVALID_ARGUMENT:
|
||||
return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||
case Status::FAILURE_UNKNOWN:
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
BnFastboot::FAILURE_UNKNOWN, ("Error " + std::string(result.message)).c_str());
|
||||
}
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
BnFastboot::FAILURE_UNKNOWN,
|
||||
("Unrecognized status value " + toString(result.status)).c_str());
|
||||
}
|
||||
FastbootShim::FastbootShim(const sp<HidlFastboot>& service) : service_(service) {}
|
||||
|
||||
ScopedAStatus FastbootShim::getPartitionType(const std::string& in_partitionName,
|
||||
FileSystemType* _aidl_return) {
|
||||
Result out_result = {Status::FAILURE_UNKNOWN, ""};
|
||||
if (in_partitionName.empty()) {
|
||||
return ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
|
||||
"Invalid partition name");
|
||||
}
|
||||
const hidl_string partition = in_partitionName;
|
||||
auto ret = service_->getPartitionType(partition, [&](auto type, auto& result) {
|
||||
out_result = result;
|
||||
if (out_result.status != Status::SUCCESS) return;
|
||||
*_aidl_return = static_cast<aidl::android::hardware::fastboot::FileSystemType>(type);
|
||||
});
|
||||
return ResultToAStatus(out_result);
|
||||
}
|
||||
|
||||
ScopedAStatus FastbootShim::doOemCommand(const std::string& in_oemCmd, std::string* _aidl_return) {
|
||||
Result out_result = {Status::FAILURE_UNKNOWN, ""};
|
||||
*_aidl_return = "";
|
||||
if (in_oemCmd.empty()) {
|
||||
return ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT, "Invalid command");
|
||||
}
|
||||
const hidl_string oemCmdArgs = in_oemCmd;
|
||||
auto ret = service_->doOemCommand(oemCmdArgs, [&](auto& result) {
|
||||
out_result = result;
|
||||
if (out_result.status != Status::SUCCESS) return;
|
||||
*_aidl_return = std::string(result.message.c_str());
|
||||
});
|
||||
return ResultToAStatus(out_result);
|
||||
}
|
||||
|
||||
ScopedAStatus FastbootShim::getVariant(std::string* _aidl_return) {
|
||||
Result out_result = {Status::FAILURE_UNKNOWN, ""};
|
||||
*_aidl_return = "";
|
||||
auto ret = service_->getVariant([&](auto& variant, auto& result) {
|
||||
out_result = result;
|
||||
if (out_result.status != Status::SUCCESS) return;
|
||||
*_aidl_return = std::string(variant.c_str());
|
||||
});
|
||||
return ResultToAStatus(out_result);
|
||||
}
|
||||
|
||||
ScopedAStatus FastbootShim::getOffModeChargeState(bool* _aidl_return) {
|
||||
Result out_result = {Status::FAILURE_UNKNOWN, ""};
|
||||
*_aidl_return = false;
|
||||
auto ret = service_->getOffModeChargeState([&](auto state, auto& result) {
|
||||
out_result = result;
|
||||
if (out_result.status != Status::SUCCESS) return;
|
||||
*_aidl_return = state;
|
||||
});
|
||||
return ResultToAStatus(out_result);
|
||||
}
|
||||
|
||||
ScopedAStatus FastbootShim::getBatteryVoltageFlashingThreshold(int32_t* _aidl_return) {
|
||||
Result out_result = {Status::FAILURE_UNKNOWN, ""};
|
||||
*_aidl_return = 0;
|
||||
auto ret = service_->getBatteryVoltageFlashingThreshold([&](auto batteryVoltage, auto& result) {
|
||||
out_result = result;
|
||||
if (out_result.status != Status::SUCCESS) return;
|
||||
*_aidl_return = batteryVoltage;
|
||||
});
|
||||
return ResultToAStatus(out_result);
|
||||
}
|
||||
|
||||
ScopedAStatus FastbootShim::doOemSpecificErase() {
|
||||
Result out_result = {Status::FAILURE_UNKNOWN, ""};
|
||||
auto ret = service_->doOemSpecificErase([&](auto& result) { out_result = result; });
|
||||
return ResultToAStatus(out_result);
|
||||
}
|
||||
|
||||
} // namespace fastboot
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
49
fastboot/aidl/fastbootshim/include/fastbootshim.h
Normal file
49
fastboot/aidl/fastbootshim/include/fastbootshim.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/android/hardware/fastboot/BnFastboot.h>
|
||||
#include <android/hardware/fastboot/1.1/IFastboot.h>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace fastboot {
|
||||
// Shim that wraps HIDL IFastboot with AIDL BnFastboot
|
||||
class FastbootShim : public BnFastboot {
|
||||
using HidlFastboot = ::android::hardware::fastboot::V1_1::IFastboot;
|
||||
|
||||
public:
|
||||
explicit FastbootShim(const ::android::sp<HidlFastboot>& service);
|
||||
::ndk::ScopedAStatus doOemCommand(const std::string& in_oemCmd,
|
||||
std::string* _aidl_return) override;
|
||||
::ndk::ScopedAStatus doOemSpecificErase() override;
|
||||
::ndk::ScopedAStatus getBatteryVoltageFlashingThreshold(int32_t* _aidl_return) override;
|
||||
::ndk::ScopedAStatus getOffModeChargeState(bool* _aidl_return) override;
|
||||
::ndk::ScopedAStatus getPartitionType(
|
||||
const std::string& in_partitionName,
|
||||
::aidl::android::hardware::fastboot::FileSystemType* _aidl_return) override;
|
||||
::ndk::ScopedAStatus getVariant(std::string* _aidl_return) override;
|
||||
|
||||
private:
|
||||
::android::sp<HidlFastboot> service_;
|
||||
};
|
||||
|
||||
} // namespace fastboot
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
Reference in New Issue
Block a user