IUidObserver.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  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. #include <binder/IUidObserver.h>
  17. #include <binder/Parcel.h>
  18. namespace android {
  19. // ------------------------------------------------------------------------------------
  20. class BpUidObserver : public BpInterface<IUidObserver>
  21. {
  22. public:
  23. explicit BpUidObserver(const sp<IBinder>& impl)
  24. : BpInterface<IUidObserver>(impl)
  25. {
  26. }
  27. virtual void onUidGone(uid_t uid, bool disabled)
  28. {
  29. Parcel data, reply;
  30. data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor());
  31. data.writeInt32((int32_t) uid);
  32. data.writeInt32(disabled ? 1 : 0);
  33. remote()->transact(ON_UID_GONE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
  34. }
  35. virtual void onUidActive(uid_t uid)
  36. {
  37. Parcel data, reply;
  38. data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor());
  39. data.writeInt32((int32_t) uid);
  40. remote()->transact(ON_UID_ACTIVE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
  41. }
  42. virtual void onUidIdle(uid_t uid, bool disabled)
  43. {
  44. Parcel data, reply;
  45. data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor());
  46. data.writeInt32((int32_t) uid);
  47. data.writeInt32(disabled ? 1 : 0);
  48. remote()->transact(ON_UID_IDLE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
  49. }
  50. virtual void onUidStateChanged(uid_t uid, int32_t procState, int64_t procStateSeq)
  51. {
  52. Parcel data, reply;
  53. data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor());
  54. data.writeInt32((int32_t) uid);
  55. data.writeInt32(procState);
  56. data.writeInt64(procStateSeq);
  57. remote()->transact(ON_UID_STATE_CHANGED_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
  58. }
  59. };
  60. // ----------------------------------------------------------------------
  61. IMPLEMENT_META_INTERFACE(UidObserver, "android.app.IUidObserver");
  62. // ----------------------------------------------------------------------
  63. status_t BnUidObserver::onTransact(
  64. uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
  65. {
  66. switch(code) {
  67. case ON_UID_GONE_TRANSACTION: {
  68. CHECK_INTERFACE(IUidObserver, data, reply);
  69. uid_t uid = data.readInt32();
  70. bool disabled = data.readInt32() == 1;
  71. onUidGone(uid, disabled);
  72. return NO_ERROR;
  73. } break;
  74. case ON_UID_ACTIVE_TRANSACTION: {
  75. CHECK_INTERFACE(IUidObserver, data, reply);
  76. uid_t uid = data.readInt32();
  77. onUidActive(uid);
  78. return NO_ERROR;
  79. } break;
  80. case ON_UID_IDLE_TRANSACTION: {
  81. CHECK_INTERFACE(IUidObserver, data, reply);
  82. uid_t uid = data.readInt32();
  83. bool disabled = data.readInt32() == 1;
  84. onUidIdle(uid, disabled);
  85. return NO_ERROR;
  86. } break;
  87. case ON_UID_STATE_CHANGED_TRANSACTION: {
  88. CHECK_INTERFACE(IUidObserver, data, reply);
  89. uid_t uid = data.readInt32();
  90. int32_t procState = data.readInt32();
  91. int64_t procStateSeq = data.readInt64();
  92. onUidStateChanged(uid, procState, procStateSeq);
  93. return NO_ERROR;
  94. } break;
  95. default:
  96. return BBinder::onTransact(code, data, reply, flags);
  97. }
  98. }
  99. }; // namespace android