private void updateWindowsAppsAndRotationAnimationsLocked() { final ArrayList<AppWindowToken> appTokens = mService.mAnimatingAppTokens; int i; final int NAT = appTokens.size(); for (i = 0; i < NAT; i++) { final AppWindowAnimator appAnimator = appTokens.get(i).mAppAnimator; final boolean wasAnimating = appAnimator.animation != null && appAnimator.animation != AppWindowAnimator.sDummyAnimation; if (appAnimator.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) { mAnimating = true; } else if (wasAnimating) { // stopped animating, do one more pass through the layout mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { mService.debugLayoutRepeats( "appToken " + appAnimator.mAppToken + " done", mPendingLayoutChanges); } if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + appAnimator.mAppToken); } } final int NEAT = mService.mExitingAppTokens.size(); for (i = 0; i < NEAT; i++) { final AppWindowAnimator appAnimator = mService.mExitingAppTokens.get(i).mAppAnimator; final boolean wasAnimating = appAnimator.animation != null && appAnimator.animation != AppWindowAnimator.sDummyAnimation; if (appAnimator.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) { mAnimating = true; } else if (wasAnimating) { // stopped animating, do one more pass through the layout mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { mService.debugLayoutRepeats( "exiting appToken " + appAnimator.mAppToken + " done", mPendingLayoutChanges); } if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating exiting " + appAnimator.mAppToken); } } if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) { if (mScreenRotationAnimation.stepAnimationLocked(mCurrentTime)) { mAnimating = true; } else { mBulkUpdateParams |= SET_UPDATE_ROTATION; mScreenRotationAnimation.kill(); mScreenRotationAnimation = null; } } }
public void onWindowLayersChangedLocked() { if (DEBUG_LAYERS) { Slog.i(LOG_TAG, "Layers changed."); } mMagnifedViewport.recomputeBoundsLocked(); mWindowManagerService.scheduleAnimationLocked(); }
/* Notifies that the input device configuration has changed. */ public void notifyConfigurationChanged() { mService.sendNewConfiguration(); synchronized (mInputDevicesReadyMonitor) { if (!mInputDevicesReady) { mInputDevicesReady = true; mInputDevicesReadyMonitor.notifyAll(); } } }
private void testTokenMayBeDrawnLocked() { // See if any windows have been drawn, so they (and others // associated with them) can now be shown. final ArrayList<AppWindowToken> appTokens = mService.mAnimatingAppTokens; final int NT = appTokens.size(); for (int i = 0; i < NT; i++) { AppWindowToken wtoken = appTokens.get(i); final boolean allDrawn = wtoken.allDrawn; if (allDrawn != wtoken.mAppAnimator.allDrawn) { wtoken.mAppAnimator.allDrawn = allDrawn; if (allDrawn) { // The token has now changed state to having all // windows shown... what to do, what to do? if (wtoken.mAppAnimator.freezingScreen) { wtoken.mAppAnimator.showAllWindowsLocked(); mService.unsetAppFreezingScreenLocked(wtoken, false, true); if (WindowManagerService.DEBUG_ORIENTATION) Slog.i( TAG, "Setting mOrientationChangeComplete=true because wtoken " + wtoken + " numInteresting=" + wtoken.numInterestingWindows + " numDrawn=" + wtoken.numDrawnWindows); // This will set mOrientationChangeComplete and cause a pass through layout. mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; } else { mPendingLayoutChanges |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { mService.debugLayoutRepeats("testTokenMayBeDrawnLocked", mPendingLayoutChanges); } // We can now show all of the drawn windows! if (!mService.mOpeningApps.contains(wtoken)) { mAnimating |= wtoken.mAppAnimator.showAllWindowsLocked(); } } } } } }
/* Notifies the window manager about a broken input channel. * * Called by the InputManager. */ public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { if (inputWindowHandle == null) { return; } synchronized (mService.mWindowMap) { WindowState windowState = (WindowState) inputWindowHandle.windowState; if (windowState != null) { Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState); mService.removeWindowLocked(windowState.mSession, windowState); } } }
void hideWallpapersLocked(final WindowState w) { if ((mService.mWallpaperTarget == w && mService.mLowerWallpaperTarget == null) || mService.mWallpaperTarget == null) { for (final WindowToken token : mService.mWallpaperTokens) { for (final WindowState wallpaper : token.windows) { final WindowStateAnimator winAnimator = wallpaper.mWinAnimator; if (!winAnimator.mLastHidden) { winAnimator.hide(); mService.dispatchWallpaperVisibility(wallpaper, false); mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; } } token.hidden = true; } } }
/* Notifies the window manager about an application that is not responding. * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch. * * Called by the InputManager. */ public long notifyANR( InputApplicationHandle inputApplicationHandle, InputWindowHandle inputWindowHandle) { AppWindowToken appWindowToken = null; synchronized (mService.mWindowMap) { WindowState windowState = null; if (inputWindowHandle != null) { windowState = (WindowState) inputWindowHandle.windowState; if (windowState != null) { appWindowToken = windowState.mAppToken; } } if (appWindowToken == null && inputApplicationHandle != null) { appWindowToken = (AppWindowToken) inputApplicationHandle.appWindowToken; } if (windowState != null) { Slog.i( WindowManagerService.TAG, "Input event dispatching timed out " + "sending to " + windowState.mAttrs.getTitle()); } else if (appWindowToken != null) { Slog.i( WindowManagerService.TAG, "Input event dispatching timed out " + "sending to application " + appWindowToken.stringName); } else { Slog.i(WindowManagerService.TAG, "Input event dispatching timed out."); } mService.saveANRStateLocked(appWindowToken, windowState); } if (appWindowToken != null && appWindowToken.appToken != null) { try { // Notify the activity manager about the timeout and let it decide whether // to abort dispatching or keep waiting. boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); if (!abort) { // The activity manager declined to abort dispatching. // Wait a bit longer and timeout again later. return appWindowToken.inputDispatchingTimeoutNanos; } } catch (RemoteException ex) { } } return 0; // abort dispatching }
public void setMagnificationSpecLocked(MagnificationSpec spec) { mMagnifedViewport.updateMagnificationSpecLocked(spec); mMagnifedViewport.recomputeBoundsLocked(); mWindowManagerService.scheduleAnimationLocked(); }
/* Notifies the window manager about an application that is not responding. * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch. * * Called by the InputManager. */ @Override public long notifyANR( InputApplicationHandle inputApplicationHandle, InputWindowHandle inputWindowHandle, String reason) { AppWindowToken appWindowToken = null; WindowState windowState = null; boolean aboveSystem = false; synchronized (mService.mWindowMap) { if (inputWindowHandle != null) { windowState = (WindowState) inputWindowHandle.windowState; if (windowState != null) { appWindowToken = windowState.mAppToken; } } if (appWindowToken == null && inputApplicationHandle != null) { appWindowToken = (AppWindowToken) inputApplicationHandle.appWindowToken; } if (windowState != null) { Slog.i( TAG_WM, "Input event dispatching timed out " + "sending to " + windowState.mAttrs.getTitle() + ". Reason: " + reason); // Figure out whether this window is layered above system windows. // We need to do this here to help the activity manager know how to // layer its ANR dialog. int systemAlertLayer = mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); aboveSystem = windowState.mBaseLayer > systemAlertLayer; } else if (appWindowToken != null) { Slog.i( TAG_WM, "Input event dispatching timed out " + "sending to application " + appWindowToken.stringName + ". Reason: " + reason); } else { Slog.i(TAG_WM, "Input event dispatching timed out " + ". Reason: " + reason); } mService.saveANRStateLocked(appWindowToken, windowState, reason); } if (appWindowToken != null && appWindowToken.appToken != null) { try { // Notify the activity manager about the timeout and let it decide whether // to abort dispatching or keep waiting. boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(reason); if (!abort) { // The activity manager declined to abort dispatching. // Wait a bit longer and timeout again later. return appWindowToken.inputDispatchingTimeoutNanos; } } catch (RemoteException ex) { } } else if (windowState != null) { try { // Notify the activity manager about the timeout and let it decide whether // to abort dispatching or keep waiting. long timeout = ActivityManagerNative.getDefault() .inputDispatchingTimedOut(windowState.mSession.mPid, aboveSystem, reason); if (timeout >= 0) { // The activity manager declined to abort dispatching. // Wait a bit longer and timeout again later. return timeout * 1000000L; // nanoseconds } } catch (RemoteException ex) { } } return 0; // abort dispatching }
void startDimming( final WindowStateAnimator winAnimator, final float target, final int width, final int height) { if (mDimAnimator == null) { mDimAnimator = new DimAnimator(mService.mFxSession); } // Only set dim params on the highest dimmed layer. final WindowStateAnimator dimWinAnimator = mDimParams == null ? null : mDimParams.mDimWinAnimator; // Don't turn on for an unshown surface, or for any layer but the highest dimmed one. if (winAnimator.mSurfaceShown && (dimWinAnimator == null || !dimWinAnimator.mSurfaceShown || dimWinAnimator.mAnimLayer < winAnimator.mAnimLayer)) { /** * Author: Onskreen Date: 21/12/2012 * * <p>Sets the dimming rect and position as per panel(main or either of cornerstone panels)'s * current position in which this window is running. */ if (winAnimator.mWin != null) { if (winAnimator.mWin.mAppToken != null) { IBinder token = winAnimator.mWin.mAppToken.token; if (token != null) { WindowPanel wp = mService.findWindowPanel(token); if (wp != null) { Rect dimRect = new Rect(); dimRect.set(wp.getPos()); mDimAnimator.mDimX = dimRect.left; mDimAnimator.mDimY = dimRect.top; mService.mH.sendMessage( mService.mH.obtainMessage( SET_DIM_PARAMETERS, new DimAnimator.Parameters( winAnimator, dimRect.width(), dimRect.height(), target))); } else { mService.mH.sendMessage( mService.mH.obtainMessage( SET_DIM_PARAMETERS, new DimAnimator.Parameters(winAnimator, width, height, target))); } } else { mService.mH.sendMessage( mService.mH.obtainMessage( SET_DIM_PARAMETERS, new DimAnimator.Parameters(winAnimator, width, height, target))); } } else { mService.mH.sendMessage( mService.mH.obtainMessage( SET_DIM_PARAMETERS, new DimAnimator.Parameters(winAnimator, width, height, target))); } } else { mService.mH.sendMessage( mService.mH.obtainMessage( SET_DIM_PARAMETERS, new DimAnimator.Parameters(winAnimator, width, height, target))); } } }
synchronized void animate() { mPendingLayoutChanges = 0; mCurrentTime = SystemClock.uptimeMillis(); mBulkUpdateParams = 0; boolean wasAnimating = mAnimating; mAnimating = false; if (WindowManagerService.DEBUG_WINDOW_TRACE) { Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime); } // Update animations of all applications, including those // associated with exiting/removed apps Surface.openTransaction(); try { updateWindowsAppsAndRotationAnimationsLocked(); performAnimationsLocked(); testWallpaperAndBackgroundLocked(); // THIRD LOOP: Update the surfaces of all windows. if (mScreenRotationAnimation != null) { mScreenRotationAnimation.updateSurfaces(); } final int N = mWinAnimators.size(); for (int i = 0; i < N; i++) { mWinAnimators.get(i).prepareSurfaceLocked(true); } if (mDimParams != null) { mDimAnimator.updateParameters(mContext.getResources(), mDimParams, mCurrentTime); } if (mDimAnimator != null && mDimAnimator.mDimShown) { mAnimating |= mDimAnimator.updateSurface(isDimming(), mCurrentTime, !mService.okToDisplay()); } if (mService.mBlackFrame != null) { if (mScreenRotationAnimation != null) { mService.mBlackFrame.setMatrix( mScreenRotationAnimation.getEnterTransformation().getMatrix()); } else { mService.mBlackFrame.clearMatrix(); } } if (mService.mWatermark != null) { mService.mWatermark.drawIfNeeded(); } } catch (RuntimeException e) { Log.wtf(TAG, "Unhandled exception in Window Manager", e); } finally { Surface.closeTransaction(); } mService.bulkSetParameters(mBulkUpdateParams, mPendingLayoutChanges); if (mAnimating) { mService.scheduleAnimationLocked(); } else if (wasAnimating) { mService.requestTraversalLocked(); } if (WindowManagerService.DEBUG_WINDOW_TRACE) { Slog.i( TAG, "!!! animate: exit mAnimating=" + mAnimating + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams) + " mPendingLayoutChanges=" + Integer.toHexString(mPendingLayoutChanges)); } }
private void updateWindowsAndWallpaperLocked() { ++mAnimTransactionSequence; ArrayList<WindowStateAnimator> unForceHiding = null; boolean wallpaperInUnForceHiding = false; for (int i = mService.mWindows.size() - 1; i >= 0; i--) { WindowState win = mService.mWindows.get(i); WindowStateAnimator winAnimator = win.mWinAnimator; final int flags = winAnimator.mAttrFlags; if (winAnimator.mSurface != null) { final boolean wasAnimating = winAnimator.mWasAnimating; final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime); if (WindowManagerService.DEBUG_WALLPAPER) { Slog.v(TAG, win + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating); } // If this window is animating, make a note that we have // an animating window and take care of a request to run // a detached wallpaper animation. if (nowAnimating) { if (winAnimator.mAnimation != null) { if ((flags & FLAG_SHOW_WALLPAPER) != 0 && winAnimator.mAnimation.getDetachWallpaper()) { mDetachedWallpaper = win; } final int backgroundColor = winAnimator.mAnimation.getBackgroundColor(); if (backgroundColor != 0) { if (mWindowAnimationBackground == null || (winAnimator.mAnimLayer < mWindowAnimationBackground.mWinAnimator.mAnimLayer)) { mWindowAnimationBackground = win; mWindowAnimationBackgroundColor = backgroundColor; } } } mAnimating = true; } // If this window's app token is running a detached wallpaper // animation, make a note so we can ensure the wallpaper is // displayed behind it. final AppWindowAnimator appAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator; if (appAnimator != null && appAnimator.animation != null && appAnimator.animating) { if ((flags & FLAG_SHOW_WALLPAPER) != 0 && appAnimator.animation.getDetachWallpaper()) { mDetachedWallpaper = win; } final int backgroundColor = appAnimator.animation.getBackgroundColor(); if (backgroundColor != 0) { if (mWindowAnimationBackground == null || (winAnimator.mAnimLayer < mWindowAnimationBackground.mWinAnimator.mAnimLayer)) { mWindowAnimationBackground = win; mWindowAnimationBackgroundColor = backgroundColor; } } } if (wasAnimating && !winAnimator.mAnimating && mService.mWallpaperTarget == win) { mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2", mPendingLayoutChanges); } } if (mPolicy.doesForceHide(win, win.mAttrs)) { if (!wasAnimating && nowAnimating) { if (WindowManagerService.DEBUG_ANIM || WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Animation started that could impact force hide: " + win); mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED; mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { mService.debugLayoutRepeats( "updateWindowsAndWallpaperLocked 3", mPendingLayoutChanges); } mService.mFocusMayChange = true; } if (win.isReadyForDisplay() && winAnimator.mAnimationIsEntrance) { mForceHiding = true; } if (WindowManagerService.DEBUG_VISIBILITY) Slog.v( TAG, "Force hide " + mForceHiding + " hasSurface=" + win.mHasSurface + " policyVis=" + win.mPolicyVisibility + " destroying=" + win.mDestroying + " attHidden=" + win.mAttachedHidden + " vis=" + win.mViewVisibility + " hidden=" + win.mRootToken.hidden + " anim=" + win.mWinAnimator.mAnimation); } else if (mPolicy.canBeForceHidden(win, win.mAttrs)) { final boolean changed; if (mForceHiding && (!winAnimator.isAnimating() || (winAnimator.mAttrFlags & FLAG_SHOW_WHEN_LOCKED) == 0)) { changed = win.hideLw(false, false); if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG, "Now policy hidden: " + win); } else { changed = win.showLw(false, false); if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG, "Now policy shown: " + win); if (changed) { if ((mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0 && win.isVisibleNow() /*w.isReadyForDisplay()*/) { if (unForceHiding == null) { unForceHiding = new ArrayList<WindowStateAnimator>(); } unForceHiding.add(winAnimator); if ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { wallpaperInUnForceHiding = true; } } if (mCurrentFocus == null || mCurrentFocus.mLayer < win.mLayer) { // We are showing on to of the current // focus, so re-evaluate focus to make // sure it is correct. mService.mFocusMayChange = true; } } } if (changed && (flags & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { mService.debugLayoutRepeats( "updateWindowsAndWallpaperLocked 4", mPendingLayoutChanges); } } } } final AppWindowToken atoken = win.mAppToken; if (winAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW) { if (atoken == null || atoken.allDrawn) { if (winAnimator.performShowLocked()) { mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; if (WindowManagerService.DEBUG_LAYOUT_REPEATS) { mService.debugLayoutRepeats( "updateWindowsAndWallpaperLocked 5", mPendingLayoutChanges); } } } } final AppWindowAnimator appAnimator = atoken == null ? null : atoken.mAppAnimator; if (appAnimator != null && appAnimator.thumbnail != null) { if (appAnimator.thumbnailTransactionSeq != mAnimTransactionSequence) { appAnimator.thumbnailTransactionSeq = mAnimTransactionSequence; appAnimator.thumbnailLayer = 0; } if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) { appAnimator.thumbnailLayer = winAnimator.mAnimLayer; } } } // end forall windows // If we have windows that are being show due to them no longer // being force-hidden, apply the appropriate animation to them. if (unForceHiding != null) { for (int i = unForceHiding.size() - 1; i >= 0; i--) { Animation a = mPolicy.createForceHideEnterAnimation(wallpaperInUnForceHiding); if (a != null) { final WindowStateAnimator winAnimator = unForceHiding.get(i); winAnimator.setAnimation(a); winAnimator.mAnimationIsEntrance = true; } } } }