Remove libbinder dependency for NDK backend
The current dependency on libbinder was accidental, not required for its
clients. It prevents the client libraries from being packaged in Vendor
APEX.
Bug: 295803971
Bug: 316234086
Test: launch cuttlefish, CtsMediaAudioTestCases
Change-Id: I042018ded92f88ab1a25f637f884313934cdfefe
diff --git a/media/audioaidlconversion/AidlConversionCppNdk.cpp b/media/audioaidlconversion/AidlConversionCppNdk.cpp
index ab48198..bcb31f3 100644
--- a/media/audioaidlconversion/AidlConversionCppNdk.cpp
+++ b/media/audioaidlconversion/AidlConversionCppNdk.cpp
@@ -28,7 +28,6 @@
#include "media/AidlConversionCppNdk.h"
-#include <media/ShmemCompat.h>
#include <media/stagefright/foundation/MediaDefs.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/media/audioaidlconversion/Android.bp b/media/audioaidlconversion/Android.bp
index d3a5755..07c59c7 100644
--- a/media/audioaidlconversion/Android.bp
+++ b/media/audioaidlconversion/Android.bp
@@ -56,6 +56,19 @@
}
cc_defaults {
+ name: "audio_aidl_conversion_common_default_cpp",
+ shared_libs: [
+ "libbinder",
+ "libshmemcompat",
+ "shared-file-region-aidl-cpp",
+ "framework-permission-aidl-cpp",
+ ],
+ export_shared_lib_headers: [
+ "shared-file-region-aidl-cpp",
+ ],
+}
+
+cc_defaults {
name: "audio_aidl_conversion_common_default",
export_include_dirs: ["include"],
host_supported: true,
@@ -67,17 +80,12 @@
],
shared_libs: [
"libbase",
- "libbinder",
"liblog",
- "libshmemcompat",
"libstagefright_foundation",
"libutils",
- "shared-file-region-aidl-cpp",
- "framework-permission-aidl-cpp",
],
export_shared_lib_headers: [
"libbase",
- "shared-file-region-aidl-cpp",
],
cflags: [
"-Wall",
@@ -113,6 +121,7 @@
],
defaults: [
"audio_aidl_conversion_common_default",
+ "audio_aidl_conversion_common_default_cpp",
"latest_android_media_audio_common_types_cpp_export_shared",
],
min_sdk_version: "29",
@@ -223,6 +232,7 @@
],
defaults: [
"audio_aidl_conversion_common_default",
+ "audio_aidl_conversion_common_default_cpp",
"audio_aidl_conversion_common_util_default",
"latest_android_media_audio_common_types_cpp_shared",
"latest_android_media_audio_common_types_ndk_shared",
diff --git a/media/audioaidlconversion/include/media/AidlConversionUtil-impl.h b/media/audioaidlconversion/include/media/AidlConversionUtil-impl.h
index 656d76a..53f529e 100644
--- a/media/audioaidlconversion/include/media/AidlConversionUtil-impl.h
+++ b/media/audioaidlconversion/include/media/AidlConversionUtil-impl.h
@@ -30,7 +30,6 @@
#include <utility>
#include <android-base/expected.h>
-#include <binder/Status.h>
#if defined(BACKEND_NDK_IMPL)
#include <android/binder_auto_utils.h>
@@ -40,6 +39,7 @@
namespace aidl {
#else
#include <binder/Enums.h>
+#include <binder/Status.h>
#endif // BACKEND_NDK_IMPL
namespace android {
@@ -374,6 +374,30 @@
* Note: for EX_TRANSACTION_FAILED and EX_SERVICE_SPECIFIC a more detailed error code
* can be found from transactionError() or serviceSpecificErrorCode().
*/
+#if defined(BACKEND_NDK_IMPL)
+static inline ::android::status_t statusTFromExceptionCode(binder_exception_t exception) {
+ switch (exception) {
+ case EX_NONE:
+ return ::android::OK;
+ case EX_SECURITY: // Java SecurityException, rethrows locally in Java
+ return ::android::PERMISSION_DENIED;
+ case EX_BAD_PARCELABLE: // Java BadParcelableException, rethrows in Java
+ case EX_ILLEGAL_ARGUMENT: // Java IllegalArgumentException, rethrows in Java
+ case EX_NULL_POINTER: // Java NullPointerException, rethrows in Java
+ return ::android::BAD_VALUE;
+ case EX_ILLEGAL_STATE: // Java IllegalStateException, rethrows in Java
+ case EX_UNSUPPORTED_OPERATION: // Java UnsupportedOperationException, rethrows
+ return ::android::INVALID_OPERATION;
+ case EX_PARCELABLE: // Java bootclass loader (not standard exception), rethrows
+ case EX_NETWORK_MAIN_THREAD: // Java NetworkOnMainThreadException, rethrows
+ case EX_TRANSACTION_FAILED: // Native - see error code
+ case EX_SERVICE_SPECIFIC: // Java ServiceSpecificException,
+ // rethrows in Java with integer error code
+ return ::android::UNKNOWN_ERROR;
+ }
+ return ::android::UNKNOWN_ERROR;
+}
+#else
static inline ::android::status_t statusTFromExceptionCode(int32_t exceptionCode) {
using namespace ::android::binder;
switch (exceptionCode) {
@@ -398,6 +422,7 @@
}
return ::android::UNKNOWN_ERROR;
}
+#endif // BACKEND_NDK_IMPL
/**
* Return the equivalent Android ::android::status_t from a binder status.
@@ -410,6 +435,7 @@
*
* return_type method(type0 param0, ...)
*/
+#if !defined(BACKEND_NDK_IMPL)
static inline ::android::status_t statusTFromBinderStatus(const ::android::binder::Status &status) {
return status.isOk() ? ::android::OK // check ::android::OK,
: status.serviceSpecificErrorCode() // service-side error, not standard Java exception
@@ -418,6 +444,7 @@
?: statusTFromExceptionCode(status.exceptionCode()); // a service-side error with a
// standard Java exception (fromExceptionCode)
}
+#endif
#if defined(BACKEND_NDK_IMPL)
static inline ::android::status_t statusTFromBinderStatus(const ::ndk::ScopedAStatus &status) {
@@ -443,6 +470,7 @@
* This is used for methods not returning an explicit status_t,
* where Java callers expect an exception, not an integer return value.
*/
+#if !defined(BACKEND_NDK_IMPL)
static inline ::android::binder::Status binderStatusFromStatusT(
::android::status_t status, const char *optionalMessage = nullptr) {
const char * const emptyIfNull = optionalMessage == nullptr ? "" : optionalMessage;
@@ -470,6 +498,7 @@
// throw a ServiceSpecificException.
return Status::fromServiceSpecificError(status, emptyIfNull);
}
+#endif
} // namespace aidl_utils
diff --git a/media/audioaidlconversion/tests/audio_aidl_ndk_conversion_tests.cpp b/media/audioaidlconversion/tests/audio_aidl_ndk_conversion_tests.cpp
index 60727b4..f78243e 100644
--- a/media/audioaidlconversion/tests/audio_aidl_ndk_conversion_tests.cpp
+++ b/media/audioaidlconversion/tests/audio_aidl_ndk_conversion_tests.cpp
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+#define LOG_TAG "AidlConversionNdkTests"
#include <iostream>
#include <type_traits>
diff --git a/media/libaudioclient/Android.bp b/media/libaudioclient/Android.bp
index 2c9e173..b44dc18 100644
--- a/media/libaudioclient/Android.bp
+++ b/media/libaudioclient/Android.bp
@@ -217,6 +217,7 @@
],
defaults: [
"audio_aidl_conversion_common_default",
+ "audio_aidl_conversion_common_default_cpp",
"latest_android_media_audio_common_types_cpp_export_shared",
],
}
diff --git a/media/libaudiohal/tests/CoreAudioHalAidl_test.cpp b/media/libaudiohal/tests/CoreAudioHalAidl_test.cpp
index adff110..1204a3b 100644
--- a/media/libaudiohal/tests/CoreAudioHalAidl_test.cpp
+++ b/media/libaudiohal/tests/CoreAudioHalAidl_test.cpp
@@ -201,6 +201,9 @@
ndk::ScopedAStatus getAAudioHardwareBurstMinUsec(int32_t*) override {
return ndk::ScopedAStatus::ok();
}
+ ndk::ScopedAStatus prepareToDisconnectExternalDevice(int32_t) override {
+ return ndk::ScopedAStatus::ok();
+ }
bool mIsScreenTurnedOn = false;
ScreenRotation mScreenRotation = ScreenRotation::DEG_0;