blob: a1106cf49b4021aafe5b8da60c160a95fba80708 [file] [log] [blame]
Steven Moreland23646142017-04-07 10:46:25 -07001/*
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 Xu0b067c62017-09-20 18:59:12 -070020#include <private/android_filesystem_config.h> // for AID_CAMERASERVER
21
Steven Moreland23646142017-04-07 10:46:25 -070022#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
Steven Moreland3ac75762017-04-10 22:09:03 -070032bool SchedulingPolicyService::isAllowed() {
Peng Xu0b067c62017-09-20 18:59:12 -070033 using ::android::hardware::IPCThreadState;
34
35 return IPCThreadState::self()->getCallingUid() == AID_CAMERASERVER;
Steven Moreland3ac75762017-04-10 22:09:03 -070036}
37
38Return<bool> SchedulingPolicyService::requestPriority(int32_t pid, int32_t tid, int32_t priority) {
Steven Moreland23646142017-04-07 10:46:25 -070039 if (priority < static_cast<int32_t>(Priority::MIN) ||
40 priority > static_cast<int32_t>(Priority::MAX)) {
41 return false;
42 }
43
Steven Moreland3ac75762017-04-10 22:09:03 -070044 if (!isAllowed()) {
Steven Moreland23646142017-04-07 10:46:25 -070045 return false;
46 }
47
Steven Moreland3ac75762017-04-10 22:09:03 -070048 // TODO(b/37226359): decouple from and remove AIDL service
Steven Moreland23646142017-04-07 10:46:25 -070049 // 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 Moreland3ac75762017-04-10 22:09:03 -070054Return<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 Moreland23646142017-04-07 10:46:25 -070063} // namespace implementation
64} // namespace V1_0
65} // namespace schedulerservice
66} // namespace frameworks
67} // namespace android