ISchedulingPolicyService.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #define LOG_TAG "ISchedulingPolicyService"
  17. //#define LOG_NDEBUG 0
  18. #include <binder/Parcel.h>
  19. #include "ISchedulingPolicyService.h"
  20. namespace android {
  21. // Keep in sync with frameworks/base/core/java/android/os/ISchedulingPolicyService.aidl
  22. enum {
  23. REQUEST_PRIORITY_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
  24. REQUEST_CPUSET_BOOST,
  25. };
  26. // ----------------------------------------------------------------------
  27. class BpSchedulingPolicyService : public BpInterface<ISchedulingPolicyService>
  28. {
  29. public:
  30. explicit BpSchedulingPolicyService(const sp<IBinder>& impl)
  31. : BpInterface<ISchedulingPolicyService>(impl)
  32. {
  33. }
  34. virtual int requestPriority(int32_t pid, int32_t tid,
  35. int32_t prio, bool isForApp, bool asynchronous)
  36. {
  37. Parcel data, reply;
  38. data.writeInterfaceToken(ISchedulingPolicyService::getInterfaceDescriptor());
  39. data.writeInt32(pid);
  40. data.writeInt32(tid);
  41. data.writeInt32(prio);
  42. data.writeBool(isForApp);
  43. uint32_t flags = asynchronous ? IBinder::FLAG_ONEWAY : 0;
  44. status_t status = remote()->transact(REQUEST_PRIORITY_TRANSACTION, data, &reply, flags);
  45. if (status != NO_ERROR) {
  46. return status;
  47. }
  48. if (asynchronous) {
  49. return NO_ERROR;
  50. }
  51. // fail on exception: force binder reconnection
  52. if (reply.readExceptionCode() != 0) {
  53. return DEAD_OBJECT;
  54. }
  55. return reply.readInt32();
  56. }
  57. virtual int requestCpusetBoost(bool enable, const sp<IInterface>& client)
  58. {
  59. Parcel data, reply;
  60. data.writeInterfaceToken(ISchedulingPolicyService::getInterfaceDescriptor());
  61. data.writeInt32(enable);
  62. data.writeStrongBinder(IInterface::asBinder(client));
  63. status_t status = remote()->transact(REQUEST_CPUSET_BOOST, data, &reply, 0);
  64. if (status != NO_ERROR) {
  65. return status;
  66. }
  67. // fail on exception: force binder reconnection
  68. if (reply.readExceptionCode() != 0) {
  69. return DEAD_OBJECT;
  70. }
  71. return reply.readInt32();
  72. }
  73. };
  74. IMPLEMENT_META_INTERFACE(SchedulingPolicyService, "android.os.ISchedulingPolicyService");
  75. // ----------------------------------------------------------------------
  76. status_t BnSchedulingPolicyService::onTransact(
  77. uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
  78. {
  79. switch (code) {
  80. case REQUEST_PRIORITY_TRANSACTION:
  81. case REQUEST_CPUSET_BOOST:
  82. // Not reached
  83. return NO_ERROR;
  84. break;
  85. default:
  86. return BBinder::onTransact(code, data, reply, flags);
  87. }
  88. }
  89. } // namespace android