usb: convert gadget to apex

This commit is contained in:
Konsta
2025-03-15 13:46:59 +02:00
parent 14b1e06e9d
commit 2e3182f4cc
11 changed files with 50 additions and 46 deletions

View File

@@ -261,7 +261,7 @@ PRODUCT_COPY_FILES += \
# USB # USB
PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \
com.android.hardware.usb \ com.android.hardware.usb \
android.hardware.usb.gadget-service.rpi com.android.hardware.usb.gadget.rpi5
PRODUCT_COPY_FILES += \ PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.usb.accessory.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.accessory.xml \ frameworks/native/data/etc/android.hardware.usb.accessory.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.accessory.xml \

View File

@@ -40,6 +40,3 @@
# Suspend # Suspend
/vendor/bin/suspend_blocker_rpi u:object_r:suspend_blocker_exec:s0 /vendor/bin/suspend_blocker_rpi u:object_r:suspend_blocker_exec:s0
# USB
/vendor/bin/hw/android\.hardware\.usb\.gadget-service\.rpi u:object_r:hal_usb_gadget_default_exec:s0

View File

@@ -5,24 +5,49 @@
cc_binary { cc_binary {
name: "android.hardware.usb.gadget-service.rpi", name: "android.hardware.usb.gadget-service.rpi",
defaults: ["hidl_defaults"],
relative_install_path: "hw", relative_install_path: "hw",
init_rc: ["android.hardware.usb.gadget-service.rpi.rc"],
vintf_fragments: ["android.hardware.usb.gadget-service.rpi.xml"],
vendor: true, vendor: true,
srcs: [ srcs: [
"service.cpp", "MonitorFfs.cpp",
"UsbGadget.cpp", "UsbGadget.cpp",
"UsbGadgetUtils.cpp",
"main.cpp",
], ],
shared_libs: [ shared_libs: [
"android.hardware.usb.gadget-V1-ndk", "android.hardware.usb.gadget-V1-ndk",
"libbinder_ndk",
"libbase", "libbase",
"libcutils", "libbinder_ndk",
"libhardware",
"libhidlbase",
"liblog", "liblog",
"libutils", "libutils",
], ],
static_libs: ["libusbconfigfs-rpi"], installable: false,
}
prebuilt_etc {
name: "android.hardware.usb.gadget-service.rpi.rc",
src: "android.hardware.usb.gadget-service.rpi.rc",
installable: false,
}
prebuilt_etc {
name: "android.hardware.usb.gadget-service.rpi.xml",
src: "android.hardware.usb.gadget-service.rpi.xml",
sub_dir: "vintf",
installable: false,
}
apex {
name: "com.android.hardware.usb.gadget.rpi5",
manifest: "apex_manifest.json",
file_contexts: "apex_file_contexts",
key: "com.android.hardware.key",
certificate: ":com.android.hardware.certificate",
updatable: false,
vendor: true,
binaries: ["android.hardware.usb.gadget-service.rpi"],
prebuilts: [
"android.hardware.usb.gadget-service.rpi.rc",
"android.hardware.usb.gadget-service.rpi.xml",
],
} }

View File

@@ -17,7 +17,7 @@
#define LOG_TAG "libusbconfigfs" #define LOG_TAG "libusbconfigfs"
#include "include/UsbGadgetCommon.h" #include "UsbGadgetCommon.h"
namespace aidl { namespace aidl {
namespace android { namespace android {

View File

@@ -17,7 +17,7 @@
#define LOG_TAG "libusbconfigfs" #define LOG_TAG "libusbconfigfs"
#include "include/UsbGadgetCommon.h" #include "UsbGadgetCommon.h"
namespace aidl { namespace aidl {
namespace android { namespace android {

View File

@@ -1,4 +1,4 @@
service vendor.usb_gadget-default /vendor/bin/hw/android.hardware.usb.gadget-service.rpi service vendor.usb_gadget-rpi /apex/com.android.hardware.usb.gadget.rpi5/bin/hw/android.hardware.usb.gadget-service.rpi
class hal class hal
user system user system
group system shell mtp group system shell mtp

3
usb/apex_file_contexts Normal file
View File

@@ -0,0 +1,3 @@
(/.*)? u:object_r:vendor_file:s0
/etc(/.*)? u:object_r:vendor_configs_file:s0
/bin/hw/android\.hardware\.usb\.gadget-service\.rpi u:object_r:hal_usb_gadget_default_exec:s0

4
usb/apex_manifest.json Normal file
View File

@@ -0,0 +1,4 @@
{
"name": "com.android.hardware.usb.gadget.rpi5",
"version": 1
}

View File

@@ -1,28 +0,0 @@
// Copyright (C) 2020 The Android Open Source Project
// Copyright (C) 2024 KonstaKANG
//
// SPDX-License-Identifier: Apache-2.0
cc_library_static {
name: "libusbconfigfs-rpi",
vendor_available: true,
export_include_dirs: ["include"],
srcs: [
"UsbGadgetUtils.cpp",
"MonitorFfs.cpp",
],
cflags: [
"-Wall",
"-Werror",
],
shared_libs: [
"android.hardware.usb.gadget-V1-ndk",
"libbase",
"libcutils",
"libhidlbase",
"libutils",
],
}

View File

@@ -15,19 +15,22 @@
* limitations under the License. * limitations under the License.
*/ */
#include "UsbGadget.h"
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <android/binder_process.h> #include <android/binder_process.h>
#include "UsbGadget.h"
using ::aidl::android::hardware::usb::gadget::UsbGadget; using ::aidl::android::hardware::usb::gadget::UsbGadget;
int main() { int main() {
ABinderProcess_setThreadPoolMaxThreadCount(0); ABinderProcess_setThreadPoolMaxThreadCount(0);
std::shared_ptr<UsbGadget> usbgadget = ndk::SharedRefBase::make<UsbGadget>(); std::shared_ptr<UsbGadget> usbgadget = ndk::SharedRefBase::make<UsbGadget>();
const std::string instance = std::string() + UsbGadget::descriptor + "/default"; const std::string instance = std::string() + UsbGadget::descriptor + "/default";
binder_status_t status = AServiceManager_addService(usbgadget->asBinder().get(), instance.c_str()); binder_status_t status = AServiceManager_addService(usbgadget->asBinder().get(), instance.c_str());
CHECK(status == STATUS_OK); CHECK(status == STATUS_OK);
ABinderProcess_joinThreadPool(); ABinderProcess_joinThreadPool();
return -1; return EXIT_FAILURE; // should not reach
} }