diff options
author | Vishnu Nair <vishnun@google.com> | 2022-02-07 23:43:51 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-02-07 23:43:51 +0000 |
commit | d5a65ea539a2bb939da68780ee6ed4ab35ae73fb (patch) | |
tree | 9be5140a33784b0714a4ed62f95e266b8a0f9960 | |
parent | 9c097670cdcc10f892eefa44a85cbc71edecbcb8 (diff) | |
parent | 77daf700ce9707d147d2cc3075d6e6bbc1a4280a (diff) | |
download | native-d5a65ea539a2bb939da68780ee6ed4ab35ae73fb.tar.gz |
SurfaceControl: Add setDropInputMode api am: 77daf700ce
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/16740114
Change-Id: I7ab2f02c81569e5ae72fff8a2e1f3ea8fccd8a2e
-rw-r--r-- | include/input/InputWindow.h | 1 | ||||
-rw-r--r-- | libs/gui/Android.bp | 10 | ||||
-rw-r--r-- | libs/gui/LayerState.cpp | 10 | ||||
-rw-r--r-- | libs/gui/SurfaceComposerClient.cpp | 15 | ||||
-rw-r--r-- | libs/gui/android/gui/DropInputMode.aidl | 40 | ||||
-rw-r--r-- | libs/gui/include/gui/LayerState.h | 5 | ||||
-rw-r--r-- | libs/gui/include/gui/SurfaceComposerClient.h | 2 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 12 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.h | 4 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 9 |
10 files changed, 106 insertions, 2 deletions
diff --git a/include/input/InputWindow.h b/include/input/InputWindow.h index 121be6d963..e2c95870cf 100644 --- a/include/input/InputWindow.h +++ b/include/input/InputWindow.h @@ -128,6 +128,7 @@ struct InputWindowInfo : public Parcelable { DISABLE_TOUCH_PAD_GESTURES = 0x00000001, NO_INPUT_CHANNEL = 0x00000002, DISABLE_USER_ACTIVITY = 0x00000004, + INPUT_FEATURE_DROP_INPUT = 0x00000008, }; /* These values are filled in by the WM and passed through SurfaceFlinger diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp index 64203f78a8..b1c6e3a5d6 100644 --- a/libs/gui/Android.bp +++ b/libs/gui/Android.bp @@ -39,13 +39,20 @@ cc_library_headers { min_sdk_version: "29", } +// AIDL files that should be exposed to java +filegroup { + name: "guiconstants_aidl", + srcs: [ + "android/gui/DropInputMode.aidl", + ], +} + cc_library_headers { name: "libgui_aidl_headers", vendor_available: true, static_libs: [ "libgui_aidl_static", ], - export_static_lib_headers: [ "libgui_aidl_static", ], @@ -102,6 +109,7 @@ cc_library_shared { ], srcs: [ + ":guiconstants_aidl", ":framework_native_aidl", ":inputconstants_aidl", ":libgui_bufferqueue_sources", diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp index 076c90dd23..2f31fbbb68 100644 --- a/libs/gui/LayerState.cpp +++ b/libs/gui/LayerState.cpp @@ -65,6 +65,7 @@ layer_state_t::layer_state_t() frameNumber(0), autoRefresh(false), isTrustedOverlay(false), + dropInputMode(gui::DropInputMode::NONE), bufferCrop(Rect::INVALID_RECT), destinationFrame(Rect::INVALID_RECT), releaseBufferListener(nullptr) { @@ -172,7 +173,7 @@ status_t layer_state_t::write(Parcel& output) const SAFE_PARCEL(output.write, bufferCrop); SAFE_PARCEL(output.write, destinationFrame); SAFE_PARCEL(output.writeBool, isTrustedOverlay); - + output.writeUint32(static_cast<uint32_t>(dropInputMode)); return NO_ERROR; } @@ -304,6 +305,9 @@ status_t layer_state_t::read(const Parcel& input) SAFE_PARCEL(input.read, destinationFrame); SAFE_PARCEL(input.readBool, &isTrustedOverlay); + uint32_t mode; + mode = input.readUint32(); + dropInputMode = static_cast<gui::DropInputMode>(mode); return NO_ERROR; } @@ -539,6 +543,10 @@ void layer_state_t::merge(const layer_state_t& other) { what |= eTrustedOverlayChanged; isTrustedOverlay = other.isTrustedOverlay; } + if (other.what & eDropInputModeChanged) { + what |= eDropInputModeChanged; + dropInputMode = other.dropInputMode; + } if (other.what & eReleaseBufferListenerChanged) { if (releaseBufferListener) { ALOGW("Overriding releaseBufferListener"); diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 96da8efd19..6ffd25d227 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -1669,6 +1669,21 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTrust return *this; } +SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDropInputMode( + const sp<SurfaceControl>& sc, gui::DropInputMode mode) { + layer_state_t* s = getLayerState(sc); + if (!s) { + mStatus = BAD_INDEX; + return *this; + } + + s->what |= layer_state_t::eDropInputModeChanged; + s->dropInputMode = mode; + + registerSurfaceControlForCallback(sc); + return *this; +} + SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setApplyToken( const sp<IBinder>& applyToken) { mApplyToken = applyToken; diff --git a/libs/gui/android/gui/DropInputMode.aidl b/libs/gui/android/gui/DropInputMode.aidl new file mode 100644 index 0000000000..294943667c --- /dev/null +++ b/libs/gui/android/gui/DropInputMode.aidl @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2021, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.gui; + + +/** + * Input event drop modes: Input event drop options for windows and its children. + * + * @hide + */ +@Backing(type="int") +enum DropInputMode { + /** + * Default mode, input events are sent to the target as usual. + */ + NONE, + + /** + * Window and its children will not receive any input even if it has a valid input channel. + * Touches and keys will be dropped. If a window is focused, it will remain focused but will + * not receive any keys. If the window has a touchable region and is the target of an input + * event, the event will be dropped and will not go to the window behind. ref: b/197296414 + */ + ALL, +} + diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h index 3e57ff611e..feef343748 100644 --- a/libs/gui/include/gui/LayerState.h +++ b/libs/gui/include/gui/LayerState.h @@ -26,6 +26,7 @@ #include <gui/ITransactionCompletedListener.h> #include <math/mat4.h> +#include <android/gui/DropInputMode.h> #ifndef NO_INPUT #include <android/FocusRequest.h> #include <input/InputWindow.h> @@ -116,6 +117,7 @@ struct layer_state_t { eFixedTransformHintChanged = 0x200'00000000, eFrameNumberChanged = 0x400'00000000, eBlurRegionsChanged = 0x800'00000000, + eDropInputModeChanged = 0x8000'00000000, eAutoRefreshChanged = 0x1000'00000000, eStretchChanged = 0x2000'00000000, eTrustedOverlayChanged = 0x4000'00000000, @@ -233,6 +235,9 @@ struct layer_state_t { // Stretch effect to be applied to this layer StretchEffect stretchEffect; + // Force inputflinger to drop all input events for the layer and its children. + gui::DropInputMode dropInputMode; + Rect bufferCrop; Rect destinationFrame; diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index baa0567617..6e17212911 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -540,6 +540,8 @@ public: // Sets that this surface control and its children are trusted overlays for input Transaction& setTrustedOverlay(const sp<SurfaceControl>& sc, bool isTrustedOverlay); + Transaction& setDropInputMode(const sp<SurfaceControl>& sc, gui::DropInputMode mode); + // Queues up transactions using this token in SurfaceFlinger. By default, all transactions // from a client are placed on the same queue. This can be used to prevent multiple // transactions from blocking each other. diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 6ee13ce508..93f8f9127d 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -133,6 +133,7 @@ Layer::Layer(const LayerCreationArgs& args) mDrawingState.fixedTransformHint = ui::Transform::ROT_INVALID; mDrawingState.frameTimelineInfo = {}; mDrawingState.postTime = -1; + mDrawingState.dropInputMode = gui::DropInputMode::NONE; mDrawingState.destinationFrame.makeInvalid(); if (args.flags & ISurfaceComposerClient::eNoColorFill) { @@ -2514,6 +2515,17 @@ Layer::FrameRateCompatibility Layer::FrameRate::convertCompatibility(int8_t comp } } +bool Layer::setDropInputMode(gui::DropInputMode mode) { + if (mDrawingState.dropInputMode == mode) { + return false; + } + mDrawingState.dropInputMode = mode; + mDrawingState.modified = true; + mFlinger->mInputInfoChanged = true; + setTransactionFlags(eTransactionNeeded); + return true; +} + scheduler::Seamlessness Layer::FrameRate::convertChangeFrameRateStrategy(int8_t strategy) { switch (strategy) { case ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS: diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 8905548b64..4b367e82bb 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -17,6 +17,7 @@ #pragma once +#include <android/gui/DropInputMode.h> #include <compositionengine/LayerFE.h> #include <gui/BufferQueue.h> #include <gui/ISurfaceComposerClient.h> @@ -279,6 +280,7 @@ public: bool isTrustedOverlay; Rect bufferCrop; + gui::DropInputMode dropInputMode; Rect destinationFrame; }; @@ -444,6 +446,8 @@ public: virtual bool setFrameRateSelectionPriority(int32_t priority); virtual bool setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint); virtual void setAutoRefresh(bool /* autoRefresh */) {} + bool setDropInputMode(gui::DropInputMode); + // If the variable is not set on the layer, it traverses up the tree to inherit the frame // rate priority from its parent. virtual int32_t getFrameRateSelectionPriority() const; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index bbf6a2db78..9b49b35ad5 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -4170,6 +4170,15 @@ uint32_t SurfaceFlinger::setClientStateLocked( ALOGE("Attempt to set trusted overlay without permission ACCESS_SURFACE_FLINGER"); } } + if (what & layer_state_t::eDropInputModeChanged) { + if (privileged) { + if (layer->setDropInputMode(s.dropInputMode)) { + flags |= eTraversalNeeded; + } + } else { + ALOGE("Attempt to update InputPolicyFlags without permission ACCESS_SURFACE_FLINGER"); + } + } if (what & layer_state_t::eStretchChanged) { if (layer->setStretchEffect(s.stretchEffect)) { flags |= eTraversalNeeded; |