Skip to content

Commit 122c4d2

Browse files
author
Vishnu Nair
committed
SurfaceControl: Add setDropInputMode api
Introduces an API to drop input events on this SurfaceControl. This policy will be inherited by its children. The caller must hold the ACCESS_SURFACE_FLINGER permission. Options include: ALL: SurfaceControl and its children will not receive any input regardless of whether it has a valid input channel. These policies are used to enable features that allow for a less trusted interaction model between apps. See the bug for more details. Note: this backport does not include the OBSCURED option since its not needed for the security fix. Test: atest libgui_test InputDispatcherDropInputFeatureTest Bug: 197296414 Merged-In: I443741d5ab51a45d37fb865f11c433c436d96c1e Change-Id: I443741d5ab51a45d37fb865f11c433c436d96c1e
1 parent eb59e47 commit 122c4d2

File tree

10 files changed

+107
-3
lines changed

10 files changed

+107
-3
lines changed

include/input/InputWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ struct InputWindowInfo {
115115
INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES = 0x00000001,
116116
INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002,
117117
INPUT_FEATURE_DISABLE_USER_ACTIVITY = 0x00000004,
118+
INPUT_FEATURE_DROP_INPUT = 0x00000008,
118119
};
119120

120121
/* These values are filled in by the WM and passed through SurfaceFlinger

libs/gui/Android.bp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ cc_library_headers {
3030
min_sdk_version: "29",
3131
}
3232

33+
// AIDL files that should be exposed to java
34+
filegroup {
35+
name: "guiconstants_aidl",
36+
srcs: [
37+
"android/gui/DropInputMode.aidl",
38+
],
39+
}
40+
3341
cc_library_shared {
3442
name: "libgui",
3543
vendor_available: false,
@@ -41,6 +49,7 @@ cc_library_shared {
4149
defaults: ["libgui_bufferqueue-defaults"],
4250

4351
srcs: [
52+
":guiconstants_aidl",
4453
":framework_native_aidl",
4554
":libgui_bufferqueue_sources",
4655

libs/gui/LayerState.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ status_t layer_state_t::write(Parcel& output) const
118118
output.writeByte(frameRateCompatibility);
119119
output.writeUint32(fixedTransformHint);
120120
output.writeBool(isTrustedOverlay);
121-
121+
output.writeUint32(static_cast<uint32_t>(dropInputMode));
122122
return NO_ERROR;
123123
}
124124

@@ -204,6 +204,9 @@ status_t layer_state_t::read(const Parcel& input)
204204
fixedTransformHint = static_cast<ui::Transform::RotationFlags>(input.readUint32());
205205
isTrustedOverlay = input.readBool();
206206

207+
uint32_t mode;
208+
mode = input.readUint32();
209+
dropInputMode = static_cast<gui::DropInputMode>(mode);
207210
return NO_ERROR;
208211
}
209212

@@ -447,6 +450,10 @@ void layer_state_t::merge(const layer_state_t& other) {
447450
what |= eTrustedOverlayChanged;
448451
isTrustedOverlay = other.isTrustedOverlay;
449452
}
453+
if (other.what & eDropInputModeChanged) {
454+
what |= eDropInputModeChanged;
455+
dropInputMode = other.dropInputMode;
456+
}
450457
if ((other.what & what) != other.what) {
451458
ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
452459
"other.what=0x%" PRIu64 " what=0x%" PRIu64,

libs/gui/SurfaceComposerClient.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,21 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTrust
14971497
return *this;
14981498
}
14991499

1500+
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDropInputMode(
1501+
const sp<SurfaceControl>& sc, gui::DropInputMode mode) {
1502+
layer_state_t* s = getLayerState(sc);
1503+
if (!s) {
1504+
mStatus = BAD_INDEX;
1505+
return *this;
1506+
}
1507+
1508+
s->what |= layer_state_t::eDropInputModeChanged;
1509+
s->dropInputMode = mode;
1510+
1511+
registerSurfaceControlForCallback(sc);
1512+
return *this;
1513+
}
1514+
15001515
// ---------------------------------------------------------------------------
15011516

15021517
DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright (c) 2022, 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+
package android.gui;
18+
19+
20+
/**
21+
* Input event drop modes: Input event drop options for windows and its children.
22+
*
23+
* @hide
24+
*/
25+
@Backing(type="int")
26+
enum DropInputMode {
27+
/**
28+
* Default mode, input events are sent to the target as usual.
29+
*/
30+
NONE,
31+
32+
/**
33+
* Window and its children will not receive any input even if it has a valid input channel.
34+
* Touches and keys will be dropped. If a window is focused, it will remain focused but will
35+
* not receive any keys. If the window has a touchable region and is the target of an input
36+
* event, the event will be dropped and will not go to the window behind. ref: b/197296414
37+
*/
38+
ALL,
39+
}
40+

libs/gui/include/gui/LayerState.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <gui/ITransactionCompletedListener.h>
2626
#include <math/mat4.h>
2727

28+
#include <android/gui/DropInputMode.h>
2829
#ifndef NO_INPUT
2930
#include <input/InputWindow.h>
3031
#endif
@@ -106,6 +107,7 @@ struct layer_state_t {
106107
eProducerDisconnect = 0x100'00000000,
107108
eFixedTransformHintChanged = 0x200'00000000,
108109
eTrustedOverlayChanged = 0x400'00000000,
110+
eDropInputModeChanged = 0x8000'00000000,
109111
};
110112

111113
layer_state_t()
@@ -141,7 +143,8 @@ struct layer_state_t {
141143
frameRate(0.0f),
142144
frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
143145
fixedTransformHint(ui::Transform::ROT_INVALID),
144-
isTrustedOverlay(false) {
146+
isTrustedOverlay(false),
147+
dropInputMode(gui::DropInputMode::NONE) {
145148
matrix.dsdx = matrix.dtdy = 1.0f;
146149
matrix.dsdy = matrix.dtdx = 0.0f;
147150
hdrMetadata.validTypes = 0;
@@ -243,6 +246,9 @@ struct layer_state_t {
243246
// An inherited state that indicates that this surface control and its children
244247
// should be trusted for input occlusion detection purposes
245248
bool isTrustedOverlay;
249+
250+
// Force inputflinger to drop all input events for the layer and its children.
251+
gui::DropInputMode dropInputMode;
246252
};
247253

248254
struct ComposerState {

libs/gui/include/gui/SurfaceComposerClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ class SurfaceComposerClient : public RefBase
531531

532532
// Sets that this surface control and its children are trusted overlays for input
533533
Transaction& setTrustedOverlay(const sp<SurfaceControl>& sc, bool isTrustedOverlay);
534-
534+
535+
Transaction& setDropInputMode(const sp<SurfaceControl>& sc, gui::DropInputMode mode);
535536
status_t setDisplaySurface(const sp<IBinder>& token,
536537
const sp<IGraphicBufferProducer>& bufferProducer);
537538

services/surfaceflinger/Layer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Layer::Layer(const LayerCreationArgs& args)
119119
mCurrentState.treeHasFrameRateVote = false;
120120
mCurrentState.fixedTransformHint = ui::Transform::ROT_INVALID;
121121
mCurrentState.isTrustedOverlay = false;
122+
mCurrentState.dropInputMode = gui::DropInputMode::NONE;
122123

123124
if (args.flags & ISurfaceComposerClient::eNoColorFill) {
124125
// Set an invalid color so there is no color fill.
@@ -2645,6 +2646,16 @@ Layer::FrameRateCompatibility Layer::FrameRate::convertCompatibility(int8_t comp
26452646
}
26462647
}
26472648

2649+
bool Layer::setDropInputMode(gui::DropInputMode mode) {
2650+
if (mCurrentState.dropInputMode == mode) {
2651+
return false;
2652+
}
2653+
mCurrentState.dropInputMode = mode;
2654+
mCurrentState.modified = true;
2655+
mCurrentState.inputInfoChanged = true;
2656+
setTransactionFlags(eTransactionNeeded);
2657+
return true;
2658+
}
26482659
// ---------------------------------------------------------------------------
26492660

26502661
}; // namespace android

services/surfaceflinger/Layer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#pragma once
1818

19+
#include <android/gui/DropInputMode.h>
1920
#include <compositionengine/LayerFE.h>
2021
#include <gui/BufferQueue.h>
2122
#include <gui/ISurfaceComposerClient.h>
@@ -282,6 +283,8 @@ class Layer : public virtual RefBase, compositionengine::LayerFE {
282283

283284
// Whether or not this layer is a trusted overlay for input
284285
bool isTrustedOverlay;
286+
287+
gui::DropInputMode dropInputMode;
285288
};
286289

287290
explicit Layer(const LayerCreationArgs& args);
@@ -410,6 +413,8 @@ class Layer : public virtual RefBase, compositionengine::LayerFE {
410413
bool setShadowRadius(float shadowRadius);
411414
virtual bool setFrameRateSelectionPriority(int32_t priority);
412415
virtual bool setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint);
416+
bool setDropInputMode(gui::DropInputMode);
417+
413418
// If the variable is not set on the layer, it traverses up the tree to inherit the frame
414419
// rate priority from its parent.
415420
virtual int32_t getFrameRateSelectionPriority() const;

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3867,6 +3867,15 @@ uint32_t SurfaceFlinger::setClientStateLocked(
38673867
ALOGE("Attempt to set trusted overlay without permission ACCESS_SURFACE_FLINGER");
38683868
}
38693869
}
3870+
if (what & layer_state_t::eDropInputModeChanged) {
3871+
if (privileged) {
3872+
if (layer->setDropInputMode(s.dropInputMode)) {
3873+
flags |= eTraversalNeeded;
3874+
}
3875+
} else {
3876+
ALOGE("Attempt to update InputPolicyFlags without permission ACCESS_SURFACE_FLINGER");
3877+
}
3878+
}
38703879
// This has to happen after we reparent children because when we reparent to null we remove
38713880
// child layers from current state and remove its relative z. If the children are reparented in
38723881
// the same transaction, then we have to make sure we reparent the children first so we do not

0 commit comments

Comments
 (0)