Request embedded focus if a SurfacePackage was added to SV

If the SV was already focus when a SurfacePackage is attached, it should
request focus to the embedded. This allows focus to work better for the
developer perspective since they don't have to understand the timing of
when a SurfacePackage is attached vs when a view gains focus.

Test: SurfaceControlViewHostTests
Bug: 230340812
Change-Id: If55b33e92769e37794bd258e7f41da40decbef8c
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index cdea97c..0e4cf89 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -1854,6 +1854,10 @@
             applyTransactionOnVriDraw(transaction);
         }
         mSurfacePackage = p;
+
+        if (isFocused()) {
+            requestEmbeddedFocus(true);
+        }
         invalidate();
     }
 
@@ -1947,8 +1951,12 @@
 
     @Override
     protected void onFocusChanged(boolean gainFocus, @FocusDirection int direction,
-                                  @Nullable Rect previouslyFocusedRect) {
+            @Nullable Rect previouslyFocusedRect) {
         super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
+        requestEmbeddedFocus(gainFocus);
+    }
+
+    private void requestEmbeddedFocus(boolean gainFocus) {
         final ViewRootImpl viewRoot = getViewRootImpl();
         if (mSurfacePackage == null || viewRoot == null) {
             return;