OSDN Git Service

FloatingActionMode: Avoid calling delayed code if view is inactive.
authorAbodunrinwa Toki <toki@google.com>
Thu, 21 Jul 2016 10:10:19 +0000 (11:10 +0100)
committerAbodunrinwa Toki <toki@google.com>
Thu, 29 Sep 2016 09:53:21 +0000 (10:53 +0100)
If something's gone wrong with the floating toolbar's host view while
there is logic posted in a runnable, avoid running that code.

These runnable callbacks are currently removed when the action mode
is finished but the issue we're running into is something else.
Seems like the app doesn't get a chance to call finish when something
went wrong with the view or host activity. Anyway, defend against
this case.

Test: Not able to reproduce the issue. This code is a defensive
fix to prevent reported crashes in GSA. Will keep if the crashes no
longer happen or revert if they continue to happen.
Bug: 29951043
Change-Id: I0e7833b8d8a63bf6205b7035b477bd8a3a7968b2

core/java/com/android/internal/view/FloatingActionMode.java

index 1203dd2..effe219 100644 (file)
@@ -59,15 +59,19 @@ public class FloatingActionMode extends ActionMode {
 
     private final Runnable mMovingOff = new Runnable() {
         public void run() {
-            mFloatingToolbarVisibilityHelper.setMoving(false);
-            mFloatingToolbarVisibilityHelper.updateToolbarVisibility();
+            if (isViewStillActive()) {
+                mFloatingToolbarVisibilityHelper.setMoving(false);
+                mFloatingToolbarVisibilityHelper.updateToolbarVisibility();
+            }
         }
     };
 
     private final Runnable mHideOff = new Runnable() {
         public void run() {
-            mFloatingToolbarVisibilityHelper.setHideRequested(false);
-            mFloatingToolbarVisibilityHelper.updateToolbarVisibility();
+            if (isViewStillActive()) {
+                mFloatingToolbarVisibilityHelper.setHideRequested(false);
+                mFloatingToolbarVisibilityHelper.updateToolbarVisibility();
+            }
         }
     };
 
@@ -301,6 +305,11 @@ public class FloatingActionMode extends ActionMode {
         mOriginatingView.removeCallbacks(mHideOff);
     }
 
+    private boolean isViewStillActive() {
+        return mOriginatingView.getWindowVisibility() == View.VISIBLE
+                && mOriginatingView.isShown();
+    }
+
     /**
      * A helper for showing/hiding the floating toolbar depending on certain states.
      */