Steven Moreland | 11a732a | 2017-03-07 17:44:17 -0800 | [diff] [blame] | 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 | */ |
Steven Moreland | 9211951 | 2018-08-08 20:01:21 +0000 | [diff] [blame] | 16 | #include <hidl/HidlBinderSupport.h> |
Steven Moreland | b917318 | 2018-08-08 20:06:08 +0000 | [diff] [blame] | 17 | #include <hidl/HidlTransportSupport.h> |
| 18 | #include <hidl/Static.h> |
Steven Moreland | 11a732a | 2017-03-07 17:44:17 -0800 | [diff] [blame] | 19 | |
Steven Moreland | b917318 | 2018-08-08 20:06:08 +0000 | [diff] [blame] | 20 | #include <android-base/logging.h> |
Yifan Hong | a8b6eab | 2017-11-22 22:15:39 -0800 | [diff] [blame] | 21 | #include <android/hidl/manager/1.0/IServiceManager.h> |
| 22 | |
Steven Moreland | 11a732a | 2017-03-07 17:44:17 -0800 | [diff] [blame] | 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | |
| 26 | void configureRpcThreadpool(size_t maxThreads, bool callerWillJoin) { |
| 27 | // TODO(b/32756130) this should be transport-dependent |
| 28 | configureBinderRpcThreadpool(maxThreads, callerWillJoin); |
| 29 | } |
| 30 | void joinRpcThreadpool() { |
| 31 | // TODO(b/32756130) this should be transport-dependent |
| 32 | joinBinderRpcThreadpool(); |
| 33 | } |
| 34 | |
Martijn Coenen | 3f5ac4c | 2017-11-27 15:09:28 -0800 | [diff] [blame] | 35 | int setupTransportPolling() { |
| 36 | return setupBinderPolling(); |
| 37 | } |
| 38 | |
| 39 | status_t handleTransportPoll(int /*fd*/) { |
| 40 | return handleBinderPoll(); |
| 41 | } |
| 42 | |
Martijn Coenen | 81ef4da | 2017-04-21 16:21:31 -0700 | [diff] [blame] | 43 | bool setMinSchedulerPolicy(const sp<::android::hidl::base::V1_0::IBase>& service, |
| 44 | int policy, int priority) { |
| 45 | if (service->isRemote()) { |
Steven Moreland | b917318 | 2018-08-08 20:06:08 +0000 | [diff] [blame] | 46 | LOG(ERROR) << "Can't set scheduler policy on remote service."; |
Martijn Coenen | 81ef4da | 2017-04-21 16:21:31 -0700 | [diff] [blame] | 47 | return false; |
| 48 | } |
| 49 | |
Steven Moreland | b7798be | 2018-09-19 13:17:37 -0700 | [diff] [blame] | 50 | switch (policy) { |
| 51 | case SCHED_NORMAL: { |
| 52 | if (priority < -20 || priority > 19) { |
| 53 | LOG(ERROR) << "Invalid priority for SCHED_NORMAL: " << priority; |
| 54 | return false; |
| 55 | } |
| 56 | } break; |
| 57 | case SCHED_RR: |
| 58 | case SCHED_FIFO: { |
| 59 | if (priority < 1 || priority > 99) { |
| 60 | LOG(ERROR) << "Invalid priority for " << policy << " policy: " << priority; |
| 61 | return false; |
| 62 | } |
| 63 | } break; |
| 64 | default: { |
| 65 | LOG(ERROR) << "Invalid scheduler policy " << policy; |
| 66 | return false; |
| 67 | } |
Martijn Coenen | 81ef4da | 2017-04-21 16:21:31 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Steven Moreland | 49ccc38 | 2018-07-24 12:18:36 -0700 | [diff] [blame] | 70 | // Due to ABI considerations, IBase cannot have a destructor to clean this up. |
| 71 | // So, because this API is so infrequently used, (expected to be usually only |
| 72 | // one time for a process, but it can be more), we are cleaning it up here. |
| 73 | // TODO(b/37794345): if ever we update the HIDL ABI for launches in an Android |
| 74 | // release in the meta-version sense, we should remove this. |
| 75 | std::unique_lock<std::mutex> lock = details::gServicePrioMap.lock(); |
| 76 | |
| 77 | std::vector<wp<::android::hidl::base::V1_0::IBase>> toDelete; |
| 78 | for (const auto& kv : details::gServicePrioMap) { |
| 79 | if (kv.first.promote() == nullptr) { |
| 80 | toDelete.push_back(kv.first); |
| 81 | } |
| 82 | } |
| 83 | for (const auto& k : toDelete) { |
| 84 | details::gServicePrioMap.eraseLocked(k); |
| 85 | } |
| 86 | details::gServicePrioMap.setLocked(service, {policy, priority}); |
Martijn Coenen | 81ef4da | 2017-04-21 16:21:31 -0700 | [diff] [blame] | 87 | |
| 88 | return true; |
Steven Moreland | 11a732a | 2017-03-07 17:44:17 -0800 | [diff] [blame] | 89 | } |
Martijn Coenen | 81ef4da | 2017-04-21 16:21:31 -0700 | [diff] [blame] | 90 | |
Yifan Hong | 7a4b756 | 2017-11-20 11:36:51 -0800 | [diff] [blame] | 91 | namespace details { |
| 92 | int32_t getPidIfSharable() { |
| 93 | #if LIBHIDL_TARGET_DEBUGGABLE |
| 94 | return getpid(); |
| 95 | #else |
| 96 | using android::hidl::manager::V1_0::IServiceManager; |
Yifan Hong | a8b6eab | 2017-11-22 22:15:39 -0800 | [diff] [blame] | 97 | return static_cast<int32_t>(IServiceManager::PidConstant::NO_PID); |
Yifan Hong | 7a4b756 | 2017-11-20 11:36:51 -0800 | [diff] [blame] | 98 | #endif |
| 99 | } |
| 100 | } // namespace details |
| 101 | |
Steven Moreland | a15479f | 2017-10-06 16:06:26 -0700 | [diff] [blame] | 102 | } // namespace hardware |
| 103 | } // namespace android |