Merge "Reduce some flaky cases of WmTests"

This commit is contained in:
Riddle Hsu
2023-07-04 16:29:11 +00:00
committed by Android (Google) Code Review
5 changed files with 27 additions and 5 deletions

View File

@@ -1603,7 +1603,7 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
// Since we created root-leash but no longer reference it from core, release it now
info.releaseAnimSurfaces();
mController.mLoggerHandler.post(mLogger::logOnSend);
mLogger.logOnSendAsync(mController.mLoggerHandler);
if (mLogger.mInfo != null) {
mController.mTransitionTracer.logSentTransition(this, mTargets);
}

View File

@@ -1434,7 +1434,7 @@ class TransitionController {
* Beside `mCreateWallTimeMs`, all times are elapsed times and will all be reported relative
* to when the transition was created.
*/
static class Logger {
static class Logger implements Runnable {
long mCreateWallTimeMs;
long mCreateTimeNs;
long mRequestTimeNs;
@@ -1458,6 +1458,20 @@ class TransitionController {
return sb.toString();
}
void logOnSendAsync(Handler handler) {
handler.post(this);
}
@Override
public void run() {
try {
logOnSend();
} catch (Exception e) {
// In case TransitionRequestInfo#toString() accesses window container with race.
Slog.w(TAG, "Failed to log transition", e);
}
}
void logOnSend() {
ProtoLog.v(ProtoLogGroup.WM_DEBUG_WINDOW_TRANSITIONS_MIN, "%s", buildOnSendLog());
ProtoLog.v(ProtoLogGroup.WM_DEBUG_WINDOW_TRANSITIONS_MIN, " startWCT=%s", mStartWCT);

View File

@@ -98,7 +98,7 @@ public class SurfaceControlViewHostTests {
mView1 = new Button(mActivity);
mView2 = new Button(mActivity);
mActivity.runOnUiThread(() -> {
mInstrumentation.runOnMainSync(() -> {
TestWindowlessWindowManager wwm = new TestWindowlessWindowManager(
mActivity.getResources().getConfiguration(), sc, null);

View File

@@ -208,7 +208,11 @@ public class SystemServicesTestRule implements TestRule {
spyOn(mContext);
doReturn(null).when(mContext)
.registerReceiver(nullable(BroadcastReceiver.class), any(IntentFilter.class));
.registerReceiver(nullable(BroadcastReceiver.class), any(IntentFilter.class),
nullable(String.class), nullable(Handler.class));
doReturn(null).when(mContext)
.registerReceiver(nullable(BroadcastReceiver.class), any(IntentFilter.class),
nullable(String.class), nullable(Handler.class), anyInt());
doReturn(null).when(mContext)
.registerReceiverAsUser(any(BroadcastReceiver.class), any(UserHandle.class),
any(IntentFilter.class), nullable(String.class), nullable(Handler.class));

View File

@@ -114,7 +114,11 @@ public class TransitionTests extends WindowTestsBase {
private BLASTSyncEngine mSyncEngine;
private Transition createTestTransition(int transitType, TransitionController controller) {
return new Transition(transitType, 0 /* flags */, controller, controller.mSyncEngine);
final Transition transition = new Transition(transitType, 0 /* flags */, controller,
controller.mSyncEngine);
spyOn(transition.mLogger);
doNothing().when(transition.mLogger).logOnSendAsync(any());
return transition;
}
private Transition createTestTransition(int transitType) {