blob: 402b37b0f7fb3c5d37211b871084bd583043f8a1 [file] [log] [blame]
Enrico Granatae23f0342017-10-23 17:17:52 -07001/*
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 "server.h"
18
19#include <binder/IPCThreadState.h>
20
21#include <private/android_filesystem_config.h>
22
23static bool isSystemUser() {
Nicholas Sauer771aade2018-10-22 15:42:01 -070024 uid_t uid = IPCThreadState::self()->getCallingUid();
25 uid_t aid = uid % AID_USER_OFFSET;
26 switch (aid) {
Enrico Granatae23f0342017-10-23 17:17:52 -070027 case AID_ROOT:
28 case AID_SYSTEM: {
29 return true;
30 } break;
31 default: {
Nicholas Sauer771aade2018-10-22 15:42:01 -070032 ALOGE("aid %u (uid %u) is not root nor system - access denied", aid, uid);
Enrico Granatae23f0342017-10-23 17:17:52 -070033 } break;
34 }
35 return false;
36}
37
38namespace procfsinspector {
39class BpProcfsInspector: public BpInterface<IProcfsInspector> {
40 public:
41 BpProcfsInspector(sp<IBinder> binder) : BpInterface<IProcfsInspector>(binder) {}
42
43 virtual std::vector<ProcessInfo> readProcessTable() override {
44 Parcel data, reply;
45 remote()->transact((uint32_t)IProcfsInspector::Call::READ_PROCESS_TABLE, data, &reply);
46
47 std::vector<procfsinspector::ProcessInfo> result;
48 reply.readParcelableVector(&result);
49 return result;
50 }
51
52};
53
54IMPLEMENT_META_INTERFACE(ProcfsInspector, "com.android.car.procfsinspector.IProcfsInspector");
55
56status_t Impl::onTransact(uint32_t code,
57 const Parcel& data, Parcel* reply, uint32_t flags) {
58
59 if (code == (uint32_t)IProcfsInspector::Call::READ_PROCESS_TABLE) {
60 CHECK_INTERFACE(IProcfsInspector, data, reply);
61 if (isSystemUser()) {
62 reply->writeNoException();
63 reply->writeParcelableVector(readProcessTable());
64 return NO_ERROR;
65 } else {
66 return PERMISSION_DENIED;
67 }
68 }
69
70 return BBinder::onTransact(code, data, reply, flags);
71}
72
73}