Merge "Add debug logs to debug flaky workspace binding" into tm-qpr-dev am: b32fd3a556 am: 01ebdf81a7

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/22163528

Change-Id: I04aa2458a861f403ae82dce1fd7965aaf2ed20f4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2023-04-03 21:34:47 +00:00
committed by Automerger Merge Worker
@@ -16,11 +16,13 @@
package com.android.launcher3.util; package com.android.launcher3.util;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnAttachStateChangeListener; import android.view.View.OnAttachStateChangeListener;
import android.view.ViewTreeObserver.OnDrawListener; import android.view.ViewTreeObserver.OnDrawListener;
import com.android.launcher3.Launcher; import com.android.launcher3.Launcher;
import com.android.launcher3.testing.shared.TestProtocol;
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -42,12 +44,21 @@ public class ViewOnDrawExecutor implements OnDrawListener, Runnable,
private boolean mCancelled; private boolean mCancelled;
public ViewOnDrawExecutor(RunnableList tasks) { public ViewOnDrawExecutor(RunnableList tasks) {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.FLAKY_BINDING, "Initialize ViewOnDrawExecutor");
}
mTasks = tasks; mTasks = tasks;
} }
public void attachTo(Launcher launcher) { public void attachTo(Launcher launcher) {
mOnClearCallback = launcher::clearPendingExecutor; mOnClearCallback = launcher::clearPendingExecutor;
mAttachedView = launcher.getWorkspace(); mAttachedView = launcher.getWorkspace();
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.FLAKY_BINDING, "ViewOnDrawExecutor.attachTo: launcher=" + launcher
+ ", isAttachedToWindow=" + mAttachedView.isAttachedToWindow());
}
mAttachedView.addOnAttachStateChangeListener(this); mAttachedView.addOnAttachStateChangeListener(this);
if (mAttachedView.isAttachedToWindow()) { if (mAttachedView.isAttachedToWindow()) {
@@ -56,6 +67,10 @@ public class ViewOnDrawExecutor implements OnDrawListener, Runnable,
} }
private void attachObserver() { private void attachObserver() {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.FLAKY_BINDING,
"ViewOnDrawExecutor.attachObserver: mCompleted=" + mCompleted);
}
if (!mCompleted) { if (!mCompleted) {
mAttachedView.getViewTreeObserver().addOnDrawListener(this); mAttachedView.getViewTreeObserver().addOnDrawListener(this);
} }
@@ -63,6 +78,9 @@ public class ViewOnDrawExecutor implements OnDrawListener, Runnable,
@Override @Override
public void onViewAttachedToWindow(View v) { public void onViewAttachedToWindow(View v) {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.FLAKY_BINDING, "ViewOnDrawExecutor.onViewAttachedToWindow");
}
attachObserver(); attachObserver();
} }
@@ -71,11 +89,19 @@ public class ViewOnDrawExecutor implements OnDrawListener, Runnable,
@Override @Override
public void onDraw() { public void onDraw() {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.FLAKY_BINDING, "ViewOnDrawExecutor.onDraw");
}
mFirstDrawCompleted = true; mFirstDrawCompleted = true;
mAttachedView.post(this); mAttachedView.post(this);
} }
public void onLoadAnimationCompleted() { public void onLoadAnimationCompleted() {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.FLAKY_BINDING,
"ViewOnDrawExecutor.onLoadAnimationCompleted: mAttachedView != null="
+ (mAttachedView != null));
}
mLoadAnimationCompleted = true; mLoadAnimationCompleted = true;
if (mAttachedView != null) { if (mAttachedView != null) {
mAttachedView.post(this); mAttachedView.post(this);
@@ -84,6 +110,12 @@ public class ViewOnDrawExecutor implements OnDrawListener, Runnable,
@Override @Override
public void run() { public void run() {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.FLAKY_BINDING,
"ViewOnDrawExecutor.run: mLoadAnimationCompleted=" + mLoadAnimationCompleted
+ ", mFirstDrawCompleted=" + mFirstDrawCompleted
+ ", mCompleted=" + mCompleted);
}
// Post the pending tasks after both onDraw and onLoadAnimationCompleted have been called. // Post the pending tasks after both onDraw and onLoadAnimationCompleted have been called.
if (mLoadAnimationCompleted && mFirstDrawCompleted && !mCompleted) { if (mLoadAnimationCompleted && mFirstDrawCompleted && !mCompleted) {
markCompleted(); markCompleted();
@@ -94,6 +126,12 @@ public class ViewOnDrawExecutor implements OnDrawListener, Runnable,
* Executes all tasks immediately * Executes all tasks immediately
*/ */
public void markCompleted() { public void markCompleted() {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.FLAKY_BINDING,
"ViewOnDrawExecutor.markCompleted: mCancelled=" + mCancelled
+ ", mOnClearCallback != null=" + (mOnClearCallback != null)
+ ", mAttachedView != null=" + (mAttachedView != null));
}
if (!mCancelled) { if (!mCancelled) {
mTasks.executeAllAndDestroy(); mTasks.executeAllAndDestroy();
} }
@@ -108,6 +146,9 @@ public class ViewOnDrawExecutor implements OnDrawListener, Runnable,
} }
public void cancel() { public void cancel() {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.FLAKY_BINDING, "ViewOnDrawExecutor.cancel");
}
mCancelled = true; mCancelled = true;
markCompleted(); markCompleted();
} }