blob: 44e6df12f6daf425e43ea93b7963ab87d8a595a3 [file] [log] [blame]
Steven Moreland3903f462017-01-13 12:57:00 -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#define LOG_TAG "libhidltransport"
17
18#include <hidl/LegacySupport.h>
19
Steven Morelandcf80b632017-01-26 09:43:18 -080020#include <chrono>
Steven Moreland3903f462017-01-13 12:57:00 -080021#include <cutils/properties.h>
Steven Morelandcf80b632017-01-26 09:43:18 -080022#include <thread>
Steven Moreland3903f462017-01-13 12:57:00 -080023#include <utils/misc.h>
24#include <utils/Log.h>
25
26namespace android {
27namespace hardware {
28
29static const char* kDataProperty = "vold.post_fs_data_done";
Steven Moreland3903f462017-01-13 12:57:00 -080030
31void waitForData() {
Steven Morelandcf80b632017-01-26 09:43:18 -080032 using namespace std::literals::chrono_literals;
Steven Moreland3903f462017-01-13 12:57:00 -080033
Steven Morelandcf80b632017-01-26 09:43:18 -080034 // TODO(b/34274385) remove this
35 while (!property_get_bool(kDataProperty, false)) {
36 std::this_thread::sleep_for(300ms);
Steven Moreland3903f462017-01-13 12:57:00 -080037 }
Steven Moreland3903f462017-01-13 12:57:00 -080038}
39
40namespace details {
41
42bool blockingHalBinderizationEnabled() {
43 waitForData();
44 return property_get_bool("persist.hal.binderization", false);
45}
46
47void blockIfBinderizationDisabled(const std::string& interface,
48 const std::string& instance) {
49 // TODO(b/34274385) remove this
Steven Moreland51fbeaa2017-01-30 16:22:06 -080050
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 Hong20273f92017-01-30 14:13:19 -080058 if (getTransport(interface) != vintf::Transport::TOGGLED) {
Steven Moreland51fbeaa2017-01-30 16:22:06 -080059 return;
60 }
61
Steven Moreland3903f462017-01-13 12:57:00 -080062 // 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