Skip to content

Commit 7605fb4

Browse files
author
Winson Chung
committed
Add mechanism for a task's windows to be trusted overlays (SF)
- Add a layer state to indicate that this layer and its children in the hierarchy are trusted. This can only be set by callers holding ACCESS_SURFACE_FLINGER, and will be used for the PIP task layer to indicate that activities in PIP are trusted (as they are controlled only by the user and SystemUI) Bug: 191529039 Bug: 196389741 Test: TBD Change-Id: Id92ccb087bd0d8dbaeeef3ba50b67fe015e53db8 Merged-In: Id92ccb087bd0d8dbaeeef3ba50b67fe015e53db8
1 parent 39bc611 commit 7605fb4

14 files changed

Lines changed: 115 additions & 1 deletion

File tree

cmds/surfacereplayer/proto/src/trace.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ message SurfaceChange {
5353
ReparentChildrenChange reparent_children = 20;
5454
BackgroundBlurRadiusChange background_blur_radius = 21;
5555
ShadowRadiusChange shadow_radius = 22;
56+
TrustedOverlayChange trusted_overlay = 23;
5657
}
5758
}
5859

@@ -208,4 +209,8 @@ message DetachChildrenChange {
208209

209210
message ShadowRadiusChange {
210211
required float radius = 1;
212+
}
213+
214+
message TrustedOverlayChange {
215+
required float is_trusted_overlay = 1;
211216
}

libs/gui/LayerState.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ status_t layer_state_t::write(Parcel& output) const
117117
output.writeFloat(frameRate);
118118
output.writeByte(frameRateCompatibility);
119119
output.writeUint32(fixedTransformHint);
120+
output.writeBool(isTrustedOverlay);
121+
120122
return NO_ERROR;
121123
}
122124

@@ -200,6 +202,8 @@ status_t layer_state_t::read(const Parcel& input)
200202
frameRate = input.readFloat();
201203
frameRateCompatibility = input.readByte();
202204
fixedTransformHint = static_cast<ui::Transform::RotationFlags>(input.readUint32());
205+
isTrustedOverlay = input.readBool();
206+
203207
return NO_ERROR;
204208
}
205209

@@ -439,6 +443,10 @@ void layer_state_t::merge(const layer_state_t& other) {
439443
what |= eFixedTransformHintChanged;
440444
fixedTransformHint = other.fixedTransformHint;
441445
}
446+
if (other.what & eTrustedOverlayChanged) {
447+
what |= eTrustedOverlayChanged;
448+
isTrustedOverlay = other.isTrustedOverlay;
449+
}
442450
if ((other.what & what) != other.what) {
443451
ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
444452
"other.what=0x%" PRIu64 " what=0x%" PRIu64,

libs/gui/SurfaceComposerClient.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,19 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFixed
14841484
return *this;
14851485
}
14861486

1487+
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTrustedOverlay(
1488+
const sp<SurfaceControl>& sc, bool isTrustedOverlay) {
1489+
layer_state_t* s = getLayerState(sc);
1490+
if (!s) {
1491+
mStatus = BAD_INDEX;
1492+
return *this;
1493+
}
1494+
1495+
s->what |= layer_state_t::eTrustedOverlayChanged;
1496+
s->isTrustedOverlay = isTrustedOverlay;
1497+
return *this;
1498+
}
1499+
14871500
// ---------------------------------------------------------------------------
14881501

14891502
DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) {

libs/gui/include/gui/LayerState.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ struct layer_state_t {
105105
eBackgroundBlurRadiusChanged = 0x80'00000000,
106106
eProducerDisconnect = 0x100'00000000,
107107
eFixedTransformHintChanged = 0x200'00000000,
108+
eTrustedOverlayChanged = 0x400'00000000,
108109
};
109110

110111
layer_state_t()
@@ -139,7 +140,8 @@ struct layer_state_t {
139140
frameRateSelectionPriority(-1),
140141
frameRate(0.0f),
141142
frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
142-
fixedTransformHint(ui::Transform::ROT_INVALID) {
143+
fixedTransformHint(ui::Transform::ROT_INVALID),
144+
isTrustedOverlay(false) {
143145
matrix.dsdx = matrix.dtdy = 1.0f;
144146
matrix.dsdy = matrix.dtdx = 0.0f;
145147
hdrMetadata.validTypes = 0;
@@ -237,6 +239,10 @@ struct layer_state_t {
237239
// a buffer of a different size. -1 means the transform hint is not set,
238240
// otherwise the value will be a valid ui::Rotation.
239241
ui::Transform::RotationFlags fixedTransformHint;
242+
243+
// An inherited state that indicates that this surface control and its children
244+
// should be trusted for input occlusion detection purposes
245+
bool isTrustedOverlay;
240246
};
241247

242248
struct ComposerState {

libs/gui/include/gui/SurfaceComposerClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@ class SurfaceComposerClient : public RefBase
529529
// a buffer of a different size.
530530
Transaction& setFixedTransformHint(const sp<SurfaceControl>& sc, int32_t transformHint);
531531

532+
// Sets that this surface control and its children are trusted overlays for input
533+
Transaction& setTrustedOverlay(const sp<SurfaceControl>& sc, bool isTrustedOverlay);
534+
532535
status_t setDisplaySurface(const sp<IBinder>& token,
533536
const sp<IGraphicBufferProducer>& bufferProducer);
534537

services/surfaceflinger/Layer.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,23 @@ bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relati
11421142
return true;
11431143
}
11441144

1145+
bool Layer::setTrustedOverlay(bool isTrustedOverlay) {
1146+
if (mCurrentState.isTrustedOverlay == isTrustedOverlay) return false;
1147+
mCurrentState.isTrustedOverlay = isTrustedOverlay;
1148+
mCurrentState.modified = true;
1149+
mCurrentState.inputInfoChanged = true;
1150+
setTransactionFlags(eTransactionNeeded);
1151+
return true;
1152+
}
1153+
1154+
bool Layer::isTrustedOverlay() const {
1155+
if (getDrawingState().isTrustedOverlay) {
1156+
return true;
1157+
}
1158+
const auto& p = mDrawingParent.promote();
1159+
return (p != nullptr) && p->isTrustedOverlay();
1160+
}
1161+
11451162
bool Layer::setSize(uint32_t w, uint32_t h) {
11461163
if (mCurrentState.requested_legacy.w == w && mCurrentState.requested_legacy.h == h)
11471164
return false;
@@ -2245,6 +2262,7 @@ void Layer::writeToProtoDrawingState(LayerProto* layerInfo, uint32_t traceFlags,
22452262
layerInfo->set_effective_scaling_mode(getEffectiveScalingMode());
22462263

22472264
layerInfo->set_corner_radius(getRoundedCornerState().radius);
2265+
layerInfo->set_is_trusted_overlay(isTrustedOverlay());
22482266
LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform());
22492267
LayerProtoHelper::writePositionToProto(transform.tx(), transform.ty(),
22502268
[&]() { return layerInfo->mutable_position(); });
@@ -2435,6 +2453,10 @@ InputWindowInfo Layer::fillInputInfo() {
24352453
info.touchableRegion = info.touchableRegion.intersect(Rect{cropLayer->mScreenBounds});
24362454
}
24372455

2456+
// Inherit the trusted state from the parent hierarchy, but don't clobber the trusted state
2457+
// if it was set by WM for a known system overlay
2458+
info.trustedOverlay = info.trustedOverlay || isTrustedOverlay();
2459+
24382460
// If the layer is a clone, we need to crop the input region to cloned root to prevent
24392461
// touches from going outside the cloned area.
24402462
if (isClone()) {

services/surfaceflinger/Layer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ class Layer : public virtual RefBase, compositionengine::LayerFE {
279279
// a buffer of a different size. ui::Transform::ROT_INVALID means the
280280
// a fixed transform hint is not set.
281281
ui::Transform::RotationFlags fixedTransformHint;
282+
283+
// Whether or not this layer is a trusted overlay for input
284+
bool isTrustedOverlay;
282285
};
283286

284287
explicit Layer(const LayerCreationArgs& args);
@@ -356,6 +359,7 @@ class Layer : public virtual RefBase, compositionengine::LayerFE {
356359
// is specified in pixels.
357360
virtual bool setBackgroundBlurRadius(int backgroundBlurRadius);
358361
virtual bool setTransparentRegionHint(const Region& transparent);
362+
virtual bool setTrustedOverlay(bool);
359363
virtual bool setFlags(uint8_t flags, uint8_t mask);
360364
virtual bool setLayerStack(uint32_t layerStack);
361365
virtual uint32_t getLayerStack() const;
@@ -1064,6 +1068,7 @@ class Layer : public virtual RefBase, compositionengine::LayerFE {
10641068
const std::vector<Layer*>& layersInTree);
10651069

10661070
void updateTreeHasFrameRateVote();
1071+
bool isTrustedOverlay() const;
10671072

10681073
// Cached properties computed from drawing state
10691074
// Effective transform taking into account parent transforms and any parent scaling.

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3858,6 +3858,15 @@ uint32_t SurfaceFlinger::setClientStateLocked(
38583858
flags |= eTraversalNeeded | eTransformHintUpdateNeeded;
38593859
}
38603860
}
3861+
if (what & layer_state_t::eTrustedOverlayChanged) {
3862+
if (privileged) {
3863+
if (layer->setTrustedOverlay(s.isTrustedOverlay)) {
3864+
flags |= eTraversalNeeded;
3865+
}
3866+
} else {
3867+
ALOGE("Attempt to set trusted overlay without permission ACCESS_SURFACE_FLINGER");
3868+
}
3869+
}
38613870
// This has to happen after we reparent children because when we reparent to null we remove
38623871
// child layers from current state and remove its relative z. If the children are reparented in
38633872
// the same transaction, then we have to make sure we reparent the children first so we do not

services/surfaceflinger/SurfaceInterceptor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void SurfaceInterceptor::addInitialSurfaceStateLocked(Increment* increment,
130130
getLayerIdFromWeakRef(layer->mCurrentState.zOrderRelativeOf),
131131
layer->mCurrentState.z);
132132
addShadowRadiusLocked(transaction, layerId, layer->mCurrentState.shadowRadius);
133+
addTrustedOverlayLocked(transaction, layerId, layer->mDrawingState.isTrustedOverlay);
133134
}
134135

135136
void SurfaceInterceptor::addInitialDisplayStateLocked(Increment* increment,
@@ -388,6 +389,13 @@ void SurfaceInterceptor::addShadowRadiusLocked(Transaction* transaction, int32_t
388389
overrideChange->set_radius(shadowRadius);
389390
}
390391

392+
void SurfaceInterceptor::addTrustedOverlayLocked(Transaction* transaction, int32_t layerId,
393+
bool isTrustedOverlay) {
394+
SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
395+
TrustedOverlayChange* overrideChange(change->mutable_trusted_overlay());
396+
overrideChange->set_is_trusted_overlay(isTrustedOverlay);
397+
}
398+
391399
void SurfaceInterceptor::addSurfaceChangesLocked(Transaction* transaction,
392400
const layer_state_t& state)
393401
{
@@ -467,6 +475,9 @@ void SurfaceInterceptor::addSurfaceChangesLocked(Transaction* transaction,
467475
if (state.what & layer_state_t::eShadowRadiusChanged) {
468476
addShadowRadiusLocked(transaction, layerId, state.shadowRadius);
469477
}
478+
if (state.what & layer_state_t::eTrustedOverlayChanged) {
479+
addTrustedOverlayLocked(transaction, layerId, state.isTrustedOverlay);
480+
}
470481
}
471482

472483
void SurfaceInterceptor::addDisplayChangesLocked(Transaction* transaction,

services/surfaceflinger/SurfaceInterceptor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class SurfaceInterceptor final : public android::SurfaceInterceptor {
168168
void addRelativeParentLocked(Transaction* transaction, int32_t layerId, int32_t parentId,
169169
int z);
170170
void addShadowRadiusLocked(Transaction* transaction, int32_t layerId, float shadowRadius);
171+
void addTrustedOverlayLocked(Transaction* transaction, int32_t layerId, bool isTrustedOverlay);
171172

172173
// Add display transactions to the trace
173174
DisplayChange* createDisplayChangeLocked(Transaction* transaction, int32_t sequenceId);

0 commit comments

Comments
 (0)