Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 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 | |
| 17 | #include <binder/IUidObserver.h> |
| 18 | |
| 19 | #include <binder/Parcel.h> |
| 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | // ------------------------------------------------------------------------------------ |
| 24 | |
| 25 | class BpUidObserver : public BpInterface<IUidObserver> |
| 26 | { |
| 27 | public: |
| 28 | explicit BpUidObserver(const sp<IBinder>& impl) |
| 29 | : BpInterface<IUidObserver>(impl) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | virtual void onUidGone(uid_t uid, bool disabled) |
| 34 | { |
| 35 | Parcel data, reply; |
| 36 | data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor()); |
| 37 | data.writeInt32((int32_t) uid); |
| 38 | data.writeInt32(disabled ? 1 : 0); |
| 39 | remote()->transact(ON_UID_GONE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); |
| 40 | } |
| 41 | |
| 42 | virtual void onUidActive(uid_t uid) |
| 43 | { |
| 44 | Parcel data, reply; |
| 45 | data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor()); |
| 46 | data.writeInt32((int32_t) uid); |
| 47 | remote()->transact(ON_UID_ACTIVE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); |
| 48 | } |
| 49 | |
| 50 | virtual void onUidIdle(uid_t uid, bool disabled) |
| 51 | { |
| 52 | Parcel data, reply; |
| 53 | data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor()); |
| 54 | data.writeInt32((int32_t) uid); |
| 55 | data.writeInt32(disabled ? 1 : 0); |
| 56 | remote()->transact(ON_UID_IDLE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); |
| 57 | } |
Eric Laurent | 0559589 | 2018-10-18 14:56:24 -0700 | [diff] [blame] | 58 | |
Hui Yu | ee03b78 | 2019-08-22 14:48:40 -0700 | [diff] [blame] | 59 | virtual void onUidStateChanged(uid_t uid, int32_t procState, int64_t procStateSeq, |
Austin Borger | 5144233 | 2022-02-17 00:26:18 +0000 | [diff] [blame] | 60 | int32_t capability) { |
Eric Laurent | 0559589 | 2018-10-18 14:56:24 -0700 | [diff] [blame] | 61 | Parcel data, reply; |
| 62 | data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor()); |
| 63 | data.writeInt32((int32_t) uid); |
| 64 | data.writeInt32(procState); |
| 65 | data.writeInt64(procStateSeq); |
Hui Yu | ee03b78 | 2019-08-22 14:48:40 -0700 | [diff] [blame] | 66 | data.writeInt32(capability); |
Eric Laurent | 0559589 | 2018-10-18 14:56:24 -0700 | [diff] [blame] | 67 | remote()->transact(ON_UID_STATE_CHANGED_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); |
| 68 | } |
Austin Borger | 5144233 | 2022-02-17 00:26:18 +0000 | [diff] [blame] | 69 | |
| 70 | virtual void onUidProcAdjChanged(uid_t uid) { |
| 71 | Parcel data, reply; |
| 72 | data.writeInt32((int32_t)uid); |
| 73 | remote()->transact(ON_UID_PROC_ADJ_CHANGED_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); |
| 74 | } |
Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | // ---------------------------------------------------------------------- |
| 78 | |
Jooyung Han | c91e3cb | 2020-11-25 06:38:17 +0900 | [diff] [blame] | 79 | IMPLEMENT_META_INTERFACE(UidObserver, "android.app.IUidObserver") |
Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 80 | |
| 81 | // ---------------------------------------------------------------------- |
| 82 | |
Jiyong Park | 276781a | 2020-11-13 18:19:27 +0900 | [diff] [blame] | 83 | // NOLINTNEXTLINE(google-default-arguments) |
Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 84 | status_t BnUidObserver::onTransact( |
| 85 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 86 | { |
| 87 | switch(code) { |
| 88 | case ON_UID_GONE_TRANSACTION: { |
| 89 | CHECK_INTERFACE(IUidObserver, data, reply); |
| 90 | uid_t uid = data.readInt32(); |
| 91 | bool disabled = data.readInt32() == 1; |
| 92 | onUidGone(uid, disabled); |
| 93 | return NO_ERROR; |
| 94 | } break; |
| 95 | |
| 96 | case ON_UID_ACTIVE_TRANSACTION: { |
| 97 | CHECK_INTERFACE(IUidObserver, data, reply); |
| 98 | uid_t uid = data.readInt32(); |
| 99 | onUidActive(uid); |
| 100 | return NO_ERROR; |
| 101 | } break; |
| 102 | |
| 103 | case ON_UID_IDLE_TRANSACTION: { |
| 104 | CHECK_INTERFACE(IUidObserver, data, reply); |
| 105 | uid_t uid = data.readInt32(); |
| 106 | bool disabled = data.readInt32() == 1; |
| 107 | onUidIdle(uid, disabled); |
| 108 | return NO_ERROR; |
| 109 | } break; |
Austin Borger | 5144233 | 2022-02-17 00:26:18 +0000 | [diff] [blame] | 110 | |
Eric Laurent | 0559589 | 2018-10-18 14:56:24 -0700 | [diff] [blame] | 111 | case ON_UID_STATE_CHANGED_TRANSACTION: { |
| 112 | CHECK_INTERFACE(IUidObserver, data, reply); |
| 113 | uid_t uid = data.readInt32(); |
| 114 | int32_t procState = data.readInt32(); |
| 115 | int64_t procStateSeq = data.readInt64(); |
Hui Yu | ee03b78 | 2019-08-22 14:48:40 -0700 | [diff] [blame] | 116 | int32_t capability = data.readInt32(); |
| 117 | onUidStateChanged(uid, procState, procStateSeq, capability); |
Eric Laurent | 0559589 | 2018-10-18 14:56:24 -0700 | [diff] [blame] | 118 | return NO_ERROR; |
| 119 | } break; |
Austin Borger | 5144233 | 2022-02-17 00:26:18 +0000 | [diff] [blame] | 120 | |
| 121 | case ON_UID_PROC_ADJ_CHANGED_TRANSACTION: { |
| 122 | CHECK_INTERFACE(IUidObserver, data, reply); |
| 123 | uid_t uid = data.readInt32(); |
| 124 | onUidProcAdjChanged(uid); |
| 125 | return NO_ERROR; |
| 126 | } break; |
| 127 | |
Ganesh Mahendran | 4d85b8c | 2017-11-02 14:43:38 +0000 | [diff] [blame] | 128 | default: |
| 129 | return BBinder::onTransact(code, data, reply, flags); |
| 130 | } |
| 131 | } |
| 132 | |
Steven Moreland | 6511af5 | 2019-09-26 16:05:45 -0700 | [diff] [blame] | 133 | } // namespace android |