1 /*
2  * Copyright 2023 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 
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "Codec2-HalSelection"
19 #include <android-base/logging.h>
20 
21 // NOTE: due to dependency from mainline modules cannot use libsysprop
22 // #include <android/sysprop/MediaProperties.sysprop.h>
23 #include <android-base/properties.h>
24 #include <com_android_media_codec_flags.h>
25 
26 #include <codec2/common/HalSelection.h>
27 
28 namespace android {
29 
IsCodec2AidlHalSelected()30 bool IsCodec2AidlHalSelected() {
31     // For new devices with vendor software targeting 202404, we always want to
32     // use AIDL if it exists
33     constexpr int kAndroidApi202404 = 202404;
34     int vendorVersion = ::android::base::GetIntProperty("ro.vendor.api_level", -1);
35     if (!com::android::media::codec::flags::provider_->aidl_hal() &&
36         vendorVersion < kAndroidApi202404) {
37         // Cannot select AIDL if not enabled
38         return false;
39     }
40 #if 0
41     // NOTE: due to dependency from mainline modules cannot use libsysprop
42     using ::android::sysprop::MediaProperties::codec2_hal_selection;
43     using ::android::sysprop::MediaProperties::codec2_hal_selection_values;
44     constexpr codec2_hal_selection_values AIDL = codec2_hal_selection_values::AIDL;
45     constexpr codec2_hal_selection_values HIDL = codec2_hal_selection_values::HIDL;
46     codec2_hal_selection_values selection = codec2_hal_selection().value_or(HIDL);
47     switch (selection) {
48     case AIDL:
49         return true;
50     case HIDL:
51         return false;
52     default:
53         LOG(FATAL) << "Unexpected codec2 HAL selection value: " << (int)selection;
54     }
55 #else
56     std::string selection = ::android::base::GetProperty("media.c2.hal.selection", "hidl");
57     if (selection == "aidl") {
58         return true;
59     } else if (selection == "hidl") {
60         return false;
61     } else {
62         LOG(FATAL) << "Unexpected codec2 HAL selection value: " << selection;
63     }
64 #endif
65 
66     return false;
67 }
68 
69 }  // namespace android
70