blob: 9c2bf25b3eaa10a338c1f87a11794916c9bd1948 [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 Moreland128040a2018-07-31 15:29:53 -070016#include <hidl/HidlTransportSupport.h>
Steven Moreland92119512018-08-08 20:01:21 +000017#include <hidl/HidlBinderSupport.h>
Steven Moreland11a732a2017-03-07 17:44:17 -080018
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()) {
Steven Moreland92119512018-08-08 20:01:21 +000044 ALOGE("Can't set scheduler policy on remote service.");
Martijn Coenen81ef4da2017-04-21 16:21:31 -070045 return false;
46 }
47
48 if (policy != SCHED_NORMAL && policy != SCHED_FIFO && policy != SCHED_RR) {
Steven Moreland92119512018-08-08 20:01:21 +000049 ALOGE("Invalid scheduler policy %d", policy);
Martijn Coenen81ef4da2017-04-21 16:21:31 -070050 return false;
51 }
52
53 if (policy == SCHED_NORMAL && (priority < -20 || priority > 19)) {
Steven Moreland92119512018-08-08 20:01:21 +000054 ALOGE("Invalid priority for SCHED_NORMAL: %d", priority);
Martijn Coenen81ef4da2017-04-21 16:21:31 -070055 return false;
56 } else if (priority < 1 || priority > 99) {
Steven Moreland92119512018-08-08 20:01:21 +000057 ALOGE("Invalid priority for real-time policy: %d", priority);
Martijn Coenen81ef4da2017-04-21 16:21:31 -070058 return false;
59 }
60
Steven Moreland49ccc382018-07-24 12:18:36 -070061 // Due to ABI considerations, IBase cannot have a destructor to clean this up.
62 // So, because this API is so infrequently used, (expected to be usually only
63 // one time for a process, but it can be more), we are cleaning it up here.
64 // TODO(b/37794345): if ever we update the HIDL ABI for launches in an Android
65 // release in the meta-version sense, we should remove this.
66 std::unique_lock<std::mutex> lock = details::gServicePrioMap.lock();
67
68 std::vector<wp<::android::hidl::base::V1_0::IBase>> toDelete;
69 for (const auto& kv : details::gServicePrioMap) {
70 if (kv.first.promote() == nullptr) {
71 toDelete.push_back(kv.first);
72 }
73 }
74 for (const auto& k : toDelete) {
75 details::gServicePrioMap.eraseLocked(k);
76 }
77 details::gServicePrioMap.setLocked(service, {policy, priority});
Martijn Coenen81ef4da2017-04-21 16:21:31 -070078
79 return true;
Steven Moreland11a732a2017-03-07 17:44:17 -080080}
Martijn Coenen81ef4da2017-04-21 16:21:31 -070081
Yifan Hong7a4b7562017-11-20 11:36:51 -080082namespace details {
83int32_t getPidIfSharable() {
84#if LIBHIDL_TARGET_DEBUGGABLE
85 return getpid();
86#else
87 using android::hidl::manager::V1_0::IServiceManager;
Yifan Honga8b6eab2017-11-22 22:15:39 -080088 return static_cast<int32_t>(IServiceManager::PidConstant::NO_PID);
Yifan Hong7a4b7562017-11-20 11:36:51 -080089#endif
90}
91} // namespace details
92
Steven Morelanda15479f2017-10-06 16:06:26 -070093} // namespace hardware
94} // namespace android