Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 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 | |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 19 | #include <stdint.h> |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 20 | #include <sys/types.h> |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 21 | #include <unistd.h> |
| 22 | |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 23 | #include <android/log.h> |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 24 | #include <binder/IPCThreadState.h> |
| 25 | #include <binder/PermissionCache.h> |
Michael Wright | 6f78360 | 2015-02-13 17:35:16 -0800 | [diff] [blame] | 26 | #include <hardware/input.h> |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 27 | #include <private/android_filesystem_config.h> |
| 28 | |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 29 | #include "InputFlinger.h" |
| 30 | #include "InputDriver.h" |
| 31 | |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | |
| 34 | const String16 sAccessInputFlingerPermission("android.permission.ACCESS_INPUT_FLINGER"); |
| 35 | const String16 sDumpPermission("android.permission.DUMP"); |
| 36 | |
| 37 | |
| 38 | InputFlinger::InputFlinger() : |
| 39 | BnInputFlinger() { |
| 40 | ALOGI("InputFlinger is starting"); |
Michael Wright | 6f78360 | 2015-02-13 17:35:16 -0800 | [diff] [blame] | 41 | mHost = new InputHost(); |
| 42 | mHost->registerInputDriver(new InputDriver(INPUT_INSTANCE_EVDEV)); |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | InputFlinger::~InputFlinger() { |
| 46 | } |
| 47 | |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 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 SurfaceFlinger 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 | |
| 64 | void InputFlinger::dumpInternal(String8& result) { |
| 65 | result.append("INPUT FLINGER (dumpsys inputflinger)\n"); |
Michael Wright | 6f78360 | 2015-02-13 17:35:16 -0800 | [diff] [blame] | 66 | mHost->dump(result); |
Jeff Brown | 40c9e0a | 2013-07-15 13:27:05 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | }; // namespace android |