Blank Screen in Emergency Call UI screen

Blank Screen is observed When Emergency Call is
initiated one after ending other with in a short
gap. The reason for this is CircularRevealAnimation
is not succesfully completed sometimes when Screen
is locked and leading to unhandling CallCardFragment.
With the current design CallCardFragment is shown
only when RevealAnimation is finished succesfully.

The fix is to setup some expiry to the animation
and If Animation is not finished with in expiry
then launch CallCardfragment.The expiry duration
is set as Animation duration + 200ms.

Change-Id: I46e9dac9fb148efc1556f577c2822b0dd8e03b68
CRs-Fixed: 1062926
diff --git a/InCallUI/src/com/android/incallui/CircularRevealFragment.java b/InCallUI/src/com/android/incallui/CircularRevealFragment.java
index 01bd253..f9816de 100644
--- a/InCallUI/src/com/android/incallui/CircularRevealFragment.java
+++ b/InCallUI/src/com/android/incallui/CircularRevealFragment.java
@@ -24,6 +24,7 @@
 import android.graphics.Outline;
 import android.graphics.Point;
 import android.os.Bundle;
+import android.os.Handler;
 import android.view.Display;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -39,9 +40,16 @@
 public class CircularRevealFragment extends Fragment {
     static final String TAG = "CircularRevealFragment";
 
+    // This is used to extend the expiration time of Circular reveal
+    // animation. So over all time the handler waits is Animation
+    // duration + REVEAL_ADDITIONAL_EXPIRATION_TIME and notifies
+    // the Circular reveal completion to listeners.
+    private static final int REVEAL_ADDITIONAL_EXPIRATION_TIME = 200;
+
     private Point mTouchPoint;
     private OnCircularRevealCompleteListener mListener;
     private boolean mAnimationStarted;
+    private boolean mAnimationFinished;
 
     interface OnCircularRevealCompleteListener {
         public void onCircularRevealComplete(FragmentManager fm);
@@ -123,6 +131,7 @@
         view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
             @Override
             public boolean onPreDraw() {
+                mAnimationFinished = false;
                 final ViewTreeObserver vto = view.getViewTreeObserver();
                 if (vto.isAlive()) {
                     vto.removeOnPreDrawListener(this);
@@ -132,13 +141,31 @@
                     animator.addListener(new AnimatorListenerAdapter() {
                         @Override
                         public void onAnimationEnd(Animator animation) {
+                            Log.w(TAG, " CircularRevealFragment - onAnimationEnd");
                             view.setClipToOutline(false);
-                            if (mListener != null) {
+                            if (mListener != null && mAnimationFinished == false) {
                                 mListener.onCircularRevealComplete(getFragmentManager());
+                                mAnimationFinished = true;
                             }
                         }
                     });
                     animator.start();
+                    // If somehow the animator is failed to run from lower layers,
+                    // need to wait for certain expiration time and inform the
+                    // listeners with OnCircularComplete callback so that rest of
+                    // the things will not be blocked.
+                    Handler handler = new Handler();
+                    handler.postDelayed(new Runnable() {
+                         @Override
+                         public void run() {
+                             Log.w(TAG, " Failed to complete animation");
+                             if (mListener != null && mAnimationFinished == false) {
+                                 mListener.onCircularRevealComplete(getFragmentManager());
+                                 mAnimationFinished = true;
+                             }
+                         }
+                    }, getResources().getInteger(R.integer.reveal_animation_duration) +
+                            REVEAL_ADDITIONAL_EXPIRATION_TIME);
                 }
                 return false;
             }