Steven Moreland | 337c3ae | 2016-11-22 13:37:32 -0800 | [diff] [blame] | 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 | |
Jooyung Han | 219106c | 2020-07-17 15:01:19 +0900 | [diff] [blame] | 21 | #ifdef __ANDROID__ |
| 22 | #include <android/api-level.h> |
| 23 | #endif |
Steven Moreland | 337c3ae | 2016-11-22 13:37:32 -0800 | [diff] [blame] | 24 | #include <android-base/logging.h> |
Justin Yun | 1f04810 | 2017-12-01 15:30:08 +0900 | [diff] [blame] | 25 | #include <android-base/properties.h> |
| 26 | #include <android-base/stringprintf.h> |
Zhuoyao Zhang | 7a57de6 | 2017-02-15 21:04:19 +0000 | [diff] [blame] | 27 | |
Steven Moreland | 337c3ae | 2016-11-22 13:37:32 -0800 | [diff] [blame] | 28 | namespace android { |
| 29 | namespace hardware { |
| 30 | namespace details { |
| 31 | |
Ryan Campbell | 69aff75 | 2017-07-27 13:49:46 -0700 | [diff] [blame] | 32 | void logAlwaysFatal(const char* message) { |
Steven Moreland | 337c3ae | 2016-11-22 13:37:32 -0800 | [diff] [blame] | 33 | LOG(FATAL) << message; |
| 34 | } |
| 35 | |
Jooyung Han | 219106c | 2020-07-17 15:01:19 +0900 | [diff] [blame] | 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()); |
Justin Yun | 1f04810 | 2017-12-01 15:30:08 +0900 | [diff] [blame] | 46 | } |
| 47 | |
Zhuoyao Zhang | 7a57de6 | 2017-02-15 21:04:19 +0000 | [diff] [blame] | 48 | // ---------------------------------------------------------------------- |
| 49 | // HidlInstrumentor implementation. |
Steven Moreland | 384792b | 2017-06-19 18:24:40 -0700 | [diff] [blame] | 50 | HidlInstrumentor::HidlInstrumentor(const std::string& package, const std::string& interface) |
| 51 | : mEnableInstrumentation(false), |
| 52 | mInstrumentationLibPackage(package), |
Steven Moreland | 78f989d | 2021-10-12 15:51:16 -0700 | [diff] [blame] | 53 | mInterfaceName(interface) {} |
Zhuoyao Zhang | 7a57de6 | 2017-02-15 21:04:19 +0000 | [diff] [blame] | 54 | |
Ryan Campbell | 69aff75 | 2017-07-27 13:49:46 -0700 | [diff] [blame] | 55 | HidlInstrumentor::~HidlInstrumentor() {} |
Zhuoyao Zhang | 7a57de6 | 2017-02-15 21:04:19 +0000 | [diff] [blame] | 56 | |
| 57 | void HidlInstrumentor::configureInstrumentation(bool log) { |
Steven Moreland | 2056cf3 | 2019-09-17 17:41:02 -0700 | [diff] [blame] | 58 | mEnableInstrumentation = base::GetBoolProperty("hal.instrumentation.enable", false); |
Zhuoyao Zhang | e8f8259 | 2018-02-01 16:18:15 -0800 | [diff] [blame] | 59 | if (mEnableInstrumentation) { |
| 60 | if (log) { |
| 61 | LOG(INFO) << "Enable instrumentation."; |
Zhuoyao Zhang | 7a57de6 | 2017-02-15 21:04:19 +0000 | [diff] [blame] | 62 | } |
Zhuoyao Zhang | e8f8259 | 2018-02-01 16:18:15 -0800 | [diff] [blame] | 63 | mInstrumentationCallbacks.clear(); |
| 64 | registerInstrumentationCallbacks(&mInstrumentationCallbacks); |
| 65 | } else { |
| 66 | if (log) { |
| 67 | LOG(INFO) << "Disable instrumentation."; |
| 68 | } |
| 69 | mInstrumentationCallbacks.clear(); |
Zhuoyao Zhang | 7a57de6 | 2017-02-15 21:04:19 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | void HidlInstrumentor::registerInstrumentationCallbacks( |
| 74 | std::vector<InstrumentationCallback> *instrumentationCallbacks) { |
Steven Moreland | 78f989d | 2021-10-12 15:51:16 -0700 | [diff] [blame] | 75 | // No-op, historical |
Steven Moreland | ead33e2 | 2017-02-21 19:19:39 -0800 | [diff] [blame] | 76 | (void) instrumentationCallbacks; |
Zhuoyao Zhang | 7a57de6 | 2017-02-15 21:04:19 +0000 | [diff] [blame] | 77 | return; |
Zhuoyao Zhang | 7a57de6 | 2017-02-15 21:04:19 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | bool HidlInstrumentor::isInstrumentationLib(const dirent *file) { |
Steven Moreland | ead33e2 | 2017-02-21 19:19:39 -0800 | [diff] [blame] | 81 | (void) file; |
Zhuoyao Zhang | 7a57de6 | 2017-02-15 21:04:19 +0000 | [diff] [blame] | 82 | return false; |
| 83 | } |
| 84 | |
Steven Moreland | 337c3ae | 2016-11-22 13:37:32 -0800 | [diff] [blame] | 85 | } // namespace details |
| 86 | } // namespace hardware |
| 87 | } // namespace android |