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 namespace android {
20 namespace hardware {
21 
configureRpcThreadpool(size_t maxThreads,bool callerWillJoin)22 void configureRpcThreadpool(size_t maxThreads, bool callerWillJoin) {
23     // TODO(b/32756130) this should be transport-dependent
24     configureBinderRpcThreadpool(maxThreads, callerWillJoin);
25 }
joinRpcThreadpool()26 void joinRpcThreadpool() {
27     // TODO(b/32756130) this should be transport-dependent
28     joinBinderRpcThreadpool();
29 }
30 
setMinSchedulerPolicy(const sp<::android::hidl::base::V1_0::IBase> & service,int policy,int priority)31 bool setMinSchedulerPolicy(const sp<::android::hidl::base::V1_0::IBase>& service,
32                            int policy, int priority) {
33     if (service->isRemote()) {
34         ALOGE("Can't set scheduler policy on remote service.");
35         return false;
36     }
37 
38     if (policy != SCHED_NORMAL && policy != SCHED_FIFO && policy != SCHED_RR) {
39         ALOGE("Invalid scheduler policy %d", policy);
40         return false;
41     }
42 
43     if (policy == SCHED_NORMAL && (priority < -20 || priority > 19)) {
44         ALOGE("Invalid priority for SCHED_NORMAL: %d", priority);
45         return false;
46     } else if (priority < 1 || priority > 99) {
47         ALOGE("Invalid priority for real-time policy: %d", priority);
48         return false;
49     }
50 
51     details::gServicePrioMap.set(service, { policy, priority });
52 
53     return true;
54 }
55 
56 }
57 }
58