Steven Moreland | 2364614 | 2017-04-07 10:46:25 -0700 | [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 | */ |
| 16 | #define LOG_TAG "schedulerservicehidl" |
| 17 | |
| 18 | #include "SchedulingPolicyService.h" |
| 19 | |
Peng Xu | 0b067c6 | 2017-09-20 18:59:12 -0700 | [diff] [blame^] | 20 | #include <private/android_filesystem_config.h> // for AID_CAMERASERVER |
| 21 | |
Steven Moreland | 2364614 | 2017-04-07 10:46:25 -0700 | [diff] [blame] | 22 | #include <log/log.h> |
| 23 | #include <hwbinder/IPCThreadState.h> |
| 24 | #include <mediautils/SchedulingPolicyService.h> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace frameworks { |
| 28 | namespace schedulerservice { |
| 29 | namespace V1_0 { |
| 30 | namespace implementation { |
| 31 | |
Steven Moreland | 3ac7576 | 2017-04-10 22:09:03 -0700 | [diff] [blame] | 32 | bool SchedulingPolicyService::isAllowed() { |
Peng Xu | 0b067c6 | 2017-09-20 18:59:12 -0700 | [diff] [blame^] | 33 | using ::android::hardware::IPCThreadState; |
| 34 | |
| 35 | return IPCThreadState::self()->getCallingUid() == AID_CAMERASERVER; |
Steven Moreland | 3ac7576 | 2017-04-10 22:09:03 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | Return<bool> SchedulingPolicyService::requestPriority(int32_t pid, int32_t tid, int32_t priority) { |
Steven Moreland | 2364614 | 2017-04-07 10:46:25 -0700 | [diff] [blame] | 39 | if (priority < static_cast<int32_t>(Priority::MIN) || |
| 40 | priority > static_cast<int32_t>(Priority::MAX)) { |
| 41 | return false; |
| 42 | } |
| 43 | |
Steven Moreland | 3ac7576 | 2017-04-10 22:09:03 -0700 | [diff] [blame] | 44 | if (!isAllowed()) { |
Steven Moreland | 2364614 | 2017-04-07 10:46:25 -0700 | [diff] [blame] | 45 | return false; |
| 46 | } |
| 47 | |
Steven Moreland | 3ac7576 | 2017-04-10 22:09:03 -0700 | [diff] [blame] | 48 | // TODO(b/37226359): decouple from and remove AIDL service |
Steven Moreland | 2364614 | 2017-04-07 10:46:25 -0700 | [diff] [blame] | 49 | // this should always be allowed since we are in system_server. |
| 50 | int value = ::android::requestPriority(pid, tid, priority, false /* isForApp */); |
| 51 | return value == 0 /* success */; |
| 52 | } |
| 53 | |
Steven Moreland | 3ac7576 | 2017-04-10 22:09:03 -0700 | [diff] [blame] | 54 | Return<int32_t> SchedulingPolicyService::getMaxAllowedPriority() { |
| 55 | if (!isAllowed()) { |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | // TODO(b/37226359): decouple from and remove AIDL service |
| 60 | return 3; |
| 61 | } |
| 62 | |
Steven Moreland | 2364614 | 2017-04-07 10:46:25 -0700 | [diff] [blame] | 63 | } // namespace implementation |
| 64 | } // namespace V1_0 |
| 65 | } // namespace schedulerservice |
| 66 | } // namespace frameworks |
| 67 | } // namespace android |