blob: ae029281ee4725155bea022386055d73f22521ed [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;
Keun-young Park85757452017-02-17 14:15:54 -080036using android::base::WaitForPropertyCreation;
37
Keun-young Parka256dc32017-02-28 19:19:05 -080038static const char* kPersistPropReadyProperty = "ro.persistent_properties.ready";
Keun-young Park85757452017-02-17 14:15:54 -080039static const char* kBinderizationProperty = "persist.hal.binderization";
40
Steven Moreland3903f462017-01-13 12:57:00 -080041bool blockingHalBinderizationEnabled() {
Keun-young Parka256dc32017-02-28 19:19:05 -080042 if (!GetBoolProperty(kPersistPropReadyProperty, false)) { // not set yet
Keun-young Park85757452017-02-17 14:15:54 -080043 int64_t startTime = elapsedRealtime();
44 WaitForPropertyCreation(kPersistPropReadyProperty, std::chrono::milliseconds::max());
45 ALOGI("Waiting for %s took %" PRId64 " ms", kPersistPropReadyProperty,
46 elapsedRealtime() - startTime);
47 }
48 return GetBoolProperty(kBinderizationProperty, false);
Steven Moreland3903f462017-01-13 12:57:00 -080049}
50
51void blockIfBinderizationDisabled(const std::string& interface,
52 const std::string& instance) {
53 // TODO(b/34274385) remove this
Steven Moreland51fbeaa2017-01-30 16:22:06 -080054
55 size_t loc = interface.find_first_of("@");
56 if (loc == std::string::npos) {
57 LOG_ALWAYS_FATAL("Bad interface name: %s", interface.c_str());
58 }
59 std::string package = interface.substr(0, loc);
60
61 // only block if this is supposed to be toggled
Yifan Hong37b36202017-02-28 16:04:22 -080062 if (getTransport(interface, instance) != vintf::Transport::TOGGLED) {
Steven Moreland51fbeaa2017-01-30 16:22:06 -080063 return;
64 }
65
Steven Moreland3903f462017-01-13 12:57:00 -080066 // Must wait for data to be mounted and persistant properties to be read,
67 // but only delay the start of hals which require reading this property.
68 bool enabled = blockingHalBinderizationEnabled();
69
70 if (!enabled) {
71 ALOGI("Deactivating %s/%s binderized service to"
72 " yield to passthrough implementation.",
73 interface.c_str(),
74 instance.c_str());
75 while (true) {
76 sleep(UINT_MAX);
77 }
78 }
79}
80} // namespace details
81
82} // namespace hardware
83} // namespace android