blob: 9ea6ce5843a22bfe4f13f4550b9a763682d04cc1 [file] [log] [blame]
Jeff Brown40c9e0a2013-07-15 13:27:05 -07001/*
2 * Copyright (C) 2013 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#define LOG_TAG "InputFlinger"
18
19#include "InputFlinger.h"
20
21#include <stdint.h>
22#include <unistd.h>
23
24#include <sys/types.h>
25
26#include <binder/IPCThreadState.h>
27#include <binder/PermissionCache.h>
28#include <cutils/log.h>
29#include <private/android_filesystem_config.h>
30
31namespace android {
32
33const String16 sAccessInputFlingerPermission("android.permission.ACCESS_INPUT_FLINGER");
34const String16 sDumpPermission("android.permission.DUMP");
35
36
37InputFlinger::InputFlinger() :
38 BnInputFlinger() {
39 ALOGI("InputFlinger is starting");
40}
41
42InputFlinger::~InputFlinger() {
43}
44
45status_t InputFlinger::onTransact(
46 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
47 switch (code) {
48 case DO_SOMETHING_TRANSACTION:
49 const IPCThreadState* ipc = IPCThreadState::self();
50 const int pid = ipc->getCallingPid();
51 const int uid = ipc->getCallingUid();
52 if (!PermissionCache::checkPermission(sAccessInputFlingerPermission, pid, uid)) {
53 ALOGE("Permission Denial: "
54 "can't access InputFlinger from pid=%d, uid=%d", pid, uid);
55 return PERMISSION_DENIED;
56 }
57 break;
58 }
59
60 return BnInputFlinger::onTransact(code, data, reply, flags);
61}
62
63status_t InputFlinger::dump(int fd, const Vector<String16>& args) {
64 String8 result;
65 const IPCThreadState* ipc = IPCThreadState::self();
66 const int pid = ipc->getCallingPid();
67 const int uid = ipc->getCallingUid();
68 if ((uid != AID_SHELL)
69 && !PermissionCache::checkPermission(sDumpPermission, pid, uid)) {
70 result.appendFormat("Permission Denial: "
71 "can't dump SurfaceFlinger from pid=%d, uid=%d\n", pid, uid);
72 } else {
73 dumpInternal(result);
74 }
75 write(fd, result.string(), result.size());
76 return OK;
77}
78
79void InputFlinger::dumpInternal(String8& result) {
80 result.append("INPUT FLINGER (dumpsys inputflinger)\n");
81 result.append("... nothing here yet...\n");
82}
83
84status_t InputFlinger::doSomething() {
85 ALOGI("Did something...");
86 return OK;
87}
88
89}; // namespace android