blob: 82e196f26622c13910753ffc9a8113330783803f [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() {
24 uid_t uid = IPCThreadState::self()->getCallingUid();
25 switch (uid) {
26 case AID_ROOT:
27 case AID_SYSTEM: {
28 return true;
29 } break;
30 default: {
31 ALOGE("uid %u is not root nor system - access denied", uid);
32 } break;
33 }
34 return false;
35}
36
37namespace procfsinspector {
38class BpProcfsInspector: public BpInterface<IProcfsInspector> {
39 public:
40 BpProcfsInspector(sp<IBinder> binder) : BpInterface<IProcfsInspector>(binder) {}
41
42 virtual std::vector<ProcessInfo> readProcessTable() override {
43 Parcel data, reply;
44 remote()->transact((uint32_t)IProcfsInspector::Call::READ_PROCESS_TABLE, data, &reply);
45
46 std::vector<procfsinspector::ProcessInfo> result;
47 reply.readParcelableVector(&result);
48 return result;
49 }
50
51};
52
53IMPLEMENT_META_INTERFACE(ProcfsInspector, "com.android.car.procfsinspector.IProcfsInspector");
54
55status_t Impl::onTransact(uint32_t code,
56 const Parcel& data, Parcel* reply, uint32_t flags) {
57
58 if (code == (uint32_t)IProcfsInspector::Call::READ_PROCESS_TABLE) {
59 CHECK_INTERFACE(IProcfsInspector, data, reply);
60 if (isSystemUser()) {
61 reply->writeNoException();
62 reply->writeParcelableVector(readProcessTable());
63 return NO_ERROR;
64 } else {
65 return PERMISSION_DENIED;
66 }
67 }
68
69 return BBinder::onTransact(code, data, reply, flags);
70}
71
72}