blob: 0032fc3267d1d5a2d6ea0abc6f6ab36061d432a3 [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
Keun-young Park85757452017-02-17 14:15:54 -080018#include <inttypes.h>
19
Steven Moreland3903f462017-01-13 12:57:00 -080020#include <hidl/LegacySupport.h>
21
Steven Morelandcf80b632017-01-26 09:43:18 -080022#include <chrono>
Steven Morelandcf80b632017-01-26 09:43:18 -080023#include <thread>
Steven Moreland3903f462017-01-13 12:57:00 -080024#include <utils/misc.h>
25#include <utils/Log.h>
Keun-young Park85757452017-02-17 14:15:54 -080026#include <utils/SystemClock.h>
27
28#include <android-base/properties.h>
Steven Moreland3903f462017-01-13 12:57:00 -080029
30namespace android {
31namespace hardware {
32
Steven Moreland3903f462017-01-13 12:57:00 -080033namespace details {
34
Keun-young Park85757452017-02-17 14:15:54 -080035using android::base::GetBoolProperty;
36using android::base::GetUintProperty;
37using android::base::WaitForPropertyCreation;
38
39static const char* kPersistPropReadyProperty = "ro.boottime.persistent_properties";
40static const char* kBinderizationProperty = "persist.hal.binderization";
41
Steven Moreland3903f462017-01-13 12:57:00 -080042bool blockingHalBinderizationEnabled() {
Keun-young Park85757452017-02-17 14:15:54 -080043 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 Moreland3903f462017-01-13 12:57:00 -080051}
52
53void blockIfBinderizationDisabled(const std::string& interface,
54 const std::string& instance) {
55 // TODO(b/34274385) remove this
Steven Moreland51fbeaa2017-01-30 16:22:06 -080056
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 Hong20273f92017-01-30 14:13:19 -080064 if (getTransport(interface) != vintf::Transport::TOGGLED) {
Steven Moreland51fbeaa2017-01-30 16:22:06 -080065 return;
66 }
67
Steven Moreland3903f462017-01-13 12:57:00 -080068 // 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