Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4eb1cb4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Remove libbinder dependency for NDK backend" into main

parents 014605a5 285c125f
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@

#include "media/AidlConversionCppNdk.h"

#include <media/ShmemCompat.h>
#include <media/stagefright/foundation/MediaDefs.h>

////////////////////////////////////////////////////////////////////////////////////////////////////
+15 −5
Original line number Diff line number Diff line
@@ -55,6 +55,19 @@ cc_library_headers {
    ],
}

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"],
@@ -67,17 +80,12 @@ cc_defaults {
    ],
    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 @@ cc_library {
    ],
    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 @@ cc_library {
    ],
    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",
+30 −1
Original line number Diff line number Diff line
@@ -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 @@ std::string enumsToString(const T& t) {
 * 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 @@ static inline ::android::status_t statusTFromExceptionCode(int32_t exceptionCode
    }
    return ::android::UNKNOWN_ERROR;
}
#endif  // BACKEND_NDK_IMPL

/**
 * Return the equivalent Android ::android::status_t from a binder status.
@@ -410,6 +435,7 @@ static inline ::android::status_t statusTFromExceptionCode(int32_t exceptionCode
 *
 * 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 @@ static inline ::android::status_t statusTFromBinderStatus(const ::android::binde
        ?: 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 @@ static inline ::android::status_t statusTFromBinderStatusT(binder_status_t statu
 * 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 @@ static inline ::android::binder::Status binderStatusFromStatusT(
    // throw a ServiceSpecificException.
    return Status::fromServiceSpecificError(status, emptyIfNull);
}
#endif

} // namespace aidl_utils

+1 −1
Original line number Diff line number Diff line
@@ -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>

+1 −0
Original line number Diff line number Diff line
@@ -217,6 +217,7 @@ cc_library {
    ],
    defaults: [
        "audio_aidl_conversion_common_default",
        "audio_aidl_conversion_common_default_cpp",
        "latest_android_media_audio_common_types_cpp_export_shared",
    ],
}