blob: 17371d4ebd5dd49eca2730f6177f7598a7de696d [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 }
Chia-I Wu93b6ecb2017-02-08 19:03:08 -080038
39 // TODO(b/35178781) wait a bit longer
40 std::this_thread::sleep_for(300ms);
Steven Moreland3903f462017-01-13 12:57:00 -080041}
42
43namespace details {
44
45bool blockingHalBinderizationEnabled() {
46 waitForData();
47 return property_get_bool("persist.hal.binderization", false);
48}
49
50void blockIfBinderizationDisabled(const std::string& interface,
51 const std::string& instance) {
52 // TODO(b/34274385) remove this
Steven Moreland51fbeaa2017-01-30 16:22:06 -080053
54 size_t loc = interface.find_first_of("@");
55 if (loc == std::string::npos) {
56 LOG_ALWAYS_FATAL("Bad interface name: %s", interface.c_str());
57 }
58 std::string package = interface.substr(0, loc);
59
60 // only block if this is supposed to be toggled
Yifan Hong20273f92017-01-30 14:13:19 -080061 if (getTransport(interface) != vintf::Transport::TOGGLED) {
Steven Moreland51fbeaa2017-01-30 16:22:06 -080062 return;
63 }
64
Steven Moreland3903f462017-01-13 12:57:00 -080065 // Must wait for data to be mounted and persistant properties to be read,
66 // but only delay the start of hals which require reading this property.
67 bool enabled = blockingHalBinderizationEnabled();
68
69 if (!enabled) {
70 ALOGI("Deactivating %s/%s binderized service to"
71 " yield to passthrough implementation.",
72 interface.c_str(),
73 instance.c_str());
74 while (true) {
75 sleep(UINT_MAX);
76 }
77 }
78}
79} // namespace details
80
81} // namespace hardware
82} // namespace android