blob: d26754e96c1d774f4db2a61b8bea7be361ef86ee [file] [log] [blame]
Ruben Brunk52f04072015-01-28 18:13:33 -08001/*
2 * Copyright 2015 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
Steven Moreland45e25cb2021-04-02 04:30:41 +000017#include <processinfo/IProcessInfoService.h>
Ruben Brunk52f04072015-01-28 18:13:33 -080018#include <binder/Parcel.h>
19#include <utils/Errors.h>
20#include <sys/types.h>
21
22namespace android {
23
24// ----------------------------------------------------------------------
25
26class BpProcessInfoService : public BpInterface<IProcessInfoService> {
27public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070028 explicit BpProcessInfoService(const sp<IBinder>& impl)
Ruben Brunk52f04072015-01-28 18:13:33 -080029 : BpInterface<IProcessInfoService>(impl) {}
30
31 virtual status_t getProcessStatesFromPids(size_t length, /*in*/ int32_t* pids,
32 /*out*/ int32_t* states)
33 {
34 Parcel data, reply;
35 data.writeInterfaceToken(IProcessInfoService::getInterfaceDescriptor());
36 data.writeInt32Array(length, pids);
37 data.writeInt32(length); // write length of output array, used by java AIDL stubs
38 status_t err = remote()->transact(GET_PROCESS_STATES_FROM_PIDS, data, &reply);
39 if (err != NO_ERROR || ((err = reply.readExceptionCode()) != NO_ERROR)) {
40 return err;
41 }
42 int32_t replyLen = reply.readInt32();
43 if (static_cast<size_t>(replyLen) != length) {
44 return NOT_ENOUGH_DATA;
45 }
46 if (replyLen > 0 && (err = reply.read(states, length * sizeof(*states))) != NO_ERROR) {
47 return err;
48 }
49 return reply.readInt32();
50 }
51
Chong Zhangc72a90a2015-12-01 14:08:22 -080052 virtual status_t getProcessStatesAndOomScoresFromPids(size_t length,
53 /*in*/ int32_t* pids, /*out*/ int32_t* states, /*out*/ int32_t* scores)
54 {
55 Parcel data, reply;
56 data.writeInterfaceToken(IProcessInfoService::getInterfaceDescriptor());
57 data.writeInt32Array(length, pids);
58 // write length of output arrays, used by java AIDL stubs
59 data.writeInt32(length);
60 data.writeInt32(length);
61 status_t err = remote()->transact(
62 GET_PROCESS_STATES_AND_OOM_SCORES_FROM_PIDS, data, &reply);
63 if (err != NO_ERROR
64 || ((err = reply.readExceptionCode()) != NO_ERROR)) {
65 return err;
66 }
67 int32_t replyLen = reply.readInt32();
68 if (static_cast<size_t>(replyLen) != length) {
69 return NOT_ENOUGH_DATA;
70 }
71 if (replyLen > 0 && (err = reply.read(
72 states, length * sizeof(*states))) != NO_ERROR) {
73 return err;
74 }
75 replyLen = reply.readInt32();
76 if (static_cast<size_t>(replyLen) != length) {
77 return NOT_ENOUGH_DATA;
78 }
79 if (replyLen > 0 && (err = reply.read(
80 scores, length * sizeof(*scores))) != NO_ERROR) {
81 return err;
82 }
83 return reply.readInt32();
84 }
Ruben Brunk52f04072015-01-28 18:13:33 -080085};
86
Jooyung Hanc91e3cb2020-11-25 06:38:17 +090087IMPLEMENT_META_INTERFACE(ProcessInfoService, "android.os.IProcessInfoService")
Ruben Brunk52f04072015-01-28 18:13:33 -080088
89// ----------------------------------------------------------------------
90
Steven Moreland61ff8492019-09-26 16:05:45 -070091} // namespace android