blob: d0871f6f3ee46807e22725c0c6df71609d10bc4f [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 */
16#include <hidl/HidlTransportSupport.h>
Steven Moreland11a732a2017-03-07 17:44:17 -080017#include <hidl/HidlBinderSupport.h>
18
Yifan Honga8b6eab2017-11-22 22:15:39 -080019#include <android/hidl/manager/1.0/IServiceManager.h>
20
Steven Moreland11a732a2017-03-07 17:44:17 -080021namespace android {
22namespace hardware {
23
24void configureRpcThreadpool(size_t maxThreads, bool callerWillJoin) {
25 // TODO(b/32756130) this should be transport-dependent
26 configureBinderRpcThreadpool(maxThreads, callerWillJoin);
27}
28void joinRpcThreadpool() {
29 // TODO(b/32756130) this should be transport-dependent
30 joinBinderRpcThreadpool();
31}
32
Martijn Coenen3f5ac4c2017-11-27 15:09:28 -080033int setupTransportPolling() {
34 return setupBinderPolling();
35}
36
37status_t handleTransportPoll(int /*fd*/) {
38 return handleBinderPoll();
39}
40
Martijn Coenen81ef4da2017-04-21 16:21:31 -070041bool setMinSchedulerPolicy(const sp<::android::hidl::base::V1_0::IBase>& service,
42 int policy, int priority) {
43 if (service->isRemote()) {
44 ALOGE("Can't set scheduler policy on remote service.");
45 return false;
46 }
47
48 if (policy != SCHED_NORMAL && policy != SCHED_FIFO && policy != SCHED_RR) {
49 ALOGE("Invalid scheduler policy %d", policy);
50 return false;
51 }
52
53 if (policy == SCHED_NORMAL && (priority < -20 || priority > 19)) {
54 ALOGE("Invalid priority for SCHED_NORMAL: %d", priority);
55 return false;
56 } else if (priority < 1 || priority > 99) {
57 ALOGE("Invalid priority for real-time policy: %d", priority);
58 return false;
59 }
60
61 details::gServicePrioMap.set(service, { policy, priority });
62
63 return true;
Steven Moreland11a732a2017-03-07 17:44:17 -080064}
Martijn Coenen81ef4da2017-04-21 16:21:31 -070065
Yifan Hong7a4b7562017-11-20 11:36:51 -080066namespace details {
67int32_t getPidIfSharable() {
68#if LIBHIDL_TARGET_DEBUGGABLE
69 return getpid();
70#else
71 using android::hidl::manager::V1_0::IServiceManager;
Yifan Honga8b6eab2017-11-22 22:15:39 -080072 return static_cast<int32_t>(IServiceManager::PidConstant::NO_PID);
Yifan Hong7a4b7562017-11-20 11:36:51 -080073#endif
74}
75} // namespace details
76
Steven Morelanda15479f2017-10-06 16:06:26 -070077} // namespace hardware
78} // namespace android