InputFlinger.cpp 2.0 KB

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