From 47baf4a55bbef543789fc0bd0e7e75c07dabb966 Mon Sep 17 00:00:00 2001 From: Matsvei Niaverau Date: Tue, 9 May 2023 09:15:52 +0200 Subject: [PATCH] rosemary: Checkout packages from V13.0.6.0 * Drop unneeded shims * Spoofing roles is not needed anymore, so drop USB HAL Change-Id: I4af4ace2db11e2388d5c14157f72f30ec5c5e625 --- device.mk | 72 +- extract-files.sh | 37 +- libshims/Android.bp | 69 -- libshims/include/DisplayConfig.h | 39 - libshims/libshim_audio.cpp | 105 --- libshims/libshim_beanpod.cpp | 9 - libshims/libshim_showlogo.cpp | 35 - libshims/libshim_utils.cpp | 25 - libshims/libshim_vtservice.cpp | 74 -- usb/Android.bp | 35 - usb/Usb.cpp | 672 ------------------ usb/Usb.h | 72 -- usb/UsbGadget.cpp | 182 ----- usb/UsbGadget.h | 94 --- ...rdware.usb.gadget@1.1-service.rosemary.xml | 11 - ...droid.hardware.usb@1.1-service.rosemary.rc | 13 - ...roid.hardware.usb@1.1-service.rosemary.xml | 11 - usb/lib/Android.bp | 40 -- usb/lib/UsbGadgetUtils.cpp | 156 ---- usb/lib/include/UsbGadgetCommon.h | 114 --- usb/service.cpp | 62 -- vndk/Android.mk | 23 - 22 files changed, 42 insertions(+), 1908 deletions(-) delete mode 100644 libshims/Android.bp delete mode 100644 libshims/include/DisplayConfig.h delete mode 100644 libshims/libshim_audio.cpp delete mode 100644 libshims/libshim_beanpod.cpp delete mode 100644 libshims/libshim_showlogo.cpp delete mode 100644 libshims/libshim_utils.cpp delete mode 100644 libshims/libshim_vtservice.cpp delete mode 100644 usb/Android.bp delete mode 100755 usb/Usb.cpp delete mode 100755 usb/Usb.h delete mode 100644 usb/UsbGadget.cpp delete mode 100644 usb/UsbGadget.h delete mode 100644 usb/android.hardware.usb.gadget@1.1-service.rosemary.xml delete mode 100755 usb/android.hardware.usb@1.1-service.rosemary.rc delete mode 100755 usb/android.hardware.usb@1.1-service.rosemary.xml delete mode 100644 usb/lib/Android.bp delete mode 100644 usb/lib/UsbGadgetUtils.cpp delete mode 100644 usb/lib/include/UsbGadgetCommon.h delete mode 100755 usb/service.cpp diff --git a/device.mk b/device.mk index 81535bf..1a9ec6d 100644 --- a/device.mk +++ b/device.mk @@ -50,8 +50,8 @@ PRODUCT_PACKAGES += \ # Audio PRODUCT_PACKAGES += \ android.hardware.audio.service.mediatek \ - android.hardware.audio@6.0-impl \ - android.hardware.audio.effect@6.0-impl \ + android.hardware.audio@7.0-impl \ + android.hardware.audio.effect@7.0-impl \ android.hardware.bluetooth.audio-impl \ android.hardware.soundtrigger@2.3-impl @@ -61,12 +61,8 @@ PRODUCT_PACKAGES += \ audio.usb.default PRODUCT_PACKAGES += \ - libshim_audio - -PRODUCT_PACKAGES += \ - libalsautils_legacy \ libtinycompress \ - libtinyxml \ + libaudiofoundation.vendor \ tinymix PRODUCT_PACKAGES += \ @@ -82,9 +78,9 @@ PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/configs/audio/usb_audio_accessory_only_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/usb_audio_accessory_only_policy_configuration.xml PRODUCT_COPY_FILES += \ - frameworks/av/services/audiopolicy/config/a2dp_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/a2dp_audio_policy_configuration.xml \ - frameworks/av/services/audiopolicy/config/a2dp_in_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/a2dp_in_audio_policy_configuration.xml \ - frameworks/av/services/audiopolicy/config/bluetooth_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/bluetooth_audio_policy_configuration.xml \ + frameworks/av/services/audiopolicy/config/a2dp_audio_policy_configuration_7_0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/a2dp_audio_policy_configuration.xml \ + frameworks/av/services/audiopolicy/config/a2dp_in_audio_policy_configuration_7_0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/a2dp_in_audio_policy_configuration.xml \ + frameworks/av/services/audiopolicy/config/bluetooth_audio_policy_configuration_7_0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/bluetooth_audio_policy_configuration.xml \ frameworks/av/services/audiopolicy/config/r_submix_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/r_submix_audio_policy_configuration.xml \ frameworks/av/services/audiopolicy/config/usb_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/usb_audio_policy_configuration.xml \ frameworks/av/services/audiopolicy/config/default_volume_tables.xml:$(TARGET_COPY_OUT_VENDOR)/etc/default_volume_tables.xml @@ -109,16 +105,10 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ libdng_sdk.vendor -PRODUCT_PACKAGES += \ - libshim_utils - # Charger PRODUCT_PACKAGES += \ libsuspend -PRODUCT_PACKAGES += \ - libshim_showlogo - # Display TARGET_SCREEN_DENSITY := 440 TARGET_SCREEN_HEIGHT := 2400 @@ -143,7 +133,7 @@ PRODUCT_PACKAGES += \ # Display PRODUCT_PACKAGES += \ - android.hardware.graphics.composer@2.1-service + android.hardware.graphics.composer@2.2-service PRODUCT_PACKAGES += \ android.hardware.memtrack-service.mediatek-mali @@ -154,6 +144,7 @@ PRODUCT_PACKAGES += \ android.hardware.graphics.allocator@4.0.vendor PRODUCT_PACKAGES += \ + libdrm \ libdrm.vendor # Dynamic Partitions @@ -188,7 +179,8 @@ PRODUCT_PACKAGES += \ android.hardware.gnss@2.1.vendor \ android.hardware.gnss.measurement_corrections@1.0.vendor \ android.hardware.gnss.measurement_corrections@1.1.vendor \ - android.hardware.gnss.visibility_control@1.0.vendor + android.hardware.gnss.visibility_control@1.0.vendor \ + android.hardware.gnss-V1-ndk_platform.vendor # Health PRODUCT_PACKAGES += \ @@ -225,9 +217,6 @@ PRODUCT_BOOT_JARS += \ mediatek-telephony-base \ mediatek-telephony-common -PRODUCT_PACKAGES += \ - libshim_vtservice - PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/configs/permissions/privapp-permissions-com.mediatek.ims.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/privapp-permissions-com.mediatek.ims.xml @@ -238,17 +227,11 @@ PRODUCT_PACKAGES += \ # Keymaster PRODUCT_PACKAGES += \ - android.hardware.keymaster@4.0.vendor - -PRODUCT_PACKAGES += \ - libkeymaster4.vendor \ - libkeymaster4support.vendor \ + libkeymaster41.vendor \ + libkeymaster4_1support.vendor \ libpuresoftkeymasterdevice.vendor \ libsoft_attestation_cert.vendor -PRODUCT_PACKAGES += \ - libshim_beanpod - # Lights PRODUCT_PACKAGES += \ android.hardware.light-service.rosemary @@ -258,6 +241,14 @@ PRODUCT_PACKAGES += \ vendor.lineage.health-service.default # Media +PRODUCT_PACKAGES += \ + libcodec2_hidl@1.1.vendor \ + libcodec2_hidl@1.2.vendor \ + libavservices_minijail_vendor \ + libstagefright_softomx_plugin.vendor \ + libsfplugin_ccodec_utils.vendor \ + libcodec2_soft_common.vendor + PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/configs/media/media_codecs.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs.xml \ $(LOCAL_PATH)/configs/media/media_codecs_c2.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_c2.xml \ @@ -378,6 +369,7 @@ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.location.gps.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.location.gps.xml \ frameworks/native/data/etc/android.hardware.opengles.aep.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.opengles.aep.xml \ frameworks/native/data/etc/android.hardware.sensor.accelerometer.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.accelerometer.xml \ + frameworks/native/data/etc/android.hardware.sensor.barometer.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.barometer.xml \ frameworks/native/data/etc/android.hardware.sensor.compass.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.compass.xml \ frameworks/native/data/etc/android.hardware.sensor.gyroscope.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.gyroscope.xml \ frameworks/native/data/etc/android.hardware.sensor.light.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.light.xml \ @@ -402,6 +394,7 @@ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.software.ipsec_tunnels.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.ipsec_tunnels.xml \ frameworks/native/data/etc/android.software.midi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.midi.xml \ frameworks/native/data/etc/android.software.verified_boot.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.verified_boot.xml \ + frameworks/native/data/etc/android.software.opengles.deqp.level-2020-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml \ frameworks/native/data/etc/android.software.vulkan.deqp.level-2020-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ frameworks/native/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml @@ -413,11 +406,11 @@ PRODUCT_PACKAGES += \ android.hardware.radio@1.3.vendor \ android.hardware.radio@1.4.vendor \ android.hardware.radio@1.5.vendor \ + android.hardware.radio@1.6.vendor \ android.hardware.radio.config@1.0.vendor \ android.hardware.radio.config@1.1.vendor \ android.hardware.radio.config@1.2.vendor \ - android.hardware.radio.deprecated@1.0.vendor \ - android.hardware.radio-V1.4-java + android.hardware.radio.config@1.3.vendor # Rootdir PRODUCT_PACKAGES += \ @@ -443,6 +436,7 @@ PRODUCT_PACKAGES += \ android.hardware.sensors@2.1-service.multihal \ android.hardware.sensors@1.0.vendor \ android.hardware.sensors@2.0.vendor \ + android.hardware.sensors@2.1.vendor \ android.hardware.sensors@2.0-ScopedWakelock.vendor \ android.frameworks.sensorservice@1.0 @@ -469,7 +463,12 @@ PRODUCT_PACKAGES += \ # USB PRODUCT_PACKAGES += \ - android.hardware.usb@1.1-service.rosemary + android.hardware.usb@1.0.vendor \ + android.hardware.usb@1.1.vendor \ + android.hardware.usb@1.2.vendor \ + android.hardware.usb@1.3.vendor \ + android.hardware.usb.gadget@1.0.vendor \ + android.hardware.usb.gadget@1.1.vendor # Vibrator PRODUCT_PACKAGES += \ @@ -478,8 +477,6 @@ PRODUCT_PACKAGES += \ # VNDK PRODUCT_PACKAGES += \ libutils-v32 \ - libhidlbase-v32 \ - libui-v32 # Wi-Fi PRODUCT_PACKAGES += \ @@ -487,9 +484,14 @@ PRODUCT_PACKAGES += \ android.hardware.wifi.supplicant@1.1.vendor \ android.hardware.wifi.supplicant@1.2.vendor \ android.hardware.wifi.supplicant@1.3.vendor \ + android.hardware.wifi.supplicant@1.4.vendor \ android.hardware.wifi.hostapd@1.0.vendor \ android.hardware.wifi.hostapd@1.1.vendor \ - android.hardware.wifi.hostapd@1.2.vendor + android.hardware.wifi.hostapd@1.2.vendor \ + android.hardware.wifi.hostapd@1.3.vendor \ + android.hardware.tetheroffload.config@1.0.vendor \ + android.hardware.tetheroffload.control@1.0.vendor \ + android.hardware.tetheroffload.control@1.1.vendor PRODUCT_PACKAGES += \ android.hardware.wifi@1.0-service-lazy.rosemary diff --git a/extract-files.sh b/extract-files.sh index 3c183b1..93ab4ec 100755 --- a/extract-files.sh +++ b/extract-files.sh @@ -55,12 +55,8 @@ fi function blob_fixup { case "$1" in - vendor/lib*/hw/audio.primary.mt6785.so) - "${PATCHELF}" --add-needed "libshim_audio.so" "${2}" - "${PATCHELF}" --replace-needed "libalsautils.so" "libalsautils_legacy.so" "${2}" - ;; - vendor/lib*/hw/audio.usb.mt6785.so) - "${PATCHELF}" --replace-needed "libalsautils.so" "libalsautils_legacy.so" "${2}" + vendor/bin/hw/vendor.mediatek.hardware.mtkpower@1.0-service) + "${PATCHELF}" --replace-needed "android.hardware.power-V2-ndk_platform.so" "android.hardware.power-V2-ndk.so" "${2}" ;; vendor/lib64/libwifi-hal-mtk.so) "$PATCHELF" --set-soname libwifi-hal-mtk.so "${2}" @@ -68,41 +64,18 @@ function blob_fixup { vendor/lib64/libmtkcam_stdutils.so) "${PATCHELF}" --replace-needed "libutils.so" "libutils-v32.so" "${2}" ;; - vendor/lib*/hw/dfps.mt6785.so) - "${PATCHELF}" --replace-needed "libutils.so" "libutils-v32.so" "${2}" - ;; - vendor/lib/libMtkOmxVdecEx.so) - "${PATCHELF}" --replace-needed "libui.so" "libui-v32.so" "${2}" - ;; - vendor/lib*/hw/vendor.mediatek.hardware.pq@2.6-impl.so) + vendor/lib*/hw/vendor.mediatek.hardware.pq@2.13-impl.so) "${PATCHELF}" --replace-needed "libutils.so" "libutils-v32.so" "${2}" ;; vendor/lib64/libvendor.goodix.hardware.biometrics.fingerprint@2.1.so) "${PATCHELF_0_8}" --remove-needed "libhidlbase.so" "${2}" sed -i "s/libhidltransport.so/libhidlbase-v32.so\x00/" "${2}" ;; - vendor/lib64/libcam.halsensor.so) - "${PATCHELF}" --add-needed "libshim_utils.so" "${2}" - ;; vendor/lib64/libgf_hal.so) - xxd -p "${2}" | sed "s/ffc301d1fd7b06a9fd830191e8031f2ae2037db2a94300d14ad03bd54a15/000080d2c0035fd6fd830191e8031f2ae2037db2a94300d14ad03bd54a15/g" | xxd -r -p > "${2}".patched - mv "${2}".patched "${2}" + sed -i 's/\xff\xc3\x01\xd1\xfd\x7b\x06\xa9/\x00\x00\x80\xd2\xc0\x03\x5f\xd6/g' "${2}" ;; vendor/lib64/hw/fingerprint.fpc.default.so) - xxd -p "${2}" | sed "s/5fd600000000ff4301d1fd7b02a9fd830091f51b00f9f44f04a954d03bd5/5fd600000000c0035fd6fd7b02a9fd830091f51b00f9f44f04a954d03bd5/g" | xxd -r -p > "${2}".patched - mv "${2}".patched "${2}" - ;; - vendor/bin/hw/android.hardware.keymaster@4.0-service.beanpod) - "${PATCHELF}" --add-needed "libshim_beanpod.so" "${2}" - ;; - vendor/bin/hw/vendor.mediatek.hardware.mtkpower@1.0-service) - "${PATCHELF}" --replace-needed "android.hardware.power-V1-ndk_platform.so" "android.hardware.power-V1-ndk.so" "${2}" - ;; - lib/libshowlogo.so) - "${PATCHELF}" --add-needed "libshim_showlogo.so" "${2}" - ;; - lib/libsink.so) - "${PATCHELF}" --add-needed "libshim_vtservice.so" "${2}" + sed -i 's/\xff\x43\x01\xd1\xfd\x7b\x02\xa9/\xc0\x03\x5f\xd6\xfd\x7b\x02\xa9/g' "${2}" ;; esac } diff --git a/libshims/Android.bp b/libshims/Android.bp deleted file mode 100644 index d441224..0000000 --- a/libshims/Android.bp +++ /dev/null @@ -1,69 +0,0 @@ -// -// Copyright (C) 2022 The LineageOS Project -// -// SPDX-License-Identifier: Apache-2.0 -// - -cc_library_shared { - name: "libshim_audio", - srcs: [ - "libshim_audio.cpp" - ], - shared_libs: [ - "libmedia_helper", - "libaudioutils" - ], - vendor: true -} - -cc_library_shared { - name: "libshim_beanpod", - srcs: ["libshim_beanpod.cpp"], - vendor: true, - shared_libs: [ - "libkeymaster_messages", - ], - header_libs: [ - "libhardware_headers", - ], - include_dirs: [ "system/keymaster/include" ], -} - -cc_library_shared { - name: "libshim_showlogo", - srcs: ["libshim_showlogo.cpp"], - shared_libs: [ - "libui", - "libgui", - "libutils", - ], - local_include_dirs: ["include"] -} - -cc_library_shared { - name: "libshim_utils", - srcs: ["libshim_utils.cpp"], - vendor: true, - compile_multilib: "64", - shared_libs: [ - "libutils", - ], -} - -cc_library_shared { - name: "libshim_vtservice", - srcs: ["libshim_vtservice.cpp"], - compile_multilib: "32", - shared_libs: [ - "libaudioclient", - "libgui", - "libstagefright", - "libutils", - "libbinder", - ], - header_libs: [ - "libaudioclient_headers", - "libmedia_headers", - "libmediametrics_headers", - ], -} diff --git a/libshims/include/DisplayConfig.h b/libshims/include/DisplayConfig.h deleted file mode 100644 index 3cd2687..0000000 --- a/libshims/include/DisplayConfig.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2019 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 - -#include -#include - -namespace android { - -// Configuration supported by physical display. -struct DisplayConfig { - ui::Size resolution; - float xDpi = 0; - float yDpi = 0; - - float refreshRate = 0; - nsecs_t appVsyncOffset = 0; - nsecs_t sfVsyncOffset = 0; - nsecs_t presentationDeadline = 0; - int configGroup = -1; -}; - -} // namespace android diff --git a/libshims/libshim_audio.cpp b/libshims/libshim_audio.cpp deleted file mode 100644 index 3b2ebc5..0000000 --- a/libshims/libshim_audio.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2016 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 - -#define MAKE_STRING_FROM_ENUM(enumval) { #enumval, enumval } -#define TERMINATOR { .literal = nullptr } - -namespace android { - -template <> -const FormatConverter::Table FormatConverter::mTable[] = { - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_16_BIT), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_8_BIT), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_32_BIT), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_8_24_BIT), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_FLOAT), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_PCM_24_BIT_PACKED), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_MP3), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AMR_NB), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AMR_WB), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_MAIN), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_SSR), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LTP), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_HE_V1), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_SCALABLE), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ERLC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LD), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_HE_V2), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ELD), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_XHE), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_MAIN), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_LC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_SSR), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_LTP), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V1), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_SCALABLE), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_ERLC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_LD), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V2), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_ELD), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS_XHE), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_VORBIS), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_HE_AAC_V1), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_HE_AAC_V2), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_OPUS), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AC3), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_E_AC3), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_DTS), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_DTS_HD), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_IEC61937), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_DOLBY_TRUEHD), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_EVRC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_EVRCB), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_EVRCWB), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_EVRCNW), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADIF), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_WMA), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_WMA_PRO), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AMR_WB_PLUS), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_MP2), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_QCELP), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_DSD), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_FLAC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_ALAC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_APE), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_ADTS), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_SBC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_APTX), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_APTX_HD), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AC4), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_LDAC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_MAT), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_E_AC3_JOC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_MAT_1_0), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_MAT_2_0), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_MAT_2_1), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LATM), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LATM_LC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V1), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V2), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_CELT), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_APTX_ADAPTIVE), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_LHDC), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_LHDC_LL), - MAKE_STRING_FROM_ENUM(AUDIO_FORMAT_APTX_TWSP), - TERMINATOR -}; - -} // namespace android diff --git a/libshims/libshim_beanpod.cpp b/libshims/libshim_beanpod.cpp deleted file mode 100644 index a4aec17..0000000 --- a/libshims/libshim_beanpod.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -extern "C" { -void _ZN9keymaster19GenerateKeyResponseD1Ev() {} -void _ZN9keymaster17AttestKeyResponseD1Ev() {} -void _ZN9keymaster16ImportKeyRequest14SetKeyMaterialEPKvm(keymaster::ImportKeyRequest* thisptr, const uint8_t* key_material, size_t length) { - thisptr->key_data = keymaster::KeymasterKeyBlob(key_material, length); -} -} diff --git a/libshims/libshim_showlogo.cpp b/libshims/libshim_showlogo.cpp deleted file mode 100644 index c816d5a..0000000 --- a/libshims/libshim_showlogo.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include - -using namespace android; - -extern "C" { - -void _ZN7android21SurfaceComposerClient13createSurfaceERKNS_7String8EjjijRKNS_2spINS_7IBinderEEENS_13LayerMetadataEPj(const String8& name, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, const sp& parentHandle, LayerMetadata metadata, uint32_t* outTransformHint); - -void _ZN7android21SurfaceComposerClient13createSurfaceERKNS_7String8EjjijPNS_14SurfaceControlENS_13LayerMetadataEPj(const String8& name, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, SurfaceControl* parent, LayerMetadata metadata, uint32_t* outTransformHint) { - _ZN7android21SurfaceComposerClient13createSurfaceERKNS_7String8EjjijRKNS_2spINS_7IBinderEEENS_13LayerMetadataEPj(name, w, h, format, flags, nullptr, metadata, nullptr); - } - -void _ZN7android14SurfaceControl10getSurfaceEv(void); - -void _ZNK7android14SurfaceControl10getSurfaceEv(void) { - _ZN7android14SurfaceControl10getSurfaceEv(); - } - -status_t _ZN7android21SurfaceComposerClient20getActiveDisplayModeERKNS_2spINS_7IBinderEEEPNS_2ui11DisplayModeE(const sp& display, ui::DisplayMode* mode); - -status_t _ZN7android21SurfaceComposerClient22getActiveDisplayConfigERKNS_2spINS_7IBinderEEEPNS_13DisplayConfigE(const sp& display, DisplayConfig* config) { - return _ZN7android21SurfaceComposerClient20getActiveDisplayModeERKNS_2spINS_7IBinderEEEPNS_2ui11DisplayModeE(display, (ui::DisplayMode*)config); -} - -status_t _ZN7android21SurfaceComposerClient11Transaction5applyEbb(void* thisptr, bool synchronous, bool oneWay); - -status_t _ZN7android21SurfaceComposerClient11Transaction5applyEb(void* thisptr, bool synchronous) { - return _ZN7android21SurfaceComposerClient11Transaction5applyEbb(thisptr, synchronous, false /* oneWay */); -} - -ui::Size _ZN7android2ui4Size7INVALIDE; - -} diff --git a/libshims/libshim_utils.cpp b/libshims/libshim_utils.cpp deleted file mode 100644 index 24d103b..0000000 --- a/libshims/libshim_utils.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2022 The LineageOS Project - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -using namespace android; - -extern "C" { - -void _ZN7android7String87toUpperEv(String8* thisptr) { - const size_t length = thisptr->size(); - if (length == 0) return; - - char* buf = thisptr->lockBuffer(length); - for (size_t i = length; i > 0; --i) { - *buf = static_cast(toupper(*buf)); - buf++; - } - thisptr->unlockBuffer(length); -} - -} diff --git a/libshims/libshim_vtservice.cpp b/libshims/libshim_vtservice.cpp deleted file mode 100644 index 136374d..0000000 --- a/libshims/libshim_vtservice.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include - -using namespace android; - -extern "C" { -void _ZN7android10AudioTrackC1E19audio_stream_type_tj14audio_format_t20audio_channel_mask_tj20audio_output_flags_tPFviPvS5_ES5_i15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbfi( - void* thisptr, - audio_stream_type_t streamType, - uint32_t sampleRate, - audio_format_t format, - audio_channel_mask_t channelMask, - size_t frameCount, - audio_output_flags_t flags, - android::AudioTrack::legacy_callback_t cbf, - void* user, - int32_t notificationFrames, - audio_session_t sessionId, - android::AudioTrack::transfer_type transferType, - const audio_offload_info_t *offloadInfo, - const AttributionSourceState& attributionSource, - const audio_attributes_t* pAttributes, - bool doNotReconnect, - float maxRequiredSpeed, - audio_port_handle_t selectedDeviceId); - -void _ZN7android10AudioTrackC1E19audio_stream_type_tj14audio_format_tjj20audio_output_flags_tPFviPvS4_ES4_i15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tjiPK18audio_attributes_tbfi( - void* thisptr, - audio_stream_type_t streamType, - uint32_t sampleRate, - audio_format_t format, - audio_channel_mask_t channelMask, - size_t frameCount, - audio_output_flags_t flags, - android::AudioTrack::legacy_callback_t cbf, - void* user, - int32_t notificationFrames, - audio_session_t sessionId, - android::AudioTrack::transfer_type transferType, - const audio_offload_info_t *offloadInfo, - uid_t uid, - pid_t pid, - const audio_attributes_t* pAttributes, - bool doNotReconnect, - float maxRequiredSpeed, - audio_port_handle_t selectedDeviceId) { - AttributionSourceState attributionSource; - attributionSource.uid = uid; - attributionSource.pid = pid; - attributionSource.packageName = "com.mediatek.ims"; - attributionSource.token = android::sp::make(); - attributionSource.attributionTag = std::nullopt; - _ZN7android10AudioTrackC1E19audio_stream_type_tj14audio_format_t20audio_channel_mask_tj20audio_output_flags_tPFviPvS5_ES5_i15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbfi( - thisptr, streamType, sampleRate, format, channelMask, frameCount, flags, cbf, - user, notificationFrames, sessionId, transferType, offloadInfo, - attributionSource, pAttributes, doNotReconnect, maxRequiredSpeed, selectedDeviceId); -} - -void _ZN7android7SurfaceC1ERKNS_2spINS_22IGraphicBufferProducerEEEbRKNS1_INS_7IBinderEEE( - void* thisptr, const sp& bufferProducer, bool controlledByApp, const sp& surfaceControlHandle); - -void _ZN7android7SurfaceC1ERKNS_2spINS_22IGraphicBufferProducerEEEb( - void* thisptr, const sp &bufferProducer, bool controlledByApp) { - _ZN7android7SurfaceC1ERKNS_2spINS_22IGraphicBufferProducerEEEbRKNS1_INS_7IBinderEEE(thisptr, bufferProducer, controlledByApp, nullptr); -} - -void _ZN7android10MediaMuxerC1EiNS_14MediaMuxerBase12OutputFormatE(void* thisptr, int fd, android::MediaMuxer::OutputFormat format); - -void _ZN7android10MediaMuxerC1EiNS0_12OutputFormatE(void* thisptr, int fd, android::MediaMuxer::OutputFormat format) { - _ZN7android10MediaMuxerC1EiNS_14MediaMuxerBase12OutputFormatE(thisptr, fd, format); -} - -} diff --git a/usb/Android.bp b/usb/Android.bp deleted file mode 100644 index 337f204..0000000 --- a/usb/Android.bp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright (C) 2017 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. -cc_binary { - name: "android.hardware.usb@1.1-service.rosemary", - relative_install_path: "hw", - init_rc: ["android.hardware.usb@1.1-service.rosemary.rc"], - vintf_fragments: ["android.hardware.usb@1.1-service.rosemary.xml", "android.hardware.usb.gadget@1.1-service.rosemary.xml"], - srcs: ["service.cpp", "Usb.cpp", "UsbGadget.cpp"], - shared_libs: [ - "android.hardware.usb@1.0", - "android.hardware.usb@1.1", - "android.hardware.usb.gadget@1.0", - "android.hardware.usb.gadget@1.1", - "libbase", - "libcutils", - "libhardware", - "libhidlbase", - "liblog", - "libutils", - ], - static_libs: ["libusbconfigfs_rosemary"], - proprietary: true, -} diff --git a/usb/Usb.cpp b/usb/Usb.cpp deleted file mode 100755 index bfbd0a6..0000000 --- a/usb/Usb.cpp +++ /dev/null @@ -1,672 +0,0 @@ -/* - * Copyright (C) 2017 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. - */ - -#define LOG_TAG "android.hardware.usb@1.1-service.rosemary" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "Usb.h" - -namespace android { -namespace hardware { -namespace usb { -namespace V1_1 { -namespace implementation { - -// Set by the signal handler to destroy the thread -volatile bool destroyThread; - -static int32_t readFile(const std::string &filename, std::string *contents) { - FILE *fp; - ssize_t read = 0; - char *line = NULL; - size_t len = 0; - - fp = fopen(filename.c_str(), "r"); - if (fp != NULL) { - if ((read = getline(&line, &len, fp)) != -1) { - char *pos; - if ((pos = strchr(line, '\n')) != NULL) *pos = '\0'; - *contents = line; - } - free(line); - fclose(fp); - return 0; - } else { - ALOGE("fopen failed in readFile %s, errno=%d", filename.c_str(), errno); - } - - return -1; -} - -static int32_t writeFile(const std::string &filename, - const std::string &contents) { // Might remove later - FILE *fp; - int ret; - - fp = fopen(filename.c_str(), "w"); - if (fp != NULL) { - ret = fputs(contents.c_str(), fp); - fclose(fp); - if (ret == EOF) { - ALOGE("fputs failed in writeFile %s", filename.c_str()); - return -1; - } - return 0; - } else { - ALOGE("fopen failed in writeFile %s, errno=%d", filename.c_str(), errno); - } - - return -1; -} - -std::string appendRoleNodeHelper(const std::string &portName, - PortRoleType type) { - std::string node("/sys/class/dual_role_usb/" + portName); // We have /sys/class/dual_role_usb, not /sys/class/typec - - switch (type) { - case PortRoleType::DATA_ROLE: - return node + "/data_role"; - case PortRoleType::POWER_ROLE: - return node + "/power_role"; - case PortRoleType::MODE: - return node + "/mode"; // We have a separate file for mode - default: - return node + "/mode"; // Disassembly shows no separate case for non-matches and MODE case could be removed, leaving just default, but let's keep it like that for now in case we need to change something. - } -} - -std::string convertRoletoString(PortRole role) { - if (role.type == PortRoleType::POWER_ROLE) { - if (role.role == static_cast(PortPowerRole::SOURCE)) return "source"; - else if (role.role == static_cast(PortPowerRole::SINK)) return "sink"; - } else if (role.type == PortRoleType::DATA_ROLE) { - if (role.role == static_cast(PortDataRole::HOST)) return "host"; - if (role.role == static_cast(PortDataRole::DEVICE)) return "device"; - } else if (role.type == PortRoleType::MODE) { - if (role.role == static_cast(PortMode_1_1::UFP)) return "ufp"; // We probably call these 'ufp' and 'dfp', as seen in switchToDrp for example - if (role.role == static_cast(PortMode_1_1::DFP)) return "dfp"; - } - return "none"; -} - -void extractRole(std::string *roleName) { // Might remove later. - std::size_t first, last; - - first = roleName->find("["); - last = roleName->find("]"); - - if (first != std::string::npos && last != std::string::npos) { - *roleName = roleName->substr(first + 1, last - first - 1); - } -} - -void switchToDrp(const std::string &portName) { - std::string filename = - appendRoleNodeHelper(std::string(portName.c_str()), PortRoleType::MODE); - FILE *fp; - - if (filename != "") { - fp = fopen(filename.c_str(), "w"); - if (fp != NULL) { - int ret = fputs("dfp", fp); // Change dual -> dfp. Based on disassembly of stock HAL. - fclose(fp); - if (ret == EOF) - ALOGE("Fatal: Error while switching back to drp"); - } else { - ALOGE("Fatal: Cannot open file to switch back to drp"); - } - } else { - ALOGE("Fatal: invalid node type"); - } -} - -Usb::Usb() - : mLock(PTHREAD_MUTEX_INITIALIZER), - mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER), - mPartnerLock(PTHREAD_MUTEX_INITIALIZER), - mPartnerUp(false) { - pthread_condattr_t attr; - if (pthread_condattr_init(&attr)) { - ALOGE("pthread_condattr_init failed: %s", strerror(errno)); - abort(); - } - if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC)) { - ALOGE("pthread_condattr_setclock failed: %s", strerror(errno)); - abort(); - } - if (pthread_cond_init(&mPartnerCV, &attr)) { - ALOGE("pthread_cond_init failed: %s", strerror(errno)); - abort(); - } - if (pthread_condattr_destroy(&attr)) { - ALOGE("pthread_condattr_destroy failed: %s", strerror(errno)); - abort(); - } -} - - -Return Usb::switchRole(const hidl_string &portName, - const V1_0::PortRole &newRole) { - std::string filename = - appendRoleNodeHelper(std::string(portName.c_str()), newRole.type); - std::string written; - FILE *fp; - bool roleSwitch = false; - - if (filename == "") { - ALOGE("Fatal: invalid node type"); - return Void(); - } - - pthread_mutex_lock(&mRoleSwitchLock); - - /* - It looks like we have some type of loop in the stock HAL. - The loop starts at 0x4860 and ends at 0x4D4C in android.hardware.usb@1.1-service-mediatek from V12.0.1.0.QJOEUXM - We break out of the loop only if the value at W24 register is equal to zero. Before loop start, we can see that W24 is set to 0x14 = 20. - We can also see that before deciding to break out or restart, W24 is decremented by 1 and there is an usleep call. - The amount of useconds to sleep is stored in register W19. This register is set to 0xC350 = 50000 before the loop. - - We can conclude that the program attempts to write the role 20 times and waits 50000 useconds before trying again. - */ - for (int i = 0; i < 20; ++i) { - ALOGI("filename write: %s role:%s", filename.c_str(), - convertRoletoString(newRole).c_str()); - - // We don't need to check role type and use a separate way of setting mode, as we simply have a "mode" file for doing that - - fp = fopen(filename.c_str(), "w"); - if (fp != NULL) { - int ret = fputs(convertRoletoString(newRole).c_str(), fp); - fclose(fp); - if ((ret != EOF) && !readFile(filename, &written)) { - // extractRole(&written); - ALOGI("written: %s", written.c_str()); - if (written == convertRoletoString(newRole)) { - roleSwitch = true; - break; // Role switched, stop retrying. - } else { - ALOGE("Role switch failed"); - } - } else { - ALOGE("failed to update the new role"); - } - } else { - ALOGE("fopen failed"); - } - - usleep(50000); - } - - pthread_mutex_lock(&mLock); - if (mCallback_1_0 != NULL) { - Return ret = - mCallback_1_0->notifyRoleSwitchStatus(portName, newRole, - roleSwitch ? Status::SUCCESS : Status::ERROR); - if (!ret.isOk()) - ALOGE("RoleSwitchStatus error %s", ret.description().c_str()); - } else { - ALOGE("Not notifying the userspace. Callback is not set"); - } - pthread_mutex_unlock(&mLock); - pthread_mutex_unlock(&mRoleSwitchLock); - - return Void(); -} - - -Status getCurrentRoleHelper(const std::string &portName, bool connected, - PortRoleType type, uint32_t *currentRole) { - std::string filename; - std::string roleName; - // Accessory stuff removed - stock HAL doesn't have that - // Mode - - if (type == PortRoleType::POWER_ROLE) { - filename = "/sys/class/dual_role_usb/" + portName + "/power_role"; - *currentRole = static_cast(PortPowerRole::NONE); - } else if (type == PortRoleType::DATA_ROLE) { - filename = "/sys/class/dual_role_usb/" + portName + "/data_role"; - *currentRole = static_cast(PortDataRole::NONE); - } else if (type == PortRoleType::MODE) { - filename = "/sys/class/dual_role_usb/" + portName + "/mode"; // We have a separate file for setting mode. - *currentRole = static_cast(PortMode_1_1::NONE); - } else { - return Status::ERROR; - } - - if (!connected) return Status::SUCCESS; - - if (readFile(filename, &roleName)) { - ALOGE("getCurrentRole: Failed to open filesystem node: %s", - filename.c_str()); - return Status::ERROR; - } - - // extractRole(&roleName); // Probably don't need to extract. The role names on our device are just single words - - // We have simple role names and don't need to make a distinction based on role type - if (roleName == "source") { - *currentRole = static_cast(PortPowerRole::SOURCE); - } else if (roleName == "sink") { - *currentRole = static_cast(PortPowerRole::SINK); - } else if (roleName == "host") { - *currentRole = static_cast(PortDataRole::HOST); - } else if (roleName == "dfp") { - *currentRole = static_cast(PortMode_1_1::DFP); - } else if (roleName == "device") { - *currentRole = static_cast(PortDataRole::DEVICE); - } else if (roleName == "ufp") { - *currentRole = static_cast(PortMode_1_1::UFP); - } else if (roleName != "none") { - /* case for none has already been addressed. - * so we check if the role isnt none. - */ - return Status::UNRECOGNIZED_ROLE; - } - - return Status::SUCCESS; -} - -Status getTypeCPortNamesHelper(std::unordered_map *names) { - DIR *dp; - - dp = opendir("/sys/class/dual_role_usb"); - if (dp != NULL) { - struct dirent *ep; - - while ((ep = readdir(dp))) { - if (ep->d_type == DT_LNK) { - // We don't have -partner suffixes - std::unordered_map::const_iterator portName = - names->find(ep->d_name); - if (portName == names->end()) { - names->insert({ep->d_name, true}); // True by default - otherwise getPortStatusHelper will never say if role can be switched - } - } - } - closedir(dp); - return Status::SUCCESS; - } - - ALOGE("Failed to open /sys/class/dual_role_usb"); - return Status::ERROR; -} - -bool canSwitchRoleHelper(const std::string &portName, PortRoleType /*type*/) { - std::string filename = "/sys/class/tcpc/type_c_port0/pe_ready"; - std::string supportsPD; - - if (!readFile(filename, &supportsPD)) { - if (supportsPD == "yes") { - return true; - } - } - - return false; -} - -/* - * Reuse the same method for both V1_0 and V1_1 callback objects. - * The caller of this method would reconstruct the V1_0::PortStatus - * object if required. - */ -Status getPortStatusHelper(hidl_vec *currentPortStatus_1_1, - bool V1_0) { - std::unordered_map names; - Status result = getTypeCPortNamesHelper(&names); - int i = -1; - - if (result == Status::SUCCESS) { - currentPortStatus_1_1->resize(names.size()); - for (const std::pair& port : names) { - i++; - ALOGI("%s", port.first.c_str()); - (*currentPortStatus_1_1)[i].status.portName = port.first; - - uint32_t currentRole; - if (getCurrentRoleHelper(port.first, port.second, - PortRoleType::POWER_ROLE, - ¤tRole) == Status::SUCCESS) { - (*currentPortStatus_1_1)[i].status.currentPowerRole = - static_cast(currentRole); - } else { - ALOGE("Error while retreiving portNames"); - goto done; - } - - if (getCurrentRoleHelper(port.first, port.second, PortRoleType::DATA_ROLE, - ¤tRole) == Status::SUCCESS) { - /* HACK: Our device has broken roles: they appear to be permanently set - to NONE and don't respond to configfs writes. This causes Android to - not see the USB port as connected, breaking the USB settings. - - To get USB preferences to work, we have to spoof some roles. */ - if (port.second == true && currentRole == static_cast(PortDataRole::NONE)) { - currentRole = static_cast(PortDataRole::DEVICE); - } - - (*currentPortStatus_1_1)[i].status.currentDataRole = - static_cast(currentRole); - } else { - ALOGE("Error while retreiving current port role"); - goto done; - } - - if (getCurrentRoleHelper(port.first, port.second, PortRoleType::MODE, - ¤tRole) == Status::SUCCESS) { - // HACK: see above - if (port.second == true && currentRole == static_cast(PortMode_1_1::NONE)) { - currentRole = static_cast(PortMode_1_1::UFP); - } - - (*currentPortStatus_1_1)[i].currentMode = - static_cast(currentRole); - (*currentPortStatus_1_1)[i].status.currentMode = - static_cast(currentRole); - } else { - ALOGE("Error while retreiving current data role"); - goto done; - } - - // Treat mode change like any type of role change - we have the "mode" file in our port directory. - (*currentPortStatus_1_1)[i].status.canChangeMode = - port.second ? canSwitchRoleHelper(port.first, PortRoleType::MODE) - : false; - (*currentPortStatus_1_1)[i].status.canChangeDataRole = - port.second ? canSwitchRoleHelper(port.first, PortRoleType::DATA_ROLE) - : false; - (*currentPortStatus_1_1)[i].status.canChangePowerRole = - port.second ? canSwitchRoleHelper(port.first, PortRoleType::POWER_ROLE) - : false; - - ALOGI("connected:%d canChangeMode:%d canChagedata:%d canChangePower:%d", - port.second, (*currentPortStatus_1_1)[i].status.canChangeMode, - (*currentPortStatus_1_1)[i].status.canChangeDataRole, - (*currentPortStatus_1_1)[i].status.canChangePowerRole); - - if (V1_0) { - (*currentPortStatus_1_1)[i].status.supportedModes = V1_0::PortMode::DFP; - } else { - (*currentPortStatus_1_1)[i].supportedModes = PortMode_1_1::UFP | PortMode_1_1::DFP; - (*currentPortStatus_1_1)[i].status.supportedModes = V1_0::PortMode::NONE; - (*currentPortStatus_1_1)[i].status.currentMode = V1_0::PortMode::NONE; - } - } - return Status::SUCCESS; - } -done: - return Status::ERROR; -} - -Return Usb::queryPortStatus() { - hidl_vec currentPortStatus_1_1; - hidl_vec currentPortStatus; - Status status; - sp callback_V1_1 = IUsbCallback::castFrom(mCallback_1_0); - - pthread_mutex_lock(&mLock); - if (mCallback_1_0 != NULL) { - if (callback_V1_1 != NULL) { - status = getPortStatusHelper(¤tPortStatus_1_1, false); - } else { - status = getPortStatusHelper(¤tPortStatus_1_1, true); - currentPortStatus.resize(currentPortStatus_1_1.size()); - for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) - currentPortStatus[i] = currentPortStatus_1_1[i].status; - } - - Return ret; - - if (callback_V1_1 != NULL) - ret = callback_V1_1->notifyPortStatusChange_1_1(currentPortStatus_1_1, status); - else - ret = mCallback_1_0->notifyPortStatusChange(currentPortStatus, status); - - if (!ret.isOk()) - ALOGE("queryPortStatus_1_1 error %s", ret.description().c_str()); - } else { - ALOGI("Notifying userspace skipped. Callback is NULL"); - } - pthread_mutex_unlock(&mLock); - - return Void(); -} - -struct data { - int uevent_fd; - android::hardware::usb::V1_1::implementation::Usb *usb; -}; - -static void uevent_event(uint32_t /*epevents*/, struct data *payload) { - char msg[UEVENT_MSG_LEN + 2]; - char *cp; - int n; - - n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); - if (n <= 0) return; - if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ - return; - - msg[n] = '\0'; - msg[n + 1] = '\0'; - cp = msg; - - while (*cp) { - // Removed regex matching for -partner, as we don't seem to have that in the stock HAL and in /sys/class/dual_role_usb. - if (!strncmp(cp, "SUBSYSTEM=dual_role_usb", strlen("SUBSYSTEM=dual_role_usb"))) { // Stock HAL looks for dual_role_usb, and it checks the SUBSYSTEM instead of DEVNAME. 0x62D4 in android.hardware.usb@1.1-service-mediatek from V12.0.1.0.QJOEUXM - hidl_vec currentPortStatus_1_1; - ALOGI("uevent received %s", cp); - pthread_mutex_lock(&payload->usb->mLock); - if (payload->usb->mCallback_1_0 != NULL) { - sp callback_V1_1 = IUsbCallback::castFrom(payload->usb->mCallback_1_0); - Return ret; - - // V1_1 callback - if (callback_V1_1 != NULL) { - Status status = getPortStatusHelper(¤tPortStatus_1_1, false); - ret = callback_V1_1->notifyPortStatusChange_1_1( - currentPortStatus_1_1, status); - } else { // V1_0 callback - Status status = getPortStatusHelper(¤tPortStatus_1_1, true); - - /* - * Copying the result from getPortStatusHelper - * into V1_0::PortStatus to pass back through - * the V1_0 callback object. - */ - hidl_vec currentPortStatus; - currentPortStatus.resize(currentPortStatus_1_1.size()); - for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) - currentPortStatus[i] = currentPortStatus_1_1[i].status; - - ret = payload->usb->mCallback_1_0->notifyPortStatusChange( - currentPortStatus, status); - } - if (!ret.isOk()) ALOGE("error %s", ret.description().c_str()); - } else { - ALOGI("Notifying userspace skipped. Callback is NULL"); - } - pthread_mutex_unlock(&payload->usb->mLock); - - //Role switch is not in progress and port is in disconnected state - if (!pthread_mutex_trylock(&payload->usb->mRoleSwitchLock)) { - for (unsigned long i = 0; i < currentPortStatus_1_1.size(); i++) { - DIR *dp = opendir(std::string("/sys/class/dual_role_usb/" - + std::string(currentPortStatus_1_1[i].status.portName.c_str())).c_str()); // Stock HAL did not append -partner. Based on disassembly - 0x65E0 in android.hardware.usb@1.1-service-mediatek from V12.0.1.0.QJOEUXM - if (dp == NULL) { - //PortRole role = {.role = static_cast(PortMode::UFP)}; - switchToDrp(currentPortStatus_1_1[i].status.portName); - } else { - closedir(dp); - } - } - pthread_mutex_unlock(&payload->usb->mRoleSwitchLock); - } - break; - } // Removed autosuspend regex match stuff - we don't even have the path that regex was looking for on a live device, and there are no mentions of auto suspend stuff in strings from the stock HAL whatsoever. The functions related to auto suspend afterwards have been nuked too. - - /* advance to after the next \0 */ - while (*cp++) {} - } -} - -void *work(void *param) { - int epoll_fd, uevent_fd; - struct epoll_event ev; - int nevents = 0; - struct data payload; - - ALOGE("creating thread"); - - uevent_fd = uevent_open_socket(64 * 1024, true); - - if (uevent_fd < 0) { - ALOGE("uevent_init: uevent_open_socket failed\n"); - return NULL; - } - - payload.uevent_fd = uevent_fd; - payload.usb = (android::hardware::usb::V1_1::implementation::Usb *)param; - - fcntl(uevent_fd, F_SETFL, O_NONBLOCK); - - ev.events = EPOLLIN; - ev.data.ptr = (void *)uevent_event; - - epoll_fd = epoll_create(64); - if (epoll_fd == -1) { - ALOGE("epoll_create failed; errno=%d", errno); - goto error; - } - - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { - ALOGE("epoll_ctl failed; errno=%d", errno); - goto error; - } - - while (!destroyThread) { - struct epoll_event events[64]; - - nevents = epoll_wait(epoll_fd, events, 64, -1); - if (nevents == -1) { - if (errno == EINTR) continue; - ALOGE("usb epoll_wait failed; errno=%d", errno); - break; - } - - for (int n = 0; n < nevents; ++n) { - if (events[n].data.ptr) - (*(void (*)(int, struct data *payload))events[n].data.ptr)( - events[n].events, &payload); - } - } - - ALOGI("exiting worker thread"); -error: - close(uevent_fd); - - if (epoll_fd >= 0) close(epoll_fd); - - return NULL; -} - -void sighandler(int sig) { - if (sig == SIGUSR1) { - destroyThread = true; - ALOGI("destroy set"); - return; - } - signal(SIGUSR1, sighandler); -} - -Return Usb::setCallback(const sp &callback) { - - sp callback_V1_1 = IUsbCallback::castFrom(callback); - - if (callback != NULL) - if (callback_V1_1 == NULL) - ALOGI("Registering 1.0 callback"); - - pthread_mutex_lock(&mLock); - /* - * When both the old callback and new callback values are NULL, - * there is no need to spin off the worker thread. - * When both the values are not NULL, we would already have a - * worker thread running, so updating the callback object would - * be suffice. - */ - if ((mCallback_1_0 == NULL && callback == NULL) || - (mCallback_1_0 != NULL && callback != NULL)) { - /* - * Always store as V1_0 callback object. Type cast to V1_1 - * when the callback is actually invoked. - */ - mCallback_1_0 = callback; - pthread_mutex_unlock(&mLock); - return Void(); - } - - mCallback_1_0 = callback; - ALOGI("registering callback"); - - // Kill the worker thread if the new callback is NULL. - if (mCallback_1_0 == NULL) { - pthread_mutex_unlock(&mLock); - if (!pthread_kill(mPoll, SIGUSR1)) { - pthread_join(mPoll, NULL); - ALOGI("pthread destroyed"); - } - return Void(); - } - - destroyThread = false; - signal(SIGUSR1, sighandler); - - /* - * Create a background thread if the old callback value is NULL - * and being updated with a new value. - */ - if (pthread_create(&mPoll, NULL, work, this)) { - ALOGE("pthread creation failed %d", errno); - mCallback_1_0 = NULL; - } - - pthread_mutex_unlock(&mLock); - return Void(); -} - -} // namespace implementation -} // namespace V1_0 -} // namespace usb -} // namespace hardware -} // namespace android diff --git a/usb/Usb.h b/usb/Usb.h deleted file mode 100755 index 09bfdf9..0000000 --- a/usb/Usb.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef ANDROID_HARDWARE_USB_V1_1_USB_H -#define ANDROID_HARDWARE_USB_V1_1_USB_H - -#include -#include -#include -#include -#include - -#define UEVENT_MSG_LEN 2048 -// The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd. -// The -partner directory would not be created until this is done. -// Having a margin of ~3 secs for the directory and other related bookeeping -// structures created and uvent fired. -#define PORT_TYPE_TIMEOUT 8 - -namespace android { -namespace hardware { -namespace usb { -namespace V1_1 { -namespace implementation { - -using ::android::hardware::usb::V1_0::PortRole; -using ::android::hardware::usb::V1_0::PortRoleType; -using ::android::hardware::usb::V1_0::PortDataRole; -using ::android::hardware::usb::V1_0::PortPowerRole; -using ::android::hardware::usb::V1_0::Status; -using ::android::hardware::usb::V1_1::IUsb; -using ::android::hardware::usb::V1_1::IUsbCallback; -using ::android::hardware::usb::V1_1::PortMode_1_1; -using ::android::hardware::usb::V1_1::PortStatus_1_1; -using ::android::hidl::base::V1_0::DebugInfo; -using ::android::hidl::base::V1_0::IBase; -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::sp; - -struct Usb : public IUsb { - Usb(); - - Return switchRole(const hidl_string& portName, const V1_0::PortRole& role) override; - Return setCallback(const sp& callback) override; - Return queryPortStatus() override; - - - sp mCallback_1_0; - // Protects mCallback variable - pthread_mutex_t mLock; - // Protects roleSwitch operation - pthread_mutex_t mRoleSwitchLock; - // Threads waiting for the partner to come back wait here - pthread_cond_t mPartnerCV; - // lock protecting mPartnerCV - pthread_mutex_t mPartnerLock; - // Variable to signal partner coming back online after type switch - bool mPartnerUp; - - private: - pthread_t mPoll; -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace usb -} // namespace hardware -} // namespace android - -#endif // ANDROID_HARDWARE_USB_V1_1_USB_H diff --git a/usb/UsbGadget.cpp b/usb/UsbGadget.cpp deleted file mode 100644 index 8d7e719..0000000 --- a/usb/UsbGadget.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * 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. - */ -#define LOG_TAG "android.hardware.usb.gadget@1.1-service.rosemary" -#include "UsbGadget.h" -#include -#include -#include -#include -#include -#include -#include -#include -namespace android { -namespace hardware { -namespace usb { -namespace gadget { -namespace V1_1 { -namespace implementation { -UsbGadget::UsbGadget() { - if (access(OS_DESC_PATH, R_OK) != 0) { - ALOGE("configfs setup not done yet"); - abort(); - } -} -void currentFunctionsAppliedCallback(bool functionsApplied, void* payload) { - UsbGadget* gadget = (UsbGadget*)payload; - gadget->mCurrentUsbFunctionsApplied = functionsApplied; -} -Return UsbGadget::getCurrentUsbFunctions(const sp& callback) { - Return 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()); - return Void(); -} -V1_0::Status UsbGadget::tearDownGadget() { - if (resetGadget() != V1_0::Status::SUCCESS) return V1_0::Status::ERROR; - return V1_0::Status::SUCCESS; -} -Return UsbGadget::reset() { - if (!WriteStringToFile("none", PULLUP_PATH)) { - ALOGI("Gadget cannot be pulled down"); - return Status::ERROR; - } - return Status::SUCCESS; -} -static V1_0::Status validateAndSetVidPid(uint64_t functions) { - V1_0::Status ret = V1_0::Status::SUCCESS; - switch (functions) { - case static_cast(V1_0::GadgetFunction::MTP): - ret = setVidPid("0x2717", "0xFF40"); - WriteStringToFile("mtp", CONFIG_STR_PATH); - WriteStringToFile("1", DESC_USE_PATH); - break; - case V1_0::GadgetFunction::ADB | V1_0::GadgetFunction::MTP: - ret = setVidPid("0x2717", "0xFF48"); - WriteStringToFile("mtp_adb", CONFIG_STR_PATH); - WriteStringToFile("1", DESC_USE_PATH); - break; - case static_cast(V1_0::GadgetFunction::RNDIS): - ret = setVidPid("0x2717", "0xFF80"); - WriteStringToFile("rndis", CONFIG_STR_PATH); - break; - case V1_0::GadgetFunction::ADB | V1_0::GadgetFunction::RNDIS: - ret = setVidPid("0x2717", "0xFF88"); - WriteStringToFile("rndis_adb", CONFIG_STR_PATH); - break; - case static_cast(V1_0::GadgetFunction::PTP): - ret = setVidPid("0x2717", "0xFF10"); - WriteStringToFile("ptp", CONFIG_STR_PATH); - break; - case V1_0::GadgetFunction::ADB | V1_0::GadgetFunction::PTP: - ret = setVidPid("0x2717", "0xFF18"); - WriteStringToFile("ptp_adb", CONFIG_STR_PATH); - break; - case static_cast(V1_0::GadgetFunction::ADB): - ret = setVidPid("0x18d1", "0x4ee7"); - WriteStringToFile("adb", CONFIG_STR_PATH); - break; - case static_cast(V1_0::GadgetFunction::MIDI): - ret = setVidPid("0x0E8D", "0x2046"); - break; - case V1_0::GadgetFunction::ADB | V1_0::GadgetFunction::MIDI: - ret = setVidPid("0x0E8D", "0x2048"); - break; - case static_cast(V1_0::GadgetFunction::ACCESSORY): - ret = setVidPid("0x18d1", "0x2d00"); - break; - case V1_0::GadgetFunction::ADB | V1_0::GadgetFunction::ACCESSORY: - ret = setVidPid("0x18d1", "0x2d01"); - break; - case static_cast(V1_0::GadgetFunction::AUDIO_SOURCE): - ret = setVidPid("0x18d1", "0x2d02"); - break; - case V1_0::GadgetFunction::ADB | V1_0::GadgetFunction::AUDIO_SOURCE: - ret = setVidPid("0x18d1", "0x2d03"); - break; - case V1_0::GadgetFunction::ACCESSORY | V1_0::GadgetFunction::AUDIO_SOURCE: - ret = setVidPid("0x18d1", "0x2d04"); - break; - case V1_0::GadgetFunction::ADB | V1_0::GadgetFunction::ACCESSORY | - V1_0::GadgetFunction::AUDIO_SOURCE: - ret = setVidPid("0x18d1", "0x2d05"); - break; - default: - ALOGE("Combination not supported"); - ret = V1_0::Status::CONFIGURATION_NOT_SUPPORTED; - } - return ret; -} -V1_0::Status UsbGadget::setupFunctions(uint64_t functions, - const sp& callback, - uint64_t timeout) { - int i = 1; - if (addGenericAndroidFunctions(functions, &i) != - V1_0::Status::SUCCESS) - return V1_0::Status::ERROR; - - if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) return V1_0::Status::ERROR; - mCurrentUsbFunctionsApplied = true; - if (callback) callback->setCurrentUsbFunctionsCb(functions, V1_0::Status::SUCCESS); - return V1_0::Status::SUCCESS; -} - -Return UsbGadget::setCurrentUsbFunctions(uint64_t functions, - const sp& callback, - uint64_t timeout) { - std::unique_lock lk(mLockSetCurrentFunction); - mCurrentUsbFunctions = functions; - mCurrentUsbFunctionsApplied = false; - // Unlink the gadget - V1_0::Status status = tearDownGadget(); - if (status != V1_0::Status::SUCCESS) { - goto error; - } - ALOGI("Returned from tearDown gadget"); - // Leave the gadget pulled down to give time for the host to sense disconnect. - usleep(kDisconnectWaitUs); - if (functions == static_cast(V1_0::GadgetFunction::NONE)) { - if (callback == NULL) return Void(); - Return ret = callback->setCurrentUsbFunctionsCb(functions, V1_0::Status::SUCCESS); - if (!ret.isOk()) - ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str()); - return Void(); - } - status = validateAndSetVidPid(functions); - if (status != V1_0::Status::SUCCESS) { - goto error; - } - status = setupFunctions(functions, callback, timeout); - if (status != V1_0::Status::SUCCESS) { - goto error; - } - ALOGI("Usb Gadget setcurrent functions called successfully"); - return Void(); -error: - ALOGI("Usb Gadget setcurrent functions failed"); - if (callback == NULL) return Void(); - Return ret = callback->setCurrentUsbFunctionsCb(functions, status); - if (!ret.isOk()) - ALOGE("Error while calling setCurrentUsbFunctionsCb %s", ret.description().c_str()); - return Void(); -} -} // namespace implementation -} // namespace V1_1 -} // namespace gadget -} // namespace usb -} // namespace hardware -} // namespace android diff --git a/usb/UsbGadget.h b/usb/UsbGadget.h deleted file mode 100644 index 040878b..0000000 --- a/usb/UsbGadget.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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. - */ - -#ifndef ANDROID_HARDWARE_USB_GADGET_V1_1_USBGADGET_H -#define ANDROID_HARDWARE_USB_GADGET_V1_1_USBGADGET_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace usb { -namespace gadget { -namespace V1_1 { -namespace implementation { - -using ::android::sp; -using ::android::base::GetProperty; -using ::android::base::SetProperty; -using ::android::base::unique_fd; -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::getVendorFunctions; -using ::android::hardware::usb::gadget::kDebug; -using ::android::hardware::usb::gadget::kDisconnectWaitUs; -using ::android::hardware::usb::gadget::linkFunction; -using ::android::hardware::usb::gadget::resetGadget; -using ::android::hardware::usb::gadget::setVidPid; -using ::android::hardware::usb::gadget::unlinkFunctions; -using ::std::string; - -constexpr char kGadgetName[] = "musb-hdrc"; - -struct UsbGadget : public IUsbGadget { - UsbGadget(); - - // Makes sure that only one request is processed at a time. - std::mutex mLockSetCurrentFunction; - uint64_t mCurrentUsbFunctions; - bool mCurrentUsbFunctionsApplied; - - Return setCurrentUsbFunctions(uint64_t functions, - const sp& callback, - uint64_t timeout) override; - - Return getCurrentUsbFunctions(const sp& callback) override; - - Return reset() override; - - private: - V1_0::Status tearDownGadget(); - V1_0::Status setupFunctions(uint64_t functions, const sp& callback, - uint64_t timeout); -}; - -} // namespace implementation -} // namespace V1_1 -} // namespace gadget -} // namespace usb -} // namespace hardware -} // namespace android - -#endif // ANDROID_HARDWARE_USB_V1_1_USBGADGET_H diff --git a/usb/android.hardware.usb.gadget@1.1-service.rosemary.xml b/usb/android.hardware.usb.gadget@1.1-service.rosemary.xml deleted file mode 100644 index a6f9a1f..0000000 --- a/usb/android.hardware.usb.gadget@1.1-service.rosemary.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - android.hardware.usb.gadget - hwbinder - 1.1 - - IUsbGadget - default - - - diff --git a/usb/android.hardware.usb@1.1-service.rosemary.rc b/usb/android.hardware.usb@1.1-service.rosemary.rc deleted file mode 100755 index d09093b..0000000 --- a/usb/android.hardware.usb@1.1-service.rosemary.rc +++ /dev/null @@ -1,13 +0,0 @@ -service vendor.usb-hal-1-1 /vendor/bin/hw/android.hardware.usb@1.1-service.rosemary - class hal - user root - group root system shell mtp - capabilities - -on boot - chown root system /sys/class/dual_role_usb/dual-role-type_c_port0/power_role - chown root system /sys/class/dual_role_usb/dual-role-type_c_port0/data_role - chown root system /sys/class/dual_role_usb/dual-role-type_c_port0/port_type - chmod 664 /sys/class/dual_role_usb/dual-role-type_c_port0/power_role - chmod 664 /sys/class/dual_role_usb/dual-role-type_c_port0/data_role - chmod 664 /sys/class/dual_role_usb/dual-role-type_c_port0/port_type diff --git a/usb/android.hardware.usb@1.1-service.rosemary.xml b/usb/android.hardware.usb@1.1-service.rosemary.xml deleted file mode 100755 index 81f75e1..0000000 --- a/usb/android.hardware.usb@1.1-service.rosemary.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - android.hardware.usb - hwbinder - 1.1 - - IUsb - default - - - diff --git a/usb/lib/Android.bp b/usb/lib/Android.bp deleted file mode 100644 index e42c1c6..0000000 --- a/usb/lib/Android.bp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ - -cc_library_static { - name: "libusbconfigfs_rosemary", - vendor_available: true, - export_include_dirs: ["include"], - - srcs: [ - "UsbGadgetUtils.cpp", - ], - - cflags: [ - "-Wall", - "-Werror", - "-Wno-error=unused-parameter", - ], - - shared_libs: [ - "android.hardware.usb.gadget@1.0", - "android.hardware.usb.gadget@1.1", - "libbase", - "libcutils", - "libhidlbase", - "libutils", - ], -} diff --git a/usb/lib/UsbGadgetUtils.cpp b/usb/lib/UsbGadgetUtils.cpp deleted file mode 100644 index e6564e0..0000000 --- a/usb/lib/UsbGadgetUtils.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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. - */ - -#define LOG_TAG "libusbconfigfs" - -#include "include/UsbGadgetCommon.h" - -namespace android { -namespace hardware { -namespace usb { -namespace gadget { - -int unlinkFunctions(const char* path) { - DIR* config = opendir(path); - struct dirent* function; - char filepath[kMaxFilePathLength]; - int ret = 0; - - if (config == NULL) return -1; - - // d_type does not seems to be supported in /config - // so filtering by name. - while (((function = readdir(config)) != NULL)) { - if ((strstr(function->d_name, FUNCTION_NAME) == NULL)) continue; - // build the path for each file in the folder. - sprintf(filepath, "%s/%s", path, function->d_name); - ret = remove(filepath); - if (ret) { - ALOGE("Unable remove file %s errno:%d", filepath, errno); - break; - } - } - - closedir(config); - return ret; -} - - -int linkFunction(const char* function, int index) { - char functionPath[kMaxFilePathLength]; - char link[kMaxFilePathLength]; - - sprintf(functionPath, "%s%s", FUNCTIONS_PATH, function); - sprintf(link, "%s%d", FUNCTION_PATH, index); - if (strcmp(function, "rndis.gs4") == 0) { - mkdir(functionPath, 0755); - } - if (symlink(functionPath, link)) { - ALOGE("Cannot create symlink %s -> %s errno:%d", link, functionPath, errno); - return -1; - } - return 0; -} - -Status setVidPid(const char* vid, const char* pid) { - ALOGI("setVidPid %s %s", vid, pid); - if (!WriteStringToFile(vid, VENDOR_ID_PATH)) return Status::ERROR; - - if (!WriteStringToFile(pid, PRODUCT_ID_PATH)) return Status::ERROR; - ALOGI("setVidPid %s %s: success", vid, pid); - return Status::SUCCESS; -} - -std::string getVendorFunctions() { - if (GetProperty(kBuildType, "") == "user") return "user"; - - std::string bootMode = GetProperty(PERSISTENT_BOOT_MODE, ""); - std::string persistVendorFunctions = GetProperty(kPersistentVendorConfig, ""); - std::string vendorFunctions = GetProperty(kVendorConfig, ""); - std::string ret = ""; - - if (vendorFunctions != "") { - ret = vendorFunctions; - } else if (bootMode == "usbradio" || bootMode == "factory" || bootMode == "ffbm-00" || - bootMode == "ffbm-01") { - if (persistVendorFunctions != "") - ret = persistVendorFunctions; - else - ret = "diag"; - // vendor.usb.config will reflect the current configured functions - SetProperty(kVendorConfig, ret); - } - - return ret; -} - -Status resetGadget() { - ALOGI("setCurrentUsbFunctions None"); - - if (!WriteStringToFile("none", PULLUP_PATH)) ALOGI("Gadget cannot be pulled down"); - ALOGI("RESETGADGET: gadget pulled down"); - if (!WriteStringToFile("0", DEVICE_CLASS_PATH)) return Status::ERROR; - ALOGI("RESETGADGET: class reset"); - if (!WriteStringToFile("0", DEVICE_SUB_CLASS_PATH)) return Status::ERROR; - ALOGI("RESETGADGET: subclass reset"); - if (!WriteStringToFile("0", DEVICE_PROTOCOL_PATH)) return Status::ERROR; - ALOGI("RESETGADGET: protocol reset"); - if (!WriteStringToFile("0", DESC_USE_PATH)) return Status::ERROR; - ALOGI("RESETGADGET: use set to 0"); - if (unlinkFunctions(CONFIG_PATH)) return Status::ERROR; - - return Status::SUCCESS; -} - -Status addGenericAndroidFunctions(uint64_t functions, int* functionCount) { - if ((functions & GadgetFunction::MTP) != 0) { - ALOGI("setCurrentUsbFunctions MTP"); - if (linkFunction("mtp.gs0", (*functionCount)++)) return Status::ERROR; - } else if ((functions & GadgetFunction::PTP) != 0) { - ALOGI("setCurrentUsbFunctions PTP"); - if (linkFunction("ptp.gs1", (*functionCount)++)) return Status::ERROR; - } - if ((functions & GadgetFunction::MIDI) != 0) { - ALOGI("setCurrentUsbFunctions MIDI"); - if (linkFunction("midi.gs5", (*functionCount)++)) return Status::ERROR; - } - - if ((functions & GadgetFunction::ACCESSORY) != 0) { - ALOGI("setCurrentUsbFunctions Accessory"); - if (linkFunction("accessory.gs2", (*functionCount)++)) return Status::ERROR; - } - - if ((functions & GadgetFunction::AUDIO_SOURCE) != 0) { - ALOGI("setCurrentUsbFunctions Audio Source"); - if (linkFunction("audio_source.gs3", (*functionCount)++)) return Status::ERROR; - } - - if ((functions & GadgetFunction::RNDIS) != 0) { - ALOGI("setCurrentUsbFunctions rndis"); - if (linkFunction("rndis.gs4", (*functionCount)++)) return Status::ERROR; - } - - if ((functions & GadgetFunction::ADB) != 0) { - ALOGI("setCurrentUsbFunctions ADB"); - if (linkFunction("ffs.adb", (*functionCount)++)) return Status::ERROR; - } - return Status::SUCCESS; -} - -} // namespace gadget -} // namespace usb -} // namespace hardware -} // namespace android diff --git a/usb/lib/include/UsbGadgetCommon.h b/usb/lib/include/UsbGadgetCommon.h deleted file mode 100644 index 8dc49dc..0000000 --- a/usb/lib/include/UsbGadgetCommon.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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. - */ - -#ifndef HARDWARE_USB_USBGADGETCOMMON_H -#define HARDWARE_USB_USBGADGETCOMMON_H - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace usb { -namespace gadget { - -constexpr int kBufferSize = 512; -constexpr int kMaxFilePathLength = 256; -constexpr int kEpollEvents = 10; -constexpr bool kDebug = false; -constexpr int kDisconnectWaitUs = 100000; -constexpr int kPullUpDelay = 500000; -constexpr int kShutdownMonitor = 100; - -constexpr char kBuildType[] = "ro.build.type"; -constexpr char kPersistentVendorConfig[] = "persist.vendor.usb.usbradio.config"; -constexpr char kVendorConfig[] = "vendor.usb.config"; - -#define GADGET_PATH "/config/usb_gadget/g1/" -#define PULLUP_PATH GADGET_PATH "UDC" -#define PERSISTENT_BOOT_MODE "ro.bootmode" -#define VENDOR_ID_PATH GADGET_PATH "idVendor" -#define PRODUCT_ID_PATH GADGET_PATH "idProduct" -#define DEVICE_CLASS_PATH GADGET_PATH "bDeviceClass" -#define DEVICE_SUB_CLASS_PATH GADGET_PATH "bDeviceSubClass" -#define DEVICE_PROTOCOL_PATH GADGET_PATH "bDeviceProtocol" -#define DESC_USE_PATH GADGET_PATH "os_desc/use" -#define OS_DESC_PATH GADGET_PATH "os_desc/b.1" -#define CONFIG_PATH GADGET_PATH "configs/b.1/" -#define CONFIG_STR_PATH CONFIG_PATH "strings/0x409/configuration" -#define FUNCTIONS_PATH GADGET_PATH "functions/" -#define FUNCTION_NAME "f" -#define FUNCTION_PATH CONFIG_PATH FUNCTION_NAME -#define RNDIS_PATH FUNCTIONS_PATH "rndis.gs4" - -using ::android::base::GetProperty; -using ::android::base::SetProperty; -using ::android::base::unique_fd; -using ::android::base::WriteStringToFile; -using ::android::hardware::usb::gadget::V1_0::GadgetFunction; -using ::android::hardware::usb::gadget::V1_0::Status; - -using ::std::lock_guard; -using ::std::move; -using ::std::mutex; -using ::std::string; -using ::std::thread; -using ::std::unique_ptr; -using ::std::vector; -using ::std::chrono::microseconds; -using ::std::chrono::steady_clock; -using ::std::literals::chrono_literals::operator""ms; - -//**************** Helper functions ************************// - -// Removes all the usb functions link in the specified path. -int unlinkFunctions(const char* path); -// Craetes a configfs link for the function. -int linkFunction(const char* function, int index); -// Sets the USB VID and PID. -Status setVidPid(const char* vid, const char* pid); -// Extracts vendor functions from the vendor init properties. -std::string getVendorFunctions(); -// Adds all applicable generic android usb functions other than ADB. -Status addGenericAndroidFunctions(uint64_t functions, int* functionCount); -// Pulls down USB gadget. -Status resetGadget(); - -} // namespace gadget -} // namespace usb -} // namespace hardware -} // namespace android -#endif diff --git a/usb/service.cpp b/usb/service.cpp deleted file mode 100755 index f8b910f..0000000 --- a/usb/service.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -#define LOG_TAG "android.hardware.usb@1.1-service.rosemary" - -#include -#include "Usb.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_1::IUsbGadget; -using android::hardware::usb::gadget::V1_1::implementation::UsbGadget; -using android::hardware::usb::V1_1::IUsb; -using android::hardware::usb::V1_1::implementation::Usb; - -using android::OK; -using android::status_t; - -int main() { - android::sp service = new Usb(); - android::sp service2 = new UsbGadget(); - - configureRpcThreadpool(2, true /*callerWillJoin*/); - status_t status = service->registerAsService(); - - if (status != OK) { - ALOGE("Cannot register USB HAL service"); - return 1; - } - - status = service2->registerAsService(); - - if (status != OK) { - ALOGE("Cannot register USB Gadget HAL service"); - return 1; - } - - ALOGI("USB HAL Ready."); - joinRpcThreadpool(); - // Under noraml cases, execution will not reach this line. - ALOGI("USB HAL failed to join thread pool."); - return 1; -} diff --git a/vndk/Android.mk b/vndk/Android.mk index fbbe3a7..bea275b 100644 --- a/vndk/Android.mk +++ b/vndk/Android.mk @@ -12,26 +12,3 @@ LOCAL_MODULE_TAGS := optional LOCAL_CHECK_ELF_FILES := false LOCAL_VENDOR_MODULE := true include $(BUILD_PREBUILT) - -include $(CLEAR_VARS) -LOCAL_MODULE := libhidlbase-v32 -LOCAL_SRC_FILES_arm64 := v32/arm64/arch-arm64-armv8-a/shared/vndk-sp/libhidlbase.so -LOCAL_MODULE_SUFFIX := .so -LOCAL_MODULE_CLASS := SHARED_LIBRARIES -LOCAL_MODULE_TARGET_ARCH := arm64 -LOCAL_MODULE_TAGS := optional -LOCAL_CHECK_ELF_FILES := false -LOCAL_VENDOR_MODULE := true -include $(BUILD_PREBUILT) - -include $(CLEAR_VARS) -LOCAL_MODULE := libui-v32 -LOCAL_SRC_FILES := v32/arm64/arch-arm-armv8-a/shared/vndk-core/libui.so -LOCAL_MODULE_SUFFIX := .so -LOCAL_MODULE_CLASS := SHARED_LIBRARIES -LOCAL_MODULE_TARGET_ARCH := arm -LOCAL_MODULE_TAGS := optional -LOCAL_CHECK_ELF_FILES := false -LOCAL_VENDOR_MODULE := true -LOCAL_REQUIRED_MODULES := android.hardware.graphics.common-V2-ndk_platform -include $(BUILD_PREBUILT)