From 00e46f0d1e02084caec2419ac33c57aa166f6396 Mon Sep 17 00:00:00 2001 From: Konsta Date: Sat, 15 Mar 2025 13:46:59 +0200 Subject: [PATCH] usb: convert gadget to apex --- device.mk | 2 +- sepolicy/file_contexts | 3 -- usb/Android.bp | 43 +++++++++++++++---- usb/{lib => }/MonitorFfs.cpp | 2 +- usb/{lib/include => }/UsbGadgetCommon.h | 0 usb/{lib => }/UsbGadgetUtils.cpp | 2 +- ...android.hardware.usb.gadget-service.rpi.rc | 2 +- usb/apex_file_contexts | 3 ++ usb/apex_manifest.json | 4 ++ usb/lib/Android.bp | 28 ------------ usb/{service.cpp => main.cpp} | 7 ++- 11 files changed, 50 insertions(+), 46 deletions(-) rename usb/{lib => }/MonitorFfs.cpp (99%) rename usb/{lib/include => }/UsbGadgetCommon.h (100%) rename usb/{lib => }/UsbGadgetUtils.cpp (99%) create mode 100644 usb/apex_file_contexts create mode 100644 usb/apex_manifest.json delete mode 100644 usb/lib/Android.bp rename usb/{service.cpp => main.cpp} (96%) diff --git a/device.mk b/device.mk index f029c4d..0819ad1 100644 --- a/device.mk +++ b/device.mk @@ -262,7 +262,7 @@ PRODUCT_COPY_FILES += \ # USB PRODUCT_PACKAGES += \ com.android.hardware.usb \ - android.hardware.usb.gadget-service.rpi + com.android.hardware.usb.gadget.rpi4 PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.usb.accessory.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.accessory.xml \ diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index be7b007..8677e22 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -41,8 +41,5 @@ # Suspend /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 - # V4L2 /vendor/bin/hw/android\.hardware\.media\.c2@1\.2-service-v4l2(.*)? u:object_r:mediacodec_exec:s0 diff --git a/usb/Android.bp b/usb/Android.bp index 9a40349..459fb93 100644 --- a/usb/Android.bp +++ b/usb/Android.bp @@ -5,24 +5,49 @@ cc_binary { name: "android.hardware.usb.gadget-service.rpi", - defaults: ["hidl_defaults"], relative_install_path: "hw", - init_rc: ["android.hardware.usb.gadget-service.rpi.rc"], - vintf_fragments: ["android.hardware.usb.gadget-service.rpi.xml"], vendor: true, srcs: [ - "service.cpp", + "MonitorFfs.cpp", "UsbGadget.cpp", + "UsbGadgetUtils.cpp", + "main.cpp", ], shared_libs: [ "android.hardware.usb.gadget-V1-ndk", - "libbinder_ndk", "libbase", - "libcutils", - "libhardware", - "libhidlbase", + "libbinder_ndk", "liblog", "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.rpi4", + 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", + ], } diff --git a/usb/lib/MonitorFfs.cpp b/usb/MonitorFfs.cpp similarity index 99% rename from usb/lib/MonitorFfs.cpp rename to usb/MonitorFfs.cpp index a410b51..54e4764 100644 --- a/usb/lib/MonitorFfs.cpp +++ b/usb/MonitorFfs.cpp @@ -17,7 +17,7 @@ #define LOG_TAG "libusbconfigfs" -#include "include/UsbGadgetCommon.h" +#include "UsbGadgetCommon.h" namespace aidl { namespace android { diff --git a/usb/lib/include/UsbGadgetCommon.h b/usb/UsbGadgetCommon.h similarity index 100% rename from usb/lib/include/UsbGadgetCommon.h rename to usb/UsbGadgetCommon.h diff --git a/usb/lib/UsbGadgetUtils.cpp b/usb/UsbGadgetUtils.cpp similarity index 99% rename from usb/lib/UsbGadgetUtils.cpp rename to usb/UsbGadgetUtils.cpp index 66685f4..d9843dc 100644 --- a/usb/lib/UsbGadgetUtils.cpp +++ b/usb/UsbGadgetUtils.cpp @@ -17,7 +17,7 @@ #define LOG_TAG "libusbconfigfs" -#include "include/UsbGadgetCommon.h" +#include "UsbGadgetCommon.h" namespace aidl { namespace android { diff --git a/usb/android.hardware.usb.gadget-service.rpi.rc b/usb/android.hardware.usb.gadget-service.rpi.rc index a549ef5..79efe5c 100644 --- a/usb/android.hardware.usb.gadget-service.rpi.rc +++ b/usb/android.hardware.usb.gadget-service.rpi.rc @@ -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.rpi4/bin/hw/android.hardware.usb.gadget-service.rpi class hal user system group system shell mtp diff --git a/usb/apex_file_contexts b/usb/apex_file_contexts new file mode 100644 index 0000000..29c7158 --- /dev/null +++ b/usb/apex_file_contexts @@ -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 diff --git a/usb/apex_manifest.json b/usb/apex_manifest.json new file mode 100644 index 0000000..8a307c0 --- /dev/null +++ b/usb/apex_manifest.json @@ -0,0 +1,4 @@ +{ + "name": "com.android.hardware.usb.gadget.rpi4", + "version": 1 +} diff --git a/usb/lib/Android.bp b/usb/lib/Android.bp deleted file mode 100644 index 6335692..0000000 --- a/usb/lib/Android.bp +++ /dev/null @@ -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", - ], -} diff --git a/usb/service.cpp b/usb/main.cpp similarity index 96% rename from usb/service.cpp rename to usb/main.cpp index 93c0811..693a163 100644 --- a/usb/service.cpp +++ b/usb/main.cpp @@ -15,19 +15,22 @@ * limitations under the License. */ +#include "UsbGadget.h" + #include #include #include -#include "UsbGadget.h" using ::aidl::android::hardware::usb::gadget::UsbGadget; int main() { ABinderProcess_setThreadPoolMaxThreadCount(0); std::shared_ptr usbgadget = ndk::SharedRefBase::make(); + 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; + return EXIT_FAILURE; // should not reach }