Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13f6ea78 authored by Craig Mautner's avatar Craig Mautner
Browse files

Avoid unnecessary timeouts.

And fix a couple of other inefficiencies.

Fixes bug 15444410.

Change-Id: Idad95d4e4d70bc7d2965e1bd6ff3d3135b73dd9c
parent 61606cec
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -167,5 +167,5 @@ public abstract class WindowManagerInternal {
     * Invalidate all visible windows. Then report back on the callback once all windows have
     * redrawn.
     */
    public abstract void waitForAllWindowsDrawn(IRemoteCallback callback, long timeout);
    public abstract void waitForAllWindowsDrawn(Runnable callback, long timeout);
}
+9 −9
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import android.database.ContentObserver;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.media.AudioManager;
import android.media.AudioSystem;
import android.media.IAudioService;
import android.media.Ringtone;
import android.media.RingtoneManager;
@@ -51,7 +50,6 @@ import android.os.Bundle;
import android.os.FactoryTest;
import android.os.Handler;
import android.os.IBinder;
import android.os.IRemoteCallback;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
@@ -105,7 +103,6 @@ import com.android.internal.policy.PolicyManager;
import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.telephony.ITelephony;
import com.android.internal.widget.PointerLocationView;
import com.android.server.LocalServices;

@@ -270,10 +267,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    // The following are only accessed on the mHandler thread.
    boolean mKeyguardDrawComplete;
    boolean mWindowManagerDrawComplete;
    ArrayList<ScreenOnListener> mScreenOnListeners = new ArrayList<ScreenOnListener>();
    final IRemoteCallback mWindowManagerDrawCallback = new IRemoteCallback.Stub() {
    ScreenOnListener mScreenOnListener;
    final Runnable mWindowManagerDrawCallback = new Runnable() {
        @Override
        public void sendResult(Bundle data) {
        public void run() {
            if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
            mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
        }
@@ -4543,7 +4540,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    // Called on the mHandler thread.
    private void handleWakingUp(final ScreenOnListener screenOnListener) {
        if (screenOnListener != null) {
            mScreenOnListeners.add(screenOnListener);
            mScreenOnListener = screenOnListener;
        }

        synchronized (mLock) {
@@ -4575,8 +4572,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            return;
        }

        ScreenOnListener screenOnListener;
        synchronized (mLock) {
            mScreenOnFully = true;
            screenOnListener = mScreenOnListener;
            mScreenOnListener = null;
        }

        try {
@@ -4584,8 +4584,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        } catch (RemoteException unhandled) {
        }

        for (int i = mScreenOnListeners.size() - 1; i >=0; --i) {
            mScreenOnListeners.remove(i).onScreenOn();
        if (screenOnListener != null) {
            screenOnListener.onScreenOn();
        }

        setKeyguardDrawn();
+20 −18
Original line number Diff line number Diff line
@@ -411,7 +411,7 @@ public class WindowManagerService extends IWindowManager.Stub
    /**
     * And the callback to make when they've all been drawn.
     */
    IRemoteCallback mWaitingForDrawnCallback;
    Runnable mWaitingForDrawnCallback;

    /**
     * Windows that have called relayout() while we were running animations,
@@ -7561,7 +7561,7 @@ public class WindowManagerService extends IWindowManager.Stub
                }

                case WAITING_FOR_DRAWN_TIMEOUT: {
                    IRemoteCallback callback = null;
                    Runnable callback = null;
                    synchronized (mWindowMap) {
                        Slog.w(TAG, "Timeout waiting for drawn: undrawn=" + mWaitingForDrawn);
                        mWaitingForDrawn.clear();
@@ -7569,10 +7569,7 @@ public class WindowManagerService extends IWindowManager.Stub
                        mWaitingForDrawnCallback = null;
                    }
                    if (callback != null) {
                        try {
                            callback.sendResult(null);
                        } catch (RemoteException e) {
                        }
                        callback.run();
                    }
                    break;
                }
@@ -7626,16 +7623,13 @@ public class WindowManagerService extends IWindowManager.Stub
                    }
                    break;
                case ALL_WINDOWS_DRAWN: {
                    IRemoteCallback callback;
                    Runnable callback;
                    synchronized (mWindowMap) {
                        callback = mWaitingForDrawnCallback;
                        mWaitingForDrawnCallback = null;
                    }
                    if (callback != null) {
                        try {
                            callback.sendResult(null);
                        } catch (RemoteException e) {
                        }
                        callback.run();
                    }
                }
                case NEW_ANIMATOR_SCALE: {
@@ -9555,8 +9549,9 @@ public class WindowManagerService extends IWindowManager.Stub
            }
        }

        if (mInnerFields.mOrientationChangeComplete && !defaultDisplay.layoutNeeded
                && !mInnerFields.mUpdateRotation) {
        if (mWaitingForDrawnCallback != null ||
                (mInnerFields.mOrientationChangeComplete && !defaultDisplay.layoutNeeded &&
                        !mInnerFields.mUpdateRotation)) {
            checkDrawnWindowsLocked();
        }

@@ -11141,24 +11136,31 @@ public class WindowManagerService extends IWindowManager.Stub
            }
        }

        public void waitForAllWindowsDrawn(IRemoteCallback callback, long timeout) {
        public void waitForAllWindowsDrawn(Runnable callback, long timeout) {
            synchronized (mWindowMap) {
                mWaitingForDrawnCallback = callback;
                final WindowList windows = getDefaultWindowListLocked();
                for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
                    final WindowState win = windows.get(winNdx);
                    if (win.mHasSurface) {
                    if (win.mHasSurface && win.isWinVisibleLw()) {
                        if (!win.mIsWallpaper) {
                            // Don't force wallpaper to redraw.
                            win.mWinAnimator.mDrawState = WindowStateAnimator.DRAW_PENDING;
                        }
                        // Force add to mResizingWindows.
                        win.mLastContentInsets.set(-1, -1, -1, -1);
                        mWaitingForDrawn.add(win);
                    }
                }
                requestTraversalLocked();
            }
            mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT);
            if (mWaitingForDrawn.isEmpty()) {
                callback.run();
            } else {
                mH.sendEmptyMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT, timeout);
            }
                checkDrawnWindowsLocked();
            }
        }
    }
}