Clear mSyncGroups when VRI does a performTraversal

When VRI is ready to start drawing, we need to sync any SV syncs
that have started, but not completed yet. However, it's possible a
second VRI can start drawing before the SV completes which would include
those original SV syncs in the second VRI frame. This isn't the expected
behavior since each SV sync is intended for a single VRI frame.
Therefore, clear the saved SV syncGroups once VRI is expected to start
drawing.

Test: async SV with resize due to insets no longer ANRs.
Bug: 263340543
Change-Id: Ib37505cd494ced68a7d9db291fe42d786d900a8a
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index e38376d..c64a2e8 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -1122,14 +1122,15 @@
      * @hide
      */
     @Override
-    public void surfaceSyncStarted() {
+    public void vriDrawStarted(boolean isWmSync) {
         ViewRootImpl viewRoot = getViewRootImpl();
-        if (viewRoot != null) {
-            synchronized (mSyncGroups) {
+        synchronized (mSyncGroups) {
+            if (isWmSync && viewRoot != null) {
                 for (SurfaceSyncGroup syncGroup : mSyncGroups) {
                     viewRoot.addToSync(syncGroup);
                 }
             }
+            mSyncGroups.clear();
         }
     }
 
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index c0f4731..3d1a1dd 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -2115,7 +2115,7 @@
         void surfaceCreated(Transaction t);
         void surfaceReplaced(Transaction t);
         void surfaceDestroyed();
-        default void surfaceSyncStarted() {};
+        default void vriDrawStarted(boolean isWmSync) {};
     }
 
     private final ArrayList<SurfaceChangedCallback> mSurfaceChangedCallbacks = new ArrayList<>();
@@ -2150,9 +2150,9 @@
         }
     }
 
-    private void notifySurfaceSyncStarted() {
+    private void notifyDrawStarted(boolean isWmSync) {
         for (int i = 0; i < mSurfaceChangedCallbacks.size(); i++) {
-            mSurfaceChangedCallbacks.get(i).surfaceSyncStarted();
+            mSurfaceChangedCallbacks.get(i).vriDrawStarted(isWmSync);
         }
     }
 
@@ -3664,6 +3664,7 @@
             }
 
             createSyncIfNeeded();
+            notifyDrawStarted(isInWMSRequestedSync());
             mDrewOnceForSync = true;
         }
 
@@ -3737,7 +3738,6 @@
 
         mWmsRequestSyncGroup.addToSync(this);
         Trace.traceEnd(Trace.TRACE_TAG_VIEW);
-        notifySurfaceSyncStarted();
     }
 
     private void notifyContentCatpureEvents() {