Merge "WM: Mark task overlays as trusted overlays"

This commit is contained in:
Rob Carr
2022-02-05 00:11:36 +00:00
committed by Android (Google) Code Review
6 changed files with 37 additions and 19 deletions

View File

@@ -473,7 +473,7 @@ final class GameServiceProviderInstanceImpl implements GameServiceProviderInstan
}
try {
mWindowManagerInternal.addTaskOverlay(
mWindowManagerInternal.addTrustedTaskOverlay(
taskId,
createGameSessionResult.getSurfacePackage());
} catch (IllegalArgumentException ex) {
@@ -519,7 +519,7 @@ final class GameServiceProviderInstanceImpl implements GameServiceProviderInstan
SurfacePackage surfacePackage = gameSessionRecord.getSurfacePackage();
if (surfacePackage != null) {
try {
mWindowManagerInternal.removeTaskOverlay(
mWindowManagerInternal.removeTrustedTaskOverlay(
gameSessionRecord.getTaskId(),
surfacePackage);
} catch (IllegalArgumentException ex) {

View File

@@ -32,14 +32,20 @@ import java.util.ArrayList;
*
* Also handles multiplexing of event dispatch and tracking of overlays
* to make things easier for WindowContainer.
*
* These overlays are to be used for various types of System UI and UI
* under the systems control. Provided SurfacePackages will be able
* to overlay application content, without engaging the usual cross process
* obscured touch filtering mechanisms. It's imperative that all UI provided
* be under complete control of the system.
*/
class OverlayHost {
class TrustedOverlayHost {
// Lazily initialized when required
SurfaceControl mSurfaceControl;
final ArrayList<SurfaceControlViewHost.SurfacePackage> mOverlays = new ArrayList<>();
final WindowManagerService mWmService;
OverlayHost(WindowManagerService wms) {
TrustedOverlayHost(WindowManagerService wms) {
mWmService = wms;
}
@@ -51,6 +57,8 @@ class OverlayHost {
.setName("Overlay Host Leash");
mSurfaceControl = b.build();
SurfaceControl.Transaction t = mWmService.mTransactionFactory.get();
t.setTrustedOverlay(mSurfaceControl, true).apply();
}
}

View File

@@ -314,7 +314,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
private final List<WindowContainerListener> mListeners = new ArrayList<>();
protected OverlayHost mOverlayHost;
protected TrustedOverlayHost mOverlayHost;
WindowContainer(WindowManagerService wms) {
mWmService = wms;
@@ -3600,9 +3600,9 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
@AnimationType int type, @Nullable AnimationAdapter snapshotAnim);
}
void addOverlay(SurfaceControlViewHost.SurfacePackage overlay) {
void addTrustedOverlay(SurfaceControlViewHost.SurfacePackage overlay) {
if (mOverlayHost == null) {
mOverlayHost = new OverlayHost(mWmService);
mOverlayHost = new TrustedOverlayHost(mWmService);
}
mOverlayHost.addOverlay(overlay, mSurfaceControl);
@@ -3613,11 +3613,11 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
overlay.getRemoteInterface().onConfigurationChanged(getConfiguration());
} catch (Exception e) {
Slog.e(TAG, "Error sending initial configuration change to WindowContainer overlay");
removeOverlay(overlay);
removeTrustedOverlay(overlay);
}
}
void removeOverlay(SurfaceControlViewHost.SurfacePackage overlay) {
void removeTrustedOverlay(SurfaceControlViewHost.SurfacePackage overlay) {
if (mOverlayHost != null && !mOverlayHost.removeOverlay(overlay)) {
mOverlayHost.release();
mOverlayHost = null;

View File

@@ -827,6 +827,11 @@ public abstract class WindowManagerInternal {
* Internal methods for other parts of SystemServer to manage
* SurfacePackage based overlays on tasks.
*
* Since these overlays will overlay application content, they exist
* in a container with setTrustedOverlay(true). This means its imperative
* that this overlay feature only be used with UI completely under the control
* of the system, without 3rd party content.
*
* Callers prepare a view hierarchy with SurfaceControlViewHost
* and send the package to WM here. The remote view hierarchy will receive
* configuration change, lifecycle events, etc, forwarded over the
@@ -837,8 +842,10 @@ public abstract class WindowManagerInternal {
* The embedded hierarchy exists in a coordinate space relative to the task
* bounds.
*/
public abstract void addTaskOverlay(int taskId, SurfaceControlViewHost.SurfacePackage overlay);
public abstract void removeTaskOverlay(int taskId, SurfaceControlViewHost.SurfacePackage overlay);
public abstract void addTrustedTaskOverlay(int taskId,
SurfaceControlViewHost.SurfacePackage overlay);
public abstract void removeTrustedTaskOverlay(int taskId,
SurfaceControlViewHost.SurfacePackage overlay);
/**
* Get a SurfaceControl that is the container layer that should be used to receive input to

View File

@@ -8012,27 +8012,29 @@ public class WindowManagerService extends IWindowManager.Stub
@Override
public boolean shouldRestoreImeVisibility(IBinder imeTargetWindowToken) {
return WindowManagerService.this.shouldRestoreImeVisibility(imeTargetWindowToken);
}
}
@Override
public void addTaskOverlay(int taskId, SurfaceControlViewHost.SurfacePackage overlay) {
public void addTrustedTaskOverlay(int taskId,
SurfaceControlViewHost.SurfacePackage overlay) {
synchronized (mGlobalLock) {
final Task task = mRoot.getRootTask(taskId);
if (task == null) {
throw new IllegalArgumentException("no task with taskId" + taskId);
}
task.addOverlay(overlay);
task.addTrustedOverlay(overlay);
}
}
@Override
public void removeTaskOverlay(int taskId, SurfaceControlViewHost.SurfacePackage overlay) {
public void removeTrustedTaskOverlay(int taskId,
SurfaceControlViewHost.SurfacePackage overlay) {
synchronized (mGlobalLock) {
final Task task = mRoot.getRootTask(taskId);
if (task == null) {
throw new IllegalArgumentException("no task with taskId" + taskId);
}
task.removeOverlay(overlay);
task.removeTrustedOverlay(overlay);
}
}

View File

@@ -406,7 +406,7 @@ public final class GameServiceProviderInstanceImplTest {
mFakeGameSessionService.removePendingFutureForTaskId(10)
.complete(new CreateGameSessionResult(gameSession10, mockSurfacePackage10));
verify(mMockWindowManagerInternal).addTaskOverlay(eq(10), eq(mockSurfacePackage10));
verify(mMockWindowManagerInternal).addTrustedTaskOverlay(eq(10), eq(mockSurfacePackage10));
}
@Test
@@ -556,8 +556,9 @@ public final class GameServiceProviderInstanceImplTest {
stopTask(10);
verify(mMockWindowManagerInternal).addTaskOverlay(eq(10), eq(mockSurfacePackage10));
verify(mMockWindowManagerInternal).removeTaskOverlay(eq(10), eq(mockSurfacePackage10));
verify(mMockWindowManagerInternal).addTrustedTaskOverlay(eq(10), eq(mockSurfacePackage10));
verify(mMockWindowManagerInternal).removeTrustedTaskOverlay(eq(10),
eq(mockSurfacePackage10));
}
@Test