blob: b214f1a041ef49fa51cb34d6f8d476f1c3b19c97 [file] [log] [blame]
Steven Moreland11a732a2017-03-07 17:44:17 -08001/*
2 * Copyright (C) 2017 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 */
Steven Moreland11a732a2017-03-07 17:44:17 -080016#include <hidl/HidlBinderSupport.h>
Steven Moreland128040a2018-07-31 15:29:53 -070017#include <hidl/HidlTransportSupport.h>
18#include <hidl/Static.h>
Steven Moreland11a732a2017-03-07 17:44:17 -080019
Steven Moreland128040a2018-07-31 15:29:53 -070020#include <android-base/logging.h>
Yifan Honga8b6eab2017-11-22 22:15:39 -080021#include <android/hidl/manager/1.0/IServiceManager.h>
22
Steven Moreland11a732a2017-03-07 17:44:17 -080023namespace android {
24namespace hardware {
25
26void configureRpcThreadpool(size_t maxThreads, bool callerWillJoin) {
27 // TODO(b/32756130) this should be transport-dependent
28 configureBinderRpcThreadpool(maxThreads, callerWillJoin);
29}
30void joinRpcThreadpool() {
31 // TODO(b/32756130) this should be transport-dependent
32 joinBinderRpcThreadpool();
33}
34
Martijn Coenen3f5ac4c2017-11-27 15:09:28 -080035int setupTransportPolling() {
36 return setupBinderPolling();
37}
38
39status_t handleTransportPoll(int /*fd*/) {
40 return handleBinderPoll();
41}
42
Martijn Coenen81ef4da2017-04-21 16:21:31 -070043bool setMinSchedulerPolicy(const sp<::android::hidl::base::V1_0::IBase>& service,
44 int policy, int priority) {
45 if (service->isRemote()) {
Steven Moreland128040a2018-07-31 15:29:53 -070046 LOG(ERROR) << "Can't set scheduler policy on remote service.";
Martijn Coenen81ef4da2017-04-21 16:21:31 -070047 return false;
48 }
49
50 if (policy != SCHED_NORMAL && policy != SCHED_FIFO && policy != SCHED_RR) {
Steven Moreland128040a2018-07-31 15:29:53 -070051 LOG(ERROR) << "Invalid scheduler policy " << policy;
Martijn Coenen81ef4da2017-04-21 16:21:31 -070052 return false;
53 }
54
55 if (policy == SCHED_NORMAL && (priority < -20 || priority > 19)) {
Steven Moreland128040a2018-07-31 15:29:53 -070056 LOG(ERROR) << "Invalid priority for SCHED_NORMAL: " << priority;
Martijn Coenen81ef4da2017-04-21 16:21:31 -070057 return false;
58 } else if (priority < 1 || priority > 99) {
Steven Moreland128040a2018-07-31 15:29:53 -070059 LOG(ERROR) << "Invalid priority for real-time policy: " << priority;
Martijn Coenen81ef4da2017-04-21 16:21:31 -070060 return false;
61 }
62
Steven Moreland49ccc382018-07-24 12:18:36 -070063 // Due to ABI considerations, IBase cannot have a destructor to clean this up.
64 // So, because this API is so infrequently used, (expected to be usually only
65 // one time for a process, but it can be more), we are cleaning it up here.
66 // TODO(b/37794345): if ever we update the HIDL ABI for launches in an Android
67 // release in the meta-version sense, we should remove this.
68 std::unique_lock<std::mutex> lock = details::gServicePrioMap.lock();
69
70 std::vector<wp<::android::hidl::base::V1_0::IBase>> toDelete;
71 for (const auto& kv : details::gServicePrioMap) {
72 if (kv.first.promote() == nullptr) {
73 toDelete.push_back(kv.first);
74 }
75 }
76 for (const auto& k : toDelete) {
77 details::gServicePrioMap.eraseLocked(k);
78 }
79 details::gServicePrioMap.setLocked(service, {policy, priority});
Martijn Coenen81ef4da2017-04-21 16:21:31 -070080
81 return true;
Steven Moreland11a732a2017-03-07 17:44:17 -080082}
Martijn Coenen81ef4da2017-04-21 16:21:31 -070083
Yifan Hong7a4b7562017-11-20 11:36:51 -080084namespace details {
85int32_t getPidIfSharable() {
86#if LIBHIDL_TARGET_DEBUGGABLE
87 return getpid();
88#else
89 using android::hidl::manager::V1_0::IServiceManager;
Yifan Honga8b6eab2017-11-22 22:15:39 -080090 return static_cast<int32_t>(IServiceManager::PidConstant::NO_PID);
Yifan Hong7a4b7562017-11-20 11:36:51 -080091#endif
92}
93} // namespace details
94
Steven Morelanda15479f2017-10-06 16:06:26 -070095} // namespace hardware
96} // namespace android