InputWindow.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (C) 2011 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 "InputWindow"
  17. #define LOG_NDEBUG 0
  18. #include <binder/Parcel.h>
  19. #include <input/InputWindow.h>
  20. #include <input/InputTransport.h>
  21. #include <log/log.h>
  22. #include <ui/Rect.h>
  23. #include <ui/Region.h>
  24. namespace android {
  25. // --- InputWindowInfo ---
  26. void InputWindowInfo::addTouchableRegion(const Rect& region) {
  27. touchableRegion.orSelf(region);
  28. }
  29. bool InputWindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const {
  30. return touchableRegion.contains(x,y);
  31. }
  32. bool InputWindowInfo::frameContainsPoint(int32_t x, int32_t y) const {
  33. return x >= frameLeft && x < frameRight
  34. && y >= frameTop && y < frameBottom;
  35. }
  36. bool InputWindowInfo::isTrustedOverlay() const {
  37. return layoutParamsType == TYPE_INPUT_METHOD
  38. || layoutParamsType == TYPE_INPUT_METHOD_DIALOG
  39. || layoutParamsType == TYPE_MAGNIFICATION_OVERLAY
  40. || layoutParamsType == TYPE_STATUS_BAR
  41. || layoutParamsType == TYPE_NAVIGATION_BAR
  42. || layoutParamsType == TYPE_NAVIGATION_BAR_PANEL
  43. || layoutParamsType == TYPE_SECURE_SYSTEM_OVERLAY
  44. || layoutParamsType == TYPE_DOCK_DIVIDER
  45. || layoutParamsType == TYPE_ACCESSIBILITY_OVERLAY
  46. || layoutParamsType == TYPE_INPUT_CONSUMER;
  47. }
  48. bool InputWindowInfo::supportsSplitTouch() const {
  49. return layoutParamsFlags & FLAG_SPLIT_TOUCH;
  50. }
  51. bool InputWindowInfo::overlaps(const InputWindowInfo* other) const {
  52. return frameLeft < other->frameRight && frameRight > other->frameLeft
  53. && frameTop < other->frameBottom && frameBottom > other->frameTop;
  54. }
  55. status_t InputWindowInfo::write(Parcel& output) const {
  56. if (token == nullptr) {
  57. output.writeInt32(0);
  58. return OK;
  59. }
  60. output.writeInt32(1);
  61. status_t s = output.writeStrongBinder(token);
  62. if (s != OK) return s;
  63. output.writeString8(String8(name.c_str()));
  64. output.writeInt32(layoutParamsFlags);
  65. output.writeInt32(layoutParamsType);
  66. output.writeInt64(dispatchingTimeout);
  67. output.writeInt32(frameLeft);
  68. output.writeInt32(frameTop);
  69. output.writeInt32(frameRight);
  70. output.writeInt32(frameBottom);
  71. output.writeInt32(surfaceInset);
  72. output.writeFloat(globalScaleFactor);
  73. output.writeFloat(windowXScale);
  74. output.writeFloat(windowYScale);
  75. output.writeBool(visible);
  76. output.writeBool(canReceiveKeys);
  77. output.writeBool(hasFocus);
  78. output.writeBool(hasWallpaper);
  79. output.writeBool(paused);
  80. output.writeInt32(layer);
  81. output.writeInt32(ownerPid);
  82. output.writeInt32(ownerUid);
  83. output.writeInt32(inputFeatures);
  84. output.writeInt32(displayId);
  85. output.writeInt32(portalToDisplayId);
  86. applicationInfo.write(output);
  87. output.write(touchableRegion);
  88. output.writeBool(replaceTouchableRegionWithCrop);
  89. output.writeWeakBinder(touchableRegionCropHandle);
  90. return OK;
  91. }
  92. InputWindowInfo InputWindowInfo::read(const Parcel& from) {
  93. InputWindowInfo ret;
  94. if (from.readInt32() == 0) {
  95. return ret;
  96. }
  97. sp<IBinder> token = from.readStrongBinder();
  98. if (token == nullptr) {
  99. return ret;
  100. }
  101. ret.token = token;
  102. ret.name = from.readString8().c_str();
  103. ret.layoutParamsFlags = from.readInt32();
  104. ret.layoutParamsType = from.readInt32();
  105. ret.dispatchingTimeout = from.readInt64();
  106. ret.frameLeft = from.readInt32();
  107. ret.frameTop = from.readInt32();
  108. ret.frameRight = from.readInt32();
  109. ret.frameBottom = from.readInt32();
  110. ret.surfaceInset = from.readInt32();
  111. ret.globalScaleFactor = from.readFloat();
  112. ret.windowXScale = from.readFloat();
  113. ret.windowYScale = from.readFloat();
  114. ret.visible = from.readBool();
  115. ret.canReceiveKeys = from.readBool();
  116. ret.hasFocus = from.readBool();
  117. ret.hasWallpaper = from.readBool();
  118. ret.paused = from.readBool();
  119. ret.layer = from.readInt32();
  120. ret.ownerPid = from.readInt32();
  121. ret.ownerUid = from.readInt32();
  122. ret.inputFeatures = from.readInt32();
  123. ret.displayId = from.readInt32();
  124. ret.portalToDisplayId = from.readInt32();
  125. ret.applicationInfo = InputApplicationInfo::read(from);
  126. from.read(ret.touchableRegion);
  127. ret.replaceTouchableRegionWithCrop = from.readBool();
  128. ret.touchableRegionCropHandle = from.readWeakBinder();
  129. return ret;
  130. }
  131. InputWindowInfo::InputWindowInfo(const Parcel& from) {
  132. *this = read(from);
  133. }
  134. // --- InputWindowHandle ---
  135. InputWindowHandle::InputWindowHandle() {
  136. }
  137. InputWindowHandle::~InputWindowHandle() {
  138. }
  139. void InputWindowHandle::releaseChannel() {
  140. mInfo.token.clear();
  141. }
  142. sp<IBinder> InputWindowHandle::getToken() const {
  143. return mInfo.token;
  144. }
  145. void InputWindowHandle::updateFrom(sp<InputWindowHandle> handle) {
  146. mInfo = handle->mInfo;
  147. }
  148. } // namespace android