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

Commit f8146d56 authored by Praveena Pachipulusu's avatar Praveena Pachipulusu Committed by Steve Kondik
Browse files

frameworks/base: Fix to avoid UI freeze issue.

Due to some race condition in WindowManagerService, Screenshot
layer remains as topmost and buffers are not flipped hence
no updates seen on the screen. So, trying to destroy persistent
layer explicitly if freeze timeout expires 6sec.

Change-Id: Ibe295550a7431a4f633a57e7dfab0cbda102ab87
parent 07f66bae
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@ import android.view.SurfaceSession;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Transformation;
import android.os.Handler;
import android.os.Message;
import com.android.server.DisplayThread;
import android.os.Looper;

class ScreenRotationAnimation {
    static final String TAG = "ScreenRotationAnimation";
@@ -130,6 +134,7 @@ class ScreenRotationAnimation {
    private boolean mMoreStartExit;
    private boolean mMoreStartFrame;
    long mHalfwayPoint;
    final H mHandler = new H(DisplayThread.get().getLooper());

    public void printTo(String prefix, PrintWriter pw) {
        pw.print(prefix); pw.print("mSurface="); pw.print(mSurfaceControl);
@@ -269,6 +274,12 @@ class ScreenRotationAnimation {
                mSurfaceControl.setAlpha(0);
                mSurfaceControl.show();
                sur.destroy();
                // If screenshot layer stays for more than freeze
                // timeout value with no updates on the screen,
                // destroy the layer explicitly.
                mHandler.removeMessages(H.SCREENSHOT_FREEZE_TIMEOUT);
                mHandler.sendEmptyMessageDelayed(H.SCREENSHOT_FREEZE_TIMEOUT,
                                           H.FREEZE_TIMEOUT_VAL);
            } catch (OutOfResourcesException e) {
                Slog.w(TAG, "Unable to allocate freeze surface", e);
            }
@@ -1007,4 +1018,37 @@ class ScreenRotationAnimation {
    public Transformation getEnterTransformation() {
        return mEnterTransformation;
    }

    final class H extends Handler {
        public static final int SCREENSHOT_FREEZE_TIMEOUT = 2;

        //Set the freeze timeout value to 6sec (which is greater than
        //APP_FREEZE_TIMEOUT value in WindowManagerService)
        public static final int FREEZE_TIMEOUT_VAL = 6000;

        public H(Looper looper) {
            super(looper, null, true /*async*/);
        }

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SCREENSHOT_FREEZE_TIMEOUT: {
                     if ((mSurfaceControl != null) && (isAnimating())) {
                        Slog.e(TAG, "Exceeded Freeze timeout. Destroy layers");
                        kill();
                     } else if (mSurfaceControl != null){
                        Slog.e(TAG,
                          "No animation, exceeded freeze timeout. Destroy Screenshot layer");
                        mSurfaceControl.destroy();
                        mSurfaceControl = null;
                     }
                     break;
                }
                default:
                     Slog.e(TAG, "No Valid Message To Handle");
                break;
            }
        }
    }
}