Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -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 | #define LOG_TAG "libhidltransport" |
| 17 | |
Keun-young Park | 8575745 | 2017-02-17 14:15:54 -0800 | [diff] [blame] | 18 | #include <inttypes.h> |
| 19 | |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 20 | #include <hidl/LegacySupport.h> |
| 21 | |
Steven Moreland | cf80b63 | 2017-01-26 09:43:18 -0800 | [diff] [blame] | 22 | #include <chrono> |
Steven Moreland | cf80b63 | 2017-01-26 09:43:18 -0800 | [diff] [blame] | 23 | #include <thread> |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 24 | #include <utils/misc.h> |
| 25 | #include <utils/Log.h> |
Keun-young Park | 8575745 | 2017-02-17 14:15:54 -0800 | [diff] [blame] | 26 | #include <utils/SystemClock.h> |
| 27 | |
| 28 | #include <android-base/properties.h> |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | namespace hardware { |
| 32 | |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 33 | namespace details { |
| 34 | |
Keun-young Park | 8575745 | 2017-02-17 14:15:54 -0800 | [diff] [blame] | 35 | using android::base::GetBoolProperty; |
| 36 | using android::base::GetUintProperty; |
| 37 | using android::base::WaitForPropertyCreation; |
| 38 | |
| 39 | static const char* kPersistPropReadyProperty = "ro.boottime.persistent_properties"; |
| 40 | static const char* kBinderizationProperty = "persist.hal.binderization"; |
| 41 | |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 42 | bool blockingHalBinderizationEnabled() { |
Keun-young Park | 8575745 | 2017-02-17 14:15:54 -0800 | [diff] [blame] | 43 | uint64_t t = GetUintProperty<uint64_t>(kPersistPropReadyProperty, 0, UINT64_MAX); |
| 44 | if (t == 0) { // not set yet |
| 45 | int64_t startTime = elapsedRealtime(); |
| 46 | WaitForPropertyCreation(kPersistPropReadyProperty, std::chrono::milliseconds::max()); |
| 47 | ALOGI("Waiting for %s took %" PRId64 " ms", kPersistPropReadyProperty, |
| 48 | elapsedRealtime() - startTime); |
| 49 | } |
| 50 | return GetBoolProperty(kBinderizationProperty, false); |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void blockIfBinderizationDisabled(const std::string& interface, |
| 54 | const std::string& instance) { |
| 55 | // TODO(b/34274385) remove this |
Steven Moreland | 51fbeaa | 2017-01-30 16:22:06 -0800 | [diff] [blame] | 56 | |
| 57 | size_t loc = interface.find_first_of("@"); |
| 58 | if (loc == std::string::npos) { |
| 59 | LOG_ALWAYS_FATAL("Bad interface name: %s", interface.c_str()); |
| 60 | } |
| 61 | std::string package = interface.substr(0, loc); |
| 62 | |
| 63 | // only block if this is supposed to be toggled |
Yifan Hong | 20273f9 | 2017-01-30 14:13:19 -0800 | [diff] [blame] | 64 | if (getTransport(interface) != vintf::Transport::TOGGLED) { |
Steven Moreland | 51fbeaa | 2017-01-30 16:22:06 -0800 | [diff] [blame] | 65 | return; |
| 66 | } |
| 67 | |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 68 | // Must wait for data to be mounted and persistant properties to be read, |
| 69 | // but only delay the start of hals which require reading this property. |
| 70 | bool enabled = blockingHalBinderizationEnabled(); |
| 71 | |
| 72 | if (!enabled) { |
| 73 | ALOGI("Deactivating %s/%s binderized service to" |
| 74 | " yield to passthrough implementation.", |
| 75 | interface.c_str(), |
| 76 | instance.c_str()); |
| 77 | while (true) { |
| 78 | sleep(UINT_MAX); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } // namespace details |
| 83 | |
| 84 | } // namespace hardware |
| 85 | } // namespace android |