1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include <string> 19 #include <vector> 20 21 #include <android/binder_auto_utils.h> 22 #include "aidl/android/hardware/drm/Status.h" 23 #include "ClearKeyTypes.h" 24 25 namespace aidl { 26 namespace android { 27 namespace hardware { 28 namespace drm { 29 namespace clearkey { 30 toMockStatus(::aidl::android::hardware::drm::Status status)31inline ::aidl::android::hardware::drm::Status toMockStatus( 32 ::aidl::android::hardware::drm::Status status) { 33 switch (status) { 34 case ::aidl::android::hardware::drm::Status::ERROR_DRM_INSUFFICIENT_SECURITY: 35 case ::aidl::android::hardware::drm::Status::ERROR_DRM_FRAME_TOO_LARGE: 36 case ::aidl::android::hardware::drm::Status::ERROR_DRM_SESSION_LOST_STATE: 37 return ::aidl::android::hardware::drm::Status::ERROR_DRM_UNKNOWN; 38 default: 39 return status; 40 } 41 } 42 43 inline ::ndk::ScopedAStatus toNdkScopedAStatus(::aidl::android::hardware::drm::Status status, 44 const char* msg = nullptr) { 45 if (Status::OK == status) { 46 return ::ndk::ScopedAStatus::ok(); 47 } else { 48 auto err = static_cast<int32_t>(status); 49 if (msg) { 50 return ::ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(err, msg); 51 } else { 52 return ::ndk::ScopedAStatus::fromServiceSpecificError(err); 53 } 54 } 55 } 56 toNdkScopedAStatus(clearkeydrm::CdmResponseType res)57inline ::ndk::ScopedAStatus toNdkScopedAStatus(clearkeydrm::CdmResponseType res) { 58 return toNdkScopedAStatus(static_cast<::aidl::android::hardware::drm::Status>(res)); 59 } 60 61 #define UNUSED(x) (void)(x); 62 63 } // namespace clearkey 64 } // namespace drm 65 } // namespace hardware 66 } // namespace android 67 } // namespace aidl 68