1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker *
4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker *
8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker *
10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker */
16*38e8c45fSAndroid Build Coastguard Worker #define LOG_TAG "schedulerservicehidl"
17*38e8c45fSAndroid Build Coastguard Worker
18*38e8c45fSAndroid Build Coastguard Worker #include "SchedulingPolicyService.h"
19*38e8c45fSAndroid Build Coastguard Worker
20*38e8c45fSAndroid Build Coastguard Worker #include <private/android_filesystem_config.h> // for AID_CAMERASERVER
21*38e8c45fSAndroid Build Coastguard Worker
22*38e8c45fSAndroid Build Coastguard Worker #include <log/log.h>
23*38e8c45fSAndroid Build Coastguard Worker #include <hwbinder/IPCThreadState.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <mediautils/SchedulingPolicyService.h>
25*38e8c45fSAndroid Build Coastguard Worker
26*38e8c45fSAndroid Build Coastguard Worker namespace android {
27*38e8c45fSAndroid Build Coastguard Worker namespace frameworks {
28*38e8c45fSAndroid Build Coastguard Worker namespace schedulerservice {
29*38e8c45fSAndroid Build Coastguard Worker namespace V1_0 {
30*38e8c45fSAndroid Build Coastguard Worker namespace implementation {
31*38e8c45fSAndroid Build Coastguard Worker
isAllowed()32*38e8c45fSAndroid Build Coastguard Worker bool SchedulingPolicyService::isAllowed() {
33*38e8c45fSAndroid Build Coastguard Worker using ::android::hardware::IPCThreadState;
34*38e8c45fSAndroid Build Coastguard Worker
35*38e8c45fSAndroid Build Coastguard Worker return IPCThreadState::self()->getCallingUid() == AID_CAMERASERVER;
36*38e8c45fSAndroid Build Coastguard Worker }
37*38e8c45fSAndroid Build Coastguard Worker
requestPriority(int32_t pid,int32_t tid,int32_t priority)38*38e8c45fSAndroid Build Coastguard Worker Return<bool> SchedulingPolicyService::requestPriority(int32_t pid, int32_t tid, int32_t priority) {
39*38e8c45fSAndroid Build Coastguard Worker if (priority < static_cast<int32_t>(Priority::MIN) ||
40*38e8c45fSAndroid Build Coastguard Worker priority > static_cast<int32_t>(Priority::MAX)) {
41*38e8c45fSAndroid Build Coastguard Worker return false;
42*38e8c45fSAndroid Build Coastguard Worker }
43*38e8c45fSAndroid Build Coastguard Worker
44*38e8c45fSAndroid Build Coastguard Worker if (!isAllowed()) {
45*38e8c45fSAndroid Build Coastguard Worker return false;
46*38e8c45fSAndroid Build Coastguard Worker }
47*38e8c45fSAndroid Build Coastguard Worker
48*38e8c45fSAndroid Build Coastguard Worker // TODO(b/37226359): decouple from and remove AIDL service
49*38e8c45fSAndroid Build Coastguard Worker // this should always be allowed since we are in system_server.
50*38e8c45fSAndroid Build Coastguard Worker int value = ::android::requestPriority(pid, tid, priority, false /* isForApp */);
51*38e8c45fSAndroid Build Coastguard Worker return value == 0 /* success */;
52*38e8c45fSAndroid Build Coastguard Worker }
53*38e8c45fSAndroid Build Coastguard Worker
getMaxAllowedPriority()54*38e8c45fSAndroid Build Coastguard Worker Return<int32_t> SchedulingPolicyService::getMaxAllowedPriority() {
55*38e8c45fSAndroid Build Coastguard Worker if (!isAllowed()) {
56*38e8c45fSAndroid Build Coastguard Worker return 0;
57*38e8c45fSAndroid Build Coastguard Worker }
58*38e8c45fSAndroid Build Coastguard Worker
59*38e8c45fSAndroid Build Coastguard Worker // TODO(b/37226359): decouple from and remove AIDL service
60*38e8c45fSAndroid Build Coastguard Worker return 3;
61*38e8c45fSAndroid Build Coastguard Worker }
62*38e8c45fSAndroid Build Coastguard Worker
63*38e8c45fSAndroid Build Coastguard Worker } // namespace implementation
64*38e8c45fSAndroid Build Coastguard Worker } // namespace V1_0
65*38e8c45fSAndroid Build Coastguard Worker } // namespace schedulerservice
66*38e8c45fSAndroid Build Coastguard Worker } // namespace frameworks
67*38e8c45fSAndroid Build Coastguard Worker } // namespace android
68