Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Eric Laurent | f59a4b3 | 2013-07-02 11:15:41 -0700 | [diff] [blame] | 17 | #define LOG_TAG "ISchedulingPolicyService" |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <binder/Parcel.h> |
| 21 | #include "ISchedulingPolicyService.h" |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | // Keep in sync with frameworks/base/core/java/android/os/ISchedulingPolicyService.aidl |
| 26 | enum { |
| 27 | REQUEST_PRIORITY_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 28 | REQUEST_CPUSET_BOOST, |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | // ---------------------------------------------------------------------- |
| 32 | |
| 33 | class BpSchedulingPolicyService : public BpInterface<ISchedulingPolicyService> |
| 34 | { |
| 35 | public: |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 36 | explicit BpSchedulingPolicyService(const sp<IBinder>& impl) |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 37 | : BpInterface<ISchedulingPolicyService>(impl) |
| 38 | { |
| 39 | } |
| 40 | |
Mikhail Naganov | 83f0427 | 2017-02-07 10:45:09 -0800 | [diff] [blame] | 41 | virtual int requestPriority(int32_t pid, int32_t tid, |
| 42 | int32_t prio, bool isForApp, bool asynchronous) |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 43 | { |
| 44 | Parcel data, reply; |
| 45 | data.writeInterfaceToken(ISchedulingPolicyService::getInterfaceDescriptor()); |
| 46 | data.writeInt32(pid); |
| 47 | data.writeInt32(tid); |
| 48 | data.writeInt32(prio); |
Mikhail Naganov | 83f0427 | 2017-02-07 10:45:09 -0800 | [diff] [blame] | 49 | data.writeBool(isForApp); |
Glenn Kasten | f8197a6 | 2013-04-23 12:39:37 -0700 | [diff] [blame] | 50 | uint32_t flags = asynchronous ? IBinder::FLAG_ONEWAY : 0; |
Eric Laurent | f59a4b3 | 2013-07-02 11:15:41 -0700 | [diff] [blame] | 51 | status_t status = remote()->transact(REQUEST_PRIORITY_TRANSACTION, data, &reply, flags); |
| 52 | if (status != NO_ERROR) { |
| 53 | return status; |
| 54 | } |
| 55 | if (asynchronous) { |
| 56 | return NO_ERROR; |
| 57 | } |
| 58 | // fail on exception: force binder reconnection |
| 59 | if (reply.readExceptionCode() != 0) { |
| 60 | return DEAD_OBJECT; |
| 61 | } |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 62 | return reply.readInt32(); |
| 63 | } |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 64 | |
| 65 | virtual int requestCpusetBoost(bool enable, const sp<IInterface>& client) |
| 66 | { |
| 67 | Parcel data, reply; |
| 68 | data.writeInterfaceToken(ISchedulingPolicyService::getInterfaceDescriptor()); |
| 69 | data.writeInt32(enable); |
| 70 | data.writeStrongBinder(IInterface::asBinder(client)); |
| 71 | status_t status = remote()->transact(REQUEST_CPUSET_BOOST, data, &reply, 0); |
| 72 | if (status != NO_ERROR) { |
| 73 | return status; |
| 74 | } |
| 75 | // fail on exception: force binder reconnection |
| 76 | if (reply.readExceptionCode() != 0) { |
| 77 | return DEAD_OBJECT; |
| 78 | } |
| 79 | return reply.readInt32(); |
| 80 | } |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | IMPLEMENT_META_INTERFACE(SchedulingPolicyService, "android.os.ISchedulingPolicyService"); |
| 84 | |
| 85 | // ---------------------------------------------------------------------- |
| 86 | |
| 87 | status_t BnSchedulingPolicyService::onTransact( |
| 88 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 89 | { |
| 90 | switch (code) { |
| 91 | case REQUEST_PRIORITY_TRANSACTION: |
Chong Zhang | 79d2b28 | 2018-04-17 14:14:31 -0700 | [diff] [blame] | 92 | case REQUEST_CPUSET_BOOST: |
Glenn Kasten | 1dc28b7 | 2012-04-24 10:01:03 -0700 | [diff] [blame] | 93 | // Not reached |
| 94 | return NO_ERROR; |
| 95 | break; |
| 96 | default: |
| 97 | return BBinder::onTransact(code, data, reply, flags); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | } // namespace android |