SchedulingPolicyService.cpp revision 3ac757658dd8dc81f3b18ad1e8788640a1f2183b
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 20#include <private/android_filesystem_config.h> // for AID_CAMERASERVER 21 22#include <log/log.h> 23#include <hwbinder/IPCThreadState.h> 24#include <mediautils/SchedulingPolicyService.h> 25 26namespace android { 27namespace frameworks { 28namespace schedulerservice { 29namespace V1_0 { 30namespace implementation { 31 32bool SchedulingPolicyService::isAllowed() { 33 using ::android::hardware::IPCThreadState; 34 35 return IPCThreadState::self()->getCallingUid() == AID_CAMERASERVER; 36} 37 38Return<bool> SchedulingPolicyService::requestPriority(int32_t pid, int32_t tid, int32_t priority) { 39 if (priority < static_cast<int32_t>(Priority::MIN) || 40 priority > static_cast<int32_t>(Priority::MAX)) { 41 return false; 42 } 43 44 if (!isAllowed()) { 45 return false; 46 } 47 48 // TODO(b/37226359): decouple from and remove AIDL service 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 54Return<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 63} // namespace implementation 64} // namespace V1_0 65} // namespace schedulerservice 66} // namespace frameworks 67} // namespace android 68