1 /*
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>
17 #include <hidl/HidlBinderSupport.h>
18 
19 #include <android/hidl/manager/1.0/IServiceManager.h>
20 
21 namespace android {
22 namespace hardware {
23 
configureRpcThreadpool(size_t maxThreads,bool callerWillJoin)24 void configureRpcThreadpool(size_t maxThreads, bool callerWillJoin) {
25     // TODO(b/32756130) this should be transport-dependent
26     configureBinderRpcThreadpool(maxThreads, callerWillJoin);
27 }
joinRpcThreadpool()28 void joinRpcThreadpool() {
29     // TODO(b/32756130) this should be transport-dependent
30     joinBinderRpcThreadpool();
31 }
32 
setupTransportPolling()33 int setupTransportPolling() {
34     return setupBinderPolling();
35 }
36 
handleTransportPoll(int)37 status_t handleTransportPoll(int /*fd*/) {
38     return handleBinderPoll();
39 }
40 
setMinSchedulerPolicy(const sp<::android::hidl::base::V1_0::IBase> & service,int policy,int priority)41 bool 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;
64 }
65 
66 namespace details {
getPidIfSharable()67 int32_t getPidIfSharable() {
68 #if LIBHIDL_TARGET_DEBUGGABLE
69     return getpid();
70 #else
71     using android::hidl::manager::V1_0::IServiceManager;
72     return static_cast<int32_t>(IServiceManager::PidConstant::NO_PID);
73 #endif
74 }
75 }  // namespace details
76 
77 }  // namespace hardware
78 }  // namespace android
79