Tests for updatePose

Fixed issue where reconfigure loses filter information.
Fix copypasted comments that incorrectly state that a call should fail.
Updated tests
(tests for updatePose are not included as the API is hidden in AOSP)

Bug: b/269491736, b/266223590
Test: atest CtsUwbTestCases FrameworkUwbTests ServiceUwbTests
Merged-In: I485707f8951bd4cc5e5b0ba2c60e6b47c80f5872
Change-Id: I485707f8951bd4cc5e5b0ba2c60e6b47c80f5872
diff --git a/framework/tests/src/android/uwb/RangingSessionTest.java b/framework/tests/src/android/uwb/RangingSessionTest.java
index f82ab1e..e15486a 100644
--- a/framework/tests/src/android/uwb/RangingSessionTest.java
+++ b/framework/tests/src/android/uwb/RangingSessionTest.java
@@ -487,7 +487,6 @@
         IUwbAdapter adapter = mock(IUwbAdapter.Stub.class);
         doNothing().when(adapter).updatePose(any(), any());
         RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle);
-        PersistableBundle params = new PersistableBundle();
         assertFalse(session.isOpen());
 
         session.onRangingOpened();
diff --git a/service/java/com/android/server/uwb/UwbSessionManager.java b/service/java/com/android/server/uwb/UwbSessionManager.java
index 3a62048..28fd60d 100644
--- a/service/java/com/android/server/uwb/UwbSessionManager.java
+++ b/service/java/com/android/server/uwb/UwbSessionManager.java
@@ -2007,6 +2007,8 @@
             if (mPoseSource instanceof ApplicationPoseSource) {
                 ApplicationPoseSource aps = (ApplicationPoseSource) mPoseSource;
                 aps.applyPose(updateParams.getPoseInfo());
+            } else {
+                throw new IllegalStateException("Session not configured for application poses.");
             }
         }
 
diff --git a/service/support_lib/src/com/google/uwb/support/fira/FiraOpenSessionParams.java b/service/support_lib/src/com/google/uwb/support/fira/FiraOpenSessionParams.java
index e532851..3bf37c7 100644
--- a/service/support_lib/src/com/google/uwb/support/fira/FiraOpenSessionParams.java
+++ b/service/support_lib/src/com/google/uwb/support/fira/FiraOpenSessionParams.java
@@ -1327,6 +1327,7 @@
             mUlTdoaDeviceIdType = params.mUlTdoaDeviceIdType;
             mUlTdoaDeviceId = params.mUlTdoaDeviceId;
             mUlTdoaTxTimestampType = params.mUlTdoaTxTimestampType;
+            mFilterType = params.mFilterType;
         }
 
         public FiraOpenSessionParams.Builder setProtocolVersion(FiraProtocolVersion version) {
diff --git a/service/support_lib/test/com/google/uwb/support/fira/FiraPoseUpdateParamsTest.java b/service/support_lib/test/com/google/uwb/support/fira/FiraPoseUpdateParamsTest.java
new file mode 100644
index 0000000..1121a4c
--- /dev/null
+++ b/service/support_lib/test/com/google/uwb/support/fira/FiraPoseUpdateParamsTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.uwb.support.fira;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import android.os.PersistableBundle;
+
+import org.junit.Test;
+
+public class FiraPoseUpdateParamsTest {
+    @Test
+    public void testParams() {
+        float[] floats = new float[] {1, 2, 3, 4, 5, 6, 7};
+        double[] doubles = new double[] {1, 2, 3, 4, 5, 6, 7};
+        FiraPoseUpdateParams poseParams;
+        FiraPoseUpdateParams unbundled;
+        PersistableBundle bundle;
+
+        // floats array - vec+quat
+        poseParams = new FiraPoseUpdateParams.Builder()
+                .setPose(floats)
+                .build();
+        bundle = poseParams.toBundle();
+        unbundled = FiraPoseUpdateParams.fromBundle(bundle);
+        assertArrayEquals(doubles, unbundled.getPoseInfo(), 0.001);
+
+        // doubles array - vec+quat
+        poseParams = new FiraPoseUpdateParams.Builder()
+                .setPose(doubles)
+                .build();
+        bundle = poseParams.toBundle();
+        unbundled = FiraPoseUpdateParams.fromBundle(bundle);
+        assertArrayEquals(doubles, unbundled.getPoseInfo(), 0.001);
+
+        // floats array - affine transform matrix
+        floats = new float[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+        doubles = new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+        poseParams = new FiraPoseUpdateParams.Builder()
+                .setPose(floats)
+                .build();
+        bundle = poseParams.toBundle();
+        unbundled = FiraPoseUpdateParams.fromBundle(bundle);
+        assertArrayEquals(doubles, unbundled.getPoseInfo(), 0.001);
+    }
+
+    @Test
+    public void testWrongParams() {
+        // floats array - wrong number of elements
+        org.junit.Assert.assertThrows(IllegalArgumentException.class, () ->
+                new FiraPoseUpdateParams.Builder()
+                        .setPose(new float[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13})
+                        .build());
+    }
+}
diff --git a/tests/cts/tests/src/android/uwb/cts/UwbManagerTest.java b/tests/cts/tests/src/android/uwb/cts/UwbManagerTest.java
index 0e0d128..376a25f 100644
--- a/tests/cts/tests/src/android/uwb/cts/UwbManagerTest.java
+++ b/tests/cts/tests/src/android/uwb/cts/UwbManagerTest.java
@@ -863,16 +863,8 @@
         }
     }
 
-    @Test
-    @CddTest(requirements = {"7.3.13/C-1-1,C-1-2,C-1-5"})
-    public void testFiraRangingSession() throws Exception {
-        UiAutomation uiAutomation = getInstrumentation().getUiAutomation();
-        CancellationSignal cancellationSignal = null;
-        CountDownLatch countDownLatch = new CountDownLatch(1);
-        CountDownLatch resultCountDownLatch = new CountDownLatch(1);
-        RangingSessionCallback rangingSessionCallback =
-                new RangingSessionCallback(countDownLatch, resultCountDownLatch);
-        FiraOpenSessionParams firaOpenSessionParams = new FiraOpenSessionParams.Builder()
+    private FiraOpenSessionParams.Builder makeOpenSessionBuilder() {
+        return new FiraOpenSessionParams.Builder()
                 .setProtocolVersion(new FiraProtocolVersion(1, 1))
                 .setSessionId(1)
                 .setSessionType(FiraParams.SESSION_TYPE_RANGING)
@@ -883,12 +875,24 @@
                 .setDeviceRole(FiraParams.RANGING_DEVICE_ROLE_INITIATOR)
                 .setMultiNodeMode(FiraParams.MULTI_NODE_MODE_UNICAST)
                 .setDeviceAddress(UwbAddress.fromBytes(new byte[] {0x5, 6}))
-                .setDestAddressList(List.of(UwbAddress.fromBytes(new byte[] {0x5, 6})))
+                .setDestAddressList(List.of(UwbAddress.fromBytes(new byte[] {0x5, 6})));
+    }
+
+    @Test
+    @CddTest(requirements = {"7.3.13/C-1-1,C-1-2,C-1-5"})
+    public void testFiraRangingSession() throws Exception {
+        UiAutomation uiAutomation = getInstrumentation().getUiAutomation();
+        CancellationSignal cancellationSignal = null;
+        CountDownLatch countDownLatch = new CountDownLatch(1);
+        CountDownLatch resultCountDownLatch = new CountDownLatch(1);
+        RangingSessionCallback rangingSessionCallback =
+                new RangingSessionCallback(countDownLatch, resultCountDownLatch);
+        FiraOpenSessionParams firaOpenSessionParams = makeOpenSessionBuilder()
                 .build();
         try {
             // Needs UWB_PRIVILEGED & UWB_RANGING permission which is held by shell.
             uiAutomation.adoptShellPermissionIdentity();
-            // Try to start a ranging session with invalid params, should fail.
+            // Start ranging session
             cancellationSignal = mUwbManager.openRangingSession(
                     firaOpenSessionParams.toBundle(),
                     Executors.newSingleThreadExecutor(),