1236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland/*
2236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland * Copyright (C) 2017 The Android Open Source Project
3236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland *
4236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland * Licensed under the Apache License, Version 2.0 (the "License");
5236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland * you may not use this file except in compliance with the License.
6236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland * You may obtain a copy of the License at
7236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland *
8236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland *      http://www.apache.org/licenses/LICENSE-2.0
9236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland *
10236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland * Unless required by applicable law or agreed to in writing, software
11236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland * distributed under the License is distributed on an "AS IS" BASIS,
12236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland * See the License for the specific language governing permissions and
14236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland * limitations under the License.
15236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland */
16236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland#define LOG_TAG "schedulerservicehidl"
17236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland
18236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland#include "SchedulingPolicyService.h"
19236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland
20236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland#include <log/log.h>
21236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland#include <hwbinder/IPCThreadState.h>
22236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland#include <mediautils/SchedulingPolicyService.h>
23236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland
24236461444e6a29de42ab3d49e3308fd75306cd9dSteven Morelandnamespace android {
25236461444e6a29de42ab3d49e3308fd75306cd9dSteven Morelandnamespace frameworks {
26236461444e6a29de42ab3d49e3308fd75306cd9dSteven Morelandnamespace schedulerservice {
27236461444e6a29de42ab3d49e3308fd75306cd9dSteven Morelandnamespace V1_0 {
28236461444e6a29de42ab3d49e3308fd75306cd9dSteven Morelandnamespace implementation {
29236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland
303ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Morelandbool SchedulingPolicyService::isAllowed() {
3176dc595d2a268792900663dac756c691374bae85Peng Xu    // TODO(b/37291237)
3276dc595d2a268792900663dac756c691374bae85Peng Xu    return true;
333ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland}
343ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland
353ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven MorelandReturn<bool> SchedulingPolicyService::requestPriority(int32_t pid, int32_t tid, int32_t priority) {
36236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland    if (priority < static_cast<int32_t>(Priority::MIN) ||
37236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland            priority > static_cast<int32_t>(Priority::MAX)) {
38236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland        return false;
39236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland    }
40236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland
413ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland    if (!isAllowed()) {
42236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland        return false;
43236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland    }
44236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland
453ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland    // TODO(b/37226359): decouple from and remove AIDL service
46236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland    // this should always be allowed since we are in system_server.
47236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland    int value = ::android::requestPriority(pid, tid, priority, false /* isForApp */);
48236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland    return value == 0 /* success */;
49236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland}
50236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland
513ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven MorelandReturn<int32_t> SchedulingPolicyService::getMaxAllowedPriority() {
523ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland    if (!isAllowed()) {
533ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland        return 0;
543ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland    }
553ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland
563ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland    // TODO(b/37226359): decouple from and remove AIDL service
573ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland    return 3;
583ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland}
593ac757658dd8dc81f3b18ad1e8788640a1f2183bSteven Moreland
60236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland}  // namespace implementation
61236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland}  // namespace V1_0
62236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland}  // namespace schedulerservice
63236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland}  // namespace frameworks
64236461444e6a29de42ab3d49e3308fd75306cd9dSteven Moreland}  // namespace android
65