1 /*
2 * Copyright (C) 2016 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_TAG "HidlInternal"
18
19 #include <hidl/HidlInternal.h>
20
21 #ifdef __ANDROID__
22 #include <android/api-level.h>
23 #endif
24 #include <android-base/logging.h>
25 #include <android-base/properties.h>
26 #include <android-base/stringprintf.h>
27
28 namespace android {
29 namespace hardware {
30 namespace details {
31
logAlwaysFatal(const char * message)32 void logAlwaysFatal(const char* message) {
33 LOG(FATAL) << message;
34 }
35
getVndkSpHwPath(const char * lib)36 std::string getVndkSpHwPath(const char* lib) {
37 static std::string vndk_version = base::GetProperty("ro.vndk.version", "");
38 #ifdef __ANDROID__
39 static int api_level = android_get_device_api_level();
40 if (api_level >= __ANDROID_API_R__) {
41 return android::base::StringPrintf("/apex/com.android.vndk.v%s/%s/hw/",
42 vndk_version.c_str(), lib);
43 }
44 #endif
45 return android::base::StringPrintf("/system/%s/vndk-sp-%s/hw/", lib, vndk_version.c_str());
46 }
47
48 // ----------------------------------------------------------------------
49 // HidlInstrumentor implementation.
HidlInstrumentor(const std::string & package,const std::string & interface)50 HidlInstrumentor::HidlInstrumentor(const std::string& package, const std::string& interface)
51 : mEnableInstrumentation(false),
52 mInstrumentationLibPackage(package),
53 mInterfaceName(interface) {}
54
~HidlInstrumentor()55 HidlInstrumentor::~HidlInstrumentor() {}
56
configureInstrumentation(bool log)57 void HidlInstrumentor::configureInstrumentation(bool log) {
58 mEnableInstrumentation = base::GetBoolProperty("hal.instrumentation.enable", false);
59 if (mEnableInstrumentation) {
60 if (log) {
61 LOG(INFO) << "Enable instrumentation.";
62 }
63 mInstrumentationCallbacks.clear();
64 registerInstrumentationCallbacks(&mInstrumentationCallbacks);
65 } else {
66 if (log) {
67 LOG(INFO) << "Disable instrumentation.";
68 }
69 mInstrumentationCallbacks.clear();
70 }
71 }
72
registerInstrumentationCallbacks(std::vector<InstrumentationCallback> * instrumentationCallbacks)73 void HidlInstrumentor::registerInstrumentationCallbacks(
74 std::vector<InstrumentationCallback> *instrumentationCallbacks) {
75 // No-op, historical
76 (void) instrumentationCallbacks;
77 return;
78 }
79
isInstrumentationLib(const dirent * file)80 bool HidlInstrumentor::isInstrumentationLib(const dirent *file) {
81 (void) file;
82 return false;
83 }
84
85 } // namespace details
86 } // namespace hardware
87 } // namespace android
88