blob: 1df6c383e1ba1d42c1aba207401a31548f75340b [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 Coenen81ef4da2017-04-21 16:21:31 -070033bool setMinSchedulerPolicy(const sp<::android::hidl::base::V1_0::IBase>& service,
34 int policy, int priority) {
35 if (service->isRemote()) {
36 ALOGE("Can't set scheduler policy on remote service.");
37 return false;
38 }
39
40 if (policy != SCHED_NORMAL && policy != SCHED_FIFO && policy != SCHED_RR) {
41 ALOGE("Invalid scheduler policy %d", policy);
42 return false;
43 }
44
45 if (policy == SCHED_NORMAL && (priority < -20 || priority > 19)) {
46 ALOGE("Invalid priority for SCHED_NORMAL: %d", priority);
47 return false;
48 } else if (priority < 1 || priority > 99) {
49 ALOGE("Invalid priority for real-time policy: %d", priority);
50 return false;
51 }
52
53 details::gServicePrioMap.set(service, { policy, priority });
54
55 return true;
Steven Moreland11a732a2017-03-07 17:44:17 -080056}
Martijn Coenen81ef4da2017-04-21 16:21:31 -070057
Yifan Hong7a4b7562017-11-20 11:36:51 -080058namespace details {
59int32_t getPidIfSharable() {
60#if LIBHIDL_TARGET_DEBUGGABLE
61 return getpid();
62#else
63 using android::hidl::manager::V1_0::IServiceManager;
Yifan Honga8b6eab2017-11-22 22:15:39 -080064 return static_cast<int32_t>(IServiceManager::PidConstant::NO_PID);
Yifan Hong7a4b7562017-11-20 11:36:51 -080065#endif
66}
67} // namespace details
68
Steven Morelanda15479f2017-10-06 16:06:26 -070069} // namespace hardware
70} // namespace android