1 /*
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 <stdint.h>
20 #include <sys/types.h>
21 #include <unistd.h>
22
23 #include <binder/IPCThreadState.h>
24 #include <binder/PermissionCache.h>
25 #include <hardware/input.h>
26 #include <log/log.h>
27 #include <private/android_filesystem_config.h>
28
29 #include "InputFlinger.h"
30 #include "InputDriver.h"
31
32 namespace android {
33
34 const String16 sAccessInputFlingerPermission("android.permission.ACCESS_INPUT_FLINGER");
35 const String16 sDumpPermission("android.permission.DUMP");
36
37
InputFlinger()38 InputFlinger::InputFlinger() :
39 BnInputFlinger() {
40 ALOGI("InputFlinger is starting");
41 mHost = new InputHost();
42 mHost->registerInputDriver(new InputDriver(INPUT_INSTANCE_EVDEV));
43 }
44
~InputFlinger()45 InputFlinger::~InputFlinger() {
46 }
47
dump(int fd,const Vector<String16> & args)48 status_t InputFlinger::dump(int fd, const Vector<String16>& args) {
49 String8 result;
50 const IPCThreadState* ipc = IPCThreadState::self();
51 const int pid = ipc->getCallingPid();
52 const int uid = ipc->getCallingUid();
53 if ((uid != AID_SHELL)
54 && !PermissionCache::checkPermission(sDumpPermission, pid, uid)) {
55 result.appendFormat("Permission Denial: "
56 "can't dump InputFlinger from pid=%d, uid=%d\n", pid, uid);
57 } else {
58 dumpInternal(result);
59 }
60 write(fd, result.string(), result.size());
61 return OK;
62 }
63
dumpInternal(String8 & result)64 void InputFlinger::dumpInternal(String8& result) {
65 result.append("INPUT FLINGER (dumpsys inputflinger)\n");
66 mHost->dump(result);
67 }
68
69 }; // namespace android
70