usb: convert gadget hal to aidl
* Based on hardware/interfaces/usb/gadget/aidl/default.
This commit is contained in:
@@ -253,7 +253,7 @@ PRODUCT_PACKAGES += \
|
||||
# USB
|
||||
PRODUCT_PACKAGES += \
|
||||
android.hardware.usb-service.example \
|
||||
android.hardware.usb.gadget@1.2-service.rpi
|
||||
android.hardware.usb.gadget-service.rpi
|
||||
|
||||
PRODUCT_COPY_FILES += \
|
||||
frameworks/native/data/etc/android.hardware.usb.accessory.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.accessory.xml \
|
||||
|
@@ -48,7 +48,7 @@
|
||||
/vendor/bin/suspend_blocker_rpi u:object_r:suspend_blocker_exec:s0
|
||||
|
||||
# USB
|
||||
/vendor/bin/hw/android\.hardware\.usb\.gadget@1\.2-service\.rpi u:object_r:hal_usb_gadget_default_exec:s0
|
||||
/vendor/bin/hw/android\.hardware\.usb\.gadget-service\.rpi u:object_r:hal_usb_gadget_default_exec:s0
|
||||
|
||||
# V4L2
|
||||
/vendor/bin/hw/android\.hardware\.media\.c2@1\.2-service-v4l2(.*)? u:object_r:mediacodec_exec:s0
|
||||
|
@@ -1,23 +1,22 @@
|
||||
// Copyright (C) 2020 The Android Open Source Project
|
||||
// Copyright (C) 2023 KonstaKANG
|
||||
// Copyright (C) 2024 KonstaKANG
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.usb.gadget@1.2-service.rpi",
|
||||
name: "android.hardware.usb.gadget-service.rpi",
|
||||
defaults: ["hidl_defaults"],
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["android.hardware.usb.gadget@1.2-service.rpi.rc"],
|
||||
vintf_fragments: ["android.hardware.usb.gadget@1.2-service.rpi.xml"],
|
||||
init_rc: ["android.hardware.usb.gadget-service.rpi.rc"],
|
||||
vintf_fragments: ["android.hardware.usb.gadget-service.rpi.xml"],
|
||||
vendor: true,
|
||||
srcs: [
|
||||
"service.cpp",
|
||||
"UsbGadget.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"android.hardware.usb.gadget@1.0",
|
||||
"android.hardware.usb.gadget@1.1",
|
||||
"android.hardware.usb.gadget@1.2",
|
||||
"android.hardware.usb.gadget-V1-ndk",
|
||||
"libbinder_ndk",
|
||||
"libbase",
|
||||
"libcutils",
|
||||
"libhardware",
|
||||
@@ -25,5 +24,5 @@ cc_binary {
|
||||
"liblog",
|
||||
"libutils",
|
||||
],
|
||||
static_libs: ["libusbconfigfs-2"],
|
||||
static_libs: ["libusbconfigfs-rpi"],
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* Copyright (C) 2023 KonstaKANG
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.usb.gadget@1.2-service.rpi"
|
||||
#define LOG_TAG "android.hardware.usb.gadget-service.rpi"
|
||||
|
||||
#include "UsbGadget.h"
|
||||
#include <dirent.h>
|
||||
@@ -27,12 +27,11 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
namespace gadget {
|
||||
namespace V1_2 {
|
||||
namespace implementation {
|
||||
|
||||
UsbGadget::UsbGadget() {
|
||||
if (access(OS_DESC_PATH, R_OK) != 0) {
|
||||
@@ -46,16 +45,24 @@ void currentFunctionsAppliedCallback(bool functionsApplied, void* payload) {
|
||||
gadget->mCurrentUsbFunctionsApplied = functionsApplied;
|
||||
}
|
||||
|
||||
Return<void> UsbGadget::getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback>& callback) {
|
||||
Return<void> ret = callback->getCurrentUsbFunctionsCb(
|
||||
mCurrentUsbFunctions, mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED
|
||||
: Status::FUNCTIONS_NOT_APPLIED);
|
||||
if (!ret.isOk()) ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.description().c_str());
|
||||
ScopedAStatus UsbGadget::getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback>& callback,
|
||||
int64_t in_transactionId) {
|
||||
if (callback == nullptr) {
|
||||
return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER);
|
||||
}
|
||||
|
||||
return Void();
|
||||
ScopedAStatus ret = callback->getCurrentUsbFunctionsCb(
|
||||
mCurrentUsbFunctions,
|
||||
mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED : Status::FUNCTIONS_NOT_APPLIED,
|
||||
in_transactionId);
|
||||
if (!ret.isOk())
|
||||
ALOGE("Call to getCurrentUsbFunctionsCb failed %s", ret.getDescription().c_str());
|
||||
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
Return<void> UsbGadget::getUsbSpeed(const sp<V1_2::IUsbGadgetCallback>& callback) {
|
||||
ScopedAStatus UsbGadget::getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) {
|
||||
std::string current_speed;
|
||||
if (ReadFileToString(SPEED_PATH, ¤t_speed)) {
|
||||
current_speed = Trim(current_speed);
|
||||
@@ -72,144 +79,150 @@ Return<void> UsbGadget::getUsbSpeed(const sp<V1_2::IUsbGadgetCallback>& callback
|
||||
mUsbSpeed = UsbSpeed::SUPERSPEED_10Gb;
|
||||
else if (current_speed == "UNKNOWN")
|
||||
mUsbSpeed = UsbSpeed::UNKNOWN;
|
||||
else {
|
||||
/**
|
||||
* This part is used for USB4 or reserved speed.
|
||||
*
|
||||
* If reserved speed is detected, it needs to convert to other speeds.
|
||||
* For example:
|
||||
* If the bandwidth of new speed is 7G, adding new if
|
||||
* statement and set mUsbSpeed to SUPERSPEED.
|
||||
* If the bandwidth of new speed is 80G, adding new if
|
||||
* statement and set mUsbSpeed to USB4_GEN3_40Gb.
|
||||
*/
|
||||
mUsbSpeed = UsbSpeed::RESERVED_SPEED;
|
||||
}
|
||||
else
|
||||
mUsbSpeed = UsbSpeed::UNKNOWN;
|
||||
} else {
|
||||
ALOGE("Fail to read current speed");
|
||||
mUsbSpeed = UsbSpeed::UNKNOWN;
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
Return<void> ret = callback->getUsbSpeedCb(mUsbSpeed);
|
||||
ScopedAStatus ret = callback->getUsbSpeedCb(mUsbSpeed, in_transactionId);
|
||||
|
||||
if (!ret.isOk()) ALOGE("Call to getUsbSpeedCb failed %s", ret.description().c_str());
|
||||
if (!ret.isOk())
|
||||
ALOGE("Call to getUsbSpeedCb failed %s", ret.getDescription().c_str());
|
||||
}
|
||||
|
||||
return Void();
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
V1_0::Status UsbGadget::tearDownGadget() {
|
||||
if (resetGadget() != V1_0::Status::SUCCESS) return V1_0::Status::ERROR;
|
||||
Status UsbGadget::tearDownGadget() {
|
||||
if (resetGadget() != Status::SUCCESS) return Status::ERROR;
|
||||
|
||||
if (monitorFfs.isMonitorRunning()) {
|
||||
monitorFfs.reset();
|
||||
} else {
|
||||
ALOGI("mMonitor not running");
|
||||
}
|
||||
return V1_0::Status::SUCCESS;
|
||||
return Status::SUCCESS;
|
||||
}
|
||||
|
||||
Return<Status> UsbGadget::reset() {
|
||||
ScopedAStatus UsbGadget::reset(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) {
|
||||
if (!WriteStringToFile("none", PULLUP_PATH)) {
|
||||
ALOGI("Gadget cannot be pulled down");
|
||||
return Status::ERROR;
|
||||
if (callback)
|
||||
callback->resetCb(Status::ERROR, in_transactionId);
|
||||
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Error while calling resetCb");
|
||||
}
|
||||
|
||||
usleep(kDisconnectWaitUs);
|
||||
|
||||
if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) {
|
||||
ALOGI("Gadget cannot be pulled up");
|
||||
return Status::ERROR;
|
||||
if (callback)
|
||||
callback->resetCb(Status::ERROR, in_transactionId);
|
||||
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Error while calling resetCb");
|
||||
}
|
||||
|
||||
return Status::SUCCESS;
|
||||
if (callback)
|
||||
callback->resetCb(Status::SUCCESS, in_transactionId);
|
||||
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
static V1_0::Status validateAndSetVidPid(uint64_t functions) {
|
||||
V1_0::Status ret = V1_0::Status::SUCCESS;
|
||||
static Status validateAndSetVidPid(uint64_t functions) {
|
||||
Status ret = Status::SUCCESS;
|
||||
|
||||
switch (functions) {
|
||||
case static_cast<uint64_t>(V1_2::GadgetFunction::MTP):
|
||||
case GadgetFunction::MTP:
|
||||
ret = setVidPid("0x18d1", "0x4ee1");
|
||||
break;
|
||||
case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::MTP:
|
||||
case GadgetFunction::ADB | GadgetFunction::MTP:
|
||||
ret = setVidPid("0x18d1", "0x4ee2");
|
||||
break;
|
||||
case static_cast<uint64_t>(V1_2::GadgetFunction::RNDIS):
|
||||
case GadgetFunction::RNDIS:
|
||||
ret = setVidPid("0x18d1", "0x4ee3");
|
||||
break;
|
||||
case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::RNDIS:
|
||||
case GadgetFunction::ADB | GadgetFunction::RNDIS:
|
||||
ret = setVidPid("0x18d1", "0x4ee4");
|
||||
break;
|
||||
case static_cast<uint64_t>(V1_2::GadgetFunction::PTP):
|
||||
case GadgetFunction::PTP:
|
||||
ret = setVidPid("0x18d1", "0x4ee5");
|
||||
break;
|
||||
case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::PTP:
|
||||
case GadgetFunction::ADB | GadgetFunction::PTP:
|
||||
ret = setVidPid("0x18d1", "0x4ee6");
|
||||
break;
|
||||
case static_cast<uint64_t>(V1_2::GadgetFunction::ADB):
|
||||
case GadgetFunction::ADB:
|
||||
ret = setVidPid("0x18d1", "0x4ee7");
|
||||
break;
|
||||
case static_cast<uint64_t>(V1_2::GadgetFunction::MIDI):
|
||||
case GadgetFunction::MIDI:
|
||||
ret = setVidPid("0x18d1", "0x4ee8");
|
||||
break;
|
||||
case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::MIDI:
|
||||
case GadgetFunction::ADB | GadgetFunction::MIDI:
|
||||
ret = setVidPid("0x18d1", "0x4ee9");
|
||||
break;
|
||||
case static_cast<uint64_t>(V1_2::GadgetFunction::NCM):
|
||||
case GadgetFunction::NCM:
|
||||
ret = setVidPid("0x18d1", "0x4eeb");
|
||||
break;
|
||||
case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::NCM:
|
||||
case GadgetFunction::ADB | GadgetFunction::NCM:
|
||||
ret = setVidPid("0x18d1", "0x4eec");
|
||||
break;
|
||||
case static_cast<uint64_t>(V1_2::GadgetFunction::ACCESSORY):
|
||||
case GadgetFunction::ACCESSORY:
|
||||
ret = setVidPid("0x18d1", "0x2d00");
|
||||
break;
|
||||
case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::ACCESSORY:
|
||||
case GadgetFunction::ADB | GadgetFunction::ACCESSORY:
|
||||
ret = setVidPid("0x18d1", "0x2d01");
|
||||
break;
|
||||
case static_cast<uint64_t>(V1_2::GadgetFunction::AUDIO_SOURCE):
|
||||
case GadgetFunction::AUDIO_SOURCE:
|
||||
ret = setVidPid("0x18d1", "0x2d02");
|
||||
break;
|
||||
case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::AUDIO_SOURCE:
|
||||
case GadgetFunction::ADB | GadgetFunction::AUDIO_SOURCE:
|
||||
ret = setVidPid("0x18d1", "0x2d03");
|
||||
break;
|
||||
case V1_2::GadgetFunction::ACCESSORY | V1_2::GadgetFunction::AUDIO_SOURCE:
|
||||
case GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE:
|
||||
ret = setVidPid("0x18d1", "0x2d04");
|
||||
break;
|
||||
case V1_2::GadgetFunction::ADB | V1_2::GadgetFunction::ACCESSORY |
|
||||
V1_2::GadgetFunction::AUDIO_SOURCE:
|
||||
case GadgetFunction::ADB | GadgetFunction::ACCESSORY |
|
||||
GadgetFunction::AUDIO_SOURCE:
|
||||
ret = setVidPid("0x18d1", "0x2d05");
|
||||
break;
|
||||
default:
|
||||
ALOGE("Combination not supported");
|
||||
ret = V1_0::Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
ret = Status::CONFIGURATION_NOT_SUPPORTED;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
|
||||
const sp<V1_0::IUsbGadgetCallback>& callback,
|
||||
uint64_t timeout) {
|
||||
Status UsbGadget::setupFunctions(long functions,
|
||||
const shared_ptr<IUsbGadgetCallback> &callback, uint64_t timeout,
|
||||
int64_t in_transactionId) {
|
||||
bool ffsEnabled = false;
|
||||
int i = 0;
|
||||
|
||||
if (addGenericAndroidFunctions(&monitorFfs, functions, &ffsEnabled, &i) !=
|
||||
V1_0::Status::SUCCESS)
|
||||
return V1_0::Status::ERROR;
|
||||
Status::SUCCESS)
|
||||
return Status::ERROR;
|
||||
|
||||
if ((functions & V1_2::GadgetFunction::ADB) != 0) {
|
||||
if ((functions & GadgetFunction::ADB) != 0) {
|
||||
ffsEnabled = true;
|
||||
if (addAdb(&monitorFfs, &i) != V1_0::Status::SUCCESS) return V1_0::Status::ERROR;
|
||||
if (addAdb(&monitorFfs, &i) != Status::SUCCESS) return Status::ERROR;
|
||||
}
|
||||
|
||||
// Pull up the gadget right away when there are no ffs functions.
|
||||
if (!ffsEnabled) {
|
||||
if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) return V1_0::Status::ERROR;
|
||||
if (!WriteStringToFile(kGadgetName, PULLUP_PATH))
|
||||
return Status::ERROR;
|
||||
mCurrentUsbFunctionsApplied = true;
|
||||
if (callback) callback->setCurrentUsbFunctionsCb(functions, V1_0::Status::SUCCESS);
|
||||
return V1_0::Status::SUCCESS;
|
||||
|
||||
if (callback)
|
||||
callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
|
||||
|
||||
return Status::SUCCESS;
|
||||
}
|
||||
|
||||
monitorFfs.registerFunctionsAppliedCallback(¤tFunctionsAppliedCallback, this);
|
||||
@@ -222,25 +235,28 @@ V1_0::Status UsbGadget::setupFunctions(uint64_t functions,
|
||||
|
||||
if (callback) {
|
||||
bool pullup = monitorFfs.waitForPullUp(timeout);
|
||||
Return<void> ret = callback->setCurrentUsbFunctionsCb(
|
||||
functions, pullup ? V1_0::Status::SUCCESS : V1_0::Status::ERROR);
|
||||
if (!ret.isOk()) ALOGE("setCurrentUsbFunctionsCb error %s", ret.description().c_str());
|
||||
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions,
|
||||
pullup ? Status::SUCCESS : Status::ERROR,
|
||||
in_transactionId);
|
||||
if (!ret.isOk())
|
||||
ALOGE("setCurrentUsbFunctionsCb error %s", ret.getMessage());
|
||||
}
|
||||
|
||||
return V1_0::Status::SUCCESS;
|
||||
return Status::SUCCESS;
|
||||
}
|
||||
|
||||
Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
||||
const sp<V1_0::IUsbGadgetCallback>& callback,
|
||||
uint64_t timeout) {
|
||||
ScopedAStatus UsbGadget::setCurrentUsbFunctions(int64_t functions,
|
||||
const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t timeoutMs,
|
||||
int64_t in_transactionId) {
|
||||
std::unique_lock<std::mutex> lk(mLockSetCurrentFunction);
|
||||
|
||||
mCurrentUsbFunctions = functions;
|
||||
mCurrentUsbFunctionsApplied = false;
|
||||
|
||||
// Unlink the gadget and stop the monitor if running.
|
||||
V1_0::Status status = tearDownGadget();
|
||||
if (status != V1_0::Status::SUCCESS) {
|
||||
Status status = tearDownGadget();
|
||||
if (status != Status::SUCCESS) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -249,39 +265,45 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions,
|
||||
// Leave the gadget pulled down to give time for the host to sense disconnect.
|
||||
usleep(kDisconnectWaitUs);
|
||||
|
||||
if (functions == static_cast<uint64_t>(V1_2::GadgetFunction::NONE)) {
|
||||
if (callback == NULL) return Void();
|
||||
Return<void> ret = callback->setCurrentUsbFunctionsCb(functions, V1_0::Status::SUCCESS);
|
||||
if (functions == GadgetFunction::NONE) {
|
||||
if (callback == NULL)
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "callback == NULL");
|
||||
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS, in_transactionId);
|
||||
if (!ret.isOk())
|
||||
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str());
|
||||
return Void();
|
||||
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str());
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Error while calling setCurrentUsbFunctionsCb");
|
||||
}
|
||||
|
||||
status = validateAndSetVidPid(functions);
|
||||
|
||||
if (status != V1_0::Status::SUCCESS) {
|
||||
if (status != Status::SUCCESS) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
status = setupFunctions(functions, callback, timeout);
|
||||
if (status != V1_0::Status::SUCCESS) {
|
||||
status = setupFunctions(functions, callback, timeoutMs, in_transactionId);
|
||||
if (status != Status::SUCCESS) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
ALOGI("Usb Gadget setcurrent functions called successfully");
|
||||
return Void();
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Usb Gadget setcurrent functions called successfully");
|
||||
|
||||
error:
|
||||
ALOGI("Usb Gadget setcurrent functions failed");
|
||||
if (callback == NULL) return Void();
|
||||
Return<void> ret = callback->setCurrentUsbFunctionsCb(functions, status);
|
||||
if (callback == NULL)
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Usb Gadget setcurrent functions failed");
|
||||
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, status, in_transactionId);
|
||||
if (!ret.isOk())
|
||||
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str());
|
||||
return Void();
|
||||
ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.getDescription().c_str());
|
||||
return ScopedAStatus::fromServiceSpecificErrorWithMessage(
|
||||
-1, "Error while calling setCurrentUsbFunctionsCb");
|
||||
}
|
||||
} // namespace implementation
|
||||
} // namespace V1_2
|
||||
} // namespace gadget
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // aidl
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* Copyright (C) 2023 KonstaKANG
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,18 +15,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_HARDWARE_USB_GADGET_V1_2_USBGADGET_H
|
||||
#define ANDROID_HARDWARE_USB_GADGET_V1_2_USBGADGET_H
|
||||
#pragma once
|
||||
|
||||
#include <UsbGadgetCommon.h>
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <android/hardware/usb/gadget/1.2/IUsbGadget.h>
|
||||
#include <android/hardware/usb/gadget/1.2/types.h>
|
||||
#include <hidl/MQDescriptor.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <aidl/android/hardware/usb/gadget/BnUsbGadget.h>
|
||||
#include <aidl/android/hardware/usb/gadget/BnUsbGadgetCallback.h>
|
||||
#include <aidl/android/hardware/usb/gadget/GadgetFunction.h>
|
||||
#include <aidl/android/hardware/usb/gadget/IUsbGadget.h>
|
||||
#include <aidl/android/hardware/usb/gadget/IUsbGadgetCallback.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <utils/Log.h>
|
||||
@@ -36,36 +36,25 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
namespace gadget {
|
||||
namespace V1_2 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::sp;
|
||||
using ::aidl::android::hardware::usb::gadget::GadgetFunction;
|
||||
using ::aidl::android::hardware::usb::gadget::IUsbGadgetCallback;
|
||||
using ::aidl::android::hardware::usb::gadget::IUsbGadget;
|
||||
using ::aidl::android::hardware::usb::gadget::Status;
|
||||
using ::aidl::android::hardware::usb::gadget::UsbSpeed;
|
||||
using ::android::base::GetProperty;
|
||||
using ::android::base::ReadFileToString;
|
||||
using ::android::base::SetProperty;
|
||||
using ::android::base::Trim;
|
||||
using ::android::base::unique_fd;
|
||||
using ::android::base::ReadFileToString;
|
||||
using ::android::base::Trim;
|
||||
using ::android::base::WriteStringToFile;
|
||||
using ::android::hardware::hidl_array;
|
||||
using ::android::hardware::hidl_memory;
|
||||
using ::android::hardware::hidl_string;
|
||||
using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::hardware::usb::gadget::addAdb;
|
||||
using ::android::hardware::usb::gadget::addEpollFd;
|
||||
using ::android::hardware::usb::gadget::getVendorFunctions;
|
||||
using ::android::hardware::usb::gadget::kDebug;
|
||||
using ::android::hardware::usb::gadget::kDisconnectWaitUs;
|
||||
using ::android::hardware::usb::gadget::linkFunction;
|
||||
using ::android::hardware::usb::gadget::MonitorFfs;
|
||||
using ::android::hardware::usb::gadget::resetGadget;
|
||||
using ::android::hardware::usb::gadget::setVidPid;
|
||||
using ::android::hardware::usb::gadget::unlinkFunctions;
|
||||
using ::ndk::ScopedAStatus;
|
||||
using ::std::shared_ptr;
|
||||
using ::std::string;
|
||||
|
||||
constexpr char kGadgetName[] = "fe980000.usb";
|
||||
@@ -74,36 +63,36 @@ static MonitorFfs monitorFfs(kGadgetName);
|
||||
#define UDC_PATH "/sys/class/udc/fe980000.usb/"
|
||||
#define SPEED_PATH UDC_PATH "current_speed"
|
||||
|
||||
struct UsbGadget : public IUsbGadget {
|
||||
struct UsbGadget : public BnUsbGadget {
|
||||
UsbGadget();
|
||||
|
||||
// Makes sure that only one request is processed at a time.
|
||||
std::mutex mLockSetCurrentFunction;
|
||||
uint64_t mCurrentUsbFunctions;
|
||||
long mCurrentUsbFunctions;
|
||||
bool mCurrentUsbFunctionsApplied;
|
||||
UsbSpeed mUsbSpeed;
|
||||
|
||||
Return<void> setCurrentUsbFunctions(uint64_t functions,
|
||||
const sp<V1_0::IUsbGadgetCallback>& callback,
|
||||
uint64_t timeout) override;
|
||||
ScopedAStatus setCurrentUsbFunctions(int64_t functions,
|
||||
const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t timeoutMs, int64_t in_transactionId) override;
|
||||
|
||||
Return<void> getCurrentUsbFunctions(const sp<V1_0::IUsbGadgetCallback>& callback) override;
|
||||
ScopedAStatus getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) override;
|
||||
|
||||
Return<Status> reset() override;
|
||||
ScopedAStatus reset(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) override;
|
||||
|
||||
Return<void> getUsbSpeed(const sp<V1_2::IUsbGadgetCallback>& callback) override;
|
||||
ScopedAStatus getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
int64_t in_transactionId) override;
|
||||
|
||||
private:
|
||||
V1_0::Status tearDownGadget();
|
||||
V1_0::Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback>& callback,
|
||||
uint64_t timeout);
|
||||
Status tearDownGadget();
|
||||
Status setupFunctions(long functions, const shared_ptr<IUsbGadgetCallback> &callback,
|
||||
uint64_t timeout, int64_t in_transactionId);
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_2
|
||||
} // namespace gadget
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_HARDWARE_USB_V1_2_USBGADGET_H
|
||||
} // aidl
|
||||
|
4
usb/android.hardware.usb.gadget-service.rpi.rc
Normal file
4
usb/android.hardware.usb.gadget-service.rpi.rc
Normal file
@@ -0,0 +1,4 @@
|
||||
service vendor.usb_gadget-default /vendor/bin/hw/android.hardware.usb.gadget-service.rpi
|
||||
class hal
|
||||
user system
|
||||
group system shell mtp
|
@@ -1,8 +1,7 @@
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="hidl">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.usb.gadget</name>
|
||||
<transport>hwbinder</transport>
|
||||
<version>1.2</version>
|
||||
<version>1</version>
|
||||
<interface>
|
||||
<name>IUsbGadget</name>
|
||||
<instance>default</instance>
|
@@ -1,7 +0,0 @@
|
||||
service vendor.usb-gadget-hal-1-2 /vendor/bin/hw/android.hardware.usb.gadget@1.2-service.rpi
|
||||
interface android.hardware.usb.gadget@1.0::IUsbGadget default
|
||||
interface android.hardware.usb.gadget@1.1::IUsbGadget default
|
||||
interface android.hardware.usb.gadget@1.2::IUsbGadget default
|
||||
class hal
|
||||
user system
|
||||
group system shell mtp
|
@@ -1,30 +1,10 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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"],
|
||||
}
|
||||
// Copyright (C) 2020 The Android Open Source Project
|
||||
// Copyright (C) 2024 KonstaKANG
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cc_library_static {
|
||||
name: "libusbconfigfs-2",
|
||||
name: "libusbconfigfs-rpi",
|
||||
vendor_available: true,
|
||||
export_include_dirs: ["include"],
|
||||
|
||||
@@ -39,9 +19,7 @@ cc_library_static {
|
||||
],
|
||||
|
||||
shared_libs: [
|
||||
"android.hardware.usb.gadget@1.0",
|
||||
"android.hardware.usb.gadget@1.1",
|
||||
"android.hardware.usb.gadget@1.2",
|
||||
"android.hardware.usb.gadget-V1-ndk",
|
||||
"libbase",
|
||||
"libcutils",
|
||||
"libhidlbase",
|
||||
|
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +19,7 @@
|
||||
|
||||
#include "include/UsbGadgetCommon.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
@@ -267,3 +269,4 @@ void MonitorFfs::registerFunctionsAppliedCallback(void (*callback)(bool function
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +19,7 @@
|
||||
|
||||
#include "include/UsbGadgetCommon.h"
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
@@ -205,3 +207,4 @@ Status addAdb(MonitorFfs* monitorFfs, int* functionCount) {
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,8 +22,8 @@
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
|
||||
#include <android/hardware/usb/gadget/1.2/IUsbGadget.h>
|
||||
#include <android/hardware/usb/gadget/1.2/types.h>
|
||||
#include <aidl/android/hardware/usb/gadget/IUsbGadget.h>
|
||||
#include <aidl/android/hardware/usb/gadget/GadgetFunction.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
@@ -41,6 +42,7 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace usb {
|
||||
@@ -79,8 +81,8 @@ using ::android::base::GetProperty;
|
||||
using ::android::base::SetProperty;
|
||||
using ::android::base::unique_fd;
|
||||
using ::android::base::WriteStringToFile;
|
||||
using ::android::hardware::usb::gadget::V1_0::Status;
|
||||
using ::android::hardware::usb::gadget::V1_2::GadgetFunction;
|
||||
using ::aidl::android::hardware::usb::gadget::GadgetFunction;
|
||||
using ::aidl::android::hardware::usb::gadget::Status;
|
||||
|
||||
using ::std::lock_guard;
|
||||
using ::std::move;
|
||||
@@ -176,4 +178,5 @@ Status resetGadget();
|
||||
} // namespace usb
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
#endif
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* Copyright (C) 2023 KonstaKANG
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
* Copyright (C) 2024 KonstaKANG
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,39 +15,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.usb.gadget@1.2-service.rpi"
|
||||
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
#include "UsbGadget.h"
|
||||
|
||||
using android::sp;
|
||||
|
||||
// libhwbinder:
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
using android::hardware::joinRpcThreadpool;
|
||||
|
||||
// Generated HIDL files
|
||||
using android::hardware::usb::gadget::V1_2::IUsbGadget;
|
||||
using android::hardware::usb::gadget::V1_2::implementation::UsbGadget;
|
||||
|
||||
using android::OK;
|
||||
using android::status_t;
|
||||
using ::aidl::android::hardware::usb::gadget::UsbGadget;
|
||||
|
||||
int main() {
|
||||
configureRpcThreadpool(1, true /*callerWillJoin*/);
|
||||
|
||||
android::sp<IUsbGadget> service = new UsbGadget();
|
||||
|
||||
status_t status = service->registerAsService();
|
||||
|
||||
if (status != OK) {
|
||||
ALOGE("Cannot register USB Gadget HAL service");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ALOGI("USB Gadget HAL Ready.");
|
||||
joinRpcThreadpool();
|
||||
// Under noraml cases, execution will not reach this line.
|
||||
ALOGI("USB Gadget HAL failed to join thread pool.");
|
||||
return 1;
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<UsbGadget> usbgadget = ndk::SharedRefBase::make<UsbGadget>();
|
||||
const std::string instance = std::string() + UsbGadget::descriptor + "/default";
|
||||
binder_status_t status = AServiceManager_addService(usbgadget->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
ABinderProcess_joinThreadPool();
|
||||
return -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user