blob: a94f2359b54928a37f509b915e630087758f30b1 [file] [log] [blame]
Steven Moreland337c3ae2016-11-22 13:37:32 -08001/*
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
Jooyung Han219106c2020-07-17 15:01:19 +090021#ifdef __ANDROID__
22#include <android/api-level.h>
23#endif
Steven Moreland337c3ae2016-11-22 13:37:32 -080024#include <android-base/logging.h>
Justin Yun1f048102017-12-01 15:30:08 +090025#include <android-base/properties.h>
26#include <android-base/stringprintf.h>
Zhuoyao Zhang7a57de62017-02-15 21:04:19 +000027
Steven Moreland337c3ae2016-11-22 13:37:32 -080028namespace android {
29namespace hardware {
30namespace details {
31
Ryan Campbell69aff752017-07-27 13:49:46 -070032void logAlwaysFatal(const char* message) {
Steven Moreland337c3ae2016-11-22 13:37:32 -080033 LOG(FATAL) << message;
34}
35
Jooyung Han219106c2020-07-17 15:01:19 +090036std::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());
Justin Yun1f048102017-12-01 15:30:08 +090046}
47
Zhuoyao Zhang7a57de62017-02-15 21:04:19 +000048// ----------------------------------------------------------------------
49// HidlInstrumentor implementation.
Steven Moreland384792b2017-06-19 18:24:40 -070050HidlInstrumentor::HidlInstrumentor(const std::string& package, const std::string& interface)
51 : mEnableInstrumentation(false),
52 mInstrumentationLibPackage(package),
Steven Moreland78f989d2021-10-12 15:51:16 -070053 mInterfaceName(interface) {}
Zhuoyao Zhang7a57de62017-02-15 21:04:19 +000054
Ryan Campbell69aff752017-07-27 13:49:46 -070055HidlInstrumentor::~HidlInstrumentor() {}
Zhuoyao Zhang7a57de62017-02-15 21:04:19 +000056
57void HidlInstrumentor::configureInstrumentation(bool log) {
Steven Moreland2056cf32019-09-17 17:41:02 -070058 mEnableInstrumentation = base::GetBoolProperty("hal.instrumentation.enable", false);
Zhuoyao Zhange8f82592018-02-01 16:18:15 -080059 if (mEnableInstrumentation) {
60 if (log) {
61 LOG(INFO) << "Enable instrumentation.";
Zhuoyao Zhang7a57de62017-02-15 21:04:19 +000062 }
Zhuoyao Zhange8f82592018-02-01 16:18:15 -080063 mInstrumentationCallbacks.clear();
64 registerInstrumentationCallbacks(&mInstrumentationCallbacks);
65 } else {
66 if (log) {
67 LOG(INFO) << "Disable instrumentation.";
68 }
69 mInstrumentationCallbacks.clear();
Zhuoyao Zhang7a57de62017-02-15 21:04:19 +000070 }
71}
72
73void HidlInstrumentor::registerInstrumentationCallbacks(
74 std::vector<InstrumentationCallback> *instrumentationCallbacks) {
Steven Moreland78f989d2021-10-12 15:51:16 -070075 // No-op, historical
Steven Morelandead33e22017-02-21 19:19:39 -080076 (void) instrumentationCallbacks;
Zhuoyao Zhang7a57de62017-02-15 21:04:19 +000077 return;
Zhuoyao Zhang7a57de62017-02-15 21:04:19 +000078}
79
80bool HidlInstrumentor::isInstrumentationLib(const dirent *file) {
Steven Morelandead33e22017-02-21 19:19:39 -080081 (void) file;
Zhuoyao Zhang7a57de62017-02-15 21:04:19 +000082 return false;
83}
84
Steven Moreland337c3ae2016-11-22 13:37:32 -080085} // namespace details
86} // namespace hardware
87} // namespace android