mDividerControllerLocked = new DockedStackDividerController(service, this);
mPinnedStackControllerLocked = new PinnedStackController(service, this);
- mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth);
+ // We use this as our arbitrary surface size for buffer-less parents
+ // that don't impose cropping on their children. It may need to be larger
+ // than the display size because fullscreen windows can be shifted offscreen
+ // due to surfaceInsets. 2 times the largest display dimension feels like an
+ // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
+ // layers the ability to match their parent sizes and be able to skip
+ // such arbitrary size settings.
+ mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
.setSize(mSurfaceSize, mSurfaceSize)
}, false /* traverseTopToBottom */);
}
- void enableSurfaceTrace(FileDescriptor fd) {
- forAllWindows(w -> {
- w.mWinAnimator.enableSurfaceTrace(fd);
- }, true /* traverseTopToBottom */);
- }
-
- void disableSurfaceTrace() {
- forAllWindows(w -> {
- w.mWinAnimator.disableSurfaceTrace();
- }, true /* traverseTopToBottom */);
- }
-
/**
* Starts the Keyguard exit animation on all windows that don't belong to an app token.
*/
if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
t.setLayer(mSplitScreenDividerAnchor, layer++);
}
- if (s.isSelfOrChildAnimating()) {
+ if (s.isAppAnimating() && state != ALWAYS_ON_TOP_STATE) {
// Ensure the animation layer ends up above the
// highest animating stack and no higher.
layerForAnimationLayer = layer++;
super(name, service);
}
+ @Override
+ void assignChildLayers(SurfaceControl.Transaction t) {
+ assignChildLayers(t, null /* imeContainer */);
+ }
+
void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
boolean needAssignIme = imeContainer != null
&& imeContainer.getSurfaceControl() != null;
import android.os.ParcelFileDescriptor;
import android.os.PowerManager;
import android.os.RemoteException;
-import android.os.SystemClock;
import android.os.UserHandle;
-import android.provider.Settings;
import android.util.ArraySet;
import android.util.EventLog;
import android.util.Slog;
import java.util.List;
import java.util.function.Consumer;
-import static android.app.AppOpsManager.MODE_ALLOWED;
-import static android.app.AppOpsManager.MODE_DEFAULT;
-import static android.app.AppOpsManager.OP_NONE;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
private final ArrayList<TaskStack> mTmpStackList = new ArrayList();
private final ArrayList<Integer> mTmpStackIds = new ArrayList<>();
- // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
- // instances will be replaced with an instance that writes a binary representation of all
- // commands to mSurfaceTraceFd.
- boolean mSurfaceTraceEnabled;
- ParcelFileDescriptor mSurfaceTraceFd;
- RemoteEventTrace mRemoteEventTrace;
-
final WallpaperController mWallpaperController;
private final Handler mHandler;
void updateAppOpsState() {
forAllWindows((w) -> {
- if (w.mAppOp == OP_NONE) {
- return;
- }
- final int mode = mService.mAppOps.noteOpNoThrow(w.mAppOp, w.getOwningUid(),
- w.getOwningPackage());
- w.setAppOpVisibilityLw(mode == MODE_ALLOWED || mode == MODE_DEFAULT);
+ w.updateAppOpsState();
}, false /* traverseTopToBottom */);
}
}
}
- void enableSurfaceTrace(ParcelFileDescriptor pfd) {
- final FileDescriptor fd = pfd.getFileDescriptor();
- if (mSurfaceTraceEnabled) {
- disableSurfaceTrace();
- }
- mSurfaceTraceEnabled = true;
- mRemoteEventTrace = new RemoteEventTrace(mService, fd);
- mSurfaceTraceFd = pfd;
- for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
- final DisplayContent dc = mChildren.get(displayNdx);
- dc.enableSurfaceTrace(fd);
- }
- }
-
- void disableSurfaceTrace() {
- mSurfaceTraceEnabled = false;
- mRemoteEventTrace = null;
- mSurfaceTraceFd = null;
- for (int displayNdx = mChildren.size() - 1; displayNdx >= 0; --displayNdx) {
- final DisplayContent dc = mChildren.get(displayNdx);
- dc.disableSurfaceTrace();
- }
- }
-
void dumpDisplayContents(PrintWriter pw) {
pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
if (mService.mDisplayReady) {
import static com.android.server.wm.WindowManagerDebugConfig.TAG_KEEP_SCREEN_ON;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
-import static com.android.server.wm.proto.WindowManagerServiceProto.APP_TRANSITION;
-import static com.android.server.wm.proto.WindowManagerServiceProto.DISPLAY_FROZEN;
-import static com.android.server.wm.proto.WindowManagerServiceProto.FOCUSED_APP;
-import static com.android.server.wm.proto.WindowManagerServiceProto.FOCUSED_WINDOW;
-import static com.android.server.wm.proto.WindowManagerServiceProto.INPUT_METHOD_WINDOW;
-import static com.android.server.wm.proto.WindowManagerServiceProto.LAST_ORIENTATION;
-import static com.android.server.wm.proto.WindowManagerServiceProto.POLICY;
-import static com.android.server.wm.proto.WindowManagerServiceProto.ROOT_WINDOW_CONTAINER;
-import static com.android.server.wm.proto.WindowManagerServiceProto.ROTATION;
+import static com.android.server.wm.proto.WindowManagerServiceDumpProto.APP_TRANSITION;
+import static com.android.server.wm.proto.WindowManagerServiceDumpProto.DISPLAY_FROZEN;
+import static com.android.server.wm.proto.WindowManagerServiceDumpProto.FOCUSED_APP;
+import static com.android.server.wm.proto.WindowManagerServiceDumpProto.FOCUSED_WINDOW;
+import static com.android.server.wm.proto.WindowManagerServiceDumpProto.INPUT_METHOD_WINDOW;
+import static com.android.server.wm.proto.WindowManagerServiceDumpProto.LAST_ORIENTATION;
+import static com.android.server.wm.proto.WindowManagerServiceDumpProto.POLICY;
+import static com.android.server.wm.proto.WindowManagerServiceDumpProto.ROOT_WINDOW_CONTAINER;
+import static com.android.server.wm.proto.WindowManagerServiceDumpProto.ROTATION;
import android.Manifest;
import android.Manifest.permission;
try {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "openSurfaceTransaction");
synchronized (mWindowMap) {
- if (mRoot.mSurfaceTraceEnabled) {
- mRoot.mRemoteEventTrace.openSurfaceTransaction();
- }
SurfaceControl.openTransaction();
}
} finally {
try {
traceStateLocked(where);
} finally {
- if (mRoot.mSurfaceTraceEnabled) {
- mRoot.mRemoteEventTrace.closeSurfaceTransaction();
- }
SurfaceControl.closeTransaction();
}
}
win.attach();
mWindowMap.put(client.asBinder(), win);
- if (win.mAppOp != AppOpsManager.OP_NONE) {
- int startOpResult = mAppOps.startOpNoThrow(win.mAppOp, win.getOwningUid(),
- win.getOwningPackage());
- if ((startOpResult != AppOpsManager.MODE_ALLOWED) &&
- (startOpResult != AppOpsManager.MODE_DEFAULT)) {
- win.setAppOpVisibilityLw(false);
- }
- }
+
+ win.initAppOpsState();
final boolean hideSystemAlertWindows = !mHidingNonSystemOverlayWindows.isEmpty();
win.setForceHideNonSystemOverlayWindowIfNeeded(hideSystemAlertWindows);
return false;
}
- @Override
- public void enableSurfaceTrace(ParcelFileDescriptor pfd) {
- final int callingUid = Binder.getCallingUid();
- if (callingUid != SHELL_UID && callingUid != ROOT_UID) {
- throw new SecurityException("Only shell can call enableSurfaceTrace");
- }
-
- synchronized (mWindowMap) {
- mRoot.enableSurfaceTrace(pfd);
- }
- }
-
- @Override
- public void disableSurfaceTrace() {
- final int callingUid = Binder.getCallingUid();
- if (callingUid != SHELL_UID && callingUid != ROOT_UID &&
- callingUid != SYSTEM_UID) {
- throw new SecurityException("Only shell can call disableSurfaceTrace");
- }
- synchronized (mWindowMap) {
- mRoot.disableSurfaceTrace();
- }
- }
-
/**
* Set mScreenCaptureDisabled for specific user
*/
void postWindowRemoveCleanupLocked(WindowState win) {
if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "postWindowRemoveCleanupLocked: " + win);
mWindowMap.remove(win.mClient.asBinder());
- if (win.mAppOp != AppOpsManager.OP_NONE) {
- mAppOps.finishOp(win.mAppOp, win.getOwningUid(), win.getOwningPackage());
- }
+
+ win.resetAppOpsState();
if (mCurrentFocus == null) {
mWinRemovedSinceNullFocus.add(win);
win.setLastReportedMergedConfiguration(mergedConfiguration);
+ // Update the last inset values here because the values are sent back to the client.
+ // The last inset values represent the last client state.
+ win.updateLastInsetValues();
+
outFrame.set(win.mCompatFrame);
outOverscanInsets.set(win.mOverscanInsets);
outContentInsets.set(win.mContentInsets);
IRecentsAnimationRunner recentsAnimationRunner,
RecentsAnimationController.RecentsAnimationCallbacks callbacks, int displayId) {
synchronized (mWindowMap) {
- cancelRecentsAnimation();
mRecentsAnimationController = new RecentsAnimationController(this,
recentsAnimationRunner, callbacks, displayId);
mRecentsAnimationController.initialize();
}
public void cancelRecentsAnimation() {
- synchronized (mWindowMap) {
- if (mRecentsAnimationController != null) {
- // This call will call through to cleanupAnimation() below after the animation is
- // canceled
- mRecentsAnimationController.cancelAnimation();
- }
+ // Note: Do not hold the WM lock, this will lock appropriately in the call which also
+ // calls through to AM/RecentsAnimation.onAnimationFinished()
+ if (mRecentsAnimationController != null) {
+ // This call will call through to cleanupAnimation() below after the animation is
+ // canceled
+ mRecentsAnimationController.cancelAnimation();
}
}
mDockedStackCreateBounds = bounds;
}
+ public void checkSplitScreenMinimizedChanged(boolean animate) {
+ synchronized (mWindowMap) {
+ final DisplayContent displayContent = getDefaultDisplayContentLocked();
+ displayContent.getDockedDividerController().checkMinimizeChanged(animate);
+ }
+ }
+
public boolean isValidPictureInPictureAspectRatio(int displayId, float aspectRatio) {
final DisplayContent displayContent = mRoot.getDisplayContent(displayId);
return displayContent.getPinnedStackController().isValidPictureInPictureAspectRatio(
/**
* Write to a protocol buffer output stream. Protocol buffer message definition is at
- * {@link com.android.server.wm.proto.WindowManagerServiceProto}.
+ * {@link com.android.server.wm.proto.WindowManagerServiceDumpProto}.
*
* @param proto Stream to write the WindowContainer object to.
* @param trim If true, reduce the amount of data written.
float mExtraHScale = (float) 1.0;
float mExtraVScale = (float) 1.0;
+ // An offset in pixel of the surface contents from the window position. Used for Wallpaper
+ // to provide the effect of scrolling within a large surface. We just use these values as
+ // a cache.
+ int mXOffset = 0;
+ int mYOffset = 0;
+
private final Rect mTmpSize = new Rect();
private final SurfaceControl.Transaction mReparentTransaction = new SurfaceControl.Transaction();
flags |= SurfaceControl.SECURE;
}
- mTmpSize.set(w.mFrame.left + w.mXOffset, w.mFrame.top + w.mYOffset, 0, 0);
+ mTmpSize.set(0, 0, 0, 0);
calculateSurfaceBounds(w, attrs);
final int width = mTmpSize.width();
final int height = mTmpSize.height();
// WindowState.prepareSurfaces expands for surface insets (in order they don't get
// clipped by the WindowState surface), so we need to go into the other direction here.
- tmpMatrix.postTranslate(mWin.mXOffset + mWin.mAttrs.surfaceInsets.left,
- mWin.mYOffset + mWin.mAttrs.surfaceInsets.top);
+ tmpMatrix.postTranslate(mWin.mAttrs.surfaceInsets.left,
+ mWin.mAttrs.surfaceInsets.top);
// "convert" it into SurfaceFlinger's format
mDtDx = tmpFloats[Matrix.MSKEW_Y];
mDtDy = tmpFloats[Matrix.MSKEW_X];
mDsDy = tmpFloats[Matrix.MSCALE_Y];
- float x = tmpFloats[Matrix.MTRANS_X];
- float y = tmpFloats[Matrix.MTRANS_Y];
- mWin.mShownPosition.set(Math.round(x), Math.round(y));
// Now set the alpha... but because our current hardware
// can't do alpha transformation on a non-opaque surface,
mShownAlpha = mAlpha;
if (!mService.mLimitedAlphaCompositing
|| (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
- || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDtDy, mDsDy)
- && x == frame.left && y == frame.top))) {
+ || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDtDy, mDsDy)))) {
//Slog.i(TAG_WM, "Applying alpha transform");
if (screenAnimation) {
mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
TAG, "computeShownFrameLocked: " + this +
" not attached, mAlpha=" + mAlpha);
- // WindowState.prepareSurfaces expands for surface insets (in order they don't get
- // clipped by the WindowState surface), so we need to go into the other direction here.
- mWin.mShownPosition.set(mWin.mXOffset + mWin.mAttrs.surfaceInsets.left,
- mWin.mYOffset + mWin.mAttrs.surfaceInsets.top);
mShownAlpha = mAlpha;
mHaveMatrix = false;
mDsDx = mWin.mGlobalScale;
if (DEBUG_WINDOW_CROP) Slog.d(TAG, "win=" + w + " Initial clip rect: " + clipRect
+ " fullscreen=" + fullscreen);
- if (isFreeformResizing && !w.isChildWindow()) {
- // For freeform resizing non child windows, we are using the big surface positioned
- // at 0,0. Thus we must express the crop in that coordinate space.
- clipRect.offset(w.mShownPosition.x, w.mShownPosition.y);
- }
-
w.expandForSurfaceInsets(clipRect);
// The clip rect was generated assuming (0,0) as the window origin,
final LayoutParams attrs = mWin.getAttrs();
final Task task = w.getTask();
- mTmpSize.set(w.mShownPosition.x, w.mShownPosition.y, 0, 0);
+ mTmpSize.set(0, 0, 0, 0);
calculateSurfaceBounds(w, attrs);
mExtraHScale = (float) 1.0;
float surfaceWidth = mSurfaceController.getWidth();
float surfaceHeight = mSurfaceController.getHeight();
+ final Rect insets = attrs.surfaceInsets;
+
if (isForceScaled()) {
- int hInsets = attrs.surfaceInsets.left + attrs.surfaceInsets.right;
- int vInsets = attrs.surfaceInsets.top + attrs.surfaceInsets.bottom;
+ int hInsets = insets.left + insets.right;
+ int vInsets = insets.top + insets.bottom;
float surfaceContentWidth = surfaceWidth - hInsets;
float surfaceContentHeight = surfaceHeight - vInsets;
if (!mForceScaleUntilResize) {
mSurfaceController.forceScaleableInTransaction(true);
}
- int posX = mTmpSize.left;
- int posY = mTmpSize.top;
+ int posX = 0;
+ int posY = 0;
task.mStack.getDimBounds(mTmpStackBounds);
boolean allowStretching = false;
posX -= (int) (tw * mExtraHScale * mTmpSourceBounds.left);
posY -= (int) (th * mExtraVScale * mTmpSourceBounds.top);
- // Always clip to the stack bounds since the surface can be larger with the current
- // scale
- clipRect = null;
+ // In pinned mode the clip rectangle applied to us by our stack has been
+ // expanded outwards to allow for shadows. However in case of source bounds set
+ // we need to crop to within the surface. The code above has scaled and positioned
+ // the surface to fit the unexpanded stack bounds, but now we need to reapply
+ // the cropping that the stack would have applied if it weren't expanded. This
+ // can be different in each direction based on the source bounds.
+ clipRect = mTmpClipRect;
+ clipRect.set((int)((insets.left + mTmpSourceBounds.left) * tw),
+ (int)((insets.top + mTmpSourceBounds.top) * th),
+ insets.left + (int)(surfaceWidth
+ - (tw* (surfaceWidth - mTmpSourceBounds.right))),
+ insets.top + (int)(surfaceHeight
+ - (th * (surfaceHeight - mTmpSourceBounds.bottom))));
} else {
// We want to calculate the scaling based on the content area, not based on
// the entire surface, so that we scale in sync with windows that don't have insets.
// non inset content at the same position, we have to shift the whole window
// forward. Likewise for scaling up, we've increased this distance, and we need
// to shift by a negative number to compensate.
- posX += attrs.surfaceInsets.left * (1 - mExtraHScale);
- posY += attrs.surfaceInsets.top * (1 - mExtraVScale);
+ posX += insets.left * (1 - mExtraHScale);
+ posY += insets.top * (1 - mExtraVScale);
mSurfaceController.setPositionInTransaction((float) Math.floor(posX),
(float) Math.floor(posY), recoveringMemory);
mForceScaleUntilResize = true;
} else {
if (!w.mSeamlesslyRotated) {
- mSurfaceController.setPositionInTransaction(mTmpSize.left, mTmpSize.top,
- recoveringMemory);
+ mSurfaceController.setPositionInTransaction(0, 0, recoveringMemory);
}
}
mSurfaceController.setTransparentRegionHint(region);
}
- void setWallpaperOffset(Point shownPosition) {
- final LayoutParams attrs = mWin.getAttrs();
- final int left = shownPosition.x - attrs.surfaceInsets.left;
- final int top = shownPosition.y - attrs.surfaceInsets.top;
+ boolean setWallpaperOffset(int dx, int dy) {
+ if (mXOffset == dx && mYOffset == dy) {
+ return false;
+ }
+ mXOffset = dx;
+ mYOffset = dy;
try {
if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
mService.openSurfaceTransaction();
- mSurfaceController.setPositionInTransaction(mWin.mFrame.left + left,
- mWin.mFrame.top + top, false);
+ mSurfaceController.setPositionInTransaction(dx, dy, false);
applyCrop(null, false);
} catch (RuntimeException e) {
Slog.w(TAG, "Error positioning surface of " + mWin
- + " pos=(" + left + "," + top + ")", e);
+ + " pos=(" + dx + "," + dy + ")", e);
} finally {
mService.closeSurfaceTransaction("setWallpaperOffset");
if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
"<<< CLOSE TRANSACTION setWallpaperOffset");
+ return true;
}
}
DsDy * w.mVScale, false);
}
- void enableSurfaceTrace(FileDescriptor fd) {
- if (mSurfaceController != null) {
- mSurfaceController.installRemoteTrace(fd);
- }
- }
-
- void disableSurfaceTrace() {
- if (mSurfaceController != null) {
- try {
- mSurfaceController.removeRemoteTrace();
- } catch (ClassCastException e) {
- Slog.e(TAG, "Disable surface trace for " + this + " but its not enabled");
- }
- }
- }
-
/** The force-scaled state for a given window can persist past
* the state for it's stack as the windows complete resizing
* independently of one another.