From 4e8dd649b4c72122cdf15da9cfabc45aac789365 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Sat, 6 Sep 2014 17:07:51 +0200 Subject: [PATCH] Ensuring that we retry if the callback for animation started comes before the Recents activity starts. (Bug 17316671) Change-Id: I8e50e2cd9ba6a47dda21f21afbe14bb9d3eda979 --- .../recents/AlternateRecentsComponent.java | 29 +++++++++++++++++-- .../systemui/recents/RecentsActivity.java | 3 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java index 64617bf76a6c4..5fa9fa497a46a 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java @@ -16,10 +16,12 @@ package com.android.systemui.recents; +import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityOptions; import android.appwidget.AppWidgetProviderInfo; import android.content.ActivityNotFoundException; +import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -563,11 +565,34 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta public void onAnimationStarted() { // Notify recents to start the enter animation if (!mStartAnimationTriggered) { + // There can be a race condition between the start animation callback and + // the start of the new activity (where we register the receiver that listens + // to this broadcast, so we add our own receiver and if that gets called, then + // we know the activity has not yet started and we can retry sending the broadcast. + BroadcastReceiver fallbackReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (getResultCode() == Activity.RESULT_OK) { + mStartAnimationTriggered = true; + return; + } + + // Schedule for the broadcast to be sent again after some time + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + onAnimationStarted(); + } + }, 75); + } + }; + + // Send the broadcast to notify Recents that the animation has started Intent intent = new Intent(ACTION_START_ENTER_ANIMATION); intent.setPackage(mContext.getPackageName()); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); - mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); - mStartAnimationTriggered = true; + mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null, + fallbackReceiver, null, Activity.RESULT_CANCELED, null, null); } } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index ec7799a0bddb3..8f92027206d34 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -146,6 +146,9 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView ReferenceCountedTrigger t = new ReferenceCountedTrigger(context, null, null, null); mRecentsView.startEnterRecentsAnimation(new ViewAnimation.TaskViewEnterContext(t)); onEnterAnimationTriggered(); + // Notify the fallback receiver that we have successfully got the broadcast + // See AlternateRecentsComponent.onAnimationStarted() + setResultCode(Activity.RESULT_OK); } } };