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 | } |
| 58 | }; |
| 59 | |
| 60 | // ---------------------------------------------------------------------- |
| 61 | |
| 62 | IMPLEMENT_META_INTERFACE(UidObserver, "android.app.IUidObserver"); |
| 63 | |
| 64 | // ---------------------------------------------------------------------- |
| 65 | |
| 66 | status_t BnUidObserver::onTransact( |
| 67 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 68 | { |
| 69 | switch(code) { |
| 70 | case ON_UID_GONE_TRANSACTION: { |
| 71 | CHECK_INTERFACE(IUidObserver, data, reply); |
| 72 | uid_t uid = data.readInt32(); |
| 73 | bool disabled = data.readInt32() == 1; |
| 74 | onUidGone(uid, disabled); |
| 75 | return NO_ERROR; |
| 76 | } break; |
| 77 | |
| 78 | case ON_UID_ACTIVE_TRANSACTION: { |
| 79 | CHECK_INTERFACE(IUidObserver, data, reply); |
| 80 | uid_t uid = data.readInt32(); |
| 81 | onUidActive(uid); |
| 82 | return NO_ERROR; |
| 83 | } break; |
| 84 | |
| 85 | case ON_UID_IDLE_TRANSACTION: { |
| 86 | CHECK_INTERFACE(IUidObserver, data, reply); |
| 87 | uid_t uid = data.readInt32(); |
| 88 | bool disabled = data.readInt32() == 1; |
| 89 | onUidIdle(uid, disabled); |
| 90 | return NO_ERROR; |
| 91 | } break; |
| 92 | default: |
| 93 | return BBinder::onTransact(code, data, reply, flags); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | }; // namespace android |