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 | |
| 18 | #include <hidl/LegacySupport.h> |
| 19 | |
Steven Moreland | cf80b63 | 2017-01-26 09:43:18 -0800 | [diff] [blame] | 20 | #include <chrono> |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 21 | #include <cutils/properties.h> |
Steven Moreland | cf80b63 | 2017-01-26 09:43:18 -0800 | [diff] [blame] | 22 | #include <thread> |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 23 | #include <utils/misc.h> |
| 24 | #include <utils/Log.h> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | |
| 29 | static const char* kDataProperty = "vold.post_fs_data_done"; |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 30 | |
| 31 | void waitForData() { |
Steven Moreland | cf80b63 | 2017-01-26 09:43:18 -0800 | [diff] [blame] | 32 | using namespace std::literals::chrono_literals; |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 33 | |
Steven Moreland | cf80b63 | 2017-01-26 09:43:18 -0800 | [diff] [blame] | 34 | // TODO(b/34274385) remove this |
| 35 | while (!property_get_bool(kDataProperty, false)) { |
| 36 | std::this_thread::sleep_for(300ms); |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 37 | } |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | namespace details { |
| 41 | |
| 42 | bool blockingHalBinderizationEnabled() { |
| 43 | waitForData(); |
| 44 | return property_get_bool("persist.hal.binderization", false); |
| 45 | } |
| 46 | |
| 47 | void blockIfBinderizationDisabled(const std::string& interface, |
| 48 | const std::string& instance) { |
| 49 | // TODO(b/34274385) remove this |
Steven Moreland | 51fbeaa | 2017-01-30 16:22:06 -0800 | [diff] [blame] | 50 | |
| 51 | size_t loc = interface.find_first_of("@"); |
| 52 | if (loc == std::string::npos) { |
| 53 | LOG_ALWAYS_FATAL("Bad interface name: %s", interface.c_str()); |
| 54 | } |
| 55 | std::string package = interface.substr(0, loc); |
| 56 | |
| 57 | // only block if this is supposed to be toggled |
Yifan Hong | 20273f9 | 2017-01-30 14:13:19 -0800 | [diff] [blame^] | 58 | if (getTransport(interface) != vintf::Transport::TOGGLED) { |
Steven Moreland | 51fbeaa | 2017-01-30 16:22:06 -0800 | [diff] [blame] | 59 | return; |
| 60 | } |
| 61 | |
Steven Moreland | 3903f46 | 2017-01-13 12:57:00 -0800 | [diff] [blame] | 62 | // Must wait for data to be mounted and persistant properties to be read, |
| 63 | // but only delay the start of hals which require reading this property. |
| 64 | bool enabled = blockingHalBinderizationEnabled(); |
| 65 | |
| 66 | if (!enabled) { |
| 67 | ALOGI("Deactivating %s/%s binderized service to" |
| 68 | " yield to passthrough implementation.", |
| 69 | interface.c_str(), |
| 70 | instance.c_str()); |
| 71 | while (true) { |
| 72 | sleep(UINT_MAX); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } // namespace details |
| 77 | |
| 78 | } // namespace hardware |
| 79 | } // namespace android |