blob: a1b08db50ca5ae0a7a0ef26d1d935b0a4381efe2 [file] [log] [blame]
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +00001/*
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
21namespace android {
22
23// ------------------------------------------------------------------------------------
24
25class BpUidObserver : public BpInterface<IUidObserver>
26{
27public:
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 Laurent05595892018-10-18 14:56:24 -070058
Hui Yuee03b782019-08-22 14:48:40 -070059 virtual void onUidStateChanged(uid_t uid, int32_t procState, int64_t procStateSeq,
60 int32_t capability)
Eric Laurent05595892018-10-18 14:56:24 -070061 {
62 Parcel data, reply;
63 data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor());
64 data.writeInt32((int32_t) uid);
65 data.writeInt32(procState);
66 data.writeInt64(procStateSeq);
Hui Yuee03b782019-08-22 14:48:40 -070067 data.writeInt32(capability);
Eric Laurent05595892018-10-18 14:56:24 -070068 remote()->transact(ON_UID_STATE_CHANGED_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
69 }
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000070};
71
72// ----------------------------------------------------------------------
73
Jooyung Hanc91e3cb2020-11-25 06:38:17 +090074IMPLEMENT_META_INTERFACE(UidObserver, "android.app.IUidObserver")
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000075
76// ----------------------------------------------------------------------
77
Jiyong Park276781a2020-11-13 18:19:27 +090078// NOLINTNEXTLINE(google-default-arguments)
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +000079status_t BnUidObserver::onTransact(
80 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
81{
82 switch(code) {
83 case ON_UID_GONE_TRANSACTION: {
84 CHECK_INTERFACE(IUidObserver, data, reply);
85 uid_t uid = data.readInt32();
86 bool disabled = data.readInt32() == 1;
87 onUidGone(uid, disabled);
88 return NO_ERROR;
89 } break;
90
91 case ON_UID_ACTIVE_TRANSACTION: {
92 CHECK_INTERFACE(IUidObserver, data, reply);
93 uid_t uid = data.readInt32();
94 onUidActive(uid);
95 return NO_ERROR;
96 } break;
97
98 case ON_UID_IDLE_TRANSACTION: {
99 CHECK_INTERFACE(IUidObserver, data, reply);
100 uid_t uid = data.readInt32();
101 bool disabled = data.readInt32() == 1;
102 onUidIdle(uid, disabled);
103 return NO_ERROR;
104 } break;
Eric Laurent05595892018-10-18 14:56:24 -0700105 case ON_UID_STATE_CHANGED_TRANSACTION: {
106 CHECK_INTERFACE(IUidObserver, data, reply);
107 uid_t uid = data.readInt32();
108 int32_t procState = data.readInt32();
109 int64_t procStateSeq = data.readInt64();
Hui Yuee03b782019-08-22 14:48:40 -0700110 int32_t capability = data.readInt32();
111 onUidStateChanged(uid, procState, procStateSeq, capability);
Eric Laurent05595892018-10-18 14:56:24 -0700112 return NO_ERROR;
113 } break;
Ganesh Mahendran4d85b8c2017-11-02 14:43:38 +0000114 default:
115 return BBinder::onTransact(code, data, reply, flags);
116 }
117}
118
Steven Moreland6511af52019-09-26 16:05:45 -0700119} // namespace android